]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.7-201211251900.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.7-201211251900.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 07f2308..7271d99 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/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
1853 index 37afbd1..c22ad7c 100644
1854 --- a/arch/arm/mach-omap2/omap_hwmod.c
1855 +++ b/arch/arm/mach-omap2/omap_hwmod.c
1856 @@ -187,10 +187,10 @@ struct omap_hwmod_soc_ops {
1857 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
1858 struct omap_hwmod_rst_info *ohri);
1859 int (*init_clkdm)(struct omap_hwmod *oh);
1860 -};
1861 +} __no_const;
1862
1863 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
1864 -static struct omap_hwmod_soc_ops soc_ops;
1865 +static struct omap_hwmod_soc_ops soc_ops __read_only;
1866
1867 /* omap_hwmod_list contains all registered struct omap_hwmods */
1868 static LIST_HEAD(omap_hwmod_list);
1869 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1870 index c3bd834..e81ef02 100644
1871 --- a/arch/arm/mm/fault.c
1872 +++ b/arch/arm/mm/fault.c
1873 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1874 }
1875 #endif
1876
1877 +#ifdef CONFIG_PAX_PAGEEXEC
1878 + if (fsr & FSR_LNX_PF) {
1879 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1880 + do_group_exit(SIGKILL);
1881 + }
1882 +#endif
1883 +
1884 tsk->thread.address = addr;
1885 tsk->thread.error_code = fsr;
1886 tsk->thread.trap_no = 14;
1887 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1888 }
1889 #endif /* CONFIG_MMU */
1890
1891 +#ifdef CONFIG_PAX_PAGEEXEC
1892 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1893 +{
1894 + long i;
1895 +
1896 + printk(KERN_ERR "PAX: bytes at PC: ");
1897 + for (i = 0; i < 20; i++) {
1898 + unsigned char c;
1899 + if (get_user(c, (__force unsigned char __user *)pc+i))
1900 + printk(KERN_CONT "?? ");
1901 + else
1902 + printk(KERN_CONT "%02x ", c);
1903 + }
1904 + printk("\n");
1905 +
1906 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1907 + for (i = -1; i < 20; i++) {
1908 + unsigned long c;
1909 + if (get_user(c, (__force unsigned long __user *)sp+i))
1910 + printk(KERN_CONT "???????? ");
1911 + else
1912 + printk(KERN_CONT "%08lx ", c);
1913 + }
1914 + printk("\n");
1915 +}
1916 +#endif
1917 +
1918 /*
1919 * First Level Translation Fault Handler
1920 *
1921 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1922 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1923 struct siginfo info;
1924
1925 +#ifdef CONFIG_PAX_REFCOUNT
1926 + if (fsr_fs(ifsr) == 2) {
1927 + unsigned int bkpt;
1928 +
1929 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1930 + current->thread.error_code = ifsr;
1931 + current->thread.trap_no = 0;
1932 + pax_report_refcount_overflow(regs);
1933 + fixup_exception(regs);
1934 + return;
1935 + }
1936 + }
1937 +#endif
1938 +
1939 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1940 return;
1941
1942 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1943 index ce8cb19..3ec539d 100644
1944 --- a/arch/arm/mm/mmap.c
1945 +++ b/arch/arm/mm/mmap.c
1946 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1947 if (len > TASK_SIZE)
1948 return -ENOMEM;
1949
1950 +#ifdef CONFIG_PAX_RANDMMAP
1951 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1952 +#endif
1953 +
1954 if (addr) {
1955 if (do_align)
1956 addr = COLOUR_ALIGN(addr, pgoff);
1957 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1958 addr = PAGE_ALIGN(addr);
1959
1960 vma = find_vma(mm, addr);
1961 - if (TASK_SIZE - len >= addr &&
1962 - (!vma || addr + len <= vma->vm_start))
1963 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1964 return addr;
1965 }
1966 if (len > mm->cached_hole_size) {
1967 - start_addr = addr = mm->free_area_cache;
1968 + start_addr = addr = mm->free_area_cache;
1969 } else {
1970 - start_addr = addr = mm->mmap_base;
1971 - mm->cached_hole_size = 0;
1972 + start_addr = addr = mm->mmap_base;
1973 + mm->cached_hole_size = 0;
1974 }
1975
1976 full_search:
1977 @@ -124,14 +127,14 @@ full_search:
1978 * Start a new search - just in case we missed
1979 * some holes.
1980 */
1981 - if (start_addr != TASK_UNMAPPED_BASE) {
1982 - start_addr = addr = TASK_UNMAPPED_BASE;
1983 + if (start_addr != mm->mmap_base) {
1984 + start_addr = addr = mm->mmap_base;
1985 mm->cached_hole_size = 0;
1986 goto full_search;
1987 }
1988 return -ENOMEM;
1989 }
1990 - if (!vma || addr + len <= vma->vm_start) {
1991 + if (check_heap_stack_gap(vma, addr, len)) {
1992 /*
1993 * Remember the place where we stopped the search:
1994 */
1995 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1996
1997 if (mmap_is_legacy()) {
1998 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1999 +
2000 +#ifdef CONFIG_PAX_RANDMMAP
2001 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2002 + mm->mmap_base += mm->delta_mmap;
2003 +#endif
2004 +
2005 mm->get_unmapped_area = arch_get_unmapped_area;
2006 mm->unmap_area = arch_unmap_area;
2007 } else {
2008 mm->mmap_base = mmap_base(random_factor);
2009 +
2010 +#ifdef CONFIG_PAX_RANDMMAP
2011 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2012 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2013 +#endif
2014 +
2015 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2016 mm->unmap_area = arch_unmap_area_topdown;
2017 }
2018 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2019 index fd556f7..af2e7d2 100644
2020 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2021 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2022 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2023 value in bridge_virt_base */
2024 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2025 const int win);
2026 -};
2027 +} __no_const;
2028
2029 /*
2030 * Information needed to setup one address mapping.
2031 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2032 index f5144cd..71f6d1f 100644
2033 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2034 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2035 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2036 int (*started)(unsigned ch);
2037 int (*flush)(unsigned ch);
2038 int (*stop)(unsigned ch);
2039 -};
2040 +} __no_const;
2041
2042 extern void *samsung_dmadev_get_ops(void);
2043 extern void *s3c_dma_get_ops(void);
2044 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2045 index 5f28cae..3d23723 100644
2046 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2047 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2048 @@ -14,7 +14,7 @@
2049 struct s5p_ehci_platdata {
2050 int (*phy_init)(struct platform_device *pdev, int type);
2051 int (*phy_exit)(struct platform_device *pdev, int type);
2052 -};
2053 +} __no_const;
2054
2055 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2056
2057 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2058 index c3a58a1..78fbf54 100644
2059 --- a/arch/avr32/include/asm/cache.h
2060 +++ b/arch/avr32/include/asm/cache.h
2061 @@ -1,8 +1,10 @@
2062 #ifndef __ASM_AVR32_CACHE_H
2063 #define __ASM_AVR32_CACHE_H
2064
2065 +#include <linux/const.h>
2066 +
2067 #define L1_CACHE_SHIFT 5
2068 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2069 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2070
2071 /*
2072 * Memory returned by kmalloc() may be used for DMA, so we must make
2073 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2074 index 3b3159b..425ea94 100644
2075 --- a/arch/avr32/include/asm/elf.h
2076 +++ b/arch/avr32/include/asm/elf.h
2077 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2078 the loader. We need to make sure that it is out of the way of the program
2079 that it will "exec", and that there is sufficient room for the brk. */
2080
2081 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2082 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2083
2084 +#ifdef CONFIG_PAX_ASLR
2085 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2086 +
2087 +#define PAX_DELTA_MMAP_LEN 15
2088 +#define PAX_DELTA_STACK_LEN 15
2089 +#endif
2090
2091 /* This yields a mask that user programs can use to figure out what
2092 instruction set this CPU supports. This could be done in user space,
2093 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2094 index 479330b..53717a8 100644
2095 --- a/arch/avr32/include/asm/kmap_types.h
2096 +++ b/arch/avr32/include/asm/kmap_types.h
2097 @@ -2,9 +2,9 @@
2098 #define __ASM_AVR32_KMAP_TYPES_H
2099
2100 #ifdef CONFIG_DEBUG_HIGHMEM
2101 -# define KM_TYPE_NR 29
2102 +# define KM_TYPE_NR 30
2103 #else
2104 -# define KM_TYPE_NR 14
2105 +# define KM_TYPE_NR 15
2106 #endif
2107
2108 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2109 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2110 index b92e609..b69c101 100644
2111 --- a/arch/avr32/mm/fault.c
2112 +++ b/arch/avr32/mm/fault.c
2113 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2114
2115 int exception_trace = 1;
2116
2117 +#ifdef CONFIG_PAX_PAGEEXEC
2118 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2119 +{
2120 + unsigned long i;
2121 +
2122 + printk(KERN_ERR "PAX: bytes at PC: ");
2123 + for (i = 0; i < 20; i++) {
2124 + unsigned char c;
2125 + if (get_user(c, (unsigned char *)pc+i))
2126 + printk(KERN_CONT "???????? ");
2127 + else
2128 + printk(KERN_CONT "%02x ", c);
2129 + }
2130 + printk("\n");
2131 +}
2132 +#endif
2133 +
2134 /*
2135 * This routine handles page faults. It determines the address and the
2136 * problem, and then passes it off to one of the appropriate routines.
2137 @@ -173,6 +190,16 @@ bad_area:
2138 up_read(&mm->mmap_sem);
2139
2140 if (user_mode(regs)) {
2141 +
2142 +#ifdef CONFIG_PAX_PAGEEXEC
2143 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2144 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2145 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2146 + do_group_exit(SIGKILL);
2147 + }
2148 + }
2149 +#endif
2150 +
2151 if (exception_trace && printk_ratelimit())
2152 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2153 "sp %08lx ecr %lu\n",
2154 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2155 index 568885a..f8008df 100644
2156 --- a/arch/blackfin/include/asm/cache.h
2157 +++ b/arch/blackfin/include/asm/cache.h
2158 @@ -7,6 +7,7 @@
2159 #ifndef __ARCH_BLACKFIN_CACHE_H
2160 #define __ARCH_BLACKFIN_CACHE_H
2161
2162 +#include <linux/const.h>
2163 #include <linux/linkage.h> /* for asmlinkage */
2164
2165 /*
2166 @@ -14,7 +15,7 @@
2167 * Blackfin loads 32 bytes for cache
2168 */
2169 #define L1_CACHE_SHIFT 5
2170 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2171 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2172 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2173
2174 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2175 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2176 index aea2718..3639a60 100644
2177 --- a/arch/cris/include/arch-v10/arch/cache.h
2178 +++ b/arch/cris/include/arch-v10/arch/cache.h
2179 @@ -1,8 +1,9 @@
2180 #ifndef _ASM_ARCH_CACHE_H
2181 #define _ASM_ARCH_CACHE_H
2182
2183 +#include <linux/const.h>
2184 /* Etrax 100LX have 32-byte cache-lines. */
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 #endif /* _ASM_ARCH_CACHE_H */
2190 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2191 index 7caf25d..ee65ac5 100644
2192 --- a/arch/cris/include/arch-v32/arch/cache.h
2193 +++ b/arch/cris/include/arch-v32/arch/cache.h
2194 @@ -1,11 +1,12 @@
2195 #ifndef _ASM_CRIS_ARCH_CACHE_H
2196 #define _ASM_CRIS_ARCH_CACHE_H
2197
2198 +#include <linux/const.h>
2199 #include <arch/hwregs/dma.h>
2200
2201 /* A cache-line is 32 bytes. */
2202 -#define L1_CACHE_BYTES 32
2203 #define L1_CACHE_SHIFT 5
2204 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2205
2206 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2207
2208 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2209 index b86329d..6709906 100644
2210 --- a/arch/frv/include/asm/atomic.h
2211 +++ b/arch/frv/include/asm/atomic.h
2212 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2213 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2214 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2215
2216 +#define atomic64_read_unchecked(v) atomic64_read(v)
2217 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2218 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2219 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2220 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2221 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2222 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2223 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2224 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2225 +
2226 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2227 {
2228 int c, old;
2229 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2230 index 2797163..c2a401d 100644
2231 --- a/arch/frv/include/asm/cache.h
2232 +++ b/arch/frv/include/asm/cache.h
2233 @@ -12,10 +12,11 @@
2234 #ifndef __ASM_CACHE_H
2235 #define __ASM_CACHE_H
2236
2237 +#include <linux/const.h>
2238
2239 /* bytes per L1 cache line */
2240 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2241 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2242 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2243
2244 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2245 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2246 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2247 index 43901f2..0d8b865 100644
2248 --- a/arch/frv/include/asm/kmap_types.h
2249 +++ b/arch/frv/include/asm/kmap_types.h
2250 @@ -2,6 +2,6 @@
2251 #ifndef _ASM_KMAP_TYPES_H
2252 #define _ASM_KMAP_TYPES_H
2253
2254 -#define KM_TYPE_NR 17
2255 +#define KM_TYPE_NR 18
2256
2257 #endif
2258 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2259 index 385fd30..6c3d97e 100644
2260 --- a/arch/frv/mm/elf-fdpic.c
2261 +++ b/arch/frv/mm/elf-fdpic.c
2262 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2263 if (addr) {
2264 addr = PAGE_ALIGN(addr);
2265 vma = find_vma(current->mm, addr);
2266 - if (TASK_SIZE - len >= addr &&
2267 - (!vma || addr + len <= vma->vm_start))
2268 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2269 goto success;
2270 }
2271
2272 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2273 for (; vma; vma = vma->vm_next) {
2274 if (addr > limit)
2275 break;
2276 - if (addr + len <= vma->vm_start)
2277 + if (check_heap_stack_gap(vma, addr, len))
2278 goto success;
2279 addr = vma->vm_end;
2280 }
2281 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2282 for (; vma; vma = vma->vm_next) {
2283 if (addr > limit)
2284 break;
2285 - if (addr + len <= vma->vm_start)
2286 + if (check_heap_stack_gap(vma, addr, len))
2287 goto success;
2288 addr = vma->vm_end;
2289 }
2290 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2291 index c635028..6d9445a 100644
2292 --- a/arch/h8300/include/asm/cache.h
2293 +++ b/arch/h8300/include/asm/cache.h
2294 @@ -1,8 +1,10 @@
2295 #ifndef __ARCH_H8300_CACHE_H
2296 #define __ARCH_H8300_CACHE_H
2297
2298 +#include <linux/const.h>
2299 +
2300 /* bytes per L1 cache line */
2301 -#define L1_CACHE_BYTES 4
2302 +#define L1_CACHE_BYTES _AC(4,UL)
2303
2304 /* m68k-elf-gcc 2.95.2 doesn't like these */
2305
2306 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2307 index 0f01de2..d37d309 100644
2308 --- a/arch/hexagon/include/asm/cache.h
2309 +++ b/arch/hexagon/include/asm/cache.h
2310 @@ -21,9 +21,11 @@
2311 #ifndef __ASM_CACHE_H
2312 #define __ASM_CACHE_H
2313
2314 +#include <linux/const.h>
2315 +
2316 /* Bytes per L1 cache line */
2317 -#define L1_CACHE_SHIFT (5)
2318 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2319 +#define L1_CACHE_SHIFT 5
2320 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2321
2322 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2323 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2324 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2325 index 6e6fe18..a6ae668 100644
2326 --- a/arch/ia64/include/asm/atomic.h
2327 +++ b/arch/ia64/include/asm/atomic.h
2328 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2329 #define atomic64_inc(v) atomic64_add(1, (v))
2330 #define atomic64_dec(v) atomic64_sub(1, (v))
2331
2332 +#define atomic64_read_unchecked(v) atomic64_read(v)
2333 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2334 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2335 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2336 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2337 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2338 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2339 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2340 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2341 +
2342 /* Atomic operations are already serializing */
2343 #define smp_mb__before_atomic_dec() barrier()
2344 #define smp_mb__after_atomic_dec() barrier()
2345 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2346 index 988254a..e1ee885 100644
2347 --- a/arch/ia64/include/asm/cache.h
2348 +++ b/arch/ia64/include/asm/cache.h
2349 @@ -1,6 +1,7 @@
2350 #ifndef _ASM_IA64_CACHE_H
2351 #define _ASM_IA64_CACHE_H
2352
2353 +#include <linux/const.h>
2354
2355 /*
2356 * Copyright (C) 1998-2000 Hewlett-Packard Co
2357 @@ -9,7 +10,7 @@
2358
2359 /* Bytes per L1 (data) cache line. */
2360 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2361 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2362 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2363
2364 #ifdef CONFIG_SMP
2365 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2366 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2367 index b5298eb..67c6e62 100644
2368 --- a/arch/ia64/include/asm/elf.h
2369 +++ b/arch/ia64/include/asm/elf.h
2370 @@ -42,6 +42,13 @@
2371 */
2372 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2373
2374 +#ifdef CONFIG_PAX_ASLR
2375 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2376 +
2377 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2378 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2379 +#endif
2380 +
2381 #define PT_IA_64_UNWIND 0x70000001
2382
2383 /* IA-64 relocations: */
2384 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2385 index 96a8d92..617a1cf 100644
2386 --- a/arch/ia64/include/asm/pgalloc.h
2387 +++ b/arch/ia64/include/asm/pgalloc.h
2388 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2389 pgd_val(*pgd_entry) = __pa(pud);
2390 }
2391
2392 +static inline void
2393 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2394 +{
2395 + pgd_populate(mm, pgd_entry, pud);
2396 +}
2397 +
2398 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2399 {
2400 return quicklist_alloc(0, GFP_KERNEL, NULL);
2401 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2402 pud_val(*pud_entry) = __pa(pmd);
2403 }
2404
2405 +static inline void
2406 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2407 +{
2408 + pud_populate(mm, pud_entry, pmd);
2409 +}
2410 +
2411 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2412 {
2413 return quicklist_alloc(0, GFP_KERNEL, NULL);
2414 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2415 index 815810c..d60bd4c 100644
2416 --- a/arch/ia64/include/asm/pgtable.h
2417 +++ b/arch/ia64/include/asm/pgtable.h
2418 @@ -12,7 +12,7 @@
2419 * David Mosberger-Tang <davidm@hpl.hp.com>
2420 */
2421
2422 -
2423 +#include <linux/const.h>
2424 #include <asm/mman.h>
2425 #include <asm/page.h>
2426 #include <asm/processor.h>
2427 @@ -142,6 +142,17 @@
2428 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2429 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2430 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2431 +
2432 +#ifdef CONFIG_PAX_PAGEEXEC
2433 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2434 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2435 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2436 +#else
2437 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2438 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2439 +# define PAGE_COPY_NOEXEC PAGE_COPY
2440 +#endif
2441 +
2442 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2443 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2444 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2445 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2446 index 54ff557..70c88b7 100644
2447 --- a/arch/ia64/include/asm/spinlock.h
2448 +++ b/arch/ia64/include/asm/spinlock.h
2449 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2450 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2451
2452 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2453 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2454 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2455 }
2456
2457 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2458 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2459 index 449c8c0..432a3d2 100644
2460 --- a/arch/ia64/include/asm/uaccess.h
2461 +++ b/arch/ia64/include/asm/uaccess.h
2462 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2463 const void *__cu_from = (from); \
2464 long __cu_len = (n); \
2465 \
2466 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2467 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2468 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2469 __cu_len; \
2470 })
2471 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2472 long __cu_len = (n); \
2473 \
2474 __chk_user_ptr(__cu_from); \
2475 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2476 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2477 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2478 __cu_len; \
2479 })
2480 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2481 index 24603be..948052d 100644
2482 --- a/arch/ia64/kernel/module.c
2483 +++ b/arch/ia64/kernel/module.c
2484 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2485 void
2486 module_free (struct module *mod, void *module_region)
2487 {
2488 - if (mod && mod->arch.init_unw_table &&
2489 - module_region == mod->module_init) {
2490 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2491 unw_remove_unwind_table(mod->arch.init_unw_table);
2492 mod->arch.init_unw_table = NULL;
2493 }
2494 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2495 }
2496
2497 static inline int
2498 +in_init_rx (const struct module *mod, uint64_t addr)
2499 +{
2500 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2501 +}
2502 +
2503 +static inline int
2504 +in_init_rw (const struct module *mod, uint64_t addr)
2505 +{
2506 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2507 +}
2508 +
2509 +static inline int
2510 in_init (const struct module *mod, uint64_t addr)
2511 {
2512 - return addr - (uint64_t) mod->module_init < mod->init_size;
2513 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2514 +}
2515 +
2516 +static inline int
2517 +in_core_rx (const struct module *mod, uint64_t addr)
2518 +{
2519 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2520 +}
2521 +
2522 +static inline int
2523 +in_core_rw (const struct module *mod, uint64_t addr)
2524 +{
2525 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2526 }
2527
2528 static inline int
2529 in_core (const struct module *mod, uint64_t addr)
2530 {
2531 - return addr - (uint64_t) mod->module_core < mod->core_size;
2532 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2533 }
2534
2535 static inline int
2536 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2537 break;
2538
2539 case RV_BDREL:
2540 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2541 + if (in_init_rx(mod, val))
2542 + val -= (uint64_t) mod->module_init_rx;
2543 + else if (in_init_rw(mod, val))
2544 + val -= (uint64_t) mod->module_init_rw;
2545 + else if (in_core_rx(mod, val))
2546 + val -= (uint64_t) mod->module_core_rx;
2547 + else if (in_core_rw(mod, val))
2548 + val -= (uint64_t) mod->module_core_rw;
2549 break;
2550
2551 case RV_LTV:
2552 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2553 * addresses have been selected...
2554 */
2555 uint64_t gp;
2556 - if (mod->core_size > MAX_LTOFF)
2557 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2558 /*
2559 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2560 * at the end of the module.
2561 */
2562 - gp = mod->core_size - MAX_LTOFF / 2;
2563 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2564 else
2565 - gp = mod->core_size / 2;
2566 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2567 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2568 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2569 mod->arch.gp = gp;
2570 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2571 }
2572 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2573 index d9439ef..b9a4303 100644
2574 --- a/arch/ia64/kernel/sys_ia64.c
2575 +++ b/arch/ia64/kernel/sys_ia64.c
2576 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2577 if (REGION_NUMBER(addr) == RGN_HPAGE)
2578 addr = 0;
2579 #endif
2580 +
2581 +#ifdef CONFIG_PAX_RANDMMAP
2582 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2583 + addr = mm->free_area_cache;
2584 + else
2585 +#endif
2586 +
2587 if (!addr)
2588 addr = mm->free_area_cache;
2589
2590 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2591 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2592 /* At this point: (!vma || addr < vma->vm_end). */
2593 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2594 - if (start_addr != TASK_UNMAPPED_BASE) {
2595 + if (start_addr != mm->mmap_base) {
2596 /* Start a new search --- just in case we missed some holes. */
2597 - addr = TASK_UNMAPPED_BASE;
2598 + addr = mm->mmap_base;
2599 goto full_search;
2600 }
2601 return -ENOMEM;
2602 }
2603 - if (!vma || addr + len <= vma->vm_start) {
2604 + if (check_heap_stack_gap(vma, addr, len)) {
2605 /* Remember the address where we stopped this search: */
2606 mm->free_area_cache = addr + len;
2607 return addr;
2608 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2609 index 0ccb28f..8992469 100644
2610 --- a/arch/ia64/kernel/vmlinux.lds.S
2611 +++ b/arch/ia64/kernel/vmlinux.lds.S
2612 @@ -198,7 +198,7 @@ SECTIONS {
2613 /* Per-cpu data: */
2614 . = ALIGN(PERCPU_PAGE_SIZE);
2615 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2616 - __phys_per_cpu_start = __per_cpu_load;
2617 + __phys_per_cpu_start = per_cpu_load;
2618 /*
2619 * ensure percpu data fits
2620 * into percpu page size
2621 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2622 index 8443daf..0a01e30 100644
2623 --- a/arch/ia64/mm/fault.c
2624 +++ b/arch/ia64/mm/fault.c
2625 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2626 return pte_present(pte);
2627 }
2628
2629 +#ifdef CONFIG_PAX_PAGEEXEC
2630 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2631 +{
2632 + unsigned long i;
2633 +
2634 + printk(KERN_ERR "PAX: bytes at PC: ");
2635 + for (i = 0; i < 8; i++) {
2636 + unsigned int c;
2637 + if (get_user(c, (unsigned int *)pc+i))
2638 + printk(KERN_CONT "???????? ");
2639 + else
2640 + printk(KERN_CONT "%08x ", c);
2641 + }
2642 + printk("\n");
2643 +}
2644 +#endif
2645 +
2646 # define VM_READ_BIT 0
2647 # define VM_WRITE_BIT 1
2648 # define VM_EXEC_BIT 2
2649 @@ -149,8 +166,21 @@ retry:
2650 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
2651 goto bad_area;
2652
2653 - if ((vma->vm_flags & mask) != mask)
2654 + if ((vma->vm_flags & mask) != mask) {
2655 +
2656 +#ifdef CONFIG_PAX_PAGEEXEC
2657 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2658 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2659 + goto bad_area;
2660 +
2661 + up_read(&mm->mmap_sem);
2662 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2663 + do_group_exit(SIGKILL);
2664 + }
2665 +#endif
2666 +
2667 goto bad_area;
2668 + }
2669
2670 /*
2671 * If for any reason at all we couldn't handle the fault, make
2672 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2673 index 5ca674b..e0e1b70 100644
2674 --- a/arch/ia64/mm/hugetlbpage.c
2675 +++ b/arch/ia64/mm/hugetlbpage.c
2676 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2677 /* At this point: (!vmm || addr < vmm->vm_end). */
2678 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2679 return -ENOMEM;
2680 - if (!vmm || (addr + len) <= vmm->vm_start)
2681 + if (check_heap_stack_gap(vmm, addr, len))
2682 return addr;
2683 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2684 }
2685 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2686 index 0eab454..bd794f2 100644
2687 --- a/arch/ia64/mm/init.c
2688 +++ b/arch/ia64/mm/init.c
2689 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2690 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2691 vma->vm_end = vma->vm_start + PAGE_SIZE;
2692 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2693 +
2694 +#ifdef CONFIG_PAX_PAGEEXEC
2695 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2696 + vma->vm_flags &= ~VM_EXEC;
2697 +
2698 +#ifdef CONFIG_PAX_MPROTECT
2699 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2700 + vma->vm_flags &= ~VM_MAYEXEC;
2701 +#endif
2702 +
2703 + }
2704 +#endif
2705 +
2706 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2707 down_write(&current->mm->mmap_sem);
2708 if (insert_vm_struct(current->mm, vma)) {
2709 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2710 index 40b3ee9..8c2c112 100644
2711 --- a/arch/m32r/include/asm/cache.h
2712 +++ b/arch/m32r/include/asm/cache.h
2713 @@ -1,8 +1,10 @@
2714 #ifndef _ASM_M32R_CACHE_H
2715 #define _ASM_M32R_CACHE_H
2716
2717 +#include <linux/const.h>
2718 +
2719 /* L1 cache line size */
2720 #define L1_CACHE_SHIFT 4
2721 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2722 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2723
2724 #endif /* _ASM_M32R_CACHE_H */
2725 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2726 index 82abd15..d95ae5d 100644
2727 --- a/arch/m32r/lib/usercopy.c
2728 +++ b/arch/m32r/lib/usercopy.c
2729 @@ -14,6 +14,9 @@
2730 unsigned long
2731 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2732 {
2733 + if ((long)n < 0)
2734 + return n;
2735 +
2736 prefetch(from);
2737 if (access_ok(VERIFY_WRITE, to, n))
2738 __copy_user(to,from,n);
2739 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2740 unsigned long
2741 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2742 {
2743 + if ((long)n < 0)
2744 + return n;
2745 +
2746 prefetchw(to);
2747 if (access_ok(VERIFY_READ, from, n))
2748 __copy_user_zeroing(to,from,n);
2749 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2750 index 0395c51..5f26031 100644
2751 --- a/arch/m68k/include/asm/cache.h
2752 +++ b/arch/m68k/include/asm/cache.h
2753 @@ -4,9 +4,11 @@
2754 #ifndef __ARCH_M68K_CACHE_H
2755 #define __ARCH_M68K_CACHE_H
2756
2757 +#include <linux/const.h>
2758 +
2759 /* bytes per L1 cache line */
2760 #define L1_CACHE_SHIFT 4
2761 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2762 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2763
2764 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2765
2766 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2767 index 4efe96a..60e8699 100644
2768 --- a/arch/microblaze/include/asm/cache.h
2769 +++ b/arch/microblaze/include/asm/cache.h
2770 @@ -13,11 +13,12 @@
2771 #ifndef _ASM_MICROBLAZE_CACHE_H
2772 #define _ASM_MICROBLAZE_CACHE_H
2773
2774 +#include <linux/const.h>
2775 #include <asm/registers.h>
2776
2777 #define L1_CACHE_SHIFT 5
2778 /* word-granular cache in microblaze */
2779 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2780 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2781
2782 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2783
2784 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2785 index 3f4c5cb..3439c6e 100644
2786 --- a/arch/mips/include/asm/atomic.h
2787 +++ b/arch/mips/include/asm/atomic.h
2788 @@ -21,6 +21,10 @@
2789 #include <asm/cmpxchg.h>
2790 #include <asm/war.h>
2791
2792 +#ifdef CONFIG_GENERIC_ATOMIC64
2793 +#include <asm-generic/atomic64.h>
2794 +#endif
2795 +
2796 #define ATOMIC_INIT(i) { (i) }
2797
2798 /*
2799 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2800 */
2801 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2802
2803 +#define atomic64_read_unchecked(v) atomic64_read(v)
2804 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2805 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2806 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2807 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2808 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2809 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2810 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2811 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2812 +
2813 #endif /* CONFIG_64BIT */
2814
2815 /*
2816 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2817 index b4db69f..8f3b093 100644
2818 --- a/arch/mips/include/asm/cache.h
2819 +++ b/arch/mips/include/asm/cache.h
2820 @@ -9,10 +9,11 @@
2821 #ifndef _ASM_CACHE_H
2822 #define _ASM_CACHE_H
2823
2824 +#include <linux/const.h>
2825 #include <kmalloc.h>
2826
2827 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2828 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2829 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2830
2831 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2832 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2833 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2834 index 455c0ac..ad65fbe 100644
2835 --- a/arch/mips/include/asm/elf.h
2836 +++ b/arch/mips/include/asm/elf.h
2837 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2838 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2839 #endif
2840
2841 +#ifdef CONFIG_PAX_ASLR
2842 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2843 +
2844 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2845 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2846 +#endif
2847 +
2848 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2849 struct linux_binprm;
2850 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2851 int uses_interp);
2852
2853 -struct mm_struct;
2854 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2855 -#define arch_randomize_brk arch_randomize_brk
2856 -
2857 #endif /* _ASM_ELF_H */
2858 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2859 index c1f6afa..38cc6e9 100644
2860 --- a/arch/mips/include/asm/exec.h
2861 +++ b/arch/mips/include/asm/exec.h
2862 @@ -12,6 +12,6 @@
2863 #ifndef _ASM_EXEC_H
2864 #define _ASM_EXEC_H
2865
2866 -extern unsigned long arch_align_stack(unsigned long sp);
2867 +#define arch_align_stack(x) ((x) & ~0xfUL)
2868
2869 #endif /* _ASM_EXEC_H */
2870 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2871 index da9bd7d..91aa7ab 100644
2872 --- a/arch/mips/include/asm/page.h
2873 +++ b/arch/mips/include/asm/page.h
2874 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2875 #ifdef CONFIG_CPU_MIPS32
2876 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2877 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2878 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2879 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2880 #else
2881 typedef struct { unsigned long long pte; } pte_t;
2882 #define pte_val(x) ((x).pte)
2883 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2884 index 881d18b..cea38bc 100644
2885 --- a/arch/mips/include/asm/pgalloc.h
2886 +++ b/arch/mips/include/asm/pgalloc.h
2887 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2888 {
2889 set_pud(pud, __pud((unsigned long)pmd));
2890 }
2891 +
2892 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2893 +{
2894 + pud_populate(mm, pud, pmd);
2895 +}
2896 #endif
2897
2898 /*
2899 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2900 index ca97e0e..cd08920 100644
2901 --- a/arch/mips/include/asm/thread_info.h
2902 +++ b/arch/mips/include/asm/thread_info.h
2903 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2904 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2905 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2906 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2907 +/* li takes a 32bit immediate */
2908 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2909 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2910
2911 #ifdef CONFIG_MIPS32_O32
2912 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2913 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2914 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2915 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2916 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2917 +
2918 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2919
2920 /* work to do in syscall_trace_leave() */
2921 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2922 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2923
2924 /* work to do on interrupt/exception return */
2925 #define _TIF_WORK_MASK (0x0000ffef & \
2926 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2927 /* work to do on any return to u-space */
2928 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2929 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2930
2931 #endif /* __KERNEL__ */
2932
2933 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2934 index 9fdd8bc..4bd7f1a 100644
2935 --- a/arch/mips/kernel/binfmt_elfn32.c
2936 +++ b/arch/mips/kernel/binfmt_elfn32.c
2937 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2938 #undef ELF_ET_DYN_BASE
2939 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2940
2941 +#ifdef CONFIG_PAX_ASLR
2942 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2943 +
2944 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2945 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2946 +#endif
2947 +
2948 #include <asm/processor.h>
2949 #include <linux/module.h>
2950 #include <linux/elfcore.h>
2951 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2952 index ff44823..97f8906 100644
2953 --- a/arch/mips/kernel/binfmt_elfo32.c
2954 +++ b/arch/mips/kernel/binfmt_elfo32.c
2955 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2956 #undef ELF_ET_DYN_BASE
2957 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2958
2959 +#ifdef CONFIG_PAX_ASLR
2960 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2961 +
2962 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2963 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2964 +#endif
2965 +
2966 #include <asm/processor.h>
2967
2968 /*
2969 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2970 index e9a5fd7..378809a 100644
2971 --- a/arch/mips/kernel/process.c
2972 +++ b/arch/mips/kernel/process.c
2973 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2974 out:
2975 return pc;
2976 }
2977 -
2978 -/*
2979 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2980 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2981 - */
2982 -unsigned long arch_align_stack(unsigned long sp)
2983 -{
2984 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2985 - sp -= get_random_int() & ~PAGE_MASK;
2986 -
2987 - return sp & ALMASK;
2988 -}
2989 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2990 index 4812c6d..2069554 100644
2991 --- a/arch/mips/kernel/ptrace.c
2992 +++ b/arch/mips/kernel/ptrace.c
2993 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2994 return arch;
2995 }
2996
2997 +#ifdef CONFIG_GRKERNSEC_SETXID
2998 +extern void gr_delayed_cred_worker(void);
2999 +#endif
3000 +
3001 /*
3002 * Notification of system call entry/exit
3003 * - triggered by current->work.syscall_trace
3004 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3005 /* do the secure computing check first */
3006 secure_computing_strict(regs->regs[2]);
3007
3008 +#ifdef CONFIG_GRKERNSEC_SETXID
3009 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3010 + gr_delayed_cred_worker();
3011 +#endif
3012 +
3013 if (!(current->ptrace & PT_PTRACED))
3014 goto out;
3015
3016 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3017 index a632bc1..0b77c7c 100644
3018 --- a/arch/mips/kernel/scall32-o32.S
3019 +++ b/arch/mips/kernel/scall32-o32.S
3020 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3021
3022 stack_done:
3023 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3024 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3025 + li t1, _TIF_SYSCALL_WORK
3026 and t0, t1
3027 bnez t0, syscall_trace_entry # -> yes
3028
3029 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3030 index 3b5a5e9..e1ee86d 100644
3031 --- a/arch/mips/kernel/scall64-64.S
3032 +++ b/arch/mips/kernel/scall64-64.S
3033 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3034
3035 sd a3, PT_R26(sp) # save a3 for syscall restarting
3036
3037 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3038 + li t1, _TIF_SYSCALL_WORK
3039 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3040 and t0, t1, t0
3041 bnez t0, syscall_trace_entry
3042 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3043 index 6be6f70..1859577 100644
3044 --- a/arch/mips/kernel/scall64-n32.S
3045 +++ b/arch/mips/kernel/scall64-n32.S
3046 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3047
3048 sd a3, PT_R26(sp) # save a3 for syscall restarting
3049
3050 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3051 + li t1, _TIF_SYSCALL_WORK
3052 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3053 and t0, t1, t0
3054 bnez t0, n32_syscall_trace_entry
3055 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3056 index 5422855..74e63a3 100644
3057 --- a/arch/mips/kernel/scall64-o32.S
3058 +++ b/arch/mips/kernel/scall64-o32.S
3059 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3060 PTR 4b, bad_stack
3061 .previous
3062
3063 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3064 + li t1, _TIF_SYSCALL_WORK
3065 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3066 and t0, t1, t0
3067 bnez t0, trace_a_syscall
3068 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3069 index c14f6df..537e729 100644
3070 --- a/arch/mips/mm/fault.c
3071 +++ b/arch/mips/mm/fault.c
3072 @@ -27,6 +27,23 @@
3073 #include <asm/highmem.h> /* For VMALLOC_END */
3074 #include <linux/kdebug.h>
3075
3076 +#ifdef CONFIG_PAX_PAGEEXEC
3077 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3078 +{
3079 + unsigned long i;
3080 +
3081 + printk(KERN_ERR "PAX: bytes at PC: ");
3082 + for (i = 0; i < 5; i++) {
3083 + unsigned int c;
3084 + if (get_user(c, (unsigned int *)pc+i))
3085 + printk(KERN_CONT "???????? ");
3086 + else
3087 + printk(KERN_CONT "%08x ", c);
3088 + }
3089 + printk("\n");
3090 +}
3091 +#endif
3092 +
3093 /*
3094 * This routine handles page faults. It determines the address,
3095 * and the problem, and then passes it off to one of the appropriate
3096 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3097 index 302d779..7d35bf8 100644
3098 --- a/arch/mips/mm/mmap.c
3099 +++ b/arch/mips/mm/mmap.c
3100 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3101 do_color_align = 1;
3102
3103 /* requesting a specific address */
3104 +
3105 +#ifdef CONFIG_PAX_RANDMMAP
3106 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3107 +#endif
3108 +
3109 if (addr) {
3110 if (do_color_align)
3111 addr = COLOUR_ALIGN(addr, pgoff);
3112 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3113 addr = PAGE_ALIGN(addr);
3114
3115 vma = find_vma(mm, addr);
3116 - if (TASK_SIZE - len >= addr &&
3117 - (!vma || addr + len <= vma->vm_start))
3118 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3119 return addr;
3120 }
3121
3122 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3123 /* At this point: (!vma || addr < vma->vm_end). */
3124 if (TASK_SIZE - len < addr)
3125 return -ENOMEM;
3126 - if (!vma || addr + len <= vma->vm_start)
3127 + if (check_heap_stack_gap(vmm, addr, len))
3128 return addr;
3129 addr = vma->vm_end;
3130 if (do_color_align)
3131 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3132 /* make sure it can fit in the remaining address space */
3133 if (likely(addr > len)) {
3134 vma = find_vma(mm, addr - len);
3135 - if (!vma || addr <= vma->vm_start) {
3136 + if (check_heap_stack_gap(vmm, addr - len, len))
3137 /* cache the address as a hint for next time */
3138 return mm->free_area_cache = addr - len;
3139 }
3140 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3141 * return with success:
3142 */
3143 vma = find_vma(mm, addr);
3144 - if (likely(!vma || addr + len <= vma->vm_start)) {
3145 + if (check_heap_stack_gap(vmm, addr, len)) {
3146 /* cache the address as a hint for next time */
3147 return mm->free_area_cache = addr;
3148 }
3149 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3150 mm->unmap_area = arch_unmap_area_topdown;
3151 }
3152 }
3153 -
3154 -static inline unsigned long brk_rnd(void)
3155 -{
3156 - unsigned long rnd = get_random_int();
3157 -
3158 - rnd = rnd << PAGE_SHIFT;
3159 - /* 8MB for 32bit, 256MB for 64bit */
3160 - if (TASK_IS_32BIT_ADDR)
3161 - rnd = rnd & 0x7ffffful;
3162 - else
3163 - rnd = rnd & 0xffffffful;
3164 -
3165 - return rnd;
3166 -}
3167 -
3168 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3169 -{
3170 - unsigned long base = mm->brk;
3171 - unsigned long ret;
3172 -
3173 - ret = PAGE_ALIGN(base + brk_rnd());
3174 -
3175 - if (ret < mm->brk)
3176 - return mm->brk;
3177 -
3178 - return ret;
3179 -}
3180 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3181 index 967d144..db12197 100644
3182 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3183 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3184 @@ -11,12 +11,14 @@
3185 #ifndef _ASM_PROC_CACHE_H
3186 #define _ASM_PROC_CACHE_H
3187
3188 +#include <linux/const.h>
3189 +
3190 /* L1 cache */
3191
3192 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3193 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3194 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3195 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3196 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3197 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3198
3199 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3200 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3201 index bcb5df2..84fabd2 100644
3202 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3203 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3204 @@ -16,13 +16,15 @@
3205 #ifndef _ASM_PROC_CACHE_H
3206 #define _ASM_PROC_CACHE_H
3207
3208 +#include <linux/const.h>
3209 +
3210 /*
3211 * L1 cache
3212 */
3213 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3214 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3215 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3216 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3217 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3218 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3219
3220 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3221 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3222 index 4ce7a01..449202a 100644
3223 --- a/arch/openrisc/include/asm/cache.h
3224 +++ b/arch/openrisc/include/asm/cache.h
3225 @@ -19,11 +19,13 @@
3226 #ifndef __ASM_OPENRISC_CACHE_H
3227 #define __ASM_OPENRISC_CACHE_H
3228
3229 +#include <linux/const.h>
3230 +
3231 /* FIXME: How can we replace these with values from the CPU...
3232 * they shouldn't be hard-coded!
3233 */
3234
3235 -#define L1_CACHE_BYTES 16
3236 #define L1_CACHE_SHIFT 4
3237 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3238
3239 #endif /* __ASM_OPENRISC_CACHE_H */
3240 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3241 index af9cf30..2aae9b2 100644
3242 --- a/arch/parisc/include/asm/atomic.h
3243 +++ b/arch/parisc/include/asm/atomic.h
3244 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3245
3246 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3247
3248 +#define atomic64_read_unchecked(v) atomic64_read(v)
3249 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3250 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3251 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3252 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3253 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3254 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3255 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3256 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3257 +
3258 #endif /* !CONFIG_64BIT */
3259
3260
3261 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3262 index 47f11c7..3420df2 100644
3263 --- a/arch/parisc/include/asm/cache.h
3264 +++ b/arch/parisc/include/asm/cache.h
3265 @@ -5,6 +5,7 @@
3266 #ifndef __ARCH_PARISC_CACHE_H
3267 #define __ARCH_PARISC_CACHE_H
3268
3269 +#include <linux/const.h>
3270
3271 /*
3272 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3273 @@ -15,13 +16,13 @@
3274 * just ruin performance.
3275 */
3276 #ifdef CONFIG_PA20
3277 -#define L1_CACHE_BYTES 64
3278 #define L1_CACHE_SHIFT 6
3279 #else
3280 -#define L1_CACHE_BYTES 32
3281 #define L1_CACHE_SHIFT 5
3282 #endif
3283
3284 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3285 +
3286 #ifndef __ASSEMBLY__
3287
3288 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3289 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3290 index 19f6cb1..6c78cf2 100644
3291 --- a/arch/parisc/include/asm/elf.h
3292 +++ b/arch/parisc/include/asm/elf.h
3293 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3294
3295 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3296
3297 +#ifdef CONFIG_PAX_ASLR
3298 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3299 +
3300 +#define PAX_DELTA_MMAP_LEN 16
3301 +#define PAX_DELTA_STACK_LEN 16
3302 +#endif
3303 +
3304 /* This yields a mask that user programs can use to figure out what
3305 instruction set this CPU supports. This could be done in user space,
3306 but it's not easy, and we've already done it here. */
3307 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3308 index fc987a1..6e068ef 100644
3309 --- a/arch/parisc/include/asm/pgalloc.h
3310 +++ b/arch/parisc/include/asm/pgalloc.h
3311 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3312 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3313 }
3314
3315 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3316 +{
3317 + pgd_populate(mm, pgd, pmd);
3318 +}
3319 +
3320 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3321 {
3322 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3323 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3324 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3325 #define pmd_free(mm, x) do { } while (0)
3326 #define pgd_populate(mm, pmd, pte) BUG()
3327 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3328
3329 #endif
3330
3331 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3332 index ee99f23..802b0a1 100644
3333 --- a/arch/parisc/include/asm/pgtable.h
3334 +++ b/arch/parisc/include/asm/pgtable.h
3335 @@ -212,6 +212,17 @@ struct vm_area_struct;
3336 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3337 #define PAGE_COPY PAGE_EXECREAD
3338 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3339 +
3340 +#ifdef CONFIG_PAX_PAGEEXEC
3341 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3342 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3343 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3344 +#else
3345 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3346 +# define PAGE_COPY_NOEXEC PAGE_COPY
3347 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3348 +#endif
3349 +
3350 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3351 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3352 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3353 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3354 index 4ba2c93..f5e3974 100644
3355 --- a/arch/parisc/include/asm/uaccess.h
3356 +++ b/arch/parisc/include/asm/uaccess.h
3357 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3358 const void __user *from,
3359 unsigned long n)
3360 {
3361 - int sz = __compiletime_object_size(to);
3362 + size_t sz = __compiletime_object_size(to);
3363 int ret = -EFAULT;
3364
3365 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3366 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3367 ret = __copy_from_user(to, from, n);
3368 else
3369 copy_from_user_overflow();
3370 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3371 index 5e34ccf..672bc9c 100644
3372 --- a/arch/parisc/kernel/module.c
3373 +++ b/arch/parisc/kernel/module.c
3374 @@ -98,16 +98,38 @@
3375
3376 /* three functions to determine where in the module core
3377 * or init pieces the location is */
3378 +static inline int in_init_rx(struct module *me, void *loc)
3379 +{
3380 + return (loc >= me->module_init_rx &&
3381 + loc < (me->module_init_rx + me->init_size_rx));
3382 +}
3383 +
3384 +static inline int in_init_rw(struct module *me, void *loc)
3385 +{
3386 + return (loc >= me->module_init_rw &&
3387 + loc < (me->module_init_rw + me->init_size_rw));
3388 +}
3389 +
3390 static inline int in_init(struct module *me, void *loc)
3391 {
3392 - return (loc >= me->module_init &&
3393 - loc <= (me->module_init + me->init_size));
3394 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3395 +}
3396 +
3397 +static inline int in_core_rx(struct module *me, void *loc)
3398 +{
3399 + return (loc >= me->module_core_rx &&
3400 + loc < (me->module_core_rx + me->core_size_rx));
3401 +}
3402 +
3403 +static inline int in_core_rw(struct module *me, void *loc)
3404 +{
3405 + return (loc >= me->module_core_rw &&
3406 + loc < (me->module_core_rw + me->core_size_rw));
3407 }
3408
3409 static inline int in_core(struct module *me, void *loc)
3410 {
3411 - return (loc >= me->module_core &&
3412 - loc <= (me->module_core + me->core_size));
3413 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3414 }
3415
3416 static inline int in_local(struct module *me, void *loc)
3417 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3418 }
3419
3420 /* align things a bit */
3421 - me->core_size = ALIGN(me->core_size, 16);
3422 - me->arch.got_offset = me->core_size;
3423 - me->core_size += gots * sizeof(struct got_entry);
3424 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3425 + me->arch.got_offset = me->core_size_rw;
3426 + me->core_size_rw += gots * sizeof(struct got_entry);
3427
3428 - me->core_size = ALIGN(me->core_size, 16);
3429 - me->arch.fdesc_offset = me->core_size;
3430 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3431 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3432 + me->arch.fdesc_offset = me->core_size_rw;
3433 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3434
3435 me->arch.got_max = gots;
3436 me->arch.fdesc_max = fdescs;
3437 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3438
3439 BUG_ON(value == 0);
3440
3441 - got = me->module_core + me->arch.got_offset;
3442 + got = me->module_core_rw + me->arch.got_offset;
3443 for (i = 0; got[i].addr; i++)
3444 if (got[i].addr == value)
3445 goto out;
3446 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3447 #ifdef CONFIG_64BIT
3448 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3449 {
3450 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3451 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3452
3453 if (!value) {
3454 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3455 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3456
3457 /* Create new one */
3458 fdesc->addr = value;
3459 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3460 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3461 return (Elf_Addr)fdesc;
3462 }
3463 #endif /* CONFIG_64BIT */
3464 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3465
3466 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3467 end = table + sechdrs[me->arch.unwind_section].sh_size;
3468 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3469 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3470
3471 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3472 me->arch.unwind_section, table, end, gp);
3473 diff --git a/arch/parisc/kernel/signal32.c b/arch/parisc/kernel/signal32.c
3474 index fd49aed..5dede04 100644
3475 --- a/arch/parisc/kernel/signal32.c
3476 +++ b/arch/parisc/kernel/signal32.c
3477 @@ -65,7 +65,8 @@ put_sigset32(compat_sigset_t __user *up, sigset_t *set, size_t sz)
3478 {
3479 compat_sigset_t s;
3480
3481 - if (sz != sizeof *set) panic("put_sigset32()");
3482 + if (sz != sizeof *set)
3483 + return -EINVAL;
3484 sigset_64to32(&s, set);
3485
3486 return copy_to_user(up, &s, sizeof s);
3487 @@ -77,7 +78,8 @@ get_sigset32(compat_sigset_t __user *up, sigset_t *set, size_t sz)
3488 compat_sigset_t s;
3489 int r;
3490
3491 - if (sz != sizeof *set) panic("put_sigset32()");
3492 + if (sz != sizeof *set)
3493 + return -EINVAL;
3494
3495 if ((r = copy_from_user(&s, up, sz)) == 0) {
3496 sigset_32to64(set, &s);
3497 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3498 index 7426e40..30c8dbe 100644
3499 --- a/arch/parisc/kernel/sys_parisc.c
3500 +++ b/arch/parisc/kernel/sys_parisc.c
3501 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3502 /* At this point: (!vma || addr < vma->vm_end). */
3503 if (TASK_SIZE - len < addr)
3504 return -ENOMEM;
3505 - if (!vma || addr + len <= vma->vm_start)
3506 + if (check_heap_stack_gap(vma, addr, len))
3507 return addr;
3508 addr = vma->vm_end;
3509 }
3510 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3511 /* At this point: (!vma || addr < vma->vm_end). */
3512 if (TASK_SIZE - len < addr)
3513 return -ENOMEM;
3514 - if (!vma || addr + len <= vma->vm_start)
3515 + if (check_heap_stack_gap(vma, addr, len))
3516 return addr;
3517 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3518 if (addr < vma->vm_end) /* handle wraparound */
3519 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3520 if (flags & MAP_FIXED)
3521 return addr;
3522 if (!addr)
3523 - addr = TASK_UNMAPPED_BASE;
3524 + addr = current->mm->mmap_base;
3525
3526 if (filp) {
3527 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3528 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3529 index 45ba99f..8e22c33 100644
3530 --- a/arch/parisc/kernel/traps.c
3531 +++ b/arch/parisc/kernel/traps.c
3532 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3533
3534 down_read(&current->mm->mmap_sem);
3535 vma = find_vma(current->mm,regs->iaoq[0]);
3536 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3537 - && (vma->vm_flags & VM_EXEC)) {
3538 -
3539 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3540 fault_address = regs->iaoq[0];
3541 fault_space = regs->iasq[0];
3542
3543 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3544 index 18162ce..94de376 100644
3545 --- a/arch/parisc/mm/fault.c
3546 +++ b/arch/parisc/mm/fault.c
3547 @@ -15,6 +15,7 @@
3548 #include <linux/sched.h>
3549 #include <linux/interrupt.h>
3550 #include <linux/module.h>
3551 +#include <linux/unistd.h>
3552
3553 #include <asm/uaccess.h>
3554 #include <asm/traps.h>
3555 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3556 static unsigned long
3557 parisc_acctyp(unsigned long code, unsigned int inst)
3558 {
3559 - if (code == 6 || code == 16)
3560 + if (code == 6 || code == 7 || code == 16)
3561 return VM_EXEC;
3562
3563 switch (inst & 0xf0000000) {
3564 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3565 }
3566 #endif
3567
3568 +#ifdef CONFIG_PAX_PAGEEXEC
3569 +/*
3570 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3571 + *
3572 + * returns 1 when task should be killed
3573 + * 2 when rt_sigreturn trampoline was detected
3574 + * 3 when unpatched PLT trampoline was detected
3575 + */
3576 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3577 +{
3578 +
3579 +#ifdef CONFIG_PAX_EMUPLT
3580 + int err;
3581 +
3582 + do { /* PaX: unpatched PLT emulation */
3583 + unsigned int bl, depwi;
3584 +
3585 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3586 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3587 +
3588 + if (err)
3589 + break;
3590 +
3591 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3592 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3593 +
3594 + err = get_user(ldw, (unsigned int *)addr);
3595 + err |= get_user(bv, (unsigned int *)(addr+4));
3596 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3597 +
3598 + if (err)
3599 + break;
3600 +
3601 + if (ldw == 0x0E801096U &&
3602 + bv == 0xEAC0C000U &&
3603 + ldw2 == 0x0E881095U)
3604 + {
3605 + unsigned int resolver, map;
3606 +
3607 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3608 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3609 + if (err)
3610 + break;
3611 +
3612 + regs->gr[20] = instruction_pointer(regs)+8;
3613 + regs->gr[21] = map;
3614 + regs->gr[22] = resolver;
3615 + regs->iaoq[0] = resolver | 3UL;
3616 + regs->iaoq[1] = regs->iaoq[0] + 4;
3617 + return 3;
3618 + }
3619 + }
3620 + } while (0);
3621 +#endif
3622 +
3623 +#ifdef CONFIG_PAX_EMUTRAMP
3624 +
3625 +#ifndef CONFIG_PAX_EMUSIGRT
3626 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3627 + return 1;
3628 +#endif
3629 +
3630 + do { /* PaX: rt_sigreturn emulation */
3631 + unsigned int ldi1, ldi2, bel, nop;
3632 +
3633 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3634 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3635 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3636 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3637 +
3638 + if (err)
3639 + break;
3640 +
3641 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3642 + ldi2 == 0x3414015AU &&
3643 + bel == 0xE4008200U &&
3644 + nop == 0x08000240U)
3645 + {
3646 + regs->gr[25] = (ldi1 & 2) >> 1;
3647 + regs->gr[20] = __NR_rt_sigreturn;
3648 + regs->gr[31] = regs->iaoq[1] + 16;
3649 + regs->sr[0] = regs->iasq[1];
3650 + regs->iaoq[0] = 0x100UL;
3651 + regs->iaoq[1] = regs->iaoq[0] + 4;
3652 + regs->iasq[0] = regs->sr[2];
3653 + regs->iasq[1] = regs->sr[2];
3654 + return 2;
3655 + }
3656 + } while (0);
3657 +#endif
3658 +
3659 + return 1;
3660 +}
3661 +
3662 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3663 +{
3664 + unsigned long i;
3665 +
3666 + printk(KERN_ERR "PAX: bytes at PC: ");
3667 + for (i = 0; i < 5; i++) {
3668 + unsigned int c;
3669 + if (get_user(c, (unsigned int *)pc+i))
3670 + printk(KERN_CONT "???????? ");
3671 + else
3672 + printk(KERN_CONT "%08x ", c);
3673 + }
3674 + printk("\n");
3675 +}
3676 +#endif
3677 +
3678 int fixup_exception(struct pt_regs *regs)
3679 {
3680 const struct exception_table_entry *fix;
3681 @@ -192,8 +303,33 @@ good_area:
3682
3683 acc_type = parisc_acctyp(code,regs->iir);
3684
3685 - if ((vma->vm_flags & acc_type) != acc_type)
3686 + if ((vma->vm_flags & acc_type) != acc_type) {
3687 +
3688 +#ifdef CONFIG_PAX_PAGEEXEC
3689 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3690 + (address & ~3UL) == instruction_pointer(regs))
3691 + {
3692 + up_read(&mm->mmap_sem);
3693 + switch (pax_handle_fetch_fault(regs)) {
3694 +
3695 +#ifdef CONFIG_PAX_EMUPLT
3696 + case 3:
3697 + return;
3698 +#endif
3699 +
3700 +#ifdef CONFIG_PAX_EMUTRAMP
3701 + case 2:
3702 + return;
3703 +#endif
3704 +
3705 + }
3706 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3707 + do_group_exit(SIGKILL);
3708 + }
3709 +#endif
3710 +
3711 goto bad_area;
3712 + }
3713
3714 /*
3715 * If for any reason at all we couldn't handle the fault, make
3716 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3717 index da29032..f76c24c 100644
3718 --- a/arch/powerpc/include/asm/atomic.h
3719 +++ b/arch/powerpc/include/asm/atomic.h
3720 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3721 return t1;
3722 }
3723
3724 +#define atomic64_read_unchecked(v) atomic64_read(v)
3725 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3726 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3727 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3728 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3729 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3730 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3731 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3732 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3733 +
3734 #endif /* __powerpc64__ */
3735
3736 #endif /* __KERNEL__ */
3737 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3738 index 9e495c9..b6878e5 100644
3739 --- a/arch/powerpc/include/asm/cache.h
3740 +++ b/arch/powerpc/include/asm/cache.h
3741 @@ -3,6 +3,7 @@
3742
3743 #ifdef __KERNEL__
3744
3745 +#include <linux/const.h>
3746
3747 /* bytes per L1 cache line */
3748 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3749 @@ -22,7 +23,7 @@
3750 #define L1_CACHE_SHIFT 7
3751 #endif
3752
3753 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3754 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3755
3756 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3757
3758 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3759 index 3bf9cca..e7457d0 100644
3760 --- a/arch/powerpc/include/asm/elf.h
3761 +++ b/arch/powerpc/include/asm/elf.h
3762 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3763 the loader. We need to make sure that it is out of the way of the program
3764 that it will "exec", and that there is sufficient room for the brk. */
3765
3766 -extern unsigned long randomize_et_dyn(unsigned long base);
3767 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3768 +#define ELF_ET_DYN_BASE (0x20000000)
3769 +
3770 +#ifdef CONFIG_PAX_ASLR
3771 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3772 +
3773 +#ifdef __powerpc64__
3774 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3775 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3776 +#else
3777 +#define PAX_DELTA_MMAP_LEN 15
3778 +#define PAX_DELTA_STACK_LEN 15
3779 +#endif
3780 +#endif
3781
3782 /*
3783 * Our registers are always unsigned longs, whether we're a 32 bit
3784 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3785 (0x7ff >> (PAGE_SHIFT - 12)) : \
3786 (0x3ffff >> (PAGE_SHIFT - 12)))
3787
3788 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3789 -#define arch_randomize_brk arch_randomize_brk
3790 -
3791 #endif /* __KERNEL__ */
3792
3793 /*
3794 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3795 index 8196e9c..d83a9f3 100644
3796 --- a/arch/powerpc/include/asm/exec.h
3797 +++ b/arch/powerpc/include/asm/exec.h
3798 @@ -4,6 +4,6 @@
3799 #ifndef _ASM_POWERPC_EXEC_H
3800 #define _ASM_POWERPC_EXEC_H
3801
3802 -extern unsigned long arch_align_stack(unsigned long sp);
3803 +#define arch_align_stack(x) ((x) & ~0xfUL)
3804
3805 #endif /* _ASM_POWERPC_EXEC_H */
3806 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3807 index 5acabbd..7ea14fa 100644
3808 --- a/arch/powerpc/include/asm/kmap_types.h
3809 +++ b/arch/powerpc/include/asm/kmap_types.h
3810 @@ -10,7 +10,7 @@
3811 * 2 of the License, or (at your option) any later version.
3812 */
3813
3814 -#define KM_TYPE_NR 16
3815 +#define KM_TYPE_NR 17
3816
3817 #endif /* __KERNEL__ */
3818 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3819 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3820 index d4a7f64..451de1c 100644
3821 --- a/arch/powerpc/include/asm/mman.h
3822 +++ b/arch/powerpc/include/asm/mman.h
3823 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3824 }
3825 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3826
3827 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3828 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3829 {
3830 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3831 }
3832 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3833 index f072e97..b436dee 100644
3834 --- a/arch/powerpc/include/asm/page.h
3835 +++ b/arch/powerpc/include/asm/page.h
3836 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3837 * and needs to be executable. This means the whole heap ends
3838 * up being executable.
3839 */
3840 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3841 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3842 +#define VM_DATA_DEFAULT_FLAGS32 \
3843 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3844 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3845
3846 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3847 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3848 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3849 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3850 #endif
3851
3852 +#define ktla_ktva(addr) (addr)
3853 +#define ktva_ktla(addr) (addr)
3854 +
3855 /*
3856 * Use the top bit of the higher-level page table entries to indicate whether
3857 * the entries we point to contain hugepages. This works because we know that
3858 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3859 index fed85e6..da5c71b 100644
3860 --- a/arch/powerpc/include/asm/page_64.h
3861 +++ b/arch/powerpc/include/asm/page_64.h
3862 @@ -146,15 +146,18 @@ do { \
3863 * stack by default, so in the absence of a PT_GNU_STACK program header
3864 * we turn execute permission off.
3865 */
3866 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3867 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3868 +#define VM_STACK_DEFAULT_FLAGS32 \
3869 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3870 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3871
3872 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3873 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3874
3875 +#ifndef CONFIG_PAX_PAGEEXEC
3876 #define VM_STACK_DEFAULT_FLAGS \
3877 (is_32bit_task() ? \
3878 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3879 +#endif
3880
3881 #include <asm-generic/getorder.h>
3882
3883 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3884 index 292725c..f87ae14 100644
3885 --- a/arch/powerpc/include/asm/pgalloc-64.h
3886 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3887 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3888 #ifndef CONFIG_PPC_64K_PAGES
3889
3890 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3891 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3892
3893 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3894 {
3895 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3896 pud_set(pud, (unsigned long)pmd);
3897 }
3898
3899 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3900 +{
3901 + pud_populate(mm, pud, pmd);
3902 +}
3903 +
3904 #define pmd_populate(mm, pmd, pte_page) \
3905 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3906 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3907 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3908 #else /* CONFIG_PPC_64K_PAGES */
3909
3910 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3911 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3912
3913 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3914 pte_t *pte)
3915 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3916 index 2e0e411..7899c68 100644
3917 --- a/arch/powerpc/include/asm/pgtable.h
3918 +++ b/arch/powerpc/include/asm/pgtable.h
3919 @@ -2,6 +2,7 @@
3920 #define _ASM_POWERPC_PGTABLE_H
3921 #ifdef __KERNEL__
3922
3923 +#include <linux/const.h>
3924 #ifndef __ASSEMBLY__
3925 #include <asm/processor.h> /* For TASK_SIZE */
3926 #include <asm/mmu.h>
3927 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3928 index 4aad413..85d86bf 100644
3929 --- a/arch/powerpc/include/asm/pte-hash32.h
3930 +++ b/arch/powerpc/include/asm/pte-hash32.h
3931 @@ -21,6 +21,7 @@
3932 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3933 #define _PAGE_USER 0x004 /* usermode access allowed */
3934 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3935 +#define _PAGE_EXEC _PAGE_GUARDED
3936 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3937 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3938 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3939 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3940 index 6386086..6982225 100644
3941 --- a/arch/powerpc/include/asm/reg.h
3942 +++ b/arch/powerpc/include/asm/reg.h
3943 @@ -212,6 +212,7 @@
3944 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3945 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3946 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3947 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3948 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3949 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3950 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3951 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3952 index faf9352..ab2ccec 100644
3953 --- a/arch/powerpc/include/asm/thread_info.h
3954 +++ b/arch/powerpc/include/asm/thread_info.h
3955 @@ -97,12 +97,14 @@ static inline struct thread_info *current_thread_info(void)
3956 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3957 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3958 #define TIF_SINGLESTEP 8 /* singlestepping active */
3959 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3960 #define TIF_SECCOMP 10 /* secure computing */
3961 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3962 #define TIF_NOERROR 12 /* Force successful syscall return */
3963 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3964 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3965 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3966 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3967 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3968
3969 /* as above, but as bit values */
3970 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3971 @@ -119,8 +121,10 @@ static inline struct thread_info *current_thread_info(void)
3972 #define _TIF_NOERROR (1<<TIF_NOERROR)
3973 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3974 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3975 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3976 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3977 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3978 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3979 + _TIF_GRSEC_SETXID)
3980
3981 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3982 _TIF_NOTIFY_RESUME)
3983 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3984 index 17bb40c..353c98b 100644
3985 --- a/arch/powerpc/include/asm/uaccess.h
3986 +++ b/arch/powerpc/include/asm/uaccess.h
3987 @@ -13,6 +13,8 @@
3988 #define VERIFY_READ 0
3989 #define VERIFY_WRITE 1
3990
3991 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3992 +
3993 /*
3994 * The fs value determines whether argument validity checking should be
3995 * performed or not. If get_fs() == USER_DS, checking is performed, with
3996 @@ -329,52 +331,6 @@ do { \
3997 extern unsigned long __copy_tofrom_user(void __user *to,
3998 const void __user *from, unsigned long size);
3999
4000 -#ifndef __powerpc64__
4001 -
4002 -static inline unsigned long copy_from_user(void *to,
4003 - const void __user *from, unsigned long n)
4004 -{
4005 - unsigned long over;
4006 -
4007 - if (access_ok(VERIFY_READ, from, n))
4008 - return __copy_tofrom_user((__force void __user *)to, from, n);
4009 - if ((unsigned long)from < TASK_SIZE) {
4010 - over = (unsigned long)from + n - TASK_SIZE;
4011 - return __copy_tofrom_user((__force void __user *)to, from,
4012 - n - over) + over;
4013 - }
4014 - return n;
4015 -}
4016 -
4017 -static inline unsigned long copy_to_user(void __user *to,
4018 - const void *from, unsigned long n)
4019 -{
4020 - unsigned long over;
4021 -
4022 - if (access_ok(VERIFY_WRITE, to, n))
4023 - return __copy_tofrom_user(to, (__force void __user *)from, n);
4024 - if ((unsigned long)to < TASK_SIZE) {
4025 - over = (unsigned long)to + n - TASK_SIZE;
4026 - return __copy_tofrom_user(to, (__force void __user *)from,
4027 - n - over) + over;
4028 - }
4029 - return n;
4030 -}
4031 -
4032 -#else /* __powerpc64__ */
4033 -
4034 -#define __copy_in_user(to, from, size) \
4035 - __copy_tofrom_user((to), (from), (size))
4036 -
4037 -extern unsigned long copy_from_user(void *to, const void __user *from,
4038 - unsigned long n);
4039 -extern unsigned long copy_to_user(void __user *to, const void *from,
4040 - unsigned long n);
4041 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4042 - unsigned long n);
4043 -
4044 -#endif /* __powerpc64__ */
4045 -
4046 static inline unsigned long __copy_from_user_inatomic(void *to,
4047 const void __user *from, unsigned long n)
4048 {
4049 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4050 if (ret == 0)
4051 return 0;
4052 }
4053 +
4054 + if (!__builtin_constant_p(n))
4055 + check_object_size(to, n, false);
4056 +
4057 return __copy_tofrom_user((__force void __user *)to, from, n);
4058 }
4059
4060 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4061 if (ret == 0)
4062 return 0;
4063 }
4064 +
4065 + if (!__builtin_constant_p(n))
4066 + check_object_size(from, n, true);
4067 +
4068 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4069 }
4070
4071 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4072 return __copy_to_user_inatomic(to, from, size);
4073 }
4074
4075 +#ifndef __powerpc64__
4076 +
4077 +static inline unsigned long __must_check copy_from_user(void *to,
4078 + const void __user *from, unsigned long n)
4079 +{
4080 + unsigned long over;
4081 +
4082 + if ((long)n < 0)
4083 + return n;
4084 +
4085 + if (access_ok(VERIFY_READ, from, n)) {
4086 + if (!__builtin_constant_p(n))
4087 + check_object_size(to, n, false);
4088 + return __copy_tofrom_user((__force void __user *)to, from, n);
4089 + }
4090 + if ((unsigned long)from < TASK_SIZE) {
4091 + over = (unsigned long)from + n - TASK_SIZE;
4092 + if (!__builtin_constant_p(n - over))
4093 + check_object_size(to, n - over, false);
4094 + return __copy_tofrom_user((__force void __user *)to, from,
4095 + n - over) + over;
4096 + }
4097 + return n;
4098 +}
4099 +
4100 +static inline unsigned long __must_check copy_to_user(void __user *to,
4101 + const void *from, unsigned long n)
4102 +{
4103 + unsigned long over;
4104 +
4105 + if ((long)n < 0)
4106 + return n;
4107 +
4108 + if (access_ok(VERIFY_WRITE, to, n)) {
4109 + if (!__builtin_constant_p(n))
4110 + check_object_size(from, n, true);
4111 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4112 + }
4113 + if ((unsigned long)to < TASK_SIZE) {
4114 + over = (unsigned long)to + n - TASK_SIZE;
4115 + if (!__builtin_constant_p(n))
4116 + check_object_size(from, n - over, true);
4117 + return __copy_tofrom_user(to, (__force void __user *)from,
4118 + n - over) + over;
4119 + }
4120 + return n;
4121 +}
4122 +
4123 +#else /* __powerpc64__ */
4124 +
4125 +#define __copy_in_user(to, from, size) \
4126 + __copy_tofrom_user((to), (from), (size))
4127 +
4128 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4129 +{
4130 + if ((long)n < 0 || n > INT_MAX)
4131 + return n;
4132 +
4133 + if (!__builtin_constant_p(n))
4134 + check_object_size(to, n, false);
4135 +
4136 + if (likely(access_ok(VERIFY_READ, from, n)))
4137 + n = __copy_from_user(to, from, n);
4138 + else
4139 + memset(to, 0, n);
4140 + return n;
4141 +}
4142 +
4143 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4144 +{
4145 + if ((long)n < 0 || n > INT_MAX)
4146 + return n;
4147 +
4148 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4149 + if (!__builtin_constant_p(n))
4150 + check_object_size(from, n, true);
4151 + n = __copy_to_user(to, from, n);
4152 + }
4153 + return n;
4154 +}
4155 +
4156 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4157 + unsigned long n);
4158 +
4159 +#endif /* __powerpc64__ */
4160 +
4161 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4162
4163 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4164 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4165 index 98be7f0..8ef62de 100644
4166 --- a/arch/powerpc/kernel/exceptions-64e.S
4167 +++ b/arch/powerpc/kernel/exceptions-64e.S
4168 @@ -661,6 +661,7 @@ storage_fault_common:
4169 std r14,_DAR(r1)
4170 std r15,_DSISR(r1)
4171 addi r3,r1,STACK_FRAME_OVERHEAD
4172 + bl .save_nvgprs
4173 mr r4,r14
4174 mr r5,r15
4175 ld r14,PACA_EXGEN+EX_R14(r13)
4176 @@ -669,8 +670,7 @@ storage_fault_common:
4177 cmpdi r3,0
4178 bne- 1f
4179 b .ret_from_except_lite
4180 -1: bl .save_nvgprs
4181 - mr r5,r3
4182 +1: mr r5,r3
4183 addi r3,r1,STACK_FRAME_OVERHEAD
4184 ld r4,_DAR(r1)
4185 bl .bad_page_fault
4186 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4187 index 39aa97d..dc916ee 100644
4188 --- a/arch/powerpc/kernel/exceptions-64s.S
4189 +++ b/arch/powerpc/kernel/exceptions-64s.S
4190 @@ -890,10 +890,10 @@ handle_page_fault:
4191 11: ld r4,_DAR(r1)
4192 ld r5,_DSISR(r1)
4193 addi r3,r1,STACK_FRAME_OVERHEAD
4194 + bl .save_nvgprs
4195 bl .do_page_fault
4196 cmpdi r3,0
4197 beq+ 12f
4198 - bl .save_nvgprs
4199 mr r5,r3
4200 addi r3,r1,STACK_FRAME_OVERHEAD
4201 lwz r4,_DAR(r1)
4202 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4203 index 2e3200c..72095ce 100644
4204 --- a/arch/powerpc/kernel/module_32.c
4205 +++ b/arch/powerpc/kernel/module_32.c
4206 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4207 me->arch.core_plt_section = i;
4208 }
4209 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4210 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4211 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4212 return -ENOEXEC;
4213 }
4214
4215 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4216
4217 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4218 /* Init, or core PLT? */
4219 - if (location >= mod->module_core
4220 - && location < mod->module_core + mod->core_size)
4221 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4222 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4223 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4224 - else
4225 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4226 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4227 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4228 + else {
4229 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4230 + return ~0UL;
4231 + }
4232
4233 /* Find this entry, or if that fails, the next avail. entry */
4234 while (entry->jump[0]) {
4235 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4236 index 1a1f2dd..f4d1bb4 100644
4237 --- a/arch/powerpc/kernel/process.c
4238 +++ b/arch/powerpc/kernel/process.c
4239 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4240 * Lookup NIP late so we have the best change of getting the
4241 * above info out without failing
4242 */
4243 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4244 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4245 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4246 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4247 #endif
4248 show_stack(current, (unsigned long *) regs->gpr[1]);
4249 if (!user_mode(regs))
4250 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4251 newsp = stack[0];
4252 ip = stack[STACK_FRAME_LR_SAVE];
4253 if (!firstframe || ip != lr) {
4254 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4255 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4256 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4257 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4258 - printk(" (%pS)",
4259 + printk(" (%pA)",
4260 (void *)current->ret_stack[curr_frame].ret);
4261 curr_frame--;
4262 }
4263 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4264 struct pt_regs *regs = (struct pt_regs *)
4265 (sp + STACK_FRAME_OVERHEAD);
4266 lr = regs->link;
4267 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4268 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4269 regs->trap, (void *)regs->nip, (void *)lr);
4270 firstframe = 1;
4271 }
4272 @@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4273 mtspr(SPRN_CTRLT, ctrl);
4274 }
4275 #endif /* CONFIG_PPC64 */
4276 -
4277 -unsigned long arch_align_stack(unsigned long sp)
4278 -{
4279 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4280 - sp -= get_random_int() & ~PAGE_MASK;
4281 - return sp & ~0xf;
4282 -}
4283 -
4284 -static inline unsigned long brk_rnd(void)
4285 -{
4286 - unsigned long rnd = 0;
4287 -
4288 - /* 8MB for 32bit, 1GB for 64bit */
4289 - if (is_32bit_task())
4290 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4291 - else
4292 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4293 -
4294 - return rnd << PAGE_SHIFT;
4295 -}
4296 -
4297 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4298 -{
4299 - unsigned long base = mm->brk;
4300 - unsigned long ret;
4301 -
4302 -#ifdef CONFIG_PPC_STD_MMU_64
4303 - /*
4304 - * If we are using 1TB segments and we are allowed to randomise
4305 - * the heap, we can put it above 1TB so it is backed by a 1TB
4306 - * segment. Otherwise the heap will be in the bottom 1TB
4307 - * which always uses 256MB segments and this may result in a
4308 - * performance penalty.
4309 - */
4310 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4311 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4312 -#endif
4313 -
4314 - ret = PAGE_ALIGN(base + brk_rnd());
4315 -
4316 - if (ret < mm->brk)
4317 - return mm->brk;
4318 -
4319 - return ret;
4320 -}
4321 -
4322 -unsigned long randomize_et_dyn(unsigned long base)
4323 -{
4324 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4325 -
4326 - if (ret < base)
4327 - return base;
4328 -
4329 - return ret;
4330 -}
4331 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4332 index c10fc28..c4ef063 100644
4333 --- a/arch/powerpc/kernel/ptrace.c
4334 +++ b/arch/powerpc/kernel/ptrace.c
4335 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4336 return ret;
4337 }
4338
4339 +#ifdef CONFIG_GRKERNSEC_SETXID
4340 +extern void gr_delayed_cred_worker(void);
4341 +#endif
4342 +
4343 /*
4344 * We must return the syscall number to actually look up in the table.
4345 * This can be -1L to skip running any syscall at all.
4346 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4347
4348 secure_computing_strict(regs->gpr[0]);
4349
4350 +#ifdef CONFIG_GRKERNSEC_SETXID
4351 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4352 + gr_delayed_cred_worker();
4353 +#endif
4354 +
4355 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4356 tracehook_report_syscall_entry(regs))
4357 /*
4358 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4359 {
4360 int step;
4361
4362 +#ifdef CONFIG_GRKERNSEC_SETXID
4363 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4364 + gr_delayed_cred_worker();
4365 +#endif
4366 +
4367 audit_syscall_exit(regs);
4368
4369 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4370 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4371 index 8b4c049..dcd6ef3 100644
4372 --- a/arch/powerpc/kernel/signal_32.c
4373 +++ b/arch/powerpc/kernel/signal_32.c
4374 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4375 /* Save user registers on the stack */
4376 frame = &rt_sf->uc.uc_mcontext;
4377 addr = frame;
4378 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4379 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4380 if (save_user_regs(regs, frame, 0, 1))
4381 goto badframe;
4382 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4383 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4384 index d183f87..1867f1a 100644
4385 --- a/arch/powerpc/kernel/signal_64.c
4386 +++ b/arch/powerpc/kernel/signal_64.c
4387 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4388 current->thread.fpscr.val = 0;
4389
4390 /* Set up to return from userspace. */
4391 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4392 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4393 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4394 } else {
4395 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4396 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4397 index ae0843f..f16372c 100644
4398 --- a/arch/powerpc/kernel/traps.c
4399 +++ b/arch/powerpc/kernel/traps.c
4400 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4401 return flags;
4402 }
4403
4404 +extern void gr_handle_kernel_exploit(void);
4405 +
4406 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4407 int signr)
4408 {
4409 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4410 panic("Fatal exception in interrupt");
4411 if (panic_on_oops)
4412 panic("Fatal exception");
4413 +
4414 + gr_handle_kernel_exploit();
4415 +
4416 do_exit(signr);
4417 }
4418
4419 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4420 index b67db22..38825d2 100644
4421 --- a/arch/powerpc/kernel/vdso.c
4422 +++ b/arch/powerpc/kernel/vdso.c
4423 @@ -34,6 +34,7 @@
4424 #include <asm/firmware.h>
4425 #include <asm/vdso.h>
4426 #include <asm/vdso_datapage.h>
4427 +#include <asm/mman.h>
4428
4429 #include "setup.h"
4430
4431 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4432 vdso_base = VDSO32_MBASE;
4433 #endif
4434
4435 - current->mm->context.vdso_base = 0;
4436 + current->mm->context.vdso_base = ~0UL;
4437
4438 /* vDSO has a problem and was disabled, just don't "enable" it for the
4439 * process
4440 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4441 vdso_base = get_unmapped_area(NULL, vdso_base,
4442 (vdso_pages << PAGE_SHIFT) +
4443 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4444 - 0, 0);
4445 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4446 if (IS_ERR_VALUE(vdso_base)) {
4447 rc = vdso_base;
4448 goto fail_mmapsem;
4449 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4450 index 5eea6f3..5d10396 100644
4451 --- a/arch/powerpc/lib/usercopy_64.c
4452 +++ b/arch/powerpc/lib/usercopy_64.c
4453 @@ -9,22 +9,6 @@
4454 #include <linux/module.h>
4455 #include <asm/uaccess.h>
4456
4457 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4458 -{
4459 - if (likely(access_ok(VERIFY_READ, from, n)))
4460 - n = __copy_from_user(to, from, n);
4461 - else
4462 - memset(to, 0, n);
4463 - return n;
4464 -}
4465 -
4466 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4467 -{
4468 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4469 - n = __copy_to_user(to, from, n);
4470 - return n;
4471 -}
4472 -
4473 unsigned long copy_in_user(void __user *to, const void __user *from,
4474 unsigned long n)
4475 {
4476 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4477 return n;
4478 }
4479
4480 -EXPORT_SYMBOL(copy_from_user);
4481 -EXPORT_SYMBOL(copy_to_user);
4482 EXPORT_SYMBOL(copy_in_user);
4483
4484 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4485 index 08ffcf5..a0ab912 100644
4486 --- a/arch/powerpc/mm/fault.c
4487 +++ b/arch/powerpc/mm/fault.c
4488 @@ -32,6 +32,10 @@
4489 #include <linux/perf_event.h>
4490 #include <linux/magic.h>
4491 #include <linux/ratelimit.h>
4492 +#include <linux/slab.h>
4493 +#include <linux/pagemap.h>
4494 +#include <linux/compiler.h>
4495 +#include <linux/unistd.h>
4496
4497 #include <asm/firmware.h>
4498 #include <asm/page.h>
4499 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4500 }
4501 #endif
4502
4503 +#ifdef CONFIG_PAX_PAGEEXEC
4504 +/*
4505 + * PaX: decide what to do with offenders (regs->nip = fault address)
4506 + *
4507 + * returns 1 when task should be killed
4508 + */
4509 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4510 +{
4511 + return 1;
4512 +}
4513 +
4514 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4515 +{
4516 + unsigned long i;
4517 +
4518 + printk(KERN_ERR "PAX: bytes at PC: ");
4519 + for (i = 0; i < 5; i++) {
4520 + unsigned int c;
4521 + if (get_user(c, (unsigned int __user *)pc+i))
4522 + printk(KERN_CONT "???????? ");
4523 + else
4524 + printk(KERN_CONT "%08x ", c);
4525 + }
4526 + printk("\n");
4527 +}
4528 +#endif
4529 +
4530 /*
4531 * Check whether the instruction at regs->nip is a store using
4532 * an update addressing form which will update r1.
4533 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4534 * indicate errors in DSISR but can validly be set in SRR1.
4535 */
4536 if (trap == 0x400)
4537 - error_code &= 0x48200000;
4538 + error_code &= 0x58200000;
4539 else
4540 is_write = error_code & DSISR_ISSTORE;
4541 #else
4542 @@ -366,7 +397,7 @@ good_area:
4543 * "undefined". Of those that can be set, this is the only
4544 * one which seems bad.
4545 */
4546 - if (error_code & 0x10000000)
4547 + if (error_code & DSISR_GUARDED)
4548 /* Guarded storage error. */
4549 goto bad_area;
4550 #endif /* CONFIG_8xx */
4551 @@ -381,7 +412,7 @@ good_area:
4552 * processors use the same I/D cache coherency mechanism
4553 * as embedded.
4554 */
4555 - if (error_code & DSISR_PROTFAULT)
4556 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4557 goto bad_area;
4558 #endif /* CONFIG_PPC_STD_MMU */
4559
4560 @@ -463,6 +494,23 @@ bad_area:
4561 bad_area_nosemaphore:
4562 /* User mode accesses cause a SIGSEGV */
4563 if (user_mode(regs)) {
4564 +
4565 +#ifdef CONFIG_PAX_PAGEEXEC
4566 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4567 +#ifdef CONFIG_PPC_STD_MMU
4568 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4569 +#else
4570 + if (is_exec && regs->nip == address) {
4571 +#endif
4572 + switch (pax_handle_fetch_fault(regs)) {
4573 + }
4574 +
4575 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4576 + do_group_exit(SIGKILL);
4577 + }
4578 + }
4579 +#endif
4580 +
4581 _exception(SIGSEGV, regs, code, address);
4582 return 0;
4583 }
4584 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4585 index 67a42ed..1c7210c 100644
4586 --- a/arch/powerpc/mm/mmap_64.c
4587 +++ b/arch/powerpc/mm/mmap_64.c
4588 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4589 */
4590 if (mmap_is_legacy()) {
4591 mm->mmap_base = TASK_UNMAPPED_BASE;
4592 +
4593 +#ifdef CONFIG_PAX_RANDMMAP
4594 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4595 + mm->mmap_base += mm->delta_mmap;
4596 +#endif
4597 +
4598 mm->get_unmapped_area = arch_get_unmapped_area;
4599 mm->unmap_area = arch_unmap_area;
4600 } else {
4601 mm->mmap_base = mmap_base();
4602 +
4603 +#ifdef CONFIG_PAX_RANDMMAP
4604 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4605 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4606 +#endif
4607 +
4608 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4609 mm->unmap_area = arch_unmap_area_topdown;
4610 }
4611 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4612 index 73709f7..6b90313 100644
4613 --- a/arch/powerpc/mm/slice.c
4614 +++ b/arch/powerpc/mm/slice.c
4615 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4616 if ((mm->task_size - len) < addr)
4617 return 0;
4618 vma = find_vma(mm, addr);
4619 - return (!vma || (addr + len) <= vma->vm_start);
4620 + return check_heap_stack_gap(vma, addr, len);
4621 }
4622
4623 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4624 @@ -256,7 +256,7 @@ full_search:
4625 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4626 continue;
4627 }
4628 - if (!vma || addr + len <= vma->vm_start) {
4629 + if (check_heap_stack_gap(vma, addr, len)) {
4630 /*
4631 * Remember the place where we stopped the search:
4632 */
4633 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4634 }
4635 }
4636
4637 - addr = mm->mmap_base;
4638 - while (addr > len) {
4639 + if (mm->mmap_base < len)
4640 + addr = -ENOMEM;
4641 + else
4642 + addr = mm->mmap_base - len;
4643 +
4644 + while (!IS_ERR_VALUE(addr)) {
4645 /* Go down by chunk size */
4646 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4647 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4648
4649 /* Check for hit with different page size */
4650 mask = slice_range_to_mask(addr, len);
4651 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4652 * return with success:
4653 */
4654 vma = find_vma(mm, addr);
4655 - if (!vma || (addr + len) <= vma->vm_start) {
4656 + if (check_heap_stack_gap(vma, addr, len)) {
4657 /* remember the address as a hint for next time */
4658 if (use_cache)
4659 mm->free_area_cache = addr;
4660 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4661 mm->cached_hole_size = vma->vm_start - addr;
4662
4663 /* try just below the current vma->vm_start */
4664 - addr = vma->vm_start;
4665 + addr = skip_heap_stack_gap(vma, len);
4666 }
4667
4668 /*
4669 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4670 if (fixed && addr > (mm->task_size - len))
4671 return -EINVAL;
4672
4673 +#ifdef CONFIG_PAX_RANDMMAP
4674 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4675 + addr = 0;
4676 +#endif
4677 +
4678 /* If hint, make sure it matches our alignment restrictions */
4679 if (!fixed && addr) {
4680 addr = _ALIGN_UP(addr, 1ul << pshift);
4681 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4682 index c797832..ce575c8 100644
4683 --- a/arch/s390/include/asm/atomic.h
4684 +++ b/arch/s390/include/asm/atomic.h
4685 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4686 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4687 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4688
4689 +#define atomic64_read_unchecked(v) atomic64_read(v)
4690 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4691 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4692 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4693 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4694 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4695 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4696 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4697 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4698 +
4699 #define smp_mb__before_atomic_dec() smp_mb()
4700 #define smp_mb__after_atomic_dec() smp_mb()
4701 #define smp_mb__before_atomic_inc() smp_mb()
4702 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4703 index 4d7ccac..d03d0ad 100644
4704 --- a/arch/s390/include/asm/cache.h
4705 +++ b/arch/s390/include/asm/cache.h
4706 @@ -9,8 +9,10 @@
4707 #ifndef __ARCH_S390_CACHE_H
4708 #define __ARCH_S390_CACHE_H
4709
4710 -#define L1_CACHE_BYTES 256
4711 +#include <linux/const.h>
4712 +
4713 #define L1_CACHE_SHIFT 8
4714 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4715 #define NET_SKB_PAD 32
4716
4717 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4718 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4719 index 9b94a16..63d4034 100644
4720 --- a/arch/s390/include/asm/elf.h
4721 +++ b/arch/s390/include/asm/elf.h
4722 @@ -159,8 +159,14 @@ extern unsigned int vdso_enabled;
4723 the loader. We need to make sure that it is out of the way of the program
4724 that it will "exec", and that there is sufficient room for the brk. */
4725
4726 -extern unsigned long randomize_et_dyn(unsigned long base);
4727 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4728 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4729 +
4730 +#ifdef CONFIG_PAX_ASLR
4731 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4732 +
4733 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4734 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4735 +#endif
4736
4737 /* This yields a mask that user programs can use to figure out what
4738 instruction set this CPU supports. */
4739 @@ -209,7 +215,4 @@ struct linux_binprm;
4740 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4741 int arch_setup_additional_pages(struct linux_binprm *, int);
4742
4743 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4744 -#define arch_randomize_brk arch_randomize_brk
4745 -
4746 #endif
4747 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4748 index c4a93d6..4d2a9b4 100644
4749 --- a/arch/s390/include/asm/exec.h
4750 +++ b/arch/s390/include/asm/exec.h
4751 @@ -7,6 +7,6 @@
4752 #ifndef __ASM_EXEC_H
4753 #define __ASM_EXEC_H
4754
4755 -extern unsigned long arch_align_stack(unsigned long sp);
4756 +#define arch_align_stack(x) ((x) & ~0xfUL)
4757
4758 #endif /* __ASM_EXEC_H */
4759 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4760 index a8ab18b..75ddbf0 100644
4761 --- a/arch/s390/include/asm/uaccess.h
4762 +++ b/arch/s390/include/asm/uaccess.h
4763 @@ -239,6 +239,10 @@ static inline unsigned long __must_check
4764 copy_to_user(void __user *to, const void *from, unsigned long n)
4765 {
4766 might_fault();
4767 +
4768 + if ((long)n < 0)
4769 + return n;
4770 +
4771 if (access_ok(VERIFY_WRITE, to, n))
4772 n = __copy_to_user(to, from, n);
4773 return n;
4774 @@ -264,6 +268,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4775 static inline unsigned long __must_check
4776 __copy_from_user(void *to, const void __user *from, unsigned long n)
4777 {
4778 + if ((long)n < 0)
4779 + return n;
4780 +
4781 if (__builtin_constant_p(n) && (n <= 256))
4782 return uaccess.copy_from_user_small(n, from, to);
4783 else
4784 @@ -295,10 +302,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4785 static inline unsigned long __must_check
4786 copy_from_user(void *to, const void __user *from, unsigned long n)
4787 {
4788 - unsigned int sz = __compiletime_object_size(to);
4789 + size_t sz = __compiletime_object_size(to);
4790
4791 might_fault();
4792 - if (unlikely(sz != -1 && sz < n)) {
4793 +
4794 + if ((long)n < 0)
4795 + return n;
4796 +
4797 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4798 copy_from_user_overflow();
4799 return n;
4800 }
4801 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4802 index 46412b1..e32874f 100644
4803 --- a/arch/s390/kernel/module.c
4804 +++ b/arch/s390/kernel/module.c
4805 @@ -160,11 +160,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4806
4807 /* Increase core size by size of got & plt and set start
4808 offsets for got and plt. */
4809 - me->core_size = ALIGN(me->core_size, 4);
4810 - me->arch.got_offset = me->core_size;
4811 - me->core_size += me->arch.got_size;
4812 - me->arch.plt_offset = me->core_size;
4813 - me->core_size += me->arch.plt_size;
4814 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4815 + me->arch.got_offset = me->core_size_rw;
4816 + me->core_size_rw += me->arch.got_size;
4817 + me->arch.plt_offset = me->core_size_rx;
4818 + me->core_size_rx += me->arch.plt_size;
4819 return 0;
4820 }
4821
4822 @@ -241,7 +241,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4823 if (info->got_initialized == 0) {
4824 Elf_Addr *gotent;
4825
4826 - gotent = me->module_core + me->arch.got_offset +
4827 + gotent = me->module_core_rw + me->arch.got_offset +
4828 info->got_offset;
4829 *gotent = val;
4830 info->got_initialized = 1;
4831 @@ -265,7 +265,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4832 else if (r_type == R_390_GOTENT ||
4833 r_type == R_390_GOTPLTENT)
4834 *(unsigned int *) loc =
4835 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4836 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4837 else if (r_type == R_390_GOT64 ||
4838 r_type == R_390_GOTPLT64)
4839 *(unsigned long *) loc = val;
4840 @@ -279,7 +279,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4841 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4842 if (info->plt_initialized == 0) {
4843 unsigned int *ip;
4844 - ip = me->module_core + me->arch.plt_offset +
4845 + ip = me->module_core_rx + me->arch.plt_offset +
4846 info->plt_offset;
4847 #ifndef CONFIG_64BIT
4848 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4849 @@ -304,7 +304,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4850 val - loc + 0xffffUL < 0x1ffffeUL) ||
4851 (r_type == R_390_PLT32DBL &&
4852 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4853 - val = (Elf_Addr) me->module_core +
4854 + val = (Elf_Addr) me->module_core_rx +
4855 me->arch.plt_offset +
4856 info->plt_offset;
4857 val += rela->r_addend - loc;
4858 @@ -326,7 +326,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4859 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4860 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4861 val = val + rela->r_addend -
4862 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4863 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4864 if (r_type == R_390_GOTOFF16)
4865 *(unsigned short *) loc = val;
4866 else if (r_type == R_390_GOTOFF32)
4867 @@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4868 break;
4869 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4870 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4871 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4872 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4873 rela->r_addend - loc;
4874 if (r_type == R_390_GOTPC)
4875 *(unsigned int *) loc = val;
4876 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4877 index 7331753..dd71de4 100644
4878 --- a/arch/s390/kernel/process.c
4879 +++ b/arch/s390/kernel/process.c
4880 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4881 }
4882 return 0;
4883 }
4884 -
4885 -unsigned long arch_align_stack(unsigned long sp)
4886 -{
4887 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4888 - sp -= get_random_int() & ~PAGE_MASK;
4889 - return sp & ~0xf;
4890 -}
4891 -
4892 -static inline unsigned long brk_rnd(void)
4893 -{
4894 - /* 8MB for 32bit, 1GB for 64bit */
4895 - if (is_32bit_task())
4896 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4897 - else
4898 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4899 -}
4900 -
4901 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4902 -{
4903 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4904 -
4905 - if (ret < mm->brk)
4906 - return mm->brk;
4907 - return ret;
4908 -}
4909 -
4910 -unsigned long randomize_et_dyn(unsigned long base)
4911 -{
4912 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4913 -
4914 - if (!(current->flags & PF_RANDOMIZE))
4915 - return base;
4916 - if (ret < base)
4917 - return base;
4918 - return ret;
4919 -}
4920 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4921 index c59a5ef..3fae59c 100644
4922 --- a/arch/s390/mm/mmap.c
4923 +++ b/arch/s390/mm/mmap.c
4924 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4925 */
4926 if (mmap_is_legacy()) {
4927 mm->mmap_base = TASK_UNMAPPED_BASE;
4928 +
4929 +#ifdef CONFIG_PAX_RANDMMAP
4930 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4931 + mm->mmap_base += mm->delta_mmap;
4932 +#endif
4933 +
4934 mm->get_unmapped_area = arch_get_unmapped_area;
4935 mm->unmap_area = arch_unmap_area;
4936 } else {
4937 mm->mmap_base = mmap_base();
4938 +
4939 +#ifdef CONFIG_PAX_RANDMMAP
4940 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4941 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4942 +#endif
4943 +
4944 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4945 mm->unmap_area = arch_unmap_area_topdown;
4946 }
4947 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4948 */
4949 if (mmap_is_legacy()) {
4950 mm->mmap_base = TASK_UNMAPPED_BASE;
4951 +
4952 +#ifdef CONFIG_PAX_RANDMMAP
4953 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4954 + mm->mmap_base += mm->delta_mmap;
4955 +#endif
4956 +
4957 mm->get_unmapped_area = s390_get_unmapped_area;
4958 mm->unmap_area = arch_unmap_area;
4959 } else {
4960 mm->mmap_base = mmap_base();
4961 +
4962 +#ifdef CONFIG_PAX_RANDMMAP
4963 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4964 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4965 +#endif
4966 +
4967 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4968 mm->unmap_area = arch_unmap_area_topdown;
4969 }
4970 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4971 index ae3d59f..f65f075 100644
4972 --- a/arch/score/include/asm/cache.h
4973 +++ b/arch/score/include/asm/cache.h
4974 @@ -1,7 +1,9 @@
4975 #ifndef _ASM_SCORE_CACHE_H
4976 #define _ASM_SCORE_CACHE_H
4977
4978 +#include <linux/const.h>
4979 +
4980 #define L1_CACHE_SHIFT 4
4981 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4982 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4983
4984 #endif /* _ASM_SCORE_CACHE_H */
4985 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4986 index f9f3cd5..58ff438 100644
4987 --- a/arch/score/include/asm/exec.h
4988 +++ b/arch/score/include/asm/exec.h
4989 @@ -1,6 +1,6 @@
4990 #ifndef _ASM_SCORE_EXEC_H
4991 #define _ASM_SCORE_EXEC_H
4992
4993 -extern unsigned long arch_align_stack(unsigned long sp);
4994 +#define arch_align_stack(x) (x)
4995
4996 #endif /* _ASM_SCORE_EXEC_H */
4997 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4998 index 637970c..0b6556b 100644
4999 --- a/arch/score/kernel/process.c
5000 +++ b/arch/score/kernel/process.c
5001 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
5002
5003 return task_pt_regs(task)->cp0_epc;
5004 }
5005 -
5006 -unsigned long arch_align_stack(unsigned long sp)
5007 -{
5008 - return sp;
5009 -}
5010 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5011 index ef9e555..331bd29 100644
5012 --- a/arch/sh/include/asm/cache.h
5013 +++ b/arch/sh/include/asm/cache.h
5014 @@ -9,10 +9,11 @@
5015 #define __ASM_SH_CACHE_H
5016 #ifdef __KERNEL__
5017
5018 +#include <linux/const.h>
5019 #include <linux/init.h>
5020 #include <cpu/cache.h>
5021
5022 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5023 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5024
5025 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5026
5027 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5028 index afeb710..d1d1289 100644
5029 --- a/arch/sh/mm/mmap.c
5030 +++ b/arch/sh/mm/mmap.c
5031 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5032 addr = PAGE_ALIGN(addr);
5033
5034 vma = find_vma(mm, addr);
5035 - if (TASK_SIZE - len >= addr &&
5036 - (!vma || addr + len <= vma->vm_start))
5037 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5038 return addr;
5039 }
5040
5041 @@ -106,7 +105,7 @@ full_search:
5042 }
5043 return -ENOMEM;
5044 }
5045 - if (likely(!vma || addr + len <= vma->vm_start)) {
5046 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5047 /*
5048 * Remember the place where we stopped the search:
5049 */
5050 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5051 addr = PAGE_ALIGN(addr);
5052
5053 vma = find_vma(mm, addr);
5054 - if (TASK_SIZE - len >= addr &&
5055 - (!vma || addr + len <= vma->vm_start))
5056 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5057 return addr;
5058 }
5059
5060 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5061 /* make sure it can fit in the remaining address space */
5062 if (likely(addr > len)) {
5063 vma = find_vma(mm, addr-len);
5064 - if (!vma || addr <= vma->vm_start) {
5065 + if (check_heap_stack_gap(vma, addr - len, len)) {
5066 /* remember the address as a hint for next time */
5067 return (mm->free_area_cache = addr-len);
5068 }
5069 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5070 if (unlikely(mm->mmap_base < len))
5071 goto bottomup;
5072
5073 - addr = mm->mmap_base-len;
5074 - if (do_colour_align)
5075 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5076 + addr = mm->mmap_base - len;
5077
5078 do {
5079 + if (do_colour_align)
5080 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5081 /*
5082 * Lookup failure means no vma is above this address,
5083 * else if new region fits below vma->vm_start,
5084 * return with success:
5085 */
5086 vma = find_vma(mm, addr);
5087 - if (likely(!vma || addr+len <= vma->vm_start)) {
5088 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5089 /* remember the address as a hint for next time */
5090 return (mm->free_area_cache = addr);
5091 }
5092 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5093 mm->cached_hole_size = vma->vm_start - addr;
5094
5095 /* try just below the current vma->vm_start */
5096 - addr = vma->vm_start-len;
5097 - if (do_colour_align)
5098 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5099 - } while (likely(len < vma->vm_start));
5100 + addr = skip_heap_stack_gap(vma, len);
5101 + } while (!IS_ERR_VALUE(addr));
5102
5103 bottomup:
5104 /*
5105 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5106 index ce35a1c..2e7b8f9 100644
5107 --- a/arch/sparc/include/asm/atomic_64.h
5108 +++ b/arch/sparc/include/asm/atomic_64.h
5109 @@ -14,18 +14,40 @@
5110 #define ATOMIC64_INIT(i) { (i) }
5111
5112 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5113 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5114 +{
5115 + return v->counter;
5116 +}
5117 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5118 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5119 +{
5120 + return v->counter;
5121 +}
5122
5123 #define atomic_set(v, i) (((v)->counter) = i)
5124 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5125 +{
5126 + v->counter = i;
5127 +}
5128 #define atomic64_set(v, i) (((v)->counter) = i)
5129 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5130 +{
5131 + v->counter = i;
5132 +}
5133
5134 extern void atomic_add(int, atomic_t *);
5135 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5136 extern void atomic64_add(long, atomic64_t *);
5137 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5138 extern void atomic_sub(int, atomic_t *);
5139 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5140 extern void atomic64_sub(long, atomic64_t *);
5141 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5142
5143 extern int atomic_add_ret(int, atomic_t *);
5144 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5145 extern long atomic64_add_ret(long, atomic64_t *);
5146 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5147 extern int atomic_sub_ret(int, atomic_t *);
5148 extern long atomic64_sub_ret(long, atomic64_t *);
5149
5150 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5151 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5152
5153 #define atomic_inc_return(v) atomic_add_ret(1, v)
5154 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5155 +{
5156 + return atomic_add_ret_unchecked(1, v);
5157 +}
5158 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5159 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5160 +{
5161 + return atomic64_add_ret_unchecked(1, v);
5162 +}
5163
5164 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5165 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5166
5167 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5168 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5169 +{
5170 + return atomic_add_ret_unchecked(i, v);
5171 +}
5172 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5173 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5174 +{
5175 + return atomic64_add_ret_unchecked(i, v);
5176 +}
5177
5178 /*
5179 * atomic_inc_and_test - increment and test
5180 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5181 * other cases.
5182 */
5183 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5184 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5185 +{
5186 + return atomic_inc_return_unchecked(v) == 0;
5187 +}
5188 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5189
5190 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5191 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5192 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5193
5194 #define atomic_inc(v) atomic_add(1, v)
5195 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5196 +{
5197 + atomic_add_unchecked(1, v);
5198 +}
5199 #define atomic64_inc(v) atomic64_add(1, v)
5200 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5201 +{
5202 + atomic64_add_unchecked(1, v);
5203 +}
5204
5205 #define atomic_dec(v) atomic_sub(1, v)
5206 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5207 +{
5208 + atomic_sub_unchecked(1, v);
5209 +}
5210 #define atomic64_dec(v) atomic64_sub(1, v)
5211 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5212 +{
5213 + atomic64_sub_unchecked(1, v);
5214 +}
5215
5216 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5217 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5218
5219 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5220 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5221 +{
5222 + return cmpxchg(&v->counter, old, new);
5223 +}
5224 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5225 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5226 +{
5227 + return xchg(&v->counter, new);
5228 +}
5229
5230 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5231 {
5232 - int c, old;
5233 + int c, old, new;
5234 c = atomic_read(v);
5235 for (;;) {
5236 - if (unlikely(c == (u)))
5237 + if (unlikely(c == u))
5238 break;
5239 - old = atomic_cmpxchg((v), c, c + (a));
5240 +
5241 + asm volatile("addcc %2, %0, %0\n"
5242 +
5243 +#ifdef CONFIG_PAX_REFCOUNT
5244 + "tvs %%icc, 6\n"
5245 +#endif
5246 +
5247 + : "=r" (new)
5248 + : "0" (c), "ir" (a)
5249 + : "cc");
5250 +
5251 + old = atomic_cmpxchg(v, c, new);
5252 if (likely(old == c))
5253 break;
5254 c = old;
5255 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5256 #define atomic64_cmpxchg(v, o, n) \
5257 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5258 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5259 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5260 +{
5261 + return xchg(&v->counter, new);
5262 +}
5263
5264 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5265 {
5266 - long c, old;
5267 + long c, old, new;
5268 c = atomic64_read(v);
5269 for (;;) {
5270 - if (unlikely(c == (u)))
5271 + if (unlikely(c == u))
5272 break;
5273 - old = atomic64_cmpxchg((v), c, c + (a));
5274 +
5275 + asm volatile("addcc %2, %0, %0\n"
5276 +
5277 +#ifdef CONFIG_PAX_REFCOUNT
5278 + "tvs %%xcc, 6\n"
5279 +#endif
5280 +
5281 + : "=r" (new)
5282 + : "0" (c), "ir" (a)
5283 + : "cc");
5284 +
5285 + old = atomic64_cmpxchg(v, c, new);
5286 if (likely(old == c))
5287 break;
5288 c = old;
5289 }
5290 - return c != (u);
5291 + return c != u;
5292 }
5293
5294 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5295 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5296 index 5bb6991..5c2132e 100644
5297 --- a/arch/sparc/include/asm/cache.h
5298 +++ b/arch/sparc/include/asm/cache.h
5299 @@ -7,10 +7,12 @@
5300 #ifndef _SPARC_CACHE_H
5301 #define _SPARC_CACHE_H
5302
5303 +#include <linux/const.h>
5304 +
5305 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5306
5307 #define L1_CACHE_SHIFT 5
5308 -#define L1_CACHE_BYTES 32
5309 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5310
5311 #ifdef CONFIG_SPARC32
5312 #define SMP_CACHE_BYTES_SHIFT 5
5313 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5314 index 2d4d755..81b6662 100644
5315 --- a/arch/sparc/include/asm/elf_32.h
5316 +++ b/arch/sparc/include/asm/elf_32.h
5317 @@ -114,6 +114,13 @@ typedef struct {
5318
5319 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5320
5321 +#ifdef CONFIG_PAX_ASLR
5322 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5323 +
5324 +#define PAX_DELTA_MMAP_LEN 16
5325 +#define PAX_DELTA_STACK_LEN 16
5326 +#endif
5327 +
5328 /* This yields a mask that user programs can use to figure out what
5329 instruction set this cpu supports. This can NOT be done in userspace
5330 on Sparc. */
5331 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5332 index 7df8b7f..4946269 100644
5333 --- a/arch/sparc/include/asm/elf_64.h
5334 +++ b/arch/sparc/include/asm/elf_64.h
5335 @@ -180,6 +180,13 @@ typedef struct {
5336 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5337 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5338
5339 +#ifdef CONFIG_PAX_ASLR
5340 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5341 +
5342 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5343 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5344 +#endif
5345 +
5346 extern unsigned long sparc64_elf_hwcap;
5347 #define ELF_HWCAP sparc64_elf_hwcap
5348
5349 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5350 index 9b1c36d..209298b 100644
5351 --- a/arch/sparc/include/asm/pgalloc_32.h
5352 +++ b/arch/sparc/include/asm/pgalloc_32.h
5353 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5354 }
5355
5356 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5357 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5358
5359 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5360 unsigned long address)
5361 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5362 index 40b2d7a..22a665b 100644
5363 --- a/arch/sparc/include/asm/pgalloc_64.h
5364 +++ b/arch/sparc/include/asm/pgalloc_64.h
5365 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5366 }
5367
5368 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5369 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5370
5371 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5372 {
5373 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5374 index 6fc1348..390c50a 100644
5375 --- a/arch/sparc/include/asm/pgtable_32.h
5376 +++ b/arch/sparc/include/asm/pgtable_32.h
5377 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5378 #define PAGE_SHARED SRMMU_PAGE_SHARED
5379 #define PAGE_COPY SRMMU_PAGE_COPY
5380 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5381 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5382 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5383 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5384 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5385
5386 /* Top-level page directory - dummy used by init-mm.
5387 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5388
5389 /* xwr */
5390 #define __P000 PAGE_NONE
5391 -#define __P001 PAGE_READONLY
5392 -#define __P010 PAGE_COPY
5393 -#define __P011 PAGE_COPY
5394 +#define __P001 PAGE_READONLY_NOEXEC
5395 +#define __P010 PAGE_COPY_NOEXEC
5396 +#define __P011 PAGE_COPY_NOEXEC
5397 #define __P100 PAGE_READONLY
5398 #define __P101 PAGE_READONLY
5399 #define __P110 PAGE_COPY
5400 #define __P111 PAGE_COPY
5401
5402 #define __S000 PAGE_NONE
5403 -#define __S001 PAGE_READONLY
5404 -#define __S010 PAGE_SHARED
5405 -#define __S011 PAGE_SHARED
5406 +#define __S001 PAGE_READONLY_NOEXEC
5407 +#define __S010 PAGE_SHARED_NOEXEC
5408 +#define __S011 PAGE_SHARED_NOEXEC
5409 #define __S100 PAGE_READONLY
5410 #define __S101 PAGE_READONLY
5411 #define __S110 PAGE_SHARED
5412 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5413 index 79da178..c2eede8 100644
5414 --- a/arch/sparc/include/asm/pgtsrmmu.h
5415 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5416 @@ -115,6 +115,11 @@
5417 SRMMU_EXEC | SRMMU_REF)
5418 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5419 SRMMU_EXEC | SRMMU_REF)
5420 +
5421 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5422 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5423 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5424 +
5425 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5426 SRMMU_DIRTY | SRMMU_REF)
5427
5428 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5429 index 9689176..63c18ea 100644
5430 --- a/arch/sparc/include/asm/spinlock_64.h
5431 +++ b/arch/sparc/include/asm/spinlock_64.h
5432 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5433
5434 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5435
5436 -static void inline arch_read_lock(arch_rwlock_t *lock)
5437 +static inline void arch_read_lock(arch_rwlock_t *lock)
5438 {
5439 unsigned long tmp1, tmp2;
5440
5441 __asm__ __volatile__ (
5442 "1: ldsw [%2], %0\n"
5443 " brlz,pn %0, 2f\n"
5444 -"4: add %0, 1, %1\n"
5445 +"4: addcc %0, 1, %1\n"
5446 +
5447 +#ifdef CONFIG_PAX_REFCOUNT
5448 +" tvs %%icc, 6\n"
5449 +#endif
5450 +
5451 " cas [%2], %0, %1\n"
5452 " cmp %0, %1\n"
5453 " bne,pn %%icc, 1b\n"
5454 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5455 " .previous"
5456 : "=&r" (tmp1), "=&r" (tmp2)
5457 : "r" (lock)
5458 - : "memory");
5459 + : "memory", "cc");
5460 }
5461
5462 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5463 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5464 {
5465 int tmp1, tmp2;
5466
5467 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5468 "1: ldsw [%2], %0\n"
5469 " brlz,a,pn %0, 2f\n"
5470 " mov 0, %0\n"
5471 -" add %0, 1, %1\n"
5472 +" addcc %0, 1, %1\n"
5473 +
5474 +#ifdef CONFIG_PAX_REFCOUNT
5475 +" tvs %%icc, 6\n"
5476 +#endif
5477 +
5478 " cas [%2], %0, %1\n"
5479 " cmp %0, %1\n"
5480 " bne,pn %%icc, 1b\n"
5481 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5482 return tmp1;
5483 }
5484
5485 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5486 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5487 {
5488 unsigned long tmp1, tmp2;
5489
5490 __asm__ __volatile__(
5491 "1: lduw [%2], %0\n"
5492 -" sub %0, 1, %1\n"
5493 +" subcc %0, 1, %1\n"
5494 +
5495 +#ifdef CONFIG_PAX_REFCOUNT
5496 +" tvs %%icc, 6\n"
5497 +#endif
5498 +
5499 " cas [%2], %0, %1\n"
5500 " cmp %0, %1\n"
5501 " bne,pn %%xcc, 1b\n"
5502 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5503 : "memory");
5504 }
5505
5506 -static void inline arch_write_lock(arch_rwlock_t *lock)
5507 +static inline void arch_write_lock(arch_rwlock_t *lock)
5508 {
5509 unsigned long mask, tmp1, tmp2;
5510
5511 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5512 : "memory");
5513 }
5514
5515 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5516 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5517 {
5518 __asm__ __volatile__(
5519 " stw %%g0, [%0]"
5520 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5521 : "memory");
5522 }
5523
5524 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5525 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5526 {
5527 unsigned long mask, tmp1, tmp2, result;
5528
5529 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5530 index e6cd224..3a71793 100644
5531 --- a/arch/sparc/include/asm/thread_info_32.h
5532 +++ b/arch/sparc/include/asm/thread_info_32.h
5533 @@ -49,6 +49,8 @@ struct thread_info {
5534 unsigned long w_saved;
5535
5536 struct restart_block restart_block;
5537 +
5538 + unsigned long lowest_stack;
5539 };
5540
5541 /*
5542 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5543 index cfa8c38..13f30d3 100644
5544 --- a/arch/sparc/include/asm/thread_info_64.h
5545 +++ b/arch/sparc/include/asm/thread_info_64.h
5546 @@ -63,6 +63,8 @@ struct thread_info {
5547 struct pt_regs *kern_una_regs;
5548 unsigned int kern_una_insn;
5549
5550 + unsigned long lowest_stack;
5551 +
5552 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5553 };
5554
5555 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5556 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5557 /* flag bit 6 is available */
5558 #define TIF_32BIT 7 /* 32-bit binary */
5559 -/* flag bit 8 is available */
5560 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5561 #define TIF_SECCOMP 9 /* secure computing */
5562 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5563 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5564 +
5565 /* NOTE: Thread flags >= 12 should be ones we have no interest
5566 * in using in assembly, else we can't use the mask as
5567 * an immediate value in instructions such as andcc.
5568 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5569 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5570 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5571 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5572 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5573
5574 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5575 _TIF_DO_NOTIFY_RESUME_MASK | \
5576 _TIF_NEED_RESCHED)
5577 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5578
5579 +#define _TIF_WORK_SYSCALL \
5580 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5581 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5582 +
5583 +
5584 /*
5585 * Thread-synchronous status.
5586 *
5587 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5588 index 0167d26..9acd8ed 100644
5589 --- a/arch/sparc/include/asm/uaccess.h
5590 +++ b/arch/sparc/include/asm/uaccess.h
5591 @@ -1,5 +1,13 @@
5592 #ifndef ___ASM_SPARC_UACCESS_H
5593 #define ___ASM_SPARC_UACCESS_H
5594 +
5595 +#ifdef __KERNEL__
5596 +#ifndef __ASSEMBLY__
5597 +#include <linux/types.h>
5598 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5599 +#endif
5600 +#endif
5601 +
5602 #if defined(__sparc__) && defined(__arch64__)
5603 #include <asm/uaccess_64.h>
5604 #else
5605 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5606 index 53a28dd..50c38c3 100644
5607 --- a/arch/sparc/include/asm/uaccess_32.h
5608 +++ b/arch/sparc/include/asm/uaccess_32.h
5609 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5610
5611 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5612 {
5613 - if (n && __access_ok((unsigned long) to, n))
5614 + if ((long)n < 0)
5615 + return n;
5616 +
5617 + if (n && __access_ok((unsigned long) to, n)) {
5618 + if (!__builtin_constant_p(n))
5619 + check_object_size(from, n, true);
5620 return __copy_user(to, (__force void __user *) from, n);
5621 - else
5622 + } else
5623 return n;
5624 }
5625
5626 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5627 {
5628 + if ((long)n < 0)
5629 + return n;
5630 +
5631 + if (!__builtin_constant_p(n))
5632 + check_object_size(from, n, true);
5633 +
5634 return __copy_user(to, (__force void __user *) from, n);
5635 }
5636
5637 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5638 {
5639 - if (n && __access_ok((unsigned long) from, n))
5640 + if ((long)n < 0)
5641 + return n;
5642 +
5643 + if (n && __access_ok((unsigned long) from, n)) {
5644 + if (!__builtin_constant_p(n))
5645 + check_object_size(to, n, false);
5646 return __copy_user((__force void __user *) to, from, n);
5647 - else
5648 + } else
5649 return n;
5650 }
5651
5652 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5653 {
5654 + if ((long)n < 0)
5655 + return n;
5656 +
5657 return __copy_user((__force void __user *) to, from, n);
5658 }
5659
5660 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5661 index 7c831d8..d440ca7 100644
5662 --- a/arch/sparc/include/asm/uaccess_64.h
5663 +++ b/arch/sparc/include/asm/uaccess_64.h
5664 @@ -10,6 +10,7 @@
5665 #include <linux/compiler.h>
5666 #include <linux/string.h>
5667 #include <linux/thread_info.h>
5668 +#include <linux/kernel.h>
5669 #include <asm/asi.h>
5670 #include <asm/spitfire.h>
5671 #include <asm-generic/uaccess-unaligned.h>
5672 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5673 static inline unsigned long __must_check
5674 copy_from_user(void *to, const void __user *from, unsigned long size)
5675 {
5676 - unsigned long ret = ___copy_from_user(to, from, size);
5677 + unsigned long ret;
5678
5679 + if ((long)size < 0 || size > INT_MAX)
5680 + return size;
5681 +
5682 + if (!__builtin_constant_p(size))
5683 + check_object_size(to, size, false);
5684 +
5685 + ret = ___copy_from_user(to, from, size);
5686 if (unlikely(ret))
5687 ret = copy_from_user_fixup(to, from, size);
5688
5689 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5690 static inline unsigned long __must_check
5691 copy_to_user(void __user *to, const void *from, unsigned long size)
5692 {
5693 - unsigned long ret = ___copy_to_user(to, from, size);
5694 + unsigned long ret;
5695
5696 + if ((long)size < 0 || size > INT_MAX)
5697 + return size;
5698 +
5699 + if (!__builtin_constant_p(size))
5700 + check_object_size(from, size, true);
5701 +
5702 + ret = ___copy_to_user(to, from, size);
5703 if (unlikely(ret))
5704 ret = copy_to_user_fixup(to, from, size);
5705 return ret;
5706 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5707 index 6cf591b..b49e65a 100644
5708 --- a/arch/sparc/kernel/Makefile
5709 +++ b/arch/sparc/kernel/Makefile
5710 @@ -3,7 +3,7 @@
5711 #
5712
5713 asflags-y := -ansi
5714 -ccflags-y := -Werror
5715 +#ccflags-y := -Werror
5716
5717 extra-y := head_$(BITS).o
5718
5719 diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
5720 index f8b6eee..87f60ee 100644
5721 --- a/arch/sparc/kernel/leon_kernel.c
5722 +++ b/arch/sparc/kernel/leon_kernel.c
5723 @@ -56,11 +56,13 @@ static inline unsigned int leon_eirq_get(int cpu)
5724 static void leon_handle_ext_irq(unsigned int irq, struct irq_desc *desc)
5725 {
5726 unsigned int eirq;
5727 + struct irq_bucket *p;
5728 int cpu = sparc_leon3_cpuid();
5729
5730 eirq = leon_eirq_get(cpu);
5731 - if ((eirq & 0x10) && irq_map[eirq]->irq) /* bit4 tells if IRQ happened */
5732 - generic_handle_irq(irq_map[eirq]->irq);
5733 + p = irq_map[eirq];
5734 + if ((eirq & 0x10) && p && p->irq) /* bit4 tells if IRQ happened */
5735 + generic_handle_irq(p->irq);
5736 }
5737
5738 /* The extended IRQ controller has been found, this function registers it */
5739 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5740 index 14006d8..8146238 100644
5741 --- a/arch/sparc/kernel/process_32.c
5742 +++ b/arch/sparc/kernel/process_32.c
5743 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5744
5745 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5746 r->psr, r->pc, r->npc, r->y, print_tainted());
5747 - printk("PC: <%pS>\n", (void *) r->pc);
5748 + printk("PC: <%pA>\n", (void *) r->pc);
5749 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5750 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5751 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5752 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5753 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5754 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5755 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5756 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5757
5758 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5759 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5760 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5761 rw = (struct reg_window32 *) fp;
5762 pc = rw->ins[7];
5763 printk("[%08lx : ", pc);
5764 - printk("%pS ] ", (void *) pc);
5765 + printk("%pA ] ", (void *) pc);
5766 fp = rw->ins[6];
5767 } while (++count < 16);
5768 printk("\n");
5769 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5770 index aff0c72..9067b39 100644
5771 --- a/arch/sparc/kernel/process_64.c
5772 +++ b/arch/sparc/kernel/process_64.c
5773 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5774 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5775 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5776 if (regs->tstate & TSTATE_PRIV)
5777 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5778 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5779 }
5780
5781 void show_regs(struct pt_regs *regs)
5782 {
5783 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5784 regs->tpc, regs->tnpc, regs->y, print_tainted());
5785 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5786 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5787 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5788 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5789 regs->u_regs[3]);
5790 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5791 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5792 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5793 regs->u_regs[15]);
5794 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5795 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5796 show_regwindow(regs);
5797 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5798 }
5799 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5800 ((tp && tp->task) ? tp->task->pid : -1));
5801
5802 if (gp->tstate & TSTATE_PRIV) {
5803 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5804 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5805 (void *) gp->tpc,
5806 (void *) gp->o7,
5807 (void *) gp->i7,
5808 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5809 index 484daba..0674139 100644
5810 --- a/arch/sparc/kernel/ptrace_64.c
5811 +++ b/arch/sparc/kernel/ptrace_64.c
5812 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5813 return ret;
5814 }
5815
5816 +#ifdef CONFIG_GRKERNSEC_SETXID
5817 +extern void gr_delayed_cred_worker(void);
5818 +#endif
5819 +
5820 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5821 {
5822 int ret = 0;
5823 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5824 /* do the secure computing check first */
5825 secure_computing_strict(regs->u_regs[UREG_G1]);
5826
5827 +#ifdef CONFIG_GRKERNSEC_SETXID
5828 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5829 + gr_delayed_cred_worker();
5830 +#endif
5831 +
5832 if (test_thread_flag(TIF_SYSCALL_TRACE))
5833 ret = tracehook_report_syscall_entry(regs);
5834
5835 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5836
5837 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5838 {
5839 +#ifdef CONFIG_GRKERNSEC_SETXID
5840 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5841 + gr_delayed_cred_worker();
5842 +#endif
5843 +
5844 audit_syscall_exit(regs);
5845
5846 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5847 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5848 index 0c9b31b..7cb7aee 100644
5849 --- a/arch/sparc/kernel/sys_sparc_32.c
5850 +++ b/arch/sparc/kernel/sys_sparc_32.c
5851 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5852 if (len > TASK_SIZE - PAGE_SIZE)
5853 return -ENOMEM;
5854 if (!addr)
5855 - addr = TASK_UNMAPPED_BASE;
5856 + addr = current->mm->mmap_base;
5857
5858 if (flags & MAP_SHARED)
5859 addr = COLOUR_ALIGN(addr);
5860 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5861 /* At this point: (!vmm || addr < vmm->vm_end). */
5862 if (TASK_SIZE - PAGE_SIZE - len < addr)
5863 return -ENOMEM;
5864 - if (!vmm || addr + len <= vmm->vm_start)
5865 + if (check_heap_stack_gap(vmm, addr, len))
5866 return addr;
5867 addr = vmm->vm_end;
5868 if (flags & MAP_SHARED)
5869 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5870 index 11c6c96..3ec33e8 100644
5871 --- a/arch/sparc/kernel/sys_sparc_64.c
5872 +++ b/arch/sparc/kernel/sys_sparc_64.c
5873 @@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5874 /* We do not accept a shared mapping if it would violate
5875 * cache aliasing constraints.
5876 */
5877 - if ((flags & MAP_SHARED) &&
5878 + if ((filp || (flags & MAP_SHARED)) &&
5879 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5880 return -EINVAL;
5881 return addr;
5882 @@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5883 if (filp || (flags & MAP_SHARED))
5884 do_color_align = 1;
5885
5886 +#ifdef CONFIG_PAX_RANDMMAP
5887 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5888 +#endif
5889 +
5890 if (addr) {
5891 if (do_color_align)
5892 addr = COLOUR_ALIGN(addr, pgoff);
5893 @@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5894 addr = PAGE_ALIGN(addr);
5895
5896 vma = find_vma(mm, addr);
5897 - if (task_size - len >= addr &&
5898 - (!vma || addr + len <= vma->vm_start))
5899 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5900 return addr;
5901 }
5902
5903 if (len > mm->cached_hole_size) {
5904 - start_addr = addr = mm->free_area_cache;
5905 + start_addr = addr = mm->free_area_cache;
5906 } else {
5907 - start_addr = addr = TASK_UNMAPPED_BASE;
5908 + start_addr = addr = mm->mmap_base;
5909 mm->cached_hole_size = 0;
5910 }
5911
5912 @@ -157,14 +160,14 @@ full_search:
5913 vma = find_vma(mm, VA_EXCLUDE_END);
5914 }
5915 if (unlikely(task_size < addr)) {
5916 - if (start_addr != TASK_UNMAPPED_BASE) {
5917 - start_addr = addr = TASK_UNMAPPED_BASE;
5918 + if (start_addr != mm->mmap_base) {
5919 + start_addr = addr = mm->mmap_base;
5920 mm->cached_hole_size = 0;
5921 goto full_search;
5922 }
5923 return -ENOMEM;
5924 }
5925 - if (likely(!vma || addr + len <= vma->vm_start)) {
5926 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5927 /*
5928 * Remember the place where we stopped the search:
5929 */
5930 @@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5931 /* We do not accept a shared mapping if it would violate
5932 * cache aliasing constraints.
5933 */
5934 - if ((flags & MAP_SHARED) &&
5935 + if ((filp || (flags & MAP_SHARED)) &&
5936 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5937 return -EINVAL;
5938 return addr;
5939 @@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5940 addr = PAGE_ALIGN(addr);
5941
5942 vma = find_vma(mm, addr);
5943 - if (task_size - len >= addr &&
5944 - (!vma || addr + len <= vma->vm_start))
5945 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5946 return addr;
5947 }
5948
5949 @@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5950 /* make sure it can fit in the remaining address space */
5951 if (likely(addr > len)) {
5952 vma = find_vma(mm, addr-len);
5953 - if (!vma || addr <= vma->vm_start) {
5954 + if (check_heap_stack_gap(vma, addr - len, len)) {
5955 /* remember the address as a hint for next time */
5956 return (mm->free_area_cache = addr-len);
5957 }
5958 @@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5959 if (unlikely(mm->mmap_base < len))
5960 goto bottomup;
5961
5962 - addr = mm->mmap_base-len;
5963 - if (do_color_align)
5964 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5965 + addr = mm->mmap_base - len;
5966
5967 do {
5968 + if (do_color_align)
5969 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5970 /*
5971 * Lookup failure means no vma is above this address,
5972 * else if new region fits below vma->vm_start,
5973 * return with success:
5974 */
5975 vma = find_vma(mm, addr);
5976 - if (likely(!vma || addr+len <= vma->vm_start)) {
5977 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5978 /* remember the address as a hint for next time */
5979 return (mm->free_area_cache = addr);
5980 }
5981 @@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5982 mm->cached_hole_size = vma->vm_start - addr;
5983
5984 /* try just below the current vma->vm_start */
5985 - addr = vma->vm_start-len;
5986 - if (do_color_align)
5987 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5988 - } while (likely(len < vma->vm_start));
5989 + addr = skip_heap_stack_gap(vma, len);
5990 + } while (!IS_ERR_VALUE(addr));
5991
5992 bottomup:
5993 /*
5994 @@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5995 gap == RLIM_INFINITY ||
5996 sysctl_legacy_va_layout) {
5997 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5998 +
5999 +#ifdef CONFIG_PAX_RANDMMAP
6000 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6001 + mm->mmap_base += mm->delta_mmap;
6002 +#endif
6003 +
6004 mm->get_unmapped_area = arch_get_unmapped_area;
6005 mm->unmap_area = arch_unmap_area;
6006 } else {
6007 @@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6008 gap = (task_size / 6 * 5);
6009
6010 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6011 +
6012 +#ifdef CONFIG_PAX_RANDMMAP
6013 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6014 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6015 +#endif
6016 +
6017 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6018 mm->unmap_area = arch_unmap_area_topdown;
6019 }
6020 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6021 index 7f5f65d..3308382 100644
6022 --- a/arch/sparc/kernel/syscalls.S
6023 +++ b/arch/sparc/kernel/syscalls.S
6024 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6025 #endif
6026 .align 32
6027 1: ldx [%g6 + TI_FLAGS], %l5
6028 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6029 + andcc %l5, _TIF_WORK_SYSCALL, %g0
6030 be,pt %icc, rtrap
6031 nop
6032 call syscall_trace_leave
6033 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
6034
6035 srl %i5, 0, %o5 ! IEU1
6036 srl %i2, 0, %o2 ! IEU0 Group
6037 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6038 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6039 bne,pn %icc, linux_syscall_trace32 ! CTI
6040 mov %i0, %l5 ! IEU1
6041 call %l7 ! CTI Group brk forced
6042 @@ -202,7 +202,7 @@ linux_sparc_syscall:
6043
6044 mov %i3, %o3 ! IEU1
6045 mov %i4, %o4 ! IEU0 Group
6046 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6047 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6048 bne,pn %icc, linux_syscall_trace ! CTI Group
6049 mov %i0, %l5 ! IEU0
6050 2: call %l7 ! CTI Group brk forced
6051 @@ -218,7 +218,7 @@ ret_sys_call:
6052
6053 cmp %o0, -ERESTART_RESTARTBLOCK
6054 bgeu,pn %xcc, 1f
6055 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6056 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6057 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
6058
6059 2:
6060 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6061 index a5785ea..405c5f7 100644
6062 --- a/arch/sparc/kernel/traps_32.c
6063 +++ b/arch/sparc/kernel/traps_32.c
6064 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6065 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6066 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6067
6068 +extern void gr_handle_kernel_exploit(void);
6069 +
6070 void die_if_kernel(char *str, struct pt_regs *regs)
6071 {
6072 static int die_counter;
6073 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6074 count++ < 30 &&
6075 (((unsigned long) rw) >= PAGE_OFFSET) &&
6076 !(((unsigned long) rw) & 0x7)) {
6077 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6078 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6079 (void *) rw->ins[7]);
6080 rw = (struct reg_window32 *)rw->ins[6];
6081 }
6082 }
6083 printk("Instruction DUMP:");
6084 instruction_dump ((unsigned long *) regs->pc);
6085 - if(regs->psr & PSR_PS)
6086 + if(regs->psr & PSR_PS) {
6087 + gr_handle_kernel_exploit();
6088 do_exit(SIGKILL);
6089 + }
6090 do_exit(SIGSEGV);
6091 }
6092
6093 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6094 index 3b05e66..6ea2917 100644
6095 --- a/arch/sparc/kernel/traps_64.c
6096 +++ b/arch/sparc/kernel/traps_64.c
6097 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6098 i + 1,
6099 p->trapstack[i].tstate, p->trapstack[i].tpc,
6100 p->trapstack[i].tnpc, p->trapstack[i].tt);
6101 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6102 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6103 }
6104 }
6105
6106 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6107
6108 lvl -= 0x100;
6109 if (regs->tstate & TSTATE_PRIV) {
6110 +
6111 +#ifdef CONFIG_PAX_REFCOUNT
6112 + if (lvl == 6)
6113 + pax_report_refcount_overflow(regs);
6114 +#endif
6115 +
6116 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6117 die_if_kernel(buffer, regs);
6118 }
6119 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6120 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6121 {
6122 char buffer[32];
6123 -
6124 +
6125 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6126 0, lvl, SIGTRAP) == NOTIFY_STOP)
6127 return;
6128
6129 +#ifdef CONFIG_PAX_REFCOUNT
6130 + if (lvl == 6)
6131 + pax_report_refcount_overflow(regs);
6132 +#endif
6133 +
6134 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6135
6136 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6137 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6138 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6139 printk("%s" "ERROR(%d): ",
6140 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6141 - printk("TPC<%pS>\n", (void *) regs->tpc);
6142 + printk("TPC<%pA>\n", (void *) regs->tpc);
6143 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6144 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6145 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6146 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6147 smp_processor_id(),
6148 (type & 0x1) ? 'I' : 'D',
6149 regs->tpc);
6150 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6151 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6152 panic("Irrecoverable Cheetah+ parity error.");
6153 }
6154
6155 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6156 smp_processor_id(),
6157 (type & 0x1) ? 'I' : 'D',
6158 regs->tpc);
6159 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6160 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6161 }
6162
6163 struct sun4v_error_entry {
6164 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6165
6166 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6167 regs->tpc, tl);
6168 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6169 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6170 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6171 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6172 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6173 (void *) regs->u_regs[UREG_I7]);
6174 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6175 "pte[%lx] error[%lx]\n",
6176 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6177
6178 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6179 regs->tpc, tl);
6180 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6181 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6182 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6183 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6184 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6185 (void *) regs->u_regs[UREG_I7]);
6186 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6187 "pte[%lx] error[%lx]\n",
6188 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6189 fp = (unsigned long)sf->fp + STACK_BIAS;
6190 }
6191
6192 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6193 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6194 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6195 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6196 int index = tsk->curr_ret_stack;
6197 if (tsk->ret_stack && index >= graph) {
6198 pc = tsk->ret_stack[index - graph].ret;
6199 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6200 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6201 graph++;
6202 }
6203 }
6204 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6205 return (struct reg_window *) (fp + STACK_BIAS);
6206 }
6207
6208 +extern void gr_handle_kernel_exploit(void);
6209 +
6210 void die_if_kernel(char *str, struct pt_regs *regs)
6211 {
6212 static int die_counter;
6213 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6214 while (rw &&
6215 count++ < 30 &&
6216 kstack_valid(tp, (unsigned long) rw)) {
6217 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6218 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6219 (void *) rw->ins[7]);
6220
6221 rw = kernel_stack_up(rw);
6222 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6223 }
6224 user_instruction_dump ((unsigned int __user *) regs->tpc);
6225 }
6226 - if (regs->tstate & TSTATE_PRIV)
6227 + if (regs->tstate & TSTATE_PRIV) {
6228 + gr_handle_kernel_exploit();
6229 do_exit(SIGKILL);
6230 + }
6231 do_exit(SIGSEGV);
6232 }
6233 EXPORT_SYMBOL(die_if_kernel);
6234 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6235 index f81d038..e7a4680 100644
6236 --- a/arch/sparc/kernel/unaligned_64.c
6237 +++ b/arch/sparc/kernel/unaligned_64.c
6238 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6239 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6240
6241 if (__ratelimit(&ratelimit)) {
6242 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6243 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6244 regs->tpc, (void *) regs->tpc);
6245 }
6246 }
6247 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6248 index dff4096..bd9a388 100644
6249 --- a/arch/sparc/lib/Makefile
6250 +++ b/arch/sparc/lib/Makefile
6251 @@ -2,7 +2,7 @@
6252 #
6253
6254 asflags-y := -ansi -DST_DIV0=0x02
6255 -ccflags-y := -Werror
6256 +#ccflags-y := -Werror
6257
6258 lib-$(CONFIG_SPARC32) += ashrdi3.o
6259 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6260 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6261 index 4d502da..527c48d 100644
6262 --- a/arch/sparc/lib/atomic_64.S
6263 +++ b/arch/sparc/lib/atomic_64.S
6264 @@ -17,7 +17,12 @@
6265 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6266 BACKOFF_SETUP(%o2)
6267 1: lduw [%o1], %g1
6268 - add %g1, %o0, %g7
6269 + addcc %g1, %o0, %g7
6270 +
6271 +#ifdef CONFIG_PAX_REFCOUNT
6272 + tvs %icc, 6
6273 +#endif
6274 +
6275 cas [%o1], %g1, %g7
6276 cmp %g1, %g7
6277 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6278 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6279 2: BACKOFF_SPIN(%o2, %o3, 1b)
6280 ENDPROC(atomic_add)
6281
6282 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6283 + BACKOFF_SETUP(%o2)
6284 +1: lduw [%o1], %g1
6285 + add %g1, %o0, %g7
6286 + cas [%o1], %g1, %g7
6287 + cmp %g1, %g7
6288 + bne,pn %icc, 2f
6289 + nop
6290 + retl
6291 + nop
6292 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6293 +ENDPROC(atomic_add_unchecked)
6294 +
6295 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6296 BACKOFF_SETUP(%o2)
6297 1: lduw [%o1], %g1
6298 - sub %g1, %o0, %g7
6299 + subcc %g1, %o0, %g7
6300 +
6301 +#ifdef CONFIG_PAX_REFCOUNT
6302 + tvs %icc, 6
6303 +#endif
6304 +
6305 cas [%o1], %g1, %g7
6306 cmp %g1, %g7
6307 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6308 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6309 2: BACKOFF_SPIN(%o2, %o3, 1b)
6310 ENDPROC(atomic_sub)
6311
6312 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6313 + BACKOFF_SETUP(%o2)
6314 +1: lduw [%o1], %g1
6315 + sub %g1, %o0, %g7
6316 + cas [%o1], %g1, %g7
6317 + cmp %g1, %g7
6318 + bne,pn %icc, 2f
6319 + nop
6320 + retl
6321 + nop
6322 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6323 +ENDPROC(atomic_sub_unchecked)
6324 +
6325 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6326 BACKOFF_SETUP(%o2)
6327 1: lduw [%o1], %g1
6328 - add %g1, %o0, %g7
6329 + addcc %g1, %o0, %g7
6330 +
6331 +#ifdef CONFIG_PAX_REFCOUNT
6332 + tvs %icc, 6
6333 +#endif
6334 +
6335 cas [%o1], %g1, %g7
6336 cmp %g1, %g7
6337 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6338 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6339 2: BACKOFF_SPIN(%o2, %o3, 1b)
6340 ENDPROC(atomic_add_ret)
6341
6342 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6343 + BACKOFF_SETUP(%o2)
6344 +1: lduw [%o1], %g1
6345 + addcc %g1, %o0, %g7
6346 + cas [%o1], %g1, %g7
6347 + cmp %g1, %g7
6348 + bne,pn %icc, 2f
6349 + add %g7, %o0, %g7
6350 + sra %g7, 0, %o0
6351 + retl
6352 + nop
6353 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6354 +ENDPROC(atomic_add_ret_unchecked)
6355 +
6356 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6357 BACKOFF_SETUP(%o2)
6358 1: lduw [%o1], %g1
6359 - sub %g1, %o0, %g7
6360 + subcc %g1, %o0, %g7
6361 +
6362 +#ifdef CONFIG_PAX_REFCOUNT
6363 + tvs %icc, 6
6364 +#endif
6365 +
6366 cas [%o1], %g1, %g7
6367 cmp %g1, %g7
6368 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6369 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6370 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6371 BACKOFF_SETUP(%o2)
6372 1: ldx [%o1], %g1
6373 - add %g1, %o0, %g7
6374 + addcc %g1, %o0, %g7
6375 +
6376 +#ifdef CONFIG_PAX_REFCOUNT
6377 + tvs %xcc, 6
6378 +#endif
6379 +
6380 casx [%o1], %g1, %g7
6381 cmp %g1, %g7
6382 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6383 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6384 2: BACKOFF_SPIN(%o2, %o3, 1b)
6385 ENDPROC(atomic64_add)
6386
6387 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6388 + BACKOFF_SETUP(%o2)
6389 +1: ldx [%o1], %g1
6390 + addcc %g1, %o0, %g7
6391 + casx [%o1], %g1, %g7
6392 + cmp %g1, %g7
6393 + bne,pn %xcc, 2f
6394 + nop
6395 + retl
6396 + nop
6397 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6398 +ENDPROC(atomic64_add_unchecked)
6399 +
6400 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403 - sub %g1, %o0, %g7
6404 + subcc %g1, %o0, %g7
6405 +
6406 +#ifdef CONFIG_PAX_REFCOUNT
6407 + tvs %xcc, 6
6408 +#endif
6409 +
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6414 2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 ENDPROC(atomic64_sub)
6416
6417 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6418 + BACKOFF_SETUP(%o2)
6419 +1: ldx [%o1], %g1
6420 + subcc %g1, %o0, %g7
6421 + casx [%o1], %g1, %g7
6422 + cmp %g1, %g7
6423 + bne,pn %xcc, 2f
6424 + nop
6425 + retl
6426 + nop
6427 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6428 +ENDPROC(atomic64_sub_unchecked)
6429 +
6430 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6431 BACKOFF_SETUP(%o2)
6432 1: ldx [%o1], %g1
6433 - add %g1, %o0, %g7
6434 + addcc %g1, %o0, %g7
6435 +
6436 +#ifdef CONFIG_PAX_REFCOUNT
6437 + tvs %xcc, 6
6438 +#endif
6439 +
6440 casx [%o1], %g1, %g7
6441 cmp %g1, %g7
6442 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6443 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6444 2: BACKOFF_SPIN(%o2, %o3, 1b)
6445 ENDPROC(atomic64_add_ret)
6446
6447 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6448 + BACKOFF_SETUP(%o2)
6449 +1: ldx [%o1], %g1
6450 + addcc %g1, %o0, %g7
6451 + casx [%o1], %g1, %g7
6452 + cmp %g1, %g7
6453 + bne,pn %xcc, 2f
6454 + add %g7, %o0, %g7
6455 + mov %g7, %o0
6456 + retl
6457 + nop
6458 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6459 +ENDPROC(atomic64_add_ret_unchecked)
6460 +
6461 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6462 BACKOFF_SETUP(%o2)
6463 1: ldx [%o1], %g1
6464 - sub %g1, %o0, %g7
6465 + subcc %g1, %o0, %g7
6466 +
6467 +#ifdef CONFIG_PAX_REFCOUNT
6468 + tvs %xcc, 6
6469 +#endif
6470 +
6471 casx [%o1], %g1, %g7
6472 cmp %g1, %g7
6473 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6474 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6475 index 3b31218..345c609 100644
6476 --- a/arch/sparc/lib/ksyms.c
6477 +++ b/arch/sparc/lib/ksyms.c
6478 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6479
6480 /* Atomic counter implementation. */
6481 EXPORT_SYMBOL(atomic_add);
6482 +EXPORT_SYMBOL(atomic_add_unchecked);
6483 EXPORT_SYMBOL(atomic_add_ret);
6484 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6485 EXPORT_SYMBOL(atomic_sub);
6486 +EXPORT_SYMBOL(atomic_sub_unchecked);
6487 EXPORT_SYMBOL(atomic_sub_ret);
6488 EXPORT_SYMBOL(atomic64_add);
6489 +EXPORT_SYMBOL(atomic64_add_unchecked);
6490 EXPORT_SYMBOL(atomic64_add_ret);
6491 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6492 EXPORT_SYMBOL(atomic64_sub);
6493 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6494 EXPORT_SYMBOL(atomic64_sub_ret);
6495
6496 /* Atomic bit operations. */
6497 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6498 index 30c3ecc..736f015 100644
6499 --- a/arch/sparc/mm/Makefile
6500 +++ b/arch/sparc/mm/Makefile
6501 @@ -2,7 +2,7 @@
6502 #
6503
6504 asflags-y := -ansi
6505 -ccflags-y := -Werror
6506 +#ccflags-y := -Werror
6507
6508 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6509 obj-y += fault_$(BITS).o
6510 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6511 index 77ac917..baf45db 100644
6512 --- a/arch/sparc/mm/fault_32.c
6513 +++ b/arch/sparc/mm/fault_32.c
6514 @@ -21,6 +21,9 @@
6515 #include <linux/perf_event.h>
6516 #include <linux/interrupt.h>
6517 #include <linux/kdebug.h>
6518 +#include <linux/slab.h>
6519 +#include <linux/pagemap.h>
6520 +#include <linux/compiler.h>
6521
6522 #include <asm/page.h>
6523 #include <asm/pgtable.h>
6524 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6525 return safe_compute_effective_address(regs, insn);
6526 }
6527
6528 +#ifdef CONFIG_PAX_PAGEEXEC
6529 +#ifdef CONFIG_PAX_DLRESOLVE
6530 +static void pax_emuplt_close(struct vm_area_struct *vma)
6531 +{
6532 + vma->vm_mm->call_dl_resolve = 0UL;
6533 +}
6534 +
6535 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6536 +{
6537 + unsigned int *kaddr;
6538 +
6539 + vmf->page = alloc_page(GFP_HIGHUSER);
6540 + if (!vmf->page)
6541 + return VM_FAULT_OOM;
6542 +
6543 + kaddr = kmap(vmf->page);
6544 + memset(kaddr, 0, PAGE_SIZE);
6545 + kaddr[0] = 0x9DE3BFA8U; /* save */
6546 + flush_dcache_page(vmf->page);
6547 + kunmap(vmf->page);
6548 + return VM_FAULT_MAJOR;
6549 +}
6550 +
6551 +static const struct vm_operations_struct pax_vm_ops = {
6552 + .close = pax_emuplt_close,
6553 + .fault = pax_emuplt_fault
6554 +};
6555 +
6556 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6557 +{
6558 + int ret;
6559 +
6560 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6561 + vma->vm_mm = current->mm;
6562 + vma->vm_start = addr;
6563 + vma->vm_end = addr + PAGE_SIZE;
6564 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6565 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6566 + vma->vm_ops = &pax_vm_ops;
6567 +
6568 + ret = insert_vm_struct(current->mm, vma);
6569 + if (ret)
6570 + return ret;
6571 +
6572 + ++current->mm->total_vm;
6573 + return 0;
6574 +}
6575 +#endif
6576 +
6577 +/*
6578 + * PaX: decide what to do with offenders (regs->pc = fault address)
6579 + *
6580 + * returns 1 when task should be killed
6581 + * 2 when patched PLT trampoline was detected
6582 + * 3 when unpatched PLT trampoline was detected
6583 + */
6584 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6585 +{
6586 +
6587 +#ifdef CONFIG_PAX_EMUPLT
6588 + int err;
6589 +
6590 + do { /* PaX: patched PLT emulation #1 */
6591 + unsigned int sethi1, sethi2, jmpl;
6592 +
6593 + err = get_user(sethi1, (unsigned int *)regs->pc);
6594 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6595 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6596 +
6597 + if (err)
6598 + break;
6599 +
6600 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6601 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6602 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6603 + {
6604 + unsigned int addr;
6605 +
6606 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6607 + addr = regs->u_regs[UREG_G1];
6608 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6609 + regs->pc = addr;
6610 + regs->npc = addr+4;
6611 + return 2;
6612 + }
6613 + } while (0);
6614 +
6615 + do { /* PaX: patched PLT emulation #2 */
6616 + unsigned int ba;
6617 +
6618 + err = get_user(ba, (unsigned int *)regs->pc);
6619 +
6620 + if (err)
6621 + break;
6622 +
6623 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6624 + unsigned int addr;
6625 +
6626 + if ((ba & 0xFFC00000U) == 0x30800000U)
6627 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6628 + else
6629 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6630 + regs->pc = addr;
6631 + regs->npc = addr+4;
6632 + return 2;
6633 + }
6634 + } while (0);
6635 +
6636 + do { /* PaX: patched PLT emulation #3 */
6637 + unsigned int sethi, bajmpl, nop;
6638 +
6639 + err = get_user(sethi, (unsigned int *)regs->pc);
6640 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6641 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6642 +
6643 + if (err)
6644 + break;
6645 +
6646 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6647 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6648 + nop == 0x01000000U)
6649 + {
6650 + unsigned int addr;
6651 +
6652 + addr = (sethi & 0x003FFFFFU) << 10;
6653 + regs->u_regs[UREG_G1] = addr;
6654 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6655 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6656 + else
6657 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6658 + regs->pc = addr;
6659 + regs->npc = addr+4;
6660 + return 2;
6661 + }
6662 + } while (0);
6663 +
6664 + do { /* PaX: unpatched PLT emulation step 1 */
6665 + unsigned int sethi, ba, nop;
6666 +
6667 + err = get_user(sethi, (unsigned int *)regs->pc);
6668 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6669 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6670 +
6671 + if (err)
6672 + break;
6673 +
6674 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6675 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6676 + nop == 0x01000000U)
6677 + {
6678 + unsigned int addr, save, call;
6679 +
6680 + if ((ba & 0xFFC00000U) == 0x30800000U)
6681 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6682 + else
6683 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6684 +
6685 + err = get_user(save, (unsigned int *)addr);
6686 + err |= get_user(call, (unsigned int *)(addr+4));
6687 + err |= get_user(nop, (unsigned int *)(addr+8));
6688 + if (err)
6689 + break;
6690 +
6691 +#ifdef CONFIG_PAX_DLRESOLVE
6692 + if (save == 0x9DE3BFA8U &&
6693 + (call & 0xC0000000U) == 0x40000000U &&
6694 + nop == 0x01000000U)
6695 + {
6696 + struct vm_area_struct *vma;
6697 + unsigned long call_dl_resolve;
6698 +
6699 + down_read(&current->mm->mmap_sem);
6700 + call_dl_resolve = current->mm->call_dl_resolve;
6701 + up_read(&current->mm->mmap_sem);
6702 + if (likely(call_dl_resolve))
6703 + goto emulate;
6704 +
6705 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6706 +
6707 + down_write(&current->mm->mmap_sem);
6708 + if (current->mm->call_dl_resolve) {
6709 + call_dl_resolve = current->mm->call_dl_resolve;
6710 + up_write(&current->mm->mmap_sem);
6711 + if (vma)
6712 + kmem_cache_free(vm_area_cachep, vma);
6713 + goto emulate;
6714 + }
6715 +
6716 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6717 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6718 + up_write(&current->mm->mmap_sem);
6719 + if (vma)
6720 + kmem_cache_free(vm_area_cachep, vma);
6721 + return 1;
6722 + }
6723 +
6724 + if (pax_insert_vma(vma, call_dl_resolve)) {
6725 + up_write(&current->mm->mmap_sem);
6726 + kmem_cache_free(vm_area_cachep, vma);
6727 + return 1;
6728 + }
6729 +
6730 + current->mm->call_dl_resolve = call_dl_resolve;
6731 + up_write(&current->mm->mmap_sem);
6732 +
6733 +emulate:
6734 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6735 + regs->pc = call_dl_resolve;
6736 + regs->npc = addr+4;
6737 + return 3;
6738 + }
6739 +#endif
6740 +
6741 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6742 + if ((save & 0xFFC00000U) == 0x05000000U &&
6743 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6744 + nop == 0x01000000U)
6745 + {
6746 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6747 + regs->u_regs[UREG_G2] = addr + 4;
6748 + addr = (save & 0x003FFFFFU) << 10;
6749 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6750 + regs->pc = addr;
6751 + regs->npc = addr+4;
6752 + return 3;
6753 + }
6754 + }
6755 + } while (0);
6756 +
6757 + do { /* PaX: unpatched PLT emulation step 2 */
6758 + unsigned int save, call, nop;
6759 +
6760 + err = get_user(save, (unsigned int *)(regs->pc-4));
6761 + err |= get_user(call, (unsigned int *)regs->pc);
6762 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6763 + if (err)
6764 + break;
6765 +
6766 + if (save == 0x9DE3BFA8U &&
6767 + (call & 0xC0000000U) == 0x40000000U &&
6768 + nop == 0x01000000U)
6769 + {
6770 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6771 +
6772 + regs->u_regs[UREG_RETPC] = regs->pc;
6773 + regs->pc = dl_resolve;
6774 + regs->npc = dl_resolve+4;
6775 + return 3;
6776 + }
6777 + } while (0);
6778 +#endif
6779 +
6780 + return 1;
6781 +}
6782 +
6783 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6784 +{
6785 + unsigned long i;
6786 +
6787 + printk(KERN_ERR "PAX: bytes at PC: ");
6788 + for (i = 0; i < 8; i++) {
6789 + unsigned int c;
6790 + if (get_user(c, (unsigned int *)pc+i))
6791 + printk(KERN_CONT "???????? ");
6792 + else
6793 + printk(KERN_CONT "%08x ", c);
6794 + }
6795 + printk("\n");
6796 +}
6797 +#endif
6798 +
6799 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6800 int text_fault)
6801 {
6802 @@ -230,6 +504,24 @@ good_area:
6803 if (!(vma->vm_flags & VM_WRITE))
6804 goto bad_area;
6805 } else {
6806 +
6807 +#ifdef CONFIG_PAX_PAGEEXEC
6808 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6809 + up_read(&mm->mmap_sem);
6810 + switch (pax_handle_fetch_fault(regs)) {
6811 +
6812 +#ifdef CONFIG_PAX_EMUPLT
6813 + case 2:
6814 + case 3:
6815 + return;
6816 +#endif
6817 +
6818 + }
6819 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6820 + do_group_exit(SIGKILL);
6821 + }
6822 +#endif
6823 +
6824 /* Allow reads even for write-only mappings */
6825 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6826 goto bad_area;
6827 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6828 index 1fe0429..8dd5dd5 100644
6829 --- a/arch/sparc/mm/fault_64.c
6830 +++ b/arch/sparc/mm/fault_64.c
6831 @@ -21,6 +21,9 @@
6832 #include <linux/kprobes.h>
6833 #include <linux/kdebug.h>
6834 #include <linux/percpu.h>
6835 +#include <linux/slab.h>
6836 +#include <linux/pagemap.h>
6837 +#include <linux/compiler.h>
6838
6839 #include <asm/page.h>
6840 #include <asm/pgtable.h>
6841 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6842 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6843 regs->tpc);
6844 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6845 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6846 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6847 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6848 dump_stack();
6849 unhandled_fault(regs->tpc, current, regs);
6850 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6851 show_regs(regs);
6852 }
6853
6854 +#ifdef CONFIG_PAX_PAGEEXEC
6855 +#ifdef CONFIG_PAX_DLRESOLVE
6856 +static void pax_emuplt_close(struct vm_area_struct *vma)
6857 +{
6858 + vma->vm_mm->call_dl_resolve = 0UL;
6859 +}
6860 +
6861 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6862 +{
6863 + unsigned int *kaddr;
6864 +
6865 + vmf->page = alloc_page(GFP_HIGHUSER);
6866 + if (!vmf->page)
6867 + return VM_FAULT_OOM;
6868 +
6869 + kaddr = kmap(vmf->page);
6870 + memset(kaddr, 0, PAGE_SIZE);
6871 + kaddr[0] = 0x9DE3BFA8U; /* save */
6872 + flush_dcache_page(vmf->page);
6873 + kunmap(vmf->page);
6874 + return VM_FAULT_MAJOR;
6875 +}
6876 +
6877 +static const struct vm_operations_struct pax_vm_ops = {
6878 + .close = pax_emuplt_close,
6879 + .fault = pax_emuplt_fault
6880 +};
6881 +
6882 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6883 +{
6884 + int ret;
6885 +
6886 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6887 + vma->vm_mm = current->mm;
6888 + vma->vm_start = addr;
6889 + vma->vm_end = addr + PAGE_SIZE;
6890 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6891 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6892 + vma->vm_ops = &pax_vm_ops;
6893 +
6894 + ret = insert_vm_struct(current->mm, vma);
6895 + if (ret)
6896 + return ret;
6897 +
6898 + ++current->mm->total_vm;
6899 + return 0;
6900 +}
6901 +#endif
6902 +
6903 +/*
6904 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6905 + *
6906 + * returns 1 when task should be killed
6907 + * 2 when patched PLT trampoline was detected
6908 + * 3 when unpatched PLT trampoline was detected
6909 + */
6910 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6911 +{
6912 +
6913 +#ifdef CONFIG_PAX_EMUPLT
6914 + int err;
6915 +
6916 + do { /* PaX: patched PLT emulation #1 */
6917 + unsigned int sethi1, sethi2, jmpl;
6918 +
6919 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6920 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6921 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6922 +
6923 + if (err)
6924 + break;
6925 +
6926 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6927 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6928 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6929 + {
6930 + unsigned long addr;
6931 +
6932 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6933 + addr = regs->u_regs[UREG_G1];
6934 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6935 +
6936 + if (test_thread_flag(TIF_32BIT))
6937 + addr &= 0xFFFFFFFFUL;
6938 +
6939 + regs->tpc = addr;
6940 + regs->tnpc = addr+4;
6941 + return 2;
6942 + }
6943 + } while (0);
6944 +
6945 + do { /* PaX: patched PLT emulation #2 */
6946 + unsigned int ba;
6947 +
6948 + err = get_user(ba, (unsigned int *)regs->tpc);
6949 +
6950 + if (err)
6951 + break;
6952 +
6953 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6954 + unsigned long addr;
6955 +
6956 + if ((ba & 0xFFC00000U) == 0x30800000U)
6957 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6958 + else
6959 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6960 +
6961 + if (test_thread_flag(TIF_32BIT))
6962 + addr &= 0xFFFFFFFFUL;
6963 +
6964 + regs->tpc = addr;
6965 + regs->tnpc = addr+4;
6966 + return 2;
6967 + }
6968 + } while (0);
6969 +
6970 + do { /* PaX: patched PLT emulation #3 */
6971 + unsigned int sethi, bajmpl, nop;
6972 +
6973 + err = get_user(sethi, (unsigned int *)regs->tpc);
6974 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6975 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6976 +
6977 + if (err)
6978 + break;
6979 +
6980 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6981 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6982 + nop == 0x01000000U)
6983 + {
6984 + unsigned long addr;
6985 +
6986 + addr = (sethi & 0x003FFFFFU) << 10;
6987 + regs->u_regs[UREG_G1] = addr;
6988 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6989 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6990 + else
6991 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6992 +
6993 + if (test_thread_flag(TIF_32BIT))
6994 + addr &= 0xFFFFFFFFUL;
6995 +
6996 + regs->tpc = addr;
6997 + regs->tnpc = addr+4;
6998 + return 2;
6999 + }
7000 + } while (0);
7001 +
7002 + do { /* PaX: patched PLT emulation #4 */
7003 + unsigned int sethi, mov1, call, mov2;
7004 +
7005 + err = get_user(sethi, (unsigned int *)regs->tpc);
7006 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7007 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
7008 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7009 +
7010 + if (err)
7011 + break;
7012 +
7013 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7014 + mov1 == 0x8210000FU &&
7015 + (call & 0xC0000000U) == 0x40000000U &&
7016 + mov2 == 0x9E100001U)
7017 + {
7018 + unsigned long addr;
7019 +
7020 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7021 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7022 +
7023 + if (test_thread_flag(TIF_32BIT))
7024 + addr &= 0xFFFFFFFFUL;
7025 +
7026 + regs->tpc = addr;
7027 + regs->tnpc = addr+4;
7028 + return 2;
7029 + }
7030 + } while (0);
7031 +
7032 + do { /* PaX: patched PLT emulation #5 */
7033 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7034 +
7035 + err = get_user(sethi, (unsigned int *)regs->tpc);
7036 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7037 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7038 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7039 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7040 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7041 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7042 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7043 +
7044 + if (err)
7045 + break;
7046 +
7047 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7048 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7049 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7050 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7051 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7052 + sllx == 0x83287020U &&
7053 + jmpl == 0x81C04005U &&
7054 + nop == 0x01000000U)
7055 + {
7056 + unsigned long addr;
7057 +
7058 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7059 + regs->u_regs[UREG_G1] <<= 32;
7060 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7061 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7062 + regs->tpc = addr;
7063 + regs->tnpc = addr+4;
7064 + return 2;
7065 + }
7066 + } while (0);
7067 +
7068 + do { /* PaX: patched PLT emulation #6 */
7069 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7070 +
7071 + err = get_user(sethi, (unsigned int *)regs->tpc);
7072 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7073 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7074 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7075 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7076 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7077 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7078 +
7079 + if (err)
7080 + break;
7081 +
7082 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7083 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7084 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7085 + sllx == 0x83287020U &&
7086 + (or & 0xFFFFE000U) == 0x8A116000U &&
7087 + jmpl == 0x81C04005U &&
7088 + nop == 0x01000000U)
7089 + {
7090 + unsigned long addr;
7091 +
7092 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7093 + regs->u_regs[UREG_G1] <<= 32;
7094 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7095 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7096 + regs->tpc = addr;
7097 + regs->tnpc = addr+4;
7098 + return 2;
7099 + }
7100 + } while (0);
7101 +
7102 + do { /* PaX: unpatched PLT emulation step 1 */
7103 + unsigned int sethi, ba, nop;
7104 +
7105 + err = get_user(sethi, (unsigned int *)regs->tpc);
7106 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7107 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7108 +
7109 + if (err)
7110 + break;
7111 +
7112 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7113 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7114 + nop == 0x01000000U)
7115 + {
7116 + unsigned long addr;
7117 + unsigned int save, call;
7118 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7119 +
7120 + if ((ba & 0xFFC00000U) == 0x30800000U)
7121 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7122 + else
7123 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7124 +
7125 + if (test_thread_flag(TIF_32BIT))
7126 + addr &= 0xFFFFFFFFUL;
7127 +
7128 + err = get_user(save, (unsigned int *)addr);
7129 + err |= get_user(call, (unsigned int *)(addr+4));
7130 + err |= get_user(nop, (unsigned int *)(addr+8));
7131 + if (err)
7132 + break;
7133 +
7134 +#ifdef CONFIG_PAX_DLRESOLVE
7135 + if (save == 0x9DE3BFA8U &&
7136 + (call & 0xC0000000U) == 0x40000000U &&
7137 + nop == 0x01000000U)
7138 + {
7139 + struct vm_area_struct *vma;
7140 + unsigned long call_dl_resolve;
7141 +
7142 + down_read(&current->mm->mmap_sem);
7143 + call_dl_resolve = current->mm->call_dl_resolve;
7144 + up_read(&current->mm->mmap_sem);
7145 + if (likely(call_dl_resolve))
7146 + goto emulate;
7147 +
7148 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7149 +
7150 + down_write(&current->mm->mmap_sem);
7151 + if (current->mm->call_dl_resolve) {
7152 + call_dl_resolve = current->mm->call_dl_resolve;
7153 + up_write(&current->mm->mmap_sem);
7154 + if (vma)
7155 + kmem_cache_free(vm_area_cachep, vma);
7156 + goto emulate;
7157 + }
7158 +
7159 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7160 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7161 + up_write(&current->mm->mmap_sem);
7162 + if (vma)
7163 + kmem_cache_free(vm_area_cachep, vma);
7164 + return 1;
7165 + }
7166 +
7167 + if (pax_insert_vma(vma, call_dl_resolve)) {
7168 + up_write(&current->mm->mmap_sem);
7169 + kmem_cache_free(vm_area_cachep, vma);
7170 + return 1;
7171 + }
7172 +
7173 + current->mm->call_dl_resolve = call_dl_resolve;
7174 + up_write(&current->mm->mmap_sem);
7175 +
7176 +emulate:
7177 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7178 + regs->tpc = call_dl_resolve;
7179 + regs->tnpc = addr+4;
7180 + return 3;
7181 + }
7182 +#endif
7183 +
7184 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7185 + if ((save & 0xFFC00000U) == 0x05000000U &&
7186 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7187 + nop == 0x01000000U)
7188 + {
7189 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7190 + regs->u_regs[UREG_G2] = addr + 4;
7191 + addr = (save & 0x003FFFFFU) << 10;
7192 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7193 +
7194 + if (test_thread_flag(TIF_32BIT))
7195 + addr &= 0xFFFFFFFFUL;
7196 +
7197 + regs->tpc = addr;
7198 + regs->tnpc = addr+4;
7199 + return 3;
7200 + }
7201 +
7202 + /* PaX: 64-bit PLT stub */
7203 + err = get_user(sethi1, (unsigned int *)addr);
7204 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7205 + err |= get_user(or1, (unsigned int *)(addr+8));
7206 + err |= get_user(or2, (unsigned int *)(addr+12));
7207 + err |= get_user(sllx, (unsigned int *)(addr+16));
7208 + err |= get_user(add, (unsigned int *)(addr+20));
7209 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7210 + err |= get_user(nop, (unsigned int *)(addr+28));
7211 + if (err)
7212 + break;
7213 +
7214 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7215 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7216 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7217 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7218 + sllx == 0x89293020U &&
7219 + add == 0x8A010005U &&
7220 + jmpl == 0x89C14000U &&
7221 + nop == 0x01000000U)
7222 + {
7223 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7224 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7225 + regs->u_regs[UREG_G4] <<= 32;
7226 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7227 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7228 + regs->u_regs[UREG_G4] = addr + 24;
7229 + addr = regs->u_regs[UREG_G5];
7230 + regs->tpc = addr;
7231 + regs->tnpc = addr+4;
7232 + return 3;
7233 + }
7234 + }
7235 + } while (0);
7236 +
7237 +#ifdef CONFIG_PAX_DLRESOLVE
7238 + do { /* PaX: unpatched PLT emulation step 2 */
7239 + unsigned int save, call, nop;
7240 +
7241 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7242 + err |= get_user(call, (unsigned int *)regs->tpc);
7243 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7244 + if (err)
7245 + break;
7246 +
7247 + if (save == 0x9DE3BFA8U &&
7248 + (call & 0xC0000000U) == 0x40000000U &&
7249 + nop == 0x01000000U)
7250 + {
7251 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7252 +
7253 + if (test_thread_flag(TIF_32BIT))
7254 + dl_resolve &= 0xFFFFFFFFUL;
7255 +
7256 + regs->u_regs[UREG_RETPC] = regs->tpc;
7257 + regs->tpc = dl_resolve;
7258 + regs->tnpc = dl_resolve+4;
7259 + return 3;
7260 + }
7261 + } while (0);
7262 +#endif
7263 +
7264 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7265 + unsigned int sethi, ba, nop;
7266 +
7267 + err = get_user(sethi, (unsigned int *)regs->tpc);
7268 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7269 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7270 +
7271 + if (err)
7272 + break;
7273 +
7274 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7275 + (ba & 0xFFF00000U) == 0x30600000U &&
7276 + nop == 0x01000000U)
7277 + {
7278 + unsigned long addr;
7279 +
7280 + addr = (sethi & 0x003FFFFFU) << 10;
7281 + regs->u_regs[UREG_G1] = addr;
7282 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7283 +
7284 + if (test_thread_flag(TIF_32BIT))
7285 + addr &= 0xFFFFFFFFUL;
7286 +
7287 + regs->tpc = addr;
7288 + regs->tnpc = addr+4;
7289 + return 2;
7290 + }
7291 + } while (0);
7292 +
7293 +#endif
7294 +
7295 + return 1;
7296 +}
7297 +
7298 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7299 +{
7300 + unsigned long i;
7301 +
7302 + printk(KERN_ERR "PAX: bytes at PC: ");
7303 + for (i = 0; i < 8; i++) {
7304 + unsigned int c;
7305 + if (get_user(c, (unsigned int *)pc+i))
7306 + printk(KERN_CONT "???????? ");
7307 + else
7308 + printk(KERN_CONT "%08x ", c);
7309 + }
7310 + printk("\n");
7311 +}
7312 +#endif
7313 +
7314 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7315 {
7316 struct mm_struct *mm = current->mm;
7317 @@ -343,6 +806,29 @@ retry:
7318 if (!vma)
7319 goto bad_area;
7320
7321 +#ifdef CONFIG_PAX_PAGEEXEC
7322 + /* PaX: detect ITLB misses on non-exec pages */
7323 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7324 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7325 + {
7326 + if (address != regs->tpc)
7327 + goto good_area;
7328 +
7329 + up_read(&mm->mmap_sem);
7330 + switch (pax_handle_fetch_fault(regs)) {
7331 +
7332 +#ifdef CONFIG_PAX_EMUPLT
7333 + case 2:
7334 + case 3:
7335 + return;
7336 +#endif
7337 +
7338 + }
7339 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7340 + do_group_exit(SIGKILL);
7341 + }
7342 +#endif
7343 +
7344 /* Pure DTLB misses do not tell us whether the fault causing
7345 * load/store/atomic was a write or not, it only says that there
7346 * was no match. So in such a case we (carefully) read the
7347 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7348 index 07e1453..0a7d9e9 100644
7349 --- a/arch/sparc/mm/hugetlbpage.c
7350 +++ b/arch/sparc/mm/hugetlbpage.c
7351 @@ -67,7 +67,7 @@ full_search:
7352 }
7353 return -ENOMEM;
7354 }
7355 - if (likely(!vma || addr + len <= vma->vm_start)) {
7356 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7357 /*
7358 * Remember the place where we stopped the search:
7359 */
7360 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7361 /* make sure it can fit in the remaining address space */
7362 if (likely(addr > len)) {
7363 vma = find_vma(mm, addr-len);
7364 - if (!vma || addr <= vma->vm_start) {
7365 + if (check_heap_stack_gap(vma, addr - len, len)) {
7366 /* remember the address as a hint for next time */
7367 return (mm->free_area_cache = addr-len);
7368 }
7369 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7370 if (unlikely(mm->mmap_base < len))
7371 goto bottomup;
7372
7373 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7374 + addr = mm->mmap_base - len;
7375
7376 do {
7377 + addr &= HPAGE_MASK;
7378 /*
7379 * Lookup failure means no vma is above this address,
7380 * else if new region fits below vma->vm_start,
7381 * return with success:
7382 */
7383 vma = find_vma(mm, addr);
7384 - if (likely(!vma || addr+len <= vma->vm_start)) {
7385 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7386 /* remember the address as a hint for next time */
7387 return (mm->free_area_cache = addr);
7388 }
7389 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7390 mm->cached_hole_size = vma->vm_start - addr;
7391
7392 /* try just below the current vma->vm_start */
7393 - addr = (vma->vm_start-len) & HPAGE_MASK;
7394 - } while (likely(len < vma->vm_start));
7395 + addr = skip_heap_stack_gap(vma, len);
7396 + } while (!IS_ERR_VALUE(addr));
7397
7398 bottomup:
7399 /*
7400 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7401 if (addr) {
7402 addr = ALIGN(addr, HPAGE_SIZE);
7403 vma = find_vma(mm, addr);
7404 - if (task_size - len >= addr &&
7405 - (!vma || addr + len <= vma->vm_start))
7406 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7407 return addr;
7408 }
7409 if (mm->get_unmapped_area == arch_get_unmapped_area)
7410 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7411 index f4500c6..889656c 100644
7412 --- a/arch/tile/include/asm/atomic_64.h
7413 +++ b/arch/tile/include/asm/atomic_64.h
7414 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7415
7416 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7417
7418 +#define atomic64_read_unchecked(v) atomic64_read(v)
7419 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7420 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7421 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7422 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7423 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7424 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7425 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7426 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7427 +
7428 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7429 #define smp_mb__before_atomic_dec() smp_mb()
7430 #define smp_mb__after_atomic_dec() smp_mb()
7431 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7432 index a9a5299..0fce79e 100644
7433 --- a/arch/tile/include/asm/cache.h
7434 +++ b/arch/tile/include/asm/cache.h
7435 @@ -15,11 +15,12 @@
7436 #ifndef _ASM_TILE_CACHE_H
7437 #define _ASM_TILE_CACHE_H
7438
7439 +#include <linux/const.h>
7440 #include <arch/chip.h>
7441
7442 /* bytes per L1 data cache line */
7443 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7444 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7445 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7446
7447 /* bytes per L2 cache line */
7448 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7449 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7450 index 9ab078a..d6635c2 100644
7451 --- a/arch/tile/include/asm/uaccess.h
7452 +++ b/arch/tile/include/asm/uaccess.h
7453 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7454 const void __user *from,
7455 unsigned long n)
7456 {
7457 - int sz = __compiletime_object_size(to);
7458 + size_t sz = __compiletime_object_size(to);
7459
7460 - if (likely(sz == -1 || sz >= n))
7461 + if (likely(sz == (size_t)-1 || sz >= n))
7462 n = _copy_from_user(to, from, n);
7463 else
7464 copy_from_user_overflow();
7465 diff --git a/arch/um/Makefile b/arch/um/Makefile
7466 index 0970910..9f65c40 100644
7467 --- a/arch/um/Makefile
7468 +++ b/arch/um/Makefile
7469 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7470 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7471 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7472
7473 +ifdef CONSTIFY_PLUGIN
7474 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7475 +endif
7476 +
7477 #This will adjust *FLAGS accordingly to the platform.
7478 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7479
7480 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7481 index 19e1bdd..3665b77 100644
7482 --- a/arch/um/include/asm/cache.h
7483 +++ b/arch/um/include/asm/cache.h
7484 @@ -1,6 +1,7 @@
7485 #ifndef __UM_CACHE_H
7486 #define __UM_CACHE_H
7487
7488 +#include <linux/const.h>
7489
7490 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7491 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7492 @@ -12,6 +13,6 @@
7493 # define L1_CACHE_SHIFT 5
7494 #endif
7495
7496 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7497 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7498
7499 #endif
7500 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7501 index 2e0a6b1..a64d0f5 100644
7502 --- a/arch/um/include/asm/kmap_types.h
7503 +++ b/arch/um/include/asm/kmap_types.h
7504 @@ -8,6 +8,6 @@
7505
7506 /* No more #include "asm/arch/kmap_types.h" ! */
7507
7508 -#define KM_TYPE_NR 14
7509 +#define KM_TYPE_NR 15
7510
7511 #endif
7512 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7513 index 7cfc3ce..cbd1a58 100644
7514 --- a/arch/um/include/asm/page.h
7515 +++ b/arch/um/include/asm/page.h
7516 @@ -14,6 +14,9 @@
7517 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7518 #define PAGE_MASK (~(PAGE_SIZE-1))
7519
7520 +#define ktla_ktva(addr) (addr)
7521 +#define ktva_ktla(addr) (addr)
7522 +
7523 #ifndef __ASSEMBLY__
7524
7525 struct page;
7526 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7527 index 0032f92..cd151e0 100644
7528 --- a/arch/um/include/asm/pgtable-3level.h
7529 +++ b/arch/um/include/asm/pgtable-3level.h
7530 @@ -58,6 +58,7 @@
7531 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7532 #define pud_populate(mm, pud, pmd) \
7533 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7534 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7535
7536 #ifdef CONFIG_64BIT
7537 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7538 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7539 index c5f5afa..6abce4b 100644
7540 --- a/arch/um/kernel/process.c
7541 +++ b/arch/um/kernel/process.c
7542 @@ -402,22 +402,6 @@ int singlestepping(void * t)
7543 return 2;
7544 }
7545
7546 -/*
7547 - * Only x86 and x86_64 have an arch_align_stack().
7548 - * All other arches have "#define arch_align_stack(x) (x)"
7549 - * in their asm/system.h
7550 - * As this is included in UML from asm-um/system-generic.h,
7551 - * we can use it to behave as the subarch does.
7552 - */
7553 -#ifndef arch_align_stack
7554 -unsigned long arch_align_stack(unsigned long sp)
7555 -{
7556 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7557 - sp -= get_random_int() % 8192;
7558 - return sp & ~0xf;
7559 -}
7560 -#endif
7561 -
7562 unsigned long get_wchan(struct task_struct *p)
7563 {
7564 unsigned long stack_page, sp, ip;
7565 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7566 index ad8f795..2c7eec6 100644
7567 --- a/arch/unicore32/include/asm/cache.h
7568 +++ b/arch/unicore32/include/asm/cache.h
7569 @@ -12,8 +12,10 @@
7570 #ifndef __UNICORE_CACHE_H__
7571 #define __UNICORE_CACHE_H__
7572
7573 -#define L1_CACHE_SHIFT (5)
7574 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7575 +#include <linux/const.h>
7576 +
7577 +#define L1_CACHE_SHIFT 5
7578 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7579
7580 /*
7581 * Memory returned by kmalloc() may be used for DMA, so we must make
7582 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7583 index 50a1d1f..c26369f 100644
7584 --- a/arch/x86/Kconfig
7585 +++ b/arch/x86/Kconfig
7586 @@ -220,7 +220,7 @@ config X86_HT
7587
7588 config X86_32_LAZY_GS
7589 def_bool y
7590 - depends on X86_32 && !CC_STACKPROTECTOR
7591 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7592
7593 config ARCH_HWEIGHT_CFLAGS
7594 string
7595 @@ -1049,7 +1049,7 @@ choice
7596
7597 config NOHIGHMEM
7598 bool "off"
7599 - depends on !X86_NUMAQ
7600 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7601 ---help---
7602 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7603 However, the address space of 32-bit x86 processors is only 4
7604 @@ -1086,7 +1086,7 @@ config NOHIGHMEM
7605
7606 config HIGHMEM4G
7607 bool "4GB"
7608 - depends on !X86_NUMAQ
7609 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7610 ---help---
7611 Select this if you have a 32-bit processor and between 1 and 4
7612 gigabytes of physical RAM.
7613 @@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7614 hex
7615 default 0xB0000000 if VMSPLIT_3G_OPT
7616 default 0x80000000 if VMSPLIT_2G
7617 - default 0x78000000 if VMSPLIT_2G_OPT
7618 + default 0x70000000 if VMSPLIT_2G_OPT
7619 default 0x40000000 if VMSPLIT_1G
7620 default 0xC0000000
7621 depends on X86_32
7622 @@ -1528,6 +1528,7 @@ config SECCOMP
7623
7624 config CC_STACKPROTECTOR
7625 bool "Enable -fstack-protector buffer overflow detection"
7626 + depends on X86_64 || !PAX_MEMORY_UDEREF
7627 ---help---
7628 This option turns on the -fstack-protector GCC feature. This
7629 feature puts, at the beginning of functions, a canary value on
7630 @@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7631 config PHYSICAL_START
7632 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7633 default "0x1000000"
7634 + range 0x400000 0x40000000
7635 ---help---
7636 This gives the physical address where the kernel is loaded.
7637
7638 @@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7639 config PHYSICAL_ALIGN
7640 hex "Alignment value to which kernel should be aligned" if X86_32
7641 default "0x1000000"
7642 + range 0x400000 0x1000000 if PAX_KERNEXEC
7643 range 0x2000 0x1000000
7644 ---help---
7645 This value puts the alignment restrictions on physical address
7646 @@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7647 Say N if you want to disable CPU hotplug.
7648
7649 config COMPAT_VDSO
7650 - def_bool y
7651 + def_bool n
7652 prompt "Compat VDSO support"
7653 depends on X86_32 || IA32_EMULATION
7654 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7655 ---help---
7656 Map the 32-bit VDSO to the predictable old-style address too.
7657
7658 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7659 index 706e12e..62e4feb 100644
7660 --- a/arch/x86/Kconfig.cpu
7661 +++ b/arch/x86/Kconfig.cpu
7662 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7663
7664 config X86_F00F_BUG
7665 def_bool y
7666 - depends on M586MMX || M586TSC || M586 || M486 || M386
7667 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7668
7669 config X86_INVD_BUG
7670 def_bool y
7671 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7672
7673 config X86_ALIGNMENT_16
7674 def_bool y
7675 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7676 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7677
7678 config X86_INTEL_USERCOPY
7679 def_bool y
7680 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7681 # generates cmov.
7682 config X86_CMOV
7683 def_bool y
7684 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7685 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7686
7687 config X86_MINIMUM_CPU_FAMILY
7688 int
7689 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7690 index b322f12..652d0d9 100644
7691 --- a/arch/x86/Kconfig.debug
7692 +++ b/arch/x86/Kconfig.debug
7693 @@ -84,7 +84,7 @@ config X86_PTDUMP
7694 config DEBUG_RODATA
7695 bool "Write protect kernel read-only data structures"
7696 default y
7697 - depends on DEBUG_KERNEL
7698 + depends on DEBUG_KERNEL && BROKEN
7699 ---help---
7700 Mark the kernel read-only data as write-protected in the pagetables,
7701 in order to catch accidental (and incorrect) writes to such const
7702 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7703
7704 config DEBUG_SET_MODULE_RONX
7705 bool "Set loadable kernel module data as NX and text as RO"
7706 - depends on MODULES
7707 + depends on MODULES && BROKEN
7708 ---help---
7709 This option helps catch unintended modifications to loadable
7710 kernel module's text and read-only data. It also prevents execution
7711 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7712
7713 config DEBUG_STRICT_USER_COPY_CHECKS
7714 bool "Strict copy size checks"
7715 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7716 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7717 ---help---
7718 Enabling this option turns a certain set of sanity checks for user
7719 copy operations into compile time failures.
7720 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7721 index 05afcca..b6ecb51 100644
7722 --- a/arch/x86/Makefile
7723 +++ b/arch/x86/Makefile
7724 @@ -50,6 +50,7 @@ else
7725 UTS_MACHINE := x86_64
7726 CHECKFLAGS += -D__x86_64__ -m64
7727
7728 + biarch := $(call cc-option,-m64)
7729 KBUILD_AFLAGS += -m64
7730 KBUILD_CFLAGS += -m64
7731
7732 @@ -229,3 +230,12 @@ define archhelp
7733 echo ' FDARGS="..." arguments for the booted kernel'
7734 echo ' FDINITRD=file initrd for the booted kernel'
7735 endef
7736 +
7737 +define OLD_LD
7738 +
7739 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7740 +*** Please upgrade your binutils to 2.18 or newer
7741 +endef
7742 +
7743 +archprepare:
7744 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7745 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7746 index f7535be..37db2d1 100644
7747 --- a/arch/x86/boot/Makefile
7748 +++ b/arch/x86/boot/Makefile
7749 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7750 $(call cc-option, -fno-stack-protector) \
7751 $(call cc-option, -mpreferred-stack-boundary=2)
7752 KBUILD_CFLAGS += $(call cc-option, -m32)
7753 +ifdef CONSTIFY_PLUGIN
7754 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7755 +endif
7756 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7757 GCOV_PROFILE := n
7758
7759 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7760 index 878e4b9..20537ab 100644
7761 --- a/arch/x86/boot/bitops.h
7762 +++ b/arch/x86/boot/bitops.h
7763 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7764 u8 v;
7765 const u32 *p = (const u32 *)addr;
7766
7767 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7768 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7769 return v;
7770 }
7771
7772 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7773
7774 static inline void set_bit(int nr, void *addr)
7775 {
7776 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7777 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7778 }
7779
7780 #endif /* BOOT_BITOPS_H */
7781 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7782 index 18997e5..83d9c67 100644
7783 --- a/arch/x86/boot/boot.h
7784 +++ b/arch/x86/boot/boot.h
7785 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7786 static inline u16 ds(void)
7787 {
7788 u16 seg;
7789 - asm("movw %%ds,%0" : "=rm" (seg));
7790 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7791 return seg;
7792 }
7793
7794 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7795 static inline int memcmp(const void *s1, const void *s2, size_t len)
7796 {
7797 u8 diff;
7798 - asm("repe; cmpsb; setnz %0"
7799 + asm volatile("repe; cmpsb; setnz %0"
7800 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7801 return diff;
7802 }
7803 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7804 index 8a84501..b2d165f 100644
7805 --- a/arch/x86/boot/compressed/Makefile
7806 +++ b/arch/x86/boot/compressed/Makefile
7807 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7808 KBUILD_CFLAGS += $(cflags-y)
7809 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7810 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7811 +ifdef CONSTIFY_PLUGIN
7812 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7813 +endif
7814
7815 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7816 GCOV_PROFILE := n
7817 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7818 index b3e0227..f2c02d5 100644
7819 --- a/arch/x86/boot/compressed/eboot.c
7820 +++ b/arch/x86/boot/compressed/eboot.c
7821 @@ -142,7 +142,6 @@ again:
7822 *addr = max_addr;
7823 }
7824
7825 -free_pool:
7826 efi_call_phys1(sys_table->boottime->free_pool, map);
7827
7828 fail:
7829 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7830 if (i == map_size / desc_size)
7831 status = EFI_NOT_FOUND;
7832
7833 -free_pool:
7834 efi_call_phys1(sys_table->boottime->free_pool, map);
7835 fail:
7836 return status;
7837 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7838 index aa4aaf1..6656f2f 100644
7839 --- a/arch/x86/boot/compressed/head_32.S
7840 +++ b/arch/x86/boot/compressed/head_32.S
7841 @@ -116,7 +116,7 @@ preferred_addr:
7842 notl %eax
7843 andl %eax, %ebx
7844 #else
7845 - movl $LOAD_PHYSICAL_ADDR, %ebx
7846 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7847 #endif
7848
7849 /* Target address to relocate to for decompression */
7850 @@ -202,7 +202,7 @@ relocated:
7851 * and where it was actually loaded.
7852 */
7853 movl %ebp, %ebx
7854 - subl $LOAD_PHYSICAL_ADDR, %ebx
7855 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7856 jz 2f /* Nothing to be done if loaded at compiled addr. */
7857 /*
7858 * Process relocations.
7859 @@ -210,8 +210,7 @@ relocated:
7860
7861 1: subl $4, %edi
7862 movl (%edi), %ecx
7863 - testl %ecx, %ecx
7864 - jz 2f
7865 + jecxz 2f
7866 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7867 jmp 1b
7868 2:
7869 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7870 index 2c4b171..e1fa5b1 100644
7871 --- a/arch/x86/boot/compressed/head_64.S
7872 +++ b/arch/x86/boot/compressed/head_64.S
7873 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7874 notl %eax
7875 andl %eax, %ebx
7876 #else
7877 - movl $LOAD_PHYSICAL_ADDR, %ebx
7878 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7879 #endif
7880
7881 /* Target address to relocate to for decompression */
7882 @@ -273,7 +273,7 @@ preferred_addr:
7883 notq %rax
7884 andq %rax, %rbp
7885 #else
7886 - movq $LOAD_PHYSICAL_ADDR, %rbp
7887 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7888 #endif
7889
7890 /* Target address to relocate to for decompression */
7891 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7892 index 88f7ff6..ed695dd 100644
7893 --- a/arch/x86/boot/compressed/misc.c
7894 +++ b/arch/x86/boot/compressed/misc.c
7895 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
7896 case PT_LOAD:
7897 #ifdef CONFIG_RELOCATABLE
7898 dest = output;
7899 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7900 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7901 #else
7902 dest = (void *)(phdr->p_paddr);
7903 #endif
7904 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7905 error("Destination address too large");
7906 #endif
7907 #ifndef CONFIG_RELOCATABLE
7908 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7909 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7910 error("Wrong destination address");
7911 #endif
7912
7913 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7914 index 4d3ff03..e4972ff 100644
7915 --- a/arch/x86/boot/cpucheck.c
7916 +++ b/arch/x86/boot/cpucheck.c
7917 @@ -74,7 +74,7 @@ static int has_fpu(void)
7918 u16 fcw = -1, fsw = -1;
7919 u32 cr0;
7920
7921 - asm("movl %%cr0,%0" : "=r" (cr0));
7922 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7923 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7924 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7925 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7926 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7927 {
7928 u32 f0, f1;
7929
7930 - asm("pushfl ; "
7931 + asm volatile("pushfl ; "
7932 "pushfl ; "
7933 "popl %0 ; "
7934 "movl %0,%1 ; "
7935 @@ -115,7 +115,7 @@ static void get_flags(void)
7936 set_bit(X86_FEATURE_FPU, cpu.flags);
7937
7938 if (has_eflag(X86_EFLAGS_ID)) {
7939 - asm("cpuid"
7940 + asm volatile("cpuid"
7941 : "=a" (max_intel_level),
7942 "=b" (cpu_vendor[0]),
7943 "=d" (cpu_vendor[1]),
7944 @@ -124,7 +124,7 @@ static void get_flags(void)
7945
7946 if (max_intel_level >= 0x00000001 &&
7947 max_intel_level <= 0x0000ffff) {
7948 - asm("cpuid"
7949 + asm volatile("cpuid"
7950 : "=a" (tfms),
7951 "=c" (cpu.flags[4]),
7952 "=d" (cpu.flags[0])
7953 @@ -136,7 +136,7 @@ static void get_flags(void)
7954 cpu.model += ((tfms >> 16) & 0xf) << 4;
7955 }
7956
7957 - asm("cpuid"
7958 + asm volatile("cpuid"
7959 : "=a" (max_amd_level)
7960 : "a" (0x80000000)
7961 : "ebx", "ecx", "edx");
7962 @@ -144,7 +144,7 @@ static void get_flags(void)
7963 if (max_amd_level >= 0x80000001 &&
7964 max_amd_level <= 0x8000ffff) {
7965 u32 eax = 0x80000001;
7966 - asm("cpuid"
7967 + asm volatile("cpuid"
7968 : "+a" (eax),
7969 "=c" (cpu.flags[6]),
7970 "=d" (cpu.flags[1])
7971 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7972 u32 ecx = MSR_K7_HWCR;
7973 u32 eax, edx;
7974
7975 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7976 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7977 eax &= ~(1 << 15);
7978 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7979 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7980
7981 get_flags(); /* Make sure it really did something */
7982 err = check_flags();
7983 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7984 u32 ecx = MSR_VIA_FCR;
7985 u32 eax, edx;
7986
7987 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7988 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7989 eax |= (1<<1)|(1<<7);
7990 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7991 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7992
7993 set_bit(X86_FEATURE_CX8, cpu.flags);
7994 err = check_flags();
7995 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7996 u32 eax, edx;
7997 u32 level = 1;
7998
7999 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8000 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8001 - asm("cpuid"
8002 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8003 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8004 + asm volatile("cpuid"
8005 : "+a" (level), "=d" (cpu.flags[0])
8006 : : "ecx", "ebx");
8007 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8008 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8009
8010 err = check_flags();
8011 }
8012 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8013 index b4e15dd..8ac59ce 100644
8014 --- a/arch/x86/boot/header.S
8015 +++ b/arch/x86/boot/header.S
8016 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
8017 # single linked list of
8018 # struct setup_data
8019
8020 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8021 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8022
8023 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8024 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8025 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8026 +#else
8027 #define VO_INIT_SIZE (VO__end - VO__text)
8028 +#endif
8029 #if ZO_INIT_SIZE > VO_INIT_SIZE
8030 #define INIT_SIZE ZO_INIT_SIZE
8031 #else
8032 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8033 index db75d07..8e6d0af 100644
8034 --- a/arch/x86/boot/memory.c
8035 +++ b/arch/x86/boot/memory.c
8036 @@ -19,7 +19,7 @@
8037
8038 static int detect_memory_e820(void)
8039 {
8040 - int count = 0;
8041 + unsigned int count = 0;
8042 struct biosregs ireg, oreg;
8043 struct e820entry *desc = boot_params.e820_map;
8044 static struct e820entry buf; /* static so it is zeroed */
8045 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8046 index 11e8c6e..fdbb1ed 100644
8047 --- a/arch/x86/boot/video-vesa.c
8048 +++ b/arch/x86/boot/video-vesa.c
8049 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8050
8051 boot_params.screen_info.vesapm_seg = oreg.es;
8052 boot_params.screen_info.vesapm_off = oreg.di;
8053 + boot_params.screen_info.vesapm_size = oreg.cx;
8054 }
8055
8056 /*
8057 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8058 index 43eda28..5ab5fdb 100644
8059 --- a/arch/x86/boot/video.c
8060 +++ b/arch/x86/boot/video.c
8061 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8062 static unsigned int get_entry(void)
8063 {
8064 char entry_buf[4];
8065 - int i, len = 0;
8066 + unsigned int i, len = 0;
8067 int key;
8068 unsigned int v;
8069
8070 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8071 index 5b577d5..3c1fed4 100644
8072 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8073 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8074 @@ -8,6 +8,8 @@
8075 * including this sentence is retained in full.
8076 */
8077
8078 +#include <asm/alternative-asm.h>
8079 +
8080 .extern crypto_ft_tab
8081 .extern crypto_it_tab
8082 .extern crypto_fl_tab
8083 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8084 je B192; \
8085 leaq 32(r9),r9;
8086
8087 +#define ret pax_force_retaddr 0, 1; ret
8088 +
8089 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8090 movq r1,r2; \
8091 movq r3,r4; \
8092 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8093 index 3470624..201259d 100644
8094 --- a/arch/x86/crypto/aesni-intel_asm.S
8095 +++ b/arch/x86/crypto/aesni-intel_asm.S
8096 @@ -31,6 +31,7 @@
8097
8098 #include <linux/linkage.h>
8099 #include <asm/inst.h>
8100 +#include <asm/alternative-asm.h>
8101
8102 #ifdef __x86_64__
8103 .data
8104 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8105 pop %r14
8106 pop %r13
8107 pop %r12
8108 + pax_force_retaddr 0, 1
8109 ret
8110 +ENDPROC(aesni_gcm_dec)
8111
8112
8113 /*****************************************************************************
8114 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8115 pop %r14
8116 pop %r13
8117 pop %r12
8118 + pax_force_retaddr 0, 1
8119 ret
8120 +ENDPROC(aesni_gcm_enc)
8121
8122 #endif
8123
8124 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8125 pxor %xmm1, %xmm0
8126 movaps %xmm0, (TKEYP)
8127 add $0x10, TKEYP
8128 + pax_force_retaddr_bts
8129 ret
8130
8131 .align 4
8132 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8133 shufps $0b01001110, %xmm2, %xmm1
8134 movaps %xmm1, 0x10(TKEYP)
8135 add $0x20, TKEYP
8136 + pax_force_retaddr_bts
8137 ret
8138
8139 .align 4
8140 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8141
8142 movaps %xmm0, (TKEYP)
8143 add $0x10, TKEYP
8144 + pax_force_retaddr_bts
8145 ret
8146
8147 .align 4
8148 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8149 pxor %xmm1, %xmm2
8150 movaps %xmm2, (TKEYP)
8151 add $0x10, TKEYP
8152 + pax_force_retaddr_bts
8153 ret
8154
8155 /*
8156 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8157 #ifndef __x86_64__
8158 popl KEYP
8159 #endif
8160 + pax_force_retaddr 0, 1
8161 ret
8162 +ENDPROC(aesni_set_key)
8163
8164 /*
8165 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8166 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8167 popl KLEN
8168 popl KEYP
8169 #endif
8170 + pax_force_retaddr 0, 1
8171 ret
8172 +ENDPROC(aesni_enc)
8173
8174 /*
8175 * _aesni_enc1: internal ABI
8176 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8177 AESENC KEY STATE
8178 movaps 0x70(TKEYP), KEY
8179 AESENCLAST KEY STATE
8180 + pax_force_retaddr_bts
8181 ret
8182
8183 /*
8184 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8185 AESENCLAST KEY STATE2
8186 AESENCLAST KEY STATE3
8187 AESENCLAST KEY STATE4
8188 + pax_force_retaddr_bts
8189 ret
8190
8191 /*
8192 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8193 popl KLEN
8194 popl KEYP
8195 #endif
8196 + pax_force_retaddr 0, 1
8197 ret
8198 +ENDPROC(aesni_dec)
8199
8200 /*
8201 * _aesni_dec1: internal ABI
8202 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8203 AESDEC KEY STATE
8204 movaps 0x70(TKEYP), KEY
8205 AESDECLAST KEY STATE
8206 + pax_force_retaddr_bts
8207 ret
8208
8209 /*
8210 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8211 AESDECLAST KEY STATE2
8212 AESDECLAST KEY STATE3
8213 AESDECLAST KEY STATE4
8214 + pax_force_retaddr_bts
8215 ret
8216
8217 /*
8218 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8219 popl KEYP
8220 popl LEN
8221 #endif
8222 + pax_force_retaddr 0, 1
8223 ret
8224 +ENDPROC(aesni_ecb_enc)
8225
8226 /*
8227 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8228 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8229 popl KEYP
8230 popl LEN
8231 #endif
8232 + pax_force_retaddr 0, 1
8233 ret
8234 +ENDPROC(aesni_ecb_dec)
8235
8236 /*
8237 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8238 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8239 popl LEN
8240 popl IVP
8241 #endif
8242 + pax_force_retaddr 0, 1
8243 ret
8244 +ENDPROC(aesni_cbc_enc)
8245
8246 /*
8247 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8248 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8249 popl LEN
8250 popl IVP
8251 #endif
8252 + pax_force_retaddr 0, 1
8253 ret
8254 +ENDPROC(aesni_cbc_dec)
8255
8256 #ifdef __x86_64__
8257 .align 16
8258 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8259 mov $1, TCTR_LOW
8260 MOVQ_R64_XMM TCTR_LOW INC
8261 MOVQ_R64_XMM CTR TCTR_LOW
8262 + pax_force_retaddr_bts
8263 ret
8264
8265 /*
8266 @@ -2554,6 +2582,7 @@ _aesni_inc:
8267 .Linc_low:
8268 movaps CTR, IV
8269 PSHUFB_XMM BSWAP_MASK IV
8270 + pax_force_retaddr_bts
8271 ret
8272
8273 /*
8274 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8275 .Lctr_enc_ret:
8276 movups IV, (IVP)
8277 .Lctr_enc_just_ret:
8278 + pax_force_retaddr 0, 1
8279 ret
8280 +ENDPROC(aesni_ctr_enc)
8281 #endif
8282 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8283 index 391d245..67f35c2 100644
8284 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8285 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8286 @@ -20,6 +20,8 @@
8287 *
8288 */
8289
8290 +#include <asm/alternative-asm.h>
8291 +
8292 .file "blowfish-x86_64-asm.S"
8293 .text
8294
8295 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8296 jnz __enc_xor;
8297
8298 write_block();
8299 + pax_force_retaddr 0, 1
8300 ret;
8301 __enc_xor:
8302 xor_block();
8303 + pax_force_retaddr 0, 1
8304 ret;
8305
8306 .align 8
8307 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8308
8309 movq %r11, %rbp;
8310
8311 + pax_force_retaddr 0, 1
8312 ret;
8313
8314 /**********************************************************************
8315 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8316
8317 popq %rbx;
8318 popq %rbp;
8319 + pax_force_retaddr 0, 1
8320 ret;
8321
8322 __enc_xor4:
8323 @@ -349,6 +355,7 @@ __enc_xor4:
8324
8325 popq %rbx;
8326 popq %rbp;
8327 + pax_force_retaddr 0, 1
8328 ret;
8329
8330 .align 8
8331 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8332 popq %rbx;
8333 popq %rbp;
8334
8335 + pax_force_retaddr 0, 1
8336 ret;
8337
8338 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8339 index 0b33743..7a56206 100644
8340 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8341 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8342 @@ -20,6 +20,8 @@
8343 *
8344 */
8345
8346 +#include <asm/alternative-asm.h>
8347 +
8348 .file "camellia-x86_64-asm_64.S"
8349 .text
8350
8351 @@ -229,12 +231,14 @@ __enc_done:
8352 enc_outunpack(mov, RT1);
8353
8354 movq RRBP, %rbp;
8355 + pax_force_retaddr 0, 1
8356 ret;
8357
8358 __enc_xor:
8359 enc_outunpack(xor, RT1);
8360
8361 movq RRBP, %rbp;
8362 + pax_force_retaddr 0, 1
8363 ret;
8364
8365 .global camellia_dec_blk;
8366 @@ -275,6 +279,7 @@ __dec_rounds16:
8367 dec_outunpack();
8368
8369 movq RRBP, %rbp;
8370 + pax_force_retaddr 0, 1
8371 ret;
8372
8373 /**********************************************************************
8374 @@ -468,6 +473,7 @@ __enc2_done:
8375
8376 movq RRBP, %rbp;
8377 popq %rbx;
8378 + pax_force_retaddr 0, 1
8379 ret;
8380
8381 __enc2_xor:
8382 @@ -475,6 +481,7 @@ __enc2_xor:
8383
8384 movq RRBP, %rbp;
8385 popq %rbx;
8386 + pax_force_retaddr 0, 1
8387 ret;
8388
8389 .global camellia_dec_blk_2way;
8390 @@ -517,4 +524,5 @@ __dec2_rounds16:
8391
8392 movq RRBP, %rbp;
8393 movq RXOR, %rbx;
8394 + pax_force_retaddr 0, 1
8395 ret;
8396 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8397 index 6214a9b..1f4fc9a 100644
8398 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8399 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8400 @@ -1,3 +1,5 @@
8401 +#include <asm/alternative-asm.h>
8402 +
8403 # enter ECRYPT_encrypt_bytes
8404 .text
8405 .p2align 5
8406 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8407 add %r11,%rsp
8408 mov %rdi,%rax
8409 mov %rsi,%rdx
8410 + pax_force_retaddr 0, 1
8411 ret
8412 # bytesatleast65:
8413 ._bytesatleast65:
8414 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8415 add %r11,%rsp
8416 mov %rdi,%rax
8417 mov %rsi,%rdx
8418 + pax_force_retaddr
8419 ret
8420 # enter ECRYPT_ivsetup
8421 .text
8422 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8423 add %r11,%rsp
8424 mov %rdi,%rax
8425 mov %rsi,%rdx
8426 + pax_force_retaddr
8427 ret
8428 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8429 index 504106b..4e50951 100644
8430 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8431 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8432 @@ -24,6 +24,8 @@
8433 *
8434 */
8435
8436 +#include <asm/alternative-asm.h>
8437 +
8438 .file "serpent-avx-x86_64-asm_64.S"
8439 .text
8440
8441 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8442 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8443 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8444
8445 + pax_force_retaddr
8446 ret;
8447
8448 __enc_xor8:
8449 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8450 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8451
8452 + pax_force_retaddr
8453 ret;
8454
8455 .align 8
8456 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8457 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8458 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8459
8460 + pax_force_retaddr
8461 ret;
8462 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8463 index 3ee1ff0..cbc568b 100644
8464 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8465 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8466 @@ -24,6 +24,8 @@
8467 *
8468 */
8469
8470 +#include <asm/alternative-asm.h>
8471 +
8472 .file "serpent-sse2-x86_64-asm_64.S"
8473 .text
8474
8475 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8476 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8477 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8478
8479 + pax_force_retaddr
8480 ret;
8481
8482 __enc_xor8:
8483 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8484 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8485
8486 + pax_force_retaddr
8487 ret;
8488
8489 .align 8
8490 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8491 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8492 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8493
8494 + pax_force_retaddr
8495 ret;
8496 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8497 index 49d6987..df66bd4 100644
8498 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8499 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8500 @@ -28,6 +28,8 @@
8501 * (at your option) any later version.
8502 */
8503
8504 +#include <asm/alternative-asm.h>
8505 +
8506 #define CTX %rdi // arg1
8507 #define BUF %rsi // arg2
8508 #define CNT %rdx // arg3
8509 @@ -104,6 +106,7 @@
8510 pop %r12
8511 pop %rbp
8512 pop %rbx
8513 + pax_force_retaddr 0, 1
8514 ret
8515
8516 .size \name, .-\name
8517 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8518 index 35f4557..16b379f 100644
8519 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8520 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8521 @@ -21,6 +21,8 @@
8522 *
8523 */
8524
8525 +#include <asm/alternative-asm.h>
8526 +
8527 .file "twofish-avx-x86_64-asm_64.S"
8528 .text
8529
8530 @@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8531 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8532 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8533
8534 + pax_force_retaddr
8535 ret;
8536
8537 __enc_xor8:
8538 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8539 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8540
8541 + pax_force_retaddr
8542 ret;
8543
8544 .align 8
8545 @@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8546 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8547 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8548
8549 + pax_force_retaddr
8550 ret;
8551 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8552 index 5b012a2..36d5364 100644
8553 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8554 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8555 @@ -20,6 +20,8 @@
8556 *
8557 */
8558
8559 +#include <asm/alternative-asm.h>
8560 +
8561 .file "twofish-x86_64-asm-3way.S"
8562 .text
8563
8564 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8565 popq %r13;
8566 popq %r14;
8567 popq %r15;
8568 + pax_force_retaddr 0, 1
8569 ret;
8570
8571 __enc_xor3:
8572 @@ -271,6 +274,7 @@ __enc_xor3:
8573 popq %r13;
8574 popq %r14;
8575 popq %r15;
8576 + pax_force_retaddr 0, 1
8577 ret;
8578
8579 .global twofish_dec_blk_3way
8580 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8581 popq %r13;
8582 popq %r14;
8583 popq %r15;
8584 + pax_force_retaddr 0, 1
8585 ret;
8586
8587 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8588 index 7bcf3fc..f53832f 100644
8589 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8590 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8591 @@ -21,6 +21,7 @@
8592 .text
8593
8594 #include <asm/asm-offsets.h>
8595 +#include <asm/alternative-asm.h>
8596
8597 #define a_offset 0
8598 #define b_offset 4
8599 @@ -268,6 +269,7 @@ twofish_enc_blk:
8600
8601 popq R1
8602 movq $1,%rax
8603 + pax_force_retaddr 0, 1
8604 ret
8605
8606 twofish_dec_blk:
8607 @@ -319,4 +321,5 @@ twofish_dec_blk:
8608
8609 popq R1
8610 movq $1,%rax
8611 + pax_force_retaddr 0, 1
8612 ret
8613 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8614 index 07b3a68..bd2a388 100644
8615 --- a/arch/x86/ia32/ia32_aout.c
8616 +++ b/arch/x86/ia32/ia32_aout.c
8617 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8618 unsigned long dump_start, dump_size;
8619 struct user32 dump;
8620
8621 + memset(&dump, 0, sizeof(dump));
8622 +
8623 fs = get_fs();
8624 set_fs(KERNEL_DS);
8625 has_dumped = 1;
8626 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8627 index 673ac9b..7a8c5df 100644
8628 --- a/arch/x86/ia32/ia32_signal.c
8629 +++ b/arch/x86/ia32/ia32_signal.c
8630 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8631 }
8632 seg = get_fs();
8633 set_fs(KERNEL_DS);
8634 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8635 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8636 set_fs(seg);
8637 if (ret >= 0 && uoss_ptr) {
8638 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8639 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8640 */
8641 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8642 size_t frame_size,
8643 - void **fpstate)
8644 + void __user **fpstate)
8645 {
8646 unsigned long sp;
8647
8648 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8649
8650 if (used_math()) {
8651 sp = sp - sig_xstate_ia32_size;
8652 - *fpstate = (struct _fpstate_ia32 *) sp;
8653 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8654 if (save_i387_xstate_ia32(*fpstate) < 0)
8655 return (void __user *) -1L;
8656 }
8657 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8658 sp -= frame_size;
8659 /* Align the stack pointer according to the i386 ABI,
8660 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8661 - sp = ((sp + 4) & -16ul) - 4;
8662 + sp = ((sp - 12) & -16ul) - 4;
8663 return (void __user *) sp;
8664 }
8665
8666 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8667 * These are actually not used anymore, but left because some
8668 * gdb versions depend on them as a marker.
8669 */
8670 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8671 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8672 } put_user_catch(err);
8673
8674 if (err)
8675 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8676 0xb8,
8677 __NR_ia32_rt_sigreturn,
8678 0x80cd,
8679 - 0,
8680 + 0
8681 };
8682
8683 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8684 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8685
8686 if (ka->sa.sa_flags & SA_RESTORER)
8687 restorer = ka->sa.sa_restorer;
8688 + else if (current->mm->context.vdso)
8689 + /* Return stub is in 32bit vsyscall page */
8690 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8691 else
8692 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8693 - rt_sigreturn);
8694 + restorer = &frame->retcode;
8695 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8696
8697 /*
8698 * Not actually used anymore, but left because some gdb
8699 * versions need it.
8700 */
8701 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8702 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8703 } put_user_catch(err);
8704
8705 if (err)
8706 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8707 index 20e5f7b..f33c779 100644
8708 --- a/arch/x86/ia32/ia32entry.S
8709 +++ b/arch/x86/ia32/ia32entry.S
8710 @@ -14,8 +14,10 @@
8711 #include <asm/segment.h>
8712 #include <asm/irqflags.h>
8713 #include <asm/asm.h>
8714 +#include <asm/pgtable.h>
8715 #include <linux/linkage.h>
8716 #include <linux/err.h>
8717 +#include <asm/alternative-asm.h>
8718
8719 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8720 #include <linux/elf-em.h>
8721 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8722 ENDPROC(native_irq_enable_sysexit)
8723 #endif
8724
8725 + .macro pax_enter_kernel_user
8726 + pax_set_fptr_mask
8727 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8728 + call pax_enter_kernel_user
8729 +#endif
8730 + .endm
8731 +
8732 + .macro pax_exit_kernel_user
8733 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8734 + call pax_exit_kernel_user
8735 +#endif
8736 +#ifdef CONFIG_PAX_RANDKSTACK
8737 + pushq %rax
8738 + pushq %r11
8739 + call pax_randomize_kstack
8740 + popq %r11
8741 + popq %rax
8742 +#endif
8743 + .endm
8744 +
8745 +.macro pax_erase_kstack
8746 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8747 + call pax_erase_kstack
8748 +#endif
8749 +.endm
8750 +
8751 /*
8752 * 32bit SYSENTER instruction entry.
8753 *
8754 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8755 CFI_REGISTER rsp,rbp
8756 SWAPGS_UNSAFE_STACK
8757 movq PER_CPU_VAR(kernel_stack), %rsp
8758 - addq $(KERNEL_STACK_OFFSET),%rsp
8759 - /*
8760 - * No need to follow this irqs on/off section: the syscall
8761 - * disabled irqs, here we enable it straight after entry:
8762 - */
8763 - ENABLE_INTERRUPTS(CLBR_NONE)
8764 movl %ebp,%ebp /* zero extension */
8765 pushq_cfi $__USER32_DS
8766 /*CFI_REL_OFFSET ss,0*/
8767 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8768 CFI_REL_OFFSET rsp,0
8769 pushfq_cfi
8770 /*CFI_REL_OFFSET rflags,0*/
8771 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8772 - CFI_REGISTER rip,r10
8773 + orl $X86_EFLAGS_IF,(%rsp)
8774 + GET_THREAD_INFO(%r11)
8775 + movl TI_sysenter_return(%r11), %r11d
8776 + CFI_REGISTER rip,r11
8777 pushq_cfi $__USER32_CS
8778 /*CFI_REL_OFFSET cs,0*/
8779 movl %eax, %eax
8780 - pushq_cfi %r10
8781 + pushq_cfi %r11
8782 CFI_REL_OFFSET rip,0
8783 pushq_cfi %rax
8784 cld
8785 SAVE_ARGS 0,1,0
8786 + pax_enter_kernel_user
8787 +
8788 +#ifdef CONFIG_PAX_RANDKSTACK
8789 + pax_erase_kstack
8790 +#endif
8791 +
8792 + /*
8793 + * No need to follow this irqs on/off section: the syscall
8794 + * disabled irqs, here we enable it straight after entry:
8795 + */
8796 + ENABLE_INTERRUPTS(CLBR_NONE)
8797 /* no need to do an access_ok check here because rbp has been
8798 32bit zero extended */
8799 +
8800 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8801 + mov $PAX_USER_SHADOW_BASE,%r11
8802 + add %r11,%rbp
8803 +#endif
8804 +
8805 1: movl (%rbp),%ebp
8806 _ASM_EXTABLE(1b,ia32_badarg)
8807 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8808 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8809 + GET_THREAD_INFO(%r11)
8810 + orl $TS_COMPAT,TI_status(%r11)
8811 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8812 CFI_REMEMBER_STATE
8813 jnz sysenter_tracesys
8814 cmpq $(IA32_NR_syscalls-1),%rax
8815 @@ -159,12 +201,15 @@ sysenter_do_call:
8816 sysenter_dispatch:
8817 call *ia32_sys_call_table(,%rax,8)
8818 movq %rax,RAX-ARGOFFSET(%rsp)
8819 + GET_THREAD_INFO(%r11)
8820 DISABLE_INTERRUPTS(CLBR_NONE)
8821 TRACE_IRQS_OFF
8822 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8823 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8824 jnz sysexit_audit
8825 sysexit_from_sys_call:
8826 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8827 + pax_exit_kernel_user
8828 + pax_erase_kstack
8829 + andl $~TS_COMPAT,TI_status(%r11)
8830 /* clear IF, that popfq doesn't enable interrupts early */
8831 andl $~0x200,EFLAGS-R11(%rsp)
8832 movl RIP-R11(%rsp),%edx /* User %eip */
8833 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8834 movl %eax,%esi /* 2nd arg: syscall number */
8835 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8836 call __audit_syscall_entry
8837 +
8838 + pax_erase_kstack
8839 +
8840 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8841 cmpq $(IA32_NR_syscalls-1),%rax
8842 ja ia32_badsys
8843 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8844 .endm
8845
8846 .macro auditsys_exit exit
8847 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8848 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8849 jnz ia32_ret_from_sys_call
8850 TRACE_IRQS_ON
8851 sti
8852 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8853 1: setbe %al /* 1 if error, 0 if not */
8854 movzbl %al,%edi /* zero-extend that into %edi */
8855 call __audit_syscall_exit
8856 + GET_THREAD_INFO(%r11)
8857 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8858 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8859 cli
8860 TRACE_IRQS_OFF
8861 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8862 + testl %edi,TI_flags(%r11)
8863 jz \exit
8864 CLEAR_RREGS -ARGOFFSET
8865 jmp int_with_check
8866 @@ -234,7 +283,7 @@ sysexit_audit:
8867
8868 sysenter_tracesys:
8869 #ifdef CONFIG_AUDITSYSCALL
8870 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8871 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8872 jz sysenter_auditsys
8873 #endif
8874 SAVE_REST
8875 @@ -246,6 +295,9 @@ sysenter_tracesys:
8876 RESTORE_REST
8877 cmpq $(IA32_NR_syscalls-1),%rax
8878 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8879 +
8880 + pax_erase_kstack
8881 +
8882 jmp sysenter_do_call
8883 CFI_ENDPROC
8884 ENDPROC(ia32_sysenter_target)
8885 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8886 ENTRY(ia32_cstar_target)
8887 CFI_STARTPROC32 simple
8888 CFI_SIGNAL_FRAME
8889 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8890 + CFI_DEF_CFA rsp,0
8891 CFI_REGISTER rip,rcx
8892 /*CFI_REGISTER rflags,r11*/
8893 SWAPGS_UNSAFE_STACK
8894 movl %esp,%r8d
8895 CFI_REGISTER rsp,r8
8896 movq PER_CPU_VAR(kernel_stack),%rsp
8897 + SAVE_ARGS 8*6,0,0
8898 + pax_enter_kernel_user
8899 +
8900 +#ifdef CONFIG_PAX_RANDKSTACK
8901 + pax_erase_kstack
8902 +#endif
8903 +
8904 /*
8905 * No need to follow this irqs on/off section: the syscall
8906 * disabled irqs and here we enable it straight after entry:
8907 */
8908 ENABLE_INTERRUPTS(CLBR_NONE)
8909 - SAVE_ARGS 8,0,0
8910 movl %eax,%eax /* zero extension */
8911 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8912 movq %rcx,RIP-ARGOFFSET(%rsp)
8913 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8914 /* no need to do an access_ok check here because r8 has been
8915 32bit zero extended */
8916 /* hardware stack frame is complete now */
8917 +
8918 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8919 + mov $PAX_USER_SHADOW_BASE,%r11
8920 + add %r11,%r8
8921 +#endif
8922 +
8923 1: movl (%r8),%r9d
8924 _ASM_EXTABLE(1b,ia32_badarg)
8925 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8926 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8927 + GET_THREAD_INFO(%r11)
8928 + orl $TS_COMPAT,TI_status(%r11)
8929 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8930 CFI_REMEMBER_STATE
8931 jnz cstar_tracesys
8932 cmpq $IA32_NR_syscalls-1,%rax
8933 @@ -314,12 +379,15 @@ cstar_do_call:
8934 cstar_dispatch:
8935 call *ia32_sys_call_table(,%rax,8)
8936 movq %rax,RAX-ARGOFFSET(%rsp)
8937 + GET_THREAD_INFO(%r11)
8938 DISABLE_INTERRUPTS(CLBR_NONE)
8939 TRACE_IRQS_OFF
8940 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8941 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8942 jnz sysretl_audit
8943 sysretl_from_sys_call:
8944 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8945 + pax_exit_kernel_user
8946 + pax_erase_kstack
8947 + andl $~TS_COMPAT,TI_status(%r11)
8948 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8949 movl RIP-ARGOFFSET(%rsp),%ecx
8950 CFI_REGISTER rip,rcx
8951 @@ -347,7 +415,7 @@ sysretl_audit:
8952
8953 cstar_tracesys:
8954 #ifdef CONFIG_AUDITSYSCALL
8955 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8956 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8957 jz cstar_auditsys
8958 #endif
8959 xchgl %r9d,%ebp
8960 @@ -361,6 +429,9 @@ cstar_tracesys:
8961 xchgl %ebp,%r9d
8962 cmpq $(IA32_NR_syscalls-1),%rax
8963 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8964 +
8965 + pax_erase_kstack
8966 +
8967 jmp cstar_do_call
8968 END(ia32_cstar_target)
8969
8970 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8971 CFI_REL_OFFSET rip,RIP-RIP
8972 PARAVIRT_ADJUST_EXCEPTION_FRAME
8973 SWAPGS
8974 - /*
8975 - * No need to follow this irqs on/off section: the syscall
8976 - * disabled irqs and here we enable it straight after entry:
8977 - */
8978 - ENABLE_INTERRUPTS(CLBR_NONE)
8979 movl %eax,%eax
8980 pushq_cfi %rax
8981 cld
8982 /* note the registers are not zero extended to the sf.
8983 this could be a problem. */
8984 SAVE_ARGS 0,1,0
8985 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8986 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8987 + pax_enter_kernel_user
8988 +
8989 +#ifdef CONFIG_PAX_RANDKSTACK
8990 + pax_erase_kstack
8991 +#endif
8992 +
8993 + /*
8994 + * No need to follow this irqs on/off section: the syscall
8995 + * disabled irqs and here we enable it straight after entry:
8996 + */
8997 + ENABLE_INTERRUPTS(CLBR_NONE)
8998 + GET_THREAD_INFO(%r11)
8999 + orl $TS_COMPAT,TI_status(%r11)
9000 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9001 jnz ia32_tracesys
9002 cmpq $(IA32_NR_syscalls-1),%rax
9003 ja ia32_badsys
9004 @@ -436,6 +514,9 @@ ia32_tracesys:
9005 RESTORE_REST
9006 cmpq $(IA32_NR_syscalls-1),%rax
9007 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
9008 +
9009 + pax_erase_kstack
9010 +
9011 jmp ia32_do_call
9012 END(ia32_syscall)
9013
9014 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
9015 index 4540bec..714d913 100644
9016 --- a/arch/x86/ia32/sys_ia32.c
9017 +++ b/arch/x86/ia32/sys_ia32.c
9018 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
9019 */
9020 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
9021 {
9022 - typeof(ubuf->st_uid) uid = 0;
9023 - typeof(ubuf->st_gid) gid = 0;
9024 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
9025 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
9026 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
9027 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
9028 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9029 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
9030 return ret;
9031 }
9032
9033 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
9034 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
9035 int options)
9036 {
9037 return compat_sys_wait4(pid, stat_addr, options, NULL);
9038 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9039 mm_segment_t old_fs = get_fs();
9040
9041 set_fs(KERNEL_DS);
9042 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9043 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9044 set_fs(old_fs);
9045 if (put_compat_timespec(&t, interval))
9046 return -EFAULT;
9047 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9048 mm_segment_t old_fs = get_fs();
9049
9050 set_fs(KERNEL_DS);
9051 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9052 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9053 set_fs(old_fs);
9054 if (!ret) {
9055 switch (_NSIG_WORDS) {
9056 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9057 if (copy_siginfo_from_user32(&info, uinfo))
9058 return -EFAULT;
9059 set_fs(KERNEL_DS);
9060 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9061 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9062 set_fs(old_fs);
9063 return ret;
9064 }
9065 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9066 return -EFAULT;
9067
9068 set_fs(KERNEL_DS);
9069 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9070 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9071 count);
9072 set_fs(old_fs);
9073
9074 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9075 index 952bd01..7692c6f 100644
9076 --- a/arch/x86/include/asm/alternative-asm.h
9077 +++ b/arch/x86/include/asm/alternative-asm.h
9078 @@ -15,6 +15,45 @@
9079 .endm
9080 #endif
9081
9082 +#ifdef KERNEXEC_PLUGIN
9083 + .macro pax_force_retaddr_bts rip=0
9084 + btsq $63,\rip(%rsp)
9085 + .endm
9086 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9087 + .macro pax_force_retaddr rip=0, reload=0
9088 + btsq $63,\rip(%rsp)
9089 + .endm
9090 + .macro pax_force_fptr ptr
9091 + btsq $63,\ptr
9092 + .endm
9093 + .macro pax_set_fptr_mask
9094 + .endm
9095 +#endif
9096 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9097 + .macro pax_force_retaddr rip=0, reload=0
9098 + .if \reload
9099 + pax_set_fptr_mask
9100 + .endif
9101 + orq %r10,\rip(%rsp)
9102 + .endm
9103 + .macro pax_force_fptr ptr
9104 + orq %r10,\ptr
9105 + .endm
9106 + .macro pax_set_fptr_mask
9107 + movabs $0x8000000000000000,%r10
9108 + .endm
9109 +#endif
9110 +#else
9111 + .macro pax_force_retaddr rip=0, reload=0
9112 + .endm
9113 + .macro pax_force_fptr ptr
9114 + .endm
9115 + .macro pax_force_retaddr_bts rip=0
9116 + .endm
9117 + .macro pax_set_fptr_mask
9118 + .endm
9119 +#endif
9120 +
9121 .macro altinstruction_entry orig alt feature orig_len alt_len
9122 .long \orig - .
9123 .long \alt - .
9124 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9125 index 7078068..f58bcda 100644
9126 --- a/arch/x86/include/asm/alternative.h
9127 +++ b/arch/x86/include/asm/alternative.h
9128 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9129 ".section .discard,\"aw\",@progbits\n" \
9130 DISCARD_ENTRY(1) \
9131 ".previous\n" \
9132 - ".section .altinstr_replacement, \"ax\"\n" \
9133 + ".section .altinstr_replacement, \"a\"\n" \
9134 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9135 ".previous"
9136
9137 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9138 DISCARD_ENTRY(1) \
9139 DISCARD_ENTRY(2) \
9140 ".previous\n" \
9141 - ".section .altinstr_replacement, \"ax\"\n" \
9142 + ".section .altinstr_replacement, \"a\"\n" \
9143 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9144 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9145 ".previous"
9146 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9147 index f342612..b3fe911 100644
9148 --- a/arch/x86/include/asm/apic.h
9149 +++ b/arch/x86/include/asm/apic.h
9150 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9151
9152 #ifdef CONFIG_X86_LOCAL_APIC
9153
9154 -extern unsigned int apic_verbosity;
9155 +extern int apic_verbosity;
9156 extern int local_apic_timer_c2_ok;
9157
9158 extern int disable_apic;
9159 @@ -391,7 +391,7 @@ struct apic {
9160 */
9161 int (*x86_32_numa_cpu_node)(int cpu);
9162 #endif
9163 -};
9164 +} __do_const;
9165
9166 /*
9167 * Pointer to the local APIC driver in use on this system (there's
9168 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9169 index 20370c6..a2eb9b0 100644
9170 --- a/arch/x86/include/asm/apm.h
9171 +++ b/arch/x86/include/asm/apm.h
9172 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9173 __asm__ __volatile__(APM_DO_ZERO_SEGS
9174 "pushl %%edi\n\t"
9175 "pushl %%ebp\n\t"
9176 - "lcall *%%cs:apm_bios_entry\n\t"
9177 + "lcall *%%ss:apm_bios_entry\n\t"
9178 "setc %%al\n\t"
9179 "popl %%ebp\n\t"
9180 "popl %%edi\n\t"
9181 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9182 __asm__ __volatile__(APM_DO_ZERO_SEGS
9183 "pushl %%edi\n\t"
9184 "pushl %%ebp\n\t"
9185 - "lcall *%%cs:apm_bios_entry\n\t"
9186 + "lcall *%%ss:apm_bios_entry\n\t"
9187 "setc %%bl\n\t"
9188 "popl %%ebp\n\t"
9189 "popl %%edi\n\t"
9190 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9191 index 58cb6d4..a4b806c 100644
9192 --- a/arch/x86/include/asm/atomic.h
9193 +++ b/arch/x86/include/asm/atomic.h
9194 @@ -22,7 +22,18 @@
9195 */
9196 static inline int atomic_read(const atomic_t *v)
9197 {
9198 - return (*(volatile int *)&(v)->counter);
9199 + return (*(volatile const int *)&(v)->counter);
9200 +}
9201 +
9202 +/**
9203 + * atomic_read_unchecked - read atomic variable
9204 + * @v: pointer of type atomic_unchecked_t
9205 + *
9206 + * Atomically reads the value of @v.
9207 + */
9208 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9209 +{
9210 + return (*(volatile const int *)&(v)->counter);
9211 }
9212
9213 /**
9214 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9215 }
9216
9217 /**
9218 + * atomic_set_unchecked - set atomic variable
9219 + * @v: pointer of type atomic_unchecked_t
9220 + * @i: required value
9221 + *
9222 + * Atomically sets the value of @v to @i.
9223 + */
9224 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9225 +{
9226 + v->counter = i;
9227 +}
9228 +
9229 +/**
9230 * atomic_add - add integer to atomic variable
9231 * @i: integer value to add
9232 * @v: pointer of type atomic_t
9233 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9234 */
9235 static inline void atomic_add(int i, atomic_t *v)
9236 {
9237 - asm volatile(LOCK_PREFIX "addl %1,%0"
9238 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9239 +
9240 +#ifdef CONFIG_PAX_REFCOUNT
9241 + "jno 0f\n"
9242 + LOCK_PREFIX "subl %1,%0\n"
9243 + "int $4\n0:\n"
9244 + _ASM_EXTABLE(0b, 0b)
9245 +#endif
9246 +
9247 + : "+m" (v->counter)
9248 + : "ir" (i));
9249 +}
9250 +
9251 +/**
9252 + * atomic_add_unchecked - add integer to atomic variable
9253 + * @i: integer value to add
9254 + * @v: pointer of type atomic_unchecked_t
9255 + *
9256 + * Atomically adds @i to @v.
9257 + */
9258 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9259 +{
9260 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9261 : "+m" (v->counter)
9262 : "ir" (i));
9263 }
9264 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9265 */
9266 static inline void atomic_sub(int i, atomic_t *v)
9267 {
9268 - asm volatile(LOCK_PREFIX "subl %1,%0"
9269 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9270 +
9271 +#ifdef CONFIG_PAX_REFCOUNT
9272 + "jno 0f\n"
9273 + LOCK_PREFIX "addl %1,%0\n"
9274 + "int $4\n0:\n"
9275 + _ASM_EXTABLE(0b, 0b)
9276 +#endif
9277 +
9278 + : "+m" (v->counter)
9279 + : "ir" (i));
9280 +}
9281 +
9282 +/**
9283 + * atomic_sub_unchecked - subtract integer from atomic variable
9284 + * @i: integer value to subtract
9285 + * @v: pointer of type atomic_unchecked_t
9286 + *
9287 + * Atomically subtracts @i from @v.
9288 + */
9289 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9290 +{
9291 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9292 : "+m" (v->counter)
9293 : "ir" (i));
9294 }
9295 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9296 {
9297 unsigned char c;
9298
9299 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9300 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9301 +
9302 +#ifdef CONFIG_PAX_REFCOUNT
9303 + "jno 0f\n"
9304 + LOCK_PREFIX "addl %2,%0\n"
9305 + "int $4\n0:\n"
9306 + _ASM_EXTABLE(0b, 0b)
9307 +#endif
9308 +
9309 + "sete %1\n"
9310 : "+m" (v->counter), "=qm" (c)
9311 : "ir" (i) : "memory");
9312 return c;
9313 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9314 */
9315 static inline void atomic_inc(atomic_t *v)
9316 {
9317 - asm volatile(LOCK_PREFIX "incl %0"
9318 + asm volatile(LOCK_PREFIX "incl %0\n"
9319 +
9320 +#ifdef CONFIG_PAX_REFCOUNT
9321 + "jno 0f\n"
9322 + LOCK_PREFIX "decl %0\n"
9323 + "int $4\n0:\n"
9324 + _ASM_EXTABLE(0b, 0b)
9325 +#endif
9326 +
9327 + : "+m" (v->counter));
9328 +}
9329 +
9330 +/**
9331 + * atomic_inc_unchecked - increment atomic variable
9332 + * @v: pointer of type atomic_unchecked_t
9333 + *
9334 + * Atomically increments @v by 1.
9335 + */
9336 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9337 +{
9338 + asm volatile(LOCK_PREFIX "incl %0\n"
9339 : "+m" (v->counter));
9340 }
9341
9342 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9343 */
9344 static inline void atomic_dec(atomic_t *v)
9345 {
9346 - asm volatile(LOCK_PREFIX "decl %0"
9347 + asm volatile(LOCK_PREFIX "decl %0\n"
9348 +
9349 +#ifdef CONFIG_PAX_REFCOUNT
9350 + "jno 0f\n"
9351 + LOCK_PREFIX "incl %0\n"
9352 + "int $4\n0:\n"
9353 + _ASM_EXTABLE(0b, 0b)
9354 +#endif
9355 +
9356 + : "+m" (v->counter));
9357 +}
9358 +
9359 +/**
9360 + * atomic_dec_unchecked - decrement atomic variable
9361 + * @v: pointer of type atomic_unchecked_t
9362 + *
9363 + * Atomically decrements @v by 1.
9364 + */
9365 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9366 +{
9367 + asm volatile(LOCK_PREFIX "decl %0\n"
9368 : "+m" (v->counter));
9369 }
9370
9371 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9372 {
9373 unsigned char c;
9374
9375 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9376 + asm volatile(LOCK_PREFIX "decl %0\n"
9377 +
9378 +#ifdef CONFIG_PAX_REFCOUNT
9379 + "jno 0f\n"
9380 + LOCK_PREFIX "incl %0\n"
9381 + "int $4\n0:\n"
9382 + _ASM_EXTABLE(0b, 0b)
9383 +#endif
9384 +
9385 + "sete %1\n"
9386 : "+m" (v->counter), "=qm" (c)
9387 : : "memory");
9388 return c != 0;
9389 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9390 {
9391 unsigned char c;
9392
9393 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9394 + asm volatile(LOCK_PREFIX "incl %0\n"
9395 +
9396 +#ifdef CONFIG_PAX_REFCOUNT
9397 + "jno 0f\n"
9398 + LOCK_PREFIX "decl %0\n"
9399 + "int $4\n0:\n"
9400 + _ASM_EXTABLE(0b, 0b)
9401 +#endif
9402 +
9403 + "sete %1\n"
9404 + : "+m" (v->counter), "=qm" (c)
9405 + : : "memory");
9406 + return c != 0;
9407 +}
9408 +
9409 +/**
9410 + * atomic_inc_and_test_unchecked - increment and test
9411 + * @v: pointer of type atomic_unchecked_t
9412 + *
9413 + * Atomically increments @v by 1
9414 + * and returns true if the result is zero, or false for all
9415 + * other cases.
9416 + */
9417 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9418 +{
9419 + unsigned char c;
9420 +
9421 + asm volatile(LOCK_PREFIX "incl %0\n"
9422 + "sete %1\n"
9423 : "+m" (v->counter), "=qm" (c)
9424 : : "memory");
9425 return c != 0;
9426 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9427 {
9428 unsigned char c;
9429
9430 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9431 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9432 +
9433 +#ifdef CONFIG_PAX_REFCOUNT
9434 + "jno 0f\n"
9435 + LOCK_PREFIX "subl %2,%0\n"
9436 + "int $4\n0:\n"
9437 + _ASM_EXTABLE(0b, 0b)
9438 +#endif
9439 +
9440 + "sets %1\n"
9441 : "+m" (v->counter), "=qm" (c)
9442 : "ir" (i) : "memory");
9443 return c;
9444 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9445 goto no_xadd;
9446 #endif
9447 /* Modern 486+ processor */
9448 - return i + xadd(&v->counter, i);
9449 + return i + xadd_check_overflow(&v->counter, i);
9450
9451 #ifdef CONFIG_M386
9452 no_xadd: /* Legacy 386 processor */
9453 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9454 }
9455
9456 /**
9457 + * atomic_add_return_unchecked - add integer and return
9458 + * @i: integer value to add
9459 + * @v: pointer of type atomic_unchecked_t
9460 + *
9461 + * Atomically adds @i to @v and returns @i + @v
9462 + */
9463 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9464 +{
9465 +#ifdef CONFIG_M386
9466 + int __i;
9467 + unsigned long flags;
9468 + if (unlikely(boot_cpu_data.x86 <= 3))
9469 + goto no_xadd;
9470 +#endif
9471 + /* Modern 486+ processor */
9472 + return i + xadd(&v->counter, i);
9473 +
9474 +#ifdef CONFIG_M386
9475 +no_xadd: /* Legacy 386 processor */
9476 + raw_local_irq_save(flags);
9477 + __i = atomic_read_unchecked(v);
9478 + atomic_set_unchecked(v, i + __i);
9479 + raw_local_irq_restore(flags);
9480 + return i + __i;
9481 +#endif
9482 +}
9483 +
9484 +/**
9485 * atomic_sub_return - subtract integer and return
9486 * @v: pointer of type atomic_t
9487 * @i: integer value to subtract
9488 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9489 }
9490
9491 #define atomic_inc_return(v) (atomic_add_return(1, v))
9492 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9493 +{
9494 + return atomic_add_return_unchecked(1, v);
9495 +}
9496 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9497
9498 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9499 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9500 return cmpxchg(&v->counter, old, new);
9501 }
9502
9503 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9504 +{
9505 + return cmpxchg(&v->counter, old, new);
9506 +}
9507 +
9508 static inline int atomic_xchg(atomic_t *v, int new)
9509 {
9510 return xchg(&v->counter, new);
9511 }
9512
9513 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9514 +{
9515 + return xchg(&v->counter, new);
9516 +}
9517 +
9518 /**
9519 * __atomic_add_unless - add unless the number is already a given value
9520 * @v: pointer of type atomic_t
9521 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9522 */
9523 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9524 {
9525 - int c, old;
9526 + int c, old, new;
9527 c = atomic_read(v);
9528 for (;;) {
9529 - if (unlikely(c == (u)))
9530 + if (unlikely(c == u))
9531 break;
9532 - old = atomic_cmpxchg((v), c, c + (a));
9533 +
9534 + asm volatile("addl %2,%0\n"
9535 +
9536 +#ifdef CONFIG_PAX_REFCOUNT
9537 + "jno 0f\n"
9538 + "subl %2,%0\n"
9539 + "int $4\n0:\n"
9540 + _ASM_EXTABLE(0b, 0b)
9541 +#endif
9542 +
9543 + : "=r" (new)
9544 + : "0" (c), "ir" (a));
9545 +
9546 + old = atomic_cmpxchg(v, c, new);
9547 if (likely(old == c))
9548 break;
9549 c = old;
9550 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9551 return c;
9552 }
9553
9554 +/**
9555 + * atomic_inc_not_zero_hint - increment if not null
9556 + * @v: pointer of type atomic_t
9557 + * @hint: probable value of the atomic before the increment
9558 + *
9559 + * This version of atomic_inc_not_zero() gives a hint of probable
9560 + * value of the atomic. This helps processor to not read the memory
9561 + * before doing the atomic read/modify/write cycle, lowering
9562 + * number of bus transactions on some arches.
9563 + *
9564 + * Returns: 0 if increment was not done, 1 otherwise.
9565 + */
9566 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9567 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9568 +{
9569 + int val, c = hint, new;
9570 +
9571 + /* sanity test, should be removed by compiler if hint is a constant */
9572 + if (!hint)
9573 + return __atomic_add_unless(v, 1, 0);
9574 +
9575 + do {
9576 + asm volatile("incl %0\n"
9577 +
9578 +#ifdef CONFIG_PAX_REFCOUNT
9579 + "jno 0f\n"
9580 + "decl %0\n"
9581 + "int $4\n0:\n"
9582 + _ASM_EXTABLE(0b, 0b)
9583 +#endif
9584 +
9585 + : "=r" (new)
9586 + : "0" (c));
9587 +
9588 + val = atomic_cmpxchg(v, c, new);
9589 + if (val == c)
9590 + return 1;
9591 + c = val;
9592 + } while (c);
9593 +
9594 + return 0;
9595 +}
9596
9597 /*
9598 * atomic_dec_if_positive - decrement by 1 if old value positive
9599 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9600 #endif
9601
9602 /* These are x86-specific, used by some header files */
9603 -#define atomic_clear_mask(mask, addr) \
9604 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9605 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9606 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9607 +{
9608 + asm volatile(LOCK_PREFIX "andl %1,%0"
9609 + : "+m" (v->counter)
9610 + : "r" (~(mask))
9611 + : "memory");
9612 +}
9613
9614 -#define atomic_set_mask(mask, addr) \
9615 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9616 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9617 - : "memory")
9618 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9619 +{
9620 + asm volatile(LOCK_PREFIX "andl %1,%0"
9621 + : "+m" (v->counter)
9622 + : "r" (~(mask))
9623 + : "memory");
9624 +}
9625 +
9626 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9627 +{
9628 + asm volatile(LOCK_PREFIX "orl %1,%0"
9629 + : "+m" (v->counter)
9630 + : "r" (mask)
9631 + : "memory");
9632 +}
9633 +
9634 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9635 +{
9636 + asm volatile(LOCK_PREFIX "orl %1,%0"
9637 + : "+m" (v->counter)
9638 + : "r" (mask)
9639 + : "memory");
9640 +}
9641
9642 /* Atomic operations are already serializing on x86 */
9643 #define smp_mb__before_atomic_dec() barrier()
9644 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9645 index b154de7..aadebd8 100644
9646 --- a/arch/x86/include/asm/atomic64_32.h
9647 +++ b/arch/x86/include/asm/atomic64_32.h
9648 @@ -12,6 +12,14 @@ typedef struct {
9649 u64 __aligned(8) counter;
9650 } atomic64_t;
9651
9652 +#ifdef CONFIG_PAX_REFCOUNT
9653 +typedef struct {
9654 + u64 __aligned(8) counter;
9655 +} atomic64_unchecked_t;
9656 +#else
9657 +typedef atomic64_t atomic64_unchecked_t;
9658 +#endif
9659 +
9660 #define ATOMIC64_INIT(val) { (val) }
9661
9662 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9663 @@ -37,21 +45,31 @@ typedef struct {
9664 ATOMIC64_DECL_ONE(sym##_386)
9665
9666 ATOMIC64_DECL_ONE(add_386);
9667 +ATOMIC64_DECL_ONE(add_unchecked_386);
9668 ATOMIC64_DECL_ONE(sub_386);
9669 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9670 ATOMIC64_DECL_ONE(inc_386);
9671 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9672 ATOMIC64_DECL_ONE(dec_386);
9673 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9674 #endif
9675
9676 #define alternative_atomic64(f, out, in...) \
9677 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9678
9679 ATOMIC64_DECL(read);
9680 +ATOMIC64_DECL(read_unchecked);
9681 ATOMIC64_DECL(set);
9682 +ATOMIC64_DECL(set_unchecked);
9683 ATOMIC64_DECL(xchg);
9684 ATOMIC64_DECL(add_return);
9685 +ATOMIC64_DECL(add_return_unchecked);
9686 ATOMIC64_DECL(sub_return);
9687 +ATOMIC64_DECL(sub_return_unchecked);
9688 ATOMIC64_DECL(inc_return);
9689 +ATOMIC64_DECL(inc_return_unchecked);
9690 ATOMIC64_DECL(dec_return);
9691 +ATOMIC64_DECL(dec_return_unchecked);
9692 ATOMIC64_DECL(dec_if_positive);
9693 ATOMIC64_DECL(inc_not_zero);
9694 ATOMIC64_DECL(add_unless);
9695 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9696 }
9697
9698 /**
9699 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9700 + * @p: pointer to type atomic64_unchecked_t
9701 + * @o: expected value
9702 + * @n: new value
9703 + *
9704 + * Atomically sets @v to @n if it was equal to @o and returns
9705 + * the old value.
9706 + */
9707 +
9708 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9709 +{
9710 + return cmpxchg64(&v->counter, o, n);
9711 +}
9712 +
9713 +/**
9714 * atomic64_xchg - xchg atomic64 variable
9715 * @v: pointer to type atomic64_t
9716 * @n: value to assign
9717 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9718 }
9719
9720 /**
9721 + * atomic64_set_unchecked - set atomic64 variable
9722 + * @v: pointer to type atomic64_unchecked_t
9723 + * @n: value to assign
9724 + *
9725 + * Atomically sets the value of @v to @n.
9726 + */
9727 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9728 +{
9729 + unsigned high = (unsigned)(i >> 32);
9730 + unsigned low = (unsigned)i;
9731 + alternative_atomic64(set, /* no output */,
9732 + "S" (v), "b" (low), "c" (high)
9733 + : "eax", "edx", "memory");
9734 +}
9735 +
9736 +/**
9737 * atomic64_read - read atomic64 variable
9738 * @v: pointer to type atomic64_t
9739 *
9740 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9741 }
9742
9743 /**
9744 + * atomic64_read_unchecked - read atomic64 variable
9745 + * @v: pointer to type atomic64_unchecked_t
9746 + *
9747 + * Atomically reads the value of @v and returns it.
9748 + */
9749 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9750 +{
9751 + long long r;
9752 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9753 + return r;
9754 + }
9755 +
9756 +/**
9757 * atomic64_add_return - add and return
9758 * @i: integer value to add
9759 * @v: pointer to type atomic64_t
9760 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9761 return i;
9762 }
9763
9764 +/**
9765 + * atomic64_add_return_unchecked - add and return
9766 + * @i: integer value to add
9767 + * @v: pointer to type atomic64_unchecked_t
9768 + *
9769 + * Atomically adds @i to @v and returns @i + *@v
9770 + */
9771 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9772 +{
9773 + alternative_atomic64(add_return_unchecked,
9774 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9775 + ASM_NO_INPUT_CLOBBER("memory"));
9776 + return i;
9777 +}
9778 +
9779 /*
9780 * Other variants with different arithmetic operators:
9781 */
9782 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9783 return a;
9784 }
9785
9786 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9787 +{
9788 + long long a;
9789 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9790 + "S" (v) : "memory", "ecx");
9791 + return a;
9792 +}
9793 +
9794 static inline long long atomic64_dec_return(atomic64_t *v)
9795 {
9796 long long a;
9797 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9798 }
9799
9800 /**
9801 + * atomic64_add_unchecked - add integer to atomic64 variable
9802 + * @i: integer value to add
9803 + * @v: pointer to type atomic64_unchecked_t
9804 + *
9805 + * Atomically adds @i to @v.
9806 + */
9807 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9808 +{
9809 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9810 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9811 + ASM_NO_INPUT_CLOBBER("memory"));
9812 + return i;
9813 +}
9814 +
9815 +/**
9816 * atomic64_sub - subtract the atomic64 variable
9817 * @i: integer value to subtract
9818 * @v: pointer to type atomic64_t
9819 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9820 index 0e1cbfc..5623683 100644
9821 --- a/arch/x86/include/asm/atomic64_64.h
9822 +++ b/arch/x86/include/asm/atomic64_64.h
9823 @@ -18,7 +18,19 @@
9824 */
9825 static inline long atomic64_read(const atomic64_t *v)
9826 {
9827 - return (*(volatile long *)&(v)->counter);
9828 + return (*(volatile const long *)&(v)->counter);
9829 +}
9830 +
9831 +/**
9832 + * atomic64_read_unchecked - read atomic64 variable
9833 + * @v: pointer of type atomic64_unchecked_t
9834 + *
9835 + * Atomically reads the value of @v.
9836 + * Doesn't imply a read memory barrier.
9837 + */
9838 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9839 +{
9840 + return (*(volatile const long *)&(v)->counter);
9841 }
9842
9843 /**
9844 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9845 }
9846
9847 /**
9848 + * atomic64_set_unchecked - set atomic64 variable
9849 + * @v: pointer to type atomic64_unchecked_t
9850 + * @i: required value
9851 + *
9852 + * Atomically sets the value of @v to @i.
9853 + */
9854 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9855 +{
9856 + v->counter = i;
9857 +}
9858 +
9859 +/**
9860 * atomic64_add - add integer to atomic64 variable
9861 * @i: integer value to add
9862 * @v: pointer to type atomic64_t
9863 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9864 */
9865 static inline void atomic64_add(long i, atomic64_t *v)
9866 {
9867 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9868 +
9869 +#ifdef CONFIG_PAX_REFCOUNT
9870 + "jno 0f\n"
9871 + LOCK_PREFIX "subq %1,%0\n"
9872 + "int $4\n0:\n"
9873 + _ASM_EXTABLE(0b, 0b)
9874 +#endif
9875 +
9876 + : "=m" (v->counter)
9877 + : "er" (i), "m" (v->counter));
9878 +}
9879 +
9880 +/**
9881 + * atomic64_add_unchecked - add integer to atomic64 variable
9882 + * @i: integer value to add
9883 + * @v: pointer to type atomic64_unchecked_t
9884 + *
9885 + * Atomically adds @i to @v.
9886 + */
9887 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9888 +{
9889 asm volatile(LOCK_PREFIX "addq %1,%0"
9890 : "=m" (v->counter)
9891 : "er" (i), "m" (v->counter));
9892 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9893 */
9894 static inline void atomic64_sub(long i, atomic64_t *v)
9895 {
9896 - asm volatile(LOCK_PREFIX "subq %1,%0"
9897 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9898 +
9899 +#ifdef CONFIG_PAX_REFCOUNT
9900 + "jno 0f\n"
9901 + LOCK_PREFIX "addq %1,%0\n"
9902 + "int $4\n0:\n"
9903 + _ASM_EXTABLE(0b, 0b)
9904 +#endif
9905 +
9906 + : "=m" (v->counter)
9907 + : "er" (i), "m" (v->counter));
9908 +}
9909 +
9910 +/**
9911 + * atomic64_sub_unchecked - subtract the atomic64 variable
9912 + * @i: integer value to subtract
9913 + * @v: pointer to type atomic64_unchecked_t
9914 + *
9915 + * Atomically subtracts @i from @v.
9916 + */
9917 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9918 +{
9919 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9920 : "=m" (v->counter)
9921 : "er" (i), "m" (v->counter));
9922 }
9923 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9924 {
9925 unsigned char c;
9926
9927 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9928 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9929 +
9930 +#ifdef CONFIG_PAX_REFCOUNT
9931 + "jno 0f\n"
9932 + LOCK_PREFIX "addq %2,%0\n"
9933 + "int $4\n0:\n"
9934 + _ASM_EXTABLE(0b, 0b)
9935 +#endif
9936 +
9937 + "sete %1\n"
9938 : "=m" (v->counter), "=qm" (c)
9939 : "er" (i), "m" (v->counter) : "memory");
9940 return c;
9941 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9942 */
9943 static inline void atomic64_inc(atomic64_t *v)
9944 {
9945 + asm volatile(LOCK_PREFIX "incq %0\n"
9946 +
9947 +#ifdef CONFIG_PAX_REFCOUNT
9948 + "jno 0f\n"
9949 + LOCK_PREFIX "decq %0\n"
9950 + "int $4\n0:\n"
9951 + _ASM_EXTABLE(0b, 0b)
9952 +#endif
9953 +
9954 + : "=m" (v->counter)
9955 + : "m" (v->counter));
9956 +}
9957 +
9958 +/**
9959 + * atomic64_inc_unchecked - increment atomic64 variable
9960 + * @v: pointer to type atomic64_unchecked_t
9961 + *
9962 + * Atomically increments @v by 1.
9963 + */
9964 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9965 +{
9966 asm volatile(LOCK_PREFIX "incq %0"
9967 : "=m" (v->counter)
9968 : "m" (v->counter));
9969 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9970 */
9971 static inline void atomic64_dec(atomic64_t *v)
9972 {
9973 - asm volatile(LOCK_PREFIX "decq %0"
9974 + asm volatile(LOCK_PREFIX "decq %0\n"
9975 +
9976 +#ifdef CONFIG_PAX_REFCOUNT
9977 + "jno 0f\n"
9978 + LOCK_PREFIX "incq %0\n"
9979 + "int $4\n0:\n"
9980 + _ASM_EXTABLE(0b, 0b)
9981 +#endif
9982 +
9983 + : "=m" (v->counter)
9984 + : "m" (v->counter));
9985 +}
9986 +
9987 +/**
9988 + * atomic64_dec_unchecked - decrement atomic64 variable
9989 + * @v: pointer to type atomic64_t
9990 + *
9991 + * Atomically decrements @v by 1.
9992 + */
9993 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9994 +{
9995 + asm volatile(LOCK_PREFIX "decq %0\n"
9996 : "=m" (v->counter)
9997 : "m" (v->counter));
9998 }
9999 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
10000 {
10001 unsigned char c;
10002
10003 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
10004 + asm volatile(LOCK_PREFIX "decq %0\n"
10005 +
10006 +#ifdef CONFIG_PAX_REFCOUNT
10007 + "jno 0f\n"
10008 + LOCK_PREFIX "incq %0\n"
10009 + "int $4\n0:\n"
10010 + _ASM_EXTABLE(0b, 0b)
10011 +#endif
10012 +
10013 + "sete %1\n"
10014 : "=m" (v->counter), "=qm" (c)
10015 : "m" (v->counter) : "memory");
10016 return c != 0;
10017 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
10018 {
10019 unsigned char c;
10020
10021 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
10022 + asm volatile(LOCK_PREFIX "incq %0\n"
10023 +
10024 +#ifdef CONFIG_PAX_REFCOUNT
10025 + "jno 0f\n"
10026 + LOCK_PREFIX "decq %0\n"
10027 + "int $4\n0:\n"
10028 + _ASM_EXTABLE(0b, 0b)
10029 +#endif
10030 +
10031 + "sete %1\n"
10032 : "=m" (v->counter), "=qm" (c)
10033 : "m" (v->counter) : "memory");
10034 return c != 0;
10035 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10036 {
10037 unsigned char c;
10038
10039 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10040 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
10041 +
10042 +#ifdef CONFIG_PAX_REFCOUNT
10043 + "jno 0f\n"
10044 + LOCK_PREFIX "subq %2,%0\n"
10045 + "int $4\n0:\n"
10046 + _ASM_EXTABLE(0b, 0b)
10047 +#endif
10048 +
10049 + "sets %1\n"
10050 : "=m" (v->counter), "=qm" (c)
10051 : "er" (i), "m" (v->counter) : "memory");
10052 return c;
10053 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10054 */
10055 static inline long atomic64_add_return(long i, atomic64_t *v)
10056 {
10057 + return i + xadd_check_overflow(&v->counter, i);
10058 +}
10059 +
10060 +/**
10061 + * atomic64_add_return_unchecked - add and return
10062 + * @i: integer value to add
10063 + * @v: pointer to type atomic64_unchecked_t
10064 + *
10065 + * Atomically adds @i to @v and returns @i + @v
10066 + */
10067 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10068 +{
10069 return i + xadd(&v->counter, i);
10070 }
10071
10072 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10073 }
10074
10075 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10076 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10077 +{
10078 + return atomic64_add_return_unchecked(1, v);
10079 +}
10080 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10081
10082 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10083 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10084 return cmpxchg(&v->counter, old, new);
10085 }
10086
10087 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10088 +{
10089 + return cmpxchg(&v->counter, old, new);
10090 +}
10091 +
10092 static inline long atomic64_xchg(atomic64_t *v, long new)
10093 {
10094 return xchg(&v->counter, new);
10095 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10096 */
10097 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10098 {
10099 - long c, old;
10100 + long c, old, new;
10101 c = atomic64_read(v);
10102 for (;;) {
10103 - if (unlikely(c == (u)))
10104 + if (unlikely(c == u))
10105 break;
10106 - old = atomic64_cmpxchg((v), c, c + (a));
10107 +
10108 + asm volatile("add %2,%0\n"
10109 +
10110 +#ifdef CONFIG_PAX_REFCOUNT
10111 + "jno 0f\n"
10112 + "sub %2,%0\n"
10113 + "int $4\n0:\n"
10114 + _ASM_EXTABLE(0b, 0b)
10115 +#endif
10116 +
10117 + : "=r" (new)
10118 + : "0" (c), "ir" (a));
10119 +
10120 + old = atomic64_cmpxchg(v, c, new);
10121 if (likely(old == c))
10122 break;
10123 c = old;
10124 }
10125 - return c != (u);
10126 + return c != u;
10127 }
10128
10129 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10130 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10131 index 72f5009..2f8b9a9 100644
10132 --- a/arch/x86/include/asm/bitops.h
10133 +++ b/arch/x86/include/asm/bitops.h
10134 @@ -40,7 +40,7 @@
10135 * a mask operation on a byte.
10136 */
10137 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10138 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10139 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10140 #define CONST_MASK(nr) (1 << ((nr) & 7))
10141
10142 /**
10143 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10144 index b13fe63..0dab13a 100644
10145 --- a/arch/x86/include/asm/boot.h
10146 +++ b/arch/x86/include/asm/boot.h
10147 @@ -11,10 +11,15 @@
10148 #include <asm/pgtable_types.h>
10149
10150 /* Physical address where kernel should be loaded. */
10151 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10152 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10153 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10154 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10155
10156 +#ifndef __ASSEMBLY__
10157 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10158 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10159 +#endif
10160 +
10161 /* Minimum kernel alignment, as a power of two */
10162 #ifdef CONFIG_X86_64
10163 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10164 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10165 index 48f99f1..d78ebf9 100644
10166 --- a/arch/x86/include/asm/cache.h
10167 +++ b/arch/x86/include/asm/cache.h
10168 @@ -5,12 +5,13 @@
10169
10170 /* L1 cache line size */
10171 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10172 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10173 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10174
10175 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10176 +#define __read_only __attribute__((__section__(".data..read_only")))
10177
10178 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10179 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10180 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10181
10182 #ifdef CONFIG_X86_VSMP
10183 #ifdef CONFIG_SMP
10184 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10185 index 9863ee3..4a1f8e1 100644
10186 --- a/arch/x86/include/asm/cacheflush.h
10187 +++ b/arch/x86/include/asm/cacheflush.h
10188 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10189 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10190
10191 if (pg_flags == _PGMT_DEFAULT)
10192 - return -1;
10193 + return ~0UL;
10194 else if (pg_flags == _PGMT_WC)
10195 return _PAGE_CACHE_WC;
10196 else if (pg_flags == _PGMT_UC_MINUS)
10197 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10198 index 46fc474..b02b0f9 100644
10199 --- a/arch/x86/include/asm/checksum_32.h
10200 +++ b/arch/x86/include/asm/checksum_32.h
10201 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10202 int len, __wsum sum,
10203 int *src_err_ptr, int *dst_err_ptr);
10204
10205 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10206 + int len, __wsum sum,
10207 + int *src_err_ptr, int *dst_err_ptr);
10208 +
10209 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10210 + int len, __wsum sum,
10211 + int *src_err_ptr, int *dst_err_ptr);
10212 +
10213 /*
10214 * Note: when you get a NULL pointer exception here this means someone
10215 * passed in an incorrect kernel address to one of these functions.
10216 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10217 int *err_ptr)
10218 {
10219 might_sleep();
10220 - return csum_partial_copy_generic((__force void *)src, dst,
10221 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10222 len, sum, err_ptr, NULL);
10223 }
10224
10225 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10226 {
10227 might_sleep();
10228 if (access_ok(VERIFY_WRITE, dst, len))
10229 - return csum_partial_copy_generic(src, (__force void *)dst,
10230 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10231 len, sum, NULL, err_ptr);
10232
10233 if (len)
10234 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10235 index 99480e5..d81165b 100644
10236 --- a/arch/x86/include/asm/cmpxchg.h
10237 +++ b/arch/x86/include/asm/cmpxchg.h
10238 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10239 __compiletime_error("Bad argument size for cmpxchg");
10240 extern void __xadd_wrong_size(void)
10241 __compiletime_error("Bad argument size for xadd");
10242 +extern void __xadd_check_overflow_wrong_size(void)
10243 + __compiletime_error("Bad argument size for xadd_check_overflow");
10244 extern void __add_wrong_size(void)
10245 __compiletime_error("Bad argument size for add");
10246 +extern void __add_check_overflow_wrong_size(void)
10247 + __compiletime_error("Bad argument size for add_check_overflow");
10248
10249 /*
10250 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10251 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10252 __ret; \
10253 })
10254
10255 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10256 + ({ \
10257 + __typeof__ (*(ptr)) __ret = (arg); \
10258 + switch (sizeof(*(ptr))) { \
10259 + case __X86_CASE_L: \
10260 + asm volatile (lock #op "l %0, %1\n" \
10261 + "jno 0f\n" \
10262 + "mov %0,%1\n" \
10263 + "int $4\n0:\n" \
10264 + _ASM_EXTABLE(0b, 0b) \
10265 + : "+r" (__ret), "+m" (*(ptr)) \
10266 + : : "memory", "cc"); \
10267 + break; \
10268 + case __X86_CASE_Q: \
10269 + asm volatile (lock #op "q %q0, %1\n" \
10270 + "jno 0f\n" \
10271 + "mov %0,%1\n" \
10272 + "int $4\n0:\n" \
10273 + _ASM_EXTABLE(0b, 0b) \
10274 + : "+r" (__ret), "+m" (*(ptr)) \
10275 + : : "memory", "cc"); \
10276 + break; \
10277 + default: \
10278 + __ ## op ## _check_overflow_wrong_size(); \
10279 + } \
10280 + __ret; \
10281 + })
10282 +
10283 /*
10284 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10285 * Since this is generally used to protect other memory information, we
10286 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10287 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10288 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10289
10290 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10291 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10292 +
10293 #define __add(ptr, inc, lock) \
10294 ({ \
10295 __typeof__ (*(ptr)) __ret = (inc); \
10296 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10297 index 6b7ee5f..9d664b3 100644
10298 --- a/arch/x86/include/asm/cpufeature.h
10299 +++ b/arch/x86/include/asm/cpufeature.h
10300 @@ -202,13 +202,14 @@
10301 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10302 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10303 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10304 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10305 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10306 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10307 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10308 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10309 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10310 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10311 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10312 +#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10313
10314 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10315
10316 @@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10317 ".section .discard,\"aw\",@progbits\n"
10318 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10319 ".previous\n"
10320 - ".section .altinstr_replacement,\"ax\"\n"
10321 + ".section .altinstr_replacement,\"a\"\n"
10322 "3: movb $1,%0\n"
10323 "4:\n"
10324 ".previous\n"
10325 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10326 index 8bf1c06..f723dfd 100644
10327 --- a/arch/x86/include/asm/desc.h
10328 +++ b/arch/x86/include/asm/desc.h
10329 @@ -4,6 +4,7 @@
10330 #include <asm/desc_defs.h>
10331 #include <asm/ldt.h>
10332 #include <asm/mmu.h>
10333 +#include <asm/pgtable.h>
10334
10335 #include <linux/smp.h>
10336 #include <linux/percpu.h>
10337 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10338
10339 desc->type = (info->read_exec_only ^ 1) << 1;
10340 desc->type |= info->contents << 2;
10341 + desc->type |= info->seg_not_present ^ 1;
10342
10343 desc->s = 1;
10344 desc->dpl = 0x3;
10345 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10346 }
10347
10348 extern struct desc_ptr idt_descr;
10349 -extern gate_desc idt_table[];
10350 extern struct desc_ptr nmi_idt_descr;
10351 -extern gate_desc nmi_idt_table[];
10352 -
10353 -struct gdt_page {
10354 - struct desc_struct gdt[GDT_ENTRIES];
10355 -} __attribute__((aligned(PAGE_SIZE)));
10356 -
10357 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10358 +extern gate_desc idt_table[256];
10359 +extern gate_desc nmi_idt_table[256];
10360
10361 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10362 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10363 {
10364 - return per_cpu(gdt_page, cpu).gdt;
10365 + return cpu_gdt_table[cpu];
10366 }
10367
10368 #ifdef CONFIG_X86_64
10369 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10370 unsigned long base, unsigned dpl, unsigned flags,
10371 unsigned short seg)
10372 {
10373 - gate->a = (seg << 16) | (base & 0xffff);
10374 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10375 + gate->gate.offset_low = base;
10376 + gate->gate.seg = seg;
10377 + gate->gate.reserved = 0;
10378 + gate->gate.type = type;
10379 + gate->gate.s = 0;
10380 + gate->gate.dpl = dpl;
10381 + gate->gate.p = 1;
10382 + gate->gate.offset_high = base >> 16;
10383 }
10384
10385 #endif
10386 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10387
10388 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10389 {
10390 + pax_open_kernel();
10391 memcpy(&idt[entry], gate, sizeof(*gate));
10392 + pax_close_kernel();
10393 }
10394
10395 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10396 {
10397 + pax_open_kernel();
10398 memcpy(&ldt[entry], desc, 8);
10399 + pax_close_kernel();
10400 }
10401
10402 static inline void
10403 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10404 default: size = sizeof(*gdt); break;
10405 }
10406
10407 + pax_open_kernel();
10408 memcpy(&gdt[entry], desc, size);
10409 + pax_close_kernel();
10410 }
10411
10412 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10413 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10414
10415 static inline void native_load_tr_desc(void)
10416 {
10417 + pax_open_kernel();
10418 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10419 + pax_close_kernel();
10420 }
10421
10422 static inline void native_load_gdt(const struct desc_ptr *dtr)
10423 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10424 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10425 unsigned int i;
10426
10427 + pax_open_kernel();
10428 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10429 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10430 + pax_close_kernel();
10431 }
10432
10433 #define _LDT_empty(info) \
10434 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10435 }
10436
10437 #ifdef CONFIG_X86_64
10438 -static inline void set_nmi_gate(int gate, void *addr)
10439 +static inline void set_nmi_gate(int gate, const void *addr)
10440 {
10441 gate_desc s;
10442
10443 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10444 }
10445 #endif
10446
10447 -static inline void _set_gate(int gate, unsigned type, void *addr,
10448 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10449 unsigned dpl, unsigned ist, unsigned seg)
10450 {
10451 gate_desc s;
10452 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10453 * Pentium F0 0F bugfix can have resulted in the mapped
10454 * IDT being write-protected.
10455 */
10456 -static inline void set_intr_gate(unsigned int n, void *addr)
10457 +static inline void set_intr_gate(unsigned int n, const void *addr)
10458 {
10459 BUG_ON((unsigned)n > 0xFF);
10460 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10461 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10462 /*
10463 * This routine sets up an interrupt gate at directory privilege level 3.
10464 */
10465 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10466 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10467 {
10468 BUG_ON((unsigned)n > 0xFF);
10469 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10470 }
10471
10472 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10473 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10474 {
10475 BUG_ON((unsigned)n > 0xFF);
10476 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10477 }
10478
10479 -static inline void set_trap_gate(unsigned int n, void *addr)
10480 +static inline void set_trap_gate(unsigned int n, const void *addr)
10481 {
10482 BUG_ON((unsigned)n > 0xFF);
10483 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10484 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10485 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10486 {
10487 BUG_ON((unsigned)n > 0xFF);
10488 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10489 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10490 }
10491
10492 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10493 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10494 {
10495 BUG_ON((unsigned)n > 0xFF);
10496 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10497 }
10498
10499 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10500 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10501 {
10502 BUG_ON((unsigned)n > 0xFF);
10503 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10504 }
10505
10506 +#ifdef CONFIG_X86_32
10507 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10508 +{
10509 + struct desc_struct d;
10510 +
10511 + if (likely(limit))
10512 + limit = (limit - 1UL) >> PAGE_SHIFT;
10513 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10514 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10515 +}
10516 +#endif
10517 +
10518 #endif /* _ASM_X86_DESC_H */
10519 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10520 index 278441f..b95a174 100644
10521 --- a/arch/x86/include/asm/desc_defs.h
10522 +++ b/arch/x86/include/asm/desc_defs.h
10523 @@ -31,6 +31,12 @@ struct desc_struct {
10524 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10525 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10526 };
10527 + struct {
10528 + u16 offset_low;
10529 + u16 seg;
10530 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10531 + unsigned offset_high: 16;
10532 + } gate;
10533 };
10534 } __attribute__((packed));
10535
10536 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10537 index 3778256..c5d4fce 100644
10538 --- a/arch/x86/include/asm/e820.h
10539 +++ b/arch/x86/include/asm/e820.h
10540 @@ -69,7 +69,7 @@ struct e820map {
10541 #define ISA_START_ADDRESS 0xa0000
10542 #define ISA_END_ADDRESS 0x100000
10543
10544 -#define BIOS_BEGIN 0x000a0000
10545 +#define BIOS_BEGIN 0x000c0000
10546 #define BIOS_END 0x00100000
10547
10548 #define BIOS_ROM_BASE 0xffe00000
10549 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10550 index 5939f44..f8845f6 100644
10551 --- a/arch/x86/include/asm/elf.h
10552 +++ b/arch/x86/include/asm/elf.h
10553 @@ -243,7 +243,25 @@ extern int force_personality32;
10554 the loader. We need to make sure that it is out of the way of the program
10555 that it will "exec", and that there is sufficient room for the brk. */
10556
10557 +#ifdef CONFIG_PAX_SEGMEXEC
10558 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10559 +#else
10560 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10561 +#endif
10562 +
10563 +#ifdef CONFIG_PAX_ASLR
10564 +#ifdef CONFIG_X86_32
10565 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10566 +
10567 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10568 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10569 +#else
10570 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10571 +
10572 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10573 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10574 +#endif
10575 +#endif
10576
10577 /* This yields a mask that user programs can use to figure out what
10578 instruction set this CPU supports. This could be done in user space,
10579 @@ -296,16 +314,12 @@ do { \
10580
10581 #define ARCH_DLINFO \
10582 do { \
10583 - if (vdso_enabled) \
10584 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10585 - (unsigned long)current->mm->context.vdso); \
10586 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10587 } while (0)
10588
10589 #define ARCH_DLINFO_X32 \
10590 do { \
10591 - if (vdso_enabled) \
10592 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10593 - (unsigned long)current->mm->context.vdso); \
10594 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10595 } while (0)
10596
10597 #define AT_SYSINFO 32
10598 @@ -320,7 +334,7 @@ else \
10599
10600 #endif /* !CONFIG_X86_32 */
10601
10602 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10603 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10604
10605 #define VDSO_ENTRY \
10606 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10607 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10608 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10609 #define compat_arch_setup_additional_pages syscall32_setup_pages
10610
10611 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10612 -#define arch_randomize_brk arch_randomize_brk
10613 -
10614 /*
10615 * True on X86_32 or when emulating IA32 on X86_64
10616 */
10617 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10618 index 75ce3f4..882e801 100644
10619 --- a/arch/x86/include/asm/emergency-restart.h
10620 +++ b/arch/x86/include/asm/emergency-restart.h
10621 @@ -13,6 +13,6 @@ enum reboot_type {
10622
10623 extern enum reboot_type reboot_type;
10624
10625 -extern void machine_emergency_restart(void);
10626 +extern void machine_emergency_restart(void) __noreturn;
10627
10628 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10629 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10630 index 75f4c6d..ee3eb8f 100644
10631 --- a/arch/x86/include/asm/fpu-internal.h
10632 +++ b/arch/x86/include/asm/fpu-internal.h
10633 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10634 {
10635 int err;
10636
10637 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10638 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10639 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10640 +#endif
10641 +
10642 /* See comment in fxsave() below. */
10643 #ifdef CONFIG_AS_FXSAVEQ
10644 asm volatile("1: fxrstorq %[fx]\n\t"
10645 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10646 {
10647 int err;
10648
10649 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10650 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10651 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10652 +#endif
10653 +
10654 /*
10655 * Clear the bytes not touched by the fxsave and reserved
10656 * for the SW usage.
10657 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10658 "emms\n\t" /* clear stack tags */
10659 "fildl %P[addr]", /* set F?P to defined value */
10660 X86_FEATURE_FXSAVE_LEAK,
10661 - [addr] "m" (tsk->thread.fpu.has_fpu));
10662 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10663
10664 return fpu_restore_checking(&tsk->thread.fpu);
10665 }
10666 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10667 index 71ecbcb..bac10b7 100644
10668 --- a/arch/x86/include/asm/futex.h
10669 +++ b/arch/x86/include/asm/futex.h
10670 @@ -11,16 +11,18 @@
10671 #include <asm/processor.h>
10672
10673 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10674 + typecheck(u32 __user *, uaddr); \
10675 asm volatile("1:\t" insn "\n" \
10676 "2:\t.section .fixup,\"ax\"\n" \
10677 "3:\tmov\t%3, %1\n" \
10678 "\tjmp\t2b\n" \
10679 "\t.previous\n" \
10680 _ASM_EXTABLE(1b, 3b) \
10681 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10682 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10683 : "i" (-EFAULT), "0" (oparg), "1" (0))
10684
10685 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10686 + typecheck(u32 __user *, uaddr); \
10687 asm volatile("1:\tmovl %2, %0\n" \
10688 "\tmovl\t%0, %3\n" \
10689 "\t" insn "\n" \
10690 @@ -33,7 +35,7 @@
10691 _ASM_EXTABLE(1b, 4b) \
10692 _ASM_EXTABLE(2b, 4b) \
10693 : "=&a" (oldval), "=&r" (ret), \
10694 - "+m" (*uaddr), "=&r" (tem) \
10695 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10696 : "r" (oparg), "i" (-EFAULT), "1" (0))
10697
10698 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10699 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10700
10701 switch (op) {
10702 case FUTEX_OP_SET:
10703 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10704 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10705 break;
10706 case FUTEX_OP_ADD:
10707 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10708 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10709 uaddr, oparg);
10710 break;
10711 case FUTEX_OP_OR:
10712 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10713 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10714 return -EFAULT;
10715
10716 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10717 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10718 "2:\t.section .fixup, \"ax\"\n"
10719 "3:\tmov %3, %0\n"
10720 "\tjmp 2b\n"
10721 "\t.previous\n"
10722 _ASM_EXTABLE(1b, 3b)
10723 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10724 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10725 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10726 : "memory"
10727 );
10728 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10729 index eb92a6e..b98b2f4 100644
10730 --- a/arch/x86/include/asm/hw_irq.h
10731 +++ b/arch/x86/include/asm/hw_irq.h
10732 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10733 extern void enable_IO_APIC(void);
10734
10735 /* Statistics */
10736 -extern atomic_t irq_err_count;
10737 -extern atomic_t irq_mis_count;
10738 +extern atomic_unchecked_t irq_err_count;
10739 +extern atomic_unchecked_t irq_mis_count;
10740
10741 /* EISA */
10742 extern void eisa_set_level_irq(unsigned int irq);
10743 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10744 index d8e8eef..99f81ae 100644
10745 --- a/arch/x86/include/asm/io.h
10746 +++ b/arch/x86/include/asm/io.h
10747 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10748
10749 #include <linux/vmalloc.h>
10750
10751 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10752 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10753 +{
10754 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10755 +}
10756 +
10757 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10758 +{
10759 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10760 +}
10761 +
10762 /*
10763 * Convert a virtual cached pointer to an uncached pointer
10764 */
10765 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10766 index bba3cf8..06bc8da 100644
10767 --- a/arch/x86/include/asm/irqflags.h
10768 +++ b/arch/x86/include/asm/irqflags.h
10769 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10770 sti; \
10771 sysexit
10772
10773 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10774 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10775 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10776 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10777 +
10778 #else
10779 #define INTERRUPT_RETURN iret
10780 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10781 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10782 index 5478825..839e88c 100644
10783 --- a/arch/x86/include/asm/kprobes.h
10784 +++ b/arch/x86/include/asm/kprobes.h
10785 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10786 #define RELATIVEJUMP_SIZE 5
10787 #define RELATIVECALL_OPCODE 0xe8
10788 #define RELATIVE_ADDR_SIZE 4
10789 -#define MAX_STACK_SIZE 64
10790 -#define MIN_STACK_SIZE(ADDR) \
10791 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10792 - THREAD_SIZE - (unsigned long)(ADDR))) \
10793 - ? (MAX_STACK_SIZE) \
10794 - : (((unsigned long)current_thread_info()) + \
10795 - THREAD_SIZE - (unsigned long)(ADDR)))
10796 +#define MAX_STACK_SIZE 64UL
10797 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10798
10799 #define flush_insn_slot(p) do { } while (0)
10800
10801 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10802 index 09155d6..d2e6df9 100644
10803 --- a/arch/x86/include/asm/kvm_host.h
10804 +++ b/arch/x86/include/asm/kvm_host.h
10805 @@ -694,7 +694,7 @@ struct kvm_x86_ops {
10806 int (*check_intercept)(struct kvm_vcpu *vcpu,
10807 struct x86_instruction_info *info,
10808 enum x86_intercept_stage stage);
10809 -};
10810 +} __do_const;
10811
10812 struct kvm_arch_async_pf {
10813 u32 token;
10814 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10815 index c8bed0d..e5721fa 100644
10816 --- a/arch/x86/include/asm/local.h
10817 +++ b/arch/x86/include/asm/local.h
10818 @@ -17,26 +17,58 @@ typedef struct {
10819
10820 static inline void local_inc(local_t *l)
10821 {
10822 - asm volatile(_ASM_INC "%0"
10823 + asm volatile(_ASM_INC "%0\n"
10824 +
10825 +#ifdef CONFIG_PAX_REFCOUNT
10826 + "jno 0f\n"
10827 + _ASM_DEC "%0\n"
10828 + "int $4\n0:\n"
10829 + _ASM_EXTABLE(0b, 0b)
10830 +#endif
10831 +
10832 : "+m" (l->a.counter));
10833 }
10834
10835 static inline void local_dec(local_t *l)
10836 {
10837 - asm volatile(_ASM_DEC "%0"
10838 + asm volatile(_ASM_DEC "%0\n"
10839 +
10840 +#ifdef CONFIG_PAX_REFCOUNT
10841 + "jno 0f\n"
10842 + _ASM_INC "%0\n"
10843 + "int $4\n0:\n"
10844 + _ASM_EXTABLE(0b, 0b)
10845 +#endif
10846 +
10847 : "+m" (l->a.counter));
10848 }
10849
10850 static inline void local_add(long i, local_t *l)
10851 {
10852 - asm volatile(_ASM_ADD "%1,%0"
10853 + asm volatile(_ASM_ADD "%1,%0\n"
10854 +
10855 +#ifdef CONFIG_PAX_REFCOUNT
10856 + "jno 0f\n"
10857 + _ASM_SUB "%1,%0\n"
10858 + "int $4\n0:\n"
10859 + _ASM_EXTABLE(0b, 0b)
10860 +#endif
10861 +
10862 : "+m" (l->a.counter)
10863 : "ir" (i));
10864 }
10865
10866 static inline void local_sub(long i, local_t *l)
10867 {
10868 - asm volatile(_ASM_SUB "%1,%0"
10869 + asm volatile(_ASM_SUB "%1,%0\n"
10870 +
10871 +#ifdef CONFIG_PAX_REFCOUNT
10872 + "jno 0f\n"
10873 + _ASM_ADD "%1,%0\n"
10874 + "int $4\n0:\n"
10875 + _ASM_EXTABLE(0b, 0b)
10876 +#endif
10877 +
10878 : "+m" (l->a.counter)
10879 : "ir" (i));
10880 }
10881 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10882 {
10883 unsigned char c;
10884
10885 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10886 + asm volatile(_ASM_SUB "%2,%0\n"
10887 +
10888 +#ifdef CONFIG_PAX_REFCOUNT
10889 + "jno 0f\n"
10890 + _ASM_ADD "%2,%0\n"
10891 + "int $4\n0:\n"
10892 + _ASM_EXTABLE(0b, 0b)
10893 +#endif
10894 +
10895 + "sete %1\n"
10896 : "+m" (l->a.counter), "=qm" (c)
10897 : "ir" (i) : "memory");
10898 return c;
10899 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10900 {
10901 unsigned char c;
10902
10903 - asm volatile(_ASM_DEC "%0; sete %1"
10904 + asm volatile(_ASM_DEC "%0\n"
10905 +
10906 +#ifdef CONFIG_PAX_REFCOUNT
10907 + "jno 0f\n"
10908 + _ASM_INC "%0\n"
10909 + "int $4\n0:\n"
10910 + _ASM_EXTABLE(0b, 0b)
10911 +#endif
10912 +
10913 + "sete %1\n"
10914 : "+m" (l->a.counter), "=qm" (c)
10915 : : "memory");
10916 return c != 0;
10917 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10918 {
10919 unsigned char c;
10920
10921 - asm volatile(_ASM_INC "%0; sete %1"
10922 + asm volatile(_ASM_INC "%0\n"
10923 +
10924 +#ifdef CONFIG_PAX_REFCOUNT
10925 + "jno 0f\n"
10926 + _ASM_DEC "%0\n"
10927 + "int $4\n0:\n"
10928 + _ASM_EXTABLE(0b, 0b)
10929 +#endif
10930 +
10931 + "sete %1\n"
10932 : "+m" (l->a.counter), "=qm" (c)
10933 : : "memory");
10934 return c != 0;
10935 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10936 {
10937 unsigned char c;
10938
10939 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10940 + asm volatile(_ASM_ADD "%2,%0\n"
10941 +
10942 +#ifdef CONFIG_PAX_REFCOUNT
10943 + "jno 0f\n"
10944 + _ASM_SUB "%2,%0\n"
10945 + "int $4\n0:\n"
10946 + _ASM_EXTABLE(0b, 0b)
10947 +#endif
10948 +
10949 + "sets %1\n"
10950 : "+m" (l->a.counter), "=qm" (c)
10951 : "ir" (i) : "memory");
10952 return c;
10953 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10954 #endif
10955 /* Modern 486+ processor */
10956 __i = i;
10957 - asm volatile(_ASM_XADD "%0, %1;"
10958 + asm volatile(_ASM_XADD "%0, %1\n"
10959 +
10960 +#ifdef CONFIG_PAX_REFCOUNT
10961 + "jno 0f\n"
10962 + _ASM_MOV "%0,%1\n"
10963 + "int $4\n0:\n"
10964 + _ASM_EXTABLE(0b, 0b)
10965 +#endif
10966 +
10967 : "+r" (i), "+m" (l->a.counter)
10968 : : "memory");
10969 return i + __i;
10970 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10971 index 593e51d..fa69c9a 100644
10972 --- a/arch/x86/include/asm/mman.h
10973 +++ b/arch/x86/include/asm/mman.h
10974 @@ -5,4 +5,14 @@
10975
10976 #include <asm-generic/mman.h>
10977
10978 +#ifdef __KERNEL__
10979 +#ifndef __ASSEMBLY__
10980 +#ifdef CONFIG_X86_32
10981 +#define arch_mmap_check i386_mmap_check
10982 +int i386_mmap_check(unsigned long addr, unsigned long len,
10983 + unsigned long flags);
10984 +#endif
10985 +#endif
10986 +#endif
10987 +
10988 #endif /* _ASM_X86_MMAN_H */
10989 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10990 index 5f55e69..e20bfb1 100644
10991 --- a/arch/x86/include/asm/mmu.h
10992 +++ b/arch/x86/include/asm/mmu.h
10993 @@ -9,7 +9,7 @@
10994 * we put the segment information here.
10995 */
10996 typedef struct {
10997 - void *ldt;
10998 + struct desc_struct *ldt;
10999 int size;
11000
11001 #ifdef CONFIG_X86_64
11002 @@ -18,7 +18,19 @@ typedef struct {
11003 #endif
11004
11005 struct mutex lock;
11006 - void *vdso;
11007 + unsigned long vdso;
11008 +
11009 +#ifdef CONFIG_X86_32
11010 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
11011 + unsigned long user_cs_base;
11012 + unsigned long user_cs_limit;
11013 +
11014 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11015 + cpumask_t cpu_user_cs_mask;
11016 +#endif
11017 +
11018 +#endif
11019 +#endif
11020 } mm_context_t;
11021
11022 #ifdef CONFIG_SMP
11023 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
11024 index cdbf367..adb37ac 100644
11025 --- a/arch/x86/include/asm/mmu_context.h
11026 +++ b/arch/x86/include/asm/mmu_context.h
11027 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11028
11029 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11030 {
11031 +
11032 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11033 + unsigned int i;
11034 + pgd_t *pgd;
11035 +
11036 + pax_open_kernel();
11037 + pgd = get_cpu_pgd(smp_processor_id());
11038 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11039 + set_pgd_batched(pgd+i, native_make_pgd(0));
11040 + pax_close_kernel();
11041 +#endif
11042 +
11043 #ifdef CONFIG_SMP
11044 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11045 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11046 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11047 struct task_struct *tsk)
11048 {
11049 unsigned cpu = smp_processor_id();
11050 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11051 + int tlbstate = TLBSTATE_OK;
11052 +#endif
11053
11054 if (likely(prev != next)) {
11055 #ifdef CONFIG_SMP
11056 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11057 + tlbstate = this_cpu_read(cpu_tlbstate.state);
11058 +#endif
11059 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11060 this_cpu_write(cpu_tlbstate.active_mm, next);
11061 #endif
11062 cpumask_set_cpu(cpu, mm_cpumask(next));
11063
11064 /* Re-load page tables */
11065 +#ifdef CONFIG_PAX_PER_CPU_PGD
11066 + pax_open_kernel();
11067 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11068 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11069 + pax_close_kernel();
11070 + load_cr3(get_cpu_pgd(cpu));
11071 +#else
11072 load_cr3(next->pgd);
11073 +#endif
11074
11075 /* stop flush ipis for the previous mm */
11076 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11077 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11078 */
11079 if (unlikely(prev->context.ldt != next->context.ldt))
11080 load_LDT_nolock(&next->context);
11081 - }
11082 +
11083 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11084 + if (!(__supported_pte_mask & _PAGE_NX)) {
11085 + smp_mb__before_clear_bit();
11086 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11087 + smp_mb__after_clear_bit();
11088 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11089 + }
11090 +#endif
11091 +
11092 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11093 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11094 + prev->context.user_cs_limit != next->context.user_cs_limit))
11095 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11096 #ifdef CONFIG_SMP
11097 + else if (unlikely(tlbstate != TLBSTATE_OK))
11098 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11099 +#endif
11100 +#endif
11101 +
11102 + }
11103 else {
11104 +
11105 +#ifdef CONFIG_PAX_PER_CPU_PGD
11106 + pax_open_kernel();
11107 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11108 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11109 + pax_close_kernel();
11110 + load_cr3(get_cpu_pgd(cpu));
11111 +#endif
11112 +
11113 +#ifdef CONFIG_SMP
11114 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11115 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11116
11117 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11118 * tlb flush IPI delivery. We must reload CR3
11119 * to make sure to use no freed page tables.
11120 */
11121 +
11122 +#ifndef CONFIG_PAX_PER_CPU_PGD
11123 load_cr3(next->pgd);
11124 +#endif
11125 +
11126 load_LDT_nolock(&next->context);
11127 +
11128 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11129 + if (!(__supported_pte_mask & _PAGE_NX))
11130 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11131 +#endif
11132 +
11133 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11134 +#ifdef CONFIG_PAX_PAGEEXEC
11135 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11136 +#endif
11137 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11138 +#endif
11139 +
11140 }
11141 +#endif
11142 }
11143 -#endif
11144 }
11145
11146 #define activate_mm(prev, next) \
11147 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11148 index 9eae775..c914fea 100644
11149 --- a/arch/x86/include/asm/module.h
11150 +++ b/arch/x86/include/asm/module.h
11151 @@ -5,6 +5,7 @@
11152
11153 #ifdef CONFIG_X86_64
11154 /* X86_64 does not define MODULE_PROC_FAMILY */
11155 +#define MODULE_PROC_FAMILY ""
11156 #elif defined CONFIG_M386
11157 #define MODULE_PROC_FAMILY "386 "
11158 #elif defined CONFIG_M486
11159 @@ -59,8 +60,20 @@
11160 #error unknown processor family
11161 #endif
11162
11163 -#ifdef CONFIG_X86_32
11164 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11165 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11166 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11167 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11168 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11169 +#else
11170 +#define MODULE_PAX_KERNEXEC ""
11171 #endif
11172
11173 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11174 +#define MODULE_PAX_UDEREF "UDEREF "
11175 +#else
11176 +#define MODULE_PAX_UDEREF ""
11177 +#endif
11178 +
11179 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11180 +
11181 #endif /* _ASM_X86_MODULE_H */
11182 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11183 index 320f7bb..e89f8f8 100644
11184 --- a/arch/x86/include/asm/page_64_types.h
11185 +++ b/arch/x86/include/asm/page_64_types.h
11186 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11187
11188 /* duplicated to the one in bootmem.h */
11189 extern unsigned long max_pfn;
11190 -extern unsigned long phys_base;
11191 +extern const unsigned long phys_base;
11192
11193 extern unsigned long __phys_addr(unsigned long);
11194 #define __phys_reloc_hide(x) (x)
11195 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11196 index a0facf3..c017b15 100644
11197 --- a/arch/x86/include/asm/paravirt.h
11198 +++ b/arch/x86/include/asm/paravirt.h
11199 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11200 val);
11201 }
11202
11203 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11204 +{
11205 + pgdval_t val = native_pgd_val(pgd);
11206 +
11207 + if (sizeof(pgdval_t) > sizeof(long))
11208 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11209 + val, (u64)val >> 32);
11210 + else
11211 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11212 + val);
11213 +}
11214 +
11215 static inline void pgd_clear(pgd_t *pgdp)
11216 {
11217 set_pgd(pgdp, __pgd(0));
11218 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11219 pv_mmu_ops.set_fixmap(idx, phys, flags);
11220 }
11221
11222 +#ifdef CONFIG_PAX_KERNEXEC
11223 +static inline unsigned long pax_open_kernel(void)
11224 +{
11225 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11226 +}
11227 +
11228 +static inline unsigned long pax_close_kernel(void)
11229 +{
11230 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11231 +}
11232 +#else
11233 +static inline unsigned long pax_open_kernel(void) { return 0; }
11234 +static inline unsigned long pax_close_kernel(void) { return 0; }
11235 +#endif
11236 +
11237 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11238
11239 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11240 @@ -929,7 +956,7 @@ extern void default_banner(void);
11241
11242 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11243 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11244 -#define PARA_INDIRECT(addr) *%cs:addr
11245 +#define PARA_INDIRECT(addr) *%ss:addr
11246 #endif
11247
11248 #define INTERRUPT_RETURN \
11249 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
11250 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11251 CLBR_NONE, \
11252 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11253 +
11254 +#define GET_CR0_INTO_RDI \
11255 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11256 + mov %rax,%rdi
11257 +
11258 +#define SET_RDI_INTO_CR0 \
11259 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11260 +
11261 +#define GET_CR3_INTO_RDI \
11262 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11263 + mov %rax,%rdi
11264 +
11265 +#define SET_RDI_INTO_CR3 \
11266 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11267 +
11268 #endif /* CONFIG_X86_32 */
11269
11270 #endif /* __ASSEMBLY__ */
11271 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11272 index 142236e..6a6b4a6 100644
11273 --- a/arch/x86/include/asm/paravirt_types.h
11274 +++ b/arch/x86/include/asm/paravirt_types.h
11275 @@ -84,20 +84,20 @@ struct pv_init_ops {
11276 */
11277 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11278 unsigned long addr, unsigned len);
11279 -};
11280 +} __no_const;
11281
11282
11283 struct pv_lazy_ops {
11284 /* Set deferred update mode, used for batching operations. */
11285 void (*enter)(void);
11286 void (*leave)(void);
11287 -};
11288 +} __no_const;
11289
11290 struct pv_time_ops {
11291 unsigned long long (*sched_clock)(void);
11292 unsigned long long (*steal_clock)(int cpu);
11293 unsigned long (*get_tsc_khz)(void);
11294 -};
11295 +} __no_const;
11296
11297 struct pv_cpu_ops {
11298 /* hooks for various privileged instructions */
11299 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
11300
11301 void (*start_context_switch)(struct task_struct *prev);
11302 void (*end_context_switch)(struct task_struct *next);
11303 -};
11304 +} __no_const;
11305
11306 struct pv_irq_ops {
11307 /*
11308 @@ -222,7 +222,7 @@ struct pv_apic_ops {
11309 unsigned long start_eip,
11310 unsigned long start_esp);
11311 #endif
11312 -};
11313 +} __no_const;
11314
11315 struct pv_mmu_ops {
11316 unsigned long (*read_cr2)(void);
11317 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
11318 struct paravirt_callee_save make_pud;
11319
11320 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11321 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11322 #endif /* PAGETABLE_LEVELS == 4 */
11323 #endif /* PAGETABLE_LEVELS >= 3 */
11324
11325 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
11326 an mfn. We can tell which is which from the index. */
11327 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11328 phys_addr_t phys, pgprot_t flags);
11329 +
11330 +#ifdef CONFIG_PAX_KERNEXEC
11331 + unsigned long (*pax_open_kernel)(void);
11332 + unsigned long (*pax_close_kernel)(void);
11333 +#endif
11334 +
11335 };
11336
11337 struct arch_spinlock;
11338 @@ -333,7 +340,7 @@ struct pv_lock_ops {
11339 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11340 int (*spin_trylock)(struct arch_spinlock *lock);
11341 void (*spin_unlock)(struct arch_spinlock *lock);
11342 -};
11343 +} __no_const;
11344
11345 /* This contains all the paravirt structures: we get a convenient
11346 * number for each function using the offset which we use to indicate
11347 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11348 index b4389a4..7024269 100644
11349 --- a/arch/x86/include/asm/pgalloc.h
11350 +++ b/arch/x86/include/asm/pgalloc.h
11351 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11352 pmd_t *pmd, pte_t *pte)
11353 {
11354 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11355 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11356 +}
11357 +
11358 +static inline void pmd_populate_user(struct mm_struct *mm,
11359 + pmd_t *pmd, pte_t *pte)
11360 +{
11361 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11362 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11363 }
11364
11365 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11366
11367 #ifdef CONFIG_X86_PAE
11368 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11369 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11370 +{
11371 + pud_populate(mm, pudp, pmd);
11372 +}
11373 #else /* !CONFIG_X86_PAE */
11374 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11375 {
11376 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11377 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11378 }
11379 +
11380 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11381 +{
11382 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11383 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11384 +}
11385 #endif /* CONFIG_X86_PAE */
11386
11387 #if PAGETABLE_LEVELS > 3
11388 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11389 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11390 }
11391
11392 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11393 +{
11394 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11395 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11396 +}
11397 +
11398 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11399 {
11400 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11401 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11402 index f2b489c..4f7e2e5 100644
11403 --- a/arch/x86/include/asm/pgtable-2level.h
11404 +++ b/arch/x86/include/asm/pgtable-2level.h
11405 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11406
11407 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11408 {
11409 + pax_open_kernel();
11410 *pmdp = pmd;
11411 + pax_close_kernel();
11412 }
11413
11414 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11415 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11416 index 4cc9f2b..5fd9226 100644
11417 --- a/arch/x86/include/asm/pgtable-3level.h
11418 +++ b/arch/x86/include/asm/pgtable-3level.h
11419 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11420
11421 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11422 {
11423 + pax_open_kernel();
11424 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11425 + pax_close_kernel();
11426 }
11427
11428 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11429 {
11430 + pax_open_kernel();
11431 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11432 + pax_close_kernel();
11433 }
11434
11435 /*
11436 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11437 index c3520d7..cf742ef 100644
11438 --- a/arch/x86/include/asm/pgtable.h
11439 +++ b/arch/x86/include/asm/pgtable.h
11440 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11441
11442 #ifndef __PAGETABLE_PUD_FOLDED
11443 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11444 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11445 #define pgd_clear(pgd) native_pgd_clear(pgd)
11446 #endif
11447
11448 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11449
11450 #define arch_end_context_switch(prev) do {} while(0)
11451
11452 +#define pax_open_kernel() native_pax_open_kernel()
11453 +#define pax_close_kernel() native_pax_close_kernel()
11454 #endif /* CONFIG_PARAVIRT */
11455
11456 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11457 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11458 +
11459 +#ifdef CONFIG_PAX_KERNEXEC
11460 +static inline unsigned long native_pax_open_kernel(void)
11461 +{
11462 + unsigned long cr0;
11463 +
11464 + preempt_disable();
11465 + barrier();
11466 + cr0 = read_cr0() ^ X86_CR0_WP;
11467 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11468 + write_cr0(cr0);
11469 + return cr0 ^ X86_CR0_WP;
11470 +}
11471 +
11472 +static inline unsigned long native_pax_close_kernel(void)
11473 +{
11474 + unsigned long cr0;
11475 +
11476 + cr0 = read_cr0() ^ X86_CR0_WP;
11477 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11478 + write_cr0(cr0);
11479 + barrier();
11480 + preempt_enable_no_resched();
11481 + return cr0 ^ X86_CR0_WP;
11482 +}
11483 +#else
11484 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11485 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11486 +#endif
11487 +
11488 /*
11489 * The following only work if pte_present() is true.
11490 * Undefined behaviour if not..
11491 */
11492 +static inline int pte_user(pte_t pte)
11493 +{
11494 + return pte_val(pte) & _PAGE_USER;
11495 +}
11496 +
11497 static inline int pte_dirty(pte_t pte)
11498 {
11499 return pte_flags(pte) & _PAGE_DIRTY;
11500 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11501 return pte_clear_flags(pte, _PAGE_RW);
11502 }
11503
11504 +static inline pte_t pte_mkread(pte_t pte)
11505 +{
11506 + return __pte(pte_val(pte) | _PAGE_USER);
11507 +}
11508 +
11509 static inline pte_t pte_mkexec(pte_t pte)
11510 {
11511 - return pte_clear_flags(pte, _PAGE_NX);
11512 +#ifdef CONFIG_X86_PAE
11513 + if (__supported_pte_mask & _PAGE_NX)
11514 + return pte_clear_flags(pte, _PAGE_NX);
11515 + else
11516 +#endif
11517 + return pte_set_flags(pte, _PAGE_USER);
11518 +}
11519 +
11520 +static inline pte_t pte_exprotect(pte_t pte)
11521 +{
11522 +#ifdef CONFIG_X86_PAE
11523 + if (__supported_pte_mask & _PAGE_NX)
11524 + return pte_set_flags(pte, _PAGE_NX);
11525 + else
11526 +#endif
11527 + return pte_clear_flags(pte, _PAGE_USER);
11528 }
11529
11530 static inline pte_t pte_mkdirty(pte_t pte)
11531 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11532 #endif
11533
11534 #ifndef __ASSEMBLY__
11535 +
11536 +#ifdef CONFIG_PAX_PER_CPU_PGD
11537 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11538 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11539 +{
11540 + return cpu_pgd[cpu];
11541 +}
11542 +#endif
11543 +
11544 #include <linux/mm_types.h>
11545
11546 static inline int pte_none(pte_t pte)
11547 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11548
11549 static inline int pgd_bad(pgd_t pgd)
11550 {
11551 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11552 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11553 }
11554
11555 static inline int pgd_none(pgd_t pgd)
11556 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11557 * pgd_offset() returns a (pgd_t *)
11558 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11559 */
11560 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11561 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11562 +
11563 +#ifdef CONFIG_PAX_PER_CPU_PGD
11564 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11565 +#endif
11566 +
11567 /*
11568 * a shortcut which implies the use of the kernel's pgd, instead
11569 * of a process's
11570 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11571 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11572 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11573
11574 +#ifdef CONFIG_X86_32
11575 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11576 +#else
11577 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11578 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11579 +
11580 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11581 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11582 +#else
11583 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11584 +#endif
11585 +
11586 +#endif
11587 +
11588 #ifndef __ASSEMBLY__
11589
11590 extern int direct_gbpages;
11591 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11592 * dst and src can be on the same page, but the range must not overlap,
11593 * and must not cross a page boundary.
11594 */
11595 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11596 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11597 {
11598 - memcpy(dst, src, count * sizeof(pgd_t));
11599 + pax_open_kernel();
11600 + while (count--)
11601 + *dst++ = *src++;
11602 + pax_close_kernel();
11603 }
11604
11605 +#ifdef CONFIG_PAX_PER_CPU_PGD
11606 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11607 +#endif
11608 +
11609 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11610 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11611 +#else
11612 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11613 +#endif
11614
11615 #include <asm-generic/pgtable.h>
11616 #endif /* __ASSEMBLY__ */
11617 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11618 index 0c92113..34a77c6 100644
11619 --- a/arch/x86/include/asm/pgtable_32.h
11620 +++ b/arch/x86/include/asm/pgtable_32.h
11621 @@ -25,9 +25,6 @@
11622 struct mm_struct;
11623 struct vm_area_struct;
11624
11625 -extern pgd_t swapper_pg_dir[1024];
11626 -extern pgd_t initial_page_table[1024];
11627 -
11628 static inline void pgtable_cache_init(void) { }
11629 static inline void check_pgt_cache(void) { }
11630 void paging_init(void);
11631 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11632 # include <asm/pgtable-2level.h>
11633 #endif
11634
11635 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11636 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11637 +#ifdef CONFIG_X86_PAE
11638 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11639 +#endif
11640 +
11641 #if defined(CONFIG_HIGHPTE)
11642 #define pte_offset_map(dir, address) \
11643 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11644 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11645 /* Clear a kernel PTE and flush it from the TLB */
11646 #define kpte_clear_flush(ptep, vaddr) \
11647 do { \
11648 + pax_open_kernel(); \
11649 pte_clear(&init_mm, (vaddr), (ptep)); \
11650 + pax_close_kernel(); \
11651 __flush_tlb_one((vaddr)); \
11652 } while (0)
11653
11654 @@ -74,6 +79,9 @@ do { \
11655
11656 #endif /* !__ASSEMBLY__ */
11657
11658 +#define HAVE_ARCH_UNMAPPED_AREA
11659 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11660 +
11661 /*
11662 * kern_addr_valid() is (1) for FLATMEM and (0) for
11663 * SPARSEMEM and DISCONTIGMEM
11664 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11665 index ed5903b..c7fe163 100644
11666 --- a/arch/x86/include/asm/pgtable_32_types.h
11667 +++ b/arch/x86/include/asm/pgtable_32_types.h
11668 @@ -8,7 +8,7 @@
11669 */
11670 #ifdef CONFIG_X86_PAE
11671 # include <asm/pgtable-3level_types.h>
11672 -# define PMD_SIZE (1UL << PMD_SHIFT)
11673 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11674 # define PMD_MASK (~(PMD_SIZE - 1))
11675 #else
11676 # include <asm/pgtable-2level_types.h>
11677 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11678 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11679 #endif
11680
11681 +#ifdef CONFIG_PAX_KERNEXEC
11682 +#ifndef __ASSEMBLY__
11683 +extern unsigned char MODULES_EXEC_VADDR[];
11684 +extern unsigned char MODULES_EXEC_END[];
11685 +#endif
11686 +#include <asm/boot.h>
11687 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11688 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11689 +#else
11690 +#define ktla_ktva(addr) (addr)
11691 +#define ktva_ktla(addr) (addr)
11692 +#endif
11693 +
11694 #define MODULES_VADDR VMALLOC_START
11695 #define MODULES_END VMALLOC_END
11696 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11697 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11698 index 8251be0..4ea8b46 100644
11699 --- a/arch/x86/include/asm/pgtable_64.h
11700 +++ b/arch/x86/include/asm/pgtable_64.h
11701 @@ -16,10 +16,14 @@
11702
11703 extern pud_t level3_kernel_pgt[512];
11704 extern pud_t level3_ident_pgt[512];
11705 +extern pud_t level3_vmalloc_start_pgt[512];
11706 +extern pud_t level3_vmalloc_end_pgt[512];
11707 +extern pud_t level3_vmemmap_pgt[512];
11708 +extern pud_t level2_vmemmap_pgt[512];
11709 extern pmd_t level2_kernel_pgt[512];
11710 extern pmd_t level2_fixmap_pgt[512];
11711 -extern pmd_t level2_ident_pgt[512];
11712 -extern pgd_t init_level4_pgt[];
11713 +extern pmd_t level2_ident_pgt[512*2];
11714 +extern pgd_t init_level4_pgt[512];
11715
11716 #define swapper_pg_dir init_level4_pgt
11717
11718 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11719
11720 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11721 {
11722 + pax_open_kernel();
11723 *pmdp = pmd;
11724 + pax_close_kernel();
11725 }
11726
11727 static inline void native_pmd_clear(pmd_t *pmd)
11728 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11729
11730 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11731 {
11732 + pax_open_kernel();
11733 *pudp = pud;
11734 + pax_close_kernel();
11735 }
11736
11737 static inline void native_pud_clear(pud_t *pud)
11738 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11739
11740 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11741 {
11742 + pax_open_kernel();
11743 + *pgdp = pgd;
11744 + pax_close_kernel();
11745 +}
11746 +
11747 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11748 +{
11749 *pgdp = pgd;
11750 }
11751
11752 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11753 index 766ea16..5b96cb3 100644
11754 --- a/arch/x86/include/asm/pgtable_64_types.h
11755 +++ b/arch/x86/include/asm/pgtable_64_types.h
11756 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11757 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11758 #define MODULES_END _AC(0xffffffffff000000, UL)
11759 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11760 +#define MODULES_EXEC_VADDR MODULES_VADDR
11761 +#define MODULES_EXEC_END MODULES_END
11762 +
11763 +#define ktla_ktva(addr) (addr)
11764 +#define ktva_ktla(addr) (addr)
11765
11766 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11767 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11768 index 013286a..8b42f4f 100644
11769 --- a/arch/x86/include/asm/pgtable_types.h
11770 +++ b/arch/x86/include/asm/pgtable_types.h
11771 @@ -16,13 +16,12 @@
11772 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11773 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11774 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11775 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11776 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11777 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11778 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11779 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11780 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11781 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11782 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11783 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11784 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11785 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11786
11787 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11788 @@ -40,7 +39,6 @@
11789 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11790 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11791 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11792 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11793 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11794 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11795 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11796 @@ -57,8 +55,10 @@
11797
11798 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11799 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11800 -#else
11801 +#elif defined(CONFIG_KMEMCHECK)
11802 #define _PAGE_NX (_AT(pteval_t, 0))
11803 +#else
11804 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11805 #endif
11806
11807 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11808 @@ -96,6 +96,9 @@
11809 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11810 _PAGE_ACCESSED)
11811
11812 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11813 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11814 +
11815 #define __PAGE_KERNEL_EXEC \
11816 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11817 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11818 @@ -106,7 +109,7 @@
11819 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11820 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11821 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11822 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11823 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11824 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11825 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11826 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11827 @@ -168,8 +171,8 @@
11828 * bits are combined, this will alow user to access the high address mapped
11829 * VDSO in the presence of CONFIG_COMPAT_VDSO
11830 */
11831 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11832 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11833 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11834 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11835 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11836 #endif
11837
11838 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11839 {
11840 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11841 }
11842 +#endif
11843
11844 +#if PAGETABLE_LEVELS == 3
11845 +#include <asm-generic/pgtable-nopud.h>
11846 +#endif
11847 +
11848 +#if PAGETABLE_LEVELS == 2
11849 +#include <asm-generic/pgtable-nopmd.h>
11850 +#endif
11851 +
11852 +#ifndef __ASSEMBLY__
11853 #if PAGETABLE_LEVELS > 3
11854 typedef struct { pudval_t pud; } pud_t;
11855
11856 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11857 return pud.pud;
11858 }
11859 #else
11860 -#include <asm-generic/pgtable-nopud.h>
11861 -
11862 static inline pudval_t native_pud_val(pud_t pud)
11863 {
11864 return native_pgd_val(pud.pgd);
11865 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11866 return pmd.pmd;
11867 }
11868 #else
11869 -#include <asm-generic/pgtable-nopmd.h>
11870 -
11871 static inline pmdval_t native_pmd_val(pmd_t pmd)
11872 {
11873 return native_pgd_val(pmd.pud.pgd);
11874 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11875
11876 extern pteval_t __supported_pte_mask;
11877 extern void set_nx(void);
11878 -extern int nx_enabled;
11879
11880 #define pgprot_writecombine pgprot_writecombine
11881 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11882 diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11883 index aea1d1d..680cf09 100644
11884 --- a/arch/x86/include/asm/processor-flags.h
11885 +++ b/arch/x86/include/asm/processor-flags.h
11886 @@ -65,6 +65,7 @@
11887 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11888 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11889 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11890 +#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11891
11892 /*
11893 * x86-64 Task Priority Register, CR8
11894 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11895 index d048cad..45e350f 100644
11896 --- a/arch/x86/include/asm/processor.h
11897 +++ b/arch/x86/include/asm/processor.h
11898 @@ -289,7 +289,7 @@ struct tss_struct {
11899
11900 } ____cacheline_aligned;
11901
11902 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11903 +extern struct tss_struct init_tss[NR_CPUS];
11904
11905 /*
11906 * Save the original ist values for checking stack pointers during debugging
11907 @@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11908 */
11909 #define TASK_SIZE PAGE_OFFSET
11910 #define TASK_SIZE_MAX TASK_SIZE
11911 +
11912 +#ifdef CONFIG_PAX_SEGMEXEC
11913 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11914 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11915 +#else
11916 #define STACK_TOP TASK_SIZE
11917 -#define STACK_TOP_MAX STACK_TOP
11918 +#endif
11919 +
11920 +#define STACK_TOP_MAX TASK_SIZE
11921
11922 #define INIT_THREAD { \
11923 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11924 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11925 .vm86_info = NULL, \
11926 .sysenter_cs = __KERNEL_CS, \
11927 .io_bitmap_ptr = NULL, \
11928 @@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11929 */
11930 #define INIT_TSS { \
11931 .x86_tss = { \
11932 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11933 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11934 .ss0 = __KERNEL_DS, \
11935 .ss1 = __KERNEL_CS, \
11936 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11937 @@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11938 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11939
11940 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11941 -#define KSTK_TOP(info) \
11942 -({ \
11943 - unsigned long *__ptr = (unsigned long *)(info); \
11944 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11945 -})
11946 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11947
11948 /*
11949 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11950 @@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11951 #define task_pt_regs(task) \
11952 ({ \
11953 struct pt_regs *__regs__; \
11954 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11955 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11956 __regs__ - 1; \
11957 })
11958
11959 @@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11960 /*
11961 * User space process size. 47bits minus one guard page.
11962 */
11963 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11964 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11965
11966 /* This decides where the kernel will search for a free chunk of vm
11967 * space during mmap's.
11968 */
11969 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11970 - 0xc0000000 : 0xFFFFe000)
11971 + 0xc0000000 : 0xFFFFf000)
11972
11973 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11974 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11975 @@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11976 #define STACK_TOP_MAX TASK_SIZE_MAX
11977
11978 #define INIT_THREAD { \
11979 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11980 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11981 }
11982
11983 #define INIT_TSS { \
11984 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11985 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11986 }
11987
11988 /*
11989 @@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11990 */
11991 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11992
11993 +#ifdef CONFIG_PAX_SEGMEXEC
11994 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11995 +#endif
11996 +
11997 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11998
11999 /* Get/set a process' ability to use the timestamp counter instruction */
12000 @@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
12001 #define cpu_has_amd_erratum(x) (false)
12002 #endif /* CONFIG_CPU_SUP_AMD */
12003
12004 -extern unsigned long arch_align_stack(unsigned long sp);
12005 +#define arch_align_stack(x) ((x) & ~0xfUL)
12006 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12007
12008 void default_idle(void);
12009 bool set_pm_idle_to_default(void);
12010
12011 -void stop_this_cpu(void *dummy);
12012 +void stop_this_cpu(void *dummy) __noreturn;
12013
12014 #endif /* _ASM_X86_PROCESSOR_H */
12015 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
12016 index dcfde52..dbfea06 100644
12017 --- a/arch/x86/include/asm/ptrace.h
12018 +++ b/arch/x86/include/asm/ptrace.h
12019 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
12020 }
12021
12022 /*
12023 - * user_mode_vm(regs) determines whether a register set came from user mode.
12024 + * user_mode(regs) determines whether a register set came from user mode.
12025 * This is true if V8086 mode was enabled OR if the register set was from
12026 * protected mode with RPL-3 CS value. This tricky test checks that with
12027 * one comparison. Many places in the kernel can bypass this full check
12028 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12029 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12030 + * be used.
12031 */
12032 -static inline int user_mode(struct pt_regs *regs)
12033 +static inline int user_mode_novm(struct pt_regs *regs)
12034 {
12035 #ifdef CONFIG_X86_32
12036 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12037 #else
12038 - return !!(regs->cs & 3);
12039 + return !!(regs->cs & SEGMENT_RPL_MASK);
12040 #endif
12041 }
12042
12043 -static inline int user_mode_vm(struct pt_regs *regs)
12044 +static inline int user_mode(struct pt_regs *regs)
12045 {
12046 #ifdef CONFIG_X86_32
12047 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12048 USER_RPL;
12049 #else
12050 - return user_mode(regs);
12051 + return user_mode_novm(regs);
12052 #endif
12053 }
12054
12055 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12056 #ifdef CONFIG_X86_64
12057 static inline bool user_64bit_mode(struct pt_regs *regs)
12058 {
12059 + unsigned long cs = regs->cs & 0xffff;
12060 #ifndef CONFIG_PARAVIRT
12061 /*
12062 * On non-paravirt systems, this is the only long mode CPL 3
12063 * selector. We do not allow long mode selectors in the LDT.
12064 */
12065 - return regs->cs == __USER_CS;
12066 + return cs == __USER_CS;
12067 #else
12068 /* Headers are too twisted for this to go in paravirt.h. */
12069 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12070 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12071 #endif
12072 }
12073 #endif
12074 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12075 index fe1ec5b..dc5c3fe 100644
12076 --- a/arch/x86/include/asm/realmode.h
12077 +++ b/arch/x86/include/asm/realmode.h
12078 @@ -22,16 +22,14 @@ struct real_mode_header {
12079 #endif
12080 /* APM/BIOS reboot */
12081 u32 machine_real_restart_asm;
12082 -#ifdef CONFIG_X86_64
12083 u32 machine_real_restart_seg;
12084 -#endif
12085 };
12086
12087 /* This must match data at trampoline_32/64.S */
12088 struct trampoline_header {
12089 #ifdef CONFIG_X86_32
12090 u32 start;
12091 - u16 gdt_pad;
12092 + u16 boot_cs;
12093 u16 gdt_limit;
12094 u32 gdt_base;
12095 #else
12096 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12097 index a82c4f1..ac45053 100644
12098 --- a/arch/x86/include/asm/reboot.h
12099 +++ b/arch/x86/include/asm/reboot.h
12100 @@ -6,13 +6,13 @@
12101 struct pt_regs;
12102
12103 struct machine_ops {
12104 - void (*restart)(char *cmd);
12105 - void (*halt)(void);
12106 - void (*power_off)(void);
12107 + void (* __noreturn restart)(char *cmd);
12108 + void (* __noreturn halt)(void);
12109 + void (* __noreturn power_off)(void);
12110 void (*shutdown)(void);
12111 void (*crash_shutdown)(struct pt_regs *);
12112 - void (*emergency_restart)(void);
12113 -};
12114 + void (* __noreturn emergency_restart)(void);
12115 +} __no_const;
12116
12117 extern struct machine_ops machine_ops;
12118
12119 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12120 index 2dbe4a7..ce1db00 100644
12121 --- a/arch/x86/include/asm/rwsem.h
12122 +++ b/arch/x86/include/asm/rwsem.h
12123 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12124 {
12125 asm volatile("# beginning down_read\n\t"
12126 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12127 +
12128 +#ifdef CONFIG_PAX_REFCOUNT
12129 + "jno 0f\n"
12130 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12131 + "int $4\n0:\n"
12132 + _ASM_EXTABLE(0b, 0b)
12133 +#endif
12134 +
12135 /* adds 0x00000001 */
12136 " jns 1f\n"
12137 " call call_rwsem_down_read_failed\n"
12138 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12139 "1:\n\t"
12140 " mov %1,%2\n\t"
12141 " add %3,%2\n\t"
12142 +
12143 +#ifdef CONFIG_PAX_REFCOUNT
12144 + "jno 0f\n"
12145 + "sub %3,%2\n"
12146 + "int $4\n0:\n"
12147 + _ASM_EXTABLE(0b, 0b)
12148 +#endif
12149 +
12150 " jle 2f\n\t"
12151 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12152 " jnz 1b\n\t"
12153 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12154 long tmp;
12155 asm volatile("# beginning down_write\n\t"
12156 LOCK_PREFIX " xadd %1,(%2)\n\t"
12157 +
12158 +#ifdef CONFIG_PAX_REFCOUNT
12159 + "jno 0f\n"
12160 + "mov %1,(%2)\n"
12161 + "int $4\n0:\n"
12162 + _ASM_EXTABLE(0b, 0b)
12163 +#endif
12164 +
12165 /* adds 0xffff0001, returns the old value */
12166 " test %1,%1\n\t"
12167 /* was the count 0 before? */
12168 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12169 long tmp;
12170 asm volatile("# beginning __up_read\n\t"
12171 LOCK_PREFIX " xadd %1,(%2)\n\t"
12172 +
12173 +#ifdef CONFIG_PAX_REFCOUNT
12174 + "jno 0f\n"
12175 + "mov %1,(%2)\n"
12176 + "int $4\n0:\n"
12177 + _ASM_EXTABLE(0b, 0b)
12178 +#endif
12179 +
12180 /* subtracts 1, returns the old value */
12181 " jns 1f\n\t"
12182 " call call_rwsem_wake\n" /* expects old value in %edx */
12183 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12184 long tmp;
12185 asm volatile("# beginning __up_write\n\t"
12186 LOCK_PREFIX " xadd %1,(%2)\n\t"
12187 +
12188 +#ifdef CONFIG_PAX_REFCOUNT
12189 + "jno 0f\n"
12190 + "mov %1,(%2)\n"
12191 + "int $4\n0:\n"
12192 + _ASM_EXTABLE(0b, 0b)
12193 +#endif
12194 +
12195 /* subtracts 0xffff0001, returns the old value */
12196 " jns 1f\n\t"
12197 " call call_rwsem_wake\n" /* expects old value in %edx */
12198 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12199 {
12200 asm volatile("# beginning __downgrade_write\n\t"
12201 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12202 +
12203 +#ifdef CONFIG_PAX_REFCOUNT
12204 + "jno 0f\n"
12205 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12206 + "int $4\n0:\n"
12207 + _ASM_EXTABLE(0b, 0b)
12208 +#endif
12209 +
12210 /*
12211 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12212 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12213 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12214 */
12215 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12216 {
12217 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12218 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12219 +
12220 +#ifdef CONFIG_PAX_REFCOUNT
12221 + "jno 0f\n"
12222 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12223 + "int $4\n0:\n"
12224 + _ASM_EXTABLE(0b, 0b)
12225 +#endif
12226 +
12227 : "+m" (sem->count)
12228 : "er" (delta));
12229 }
12230 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12231 */
12232 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12233 {
12234 - return delta + xadd(&sem->count, delta);
12235 + return delta + xadd_check_overflow(&sem->count, delta);
12236 }
12237
12238 #endif /* __KERNEL__ */
12239 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12240 index c48a950..c6d7468 100644
12241 --- a/arch/x86/include/asm/segment.h
12242 +++ b/arch/x86/include/asm/segment.h
12243 @@ -64,10 +64,15 @@
12244 * 26 - ESPFIX small SS
12245 * 27 - per-cpu [ offset to per-cpu data area ]
12246 * 28 - stack_canary-20 [ for stack protector ]
12247 - * 29 - unused
12248 - * 30 - unused
12249 + * 29 - PCI BIOS CS
12250 + * 30 - PCI BIOS DS
12251 * 31 - TSS for double fault handler
12252 */
12253 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12254 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12255 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12256 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12257 +
12258 #define GDT_ENTRY_TLS_MIN 6
12259 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12260
12261 @@ -79,6 +84,8 @@
12262
12263 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12264
12265 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12266 +
12267 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12268
12269 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12270 @@ -104,6 +111,12 @@
12271 #define __KERNEL_STACK_CANARY 0
12272 #endif
12273
12274 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12275 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12276 +
12277 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12278 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12279 +
12280 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12281
12282 /*
12283 @@ -141,7 +154,7 @@
12284 */
12285
12286 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12287 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12288 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12289
12290
12291 #else
12292 @@ -165,6 +178,8 @@
12293 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12294 #define __USER32_DS __USER_DS
12295
12296 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12297 +
12298 #define GDT_ENTRY_TSS 8 /* needs two entries */
12299 #define GDT_ENTRY_LDT 10 /* needs two entries */
12300 #define GDT_ENTRY_TLS_MIN 12
12301 @@ -185,6 +200,7 @@
12302 #endif
12303
12304 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12305 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12306 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12307 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12308 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12309 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12310 {
12311 unsigned long __limit;
12312 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12313 - return __limit + 1;
12314 + return __limit;
12315 }
12316
12317 #endif /* !__ASSEMBLY__ */
12318 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12319 index 4f19a15..9e14f27 100644
12320 --- a/arch/x86/include/asm/smp.h
12321 +++ b/arch/x86/include/asm/smp.h
12322 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12323 /* cpus sharing the last level cache: */
12324 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12325 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12326 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12327 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12328
12329 static inline struct cpumask *cpu_sibling_mask(int cpu)
12330 {
12331 @@ -79,7 +79,7 @@ struct smp_ops {
12332
12333 void (*send_call_func_ipi)(const struct cpumask *mask);
12334 void (*send_call_func_single_ipi)(int cpu);
12335 -};
12336 +} __no_const;
12337
12338 /* Globals due to paravirt */
12339 extern void set_cpu_sibling_map(int cpu);
12340 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12341 extern int safe_smp_processor_id(void);
12342
12343 #elif defined(CONFIG_X86_64_SMP)
12344 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12345 -
12346 -#define stack_smp_processor_id() \
12347 -({ \
12348 - struct thread_info *ti; \
12349 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12350 - ti->cpu; \
12351 -})
12352 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12353 +#define stack_smp_processor_id() raw_smp_processor_id()
12354 #define safe_smp_processor_id() smp_processor_id()
12355
12356 #endif
12357 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12358 index 33692ea..350a534 100644
12359 --- a/arch/x86/include/asm/spinlock.h
12360 +++ b/arch/x86/include/asm/spinlock.h
12361 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12362 static inline void arch_read_lock(arch_rwlock_t *rw)
12363 {
12364 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12365 +
12366 +#ifdef CONFIG_PAX_REFCOUNT
12367 + "jno 0f\n"
12368 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12369 + "int $4\n0:\n"
12370 + _ASM_EXTABLE(0b, 0b)
12371 +#endif
12372 +
12373 "jns 1f\n"
12374 "call __read_lock_failed\n\t"
12375 "1:\n"
12376 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12377 static inline void arch_write_lock(arch_rwlock_t *rw)
12378 {
12379 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12380 +
12381 +#ifdef CONFIG_PAX_REFCOUNT
12382 + "jno 0f\n"
12383 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12384 + "int $4\n0:\n"
12385 + _ASM_EXTABLE(0b, 0b)
12386 +#endif
12387 +
12388 "jz 1f\n"
12389 "call __write_lock_failed\n\t"
12390 "1:\n"
12391 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12392
12393 static inline void arch_read_unlock(arch_rwlock_t *rw)
12394 {
12395 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12396 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12397 +
12398 +#ifdef CONFIG_PAX_REFCOUNT
12399 + "jno 0f\n"
12400 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12401 + "int $4\n0:\n"
12402 + _ASM_EXTABLE(0b, 0b)
12403 +#endif
12404 +
12405 :"+m" (rw->lock) : : "memory");
12406 }
12407
12408 static inline void arch_write_unlock(arch_rwlock_t *rw)
12409 {
12410 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12411 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12412 +
12413 +#ifdef CONFIG_PAX_REFCOUNT
12414 + "jno 0f\n"
12415 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12416 + "int $4\n0:\n"
12417 + _ASM_EXTABLE(0b, 0b)
12418 +#endif
12419 +
12420 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12421 }
12422
12423 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12424 index 6a99859..03cb807 100644
12425 --- a/arch/x86/include/asm/stackprotector.h
12426 +++ b/arch/x86/include/asm/stackprotector.h
12427 @@ -47,7 +47,7 @@
12428 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12429 */
12430 #define GDT_STACK_CANARY_INIT \
12431 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12432 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12433
12434 /*
12435 * Initialize the stackprotector canary value.
12436 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12437
12438 static inline void load_stack_canary_segment(void)
12439 {
12440 -#ifdef CONFIG_X86_32
12441 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12442 asm volatile ("mov %0, %%gs" : : "r" (0));
12443 #endif
12444 }
12445 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12446 index 70bbe39..4ae2bd4 100644
12447 --- a/arch/x86/include/asm/stacktrace.h
12448 +++ b/arch/x86/include/asm/stacktrace.h
12449 @@ -11,28 +11,20 @@
12450
12451 extern int kstack_depth_to_print;
12452
12453 -struct thread_info;
12454 +struct task_struct;
12455 struct stacktrace_ops;
12456
12457 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12458 - unsigned long *stack,
12459 - unsigned long bp,
12460 - const struct stacktrace_ops *ops,
12461 - void *data,
12462 - unsigned long *end,
12463 - int *graph);
12464 +typedef unsigned long walk_stack_t(struct task_struct *task,
12465 + void *stack_start,
12466 + unsigned long *stack,
12467 + unsigned long bp,
12468 + const struct stacktrace_ops *ops,
12469 + void *data,
12470 + unsigned long *end,
12471 + int *graph);
12472
12473 -extern unsigned long
12474 -print_context_stack(struct thread_info *tinfo,
12475 - unsigned long *stack, unsigned long bp,
12476 - const struct stacktrace_ops *ops, void *data,
12477 - unsigned long *end, int *graph);
12478 -
12479 -extern unsigned long
12480 -print_context_stack_bp(struct thread_info *tinfo,
12481 - unsigned long *stack, unsigned long bp,
12482 - const struct stacktrace_ops *ops, void *data,
12483 - unsigned long *end, int *graph);
12484 +extern walk_stack_t print_context_stack;
12485 +extern walk_stack_t print_context_stack_bp;
12486
12487 /* Generic stack tracer with callbacks */
12488
12489 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12490 void (*address)(void *data, unsigned long address, int reliable);
12491 /* On negative return stop dumping */
12492 int (*stack)(void *data, char *name);
12493 - walk_stack_t walk_stack;
12494 + walk_stack_t *walk_stack;
12495 };
12496
12497 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12498 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12499 index 4ec45b3..a4f0a8a 100644
12500 --- a/arch/x86/include/asm/switch_to.h
12501 +++ b/arch/x86/include/asm/switch_to.h
12502 @@ -108,7 +108,7 @@ do { \
12503 "call __switch_to\n\t" \
12504 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12505 __switch_canary \
12506 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12507 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12508 "movq %%rax,%%rdi\n\t" \
12509 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12510 "jnz ret_from_fork\n\t" \
12511 @@ -119,7 +119,7 @@ do { \
12512 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12513 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12514 [_tif_fork] "i" (_TIF_FORK), \
12515 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12516 + [thread_info] "m" (current_tinfo), \
12517 [current_task] "m" (current_task) \
12518 __switch_canary_iparam \
12519 : "memory", "cc" __EXTRA_CLOBBER)
12520 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12521 index 3fda9db4..4ca1c61 100644
12522 --- a/arch/x86/include/asm/sys_ia32.h
12523 +++ b/arch/x86/include/asm/sys_ia32.h
12524 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12525 struct old_sigaction32 __user *);
12526 asmlinkage long sys32_alarm(unsigned int);
12527
12528 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12529 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12530 asmlinkage long sys32_sysfs(int, u32, u32);
12531
12532 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12533 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12534 index 89f794f..1422765 100644
12535 --- a/arch/x86/include/asm/thread_info.h
12536 +++ b/arch/x86/include/asm/thread_info.h
12537 @@ -10,6 +10,7 @@
12538 #include <linux/compiler.h>
12539 #include <asm/page.h>
12540 #include <asm/types.h>
12541 +#include <asm/percpu.h>
12542
12543 /*
12544 * low level task data that entry.S needs immediate access to
12545 @@ -24,7 +25,6 @@ struct exec_domain;
12546 #include <linux/atomic.h>
12547
12548 struct thread_info {
12549 - struct task_struct *task; /* main task structure */
12550 struct exec_domain *exec_domain; /* execution domain */
12551 __u32 flags; /* low level flags */
12552 __u32 status; /* thread synchronous flags */
12553 @@ -34,19 +34,13 @@ struct thread_info {
12554 mm_segment_t addr_limit;
12555 struct restart_block restart_block;
12556 void __user *sysenter_return;
12557 -#ifdef CONFIG_X86_32
12558 - unsigned long previous_esp; /* ESP of the previous stack in
12559 - case of nested (IRQ) stacks
12560 - */
12561 - __u8 supervisor_stack[0];
12562 -#endif
12563 + unsigned long lowest_stack;
12564 unsigned int sig_on_uaccess_error:1;
12565 unsigned int uaccess_err:1; /* uaccess failed */
12566 };
12567
12568 -#define INIT_THREAD_INFO(tsk) \
12569 +#define INIT_THREAD_INFO \
12570 { \
12571 - .task = &tsk, \
12572 .exec_domain = &default_exec_domain, \
12573 .flags = 0, \
12574 .cpu = 0, \
12575 @@ -57,7 +51,7 @@ struct thread_info {
12576 }, \
12577 }
12578
12579 -#define init_thread_info (init_thread_union.thread_info)
12580 +#define init_thread_info (init_thread_union.stack)
12581 #define init_stack (init_thread_union.stack)
12582
12583 #else /* !__ASSEMBLY__ */
12584 @@ -98,6 +92,7 @@ struct thread_info {
12585 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12586 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12587 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12588 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12589
12590 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12591 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12592 @@ -122,16 +117,18 @@ struct thread_info {
12593 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12594 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12595 #define _TIF_X32 (1 << TIF_X32)
12596 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12597
12598 /* work to do in syscall_trace_enter() */
12599 #define _TIF_WORK_SYSCALL_ENTRY \
12600 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12601 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12602 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12603 + _TIF_GRSEC_SETXID)
12604
12605 /* work to do in syscall_trace_leave() */
12606 #define _TIF_WORK_SYSCALL_EXIT \
12607 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12608 - _TIF_SYSCALL_TRACEPOINT)
12609 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12610
12611 /* work to do on interrupt/exception return */
12612 #define _TIF_WORK_MASK \
12613 @@ -141,7 +138,8 @@ struct thread_info {
12614
12615 /* work to do on any return to user space */
12616 #define _TIF_ALLWORK_MASK \
12617 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12618 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12619 + _TIF_GRSEC_SETXID)
12620
12621 /* Only used for 64 bit */
12622 #define _TIF_DO_NOTIFY_MASK \
12623 @@ -157,45 +155,40 @@ struct thread_info {
12624
12625 #define PREEMPT_ACTIVE 0x10000000
12626
12627 -#ifdef CONFIG_X86_32
12628 -
12629 -#define STACK_WARN (THREAD_SIZE/8)
12630 -/*
12631 - * macros/functions for gaining access to the thread information structure
12632 - *
12633 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12634 - */
12635 -#ifndef __ASSEMBLY__
12636 -
12637 -
12638 -/* how to get the current stack pointer from C */
12639 -register unsigned long current_stack_pointer asm("esp") __used;
12640 -
12641 -/* how to get the thread information struct from C */
12642 -static inline struct thread_info *current_thread_info(void)
12643 -{
12644 - return (struct thread_info *)
12645 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12646 -}
12647 -
12648 -#else /* !__ASSEMBLY__ */
12649 -
12650 +#ifdef __ASSEMBLY__
12651 /* how to get the thread information struct from ASM */
12652 #define GET_THREAD_INFO(reg) \
12653 - movl $-THREAD_SIZE, reg; \
12654 - andl %esp, reg
12655 + mov PER_CPU_VAR(current_tinfo), reg
12656
12657 /* use this one if reg already contains %esp */
12658 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12659 - andl $-THREAD_SIZE, reg
12660 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12661 +#else
12662 +/* how to get the thread information struct from C */
12663 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12664 +
12665 +static __always_inline struct thread_info *current_thread_info(void)
12666 +{
12667 + return this_cpu_read_stable(current_tinfo);
12668 +}
12669 +#endif
12670 +
12671 +#ifdef CONFIG_X86_32
12672 +
12673 +#define STACK_WARN (THREAD_SIZE/8)
12674 +/*
12675 + * macros/functions for gaining access to the thread information structure
12676 + *
12677 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12678 + */
12679 +#ifndef __ASSEMBLY__
12680 +
12681 +/* how to get the current stack pointer from C */
12682 +register unsigned long current_stack_pointer asm("esp") __used;
12683
12684 #endif
12685
12686 #else /* X86_32 */
12687
12688 -#include <asm/percpu.h>
12689 -#define KERNEL_STACK_OFFSET (5*8)
12690 -
12691 /*
12692 * macros/functions for gaining access to the thread information structure
12693 * preempt_count needs to be 1 initially, until the scheduler is functional.
12694 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12695 #ifndef __ASSEMBLY__
12696 DECLARE_PER_CPU(unsigned long, kernel_stack);
12697
12698 -static inline struct thread_info *current_thread_info(void)
12699 -{
12700 - struct thread_info *ti;
12701 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12702 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12703 - return ti;
12704 -}
12705 -
12706 -#else /* !__ASSEMBLY__ */
12707 -
12708 -/* how to get the thread information struct from ASM */
12709 -#define GET_THREAD_INFO(reg) \
12710 - movq PER_CPU_VAR(kernel_stack),reg ; \
12711 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12712 -
12713 -/*
12714 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12715 - * a certain register (to be used in assembler memory operands).
12716 - */
12717 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12718 -
12719 +/* how to get the current stack pointer from C */
12720 +register unsigned long current_stack_pointer asm("rsp") __used;
12721 #endif
12722
12723 #endif /* !X86_32 */
12724 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12725 extern void arch_task_cache_init(void);
12726 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12727 extern void arch_release_task_struct(struct task_struct *tsk);
12728 +
12729 +#define __HAVE_THREAD_FUNCTIONS
12730 +#define task_thread_info(task) (&(task)->tinfo)
12731 +#define task_stack_page(task) ((task)->stack)
12732 +#define setup_thread_stack(p, org) do {} while (0)
12733 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12734 +
12735 #endif
12736 #endif /* _ASM_X86_THREAD_INFO_H */
12737 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12738 index e1f3a17..1ab364d 100644
12739 --- a/arch/x86/include/asm/uaccess.h
12740 +++ b/arch/x86/include/asm/uaccess.h
12741 @@ -7,12 +7,15 @@
12742 #include <linux/compiler.h>
12743 #include <linux/thread_info.h>
12744 #include <linux/string.h>
12745 +#include <linux/sched.h>
12746 #include <asm/asm.h>
12747 #include <asm/page.h>
12748
12749 #define VERIFY_READ 0
12750 #define VERIFY_WRITE 1
12751
12752 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12753 +
12754 /*
12755 * The fs value determines whether argument validity checking should be
12756 * performed or not. If get_fs() == USER_DS, checking is performed, with
12757 @@ -28,7 +31,12 @@
12758
12759 #define get_ds() (KERNEL_DS)
12760 #define get_fs() (current_thread_info()->addr_limit)
12761 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12762 +void __set_fs(mm_segment_t x);
12763 +void set_fs(mm_segment_t x);
12764 +#else
12765 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12766 +#endif
12767
12768 #define segment_eq(a, b) ((a).seg == (b).seg)
12769
12770 @@ -76,8 +84,33 @@
12771 * checks that the pointer is in the user space range - after calling
12772 * this function, memory access functions may still return -EFAULT.
12773 */
12774 -#define access_ok(type, addr, size) \
12775 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12776 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12777 +#define access_ok(type, addr, size) \
12778 +({ \
12779 + long __size = size; \
12780 + unsigned long __addr = (unsigned long)addr; \
12781 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12782 + unsigned long __end_ao = __addr + __size - 1; \
12783 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12784 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12785 + while(__addr_ao <= __end_ao) { \
12786 + char __c_ao; \
12787 + __addr_ao += PAGE_SIZE; \
12788 + if (__size > PAGE_SIZE) \
12789 + cond_resched(); \
12790 + if (__get_user(__c_ao, (char __user *)__addr)) \
12791 + break; \
12792 + if (type != VERIFY_WRITE) { \
12793 + __addr = __addr_ao; \
12794 + continue; \
12795 + } \
12796 + if (__put_user(__c_ao, (char __user *)__addr)) \
12797 + break; \
12798 + __addr = __addr_ao; \
12799 + } \
12800 + } \
12801 + __ret_ao; \
12802 +})
12803
12804 /*
12805 * The exception table consists of pairs of addresses relative to the
12806 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12807 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12808 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12809
12810 -
12811 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12812 +#define __copyuser_seg "gs;"
12813 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12814 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12815 +#else
12816 +#define __copyuser_seg
12817 +#define __COPYUSER_SET_ES
12818 +#define __COPYUSER_RESTORE_ES
12819 +#endif
12820
12821 #ifdef CONFIG_X86_32
12822 #define __put_user_asm_u64(x, addr, err, errret) \
12823 - asm volatile("1: movl %%eax,0(%2)\n" \
12824 - "2: movl %%edx,4(%2)\n" \
12825 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12826 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12827 "3:\n" \
12828 ".section .fixup,\"ax\"\n" \
12829 "4: movl %3,%0\n" \
12830 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12831 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12832
12833 #define __put_user_asm_ex_u64(x, addr) \
12834 - asm volatile("1: movl %%eax,0(%1)\n" \
12835 - "2: movl %%edx,4(%1)\n" \
12836 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12837 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12838 "3:\n" \
12839 _ASM_EXTABLE_EX(1b, 2b) \
12840 _ASM_EXTABLE_EX(2b, 3b) \
12841 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12842 __typeof__(*(ptr)) __pu_val; \
12843 __chk_user_ptr(ptr); \
12844 might_fault(); \
12845 - __pu_val = x; \
12846 + __pu_val = (x); \
12847 switch (sizeof(*(ptr))) { \
12848 case 1: \
12849 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12850 @@ -379,7 +420,7 @@ do { \
12851 } while (0)
12852
12853 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12854 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12855 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12856 "2:\n" \
12857 ".section .fixup,\"ax\"\n" \
12858 "3: mov %3,%0\n" \
12859 @@ -387,7 +428,7 @@ do { \
12860 " jmp 2b\n" \
12861 ".previous\n" \
12862 _ASM_EXTABLE(1b, 3b) \
12863 - : "=r" (err), ltype(x) \
12864 + : "=r" (err), ltype (x) \
12865 : "m" (__m(addr)), "i" (errret), "0" (err))
12866
12867 #define __get_user_size_ex(x, ptr, size) \
12868 @@ -412,7 +453,7 @@ do { \
12869 } while (0)
12870
12871 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12872 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12873 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12874 "2:\n" \
12875 _ASM_EXTABLE_EX(1b, 2b) \
12876 : ltype(x) : "m" (__m(addr)))
12877 @@ -429,13 +470,24 @@ do { \
12878 int __gu_err; \
12879 unsigned long __gu_val; \
12880 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12881 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12882 + (x) = (__typeof__(*(ptr)))__gu_val; \
12883 __gu_err; \
12884 })
12885
12886 /* FIXME: this hack is definitely wrong -AK */
12887 struct __large_struct { unsigned long buf[100]; };
12888 -#define __m(x) (*(struct __large_struct __user *)(x))
12889 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12890 +#define ____m(x) \
12891 +({ \
12892 + unsigned long ____x = (unsigned long)(x); \
12893 + if (____x < PAX_USER_SHADOW_BASE) \
12894 + ____x += PAX_USER_SHADOW_BASE; \
12895 + (void __user *)____x; \
12896 +})
12897 +#else
12898 +#define ____m(x) (x)
12899 +#endif
12900 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12901
12902 /*
12903 * Tell gcc we read from memory instead of writing: this is because
12904 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12905 * aliasing issues.
12906 */
12907 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12908 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12909 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12910 "2:\n" \
12911 ".section .fixup,\"ax\"\n" \
12912 "3: mov %3,%0\n" \
12913 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12914 ".previous\n" \
12915 _ASM_EXTABLE(1b, 3b) \
12916 : "=r"(err) \
12917 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12918 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12919
12920 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12921 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12922 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12923 "2:\n" \
12924 _ASM_EXTABLE_EX(1b, 2b) \
12925 : : ltype(x), "m" (__m(addr)))
12926 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12927 * On error, the variable @x is set to zero.
12928 */
12929
12930 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12931 +#define __get_user(x, ptr) get_user((x), (ptr))
12932 +#else
12933 #define __get_user(x, ptr) \
12934 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12935 +#endif
12936
12937 /**
12938 * __put_user: - Write a simple value into user space, with less checking.
12939 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12940 * Returns zero on success, or -EFAULT on error.
12941 */
12942
12943 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12944 +#define __put_user(x, ptr) put_user((x), (ptr))
12945 +#else
12946 #define __put_user(x, ptr) \
12947 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12948 +#endif
12949
12950 #define __get_user_unaligned __get_user
12951 #define __put_user_unaligned __put_user
12952 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12953 #define get_user_ex(x, ptr) do { \
12954 unsigned long __gue_val; \
12955 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12956 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12957 + (x) = (__typeof__(*(ptr)))__gue_val; \
12958 } while (0)
12959
12960 #ifdef CONFIG_X86_WP_WORKS_OK
12961 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12962 index 576e39b..ccd0a39 100644
12963 --- a/arch/x86/include/asm/uaccess_32.h
12964 +++ b/arch/x86/include/asm/uaccess_32.h
12965 @@ -11,15 +11,15 @@
12966 #include <asm/page.h>
12967
12968 unsigned long __must_check __copy_to_user_ll
12969 - (void __user *to, const void *from, unsigned long n);
12970 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12971 unsigned long __must_check __copy_from_user_ll
12972 - (void *to, const void __user *from, unsigned long n);
12973 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12974 unsigned long __must_check __copy_from_user_ll_nozero
12975 - (void *to, const void __user *from, unsigned long n);
12976 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12977 unsigned long __must_check __copy_from_user_ll_nocache
12978 - (void *to, const void __user *from, unsigned long n);
12979 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12980 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12981 - (void *to, const void __user *from, unsigned long n);
12982 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12983
12984 /**
12985 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12986 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12987 static __always_inline unsigned long __must_check
12988 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12989 {
12990 + if ((long)n < 0)
12991 + return n;
12992 +
12993 if (__builtin_constant_p(n)) {
12994 unsigned long ret;
12995
12996 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12997 return ret;
12998 }
12999 }
13000 + if (!__builtin_constant_p(n))
13001 + check_object_size(from, n, true);
13002 return __copy_to_user_ll(to, from, n);
13003 }
13004
13005 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
13006 __copy_to_user(void __user *to, const void *from, unsigned long n)
13007 {
13008 might_fault();
13009 +
13010 return __copy_to_user_inatomic(to, from, n);
13011 }
13012
13013 static __always_inline unsigned long
13014 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
13015 {
13016 + if ((long)n < 0)
13017 + return n;
13018 +
13019 /* Avoid zeroing the tail if the copy fails..
13020 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
13021 * but as the zeroing behaviour is only significant when n is not
13022 @@ -137,6 +146,10 @@ static __always_inline unsigned long
13023 __copy_from_user(void *to, const void __user *from, unsigned long n)
13024 {
13025 might_fault();
13026 +
13027 + if ((long)n < 0)
13028 + return n;
13029 +
13030 if (__builtin_constant_p(n)) {
13031 unsigned long ret;
13032
13033 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13034 return ret;
13035 }
13036 }
13037 + if (!__builtin_constant_p(n))
13038 + check_object_size(to, n, false);
13039 return __copy_from_user_ll(to, from, n);
13040 }
13041
13042 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13043 const void __user *from, unsigned long n)
13044 {
13045 might_fault();
13046 +
13047 + if ((long)n < 0)
13048 + return n;
13049 +
13050 if (__builtin_constant_p(n)) {
13051 unsigned long ret;
13052
13053 @@ -181,15 +200,19 @@ static __always_inline unsigned long
13054 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13055 unsigned long n)
13056 {
13057 - return __copy_from_user_ll_nocache_nozero(to, from, n);
13058 + if ((long)n < 0)
13059 + return n;
13060 +
13061 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13062 }
13063
13064 -unsigned long __must_check copy_to_user(void __user *to,
13065 - const void *from, unsigned long n);
13066 -unsigned long __must_check _copy_from_user(void *to,
13067 - const void __user *from,
13068 - unsigned long n);
13069 -
13070 +extern void copy_to_user_overflow(void)
13071 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13072 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13073 +#else
13074 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13075 +#endif
13076 +;
13077
13078 extern void copy_from_user_overflow(void)
13079 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13080 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13081 #endif
13082 ;
13083
13084 -static inline unsigned long __must_check copy_from_user(void *to,
13085 - const void __user *from,
13086 - unsigned long n)
13087 +/**
13088 + * copy_to_user: - Copy a block of data into user space.
13089 + * @to: Destination address, in user space.
13090 + * @from: Source address, in kernel space.
13091 + * @n: Number of bytes to copy.
13092 + *
13093 + * Context: User context only. This function may sleep.
13094 + *
13095 + * Copy data from kernel space to user space.
13096 + *
13097 + * Returns number of bytes that could not be copied.
13098 + * On success, this will be zero.
13099 + */
13100 +static inline unsigned long __must_check
13101 +copy_to_user(void __user *to, const void *from, unsigned long n)
13102 {
13103 - int sz = __compiletime_object_size(to);
13104 + size_t sz = __compiletime_object_size(from);
13105
13106 - if (likely(sz == -1 || sz >= n))
13107 - n = _copy_from_user(to, from, n);
13108 - else
13109 + if (unlikely(sz != (size_t)-1 && sz < n))
13110 + copy_to_user_overflow();
13111 + else if (access_ok(VERIFY_WRITE, to, n))
13112 + n = __copy_to_user(to, from, n);
13113 + return n;
13114 +}
13115 +
13116 +/**
13117 + * copy_from_user: - Copy a block of data from user space.
13118 + * @to: Destination address, in kernel space.
13119 + * @from: Source address, in user space.
13120 + * @n: Number of bytes to copy.
13121 + *
13122 + * Context: User context only. This function may sleep.
13123 + *
13124 + * Copy data from user space to kernel space.
13125 + *
13126 + * Returns number of bytes that could not be copied.
13127 + * On success, this will be zero.
13128 + *
13129 + * If some data could not be copied, this function will pad the copied
13130 + * data to the requested size using zero bytes.
13131 + */
13132 +static inline unsigned long __must_check
13133 +copy_from_user(void *to, const void __user *from, unsigned long n)
13134 +{
13135 + size_t sz = __compiletime_object_size(to);
13136 +
13137 + if (unlikely(sz != (size_t)-1 && sz < n))
13138 copy_from_user_overflow();
13139 -
13140 + else if (access_ok(VERIFY_READ, from, n))
13141 + n = __copy_from_user(to, from, n);
13142 + else if ((long)n > 0) {
13143 + if (!__builtin_constant_p(n))
13144 + check_object_size(to, n, false);
13145 + memset(to, 0, n);
13146 + }
13147 return n;
13148 }
13149
13150 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13151 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13152 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13153 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13154
13155 #endif /* _ASM_X86_UACCESS_32_H */
13156 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13157 index d8def8b..ac7fc15 100644
13158 --- a/arch/x86/include/asm/uaccess_64.h
13159 +++ b/arch/x86/include/asm/uaccess_64.h
13160 @@ -10,6 +10,9 @@
13161 #include <asm/alternative.h>
13162 #include <asm/cpufeature.h>
13163 #include <asm/page.h>
13164 +#include <asm/pgtable.h>
13165 +
13166 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13167
13168 /*
13169 * Copy To/From Userspace
13170 @@ -17,13 +20,13 @@
13171
13172 /* Handles exceptions in both to and from, but doesn't do access_ok */
13173 __must_check unsigned long
13174 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13175 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13176 __must_check unsigned long
13177 -copy_user_generic_string(void *to, const void *from, unsigned len);
13178 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13179 __must_check unsigned long
13180 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13181 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13182
13183 -static __always_inline __must_check unsigned long
13184 +static __always_inline __must_check __size_overflow(3) unsigned long
13185 copy_user_generic(void *to, const void *from, unsigned len)
13186 {
13187 unsigned ret;
13188 @@ -41,142 +44,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13189 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13190 "=d" (len)),
13191 "1" (to), "2" (from), "3" (len)
13192 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13193 + : "memory", "rcx", "r8", "r9", "r11");
13194 return ret;
13195 }
13196
13197 +static __always_inline __must_check unsigned long
13198 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13199 +static __always_inline __must_check unsigned long
13200 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13201 __must_check unsigned long
13202 -_copy_to_user(void __user *to, const void *from, unsigned len);
13203 -__must_check unsigned long
13204 -_copy_from_user(void *to, const void __user *from, unsigned len);
13205 -__must_check unsigned long
13206 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13207 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13208 +
13209 +extern void copy_to_user_overflow(void)
13210 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13211 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13212 +#else
13213 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13214 +#endif
13215 +;
13216 +
13217 +extern void copy_from_user_overflow(void)
13218 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13219 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13220 +#else
13221 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13222 +#endif
13223 +;
13224
13225 static inline unsigned long __must_check copy_from_user(void *to,
13226 const void __user *from,
13227 unsigned long n)
13228 {
13229 - int sz = __compiletime_object_size(to);
13230 -
13231 might_fault();
13232 - if (likely(sz == -1 || sz >= n))
13233 - n = _copy_from_user(to, from, n);
13234 -#ifdef CONFIG_DEBUG_VM
13235 - else
13236 - WARN(1, "Buffer overflow detected!\n");
13237 -#endif
13238 +
13239 + if (access_ok(VERIFY_READ, from, n))
13240 + n = __copy_from_user(to, from, n);
13241 + else if (n < INT_MAX) {
13242 + if (!__builtin_constant_p(n))
13243 + check_object_size(to, n, false);
13244 + memset(to, 0, n);
13245 + }
13246 return n;
13247 }
13248
13249 static __always_inline __must_check
13250 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13251 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13252 {
13253 might_fault();
13254
13255 - return _copy_to_user(dst, src, size);
13256 + if (access_ok(VERIFY_WRITE, dst, size))
13257 + size = __copy_to_user(dst, src, size);
13258 + return size;
13259 }
13260
13261 static __always_inline __must_check
13262 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13263 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13264 {
13265 - int ret = 0;
13266 + size_t sz = __compiletime_object_size(dst);
13267 + unsigned ret = 0;
13268
13269 might_fault();
13270 - if (!__builtin_constant_p(size))
13271 - return copy_user_generic(dst, (__force void *)src, size);
13272 +
13273 + if (size > INT_MAX)
13274 + return size;
13275 +
13276 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13277 + if (!__access_ok(VERIFY_READ, src, size))
13278 + return size;
13279 +#endif
13280 +
13281 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13282 + copy_from_user_overflow();
13283 + return size;
13284 + }
13285 +
13286 + if (!__builtin_constant_p(size)) {
13287 + check_object_size(dst, size, false);
13288 +
13289 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13290 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13291 + src += PAX_USER_SHADOW_BASE;
13292 +#endif
13293 +
13294 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13295 + }
13296 switch (size) {
13297 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13298 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13299 ret, "b", "b", "=q", 1);
13300 return ret;
13301 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13302 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13303 ret, "w", "w", "=r", 2);
13304 return ret;
13305 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13306 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13307 ret, "l", "k", "=r", 4);
13308 return ret;
13309 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13310 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13311 ret, "q", "", "=r", 8);
13312 return ret;
13313 case 10:
13314 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13315 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13316 ret, "q", "", "=r", 10);
13317 if (unlikely(ret))
13318 return ret;
13319 __get_user_asm(*(u16 *)(8 + (char *)dst),
13320 - (u16 __user *)(8 + (char __user *)src),
13321 + (const u16 __user *)(8 + (const char __user *)src),
13322 ret, "w", "w", "=r", 2);
13323 return ret;
13324 case 16:
13325 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13326 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13327 ret, "q", "", "=r", 16);
13328 if (unlikely(ret))
13329 return ret;
13330 __get_user_asm(*(u64 *)(8 + (char *)dst),
13331 - (u64 __user *)(8 + (char __user *)src),
13332 + (const u64 __user *)(8 + (const char __user *)src),
13333 ret, "q", "", "=r", 8);
13334 return ret;
13335 default:
13336 - return copy_user_generic(dst, (__force void *)src, size);
13337 +
13338 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13339 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13340 + src += PAX_USER_SHADOW_BASE;
13341 +#endif
13342 +
13343 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13344 }
13345 }
13346
13347 static __always_inline __must_check
13348 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13349 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13350 {
13351 - int ret = 0;
13352 + size_t sz = __compiletime_object_size(src);
13353 + unsigned ret = 0;
13354
13355 might_fault();
13356 - if (!__builtin_constant_p(size))
13357 - return copy_user_generic((__force void *)dst, src, size);
13358 +
13359 + if (size > INT_MAX)
13360 + return size;
13361 +
13362 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13363 + if (!__access_ok(VERIFY_WRITE, dst, size))
13364 + return size;
13365 +#endif
13366 +
13367 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13368 + copy_to_user_overflow();
13369 + return size;
13370 + }
13371 +
13372 + if (!__builtin_constant_p(size)) {
13373 + check_object_size(src, size, true);
13374 +
13375 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13376 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13377 + dst += PAX_USER_SHADOW_BASE;
13378 +#endif
13379 +
13380 + return copy_user_generic((__force_kernel void *)dst, src, size);
13381 + }
13382 switch (size) {
13383 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13384 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13385 ret, "b", "b", "iq", 1);
13386 return ret;
13387 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13388 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13389 ret, "w", "w", "ir", 2);
13390 return ret;
13391 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13392 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13393 ret, "l", "k", "ir", 4);
13394 return ret;
13395 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13396 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13397 ret, "q", "", "er", 8);
13398 return ret;
13399 case 10:
13400 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13401 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13402 ret, "q", "", "er", 10);
13403 if (unlikely(ret))
13404 return ret;
13405 asm("":::"memory");
13406 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13407 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13408 ret, "w", "w", "ir", 2);
13409 return ret;
13410 case 16:
13411 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13412 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13413 ret, "q", "", "er", 16);
13414 if (unlikely(ret))
13415 return ret;
13416 asm("":::"memory");
13417 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13418 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13419 ret, "q", "", "er", 8);
13420 return ret;
13421 default:
13422 - return copy_user_generic((__force void *)dst, src, size);
13423 +
13424 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13425 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13426 + dst += PAX_USER_SHADOW_BASE;
13427 +#endif
13428 +
13429 + return copy_user_generic((__force_kernel void *)dst, src, size);
13430 }
13431 }
13432
13433 static __always_inline __must_check
13434 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13435 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13436 {
13437 - int ret = 0;
13438 + unsigned ret = 0;
13439
13440 might_fault();
13441 - if (!__builtin_constant_p(size))
13442 - return copy_user_generic((__force void *)dst,
13443 - (__force void *)src, size);
13444 +
13445 + if (size > INT_MAX)
13446 + return size;
13447 +
13448 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13449 + if (!__access_ok(VERIFY_READ, src, size))
13450 + return size;
13451 + if (!__access_ok(VERIFY_WRITE, dst, size))
13452 + return size;
13453 +#endif
13454 +
13455 + if (!__builtin_constant_p(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 switch (size) {
13468 case 1: {
13469 u8 tmp;
13470 - __get_user_asm(tmp, (u8 __user *)src,
13471 + __get_user_asm(tmp, (const u8 __user *)src,
13472 ret, "b", "b", "=q", 1);
13473 if (likely(!ret))
13474 __put_user_asm(tmp, (u8 __user *)dst,
13475 @@ -185,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13476 }
13477 case 2: {
13478 u16 tmp;
13479 - __get_user_asm(tmp, (u16 __user *)src,
13480 + __get_user_asm(tmp, (const u16 __user *)src,
13481 ret, "w", "w", "=r", 2);
13482 if (likely(!ret))
13483 __put_user_asm(tmp, (u16 __user *)dst,
13484 @@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13485
13486 case 4: {
13487 u32 tmp;
13488 - __get_user_asm(tmp, (u32 __user *)src,
13489 + __get_user_asm(tmp, (const u32 __user *)src,
13490 ret, "l", "k", "=r", 4);
13491 if (likely(!ret))
13492 __put_user_asm(tmp, (u32 __user *)dst,
13493 @@ -204,7 +303,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13494 }
13495 case 8: {
13496 u64 tmp;
13497 - __get_user_asm(tmp, (u64 __user *)src,
13498 + __get_user_asm(tmp, (const u64 __user *)src,
13499 ret, "q", "", "=r", 8);
13500 if (likely(!ret))
13501 __put_user_asm(tmp, (u64 __user *)dst,
13502 @@ -212,44 +311,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13503 return ret;
13504 }
13505 default:
13506 - return copy_user_generic((__force void *)dst,
13507 - (__force void *)src, size);
13508 +
13509 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13510 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13511 + src += PAX_USER_SHADOW_BASE;
13512 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13513 + dst += PAX_USER_SHADOW_BASE;
13514 +#endif
13515 +
13516 + return copy_user_generic((__force_kernel void *)dst,
13517 + (__force_kernel const void *)src, size);
13518 }
13519 }
13520
13521 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13522 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13523 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13524 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13525
13526 static __must_check __always_inline int
13527 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13528 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13529 {
13530 - return copy_user_generic(dst, (__force const void *)src, size);
13531 + if (size > INT_MAX)
13532 + return size;
13533 +
13534 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13535 + if (!__access_ok(VERIFY_READ, src, size))
13536 + return size;
13537 +
13538 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13539 + src += PAX_USER_SHADOW_BASE;
13540 +#endif
13541 +
13542 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13543 }
13544
13545 -static __must_check __always_inline int
13546 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13547 +static __must_check __always_inline unsigned long
13548 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13549 {
13550 - return copy_user_generic((__force void *)dst, src, size);
13551 + if (size > INT_MAX)
13552 + return size;
13553 +
13554 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13555 + if (!__access_ok(VERIFY_WRITE, dst, size))
13556 + return size;
13557 +
13558 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13559 + dst += PAX_USER_SHADOW_BASE;
13560 +#endif
13561 +
13562 + return copy_user_generic((__force_kernel void *)dst, src, size);
13563 }
13564
13565 -extern long __copy_user_nocache(void *dst, const void __user *src,
13566 - unsigned size, int zerorest);
13567 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13568 + unsigned long size, int zerorest) __size_overflow(3);
13569
13570 -static inline int
13571 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13572 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13573 {
13574 might_sleep();
13575 +
13576 + if (size > INT_MAX)
13577 + return size;
13578 +
13579 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13580 + if (!__access_ok(VERIFY_READ, src, size))
13581 + return size;
13582 +#endif
13583 +
13584 return __copy_user_nocache(dst, src, size, 1);
13585 }
13586
13587 -static inline int
13588 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13589 - unsigned size)
13590 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13591 + unsigned long size)
13592 {
13593 + if (size > INT_MAX)
13594 + return size;
13595 +
13596 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13597 + if (!__access_ok(VERIFY_READ, src, size))
13598 + return size;
13599 +#endif
13600 +
13601 return __copy_user_nocache(dst, src, size, 0);
13602 }
13603
13604 -unsigned long
13605 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13606 +extern unsigned long
13607 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13608
13609 #endif /* _ASM_X86_UACCESS_64_H */
13610 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13611 index bb05228..d763d5b 100644
13612 --- a/arch/x86/include/asm/vdso.h
13613 +++ b/arch/x86/include/asm/vdso.h
13614 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13615 #define VDSO32_SYMBOL(base, name) \
13616 ({ \
13617 extern const char VDSO32_##name[]; \
13618 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13619 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13620 })
13621 #endif
13622
13623 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13624 index 5b238981..77fdd78 100644
13625 --- a/arch/x86/include/asm/word-at-a-time.h
13626 +++ b/arch/x86/include/asm/word-at-a-time.h
13627 @@ -11,7 +11,7 @@
13628 * and shift, for example.
13629 */
13630 struct word_at_a_time {
13631 - const unsigned long one_bits, high_bits;
13632 + unsigned long one_bits, high_bits;
13633 };
13634
13635 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13636 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13637 index 38155f6..e4184ba 100644
13638 --- a/arch/x86/include/asm/x86_init.h
13639 +++ b/arch/x86/include/asm/x86_init.h
13640 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13641 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13642 void (*find_smp_config)(void);
13643 void (*get_smp_config)(unsigned int early);
13644 -};
13645 +} __no_const;
13646
13647 /**
13648 * struct x86_init_resources - platform specific resource related ops
13649 @@ -43,7 +43,7 @@ struct x86_init_resources {
13650 void (*probe_roms)(void);
13651 void (*reserve_resources)(void);
13652 char *(*memory_setup)(void);
13653 -};
13654 +} __no_const;
13655
13656 /**
13657 * struct x86_init_irqs - platform specific interrupt setup
13658 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13659 void (*pre_vector_init)(void);
13660 void (*intr_init)(void);
13661 void (*trap_init)(void);
13662 -};
13663 +} __no_const;
13664
13665 /**
13666 * struct x86_init_oem - oem platform specific customizing functions
13667 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13668 struct x86_init_oem {
13669 void (*arch_setup)(void);
13670 void (*banner)(void);
13671 -};
13672 +} __no_const;
13673
13674 /**
13675 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13676 @@ -77,7 +77,7 @@ struct x86_init_oem {
13677 */
13678 struct x86_init_mapping {
13679 void (*pagetable_reserve)(u64 start, u64 end);
13680 -};
13681 +} __no_const;
13682
13683 /**
13684 * struct x86_init_paging - platform specific paging functions
13685 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13686 struct x86_init_paging {
13687 void (*pagetable_setup_start)(pgd_t *base);
13688 void (*pagetable_setup_done)(pgd_t *base);
13689 -};
13690 +} __no_const;
13691
13692 /**
13693 * struct x86_init_timers - platform specific timer setup
13694 @@ -102,7 +102,7 @@ struct x86_init_timers {
13695 void (*tsc_pre_init)(void);
13696 void (*timer_init)(void);
13697 void (*wallclock_init)(void);
13698 -};
13699 +} __no_const;
13700
13701 /**
13702 * struct x86_init_iommu - platform specific iommu setup
13703 @@ -110,7 +110,7 @@ struct x86_init_timers {
13704 */
13705 struct x86_init_iommu {
13706 int (*iommu_init)(void);
13707 -};
13708 +} __no_const;
13709
13710 /**
13711 * struct x86_init_pci - platform specific pci init functions
13712 @@ -124,7 +124,7 @@ struct x86_init_pci {
13713 int (*init)(void);
13714 void (*init_irq)(void);
13715 void (*fixup_irqs)(void);
13716 -};
13717 +} __no_const;
13718
13719 /**
13720 * struct x86_init_ops - functions for platform specific setup
13721 @@ -140,7 +140,7 @@ struct x86_init_ops {
13722 struct x86_init_timers timers;
13723 struct x86_init_iommu iommu;
13724 struct x86_init_pci pci;
13725 -};
13726 +} __no_const;
13727
13728 /**
13729 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13730 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13731 void (*setup_percpu_clockev)(void);
13732 void (*early_percpu_clock_init)(void);
13733 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13734 -};
13735 +} __no_const;
13736
13737 /**
13738 * struct x86_platform_ops - platform specific runtime functions
13739 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13740 void (*save_sched_clock_state)(void);
13741 void (*restore_sched_clock_state)(void);
13742 void (*apic_post_init)(void);
13743 -};
13744 +} __no_const;
13745
13746 struct pci_dev;
13747
13748 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13749 void (*teardown_msi_irq)(unsigned int irq);
13750 void (*teardown_msi_irqs)(struct pci_dev *dev);
13751 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13752 -};
13753 +} __no_const;
13754
13755 struct x86_io_apic_ops {
13756 void (*init) (void);
13757 unsigned int (*read) (unsigned int apic, unsigned int reg);
13758 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13759 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13760 -};
13761 +} __no_const;
13762
13763 extern struct x86_init_ops x86_init;
13764 extern struct x86_cpuinit_ops x86_cpuinit;
13765 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13766 index 8a1b6f9..a29c4e4 100644
13767 --- a/arch/x86/include/asm/xsave.h
13768 +++ b/arch/x86/include/asm/xsave.h
13769 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13770 {
13771 int err;
13772
13773 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13774 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13775 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13776 +#endif
13777 +
13778 /*
13779 * Clear the xsave header first, so that reserved fields are
13780 * initialized to zero.
13781 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13782 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13783 {
13784 int err;
13785 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13786 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13787 u32 lmask = mask;
13788 u32 hmask = mask >> 32;
13789
13790 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13791 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13792 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13793 +#endif
13794 +
13795 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13796 "2:\n"
13797 ".section .fixup,\"ax\"\n"
13798 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13799 index 1b8e5a0..354fd59 100644
13800 --- a/arch/x86/kernel/acpi/sleep.c
13801 +++ b/arch/x86/kernel/acpi/sleep.c
13802 @@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13803 #else /* CONFIG_64BIT */
13804 #ifdef CONFIG_SMP
13805 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13806 +
13807 + pax_open_kernel();
13808 early_gdt_descr.address =
13809 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13810 + pax_close_kernel();
13811 +
13812 initial_gs = per_cpu_offset(smp_processor_id());
13813 #endif
13814 initial_code = (unsigned long)wakeup_long64;
13815 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13816 index 13ab720..95d5442 100644
13817 --- a/arch/x86/kernel/acpi/wakeup_32.S
13818 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13819 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13820 # and restore the stack ... but you need gdt for this to work
13821 movl saved_context_esp, %esp
13822
13823 - movl %cs:saved_magic, %eax
13824 - cmpl $0x12345678, %eax
13825 + cmpl $0x12345678, saved_magic
13826 jne bogus_magic
13827
13828 # jump to place where we left off
13829 - movl saved_eip, %eax
13830 - jmp *%eax
13831 + jmp *(saved_eip)
13832
13833 bogus_magic:
13834 jmp bogus_magic
13835 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13836 index ced4534..3e75d69 100644
13837 --- a/arch/x86/kernel/alternative.c
13838 +++ b/arch/x86/kernel/alternative.c
13839 @@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13840 */
13841 for (a = start; a < end; a++) {
13842 instr = (u8 *)&a->instr_offset + a->instr_offset;
13843 +
13844 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13845 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13846 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13847 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13848 +#endif
13849 +
13850 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13851 BUG_ON(a->replacementlen > a->instrlen);
13852 BUG_ON(a->instrlen > sizeof(insnbuf));
13853 @@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13854 for (poff = start; poff < end; poff++) {
13855 u8 *ptr = (u8 *)poff + *poff;
13856
13857 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13858 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13859 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13860 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13861 +#endif
13862 +
13863 if (!*poff || ptr < text || ptr >= text_end)
13864 continue;
13865 /* turn DS segment override prefix into lock prefix */
13866 - if (*ptr == 0x3e)
13867 + if (*ktla_ktva(ptr) == 0x3e)
13868 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13869 };
13870 mutex_unlock(&text_mutex);
13871 @@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13872 for (poff = start; poff < end; poff++) {
13873 u8 *ptr = (u8 *)poff + *poff;
13874
13875 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13876 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13877 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13878 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13879 +#endif
13880 +
13881 if (!*poff || ptr < text || ptr >= text_end)
13882 continue;
13883 /* turn lock prefix into DS segment override prefix */
13884 - if (*ptr == 0xf0)
13885 + if (*ktla_ktva(ptr) == 0xf0)
13886 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13887 };
13888 mutex_unlock(&text_mutex);
13889 @@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13890
13891 BUG_ON(p->len > MAX_PATCH_LEN);
13892 /* prep the buffer with the original instructions */
13893 - memcpy(insnbuf, p->instr, p->len);
13894 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13895 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13896 (unsigned long)p->instr, p->len);
13897
13898 @@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13899 if (smp_alt_once)
13900 free_init_pages("SMP alternatives",
13901 (unsigned long)__smp_locks,
13902 - (unsigned long)__smp_locks_end);
13903 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13904
13905 restart_nmi();
13906 }
13907 @@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13908 * instructions. And on the local CPU you need to be protected again NMI or MCE
13909 * handlers seeing an inconsistent instruction while you patch.
13910 */
13911 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13912 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13913 size_t len)
13914 {
13915 unsigned long flags;
13916 local_irq_save(flags);
13917 - memcpy(addr, opcode, len);
13918 +
13919 + pax_open_kernel();
13920 + memcpy(ktla_ktva(addr), opcode, len);
13921 sync_core();
13922 + pax_close_kernel();
13923 +
13924 local_irq_restore(flags);
13925 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13926 that causes hangs on some VIA CPUs. */
13927 @@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13928 */
13929 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13930 {
13931 - unsigned long flags;
13932 - char *vaddr;
13933 + unsigned char *vaddr = ktla_ktva(addr);
13934 struct page *pages[2];
13935 - int i;
13936 + size_t i;
13937
13938 if (!core_kernel_text((unsigned long)addr)) {
13939 - pages[0] = vmalloc_to_page(addr);
13940 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13941 + pages[0] = vmalloc_to_page(vaddr);
13942 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13943 } else {
13944 - pages[0] = virt_to_page(addr);
13945 + pages[0] = virt_to_page(vaddr);
13946 WARN_ON(!PageReserved(pages[0]));
13947 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13948 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13949 }
13950 BUG_ON(!pages[0]);
13951 - local_irq_save(flags);
13952 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13953 - if (pages[1])
13954 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13955 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13956 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13957 - clear_fixmap(FIX_TEXT_POKE0);
13958 - if (pages[1])
13959 - clear_fixmap(FIX_TEXT_POKE1);
13960 - local_flush_tlb();
13961 - sync_core();
13962 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13963 - that causes hangs on some VIA CPUs. */
13964 + text_poke_early(addr, opcode, len);
13965 for (i = 0; i < len; i++)
13966 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13967 - local_irq_restore(flags);
13968 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13969 return addr;
13970 }
13971
13972 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13973 index 24deb30..94a3426 100644
13974 --- a/arch/x86/kernel/apic/apic.c
13975 +++ b/arch/x86/kernel/apic/apic.c
13976 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13977 /*
13978 * Debug level, exported for io_apic.c
13979 */
13980 -unsigned int apic_verbosity;
13981 +int apic_verbosity;
13982
13983 int pic_mode;
13984
13985 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13986 apic_write(APIC_ESR, 0);
13987 v1 = apic_read(APIC_ESR);
13988 ack_APIC_irq();
13989 - atomic_inc(&irq_err_count);
13990 + atomic_inc_unchecked(&irq_err_count);
13991
13992 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13993 smp_processor_id(), v0 , v1);
13994 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13995 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13996 /* Should happen once for each apic */
13997 WARN_ON((*drv)->eoi_write == eoi_write);
13998 - (*drv)->eoi_write = eoi_write;
13999 + pax_open_kernel();
14000 + *(void **)&(*drv)->eoi_write = eoi_write;
14001 + pax_close_kernel();
14002 }
14003 }
14004
14005 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
14006 index c265593..137c4ac 100644
14007 --- a/arch/x86/kernel/apic/io_apic.c
14008 +++ b/arch/x86/kernel/apic/io_apic.c
14009 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
14010 }
14011 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
14012
14013 -void lock_vector_lock(void)
14014 +void lock_vector_lock(void) __acquires(vector_lock)
14015 {
14016 /* Used to the online set of cpus does not change
14017 * during assign_irq_vector.
14018 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
14019 raw_spin_lock(&vector_lock);
14020 }
14021
14022 -void unlock_vector_lock(void)
14023 +void unlock_vector_lock(void) __releases(vector_lock)
14024 {
14025 raw_spin_unlock(&vector_lock);
14026 }
14027 @@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
14028 ack_APIC_irq();
14029 }
14030
14031 -atomic_t irq_mis_count;
14032 +atomic_unchecked_t irq_mis_count;
14033
14034 #ifdef CONFIG_GENERIC_PENDING_IRQ
14035 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
14036 @@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
14037 * at the cpu.
14038 */
14039 if (!(v & (1 << (i & 0x1f)))) {
14040 - atomic_inc(&irq_mis_count);
14041 + atomic_inc_unchecked(&irq_mis_count);
14042
14043 eoi_ioapic_irq(irq, cfg);
14044 }
14045 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14046 index d65464e..1035d31 100644
14047 --- a/arch/x86/kernel/apm_32.c
14048 +++ b/arch/x86/kernel/apm_32.c
14049 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
14050 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14051 * even though they are called in protected mode.
14052 */
14053 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14054 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14055 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14056
14057 static const char driver_version[] = "1.16ac"; /* no spaces */
14058 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14059 BUG_ON(cpu != 0);
14060 gdt = get_cpu_gdt_table(cpu);
14061 save_desc_40 = gdt[0x40 / 8];
14062 +
14063 + pax_open_kernel();
14064 gdt[0x40 / 8] = bad_bios_desc;
14065 + pax_close_kernel();
14066
14067 apm_irq_save(flags);
14068 APM_DO_SAVE_SEGS;
14069 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14070 &call->esi);
14071 APM_DO_RESTORE_SEGS;
14072 apm_irq_restore(flags);
14073 +
14074 + pax_open_kernel();
14075 gdt[0x40 / 8] = save_desc_40;
14076 + pax_close_kernel();
14077 +
14078 put_cpu();
14079
14080 return call->eax & 0xff;
14081 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14082 BUG_ON(cpu != 0);
14083 gdt = get_cpu_gdt_table(cpu);
14084 save_desc_40 = gdt[0x40 / 8];
14085 +
14086 + pax_open_kernel();
14087 gdt[0x40 / 8] = bad_bios_desc;
14088 + pax_close_kernel();
14089
14090 apm_irq_save(flags);
14091 APM_DO_SAVE_SEGS;
14092 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14093 &call->eax);
14094 APM_DO_RESTORE_SEGS;
14095 apm_irq_restore(flags);
14096 +
14097 + pax_open_kernel();
14098 gdt[0x40 / 8] = save_desc_40;
14099 + pax_close_kernel();
14100 +
14101 put_cpu();
14102 return error;
14103 }
14104 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14105 * code to that CPU.
14106 */
14107 gdt = get_cpu_gdt_table(0);
14108 +
14109 + pax_open_kernel();
14110 set_desc_base(&gdt[APM_CS >> 3],
14111 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14112 set_desc_base(&gdt[APM_CS_16 >> 3],
14113 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14114 set_desc_base(&gdt[APM_DS >> 3],
14115 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14116 + pax_close_kernel();
14117
14118 proc_create("apm", 0, NULL, &apm_file_ops);
14119
14120 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14121 index 68de2dc..1f3c720 100644
14122 --- a/arch/x86/kernel/asm-offsets.c
14123 +++ b/arch/x86/kernel/asm-offsets.c
14124 @@ -33,6 +33,8 @@ void common(void) {
14125 OFFSET(TI_status, thread_info, status);
14126 OFFSET(TI_addr_limit, thread_info, addr_limit);
14127 OFFSET(TI_preempt_count, thread_info, preempt_count);
14128 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14129 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14130
14131 BLANK();
14132 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14133 @@ -53,8 +55,26 @@ void common(void) {
14134 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14135 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14136 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14137 +
14138 +#ifdef CONFIG_PAX_KERNEXEC
14139 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14140 #endif
14141
14142 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14143 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14144 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14145 +#ifdef CONFIG_X86_64
14146 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14147 +#endif
14148 +#endif
14149 +
14150 +#endif
14151 +
14152 + BLANK();
14153 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14154 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14155 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14156 +
14157 #ifdef CONFIG_XEN
14158 BLANK();
14159 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14160 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14161 index 1b4754f..fbb4227 100644
14162 --- a/arch/x86/kernel/asm-offsets_64.c
14163 +++ b/arch/x86/kernel/asm-offsets_64.c
14164 @@ -76,6 +76,7 @@ int main(void)
14165 BLANK();
14166 #undef ENTRY
14167
14168 + DEFINE(TSS_size, sizeof(struct tss_struct));
14169 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14170 BLANK();
14171
14172 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14173 index d30a6a9..79becab 100644
14174 --- a/arch/x86/kernel/cpu/Makefile
14175 +++ b/arch/x86/kernel/cpu/Makefile
14176 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14177 CFLAGS_REMOVE_perf_event.o = -pg
14178 endif
14179
14180 -# Make sure load_percpu_segment has no stackprotector
14181 -nostackp := $(call cc-option, -fno-stack-protector)
14182 -CFLAGS_common.o := $(nostackp)
14183 -
14184 obj-y := intel_cacheinfo.o scattered.o topology.o
14185 obj-y += proc.o capflags.o powerflags.o common.o
14186 obj-y += vmware.o hypervisor.o mshyperv.o
14187 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14188 index 9d92e19..49d7d79 100644
14189 --- a/arch/x86/kernel/cpu/amd.c
14190 +++ b/arch/x86/kernel/cpu/amd.c
14191 @@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14192 unsigned int size)
14193 {
14194 /* AMD errata T13 (order #21922) */
14195 - if ((c->x86 == 6)) {
14196 + if (c->x86 == 6) {
14197 /* Duron Rev A0 */
14198 if (c->x86_model == 3 && c->x86_mask == 0)
14199 size = 64;
14200 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14201 index a5fbc3c..2254849 100644
14202 --- a/arch/x86/kernel/cpu/common.c
14203 +++ b/arch/x86/kernel/cpu/common.c
14204 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14205
14206 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14207
14208 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14209 -#ifdef CONFIG_X86_64
14210 - /*
14211 - * We need valid kernel segments for data and code in long mode too
14212 - * IRET will check the segment types kkeil 2000/10/28
14213 - * Also sysret mandates a special GDT layout
14214 - *
14215 - * TLS descriptors are currently at a different place compared to i386.
14216 - * Hopefully nobody expects them at a fixed place (Wine?)
14217 - */
14218 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14219 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14220 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14221 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14222 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14223 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14224 -#else
14225 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14226 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14227 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14228 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14229 - /*
14230 - * Segments used for calling PnP BIOS have byte granularity.
14231 - * They code segments and data segments have fixed 64k limits,
14232 - * the transfer segment sizes are set at run time.
14233 - */
14234 - /* 32-bit code */
14235 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14236 - /* 16-bit code */
14237 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14238 - /* 16-bit data */
14239 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14240 - /* 16-bit data */
14241 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14242 - /* 16-bit data */
14243 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14244 - /*
14245 - * The APM segments have byte granularity and their bases
14246 - * are set at run time. All have 64k limits.
14247 - */
14248 - /* 32-bit code */
14249 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14250 - /* 16-bit code */
14251 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14252 - /* data */
14253 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14254 -
14255 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14256 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14257 - GDT_STACK_CANARY_INIT
14258 -#endif
14259 -} };
14260 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14261 -
14262 static int __init x86_xsave_setup(char *s)
14263 {
14264 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14265 @@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14266 {
14267 struct desc_ptr gdt_descr;
14268
14269 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14270 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14271 gdt_descr.size = GDT_SIZE - 1;
14272 load_gdt(&gdt_descr);
14273 /* Reload the per-cpu base */
14274 @@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14275 /* Filter out anything that depends on CPUID levels we don't have */
14276 filter_cpuid_features(c, true);
14277
14278 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14279 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14280 +#endif
14281 +
14282 /* If the model name is still unset, do table lookup. */
14283 if (!c->x86_model_id[0]) {
14284 const char *p;
14285 @@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14286 }
14287 __setup("clearcpuid=", setup_disablecpuid);
14288
14289 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14290 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14291 +
14292 #ifdef CONFIG_X86_64
14293 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14294 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14295 - (unsigned long) nmi_idt_table };
14296 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14297
14298 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14299 irq_stack_union) __aligned(PAGE_SIZE);
14300 @@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14301 EXPORT_PER_CPU_SYMBOL(current_task);
14302
14303 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14304 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14305 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14306 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14307
14308 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14309 @@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14310 {
14311 memset(regs, 0, sizeof(struct pt_regs));
14312 regs->fs = __KERNEL_PERCPU;
14313 - regs->gs = __KERNEL_STACK_CANARY;
14314 + savesegment(gs, regs->gs);
14315
14316 return regs;
14317 }
14318 @@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14319 int i;
14320
14321 cpu = stack_smp_processor_id();
14322 - t = &per_cpu(init_tss, cpu);
14323 + t = init_tss + cpu;
14324 oist = &per_cpu(orig_ist, cpu);
14325
14326 #ifdef CONFIG_NUMA
14327 @@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14328 switch_to_new_gdt(cpu);
14329 loadsegment(fs, 0);
14330
14331 - load_idt((const struct desc_ptr *)&idt_descr);
14332 + load_idt(&idt_descr);
14333
14334 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14335 syscall_init();
14336 @@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14337 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14338 barrier();
14339
14340 - x86_configure_nx();
14341 if (cpu != 0)
14342 enable_x2apic();
14343
14344 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14345 {
14346 int cpu = smp_processor_id();
14347 struct task_struct *curr = current;
14348 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14349 + struct tss_struct *t = init_tss + cpu;
14350 struct thread_struct *thread = &curr->thread;
14351
14352 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14353 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14354 index 0a4ce29..f211176 100644
14355 --- a/arch/x86/kernel/cpu/intel.c
14356 +++ b/arch/x86/kernel/cpu/intel.c
14357 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14358 * Update the IDT descriptor and reload the IDT so that
14359 * it uses the read-only mapped virtual address.
14360 */
14361 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14362 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14363 load_idt(&idt_descr);
14364 }
14365 #endif
14366 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14367 index 292d025..b520c94 100644
14368 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14369 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14370 @@ -45,6 +45,7 @@
14371 #include <asm/processor.h>
14372 #include <asm/mce.h>
14373 #include <asm/msr.h>
14374 +#include <asm/local.h>
14375
14376 #include "mce-internal.h"
14377
14378 @@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14379 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14380 m->cs, m->ip);
14381
14382 - if (m->cs == __KERNEL_CS)
14383 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14384 print_symbol("{%s}", m->ip);
14385 pr_cont("\n");
14386 }
14387 @@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14388
14389 #define PANIC_TIMEOUT 5 /* 5 seconds */
14390
14391 -static atomic_t mce_paniced;
14392 +static atomic_unchecked_t mce_paniced;
14393
14394 static int fake_panic;
14395 -static atomic_t mce_fake_paniced;
14396 +static atomic_unchecked_t mce_fake_paniced;
14397
14398 /* Panic in progress. Enable interrupts and wait for final IPI */
14399 static void wait_for_panic(void)
14400 @@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14401 /*
14402 * Make sure only one CPU runs in machine check panic
14403 */
14404 - if (atomic_inc_return(&mce_paniced) > 1)
14405 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14406 wait_for_panic();
14407 barrier();
14408
14409 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14410 console_verbose();
14411 } else {
14412 /* Don't log too much for fake panic */
14413 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14414 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14415 return;
14416 }
14417 /* First print corrected ones that are still unlogged */
14418 @@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14419 * might have been modified by someone else.
14420 */
14421 rmb();
14422 - if (atomic_read(&mce_paniced))
14423 + if (atomic_read_unchecked(&mce_paniced))
14424 wait_for_panic();
14425 if (!monarch_timeout)
14426 goto out;
14427 @@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14428 }
14429
14430 /* Call the installed machine check handler for this CPU setup. */
14431 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14432 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14433 unexpected_machine_check;
14434
14435 /*
14436 @@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14437 return;
14438 }
14439
14440 + pax_open_kernel();
14441 machine_check_vector = do_machine_check;
14442 + pax_close_kernel();
14443
14444 __mcheck_cpu_init_generic();
14445 __mcheck_cpu_init_vendor(c);
14446 @@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14447 */
14448
14449 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14450 -static int mce_chrdev_open_count; /* #times opened */
14451 +static local_t mce_chrdev_open_count; /* #times opened */
14452 static int mce_chrdev_open_exclu; /* already open exclusive? */
14453
14454 static int mce_chrdev_open(struct inode *inode, struct file *file)
14455 @@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14456 spin_lock(&mce_chrdev_state_lock);
14457
14458 if (mce_chrdev_open_exclu ||
14459 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14460 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14461 spin_unlock(&mce_chrdev_state_lock);
14462
14463 return -EBUSY;
14464 @@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14465
14466 if (file->f_flags & O_EXCL)
14467 mce_chrdev_open_exclu = 1;
14468 - mce_chrdev_open_count++;
14469 + local_inc(&mce_chrdev_open_count);
14470
14471 spin_unlock(&mce_chrdev_state_lock);
14472
14473 @@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14474 {
14475 spin_lock(&mce_chrdev_state_lock);
14476
14477 - mce_chrdev_open_count--;
14478 + local_dec(&mce_chrdev_open_count);
14479 mce_chrdev_open_exclu = 0;
14480
14481 spin_unlock(&mce_chrdev_state_lock);
14482 @@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14483 static void mce_reset(void)
14484 {
14485 cpu_missing = 0;
14486 - atomic_set(&mce_fake_paniced, 0);
14487 + atomic_set_unchecked(&mce_fake_paniced, 0);
14488 atomic_set(&mce_executing, 0);
14489 atomic_set(&mce_callin, 0);
14490 atomic_set(&global_nwo, 0);
14491 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14492 index 2d5454c..51987eb 100644
14493 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14494 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14495 @@ -11,6 +11,7 @@
14496 #include <asm/processor.h>
14497 #include <asm/mce.h>
14498 #include <asm/msr.h>
14499 +#include <asm/pgtable.h>
14500
14501 /* By default disabled */
14502 int mce_p5_enabled __read_mostly;
14503 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14504 if (!cpu_has(c, X86_FEATURE_MCE))
14505 return;
14506
14507 + pax_open_kernel();
14508 machine_check_vector = pentium_machine_check;
14509 + pax_close_kernel();
14510 /* Make sure the vector pointer is visible before we enable MCEs: */
14511 wmb();
14512
14513 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14514 index 2d7998f..17c9de1 100644
14515 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14516 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14517 @@ -10,6 +10,7 @@
14518 #include <asm/processor.h>
14519 #include <asm/mce.h>
14520 #include <asm/msr.h>
14521 +#include <asm/pgtable.h>
14522
14523 /* Machine check handler for WinChip C6: */
14524 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14525 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14526 {
14527 u32 lo, hi;
14528
14529 + pax_open_kernel();
14530 machine_check_vector = winchip_machine_check;
14531 + pax_close_kernel();
14532 /* Make sure the vector pointer is visible before we enable MCEs: */
14533 wmb();
14534
14535 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14536 index 6b96110..0da73eb 100644
14537 --- a/arch/x86/kernel/cpu/mtrr/main.c
14538 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14539 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14540 u64 size_or_mask, size_and_mask;
14541 static bool mtrr_aps_delayed_init;
14542
14543 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14544 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14545
14546 const struct mtrr_ops *mtrr_if;
14547
14548 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14549 index df5e41f..816c719 100644
14550 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14551 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14552 @@ -25,7 +25,7 @@ struct mtrr_ops {
14553 int (*validate_add_page)(unsigned long base, unsigned long size,
14554 unsigned int type);
14555 int (*have_wrcomb)(void);
14556 -};
14557 +} __do_const;
14558
14559 extern int generic_get_free_region(unsigned long base, unsigned long size,
14560 int replace_reg);
14561 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14562 index 915b876..171f845 100644
14563 --- a/arch/x86/kernel/cpu/perf_event.c
14564 +++ b/arch/x86/kernel/cpu/perf_event.c
14565 @@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14566 if (idx > GDT_ENTRIES)
14567 return 0;
14568
14569 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14570 + desc = get_cpu_gdt_table(smp_processor_id());
14571 }
14572
14573 return get_desc_base(desc + idx);
14574 @@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14575 break;
14576
14577 perf_callchain_store(entry, frame.return_address);
14578 - fp = frame.next_frame;
14579 + fp = (const void __force_user *)frame.next_frame;
14580 }
14581 }
14582
14583 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14584 index 6bca492..36e4496 100644
14585 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14586 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14587 @@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14588 * v2 and above have a perf capabilities MSR
14589 */
14590 if (version > 1) {
14591 - u64 capabilities;
14592 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14593
14594 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14595 - x86_pmu.intel_cap.capabilities = capabilities;
14596 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14597 + x86_pmu.intel_cap.capabilities = capabilities;
14598 }
14599
14600 intel_ds_init();
14601 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14602 index 13ad899..f642b9a 100644
14603 --- a/arch/x86/kernel/crash.c
14604 +++ b/arch/x86/kernel/crash.c
14605 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14606 {
14607 #ifdef CONFIG_X86_32
14608 struct pt_regs fixed_regs;
14609 -#endif
14610
14611 -#ifdef CONFIG_X86_32
14612 - if (!user_mode_vm(regs)) {
14613 + if (!user_mode(regs)) {
14614 crash_fixup_ss_esp(&fixed_regs, regs);
14615 regs = &fixed_regs;
14616 }
14617 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14618 index 37250fe..bf2ec74 100644
14619 --- a/arch/x86/kernel/doublefault_32.c
14620 +++ b/arch/x86/kernel/doublefault_32.c
14621 @@ -11,7 +11,7 @@
14622
14623 #define DOUBLEFAULT_STACKSIZE (1024)
14624 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14625 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14626 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14627
14628 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14629
14630 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14631 unsigned long gdt, tss;
14632
14633 store_gdt(&gdt_desc);
14634 - gdt = gdt_desc.address;
14635 + gdt = (unsigned long)gdt_desc.address;
14636
14637 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14638
14639 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14640 /* 0x2 bit is always set */
14641 .flags = X86_EFLAGS_SF | 0x2,
14642 .sp = STACK_START,
14643 - .es = __USER_DS,
14644 + .es = __KERNEL_DS,
14645 .cs = __KERNEL_CS,
14646 .ss = __KERNEL_DS,
14647 - .ds = __USER_DS,
14648 + .ds = __KERNEL_DS,
14649 .fs = __KERNEL_PERCPU,
14650
14651 .__cr3 = __pa_nodebug(swapper_pg_dir),
14652 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14653 index ae42418b..787c16b 100644
14654 --- a/arch/x86/kernel/dumpstack.c
14655 +++ b/arch/x86/kernel/dumpstack.c
14656 @@ -2,6 +2,9 @@
14657 * Copyright (C) 1991, 1992 Linus Torvalds
14658 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14659 */
14660 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14661 +#define __INCLUDED_BY_HIDESYM 1
14662 +#endif
14663 #include <linux/kallsyms.h>
14664 #include <linux/kprobes.h>
14665 #include <linux/uaccess.h>
14666 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14667 static void
14668 print_ftrace_graph_addr(unsigned long addr, void *data,
14669 const struct stacktrace_ops *ops,
14670 - struct thread_info *tinfo, int *graph)
14671 + struct task_struct *task, int *graph)
14672 {
14673 - struct task_struct *task;
14674 unsigned long ret_addr;
14675 int index;
14676
14677 if (addr != (unsigned long)return_to_handler)
14678 return;
14679
14680 - task = tinfo->task;
14681 index = task->curr_ret_stack;
14682
14683 if (!task->ret_stack || index < *graph)
14684 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14685 static inline void
14686 print_ftrace_graph_addr(unsigned long addr, void *data,
14687 const struct stacktrace_ops *ops,
14688 - struct thread_info *tinfo, int *graph)
14689 + struct task_struct *task, int *graph)
14690 { }
14691 #endif
14692
14693 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14694 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14695 */
14696
14697 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14698 - void *p, unsigned int size, void *end)
14699 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14700 {
14701 - void *t = tinfo;
14702 if (end) {
14703 if (p < end && p >= (end-THREAD_SIZE))
14704 return 1;
14705 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14706 }
14707
14708 unsigned long
14709 -print_context_stack(struct thread_info *tinfo,
14710 +print_context_stack(struct task_struct *task, void *stack_start,
14711 unsigned long *stack, unsigned long bp,
14712 const struct stacktrace_ops *ops, void *data,
14713 unsigned long *end, int *graph)
14714 {
14715 struct stack_frame *frame = (struct stack_frame *)bp;
14716
14717 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14718 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14719 unsigned long addr;
14720
14721 addr = *stack;
14722 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14723 } else {
14724 ops->address(data, addr, 0);
14725 }
14726 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14727 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14728 }
14729 stack++;
14730 }
14731 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14732 EXPORT_SYMBOL_GPL(print_context_stack);
14733
14734 unsigned long
14735 -print_context_stack_bp(struct thread_info *tinfo,
14736 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14737 unsigned long *stack, unsigned long bp,
14738 const struct stacktrace_ops *ops, void *data,
14739 unsigned long *end, int *graph)
14740 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14741 struct stack_frame *frame = (struct stack_frame *)bp;
14742 unsigned long *ret_addr = &frame->return_address;
14743
14744 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14745 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14746 unsigned long addr = *ret_addr;
14747
14748 if (!__kernel_text_address(addr))
14749 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14750 ops->address(data, addr, 1);
14751 frame = frame->next_frame;
14752 ret_addr = &frame->return_address;
14753 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14754 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14755 }
14756
14757 return (unsigned long)frame;
14758 @@ -189,7 +188,7 @@ void dump_stack(void)
14759
14760 bp = stack_frame(current, NULL);
14761 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14762 - current->pid, current->comm, print_tainted(),
14763 + task_pid_nr(current), current->comm, print_tainted(),
14764 init_utsname()->release,
14765 (int)strcspn(init_utsname()->version, " "),
14766 init_utsname()->version);
14767 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14768 }
14769 EXPORT_SYMBOL_GPL(oops_begin);
14770
14771 +extern void gr_handle_kernel_exploit(void);
14772 +
14773 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14774 {
14775 if (regs && kexec_should_crash(current))
14776 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14777 panic("Fatal exception in interrupt");
14778 if (panic_on_oops)
14779 panic("Fatal exception");
14780 - do_exit(signr);
14781 +
14782 + gr_handle_kernel_exploit();
14783 +
14784 + do_group_exit(signr);
14785 }
14786
14787 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14788 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14789 print_modules();
14790 show_regs(regs);
14791 #ifdef CONFIG_X86_32
14792 - if (user_mode_vm(regs)) {
14793 + if (user_mode(regs)) {
14794 sp = regs->sp;
14795 ss = regs->ss & 0xffff;
14796 } else {
14797 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14798 unsigned long flags = oops_begin();
14799 int sig = SIGSEGV;
14800
14801 - if (!user_mode_vm(regs))
14802 + if (!user_mode(regs))
14803 report_bug(regs->ip, regs);
14804
14805 if (__die(str, regs, err))
14806 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14807 index 1038a41..ac7e5f6 100644
14808 --- a/arch/x86/kernel/dumpstack_32.c
14809 +++ b/arch/x86/kernel/dumpstack_32.c
14810 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14811 bp = stack_frame(task, regs);
14812
14813 for (;;) {
14814 - struct thread_info *context;
14815 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14816
14817 - context = (struct thread_info *)
14818 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14819 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14820 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14821
14822 - stack = (unsigned long *)context->previous_esp;
14823 - if (!stack)
14824 + if (stack_start == task_stack_page(task))
14825 break;
14826 + stack = *(unsigned long **)stack_start;
14827 if (ops->stack(data, "IRQ") < 0)
14828 break;
14829 touch_nmi_watchdog();
14830 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14831 {
14832 int i;
14833
14834 - __show_regs(regs, !user_mode_vm(regs));
14835 + __show_regs(regs, !user_mode(regs));
14836
14837 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14838 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14839 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14840 * When in-kernel, we also print out the stack and code at the
14841 * time of the fault..
14842 */
14843 - if (!user_mode_vm(regs)) {
14844 + if (!user_mode(regs)) {
14845 unsigned int code_prologue = code_bytes * 43 / 64;
14846 unsigned int code_len = code_bytes;
14847 unsigned char c;
14848 u8 *ip;
14849 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14850
14851 pr_emerg("Stack:\n");
14852 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14853
14854 pr_emerg("Code:");
14855
14856 - ip = (u8 *)regs->ip - code_prologue;
14857 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14858 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14859 /* try starting at IP */
14860 - ip = (u8 *)regs->ip;
14861 + ip = (u8 *)regs->ip + cs_base;
14862 code_len = code_len - code_prologue + 1;
14863 }
14864 for (i = 0; i < code_len; i++, ip++) {
14865 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14866 pr_cont(" Bad EIP value.");
14867 break;
14868 }
14869 - if (ip == (u8 *)regs->ip)
14870 + if (ip == (u8 *)regs->ip + cs_base)
14871 pr_cont(" <%02x>", c);
14872 else
14873 pr_cont(" %02x", c);
14874 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14875 {
14876 unsigned short ud2;
14877
14878 + ip = ktla_ktva(ip);
14879 if (ip < PAGE_OFFSET)
14880 return 0;
14881 if (probe_kernel_address((unsigned short *)ip, ud2))
14882 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14883
14884 return ud2 == 0x0b0f;
14885 }
14886 +
14887 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14888 +void pax_check_alloca(unsigned long size)
14889 +{
14890 + unsigned long sp = (unsigned long)&sp, stack_left;
14891 +
14892 + /* all kernel stacks are of the same size */
14893 + stack_left = sp & (THREAD_SIZE - 1);
14894 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14895 +}
14896 +EXPORT_SYMBOL(pax_check_alloca);
14897 +#endif
14898 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14899 index b653675..33190c0 100644
14900 --- a/arch/x86/kernel/dumpstack_64.c
14901 +++ b/arch/x86/kernel/dumpstack_64.c
14902 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14903 unsigned long *irq_stack_end =
14904 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14905 unsigned used = 0;
14906 - struct thread_info *tinfo;
14907 int graph = 0;
14908 unsigned long dummy;
14909 + void *stack_start;
14910
14911 if (!task)
14912 task = current;
14913 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14914 * current stack address. If the stacks consist of nested
14915 * exceptions
14916 */
14917 - tinfo = task_thread_info(task);
14918 for (;;) {
14919 char *id;
14920 unsigned long *estack_end;
14921 +
14922 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14923 &used, &id);
14924
14925 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14926 if (ops->stack(data, id) < 0)
14927 break;
14928
14929 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14930 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14931 data, estack_end, &graph);
14932 ops->stack(data, "<EOE>");
14933 /*
14934 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14935 * second-to-last pointer (index -2 to end) in the
14936 * exception stack:
14937 */
14938 + if ((u16)estack_end[-1] != __KERNEL_DS)
14939 + goto out;
14940 stack = (unsigned long *) estack_end[-2];
14941 continue;
14942 }
14943 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14944 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14945 if (ops->stack(data, "IRQ") < 0)
14946 break;
14947 - bp = ops->walk_stack(tinfo, stack, bp,
14948 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14949 ops, data, irq_stack_end, &graph);
14950 /*
14951 * We link to the next stack (which would be
14952 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14953 /*
14954 * This handles the process stack:
14955 */
14956 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14957 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14958 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14959 +out:
14960 put_cpu();
14961 }
14962 EXPORT_SYMBOL(dump_trace);
14963 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14964
14965 return ud2 == 0x0b0f;
14966 }
14967 +
14968 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14969 +void pax_check_alloca(unsigned long size)
14970 +{
14971 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14972 + unsigned cpu, used;
14973 + char *id;
14974 +
14975 + /* check the process stack first */
14976 + stack_start = (unsigned long)task_stack_page(current);
14977 + stack_end = stack_start + THREAD_SIZE;
14978 + if (likely(stack_start <= sp && sp < stack_end)) {
14979 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14980 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14981 + return;
14982 + }
14983 +
14984 + cpu = get_cpu();
14985 +
14986 + /* check the irq stacks */
14987 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14988 + stack_start = stack_end - IRQ_STACK_SIZE;
14989 + if (stack_start <= sp && sp < stack_end) {
14990 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14991 + put_cpu();
14992 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14993 + return;
14994 + }
14995 +
14996 + /* check the exception stacks */
14997 + used = 0;
14998 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14999 + stack_start = stack_end - EXCEPTION_STKSZ;
15000 + if (stack_end && stack_start <= sp && sp < stack_end) {
15001 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
15002 + put_cpu();
15003 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15004 + return;
15005 + }
15006 +
15007 + put_cpu();
15008 +
15009 + /* unknown stack */
15010 + BUG();
15011 +}
15012 +EXPORT_SYMBOL(pax_check_alloca);
15013 +#endif
15014 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
15015 index 9b9f18b..9fcaa04 100644
15016 --- a/arch/x86/kernel/early_printk.c
15017 +++ b/arch/x86/kernel/early_printk.c
15018 @@ -7,6 +7,7 @@
15019 #include <linux/pci_regs.h>
15020 #include <linux/pci_ids.h>
15021 #include <linux/errno.h>
15022 +#include <linux/sched.h>
15023 #include <asm/io.h>
15024 #include <asm/processor.h>
15025 #include <asm/fcntl.h>
15026 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
15027 index 8f8e8ee..3617d6e 100644
15028 --- a/arch/x86/kernel/entry_32.S
15029 +++ b/arch/x86/kernel/entry_32.S
15030 @@ -176,13 +176,153 @@
15031 /*CFI_REL_OFFSET gs, PT_GS*/
15032 .endm
15033 .macro SET_KERNEL_GS reg
15034 +
15035 +#ifdef CONFIG_CC_STACKPROTECTOR
15036 movl $(__KERNEL_STACK_CANARY), \reg
15037 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15038 + movl $(__USER_DS), \reg
15039 +#else
15040 + xorl \reg, \reg
15041 +#endif
15042 +
15043 movl \reg, %gs
15044 .endm
15045
15046 #endif /* CONFIG_X86_32_LAZY_GS */
15047
15048 -.macro SAVE_ALL
15049 +.macro pax_enter_kernel
15050 +#ifdef CONFIG_PAX_KERNEXEC
15051 + call pax_enter_kernel
15052 +#endif
15053 +.endm
15054 +
15055 +.macro pax_exit_kernel
15056 +#ifdef CONFIG_PAX_KERNEXEC
15057 + call pax_exit_kernel
15058 +#endif
15059 +.endm
15060 +
15061 +#ifdef CONFIG_PAX_KERNEXEC
15062 +ENTRY(pax_enter_kernel)
15063 +#ifdef CONFIG_PARAVIRT
15064 + pushl %eax
15065 + pushl %ecx
15066 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15067 + mov %eax, %esi
15068 +#else
15069 + mov %cr0, %esi
15070 +#endif
15071 + bts $16, %esi
15072 + jnc 1f
15073 + mov %cs, %esi
15074 + cmp $__KERNEL_CS, %esi
15075 + jz 3f
15076 + ljmp $__KERNEL_CS, $3f
15077 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15078 +2:
15079 +#ifdef CONFIG_PARAVIRT
15080 + mov %esi, %eax
15081 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15082 +#else
15083 + mov %esi, %cr0
15084 +#endif
15085 +3:
15086 +#ifdef CONFIG_PARAVIRT
15087 + popl %ecx
15088 + popl %eax
15089 +#endif
15090 + ret
15091 +ENDPROC(pax_enter_kernel)
15092 +
15093 +ENTRY(pax_exit_kernel)
15094 +#ifdef CONFIG_PARAVIRT
15095 + pushl %eax
15096 + pushl %ecx
15097 +#endif
15098 + mov %cs, %esi
15099 + cmp $__KERNEXEC_KERNEL_CS, %esi
15100 + jnz 2f
15101 +#ifdef CONFIG_PARAVIRT
15102 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15103 + mov %eax, %esi
15104 +#else
15105 + mov %cr0, %esi
15106 +#endif
15107 + btr $16, %esi
15108 + ljmp $__KERNEL_CS, $1f
15109 +1:
15110 +#ifdef CONFIG_PARAVIRT
15111 + mov %esi, %eax
15112 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15113 +#else
15114 + mov %esi, %cr0
15115 +#endif
15116 +2:
15117 +#ifdef CONFIG_PARAVIRT
15118 + popl %ecx
15119 + popl %eax
15120 +#endif
15121 + ret
15122 +ENDPROC(pax_exit_kernel)
15123 +#endif
15124 +
15125 +.macro pax_erase_kstack
15126 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15127 + call pax_erase_kstack
15128 +#endif
15129 +.endm
15130 +
15131 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15132 +/*
15133 + * ebp: thread_info
15134 + */
15135 +ENTRY(pax_erase_kstack)
15136 + pushl %edi
15137 + pushl %ecx
15138 + pushl %eax
15139 +
15140 + mov TI_lowest_stack(%ebp), %edi
15141 + mov $-0xBEEF, %eax
15142 + std
15143 +
15144 +1: mov %edi, %ecx
15145 + and $THREAD_SIZE_asm - 1, %ecx
15146 + shr $2, %ecx
15147 + repne scasl
15148 + jecxz 2f
15149 +
15150 + cmp $2*16, %ecx
15151 + jc 2f
15152 +
15153 + mov $2*16, %ecx
15154 + repe scasl
15155 + jecxz 2f
15156 + jne 1b
15157 +
15158 +2: cld
15159 + mov %esp, %ecx
15160 + sub %edi, %ecx
15161 +
15162 + cmp $THREAD_SIZE_asm, %ecx
15163 + jb 3f
15164 + ud2
15165 +3:
15166 +
15167 + shr $2, %ecx
15168 + rep stosl
15169 +
15170 + mov TI_task_thread_sp0(%ebp), %edi
15171 + sub $128, %edi
15172 + mov %edi, TI_lowest_stack(%ebp)
15173 +
15174 + popl %eax
15175 + popl %ecx
15176 + popl %edi
15177 + ret
15178 +ENDPROC(pax_erase_kstack)
15179 +#endif
15180 +
15181 +.macro __SAVE_ALL _DS
15182 cld
15183 PUSH_GS
15184 pushl_cfi %fs
15185 @@ -205,7 +345,7 @@
15186 CFI_REL_OFFSET ecx, 0
15187 pushl_cfi %ebx
15188 CFI_REL_OFFSET ebx, 0
15189 - movl $(__USER_DS), %edx
15190 + movl $\_DS, %edx
15191 movl %edx, %ds
15192 movl %edx, %es
15193 movl $(__KERNEL_PERCPU), %edx
15194 @@ -213,6 +353,15 @@
15195 SET_KERNEL_GS %edx
15196 .endm
15197
15198 +.macro SAVE_ALL
15199 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15200 + __SAVE_ALL __KERNEL_DS
15201 + pax_enter_kernel
15202 +#else
15203 + __SAVE_ALL __USER_DS
15204 +#endif
15205 +.endm
15206 +
15207 .macro RESTORE_INT_REGS
15208 popl_cfi %ebx
15209 CFI_RESTORE ebx
15210 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15211 popfl_cfi
15212 jmp syscall_exit
15213 CFI_ENDPROC
15214 -END(ret_from_fork)
15215 +ENDPROC(ret_from_fork)
15216
15217 /*
15218 * Interrupt exit functions should be protected against kprobes
15219 @@ -329,7 +478,15 @@ ret_from_intr:
15220 andl $SEGMENT_RPL_MASK, %eax
15221 #endif
15222 cmpl $USER_RPL, %eax
15223 +
15224 +#ifdef CONFIG_PAX_KERNEXEC
15225 + jae resume_userspace
15226 +
15227 + pax_exit_kernel
15228 + jmp resume_kernel
15229 +#else
15230 jb resume_kernel # not returning to v8086 or userspace
15231 +#endif
15232
15233 ENTRY(resume_userspace)
15234 LOCKDEP_SYS_EXIT
15235 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15236 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15237 # int/exception return?
15238 jne work_pending
15239 - jmp restore_all
15240 -END(ret_from_exception)
15241 + jmp restore_all_pax
15242 +ENDPROC(ret_from_exception)
15243
15244 #ifdef CONFIG_PREEMPT
15245 ENTRY(resume_kernel)
15246 @@ -357,7 +514,7 @@ need_resched:
15247 jz restore_all
15248 call preempt_schedule_irq
15249 jmp need_resched
15250 -END(resume_kernel)
15251 +ENDPROC(resume_kernel)
15252 #endif
15253 CFI_ENDPROC
15254 /*
15255 @@ -391,28 +548,43 @@ sysenter_past_esp:
15256 /*CFI_REL_OFFSET cs, 0*/
15257 /*
15258 * Push current_thread_info()->sysenter_return to the stack.
15259 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15260 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15261 */
15262 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15263 + pushl_cfi $0
15264 CFI_REL_OFFSET eip, 0
15265
15266 pushl_cfi %eax
15267 SAVE_ALL
15268 + GET_THREAD_INFO(%ebp)
15269 + movl TI_sysenter_return(%ebp),%ebp
15270 + movl %ebp,PT_EIP(%esp)
15271 ENABLE_INTERRUPTS(CLBR_NONE)
15272
15273 /*
15274 * Load the potential sixth argument from user stack.
15275 * Careful about security.
15276 */
15277 + movl PT_OLDESP(%esp),%ebp
15278 +
15279 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15280 + mov PT_OLDSS(%esp),%ds
15281 +1: movl %ds:(%ebp),%ebp
15282 + push %ss
15283 + pop %ds
15284 +#else
15285 cmpl $__PAGE_OFFSET-3,%ebp
15286 jae syscall_fault
15287 1: movl (%ebp),%ebp
15288 +#endif
15289 +
15290 movl %ebp,PT_EBP(%esp)
15291 _ASM_EXTABLE(1b,syscall_fault)
15292
15293 GET_THREAD_INFO(%ebp)
15294
15295 +#ifdef CONFIG_PAX_RANDKSTACK
15296 + pax_erase_kstack
15297 +#endif
15298 +
15299 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15300 jnz sysenter_audit
15301 sysenter_do_call:
15302 @@ -427,12 +599,24 @@ sysenter_do_call:
15303 testl $_TIF_ALLWORK_MASK, %ecx
15304 jne sysexit_audit
15305 sysenter_exit:
15306 +
15307 +#ifdef CONFIG_PAX_RANDKSTACK
15308 + pushl_cfi %eax
15309 + movl %esp, %eax
15310 + call pax_randomize_kstack
15311 + popl_cfi %eax
15312 +#endif
15313 +
15314 + pax_erase_kstack
15315 +
15316 /* if something modifies registers it must also disable sysexit */
15317 movl PT_EIP(%esp), %edx
15318 movl PT_OLDESP(%esp), %ecx
15319 xorl %ebp,%ebp
15320 TRACE_IRQS_ON
15321 1: mov PT_FS(%esp), %fs
15322 +2: mov PT_DS(%esp), %ds
15323 +3: mov PT_ES(%esp), %es
15324 PTGS_TO_GS
15325 ENABLE_INTERRUPTS_SYSEXIT
15326
15327 @@ -449,6 +633,9 @@ sysenter_audit:
15328 movl %eax,%edx /* 2nd arg: syscall number */
15329 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15330 call __audit_syscall_entry
15331 +
15332 + pax_erase_kstack
15333 +
15334 pushl_cfi %ebx
15335 movl PT_EAX(%esp),%eax /* reload syscall number */
15336 jmp sysenter_do_call
15337 @@ -474,10 +661,16 @@ sysexit_audit:
15338
15339 CFI_ENDPROC
15340 .pushsection .fixup,"ax"
15341 -2: movl $0,PT_FS(%esp)
15342 +4: movl $0,PT_FS(%esp)
15343 + jmp 1b
15344 +5: movl $0,PT_DS(%esp)
15345 + jmp 1b
15346 +6: movl $0,PT_ES(%esp)
15347 jmp 1b
15348 .popsection
15349 - _ASM_EXTABLE(1b,2b)
15350 + _ASM_EXTABLE(1b,4b)
15351 + _ASM_EXTABLE(2b,5b)
15352 + _ASM_EXTABLE(3b,6b)
15353 PTGS_TO_GS_EX
15354 ENDPROC(ia32_sysenter_target)
15355
15356 @@ -491,6 +684,11 @@ ENTRY(system_call)
15357 pushl_cfi %eax # save orig_eax
15358 SAVE_ALL
15359 GET_THREAD_INFO(%ebp)
15360 +
15361 +#ifdef CONFIG_PAX_RANDKSTACK
15362 + pax_erase_kstack
15363 +#endif
15364 +
15365 # system call tracing in operation / emulation
15366 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15367 jnz syscall_trace_entry
15368 @@ -509,6 +707,15 @@ syscall_exit:
15369 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15370 jne syscall_exit_work
15371
15372 +restore_all_pax:
15373 +
15374 +#ifdef CONFIG_PAX_RANDKSTACK
15375 + movl %esp, %eax
15376 + call pax_randomize_kstack
15377 +#endif
15378 +
15379 + pax_erase_kstack
15380 +
15381 restore_all:
15382 TRACE_IRQS_IRET
15383 restore_all_notrace:
15384 @@ -565,14 +772,34 @@ ldt_ss:
15385 * compensating for the offset by changing to the ESPFIX segment with
15386 * a base address that matches for the difference.
15387 */
15388 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15389 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15390 mov %esp, %edx /* load kernel esp */
15391 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15392 mov %dx, %ax /* eax: new kernel esp */
15393 sub %eax, %edx /* offset (low word is 0) */
15394 +#ifdef CONFIG_SMP
15395 + movl PER_CPU_VAR(cpu_number), %ebx
15396 + shll $PAGE_SHIFT_asm, %ebx
15397 + addl $cpu_gdt_table, %ebx
15398 +#else
15399 + movl $cpu_gdt_table, %ebx
15400 +#endif
15401 shr $16, %edx
15402 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15403 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15404 +
15405 +#ifdef CONFIG_PAX_KERNEXEC
15406 + mov %cr0, %esi
15407 + btr $16, %esi
15408 + mov %esi, %cr0
15409 +#endif
15410 +
15411 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15412 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15413 +
15414 +#ifdef CONFIG_PAX_KERNEXEC
15415 + bts $16, %esi
15416 + mov %esi, %cr0
15417 +#endif
15418 +
15419 pushl_cfi $__ESPFIX_SS
15420 pushl_cfi %eax /* new kernel esp */
15421 /* Disable interrupts, but do not irqtrace this section: we
15422 @@ -601,35 +828,23 @@ work_resched:
15423 movl TI_flags(%ebp), %ecx
15424 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15425 # than syscall tracing?
15426 - jz restore_all
15427 + jz restore_all_pax
15428 testb $_TIF_NEED_RESCHED, %cl
15429 jnz work_resched
15430
15431 work_notifysig: # deal with pending signals and
15432 # notify-resume requests
15433 + movl %esp, %eax
15434 #ifdef CONFIG_VM86
15435 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15436 - movl %esp, %eax
15437 - jne work_notifysig_v86 # returning to kernel-space or
15438 + jz 1f # returning to kernel-space or
15439 # vm86-space
15440 - TRACE_IRQS_ON
15441 - ENABLE_INTERRUPTS(CLBR_NONE)
15442 - movb PT_CS(%esp), %bl
15443 - andb $SEGMENT_RPL_MASK, %bl
15444 - cmpb $USER_RPL, %bl
15445 - jb resume_kernel
15446 - xorl %edx, %edx
15447 - call do_notify_resume
15448 - jmp resume_userspace
15449
15450 - ALIGN
15451 -work_notifysig_v86:
15452 pushl_cfi %ecx # save ti_flags for do_notify_resume
15453 call save_v86_state # %eax contains pt_regs pointer
15454 popl_cfi %ecx
15455 movl %eax, %esp
15456 -#else
15457 - movl %esp, %eax
15458 +1:
15459 #endif
15460 TRACE_IRQS_ON
15461 ENABLE_INTERRUPTS(CLBR_NONE)
15462 @@ -640,7 +855,7 @@ work_notifysig_v86:
15463 xorl %edx, %edx
15464 call do_notify_resume
15465 jmp resume_userspace
15466 -END(work_pending)
15467 +ENDPROC(work_pending)
15468
15469 # perform syscall exit tracing
15470 ALIGN
15471 @@ -648,11 +863,14 @@ syscall_trace_entry:
15472 movl $-ENOSYS,PT_EAX(%esp)
15473 movl %esp, %eax
15474 call syscall_trace_enter
15475 +
15476 + pax_erase_kstack
15477 +
15478 /* What it returned is what we'll actually use. */
15479 cmpl $(NR_syscalls), %eax
15480 jnae syscall_call
15481 jmp syscall_exit
15482 -END(syscall_trace_entry)
15483 +ENDPROC(syscall_trace_entry)
15484
15485 # perform syscall exit tracing
15486 ALIGN
15487 @@ -665,20 +883,24 @@ syscall_exit_work:
15488 movl %esp, %eax
15489 call syscall_trace_leave
15490 jmp resume_userspace
15491 -END(syscall_exit_work)
15492 +ENDPROC(syscall_exit_work)
15493 CFI_ENDPROC
15494
15495 RING0_INT_FRAME # can't unwind into user space anyway
15496 syscall_fault:
15497 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15498 + push %ss
15499 + pop %ds
15500 +#endif
15501 GET_THREAD_INFO(%ebp)
15502 movl $-EFAULT,PT_EAX(%esp)
15503 jmp resume_userspace
15504 -END(syscall_fault)
15505 +ENDPROC(syscall_fault)
15506
15507 syscall_badsys:
15508 movl $-ENOSYS,PT_EAX(%esp)
15509 jmp resume_userspace
15510 -END(syscall_badsys)
15511 +ENDPROC(syscall_badsys)
15512 CFI_ENDPROC
15513 /*
15514 * End of kprobes section
15515 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15516 CFI_ENDPROC
15517 ENDPROC(ptregs_clone)
15518
15519 + ALIGN;
15520 +ENTRY(kernel_execve)
15521 + CFI_STARTPROC
15522 + pushl_cfi %ebp
15523 + sub $PT_OLDSS+4,%esp
15524 + pushl_cfi %edi
15525 + pushl_cfi %ecx
15526 + pushl_cfi %eax
15527 + lea 3*4(%esp),%edi
15528 + mov $PT_OLDSS/4+1,%ecx
15529 + xorl %eax,%eax
15530 + rep stosl
15531 + popl_cfi %eax
15532 + popl_cfi %ecx
15533 + popl_cfi %edi
15534 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15535 + pushl_cfi %esp
15536 + call sys_execve
15537 + add $4,%esp
15538 + CFI_ADJUST_CFA_OFFSET -4
15539 + GET_THREAD_INFO(%ebp)
15540 + test %eax,%eax
15541 + jz syscall_exit
15542 + add $PT_OLDSS+4,%esp
15543 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15544 + popl_cfi %ebp
15545 + ret
15546 + CFI_ENDPROC
15547 +ENDPROC(kernel_execve)
15548 +
15549 .macro FIXUP_ESPFIX_STACK
15550 /*
15551 * Switch back for ESPFIX stack to the normal zerobased stack
15552 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15553 * normal stack and adjusts ESP with the matching offset.
15554 */
15555 /* fixup the stack */
15556 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15557 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15558 +#ifdef CONFIG_SMP
15559 + movl PER_CPU_VAR(cpu_number), %ebx
15560 + shll $PAGE_SHIFT_asm, %ebx
15561 + addl $cpu_gdt_table, %ebx
15562 +#else
15563 + movl $cpu_gdt_table, %ebx
15564 +#endif
15565 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15566 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15567 shl $16, %eax
15568 addl %esp, %eax /* the adjusted stack pointer */
15569 pushl_cfi $__KERNEL_DS
15570 @@ -813,7 +1072,7 @@ vector=vector+1
15571 .endr
15572 2: jmp common_interrupt
15573 .endr
15574 -END(irq_entries_start)
15575 +ENDPROC(irq_entries_start)
15576
15577 .previous
15578 END(interrupt)
15579 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15580 pushl_cfi $do_coprocessor_error
15581 jmp error_code
15582 CFI_ENDPROC
15583 -END(coprocessor_error)
15584 +ENDPROC(coprocessor_error)
15585
15586 ENTRY(simd_coprocessor_error)
15587 RING0_INT_FRAME
15588 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15589 #endif
15590 jmp error_code
15591 CFI_ENDPROC
15592 -END(simd_coprocessor_error)
15593 +ENDPROC(simd_coprocessor_error)
15594
15595 ENTRY(device_not_available)
15596 RING0_INT_FRAME
15597 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15598 pushl_cfi $do_device_not_available
15599 jmp error_code
15600 CFI_ENDPROC
15601 -END(device_not_available)
15602 +ENDPROC(device_not_available)
15603
15604 #ifdef CONFIG_PARAVIRT
15605 ENTRY(native_iret)
15606 iret
15607 _ASM_EXTABLE(native_iret, iret_exc)
15608 -END(native_iret)
15609 +ENDPROC(native_iret)
15610
15611 ENTRY(native_irq_enable_sysexit)
15612 sti
15613 sysexit
15614 -END(native_irq_enable_sysexit)
15615 +ENDPROC(native_irq_enable_sysexit)
15616 #endif
15617
15618 ENTRY(overflow)
15619 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15620 pushl_cfi $do_overflow
15621 jmp error_code
15622 CFI_ENDPROC
15623 -END(overflow)
15624 +ENDPROC(overflow)
15625
15626 ENTRY(bounds)
15627 RING0_INT_FRAME
15628 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15629 pushl_cfi $do_bounds
15630 jmp error_code
15631 CFI_ENDPROC
15632 -END(bounds)
15633 +ENDPROC(bounds)
15634
15635 ENTRY(invalid_op)
15636 RING0_INT_FRAME
15637 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15638 pushl_cfi $do_invalid_op
15639 jmp error_code
15640 CFI_ENDPROC
15641 -END(invalid_op)
15642 +ENDPROC(invalid_op)
15643
15644 ENTRY(coprocessor_segment_overrun)
15645 RING0_INT_FRAME
15646 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15647 pushl_cfi $do_coprocessor_segment_overrun
15648 jmp error_code
15649 CFI_ENDPROC
15650 -END(coprocessor_segment_overrun)
15651 +ENDPROC(coprocessor_segment_overrun)
15652
15653 ENTRY(invalid_TSS)
15654 RING0_EC_FRAME
15655 pushl_cfi $do_invalid_TSS
15656 jmp error_code
15657 CFI_ENDPROC
15658 -END(invalid_TSS)
15659 +ENDPROC(invalid_TSS)
15660
15661 ENTRY(segment_not_present)
15662 RING0_EC_FRAME
15663 pushl_cfi $do_segment_not_present
15664 jmp error_code
15665 CFI_ENDPROC
15666 -END(segment_not_present)
15667 +ENDPROC(segment_not_present)
15668
15669 ENTRY(stack_segment)
15670 RING0_EC_FRAME
15671 pushl_cfi $do_stack_segment
15672 jmp error_code
15673 CFI_ENDPROC
15674 -END(stack_segment)
15675 +ENDPROC(stack_segment)
15676
15677 ENTRY(alignment_check)
15678 RING0_EC_FRAME
15679 pushl_cfi $do_alignment_check
15680 jmp error_code
15681 CFI_ENDPROC
15682 -END(alignment_check)
15683 +ENDPROC(alignment_check)
15684
15685 ENTRY(divide_error)
15686 RING0_INT_FRAME
15687 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15688 pushl_cfi $do_divide_error
15689 jmp error_code
15690 CFI_ENDPROC
15691 -END(divide_error)
15692 +ENDPROC(divide_error)
15693
15694 #ifdef CONFIG_X86_MCE
15695 ENTRY(machine_check)
15696 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15697 pushl_cfi machine_check_vector
15698 jmp error_code
15699 CFI_ENDPROC
15700 -END(machine_check)
15701 +ENDPROC(machine_check)
15702 #endif
15703
15704 ENTRY(spurious_interrupt_bug)
15705 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15706 pushl_cfi $do_spurious_interrupt_bug
15707 jmp error_code
15708 CFI_ENDPROC
15709 -END(spurious_interrupt_bug)
15710 +ENDPROC(spurious_interrupt_bug)
15711 /*
15712 * End of kprobes section
15713 */
15714 @@ -1102,7 +1361,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15715
15716 ENTRY(mcount)
15717 ret
15718 -END(mcount)
15719 +ENDPROC(mcount)
15720
15721 ENTRY(ftrace_caller)
15722 cmpl $0, function_trace_stop
15723 @@ -1131,7 +1390,7 @@ ftrace_graph_call:
15724 .globl ftrace_stub
15725 ftrace_stub:
15726 ret
15727 -END(ftrace_caller)
15728 +ENDPROC(ftrace_caller)
15729
15730 #else /* ! CONFIG_DYNAMIC_FTRACE */
15731
15732 @@ -1167,7 +1426,7 @@ trace:
15733 popl %ecx
15734 popl %eax
15735 jmp ftrace_stub
15736 -END(mcount)
15737 +ENDPROC(mcount)
15738 #endif /* CONFIG_DYNAMIC_FTRACE */
15739 #endif /* CONFIG_FUNCTION_TRACER */
15740
15741 @@ -1188,7 +1447,7 @@ ENTRY(ftrace_graph_caller)
15742 popl %ecx
15743 popl %eax
15744 ret
15745 -END(ftrace_graph_caller)
15746 +ENDPROC(ftrace_graph_caller)
15747
15748 .globl return_to_handler
15749 return_to_handler:
15750 @@ -1243,15 +1502,18 @@ error_code:
15751 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15752 REG_TO_PTGS %ecx
15753 SET_KERNEL_GS %ecx
15754 - movl $(__USER_DS), %ecx
15755 + movl $(__KERNEL_DS), %ecx
15756 movl %ecx, %ds
15757 movl %ecx, %es
15758 +
15759 + pax_enter_kernel
15760 +
15761 TRACE_IRQS_OFF
15762 movl %esp,%eax # pt_regs pointer
15763 call *%edi
15764 jmp ret_from_exception
15765 CFI_ENDPROC
15766 -END(page_fault)
15767 +ENDPROC(page_fault)
15768
15769 /*
15770 * Debug traps and NMI can happen at the one SYSENTER instruction
15771 @@ -1293,7 +1555,7 @@ debug_stack_correct:
15772 call do_debug
15773 jmp ret_from_exception
15774 CFI_ENDPROC
15775 -END(debug)
15776 +ENDPROC(debug)
15777
15778 /*
15779 * NMI is doubly nasty. It can happen _while_ we're handling
15780 @@ -1330,6 +1592,9 @@ nmi_stack_correct:
15781 xorl %edx,%edx # zero error code
15782 movl %esp,%eax # pt_regs pointer
15783 call do_nmi
15784 +
15785 + pax_exit_kernel
15786 +
15787 jmp restore_all_notrace
15788 CFI_ENDPROC
15789
15790 @@ -1366,12 +1631,15 @@ nmi_espfix_stack:
15791 FIXUP_ESPFIX_STACK # %eax == %esp
15792 xorl %edx,%edx # zero error code
15793 call do_nmi
15794 +
15795 + pax_exit_kernel
15796 +
15797 RESTORE_REGS
15798 lss 12+4(%esp), %esp # back to espfix stack
15799 CFI_ADJUST_CFA_OFFSET -24
15800 jmp irq_return
15801 CFI_ENDPROC
15802 -END(nmi)
15803 +ENDPROC(nmi)
15804
15805 ENTRY(int3)
15806 RING0_INT_FRAME
15807 @@ -1383,14 +1651,14 @@ ENTRY(int3)
15808 call do_int3
15809 jmp ret_from_exception
15810 CFI_ENDPROC
15811 -END(int3)
15812 +ENDPROC(int3)
15813
15814 ENTRY(general_protection)
15815 RING0_EC_FRAME
15816 pushl_cfi $do_general_protection
15817 jmp error_code
15818 CFI_ENDPROC
15819 -END(general_protection)
15820 +ENDPROC(general_protection)
15821
15822 #ifdef CONFIG_KVM_GUEST
15823 ENTRY(async_page_fault)
15824 @@ -1398,7 +1666,7 @@ ENTRY(async_page_fault)
15825 pushl_cfi $do_async_page_fault
15826 jmp error_code
15827 CFI_ENDPROC
15828 -END(async_page_fault)
15829 +ENDPROC(async_page_fault)
15830 #endif
15831
15832 /*
15833 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15834 index dcdd0ea..8f32835 100644
15835 --- a/arch/x86/kernel/entry_64.S
15836 +++ b/arch/x86/kernel/entry_64.S
15837 @@ -57,6 +57,8 @@
15838 #include <asm/percpu.h>
15839 #include <asm/asm.h>
15840 #include <linux/err.h>
15841 +#include <asm/pgtable.h>
15842 +#include <asm/alternative-asm.h>
15843
15844 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15845 #include <linux/elf-em.h>
15846 @@ -70,8 +72,9 @@
15847 #ifdef CONFIG_FUNCTION_TRACER
15848 #ifdef CONFIG_DYNAMIC_FTRACE
15849 ENTRY(mcount)
15850 + pax_force_retaddr
15851 retq
15852 -END(mcount)
15853 +ENDPROC(mcount)
15854
15855 ENTRY(ftrace_caller)
15856 cmpl $0, function_trace_stop
15857 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15858 #endif
15859
15860 GLOBAL(ftrace_stub)
15861 + pax_force_retaddr
15862 retq
15863 -END(ftrace_caller)
15864 +ENDPROC(ftrace_caller)
15865
15866 #else /* ! CONFIG_DYNAMIC_FTRACE */
15867 ENTRY(mcount)
15868 @@ -114,6 +118,7 @@ ENTRY(mcount)
15869 #endif
15870
15871 GLOBAL(ftrace_stub)
15872 + pax_force_retaddr
15873 retq
15874
15875 trace:
15876 @@ -123,12 +128,13 @@ trace:
15877 movq 8(%rbp), %rsi
15878 subq $MCOUNT_INSN_SIZE, %rdi
15879
15880 + pax_force_fptr ftrace_trace_function
15881 call *ftrace_trace_function
15882
15883 MCOUNT_RESTORE_FRAME
15884
15885 jmp ftrace_stub
15886 -END(mcount)
15887 +ENDPROC(mcount)
15888 #endif /* CONFIG_DYNAMIC_FTRACE */
15889 #endif /* CONFIG_FUNCTION_TRACER */
15890
15891 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15892
15893 MCOUNT_RESTORE_FRAME
15894
15895 + pax_force_retaddr
15896 retq
15897 -END(ftrace_graph_caller)
15898 +ENDPROC(ftrace_graph_caller)
15899
15900 GLOBAL(return_to_handler)
15901 subq $24, %rsp
15902 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15903 movq 8(%rsp), %rdx
15904 movq (%rsp), %rax
15905 addq $24, %rsp
15906 + pax_force_fptr %rdi
15907 jmp *%rdi
15908 #endif
15909
15910 @@ -180,6 +188,273 @@ ENTRY(native_usergs_sysret64)
15911 ENDPROC(native_usergs_sysret64)
15912 #endif /* CONFIG_PARAVIRT */
15913
15914 + .macro ljmpq sel, off
15915 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15916 + .byte 0x48; ljmp *1234f(%rip)
15917 + .pushsection .rodata
15918 + .align 16
15919 + 1234: .quad \off; .word \sel
15920 + .popsection
15921 +#else
15922 + pushq $\sel
15923 + pushq $\off
15924 + lretq
15925 +#endif
15926 + .endm
15927 +
15928 + .macro pax_enter_kernel
15929 + pax_set_fptr_mask
15930 +#ifdef CONFIG_PAX_KERNEXEC
15931 + call pax_enter_kernel
15932 +#endif
15933 + .endm
15934 +
15935 + .macro pax_exit_kernel
15936 +#ifdef CONFIG_PAX_KERNEXEC
15937 + call pax_exit_kernel
15938 +#endif
15939 + .endm
15940 +
15941 +#ifdef CONFIG_PAX_KERNEXEC
15942 +ENTRY(pax_enter_kernel)
15943 + pushq %rdi
15944 +
15945 +#ifdef CONFIG_PARAVIRT
15946 + PV_SAVE_REGS(CLBR_RDI)
15947 +#endif
15948 +
15949 + GET_CR0_INTO_RDI
15950 + bts $16,%rdi
15951 + jnc 3f
15952 + mov %cs,%edi
15953 + cmp $__KERNEL_CS,%edi
15954 + jnz 2f
15955 +1:
15956 +
15957 +#ifdef CONFIG_PARAVIRT
15958 + PV_RESTORE_REGS(CLBR_RDI)
15959 +#endif
15960 +
15961 + popq %rdi
15962 + pax_force_retaddr
15963 + retq
15964 +
15965 +2: ljmpq __KERNEL_CS,1f
15966 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15967 +4: SET_RDI_INTO_CR0
15968 + jmp 1b
15969 +ENDPROC(pax_enter_kernel)
15970 +
15971 +ENTRY(pax_exit_kernel)
15972 + pushq %rdi
15973 +
15974 +#ifdef CONFIG_PARAVIRT
15975 + PV_SAVE_REGS(CLBR_RDI)
15976 +#endif
15977 +
15978 + mov %cs,%rdi
15979 + cmp $__KERNEXEC_KERNEL_CS,%edi
15980 + jz 2f
15981 +1:
15982 +
15983 +#ifdef CONFIG_PARAVIRT
15984 + PV_RESTORE_REGS(CLBR_RDI);
15985 +#endif
15986 +
15987 + popq %rdi
15988 + pax_force_retaddr
15989 + retq
15990 +
15991 +2: GET_CR0_INTO_RDI
15992 + btr $16,%rdi
15993 + ljmpq __KERNEL_CS,3f
15994 +3: SET_RDI_INTO_CR0
15995 + jmp 1b
15996 +ENDPROC(pax_exit_kernel)
15997 +#endif
15998 +
15999 + .macro pax_enter_kernel_user
16000 + pax_set_fptr_mask
16001 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16002 + call pax_enter_kernel_user
16003 +#endif
16004 + .endm
16005 +
16006 + .macro pax_exit_kernel_user
16007 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16008 + call pax_exit_kernel_user
16009 +#endif
16010 +#ifdef CONFIG_PAX_RANDKSTACK
16011 + pushq %rax
16012 + call pax_randomize_kstack
16013 + popq %rax
16014 +#endif
16015 + .endm
16016 +
16017 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16018 +ENTRY(pax_enter_kernel_user)
16019 + pushq %rdi
16020 + pushq %rbx
16021 +
16022 +#ifdef CONFIG_PARAVIRT
16023 + PV_SAVE_REGS(CLBR_RDI)
16024 +#endif
16025 +
16026 + GET_CR3_INTO_RDI
16027 + mov %rdi,%rbx
16028 + add $__START_KERNEL_map,%rbx
16029 + sub phys_base(%rip),%rbx
16030 +
16031 +#ifdef CONFIG_PARAVIRT
16032 + pushq %rdi
16033 + cmpl $0, pv_info+PARAVIRT_enabled
16034 + jz 1f
16035 + i = 0
16036 + .rept USER_PGD_PTRS
16037 + mov i*8(%rbx),%rsi
16038 + mov $0,%sil
16039 + lea i*8(%rbx),%rdi
16040 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16041 + i = i + 1
16042 + .endr
16043 + jmp 2f
16044 +1:
16045 +#endif
16046 +
16047 + i = 0
16048 + .rept USER_PGD_PTRS
16049 + movb $0,i*8(%rbx)
16050 + i = i + 1
16051 + .endr
16052 +
16053 +#ifdef CONFIG_PARAVIRT
16054 +2: popq %rdi
16055 +#endif
16056 + SET_RDI_INTO_CR3
16057 +
16058 +#ifdef CONFIG_PAX_KERNEXEC
16059 + GET_CR0_INTO_RDI
16060 + bts $16,%rdi
16061 + SET_RDI_INTO_CR0
16062 +#endif
16063 +
16064 +#ifdef CONFIG_PARAVIRT
16065 + PV_RESTORE_REGS(CLBR_RDI)
16066 +#endif
16067 +
16068 + popq %rbx
16069 + popq %rdi
16070 + pax_force_retaddr
16071 + retq
16072 +ENDPROC(pax_enter_kernel_user)
16073 +
16074 +ENTRY(pax_exit_kernel_user)
16075 + push %rdi
16076 +
16077 +#ifdef CONFIG_PARAVIRT
16078 + pushq %rbx
16079 + PV_SAVE_REGS(CLBR_RDI)
16080 +#endif
16081 +
16082 +#ifdef CONFIG_PAX_KERNEXEC
16083 + GET_CR0_INTO_RDI
16084 + btr $16,%rdi
16085 + SET_RDI_INTO_CR0
16086 +#endif
16087 +
16088 + GET_CR3_INTO_RDI
16089 + add $__START_KERNEL_map,%rdi
16090 + sub phys_base(%rip),%rdi
16091 +
16092 +#ifdef CONFIG_PARAVIRT
16093 + cmpl $0, pv_info+PARAVIRT_enabled
16094 + jz 1f
16095 + mov %rdi,%rbx
16096 + i = 0
16097 + .rept USER_PGD_PTRS
16098 + mov i*8(%rbx),%rsi
16099 + mov $0x67,%sil
16100 + lea i*8(%rbx),%rdi
16101 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16102 + i = i + 1
16103 + .endr
16104 + jmp 2f
16105 +1:
16106 +#endif
16107 +
16108 + i = 0
16109 + .rept USER_PGD_PTRS
16110 + movb $0x67,i*8(%rdi)
16111 + i = i + 1
16112 + .endr
16113 +
16114 +#ifdef CONFIG_PARAVIRT
16115 +2: PV_RESTORE_REGS(CLBR_RDI)
16116 + popq %rbx
16117 +#endif
16118 +
16119 + popq %rdi
16120 + pax_force_retaddr
16121 + retq
16122 +ENDPROC(pax_exit_kernel_user)
16123 +#endif
16124 +
16125 +.macro pax_erase_kstack
16126 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16127 + call pax_erase_kstack
16128 +#endif
16129 +.endm
16130 +
16131 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16132 +ENTRY(pax_erase_kstack)
16133 + pushq %rdi
16134 + pushq %rcx
16135 + pushq %rax
16136 + pushq %r11
16137 +
16138 + GET_THREAD_INFO(%r11)
16139 + mov TI_lowest_stack(%r11), %rdi
16140 + mov $-0xBEEF, %rax
16141 + std
16142 +
16143 +1: mov %edi, %ecx
16144 + and $THREAD_SIZE_asm - 1, %ecx
16145 + shr $3, %ecx
16146 + repne scasq
16147 + jecxz 2f
16148 +
16149 + cmp $2*8, %ecx
16150 + jc 2f
16151 +
16152 + mov $2*8, %ecx
16153 + repe scasq
16154 + jecxz 2f
16155 + jne 1b
16156 +
16157 +2: cld
16158 + mov %esp, %ecx
16159 + sub %edi, %ecx
16160 +
16161 + cmp $THREAD_SIZE_asm, %rcx
16162 + jb 3f
16163 + ud2
16164 +3:
16165 +
16166 + shr $3, %ecx
16167 + rep stosq
16168 +
16169 + mov TI_task_thread_sp0(%r11), %rdi
16170 + sub $256, %rdi
16171 + mov %rdi, TI_lowest_stack(%r11)
16172 +
16173 + popq %r11
16174 + popq %rax
16175 + popq %rcx
16176 + popq %rdi
16177 + pax_force_retaddr
16178 + ret
16179 +ENDPROC(pax_erase_kstack)
16180 +#endif
16181
16182 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16183 #ifdef CONFIG_TRACE_IRQFLAGS
16184 @@ -271,8 +546,8 @@ ENDPROC(native_usergs_sysret64)
16185 .endm
16186
16187 .macro UNFAKE_STACK_FRAME
16188 - addq $8*6, %rsp
16189 - CFI_ADJUST_CFA_OFFSET -(6*8)
16190 + addq $8*6 + ARG_SKIP, %rsp
16191 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16192 .endm
16193
16194 /*
16195 @@ -359,7 +634,7 @@ ENDPROC(native_usergs_sysret64)
16196 movq %rsp, %rsi
16197
16198 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16199 - testl $3, CS-RBP(%rsi)
16200 + testb $3, CS-RBP(%rsi)
16201 je 1f
16202 SWAPGS
16203 /*
16204 @@ -394,9 +669,10 @@ ENTRY(save_rest)
16205 movq_cfi r15, R15+16
16206 movq %r11, 8(%rsp) /* return address */
16207 FIXUP_TOP_OF_STACK %r11, 16
16208 + pax_force_retaddr
16209 ret
16210 CFI_ENDPROC
16211 -END(save_rest)
16212 +ENDPROC(save_rest)
16213
16214 /* save complete stack frame */
16215 .pushsection .kprobes.text, "ax"
16216 @@ -425,9 +701,10 @@ ENTRY(save_paranoid)
16217 js 1f /* negative -> in kernel */
16218 SWAPGS
16219 xorl %ebx,%ebx
16220 -1: ret
16221 +1: pax_force_retaddr_bts
16222 + ret
16223 CFI_ENDPROC
16224 -END(save_paranoid)
16225 +ENDPROC(save_paranoid)
16226 .popsection
16227
16228 /*
16229 @@ -449,7 +726,7 @@ ENTRY(ret_from_fork)
16230
16231 RESTORE_REST
16232
16233 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16234 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16235 jz retint_restore_args
16236
16237 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16238 @@ -459,7 +736,7 @@ ENTRY(ret_from_fork)
16239 jmp ret_from_sys_call # go to the SYSRET fastpath
16240
16241 CFI_ENDPROC
16242 -END(ret_from_fork)
16243 +ENDPROC(ret_from_fork)
16244
16245 /*
16246 * System call entry. Up to 6 arguments in registers are supported.
16247 @@ -495,7 +772,7 @@ END(ret_from_fork)
16248 ENTRY(system_call)
16249 CFI_STARTPROC simple
16250 CFI_SIGNAL_FRAME
16251 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16252 + CFI_DEF_CFA rsp,0
16253 CFI_REGISTER rip,rcx
16254 /*CFI_REGISTER rflags,r11*/
16255 SWAPGS_UNSAFE_STACK
16256 @@ -508,16 +785,23 @@ GLOBAL(system_call_after_swapgs)
16257
16258 movq %rsp,PER_CPU_VAR(old_rsp)
16259 movq PER_CPU_VAR(kernel_stack),%rsp
16260 + SAVE_ARGS 8*6,0
16261 + pax_enter_kernel_user
16262 +
16263 +#ifdef CONFIG_PAX_RANDKSTACK
16264 + pax_erase_kstack
16265 +#endif
16266 +
16267 /*
16268 * No need to follow this irqs off/on section - it's straight
16269 * and short:
16270 */
16271 ENABLE_INTERRUPTS(CLBR_NONE)
16272 - SAVE_ARGS 8,0
16273 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16274 movq %rcx,RIP-ARGOFFSET(%rsp)
16275 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16276 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16277 + GET_THREAD_INFO(%rcx)
16278 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16279 jnz tracesys
16280 system_call_fastpath:
16281 #if __SYSCALL_MASK == ~0
16282 @@ -527,7 +811,7 @@ system_call_fastpath:
16283 cmpl $__NR_syscall_max,%eax
16284 #endif
16285 ja badsys
16286 - movq %r10,%rcx
16287 + movq R10-ARGOFFSET(%rsp),%rcx
16288 call *sys_call_table(,%rax,8) # XXX: rip relative
16289 movq %rax,RAX-ARGOFFSET(%rsp)
16290 /*
16291 @@ -541,10 +825,13 @@ sysret_check:
16292 LOCKDEP_SYS_EXIT
16293 DISABLE_INTERRUPTS(CLBR_NONE)
16294 TRACE_IRQS_OFF
16295 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16296 + GET_THREAD_INFO(%rcx)
16297 + movl TI_flags(%rcx),%edx
16298 andl %edi,%edx
16299 jnz sysret_careful
16300 CFI_REMEMBER_STATE
16301 + pax_exit_kernel_user
16302 + pax_erase_kstack
16303 /*
16304 * sysretq will re-enable interrupts:
16305 */
16306 @@ -596,14 +883,18 @@ badsys:
16307 * jump back to the normal fast path.
16308 */
16309 auditsys:
16310 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16311 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16312 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16313 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16314 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16315 movq %rax,%rsi /* 2nd arg: syscall number */
16316 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16317 call __audit_syscall_entry
16318 +
16319 + pax_erase_kstack
16320 +
16321 LOAD_ARGS 0 /* reload call-clobbered registers */
16322 + pax_set_fptr_mask
16323 jmp system_call_fastpath
16324
16325 /*
16326 @@ -624,7 +915,7 @@ sysret_audit:
16327 /* Do syscall tracing */
16328 tracesys:
16329 #ifdef CONFIG_AUDITSYSCALL
16330 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16331 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16332 jz auditsys
16333 #endif
16334 SAVE_REST
16335 @@ -632,12 +923,16 @@ tracesys:
16336 FIXUP_TOP_OF_STACK %rdi
16337 movq %rsp,%rdi
16338 call syscall_trace_enter
16339 +
16340 + pax_erase_kstack
16341 +
16342 /*
16343 * Reload arg registers from stack in case ptrace changed them.
16344 * We don't reload %rax because syscall_trace_enter() returned
16345 * the value it wants us to use in the table lookup.
16346 */
16347 LOAD_ARGS ARGOFFSET, 1
16348 + pax_set_fptr_mask
16349 RESTORE_REST
16350 #if __SYSCALL_MASK == ~0
16351 cmpq $__NR_syscall_max,%rax
16352 @@ -646,7 +941,7 @@ tracesys:
16353 cmpl $__NR_syscall_max,%eax
16354 #endif
16355 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16356 - movq %r10,%rcx /* fixup for C */
16357 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16358 call *sys_call_table(,%rax,8)
16359 movq %rax,RAX-ARGOFFSET(%rsp)
16360 /* Use IRET because user could have changed frame */
16361 @@ -667,7 +962,9 @@ GLOBAL(int_with_check)
16362 andl %edi,%edx
16363 jnz int_careful
16364 andl $~TS_COMPAT,TI_status(%rcx)
16365 - jmp retint_swapgs
16366 + pax_exit_kernel_user
16367 + pax_erase_kstack
16368 + jmp retint_swapgs_pax
16369
16370 /* Either reschedule or signal or syscall exit tracking needed. */
16371 /* First do a reschedule test. */
16372 @@ -713,7 +1010,7 @@ int_restore_rest:
16373 TRACE_IRQS_OFF
16374 jmp int_with_check
16375 CFI_ENDPROC
16376 -END(system_call)
16377 +ENDPROC(system_call)
16378
16379 /*
16380 * Certain special system calls that need to save a complete full stack frame.
16381 @@ -729,7 +1026,7 @@ ENTRY(\label)
16382 call \func
16383 jmp ptregscall_common
16384 CFI_ENDPROC
16385 -END(\label)
16386 +ENDPROC(\label)
16387 .endm
16388
16389 PTREGSCALL stub_clone, sys_clone, %r8
16390 @@ -747,9 +1044,10 @@ ENTRY(ptregscall_common)
16391 movq_cfi_restore R12+8, r12
16392 movq_cfi_restore RBP+8, rbp
16393 movq_cfi_restore RBX+8, rbx
16394 + pax_force_retaddr
16395 ret $REST_SKIP /* pop extended registers */
16396 CFI_ENDPROC
16397 -END(ptregscall_common)
16398 +ENDPROC(ptregscall_common)
16399
16400 ENTRY(stub_execve)
16401 CFI_STARTPROC
16402 @@ -764,7 +1062,7 @@ ENTRY(stub_execve)
16403 RESTORE_REST
16404 jmp int_ret_from_sys_call
16405 CFI_ENDPROC
16406 -END(stub_execve)
16407 +ENDPROC(stub_execve)
16408
16409 /*
16410 * sigreturn is special because it needs to restore all registers on return.
16411 @@ -782,7 +1080,7 @@ ENTRY(stub_rt_sigreturn)
16412 RESTORE_REST
16413 jmp int_ret_from_sys_call
16414 CFI_ENDPROC
16415 -END(stub_rt_sigreturn)
16416 +ENDPROC(stub_rt_sigreturn)
16417
16418 #ifdef CONFIG_X86_X32_ABI
16419 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16420 @@ -851,7 +1149,7 @@ vector=vector+1
16421 2: jmp common_interrupt
16422 .endr
16423 CFI_ENDPROC
16424 -END(irq_entries_start)
16425 +ENDPROC(irq_entries_start)
16426
16427 .previous
16428 END(interrupt)
16429 @@ -871,6 +1169,16 @@ END(interrupt)
16430 subq $ORIG_RAX-RBP, %rsp
16431 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16432 SAVE_ARGS_IRQ
16433 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16434 + testb $3, CS(%rdi)
16435 + jnz 1f
16436 + pax_enter_kernel
16437 + jmp 2f
16438 +1: pax_enter_kernel_user
16439 +2:
16440 +#else
16441 + pax_enter_kernel
16442 +#endif
16443 call \func
16444 .endm
16445
16446 @@ -902,7 +1210,7 @@ ret_from_intr:
16447
16448 exit_intr:
16449 GET_THREAD_INFO(%rcx)
16450 - testl $3,CS-ARGOFFSET(%rsp)
16451 + testb $3,CS-ARGOFFSET(%rsp)
16452 je retint_kernel
16453
16454 /* Interrupt came from user space */
16455 @@ -924,12 +1232,16 @@ retint_swapgs: /* return to user-space */
16456 * The iretq could re-enable interrupts:
16457 */
16458 DISABLE_INTERRUPTS(CLBR_ANY)
16459 + pax_exit_kernel_user
16460 +retint_swapgs_pax:
16461 TRACE_IRQS_IRETQ
16462 SWAPGS
16463 jmp restore_args
16464
16465 retint_restore_args: /* return to kernel space */
16466 DISABLE_INTERRUPTS(CLBR_ANY)
16467 + pax_exit_kernel
16468 + pax_force_retaddr RIP-ARGOFFSET
16469 /*
16470 * The iretq could re-enable interrupts:
16471 */
16472 @@ -1012,7 +1324,7 @@ ENTRY(retint_kernel)
16473 #endif
16474
16475 CFI_ENDPROC
16476 -END(common_interrupt)
16477 +ENDPROC(common_interrupt)
16478 /*
16479 * End of kprobes section
16480 */
16481 @@ -1029,7 +1341,7 @@ ENTRY(\sym)
16482 interrupt \do_sym
16483 jmp ret_from_intr
16484 CFI_ENDPROC
16485 -END(\sym)
16486 +ENDPROC(\sym)
16487 .endm
16488
16489 #ifdef CONFIG_SMP
16490 @@ -1084,12 +1396,22 @@ ENTRY(\sym)
16491 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16492 call error_entry
16493 DEFAULT_FRAME 0
16494 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16495 + testb $3, CS(%rsp)
16496 + jnz 1f
16497 + pax_enter_kernel
16498 + jmp 2f
16499 +1: pax_enter_kernel_user
16500 +2:
16501 +#else
16502 + pax_enter_kernel
16503 +#endif
16504 movq %rsp,%rdi /* pt_regs pointer */
16505 xorl %esi,%esi /* no error code */
16506 call \do_sym
16507 jmp error_exit /* %ebx: no swapgs flag */
16508 CFI_ENDPROC
16509 -END(\sym)
16510 +ENDPROC(\sym)
16511 .endm
16512
16513 .macro paranoidzeroentry sym do_sym
16514 @@ -1101,15 +1423,25 @@ ENTRY(\sym)
16515 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16516 call save_paranoid
16517 TRACE_IRQS_OFF
16518 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16519 + testb $3, CS(%rsp)
16520 + jnz 1f
16521 + pax_enter_kernel
16522 + jmp 2f
16523 +1: pax_enter_kernel_user
16524 +2:
16525 +#else
16526 + pax_enter_kernel
16527 +#endif
16528 movq %rsp,%rdi /* pt_regs pointer */
16529 xorl %esi,%esi /* no error code */
16530 call \do_sym
16531 jmp paranoid_exit /* %ebx: no swapgs flag */
16532 CFI_ENDPROC
16533 -END(\sym)
16534 +ENDPROC(\sym)
16535 .endm
16536
16537 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16538 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16539 .macro paranoidzeroentry_ist sym do_sym ist
16540 ENTRY(\sym)
16541 INTR_FRAME
16542 @@ -1119,14 +1451,30 @@ ENTRY(\sym)
16543 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16544 call save_paranoid
16545 TRACE_IRQS_OFF_DEBUG
16546 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16547 + testb $3, CS(%rsp)
16548 + jnz 1f
16549 + pax_enter_kernel
16550 + jmp 2f
16551 +1: pax_enter_kernel_user
16552 +2:
16553 +#else
16554 + pax_enter_kernel
16555 +#endif
16556 movq %rsp,%rdi /* pt_regs pointer */
16557 xorl %esi,%esi /* no error code */
16558 +#ifdef CONFIG_SMP
16559 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16560 + lea init_tss(%r12), %r12
16561 +#else
16562 + lea init_tss(%rip), %r12
16563 +#endif
16564 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16565 call \do_sym
16566 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16567 jmp paranoid_exit /* %ebx: no swapgs flag */
16568 CFI_ENDPROC
16569 -END(\sym)
16570 +ENDPROC(\sym)
16571 .endm
16572
16573 .macro errorentry sym do_sym
16574 @@ -1137,13 +1485,23 @@ ENTRY(\sym)
16575 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16576 call error_entry
16577 DEFAULT_FRAME 0
16578 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16579 + testb $3, CS(%rsp)
16580 + jnz 1f
16581 + pax_enter_kernel
16582 + jmp 2f
16583 +1: pax_enter_kernel_user
16584 +2:
16585 +#else
16586 + pax_enter_kernel
16587 +#endif
16588 movq %rsp,%rdi /* pt_regs pointer */
16589 movq ORIG_RAX(%rsp),%rsi /* get error code */
16590 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16591 call \do_sym
16592 jmp error_exit /* %ebx: no swapgs flag */
16593 CFI_ENDPROC
16594 -END(\sym)
16595 +ENDPROC(\sym)
16596 .endm
16597
16598 /* error code is on the stack already */
16599 @@ -1156,13 +1514,23 @@ ENTRY(\sym)
16600 call save_paranoid
16601 DEFAULT_FRAME 0
16602 TRACE_IRQS_OFF
16603 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16604 + testb $3, CS(%rsp)
16605 + jnz 1f
16606 + pax_enter_kernel
16607 + jmp 2f
16608 +1: pax_enter_kernel_user
16609 +2:
16610 +#else
16611 + pax_enter_kernel
16612 +#endif
16613 movq %rsp,%rdi /* pt_regs pointer */
16614 movq ORIG_RAX(%rsp),%rsi /* get error code */
16615 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16616 call \do_sym
16617 jmp paranoid_exit /* %ebx: no swapgs flag */
16618 CFI_ENDPROC
16619 -END(\sym)
16620 +ENDPROC(\sym)
16621 .endm
16622
16623 zeroentry divide_error do_divide_error
16624 @@ -1192,9 +1560,10 @@ gs_change:
16625 2: mfence /* workaround */
16626 SWAPGS
16627 popfq_cfi
16628 + pax_force_retaddr
16629 ret
16630 CFI_ENDPROC
16631 -END(native_load_gs_index)
16632 +ENDPROC(native_load_gs_index)
16633
16634 _ASM_EXTABLE(gs_change,bad_gs)
16635 .section .fixup,"ax"
16636 @@ -1213,13 +1582,14 @@ ENTRY(kernel_thread_helper)
16637 * Here we are in the child and the registers are set as they were
16638 * at kernel_thread() invocation in the parent.
16639 */
16640 + pax_force_fptr %rsi
16641 call *%rsi
16642 # exit
16643 mov %eax, %edi
16644 call do_exit
16645 ud2 # padding for call trace
16646 CFI_ENDPROC
16647 -END(kernel_thread_helper)
16648 +ENDPROC(kernel_thread_helper)
16649
16650 /*
16651 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16652 @@ -1246,11 +1616,11 @@ ENTRY(kernel_execve)
16653 RESTORE_REST
16654 testq %rax,%rax
16655 je int_ret_from_sys_call
16656 - RESTORE_ARGS
16657 UNFAKE_STACK_FRAME
16658 + pax_force_retaddr
16659 ret
16660 CFI_ENDPROC
16661 -END(kernel_execve)
16662 +ENDPROC(kernel_execve)
16663
16664 /* Call softirq on interrupt stack. Interrupts are off. */
16665 ENTRY(call_softirq)
16666 @@ -1268,9 +1638,10 @@ ENTRY(call_softirq)
16667 CFI_DEF_CFA_REGISTER rsp
16668 CFI_ADJUST_CFA_OFFSET -8
16669 decl PER_CPU_VAR(irq_count)
16670 + pax_force_retaddr
16671 ret
16672 CFI_ENDPROC
16673 -END(call_softirq)
16674 +ENDPROC(call_softirq)
16675
16676 #ifdef CONFIG_XEN
16677 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16678 @@ -1308,7 +1679,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16679 decl PER_CPU_VAR(irq_count)
16680 jmp error_exit
16681 CFI_ENDPROC
16682 -END(xen_do_hypervisor_callback)
16683 +ENDPROC(xen_do_hypervisor_callback)
16684
16685 /*
16686 * Hypervisor uses this for application faults while it executes.
16687 @@ -1367,7 +1738,7 @@ ENTRY(xen_failsafe_callback)
16688 SAVE_ALL
16689 jmp error_exit
16690 CFI_ENDPROC
16691 -END(xen_failsafe_callback)
16692 +ENDPROC(xen_failsafe_callback)
16693
16694 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16695 xen_hvm_callback_vector xen_evtchn_do_upcall
16696 @@ -1416,16 +1787,31 @@ ENTRY(paranoid_exit)
16697 TRACE_IRQS_OFF_DEBUG
16698 testl %ebx,%ebx /* swapgs needed? */
16699 jnz paranoid_restore
16700 - testl $3,CS(%rsp)
16701 + testb $3,CS(%rsp)
16702 jnz paranoid_userspace
16703 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16704 + pax_exit_kernel
16705 + TRACE_IRQS_IRETQ 0
16706 + SWAPGS_UNSAFE_STACK
16707 + RESTORE_ALL 8
16708 + pax_force_retaddr_bts
16709 + jmp irq_return
16710 +#endif
16711 paranoid_swapgs:
16712 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16713 + pax_exit_kernel_user
16714 +#else
16715 + pax_exit_kernel
16716 +#endif
16717 TRACE_IRQS_IRETQ 0
16718 SWAPGS_UNSAFE_STACK
16719 RESTORE_ALL 8
16720 jmp irq_return
16721 paranoid_restore:
16722 + pax_exit_kernel
16723 TRACE_IRQS_IRETQ_DEBUG 0
16724 RESTORE_ALL 8
16725 + pax_force_retaddr_bts
16726 jmp irq_return
16727 paranoid_userspace:
16728 GET_THREAD_INFO(%rcx)
16729 @@ -1454,7 +1840,7 @@ paranoid_schedule:
16730 TRACE_IRQS_OFF
16731 jmp paranoid_userspace
16732 CFI_ENDPROC
16733 -END(paranoid_exit)
16734 +ENDPROC(paranoid_exit)
16735
16736 /*
16737 * Exception entry point. This expects an error code/orig_rax on the stack.
16738 @@ -1481,12 +1867,13 @@ ENTRY(error_entry)
16739 movq_cfi r14, R14+8
16740 movq_cfi r15, R15+8
16741 xorl %ebx,%ebx
16742 - testl $3,CS+8(%rsp)
16743 + testb $3,CS+8(%rsp)
16744 je error_kernelspace
16745 error_swapgs:
16746 SWAPGS
16747 error_sti:
16748 TRACE_IRQS_OFF
16749 + pax_force_retaddr_bts
16750 ret
16751
16752 /*
16753 @@ -1513,7 +1900,7 @@ bstep_iret:
16754 movq %rcx,RIP+8(%rsp)
16755 jmp error_swapgs
16756 CFI_ENDPROC
16757 -END(error_entry)
16758 +ENDPROC(error_entry)
16759
16760
16761 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16762 @@ -1533,7 +1920,7 @@ ENTRY(error_exit)
16763 jnz retint_careful
16764 jmp retint_swapgs
16765 CFI_ENDPROC
16766 -END(error_exit)
16767 +ENDPROC(error_exit)
16768
16769 /*
16770 * Test if a given stack is an NMI stack or not.
16771 @@ -1591,9 +1978,11 @@ ENTRY(nmi)
16772 * If %cs was not the kernel segment, then the NMI triggered in user
16773 * space, which means it is definitely not nested.
16774 */
16775 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16776 + je 1f
16777 cmpl $__KERNEL_CS, 16(%rsp)
16778 jne first_nmi
16779 -
16780 +1:
16781 /*
16782 * Check the special variable on the stack to see if NMIs are
16783 * executing.
16784 @@ -1752,6 +2141,17 @@ end_repeat_nmi:
16785 */
16786 movq %cr2, %r12
16787
16788 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16789 + testb $3, CS(%rsp)
16790 + jnz 1f
16791 + pax_enter_kernel
16792 + jmp 2f
16793 +1: pax_enter_kernel_user
16794 +2:
16795 +#else
16796 + pax_enter_kernel
16797 +#endif
16798 +
16799 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16800 movq %rsp,%rdi
16801 movq $-1,%rsi
16802 @@ -1767,21 +2167,32 @@ end_repeat_nmi:
16803 testl %ebx,%ebx /* swapgs needed? */
16804 jnz nmi_restore
16805 nmi_swapgs:
16806 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16807 + pax_exit_kernel_user
16808 +#else
16809 + pax_exit_kernel
16810 +#endif
16811 SWAPGS_UNSAFE_STACK
16812 + RESTORE_ALL 8
16813 + /* Clear the NMI executing stack variable */
16814 + movq $0, 10*8(%rsp)
16815 + jmp irq_return
16816 nmi_restore:
16817 + pax_exit_kernel
16818 RESTORE_ALL 8
16819 + pax_force_retaddr_bts
16820 /* Clear the NMI executing stack variable */
16821 movq $0, 10*8(%rsp)
16822 jmp irq_return
16823 CFI_ENDPROC
16824 -END(nmi)
16825 +ENDPROC(nmi)
16826
16827 ENTRY(ignore_sysret)
16828 CFI_STARTPROC
16829 mov $-ENOSYS,%eax
16830 sysret
16831 CFI_ENDPROC
16832 -END(ignore_sysret)
16833 +ENDPROC(ignore_sysret)
16834
16835 /*
16836 * End of kprobes section
16837 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16838 index c3a7cb4..3ad00dc 100644
16839 --- a/arch/x86/kernel/ftrace.c
16840 +++ b/arch/x86/kernel/ftrace.c
16841 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16842 {
16843 unsigned char replaced[MCOUNT_INSN_SIZE];
16844
16845 + ip = ktla_ktva(ip);
16846 +
16847 /*
16848 * Note: Due to modules and __init, code can
16849 * disappear and change, we need to protect against faulting
16850 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16851 unsigned char old[MCOUNT_INSN_SIZE], *new;
16852 int ret;
16853
16854 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16855 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16856 new = ftrace_call_replace(ip, (unsigned long)func);
16857
16858 /* See comment above by declaration of modifying_ftrace_code */
16859 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16860 {
16861 unsigned char code[MCOUNT_INSN_SIZE];
16862
16863 + ip = ktla_ktva(ip);
16864 +
16865 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16866 return -EFAULT;
16867
16868 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16869 index c18f59d..9c0c9f6 100644
16870 --- a/arch/x86/kernel/head32.c
16871 +++ b/arch/x86/kernel/head32.c
16872 @@ -18,6 +18,7 @@
16873 #include <asm/io_apic.h>
16874 #include <asm/bios_ebda.h>
16875 #include <asm/tlbflush.h>
16876 +#include <asm/boot.h>
16877
16878 static void __init i386_default_early_setup(void)
16879 {
16880 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16881
16882 void __init i386_start_kernel(void)
16883 {
16884 - memblock_reserve(__pa_symbol(&_text),
16885 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16886 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16887
16888 #ifdef CONFIG_BLK_DEV_INITRD
16889 /* Reserve INITRD */
16890 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16891 index d42ab17..87b9555 100644
16892 --- a/arch/x86/kernel/head_32.S
16893 +++ b/arch/x86/kernel/head_32.S
16894 @@ -26,6 +26,12 @@
16895 /* Physical address */
16896 #define pa(X) ((X) - __PAGE_OFFSET)
16897
16898 +#ifdef CONFIG_PAX_KERNEXEC
16899 +#define ta(X) (X)
16900 +#else
16901 +#define ta(X) ((X) - __PAGE_OFFSET)
16902 +#endif
16903 +
16904 /*
16905 * References to members of the new_cpu_data structure.
16906 */
16907 @@ -55,11 +61,7 @@
16908 * and small than max_low_pfn, otherwise will waste some page table entries
16909 */
16910
16911 -#if PTRS_PER_PMD > 1
16912 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16913 -#else
16914 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16915 -#endif
16916 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16917
16918 /* Number of possible pages in the lowmem region */
16919 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16920 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16921 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16922
16923 /*
16924 + * Real beginning of normal "text" segment
16925 + */
16926 +ENTRY(stext)
16927 +ENTRY(_stext)
16928 +
16929 +/*
16930 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16931 * %esi points to the real-mode code as a 32-bit pointer.
16932 * CS and DS must be 4 GB flat segments, but we don't depend on
16933 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16934 * can.
16935 */
16936 __HEAD
16937 +
16938 +#ifdef CONFIG_PAX_KERNEXEC
16939 + jmp startup_32
16940 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16941 +.fill PAGE_SIZE-5,1,0xcc
16942 +#endif
16943 +
16944 ENTRY(startup_32)
16945 movl pa(stack_start),%ecx
16946
16947 @@ -106,6 +121,59 @@ ENTRY(startup_32)
16948 2:
16949 leal -__PAGE_OFFSET(%ecx),%esp
16950
16951 +#ifdef CONFIG_SMP
16952 + movl $pa(cpu_gdt_table),%edi
16953 + movl $__per_cpu_load,%eax
16954 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
16955 + rorl $16,%eax
16956 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
16957 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
16958 + movl $__per_cpu_end - 1,%eax
16959 + subl $__per_cpu_start,%eax
16960 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
16961 +#endif
16962 +
16963 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16964 + movl $NR_CPUS,%ecx
16965 + movl $pa(cpu_gdt_table),%edi
16966 +1:
16967 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16968 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16969 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16970 + addl $PAGE_SIZE_asm,%edi
16971 + loop 1b
16972 +#endif
16973 +
16974 +#ifdef CONFIG_PAX_KERNEXEC
16975 + movl $pa(boot_gdt),%edi
16976 + movl $__LOAD_PHYSICAL_ADDR,%eax
16977 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
16978 + rorl $16,%eax
16979 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
16980 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
16981 + rorl $16,%eax
16982 +
16983 + ljmp $(__BOOT_CS),$1f
16984 +1:
16985 +
16986 + movl $NR_CPUS,%ecx
16987 + movl $pa(cpu_gdt_table),%edi
16988 + addl $__PAGE_OFFSET,%eax
16989 +1:
16990 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
16991 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
16992 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
16993 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
16994 + rorl $16,%eax
16995 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
16996 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
16997 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
16998 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
16999 + rorl $16,%eax
17000 + addl $PAGE_SIZE_asm,%edi
17001 + loop 1b
17002 +#endif
17003 +
17004 /*
17005 * Clear BSS first so that there are no surprises...
17006 */
17007 @@ -196,8 +264,11 @@ ENTRY(startup_32)
17008 movl %eax, pa(max_pfn_mapped)
17009
17010 /* Do early initialization of the fixmap area */
17011 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17012 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
17013 +#ifdef CONFIG_COMPAT_VDSO
17014 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
17015 +#else
17016 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
17017 +#endif
17018 #else /* Not PAE */
17019
17020 page_pde_offset = (__PAGE_OFFSET >> 20);
17021 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17022 movl %eax, pa(max_pfn_mapped)
17023
17024 /* Do early initialization of the fixmap area */
17025 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17026 - movl %eax,pa(initial_page_table+0xffc)
17027 +#ifdef CONFIG_COMPAT_VDSO
17028 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17029 +#else
17030 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17031 +#endif
17032 #endif
17033
17034 #ifdef CONFIG_PARAVIRT
17035 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17036 cmpl $num_subarch_entries, %eax
17037 jae bad_subarch
17038
17039 - movl pa(subarch_entries)(,%eax,4), %eax
17040 - subl $__PAGE_OFFSET, %eax
17041 - jmp *%eax
17042 + jmp *pa(subarch_entries)(,%eax,4)
17043
17044 bad_subarch:
17045 WEAK(lguest_entry)
17046 @@ -256,10 +328,10 @@ WEAK(xen_entry)
17047 __INITDATA
17048
17049 subarch_entries:
17050 - .long default_entry /* normal x86/PC */
17051 - .long lguest_entry /* lguest hypervisor */
17052 - .long xen_entry /* Xen hypervisor */
17053 - .long default_entry /* Moorestown MID */
17054 + .long ta(default_entry) /* normal x86/PC */
17055 + .long ta(lguest_entry) /* lguest hypervisor */
17056 + .long ta(xen_entry) /* Xen hypervisor */
17057 + .long ta(default_entry) /* Moorestown MID */
17058 num_subarch_entries = (. - subarch_entries) / 4
17059 .previous
17060 #else
17061 @@ -310,6 +382,7 @@ default_entry:
17062 orl %edx,%eax
17063 movl %eax,%cr4
17064
17065 +#ifdef CONFIG_X86_PAE
17066 testb $X86_CR4_PAE, %al # check if PAE is enabled
17067 jz 6f
17068
17069 @@ -338,6 +411,9 @@ default_entry:
17070 /* Make changes effective */
17071 wrmsr
17072
17073 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17074 +#endif
17075 +
17076 6:
17077
17078 /*
17079 @@ -436,14 +512,20 @@ is386: movl $2,%ecx # set MP
17080 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17081 movl %eax,%ss # after changing gdt.
17082
17083 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17084 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17085 movl %eax,%ds
17086 movl %eax,%es
17087
17088 movl $(__KERNEL_PERCPU), %eax
17089 movl %eax,%fs # set this cpu's percpu
17090
17091 +#ifdef CONFIG_CC_STACKPROTECTOR
17092 movl $(__KERNEL_STACK_CANARY),%eax
17093 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17094 + movl $(__USER_DS),%eax
17095 +#else
17096 + xorl %eax,%eax
17097 +#endif
17098 movl %eax,%gs
17099
17100 xorl %eax,%eax # Clear LDT
17101 @@ -520,8 +602,11 @@ setup_once:
17102 * relocation. Manually set base address in stack canary
17103 * segment descriptor.
17104 */
17105 - movl $gdt_page,%eax
17106 + movl $cpu_gdt_table,%eax
17107 movl $stack_canary,%ecx
17108 +#ifdef CONFIG_SMP
17109 + addl $__per_cpu_load,%ecx
17110 +#endif
17111 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17112 shrl $16, %ecx
17113 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17114 @@ -552,7 +637,7 @@ ENDPROC(early_idt_handlers)
17115 /* This is global to keep gas from relaxing the jumps */
17116 ENTRY(early_idt_handler)
17117 cld
17118 - cmpl $2,%ss:early_recursion_flag
17119 + cmpl $1,%ss:early_recursion_flag
17120 je hlt_loop
17121 incl %ss:early_recursion_flag
17122
17123 @@ -590,8 +675,8 @@ ENTRY(early_idt_handler)
17124 pushl (20+6*4)(%esp) /* trapno */
17125 pushl $fault_msg
17126 call printk
17127 -#endif
17128 call dump_stack
17129 +#endif
17130 hlt_loop:
17131 hlt
17132 jmp hlt_loop
17133 @@ -610,8 +695,11 @@ ENDPROC(early_idt_handler)
17134 /* This is the default interrupt "handler" :-) */
17135 ALIGN
17136 ignore_int:
17137 - cld
17138 #ifdef CONFIG_PRINTK
17139 + cmpl $2,%ss:early_recursion_flag
17140 + je hlt_loop
17141 + incl %ss:early_recursion_flag
17142 + cld
17143 pushl %eax
17144 pushl %ecx
17145 pushl %edx
17146 @@ -620,9 +708,6 @@ ignore_int:
17147 movl $(__KERNEL_DS),%eax
17148 movl %eax,%ds
17149 movl %eax,%es
17150 - cmpl $2,early_recursion_flag
17151 - je hlt_loop
17152 - incl early_recursion_flag
17153 pushl 16(%esp)
17154 pushl 24(%esp)
17155 pushl 32(%esp)
17156 @@ -656,29 +741,43 @@ ENTRY(setup_once_ref)
17157 /*
17158 * BSS section
17159 */
17160 -__PAGE_ALIGNED_BSS
17161 - .align PAGE_SIZE
17162 #ifdef CONFIG_X86_PAE
17163 +.section .initial_pg_pmd,"a",@progbits
17164 initial_pg_pmd:
17165 .fill 1024*KPMDS,4,0
17166 #else
17167 +.section .initial_page_table,"a",@progbits
17168 ENTRY(initial_page_table)
17169 .fill 1024,4,0
17170 #endif
17171 +.section .initial_pg_fixmap,"a",@progbits
17172 initial_pg_fixmap:
17173 .fill 1024,4,0
17174 +.section .empty_zero_page,"a",@progbits
17175 ENTRY(empty_zero_page)
17176 .fill 4096,1,0
17177 +.section .swapper_pg_dir,"a",@progbits
17178 ENTRY(swapper_pg_dir)
17179 +#ifdef CONFIG_X86_PAE
17180 + .fill 4,8,0
17181 +#else
17182 .fill 1024,4,0
17183 +#endif
17184 +
17185 +/*
17186 + * The IDT has to be page-aligned to simplify the Pentium
17187 + * F0 0F bug workaround.. We have a special link segment
17188 + * for this.
17189 + */
17190 +.section .idt,"a",@progbits
17191 +ENTRY(idt_table)
17192 + .fill 256,8,0
17193
17194 /*
17195 * This starts the data section.
17196 */
17197 #ifdef CONFIG_X86_PAE
17198 -__PAGE_ALIGNED_DATA
17199 - /* Page-aligned for the benefit of paravirt? */
17200 - .align PAGE_SIZE
17201 +.section .initial_page_table,"a",@progbits
17202 ENTRY(initial_page_table)
17203 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17204 # if KPMDS == 3
17205 @@ -697,12 +796,20 @@ ENTRY(initial_page_table)
17206 # error "Kernel PMDs should be 1, 2 or 3"
17207 # endif
17208 .align PAGE_SIZE /* needs to be page-sized too */
17209 +
17210 +#ifdef CONFIG_PAX_PER_CPU_PGD
17211 +ENTRY(cpu_pgd)
17212 + .rept NR_CPUS
17213 + .fill 4,8,0
17214 + .endr
17215 +#endif
17216 +
17217 #endif
17218
17219 .data
17220 .balign 4
17221 ENTRY(stack_start)
17222 - .long init_thread_union+THREAD_SIZE
17223 + .long init_thread_union+THREAD_SIZE-8
17224
17225 __INITRODATA
17226 int_msg:
17227 @@ -730,7 +837,7 @@ fault_msg:
17228 * segment size, and 32-bit linear address value:
17229 */
17230
17231 - .data
17232 +.section .rodata,"a",@progbits
17233 .globl boot_gdt_descr
17234 .globl idt_descr
17235
17236 @@ -739,7 +846,7 @@ fault_msg:
17237 .word 0 # 32 bit align gdt_desc.address
17238 boot_gdt_descr:
17239 .word __BOOT_DS+7
17240 - .long boot_gdt - __PAGE_OFFSET
17241 + .long pa(boot_gdt)
17242
17243 .word 0 # 32-bit align idt_desc.address
17244 idt_descr:
17245 @@ -750,7 +857,7 @@ idt_descr:
17246 .word 0 # 32 bit align gdt_desc.address
17247 ENTRY(early_gdt_descr)
17248 .word GDT_ENTRIES*8-1
17249 - .long gdt_page /* Overwritten for secondary CPUs */
17250 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17251
17252 /*
17253 * The boot_gdt must mirror the equivalent in setup.S and is
17254 @@ -759,5 +866,65 @@ ENTRY(early_gdt_descr)
17255 .align L1_CACHE_BYTES
17256 ENTRY(boot_gdt)
17257 .fill GDT_ENTRY_BOOT_CS,8,0
17258 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17259 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17260 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17261 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17262 +
17263 + .align PAGE_SIZE_asm
17264 +ENTRY(cpu_gdt_table)
17265 + .rept NR_CPUS
17266 + .quad 0x0000000000000000 /* NULL descriptor */
17267 + .quad 0x0000000000000000 /* 0x0b reserved */
17268 + .quad 0x0000000000000000 /* 0x13 reserved */
17269 + .quad 0x0000000000000000 /* 0x1b reserved */
17270 +
17271 +#ifdef CONFIG_PAX_KERNEXEC
17272 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17273 +#else
17274 + .quad 0x0000000000000000 /* 0x20 unused */
17275 +#endif
17276 +
17277 + .quad 0x0000000000000000 /* 0x28 unused */
17278 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17279 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17280 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17281 + .quad 0x0000000000000000 /* 0x4b reserved */
17282 + .quad 0x0000000000000000 /* 0x53 reserved */
17283 + .quad 0x0000000000000000 /* 0x5b reserved */
17284 +
17285 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17286 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17287 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17288 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17289 +
17290 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17291 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17292 +
17293 + /*
17294 + * Segments used for calling PnP BIOS have byte granularity.
17295 + * The code segments and data segments have fixed 64k limits,
17296 + * the transfer segment sizes are set at run time.
17297 + */
17298 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17299 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17300 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17301 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17302 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17303 +
17304 + /*
17305 + * The APM segments have byte granularity and their bases
17306 + * are set at run time. All have 64k limits.
17307 + */
17308 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17309 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17310 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17311 +
17312 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17313 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17314 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17315 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17316 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17317 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17318 +
17319 + /* Be sure this is zeroed to avoid false validations in Xen */
17320 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17321 + .endr
17322 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17323 index 94bf9cc..400455a 100644
17324 --- a/arch/x86/kernel/head_64.S
17325 +++ b/arch/x86/kernel/head_64.S
17326 @@ -20,6 +20,8 @@
17327 #include <asm/processor-flags.h>
17328 #include <asm/percpu.h>
17329 #include <asm/nops.h>
17330 +#include <asm/cpufeature.h>
17331 +#include <asm/alternative-asm.h>
17332
17333 #ifdef CONFIG_PARAVIRT
17334 #include <asm/asm-offsets.h>
17335 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17336 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17337 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17338 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17339 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17340 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17341 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17342 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17343 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17344 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17345
17346 .text
17347 __HEAD
17348 @@ -88,35 +96,23 @@ startup_64:
17349 */
17350 addq %rbp, init_level4_pgt + 0(%rip)
17351 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17352 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17353 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17354 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17355 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17356
17357 addq %rbp, level3_ident_pgt + 0(%rip)
17358 +#ifndef CONFIG_XEN
17359 + addq %rbp, level3_ident_pgt + 8(%rip)
17360 +#endif
17361
17362 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17363 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17364 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17365 +
17366 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17367 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17368
17369 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17370 -
17371 - /* Add an Identity mapping if I am above 1G */
17372 - leaq _text(%rip), %rdi
17373 - andq $PMD_PAGE_MASK, %rdi
17374 -
17375 - movq %rdi, %rax
17376 - shrq $PUD_SHIFT, %rax
17377 - andq $(PTRS_PER_PUD - 1), %rax
17378 - jz ident_complete
17379 -
17380 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17381 - leaq level3_ident_pgt(%rip), %rbx
17382 - movq %rdx, 0(%rbx, %rax, 8)
17383 -
17384 - movq %rdi, %rax
17385 - shrq $PMD_SHIFT, %rax
17386 - andq $(PTRS_PER_PMD - 1), %rax
17387 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17388 - leaq level2_spare_pgt(%rip), %rbx
17389 - movq %rdx, 0(%rbx, %rax, 8)
17390 -ident_complete:
17391 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17392
17393 /*
17394 * Fixup the kernel text+data virtual addresses. Note that
17395 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17396 * after the boot processor executes this code.
17397 */
17398
17399 - /* Enable PAE mode and PGE */
17400 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17401 + /* Enable PAE mode and PSE/PGE */
17402 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17403 movq %rax, %cr4
17404
17405 /* Setup early boot stage 4 level pagetables. */
17406 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17407 movl $MSR_EFER, %ecx
17408 rdmsr
17409 btsl $_EFER_SCE, %eax /* Enable System Call */
17410 - btl $20,%edi /* No Execute supported? */
17411 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17412 jnc 1f
17413 btsl $_EFER_NX, %eax
17414 + leaq init_level4_pgt(%rip), %rdi
17415 +#ifndef CONFIG_EFI
17416 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17417 +#endif
17418 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17419 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17420 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17421 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17422 1: wrmsr /* Make changes effective */
17423
17424 /* Setup cr0 */
17425 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17426 * jump. In addition we need to ensure %cs is set so we make this
17427 * a far return.
17428 */
17429 + pax_set_fptr_mask
17430 movq initial_code(%rip),%rax
17431 pushq $0 # fake return address to stop unwinder
17432 pushq $__KERNEL_CS # set correct cs
17433 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17434 bad_address:
17435 jmp bad_address
17436
17437 - .section ".init.text","ax"
17438 + __INIT
17439 .globl early_idt_handlers
17440 early_idt_handlers:
17441 # 104(%rsp) %rflags
17442 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17443 addq $16,%rsp # drop vector number and error code
17444 decl early_recursion_flag(%rip)
17445 INTERRUPT_RETURN
17446 + .previous
17447
17448 + __INITDATA
17449 .balign 4
17450 early_recursion_flag:
17451 .long 0
17452 + .previous
17453
17454 + .section .rodata,"a",@progbits
17455 #ifdef CONFIG_EARLY_PRINTK
17456 early_idt_msg:
17457 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17458 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17459 #endif /* CONFIG_EARLY_PRINTK */
17460 .previous
17461
17462 + .section .rodata,"a",@progbits
17463 #define NEXT_PAGE(name) \
17464 .balign PAGE_SIZE; \
17465 ENTRY(name)
17466 @@ -372,7 +382,6 @@ ENTRY(name)
17467 i = i + 1 ; \
17468 .endr
17469
17470 - .data
17471 /*
17472 * This default setting generates an ident mapping at address 0x100000
17473 * and a mapping for the kernel that precisely maps virtual address
17474 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17475 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17476 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17477 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17478 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17479 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17480 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17481 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17482 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17483 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17484 .org init_level4_pgt + L4_START_KERNEL*8, 0
17485 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17486 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17487
17488 +#ifdef CONFIG_PAX_PER_CPU_PGD
17489 +NEXT_PAGE(cpu_pgd)
17490 + .rept NR_CPUS
17491 + .fill 512,8,0
17492 + .endr
17493 +#endif
17494 +
17495 NEXT_PAGE(level3_ident_pgt)
17496 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17497 +#ifdef CONFIG_XEN
17498 .fill 511,8,0
17499 +#else
17500 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17501 + .fill 510,8,0
17502 +#endif
17503 +
17504 +NEXT_PAGE(level3_vmalloc_start_pgt)
17505 + .fill 512,8,0
17506 +
17507 +NEXT_PAGE(level3_vmalloc_end_pgt)
17508 + .fill 512,8,0
17509 +
17510 +NEXT_PAGE(level3_vmemmap_pgt)
17511 + .fill L3_VMEMMAP_START,8,0
17512 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17513
17514 NEXT_PAGE(level3_kernel_pgt)
17515 .fill L3_START_KERNEL,8,0
17516 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17517 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17518 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17519
17520 +NEXT_PAGE(level2_vmemmap_pgt)
17521 + .fill 512,8,0
17522 +
17523 NEXT_PAGE(level2_fixmap_pgt)
17524 - .fill 506,8,0
17525 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17526 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17527 - .fill 5,8,0
17528 + .fill 507,8,0
17529 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17530 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17531 + .fill 4,8,0
17532
17533 -NEXT_PAGE(level1_fixmap_pgt)
17534 +NEXT_PAGE(level1_vsyscall_pgt)
17535 .fill 512,8,0
17536
17537 -NEXT_PAGE(level2_ident_pgt)
17538 - /* Since I easily can, map the first 1G.
17539 + /* Since I easily can, map the first 2G.
17540 * Don't set NX because code runs from these pages.
17541 */
17542 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17543 +NEXT_PAGE(level2_ident_pgt)
17544 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17545
17546 NEXT_PAGE(level2_kernel_pgt)
17547 /*
17548 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17549 * If you want to increase this then increase MODULES_VADDR
17550 * too.)
17551 */
17552 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17553 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17554 -
17555 -NEXT_PAGE(level2_spare_pgt)
17556 - .fill 512, 8, 0
17557 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17558
17559 #undef PMDS
17560 #undef NEXT_PAGE
17561
17562 - .data
17563 + .align PAGE_SIZE
17564 +ENTRY(cpu_gdt_table)
17565 + .rept NR_CPUS
17566 + .quad 0x0000000000000000 /* NULL descriptor */
17567 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17568 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17569 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17570 + .quad 0x00cffb000000ffff /* __USER32_CS */
17571 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17572 + .quad 0x00affb000000ffff /* __USER_CS */
17573 +
17574 +#ifdef CONFIG_PAX_KERNEXEC
17575 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17576 +#else
17577 + .quad 0x0 /* unused */
17578 +#endif
17579 +
17580 + .quad 0,0 /* TSS */
17581 + .quad 0,0 /* LDT */
17582 + .quad 0,0,0 /* three TLS descriptors */
17583 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17584 + /* asm/segment.h:GDT_ENTRIES must match this */
17585 +
17586 + /* zero the remaining page */
17587 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17588 + .endr
17589 +
17590 .align 16
17591 .globl early_gdt_descr
17592 early_gdt_descr:
17593 .word GDT_ENTRIES*8-1
17594 early_gdt_descr_base:
17595 - .quad INIT_PER_CPU_VAR(gdt_page)
17596 + .quad cpu_gdt_table
17597
17598 ENTRY(phys_base)
17599 /* This must match the first entry in level2_kernel_pgt */
17600 .quad 0x0000000000000000
17601
17602 #include "../../x86/xen/xen-head.S"
17603 -
17604 - .section .bss, "aw", @nobits
17605 +
17606 + .section .rodata,"a",@progbits
17607 .align L1_CACHE_BYTES
17608 ENTRY(idt_table)
17609 - .skip IDT_ENTRIES * 16
17610 + .fill 512,8,0
17611
17612 .align L1_CACHE_BYTES
17613 ENTRY(nmi_idt_table)
17614 - .skip IDT_ENTRIES * 16
17615 + .fill 512,8,0
17616
17617 __PAGE_ALIGNED_BSS
17618 .align PAGE_SIZE
17619 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17620 index 9c3bd4a..e1d9b35 100644
17621 --- a/arch/x86/kernel/i386_ksyms_32.c
17622 +++ b/arch/x86/kernel/i386_ksyms_32.c
17623 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17624 EXPORT_SYMBOL(cmpxchg8b_emu);
17625 #endif
17626
17627 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17628 +
17629 /* Networking helper routines. */
17630 EXPORT_SYMBOL(csum_partial_copy_generic);
17631 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17632 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17633
17634 EXPORT_SYMBOL(__get_user_1);
17635 EXPORT_SYMBOL(__get_user_2);
17636 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17637
17638 EXPORT_SYMBOL(csum_partial);
17639 EXPORT_SYMBOL(empty_zero_page);
17640 +
17641 +#ifdef CONFIG_PAX_KERNEXEC
17642 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17643 +#endif
17644 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17645 index f250431..54097e7 100644
17646 --- a/arch/x86/kernel/i387.c
17647 +++ b/arch/x86/kernel/i387.c
17648 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17649 static inline bool interrupted_user_mode(void)
17650 {
17651 struct pt_regs *regs = get_irq_regs();
17652 - return regs && user_mode_vm(regs);
17653 + return regs && user_mode(regs);
17654 }
17655
17656 /*
17657 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17658 index 36d1853..bf25736 100644
17659 --- a/arch/x86/kernel/i8259.c
17660 +++ b/arch/x86/kernel/i8259.c
17661 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17662 "spurious 8259A interrupt: IRQ%d.\n", irq);
17663 spurious_irq_mask |= irqmask;
17664 }
17665 - atomic_inc(&irq_err_count);
17666 + atomic_inc_unchecked(&irq_err_count);
17667 /*
17668 * Theoretically we do not have to handle this IRQ,
17669 * but in Linux this does not cause problems and is
17670 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17671 index 8c96897..be66bfa 100644
17672 --- a/arch/x86/kernel/ioport.c
17673 +++ b/arch/x86/kernel/ioport.c
17674 @@ -6,6 +6,7 @@
17675 #include <linux/sched.h>
17676 #include <linux/kernel.h>
17677 #include <linux/capability.h>
17678 +#include <linux/security.h>
17679 #include <linux/errno.h>
17680 #include <linux/types.h>
17681 #include <linux/ioport.h>
17682 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17683
17684 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17685 return -EINVAL;
17686 +#ifdef CONFIG_GRKERNSEC_IO
17687 + if (turn_on && grsec_disable_privio) {
17688 + gr_handle_ioperm();
17689 + return -EPERM;
17690 + }
17691 +#endif
17692 if (turn_on && !capable(CAP_SYS_RAWIO))
17693 return -EPERM;
17694
17695 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17696 * because the ->io_bitmap_max value must match the bitmap
17697 * contents:
17698 */
17699 - tss = &per_cpu(init_tss, get_cpu());
17700 + tss = init_tss + get_cpu();
17701
17702 if (turn_on)
17703 bitmap_clear(t->io_bitmap_ptr, from, num);
17704 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17705 return -EINVAL;
17706 /* Trying to gain more privileges? */
17707 if (level > old) {
17708 +#ifdef CONFIG_GRKERNSEC_IO
17709 + if (grsec_disable_privio) {
17710 + gr_handle_iopl();
17711 + return -EPERM;
17712 + }
17713 +#endif
17714 if (!capable(CAP_SYS_RAWIO))
17715 return -EPERM;
17716 }
17717 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17718 index d44f782..31ab01e 100644
17719 --- a/arch/x86/kernel/irq.c
17720 +++ b/arch/x86/kernel/irq.c
17721 @@ -18,7 +18,7 @@
17722 #include <asm/mce.h>
17723 #include <asm/hw_irq.h>
17724
17725 -atomic_t irq_err_count;
17726 +atomic_unchecked_t irq_err_count;
17727
17728 /* Function pointer for generic interrupt vector handling */
17729 void (*x86_platform_ipi_callback)(void) = NULL;
17730 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17731 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17732 seq_printf(p, " Machine check polls\n");
17733 #endif
17734 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17735 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17736 #if defined(CONFIG_X86_IO_APIC)
17737 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17738 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17739 #endif
17740 return 0;
17741 }
17742 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17743
17744 u64 arch_irq_stat(void)
17745 {
17746 - u64 sum = atomic_read(&irq_err_count);
17747 + u64 sum = atomic_read_unchecked(&irq_err_count);
17748
17749 #ifdef CONFIG_X86_IO_APIC
17750 - sum += atomic_read(&irq_mis_count);
17751 + sum += atomic_read_unchecked(&irq_mis_count);
17752 #endif
17753 return sum;
17754 }
17755 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17756 index 344faf8..355f60d 100644
17757 --- a/arch/x86/kernel/irq_32.c
17758 +++ b/arch/x86/kernel/irq_32.c
17759 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17760 __asm__ __volatile__("andl %%esp,%0" :
17761 "=r" (sp) : "0" (THREAD_SIZE - 1));
17762
17763 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17764 + return sp < STACK_WARN;
17765 }
17766
17767 static void print_stack_overflow(void)
17768 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17769 * per-CPU IRQ handling contexts (thread information and stack)
17770 */
17771 union irq_ctx {
17772 - struct thread_info tinfo;
17773 - u32 stack[THREAD_SIZE/sizeof(u32)];
17774 + unsigned long previous_esp;
17775 + u32 stack[THREAD_SIZE/sizeof(u32)];
17776 } __attribute__((aligned(THREAD_SIZE)));
17777
17778 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17779 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17780 static inline int
17781 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17782 {
17783 - union irq_ctx *curctx, *irqctx;
17784 + union irq_ctx *irqctx;
17785 u32 *isp, arg1, arg2;
17786
17787 - curctx = (union irq_ctx *) current_thread_info();
17788 irqctx = __this_cpu_read(hardirq_ctx);
17789
17790 /*
17791 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17792 * handler) we can't do that and just have to keep using the
17793 * current stack (which is the irq stack already after all)
17794 */
17795 - if (unlikely(curctx == irqctx))
17796 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17797 return 0;
17798
17799 /* build the stack frame on the IRQ stack */
17800 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17801 - irqctx->tinfo.task = curctx->tinfo.task;
17802 - irqctx->tinfo.previous_esp = current_stack_pointer;
17803 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17804 + irqctx->previous_esp = current_stack_pointer;
17805
17806 - /* Copy the preempt_count so that the [soft]irq checks work. */
17807 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17808 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17809 + __set_fs(MAKE_MM_SEG(0));
17810 +#endif
17811
17812 if (unlikely(overflow))
17813 call_on_stack(print_stack_overflow, isp);
17814 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17815 : "0" (irq), "1" (desc), "2" (isp),
17816 "D" (desc->handle_irq)
17817 : "memory", "cc", "ecx");
17818 +
17819 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17820 + __set_fs(current_thread_info()->addr_limit);
17821 +#endif
17822 +
17823 return 1;
17824 }
17825
17826 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17827 */
17828 void __cpuinit irq_ctx_init(int cpu)
17829 {
17830 - union irq_ctx *irqctx;
17831 -
17832 if (per_cpu(hardirq_ctx, cpu))
17833 return;
17834
17835 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17836 - THREADINFO_GFP,
17837 - THREAD_SIZE_ORDER));
17838 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17839 - irqctx->tinfo.cpu = cpu;
17840 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17841 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17842 -
17843 - per_cpu(hardirq_ctx, cpu) = irqctx;
17844 -
17845 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17846 - THREADINFO_GFP,
17847 - THREAD_SIZE_ORDER));
17848 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17849 - irqctx->tinfo.cpu = cpu;
17850 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17851 -
17852 - per_cpu(softirq_ctx, cpu) = irqctx;
17853 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17854 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17855 +
17856 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17857 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17858
17859 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17860 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17861 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17862 asmlinkage void do_softirq(void)
17863 {
17864 unsigned long flags;
17865 - struct thread_info *curctx;
17866 union irq_ctx *irqctx;
17867 u32 *isp;
17868
17869 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17870 local_irq_save(flags);
17871
17872 if (local_softirq_pending()) {
17873 - curctx = current_thread_info();
17874 irqctx = __this_cpu_read(softirq_ctx);
17875 - irqctx->tinfo.task = curctx->task;
17876 - irqctx->tinfo.previous_esp = current_stack_pointer;
17877 + irqctx->previous_esp = current_stack_pointer;
17878
17879 /* build the stack frame on the softirq stack */
17880 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17881 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17882 +
17883 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17884 + __set_fs(MAKE_MM_SEG(0));
17885 +#endif
17886
17887 call_on_stack(__do_softirq, isp);
17888 +
17889 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17890 + __set_fs(current_thread_info()->addr_limit);
17891 +#endif
17892 +
17893 /*
17894 * Shouldn't happen, we returned above if in_interrupt():
17895 */
17896 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17897 if (unlikely(!desc))
17898 return false;
17899
17900 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17901 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17902 if (unlikely(overflow))
17903 print_stack_overflow();
17904 desc->handle_irq(irq, desc);
17905 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17906 index d04d3ec..ea4b374 100644
17907 --- a/arch/x86/kernel/irq_64.c
17908 +++ b/arch/x86/kernel/irq_64.c
17909 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17910 u64 estack_top, estack_bottom;
17911 u64 curbase = (u64)task_stack_page(current);
17912
17913 - if (user_mode_vm(regs))
17914 + if (user_mode(regs))
17915 return;
17916
17917 if (regs->sp >= curbase + sizeof(struct thread_info) +
17918 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17919 index dc1404b..bbc43e7 100644
17920 --- a/arch/x86/kernel/kdebugfs.c
17921 +++ b/arch/x86/kernel/kdebugfs.c
17922 @@ -27,7 +27,7 @@ struct setup_data_node {
17923 u32 len;
17924 };
17925
17926 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17927 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17928 size_t count, loff_t *ppos)
17929 {
17930 struct setup_data_node *node = file->private_data;
17931 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17932 index 3f61904..873cea9 100644
17933 --- a/arch/x86/kernel/kgdb.c
17934 +++ b/arch/x86/kernel/kgdb.c
17935 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17936 #ifdef CONFIG_X86_32
17937 switch (regno) {
17938 case GDB_SS:
17939 - if (!user_mode_vm(regs))
17940 + if (!user_mode(regs))
17941 *(unsigned long *)mem = __KERNEL_DS;
17942 break;
17943 case GDB_SP:
17944 - if (!user_mode_vm(regs))
17945 + if (!user_mode(regs))
17946 *(unsigned long *)mem = kernel_stack_pointer(regs);
17947 break;
17948 case GDB_GS:
17949 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17950 case 'k':
17951 /* clear the trace bit */
17952 linux_regs->flags &= ~X86_EFLAGS_TF;
17953 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17954 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17955
17956 /* set the trace bit if we're stepping */
17957 if (remcomInBuffer[0] == 's') {
17958 linux_regs->flags |= X86_EFLAGS_TF;
17959 - atomic_set(&kgdb_cpu_doing_single_step,
17960 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17961 raw_smp_processor_id());
17962 }
17963
17964 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17965
17966 switch (cmd) {
17967 case DIE_DEBUG:
17968 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17969 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17970 if (user_mode(regs))
17971 return single_step_cont(regs, args);
17972 break;
17973 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17974 index c5e410e..da6aaf9 100644
17975 --- a/arch/x86/kernel/kprobes-opt.c
17976 +++ b/arch/x86/kernel/kprobes-opt.c
17977 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17978 * Verify if the address gap is in 2GB range, because this uses
17979 * a relative jump.
17980 */
17981 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17982 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17983 if (abs(rel) > 0x7fffffff)
17984 return -ERANGE;
17985
17986 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17987 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17988
17989 /* Set probe function call */
17990 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17991 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17992
17993 /* Set returning jmp instruction at the tail of out-of-line buffer */
17994 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17995 - (u8 *)op->kp.addr + op->optinsn.size);
17996 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17997
17998 flush_icache_range((unsigned long) buf,
17999 (unsigned long) buf + TMPL_END_IDX +
18000 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
18001 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
18002
18003 /* Backup instructions which will be replaced by jump address */
18004 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
18005 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
18006 RELATIVE_ADDR_SIZE);
18007
18008 insn_buf[0] = RELATIVEJUMP_OPCODE;
18009 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
18010 index e2f751e..dffa2a0 100644
18011 --- a/arch/x86/kernel/kprobes.c
18012 +++ b/arch/x86/kernel/kprobes.c
18013 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
18014 } __attribute__((packed)) *insn;
18015
18016 insn = (struct __arch_relative_insn *)from;
18017 +
18018 + pax_open_kernel();
18019 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
18020 insn->op = op;
18021 + pax_close_kernel();
18022 }
18023
18024 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
18025 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
18026 kprobe_opcode_t opcode;
18027 kprobe_opcode_t *orig_opcodes = opcodes;
18028
18029 - if (search_exception_tables((unsigned long)opcodes))
18030 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18031 return 0; /* Page fault may occur on this address. */
18032
18033 retry:
18034 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18035 /* Another subsystem puts a breakpoint, failed to recover */
18036 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
18037 return 0;
18038 + pax_open_kernel();
18039 memcpy(dest, insn.kaddr, insn.length);
18040 + pax_close_kernel();
18041
18042 #ifdef CONFIG_X86_64
18043 if (insn_rip_relative(&insn)) {
18044 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18045 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
18046 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18047 disp = (u8 *) dest + insn_offset_displacement(&insn);
18048 + pax_open_kernel();
18049 *(s32 *) disp = (s32) newdisp;
18050 + pax_close_kernel();
18051 }
18052 #endif
18053 return insn.length;
18054 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18055 * nor set current_kprobe, because it doesn't use single
18056 * stepping.
18057 */
18058 - regs->ip = (unsigned long)p->ainsn.insn;
18059 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18060 preempt_enable_no_resched();
18061 return;
18062 }
18063 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18064 if (p->opcode == BREAKPOINT_INSTRUCTION)
18065 regs->ip = (unsigned long)p->addr;
18066 else
18067 - regs->ip = (unsigned long)p->ainsn.insn;
18068 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18069 }
18070
18071 /*
18072 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18073 setup_singlestep(p, regs, kcb, 0);
18074 return 1;
18075 }
18076 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18077 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18078 /*
18079 * The breakpoint instruction was removed right
18080 * after we hit it. Another cpu has removed
18081 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18082 " movq %rax, 152(%rsp)\n"
18083 RESTORE_REGS_STRING
18084 " popfq\n"
18085 +#ifdef KERNEXEC_PLUGIN
18086 + " btsq $63,(%rsp)\n"
18087 +#endif
18088 #else
18089 " pushf\n"
18090 SAVE_REGS_STRING
18091 @@ -765,7 +775,7 @@ static void __kprobes
18092 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18093 {
18094 unsigned long *tos = stack_addr(regs);
18095 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18096 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18097 unsigned long orig_ip = (unsigned long)p->addr;
18098 kprobe_opcode_t *insn = p->ainsn.insn;
18099
18100 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18101 struct die_args *args = data;
18102 int ret = NOTIFY_DONE;
18103
18104 - if (args->regs && user_mode_vm(args->regs))
18105 + if (args->regs && user_mode(args->regs))
18106 return ret;
18107
18108 switch (val) {
18109 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18110 index ebc9873..1b9724b 100644
18111 --- a/arch/x86/kernel/ldt.c
18112 +++ b/arch/x86/kernel/ldt.c
18113 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18114 if (reload) {
18115 #ifdef CONFIG_SMP
18116 preempt_disable();
18117 - load_LDT(pc);
18118 + load_LDT_nolock(pc);
18119 if (!cpumask_equal(mm_cpumask(current->mm),
18120 cpumask_of(smp_processor_id())))
18121 smp_call_function(flush_ldt, current->mm, 1);
18122 preempt_enable();
18123 #else
18124 - load_LDT(pc);
18125 + load_LDT_nolock(pc);
18126 #endif
18127 }
18128 if (oldsize) {
18129 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18130 return err;
18131
18132 for (i = 0; i < old->size; i++)
18133 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18134 + write_ldt_entry(new->ldt, i, old->ldt + i);
18135 return 0;
18136 }
18137
18138 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18139 retval = copy_ldt(&mm->context, &old_mm->context);
18140 mutex_unlock(&old_mm->context.lock);
18141 }
18142 +
18143 + if (tsk == current) {
18144 + mm->context.vdso = 0;
18145 +
18146 +#ifdef CONFIG_X86_32
18147 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18148 + mm->context.user_cs_base = 0UL;
18149 + mm->context.user_cs_limit = ~0UL;
18150 +
18151 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18152 + cpus_clear(mm->context.cpu_user_cs_mask);
18153 +#endif
18154 +
18155 +#endif
18156 +#endif
18157 +
18158 + }
18159 +
18160 return retval;
18161 }
18162
18163 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18164 }
18165 }
18166
18167 +#ifdef CONFIG_PAX_SEGMEXEC
18168 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18169 + error = -EINVAL;
18170 + goto out_unlock;
18171 + }
18172 +#endif
18173 +
18174 fill_ldt(&ldt, &ldt_info);
18175 if (oldmode)
18176 ldt.avl = 0;
18177 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18178 index 5b19e4d..6476a76 100644
18179 --- a/arch/x86/kernel/machine_kexec_32.c
18180 +++ b/arch/x86/kernel/machine_kexec_32.c
18181 @@ -26,7 +26,7 @@
18182 #include <asm/cacheflush.h>
18183 #include <asm/debugreg.h>
18184
18185 -static void set_idt(void *newidt, __u16 limit)
18186 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18187 {
18188 struct desc_ptr curidt;
18189
18190 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18191 }
18192
18193
18194 -static void set_gdt(void *newgdt, __u16 limit)
18195 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18196 {
18197 struct desc_ptr curgdt;
18198
18199 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18200 }
18201
18202 control_page = page_address(image->control_code_page);
18203 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18204 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18205
18206 relocate_kernel_ptr = control_page;
18207 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18208 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18209 index 0327e2b..e43737b 100644
18210 --- a/arch/x86/kernel/microcode_intel.c
18211 +++ b/arch/x86/kernel/microcode_intel.c
18212 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18213
18214 static int get_ucode_user(void *to, const void *from, size_t n)
18215 {
18216 - return copy_from_user(to, from, n);
18217 + return copy_from_user(to, (const void __force_user *)from, n);
18218 }
18219
18220 static enum ucode_state
18221 request_microcode_user(int cpu, const void __user *buf, size_t size)
18222 {
18223 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18224 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18225 }
18226
18227 static void microcode_fini_cpu(int cpu)
18228 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18229 index 216a4d7..b328f09 100644
18230 --- a/arch/x86/kernel/module.c
18231 +++ b/arch/x86/kernel/module.c
18232 @@ -43,15 +43,60 @@ do { \
18233 } while (0)
18234 #endif
18235
18236 -void *module_alloc(unsigned long size)
18237 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18238 {
18239 - if (PAGE_ALIGN(size) > MODULES_LEN)
18240 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18241 return NULL;
18242 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18243 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18244 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18245 -1, __builtin_return_address(0));
18246 }
18247
18248 +void *module_alloc(unsigned long size)
18249 +{
18250 +
18251 +#ifdef CONFIG_PAX_KERNEXEC
18252 + return __module_alloc(size, PAGE_KERNEL);
18253 +#else
18254 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18255 +#endif
18256 +
18257 +}
18258 +
18259 +#ifdef CONFIG_PAX_KERNEXEC
18260 +#ifdef CONFIG_X86_32
18261 +void *module_alloc_exec(unsigned long size)
18262 +{
18263 + struct vm_struct *area;
18264 +
18265 + if (size == 0)
18266 + return NULL;
18267 +
18268 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18269 + return area ? area->addr : NULL;
18270 +}
18271 +EXPORT_SYMBOL(module_alloc_exec);
18272 +
18273 +void module_free_exec(struct module *mod, void *module_region)
18274 +{
18275 + vunmap(module_region);
18276 +}
18277 +EXPORT_SYMBOL(module_free_exec);
18278 +#else
18279 +void module_free_exec(struct module *mod, void *module_region)
18280 +{
18281 + module_free(mod, module_region);
18282 +}
18283 +EXPORT_SYMBOL(module_free_exec);
18284 +
18285 +void *module_alloc_exec(unsigned long size)
18286 +{
18287 + return __module_alloc(size, PAGE_KERNEL_RX);
18288 +}
18289 +EXPORT_SYMBOL(module_alloc_exec);
18290 +#endif
18291 +#endif
18292 +
18293 #ifdef CONFIG_X86_32
18294 int apply_relocate(Elf32_Shdr *sechdrs,
18295 const char *strtab,
18296 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18297 unsigned int i;
18298 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18299 Elf32_Sym *sym;
18300 - uint32_t *location;
18301 + uint32_t *plocation, location;
18302
18303 DEBUGP("Applying relocate section %u to %u\n",
18304 relsec, sechdrs[relsec].sh_info);
18305 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18306 /* This is where to make the change */
18307 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18308 - + rel[i].r_offset;
18309 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18310 + location = (uint32_t)plocation;
18311 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18312 + plocation = ktla_ktva((void *)plocation);
18313 /* This is the symbol it is referring to. Note that all
18314 undefined symbols have been resolved. */
18315 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18316 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18317 switch (ELF32_R_TYPE(rel[i].r_info)) {
18318 case R_386_32:
18319 /* We add the value into the location given */
18320 - *location += sym->st_value;
18321 + pax_open_kernel();
18322 + *plocation += sym->st_value;
18323 + pax_close_kernel();
18324 break;
18325 case R_386_PC32:
18326 /* Add the value, subtract its position */
18327 - *location += sym->st_value - (uint32_t)location;
18328 + pax_open_kernel();
18329 + *plocation += sym->st_value - location;
18330 + pax_close_kernel();
18331 break;
18332 default:
18333 pr_err("%s: Unknown relocation: %u\n",
18334 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18335 case R_X86_64_NONE:
18336 break;
18337 case R_X86_64_64:
18338 + pax_open_kernel();
18339 *(u64 *)loc = val;
18340 + pax_close_kernel();
18341 break;
18342 case R_X86_64_32:
18343 + pax_open_kernel();
18344 *(u32 *)loc = val;
18345 + pax_close_kernel();
18346 if (val != *(u32 *)loc)
18347 goto overflow;
18348 break;
18349 case R_X86_64_32S:
18350 + pax_open_kernel();
18351 *(s32 *)loc = val;
18352 + pax_close_kernel();
18353 if ((s64)val != *(s32 *)loc)
18354 goto overflow;
18355 break;
18356 case R_X86_64_PC32:
18357 val -= (u64)loc;
18358 + pax_open_kernel();
18359 *(u32 *)loc = val;
18360 + pax_close_kernel();
18361 +
18362 #if 0
18363 if ((s64)val != *(s32 *)loc)
18364 goto overflow;
18365 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18366 index f84f5c5..e27e54b 100644
18367 --- a/arch/x86/kernel/nmi.c
18368 +++ b/arch/x86/kernel/nmi.c
18369 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18370 dotraplinkage notrace __kprobes void
18371 do_nmi(struct pt_regs *regs, long error_code)
18372 {
18373 +
18374 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18375 + if (!user_mode(regs)) {
18376 + unsigned long cs = regs->cs & 0xFFFF;
18377 + unsigned long ip = ktva_ktla(regs->ip);
18378 +
18379 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18380 + regs->ip = ip;
18381 + }
18382 +#endif
18383 +
18384 nmi_nesting_preprocess(regs);
18385
18386 nmi_enter();
18387 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18388 index 676b8c7..870ba04 100644
18389 --- a/arch/x86/kernel/paravirt-spinlocks.c
18390 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18391 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18392 arch_spin_lock(lock);
18393 }
18394
18395 -struct pv_lock_ops pv_lock_ops = {
18396 +struct pv_lock_ops pv_lock_ops __read_only = {
18397 #ifdef CONFIG_SMP
18398 .spin_is_locked = __ticket_spin_is_locked,
18399 .spin_is_contended = __ticket_spin_is_contended,
18400 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18401 index 17fff18..7bb2088 100644
18402 --- a/arch/x86/kernel/paravirt.c
18403 +++ b/arch/x86/kernel/paravirt.c
18404 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18405 {
18406 return x;
18407 }
18408 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18409 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18410 +#endif
18411
18412 void __init default_banner(void)
18413 {
18414 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18415 if (opfunc == NULL)
18416 /* If there's no function, patch it with a ud2a (BUG) */
18417 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18418 - else if (opfunc == _paravirt_nop)
18419 + else if (opfunc == (void *)_paravirt_nop)
18420 /* If the operation is a nop, then nop the callsite */
18421 ret = paravirt_patch_nop();
18422
18423 /* identity functions just return their single argument */
18424 - else if (opfunc == _paravirt_ident_32)
18425 + else if (opfunc == (void *)_paravirt_ident_32)
18426 ret = paravirt_patch_ident_32(insnbuf, len);
18427 - else if (opfunc == _paravirt_ident_64)
18428 + else if (opfunc == (void *)_paravirt_ident_64)
18429 ret = paravirt_patch_ident_64(insnbuf, len);
18430 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18431 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18432 + ret = paravirt_patch_ident_64(insnbuf, len);
18433 +#endif
18434
18435 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18436 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18437 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18438 if (insn_len > len || start == NULL)
18439 insn_len = len;
18440 else
18441 - memcpy(insnbuf, start, insn_len);
18442 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18443
18444 return insn_len;
18445 }
18446 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18447 preempt_enable();
18448 }
18449
18450 -struct pv_info pv_info = {
18451 +struct pv_info pv_info __read_only = {
18452 .name = "bare hardware",
18453 .paravirt_enabled = 0,
18454 .kernel_rpl = 0,
18455 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18456 #endif
18457 };
18458
18459 -struct pv_init_ops pv_init_ops = {
18460 +struct pv_init_ops pv_init_ops __read_only = {
18461 .patch = native_patch,
18462 };
18463
18464 -struct pv_time_ops pv_time_ops = {
18465 +struct pv_time_ops pv_time_ops __read_only = {
18466 .sched_clock = native_sched_clock,
18467 .steal_clock = native_steal_clock,
18468 };
18469
18470 -struct pv_irq_ops pv_irq_ops = {
18471 +struct pv_irq_ops pv_irq_ops __read_only = {
18472 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18473 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18474 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18475 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18476 #endif
18477 };
18478
18479 -struct pv_cpu_ops pv_cpu_ops = {
18480 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18481 .cpuid = native_cpuid,
18482 .get_debugreg = native_get_debugreg,
18483 .set_debugreg = native_set_debugreg,
18484 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18485 .end_context_switch = paravirt_nop,
18486 };
18487
18488 -struct pv_apic_ops pv_apic_ops = {
18489 +struct pv_apic_ops pv_apic_ops __read_only = {
18490 #ifdef CONFIG_X86_LOCAL_APIC
18491 .startup_ipi_hook = paravirt_nop,
18492 #endif
18493 };
18494
18495 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18496 +#ifdef CONFIG_X86_32
18497 +#ifdef CONFIG_X86_PAE
18498 +/* 64-bit pagetable entries */
18499 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18500 +#else
18501 /* 32-bit pagetable entries */
18502 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18503 +#endif
18504 #else
18505 /* 64-bit pagetable entries */
18506 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18507 #endif
18508
18509 -struct pv_mmu_ops pv_mmu_ops = {
18510 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18511
18512 .read_cr2 = native_read_cr2,
18513 .write_cr2 = native_write_cr2,
18514 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18515 .make_pud = PTE_IDENT,
18516
18517 .set_pgd = native_set_pgd,
18518 + .set_pgd_batched = native_set_pgd_batched,
18519 #endif
18520 #endif /* PAGETABLE_LEVELS >= 3 */
18521
18522 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18523 },
18524
18525 .set_fixmap = native_set_fixmap,
18526 +
18527 +#ifdef CONFIG_PAX_KERNEXEC
18528 + .pax_open_kernel = native_pax_open_kernel,
18529 + .pax_close_kernel = native_pax_close_kernel,
18530 +#endif
18531 +
18532 };
18533
18534 EXPORT_SYMBOL_GPL(pv_time_ops);
18535 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18536 index 35ccf75..7a15747 100644
18537 --- a/arch/x86/kernel/pci-iommu_table.c
18538 +++ b/arch/x86/kernel/pci-iommu_table.c
18539 @@ -2,7 +2,7 @@
18540 #include <asm/iommu_table.h>
18541 #include <linux/string.h>
18542 #include <linux/kallsyms.h>
18543 -
18544 +#include <linux/sched.h>
18545
18546 #define DEBUG 1
18547
18548 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18549 index ef6a845..8028ed3 100644
18550 --- a/arch/x86/kernel/process.c
18551 +++ b/arch/x86/kernel/process.c
18552 @@ -36,7 +36,8 @@
18553 * section. Since TSS's are completely CPU-local, we want them
18554 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18555 */
18556 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18557 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18558 +EXPORT_SYMBOL(init_tss);
18559
18560 #ifdef CONFIG_X86_64
18561 static DEFINE_PER_CPU(unsigned char, is_idle);
18562 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18563 task_xstate_cachep =
18564 kmem_cache_create("task_xstate", xstate_size,
18565 __alignof__(union thread_xstate),
18566 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18567 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18568 }
18569
18570 static inline void drop_fpu(struct task_struct *tsk)
18571 @@ -117,7 +118,7 @@ void exit_thread(void)
18572 unsigned long *bp = t->io_bitmap_ptr;
18573
18574 if (bp) {
18575 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18576 + struct tss_struct *tss = init_tss + get_cpu();
18577
18578 t->io_bitmap_ptr = NULL;
18579 clear_thread_flag(TIF_IO_BITMAP);
18580 @@ -148,7 +149,7 @@ void show_regs_common(void)
18581 board = dmi_get_system_info(DMI_BOARD_NAME);
18582
18583 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18584 - current->pid, current->comm, print_tainted(),
18585 + task_pid_nr(current), current->comm, print_tainted(),
18586 init_utsname()->release,
18587 (int)strcspn(init_utsname()->version, " "),
18588 init_utsname()->version,
18589 @@ -161,6 +162,9 @@ void flush_thread(void)
18590 {
18591 struct task_struct *tsk = current;
18592
18593 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18594 + loadsegment(gs, 0);
18595 +#endif
18596 flush_ptrace_hw_breakpoint(tsk);
18597 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18598 drop_fpu(tsk);
18599 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18600 regs.di = (unsigned long) arg;
18601
18602 #ifdef CONFIG_X86_32
18603 - regs.ds = __USER_DS;
18604 - regs.es = __USER_DS;
18605 + regs.ds = __KERNEL_DS;
18606 + regs.es = __KERNEL_DS;
18607 regs.fs = __KERNEL_PERCPU;
18608 - regs.gs = __KERNEL_STACK_CANARY;
18609 + savesegment(gs, regs.gs);
18610 #else
18611 regs.ss = __KERNEL_DS;
18612 #endif
18613 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18614 void exit_idle(void)
18615 {
18616 /* idle loop has pid 0 */
18617 - if (current->pid)
18618 + if (task_pid_nr(current))
18619 return;
18620 __exit_idle();
18621 }
18622 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18623
18624 return ret;
18625 }
18626 -void stop_this_cpu(void *dummy)
18627 +__noreturn void stop_this_cpu(void *dummy)
18628 {
18629 local_irq_disable();
18630 /*
18631 @@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18632 }
18633 early_param("idle", idle_setup);
18634
18635 -unsigned long arch_align_stack(unsigned long sp)
18636 +#ifdef CONFIG_PAX_RANDKSTACK
18637 +void pax_randomize_kstack(struct pt_regs *regs)
18638 {
18639 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18640 - sp -= get_random_int() % 8192;
18641 - return sp & ~0xf;
18642 -}
18643 + struct thread_struct *thread = &current->thread;
18644 + unsigned long time;
18645
18646 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18647 -{
18648 - unsigned long range_end = mm->brk + 0x02000000;
18649 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18650 -}
18651 + if (!randomize_va_space)
18652 + return;
18653 +
18654 + if (v8086_mode(regs))
18655 + return;
18656
18657 + rdtscl(time);
18658 +
18659 + /* P4 seems to return a 0 LSB, ignore it */
18660 +#ifdef CONFIG_MPENTIUM4
18661 + time &= 0x3EUL;
18662 + time <<= 2;
18663 +#elif defined(CONFIG_X86_64)
18664 + time &= 0xFUL;
18665 + time <<= 4;
18666 +#else
18667 + time &= 0x1FUL;
18668 + time <<= 3;
18669 +#endif
18670 +
18671 + thread->sp0 ^= time;
18672 + load_sp0(init_tss + smp_processor_id(), thread);
18673 +
18674 +#ifdef CONFIG_X86_64
18675 + this_cpu_write(kernel_stack, thread->sp0);
18676 +#endif
18677 +}
18678 +#endif
18679 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18680 index 516fa18..80bd9e6 100644
18681 --- a/arch/x86/kernel/process_32.c
18682 +++ b/arch/x86/kernel/process_32.c
18683 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18684 unsigned long thread_saved_pc(struct task_struct *tsk)
18685 {
18686 return ((unsigned long *)tsk->thread.sp)[3];
18687 +//XXX return tsk->thread.eip;
18688 }
18689
18690 void __show_regs(struct pt_regs *regs, int all)
18691 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18692 unsigned long sp;
18693 unsigned short ss, gs;
18694
18695 - if (user_mode_vm(regs)) {
18696 + if (user_mode(regs)) {
18697 sp = regs->sp;
18698 ss = regs->ss & 0xffff;
18699 - gs = get_user_gs(regs);
18700 } else {
18701 sp = kernel_stack_pointer(regs);
18702 savesegment(ss, ss);
18703 - savesegment(gs, gs);
18704 }
18705 + gs = get_user_gs(regs);
18706
18707 show_regs_common();
18708
18709 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18710 struct task_struct *tsk;
18711 int err;
18712
18713 - childregs = task_pt_regs(p);
18714 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18715 *childregs = *regs;
18716 childregs->ax = 0;
18717 childregs->sp = sp;
18718
18719 p->thread.sp = (unsigned long) childregs;
18720 p->thread.sp0 = (unsigned long) (childregs+1);
18721 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18722
18723 p->thread.ip = (unsigned long) ret_from_fork;
18724
18725 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18726 struct thread_struct *prev = &prev_p->thread,
18727 *next = &next_p->thread;
18728 int cpu = smp_processor_id();
18729 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18730 + struct tss_struct *tss = init_tss + cpu;
18731 fpu_switch_t fpu;
18732
18733 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18734 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18735 */
18736 lazy_save_gs(prev->gs);
18737
18738 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18739 + __set_fs(task_thread_info(next_p)->addr_limit);
18740 +#endif
18741 +
18742 /*
18743 * Load the per-thread Thread-Local Storage descriptor.
18744 */
18745 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18746 */
18747 arch_end_context_switch(next_p);
18748
18749 + this_cpu_write(current_task, next_p);
18750 + this_cpu_write(current_tinfo, &next_p->tinfo);
18751 +
18752 /*
18753 * Restore %gs if needed (which is common)
18754 */
18755 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18756
18757 switch_fpu_finish(next_p, fpu);
18758
18759 - this_cpu_write(current_task, next_p);
18760 -
18761 return prev_p;
18762 }
18763
18764 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18765 } while (count++ < 16);
18766 return 0;
18767 }
18768 -
18769 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18770 index 0a980c9..1d0e689 100644
18771 --- a/arch/x86/kernel/process_64.c
18772 +++ b/arch/x86/kernel/process_64.c
18773 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18774 struct pt_regs *childregs;
18775 struct task_struct *me = current;
18776
18777 - childregs = ((struct pt_regs *)
18778 - (THREAD_SIZE + task_stack_page(p))) - 1;
18779 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18780 *childregs = *regs;
18781
18782 childregs->ax = 0;
18783 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18784 p->thread.sp = (unsigned long) childregs;
18785 p->thread.sp0 = (unsigned long) (childregs+1);
18786 p->thread.usersp = me->thread.usersp;
18787 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18788
18789 set_tsk_thread_flag(p, TIF_FORK);
18790
18791 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18792 struct thread_struct *prev = &prev_p->thread;
18793 struct thread_struct *next = &next_p->thread;
18794 int cpu = smp_processor_id();
18795 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18796 + struct tss_struct *tss = init_tss + cpu;
18797 unsigned fsindex, gsindex;
18798 fpu_switch_t fpu;
18799
18800 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18801 prev->usersp = this_cpu_read(old_rsp);
18802 this_cpu_write(old_rsp, next->usersp);
18803 this_cpu_write(current_task, next_p);
18804 + this_cpu_write(current_tinfo, &next_p->tinfo);
18805
18806 - this_cpu_write(kernel_stack,
18807 - (unsigned long)task_stack_page(next_p) +
18808 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18809 + this_cpu_write(kernel_stack, next->sp0);
18810
18811 /*
18812 * Now maybe reload the debug registers and handle I/O bitmaps
18813 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18814 if (!p || p == current || p->state == TASK_RUNNING)
18815 return 0;
18816 stack = (unsigned long)task_stack_page(p);
18817 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18818 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18819 return 0;
18820 fp = *(u64 *)(p->thread.sp);
18821 do {
18822 - if (fp < (unsigned long)stack ||
18823 - fp >= (unsigned long)stack+THREAD_SIZE)
18824 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18825 return 0;
18826 ip = *(u64 *)(fp+8);
18827 if (!in_sched_functions(ip))
18828 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18829 index c4c6a5c..905f440 100644
18830 --- a/arch/x86/kernel/ptrace.c
18831 +++ b/arch/x86/kernel/ptrace.c
18832 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18833 unsigned long addr, unsigned long data)
18834 {
18835 int ret;
18836 - unsigned long __user *datap = (unsigned long __user *)data;
18837 + unsigned long __user *datap = (__force unsigned long __user *)data;
18838
18839 switch (request) {
18840 /* read the word at location addr in the USER area. */
18841 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18842 if ((int) addr < 0)
18843 return -EIO;
18844 ret = do_get_thread_area(child, addr,
18845 - (struct user_desc __user *)data);
18846 + (__force struct user_desc __user *) data);
18847 break;
18848
18849 case PTRACE_SET_THREAD_AREA:
18850 if ((int) addr < 0)
18851 return -EIO;
18852 ret = do_set_thread_area(child, addr,
18853 - (struct user_desc __user *)data, 0);
18854 + (__force struct user_desc __user *) data, 0);
18855 break;
18856 #endif
18857
18858 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18859 memset(info, 0, sizeof(*info));
18860 info->si_signo = SIGTRAP;
18861 info->si_code = si_code;
18862 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18863 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18864 }
18865
18866 void user_single_step_siginfo(struct task_struct *tsk,
18867 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18868 # define IS_IA32 0
18869 #endif
18870
18871 +#ifdef CONFIG_GRKERNSEC_SETXID
18872 +extern void gr_delayed_cred_worker(void);
18873 +#endif
18874 +
18875 /*
18876 * We must return the syscall number to actually look up in the table.
18877 * This can be -1L to skip running any syscall at all.
18878 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18879 {
18880 long ret = 0;
18881
18882 +#ifdef CONFIG_GRKERNSEC_SETXID
18883 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18884 + gr_delayed_cred_worker();
18885 +#endif
18886 +
18887 /*
18888 * If we stepped into a sysenter/syscall insn, it trapped in
18889 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18890 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18891 {
18892 bool step;
18893
18894 +#ifdef CONFIG_GRKERNSEC_SETXID
18895 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18896 + gr_delayed_cred_worker();
18897 +#endif
18898 +
18899 audit_syscall_exit(regs);
18900
18901 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18902 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18903 index 42eb330..139955c 100644
18904 --- a/arch/x86/kernel/pvclock.c
18905 +++ b/arch/x86/kernel/pvclock.c
18906 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18907 return pv_tsc_khz;
18908 }
18909
18910 -static atomic64_t last_value = ATOMIC64_INIT(0);
18911 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18912
18913 void pvclock_resume(void)
18914 {
18915 - atomic64_set(&last_value, 0);
18916 + atomic64_set_unchecked(&last_value, 0);
18917 }
18918
18919 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18920 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18921 * updating at the same time, and one of them could be slightly behind,
18922 * making the assumption that last_value always go forward fail to hold.
18923 */
18924 - last = atomic64_read(&last_value);
18925 + last = atomic64_read_unchecked(&last_value);
18926 do {
18927 if (ret < last)
18928 return last;
18929 - last = atomic64_cmpxchg(&last_value, last, ret);
18930 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18931 } while (unlikely(last != ret));
18932
18933 return ret;
18934 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18935 index 52190a9..8074389 100644
18936 --- a/arch/x86/kernel/reboot.c
18937 +++ b/arch/x86/kernel/reboot.c
18938 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18939 EXPORT_SYMBOL(pm_power_off);
18940
18941 static const struct desc_ptr no_idt = {};
18942 -static int reboot_mode;
18943 +static unsigned short reboot_mode;
18944 enum reboot_type reboot_type = BOOT_ACPI;
18945 int reboot_force;
18946
18947 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18948
18949 void __noreturn machine_real_restart(unsigned int type)
18950 {
18951 +
18952 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18953 + struct desc_struct *gdt;
18954 +#endif
18955 +
18956 local_irq_disable();
18957
18958 /*
18959 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18960
18961 /* Jump to the identity-mapped low memory code */
18962 #ifdef CONFIG_X86_32
18963 - asm volatile("jmpl *%0" : :
18964 +
18965 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18966 + gdt = get_cpu_gdt_table(smp_processor_id());
18967 + pax_open_kernel();
18968 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18969 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18970 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18971 + loadsegment(ds, __KERNEL_DS);
18972 + loadsegment(es, __KERNEL_DS);
18973 + loadsegment(ss, __KERNEL_DS);
18974 +#endif
18975 +#ifdef CONFIG_PAX_KERNEXEC
18976 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18977 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18978 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18979 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18980 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18981 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18982 +#endif
18983 + pax_close_kernel();
18984 +#endif
18985 +
18986 + asm volatile("ljmpl *%0" : :
18987 "rm" (real_mode_header->machine_real_restart_asm),
18988 "a" (type));
18989 #else
18990 @@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18991 * try to force a triple fault and then cycle between hitting the keyboard
18992 * controller and doing that
18993 */
18994 -static void native_machine_emergency_restart(void)
18995 +static void __noreturn native_machine_emergency_restart(void)
18996 {
18997 int i;
18998 int attempt = 0;
18999 @@ -662,13 +689,13 @@ void native_machine_shutdown(void)
19000 #endif
19001 }
19002
19003 -static void __machine_emergency_restart(int emergency)
19004 +static void __noreturn __machine_emergency_restart(int emergency)
19005 {
19006 reboot_emergency = emergency;
19007 machine_ops.emergency_restart();
19008 }
19009
19010 -static void native_machine_restart(char *__unused)
19011 +static void __noreturn native_machine_restart(char *__unused)
19012 {
19013 pr_notice("machine restart\n");
19014
19015 @@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
19016 __machine_emergency_restart(0);
19017 }
19018
19019 -static void native_machine_halt(void)
19020 +static void __noreturn native_machine_halt(void)
19021 {
19022 /* Stop other cpus and apics */
19023 machine_shutdown();
19024 @@ -687,7 +714,7 @@ static void native_machine_halt(void)
19025 stop_this_cpu(NULL);
19026 }
19027
19028 -static void native_machine_power_off(void)
19029 +static void __noreturn native_machine_power_off(void)
19030 {
19031 if (pm_power_off) {
19032 if (!reboot_force)
19033 @@ -696,6 +723,7 @@ static void native_machine_power_off(void)
19034 }
19035 /* A fallback in case there is no PM info available */
19036 tboot_shutdown(TB_SHUTDOWN_HALT);
19037 + unreachable();
19038 }
19039
19040 struct machine_ops machine_ops = {
19041 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19042 index 7a6f3b3..bed145d7 100644
19043 --- a/arch/x86/kernel/relocate_kernel_64.S
19044 +++ b/arch/x86/kernel/relocate_kernel_64.S
19045 @@ -11,6 +11,7 @@
19046 #include <asm/kexec.h>
19047 #include <asm/processor-flags.h>
19048 #include <asm/pgtable_types.h>
19049 +#include <asm/alternative-asm.h>
19050
19051 /*
19052 * Must be relocatable PIC code callable as a C function
19053 @@ -160,13 +161,14 @@ identity_mapped:
19054 xorq %rbp, %rbp
19055 xorq %r8, %r8
19056 xorq %r9, %r9
19057 - xorq %r10, %r9
19058 + xorq %r10, %r10
19059 xorq %r11, %r11
19060 xorq %r12, %r12
19061 xorq %r13, %r13
19062 xorq %r14, %r14
19063 xorq %r15, %r15
19064
19065 + pax_force_retaddr 0, 1
19066 ret
19067
19068 1:
19069 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19070 index 5cee802..bc22bc3 100644
19071 --- a/arch/x86/kernel/setup.c
19072 +++ b/arch/x86/kernel/setup.c
19073 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19074
19075 switch (data->type) {
19076 case SETUP_E820_EXT:
19077 - parse_e820_ext(data);
19078 + parse_e820_ext((struct setup_data __force_kernel *)data);
19079 break;
19080 case SETUP_DTB:
19081 add_dtb(pa_data);
19082 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19083 * area (640->1Mb) as ram even though it is not.
19084 * take them out.
19085 */
19086 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19087 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19088 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19089 }
19090
19091 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19092
19093 if (!boot_params.hdr.root_flags)
19094 root_mountflags &= ~MS_RDONLY;
19095 - init_mm.start_code = (unsigned long) _text;
19096 - init_mm.end_code = (unsigned long) _etext;
19097 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19098 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19099 init_mm.end_data = (unsigned long) _edata;
19100 init_mm.brk = _brk_end;
19101
19102 - code_resource.start = virt_to_phys(_text);
19103 - code_resource.end = virt_to_phys(_etext)-1;
19104 - data_resource.start = virt_to_phys(_etext);
19105 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19106 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19107 + data_resource.start = virt_to_phys(_sdata);
19108 data_resource.end = virt_to_phys(_edata)-1;
19109 bss_resource.start = virt_to_phys(&__bss_start);
19110 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19111 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19112 index 5cdff03..5810740 100644
19113 --- a/arch/x86/kernel/setup_percpu.c
19114 +++ b/arch/x86/kernel/setup_percpu.c
19115 @@ -21,19 +21,17 @@
19116 #include <asm/cpu.h>
19117 #include <asm/stackprotector.h>
19118
19119 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19120 +#ifdef CONFIG_SMP
19121 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19122 EXPORT_PER_CPU_SYMBOL(cpu_number);
19123 +#endif
19124
19125 -#ifdef CONFIG_X86_64
19126 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19127 -#else
19128 -#define BOOT_PERCPU_OFFSET 0
19129 -#endif
19130
19131 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19132 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19133
19134 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19135 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19136 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19137 };
19138 EXPORT_SYMBOL(__per_cpu_offset);
19139 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19140 {
19141 #ifdef CONFIG_X86_32
19142 struct desc_struct gdt;
19143 + unsigned long base = per_cpu_offset(cpu);
19144
19145 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19146 - 0x2 | DESCTYPE_S, 0x8);
19147 - gdt.s = 1;
19148 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19149 + 0x83 | DESCTYPE_S, 0xC);
19150 write_gdt_entry(get_cpu_gdt_table(cpu),
19151 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19152 #endif
19153 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19154 /* alrighty, percpu areas up and running */
19155 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19156 for_each_possible_cpu(cpu) {
19157 +#ifdef CONFIG_CC_STACKPROTECTOR
19158 +#ifdef CONFIG_X86_32
19159 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19160 +#endif
19161 +#endif
19162 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19163 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19164 per_cpu(cpu_number, cpu) = cpu;
19165 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19166 */
19167 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19168 #endif
19169 +#ifdef CONFIG_CC_STACKPROTECTOR
19170 +#ifdef CONFIG_X86_32
19171 + if (!cpu)
19172 + per_cpu(stack_canary.canary, cpu) = canary;
19173 +#endif
19174 +#endif
19175 /*
19176 * Up to this point, the boot CPU has been using .init.data
19177 * area. Reload any changed state for the boot CPU.
19178 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19179 index b280908..6de349e 100644
19180 --- a/arch/x86/kernel/signal.c
19181 +++ b/arch/x86/kernel/signal.c
19182 @@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19183 * Align the stack pointer according to the i386 ABI,
19184 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19185 */
19186 - sp = ((sp + 4) & -16ul) - 4;
19187 + sp = ((sp - 12) & -16ul) - 4;
19188 #else /* !CONFIG_X86_32 */
19189 sp = round_down(sp, 16) - 8;
19190 #endif
19191 @@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19192 * Return an always-bogus address instead so we will die with SIGSEGV.
19193 */
19194 if (onsigstack && !likely(on_sig_stack(sp)))
19195 - return (void __user *)-1L;
19196 + return (__force void __user *)-1L;
19197
19198 /* save i387 state */
19199 if (used_math() && save_i387_xstate(*fpstate) < 0)
19200 - return (void __user *)-1L;
19201 + return (__force void __user *)-1L;
19202
19203 return (void __user *)sp;
19204 }
19205 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19206 }
19207
19208 if (current->mm->context.vdso)
19209 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19210 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19211 else
19212 - restorer = &frame->retcode;
19213 + restorer = (void __user *)&frame->retcode;
19214 if (ka->sa.sa_flags & SA_RESTORER)
19215 restorer = ka->sa.sa_restorer;
19216
19217 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19218 * reasons and because gdb uses it as a signature to notice
19219 * signal handler stack frames.
19220 */
19221 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19222 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19223
19224 if (err)
19225 return -EFAULT;
19226 @@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19227 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19228
19229 /* Set up to return from userspace. */
19230 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19231 + if (current->mm->context.vdso)
19232 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19233 + else
19234 + restorer = (void __user *)&frame->retcode;
19235 if (ka->sa.sa_flags & SA_RESTORER)
19236 restorer = ka->sa.sa_restorer;
19237 put_user_ex(restorer, &frame->pretcode);
19238 @@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19239 * reasons and because gdb uses it as a signature to notice
19240 * signal handler stack frames.
19241 */
19242 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19243 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19244 } put_user_catch(err);
19245
19246 if (err)
19247 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19248 index 7c5a8c3..88d422f 100644
19249 --- a/arch/x86/kernel/smpboot.c
19250 +++ b/arch/x86/kernel/smpboot.c
19251 @@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19252 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19253 (THREAD_SIZE + task_stack_page(idle))) - 1);
19254 per_cpu(current_task, cpu) = idle;
19255 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19256
19257 #ifdef CONFIG_X86_32
19258 /* Stack for startup_32 can be just as for start_secondary onwards */
19259 @@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19260 #else
19261 clear_tsk_thread_flag(idle, TIF_FORK);
19262 initial_gs = per_cpu_offset(cpu);
19263 - per_cpu(kernel_stack, cpu) =
19264 - (unsigned long)task_stack_page(idle) -
19265 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19266 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19267 #endif
19268 +
19269 + pax_open_kernel();
19270 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19271 + pax_close_kernel();
19272 +
19273 initial_code = (unsigned long)start_secondary;
19274 stack_start = idle->thread.sp;
19275
19276 @@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19277
19278 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19279
19280 +#ifdef CONFIG_PAX_PER_CPU_PGD
19281 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19282 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19283 + KERNEL_PGD_PTRS);
19284 +#endif
19285 +
19286 err = do_boot_cpu(apicid, cpu, tidle);
19287 if (err) {
19288 pr_debug("do_boot_cpu failed %d\n", err);
19289 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19290 index c346d11..d43b163 100644
19291 --- a/arch/x86/kernel/step.c
19292 +++ b/arch/x86/kernel/step.c
19293 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19294 struct desc_struct *desc;
19295 unsigned long base;
19296
19297 - seg &= ~7UL;
19298 + seg >>= 3;
19299
19300 mutex_lock(&child->mm->context.lock);
19301 - if (unlikely((seg >> 3) >= child->mm->context.size))
19302 + if (unlikely(seg >= child->mm->context.size))
19303 addr = -1L; /* bogus selector, access would fault */
19304 else {
19305 desc = child->mm->context.ldt + seg;
19306 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19307 addr += base;
19308 }
19309 mutex_unlock(&child->mm->context.lock);
19310 - }
19311 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19312 + addr = ktla_ktva(addr);
19313
19314 return addr;
19315 }
19316 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19317 unsigned char opcode[15];
19318 unsigned long addr = convert_ip_to_linear(child, regs);
19319
19320 + if (addr == -EINVAL)
19321 + return 0;
19322 +
19323 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19324 for (i = 0; i < copied; i++) {
19325 switch (opcode[i]) {
19326 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19327 index 0b0cb5f..db6b9ed 100644
19328 --- a/arch/x86/kernel/sys_i386_32.c
19329 +++ b/arch/x86/kernel/sys_i386_32.c
19330 @@ -24,17 +24,224 @@
19331
19332 #include <asm/syscalls.h>
19333
19334 -/*
19335 - * Do a system call from kernel instead of calling sys_execve so we
19336 - * end up with proper pt_regs.
19337 - */
19338 -int kernel_execve(const char *filename,
19339 - const char *const argv[],
19340 - const char *const envp[])
19341 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19342 {
19343 - long __res;
19344 - asm volatile ("int $0x80"
19345 - : "=a" (__res)
19346 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19347 - return __res;
19348 + unsigned long pax_task_size = TASK_SIZE;
19349 +
19350 +#ifdef CONFIG_PAX_SEGMEXEC
19351 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19352 + pax_task_size = SEGMEXEC_TASK_SIZE;
19353 +#endif
19354 +
19355 + if (len > pax_task_size || addr > pax_task_size - len)
19356 + return -EINVAL;
19357 +
19358 + return 0;
19359 +}
19360 +
19361 +unsigned long
19362 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19363 + unsigned long len, unsigned long pgoff, unsigned long flags)
19364 +{
19365 + struct mm_struct *mm = current->mm;
19366 + struct vm_area_struct *vma;
19367 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19368 +
19369 +#ifdef CONFIG_PAX_SEGMEXEC
19370 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19371 + pax_task_size = SEGMEXEC_TASK_SIZE;
19372 +#endif
19373 +
19374 + pax_task_size -= PAGE_SIZE;
19375 +
19376 + if (len > pax_task_size)
19377 + return -ENOMEM;
19378 +
19379 + if (flags & MAP_FIXED)
19380 + return addr;
19381 +
19382 +#ifdef CONFIG_PAX_RANDMMAP
19383 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19384 +#endif
19385 +
19386 + if (addr) {
19387 + addr = PAGE_ALIGN(addr);
19388 + if (pax_task_size - len >= addr) {
19389 + vma = find_vma(mm, addr);
19390 + if (check_heap_stack_gap(vma, addr, len))
19391 + return addr;
19392 + }
19393 + }
19394 + if (len > mm->cached_hole_size) {
19395 + start_addr = addr = mm->free_area_cache;
19396 + } else {
19397 + start_addr = addr = mm->mmap_base;
19398 + mm->cached_hole_size = 0;
19399 + }
19400 +
19401 +#ifdef CONFIG_PAX_PAGEEXEC
19402 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19403 + start_addr = 0x00110000UL;
19404 +
19405 +#ifdef CONFIG_PAX_RANDMMAP
19406 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19407 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19408 +#endif
19409 +
19410 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19411 + start_addr = addr = mm->mmap_base;
19412 + else
19413 + addr = start_addr;
19414 + }
19415 +#endif
19416 +
19417 +full_search:
19418 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19419 + /* At this point: (!vma || addr < vma->vm_end). */
19420 + if (pax_task_size - len < addr) {
19421 + /*
19422 + * Start a new search - just in case we missed
19423 + * some holes.
19424 + */
19425 + if (start_addr != mm->mmap_base) {
19426 + start_addr = addr = mm->mmap_base;
19427 + mm->cached_hole_size = 0;
19428 + goto full_search;
19429 + }
19430 + return -ENOMEM;
19431 + }
19432 + if (check_heap_stack_gap(vma, addr, len))
19433 + break;
19434 + if (addr + mm->cached_hole_size < vma->vm_start)
19435 + mm->cached_hole_size = vma->vm_start - addr;
19436 + addr = vma->vm_end;
19437 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19438 + start_addr = addr = mm->mmap_base;
19439 + mm->cached_hole_size = 0;
19440 + goto full_search;
19441 + }
19442 + }
19443 +
19444 + /*
19445 + * Remember the place where we stopped the search:
19446 + */
19447 + mm->free_area_cache = addr + len;
19448 + return addr;
19449 +}
19450 +
19451 +unsigned long
19452 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19453 + const unsigned long len, const unsigned long pgoff,
19454 + const unsigned long flags)
19455 +{
19456 + struct vm_area_struct *vma;
19457 + struct mm_struct *mm = current->mm;
19458 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19459 +
19460 +#ifdef CONFIG_PAX_SEGMEXEC
19461 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19462 + pax_task_size = SEGMEXEC_TASK_SIZE;
19463 +#endif
19464 +
19465 + pax_task_size -= PAGE_SIZE;
19466 +
19467 + /* requested length too big for entire address space */
19468 + if (len > pax_task_size)
19469 + return -ENOMEM;
19470 +
19471 + if (flags & MAP_FIXED)
19472 + return addr;
19473 +
19474 +#ifdef CONFIG_PAX_PAGEEXEC
19475 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19476 + goto bottomup;
19477 +#endif
19478 +
19479 +#ifdef CONFIG_PAX_RANDMMAP
19480 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19481 +#endif
19482 +
19483 + /* requesting a specific address */
19484 + if (addr) {
19485 + addr = PAGE_ALIGN(addr);
19486 + if (pax_task_size - len >= addr) {
19487 + vma = find_vma(mm, addr);
19488 + if (check_heap_stack_gap(vma, addr, len))
19489 + return addr;
19490 + }
19491 + }
19492 +
19493 + /* check if free_area_cache is useful for us */
19494 + if (len <= mm->cached_hole_size) {
19495 + mm->cached_hole_size = 0;
19496 + mm->free_area_cache = mm->mmap_base;
19497 + }
19498 +
19499 + /* either no address requested or can't fit in requested address hole */
19500 + addr = mm->free_area_cache;
19501 +
19502 + /* make sure it can fit in the remaining address space */
19503 + if (addr > len) {
19504 + vma = find_vma(mm, addr-len);
19505 + if (check_heap_stack_gap(vma, addr - len, len))
19506 + /* remember the address as a hint for next time */
19507 + return (mm->free_area_cache = addr-len);
19508 + }
19509 +
19510 + if (mm->mmap_base < len)
19511 + goto bottomup;
19512 +
19513 + addr = mm->mmap_base-len;
19514 +
19515 + do {
19516 + /*
19517 + * Lookup failure means no vma is above this address,
19518 + * else if new region fits below vma->vm_start,
19519 + * return with success:
19520 + */
19521 + vma = find_vma(mm, addr);
19522 + if (check_heap_stack_gap(vma, addr, len))
19523 + /* remember the address as a hint for next time */
19524 + return (mm->free_area_cache = addr);
19525 +
19526 + /* remember the largest hole we saw so far */
19527 + if (addr + mm->cached_hole_size < vma->vm_start)
19528 + mm->cached_hole_size = vma->vm_start - addr;
19529 +
19530 + /* try just below the current vma->vm_start */
19531 + addr = skip_heap_stack_gap(vma, len);
19532 + } while (!IS_ERR_VALUE(addr));
19533 +
19534 +bottomup:
19535 + /*
19536 + * A failed mmap() very likely causes application failure,
19537 + * so fall back to the bottom-up function here. This scenario
19538 + * can happen with large stack limits and large mmap()
19539 + * allocations.
19540 + */
19541 +
19542 +#ifdef CONFIG_PAX_SEGMEXEC
19543 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19544 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19545 + else
19546 +#endif
19547 +
19548 + mm->mmap_base = TASK_UNMAPPED_BASE;
19549 +
19550 +#ifdef CONFIG_PAX_RANDMMAP
19551 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19552 + mm->mmap_base += mm->delta_mmap;
19553 +#endif
19554 +
19555 + mm->free_area_cache = mm->mmap_base;
19556 + mm->cached_hole_size = ~0UL;
19557 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19558 + /*
19559 + * Restore the topdown base:
19560 + */
19561 + mm->mmap_base = base;
19562 + mm->free_area_cache = base;
19563 + mm->cached_hole_size = ~0UL;
19564 +
19565 + return addr;
19566 }
19567 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19568 index b4d3c39..82bb73b 100644
19569 --- a/arch/x86/kernel/sys_x86_64.c
19570 +++ b/arch/x86/kernel/sys_x86_64.c
19571 @@ -95,8 +95,8 @@ out:
19572 return error;
19573 }
19574
19575 -static void find_start_end(unsigned long flags, unsigned long *begin,
19576 - unsigned long *end)
19577 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19578 + unsigned long *begin, unsigned long *end)
19579 {
19580 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19581 unsigned long new_begin;
19582 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19583 *begin = new_begin;
19584 }
19585 } else {
19586 - *begin = TASK_UNMAPPED_BASE;
19587 + *begin = mm->mmap_base;
19588 *end = TASK_SIZE;
19589 }
19590 }
19591 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19592 if (flags & MAP_FIXED)
19593 return addr;
19594
19595 - find_start_end(flags, &begin, &end);
19596 + find_start_end(mm, flags, &begin, &end);
19597
19598 if (len > end)
19599 return -ENOMEM;
19600
19601 +#ifdef CONFIG_PAX_RANDMMAP
19602 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19603 +#endif
19604 +
19605 if (addr) {
19606 addr = PAGE_ALIGN(addr);
19607 vma = find_vma(mm, addr);
19608 - if (end - len >= addr &&
19609 - (!vma || addr + len <= vma->vm_start))
19610 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19611 return addr;
19612 }
19613 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19614 @@ -172,7 +175,7 @@ full_search:
19615 }
19616 return -ENOMEM;
19617 }
19618 - if (!vma || addr + len <= vma->vm_start) {
19619 + if (check_heap_stack_gap(vma, addr, len)) {
19620 /*
19621 * Remember the place where we stopped the search:
19622 */
19623 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19624 {
19625 struct vm_area_struct *vma;
19626 struct mm_struct *mm = current->mm;
19627 - unsigned long addr = addr0, start_addr;
19628 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19629
19630 /* requested length too big for entire address space */
19631 if (len > TASK_SIZE)
19632 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19633 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19634 goto bottomup;
19635
19636 +#ifdef CONFIG_PAX_RANDMMAP
19637 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19638 +#endif
19639 +
19640 /* requesting a specific address */
19641 if (addr) {
19642 addr = PAGE_ALIGN(addr);
19643 - vma = find_vma(mm, addr);
19644 - if (TASK_SIZE - len >= addr &&
19645 - (!vma || addr + len <= vma->vm_start))
19646 - return addr;
19647 + if (TASK_SIZE - len >= addr) {
19648 + vma = find_vma(mm, addr);
19649 + if (check_heap_stack_gap(vma, addr, len))
19650 + return addr;
19651 + }
19652 }
19653
19654 /* check if free_area_cache is useful for us */
19655 @@ -240,7 +248,7 @@ try_again:
19656 * return with success:
19657 */
19658 vma = find_vma(mm, addr);
19659 - if (!vma || addr+len <= vma->vm_start)
19660 + if (check_heap_stack_gap(vma, addr, len))
19661 /* remember the address as a hint for next time */
19662 return mm->free_area_cache = addr;
19663
19664 @@ -249,8 +257,8 @@ try_again:
19665 mm->cached_hole_size = vma->vm_start - addr;
19666
19667 /* try just below the current vma->vm_start */
19668 - addr = vma->vm_start-len;
19669 - } while (len < vma->vm_start);
19670 + addr = skip_heap_stack_gap(vma, len);
19671 + } while (!IS_ERR_VALUE(addr));
19672
19673 fail:
19674 /*
19675 @@ -270,13 +278,21 @@ bottomup:
19676 * can happen with large stack limits and large mmap()
19677 * allocations.
19678 */
19679 + mm->mmap_base = TASK_UNMAPPED_BASE;
19680 +
19681 +#ifdef CONFIG_PAX_RANDMMAP
19682 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19683 + mm->mmap_base += mm->delta_mmap;
19684 +#endif
19685 +
19686 + mm->free_area_cache = mm->mmap_base;
19687 mm->cached_hole_size = ~0UL;
19688 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19689 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19690 /*
19691 * Restore the topdown base:
19692 */
19693 - mm->free_area_cache = mm->mmap_base;
19694 + mm->mmap_base = base;
19695 + mm->free_area_cache = base;
19696 mm->cached_hole_size = ~0UL;
19697
19698 return addr;
19699 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19700 index f84fe00..93fe08f 100644
19701 --- a/arch/x86/kernel/tboot.c
19702 +++ b/arch/x86/kernel/tboot.c
19703 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19704
19705 void tboot_shutdown(u32 shutdown_type)
19706 {
19707 - void (*shutdown)(void);
19708 + void (* __noreturn shutdown)(void);
19709
19710 if (!tboot_enabled())
19711 return;
19712 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19713
19714 switch_to_tboot_pt();
19715
19716 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19717 + shutdown = (void *)tboot->shutdown_entry;
19718 shutdown();
19719
19720 /* should not reach here */
19721 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19722 return 0;
19723 }
19724
19725 -static atomic_t ap_wfs_count;
19726 +static atomic_unchecked_t ap_wfs_count;
19727
19728 static int tboot_wait_for_aps(int num_aps)
19729 {
19730 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19731 {
19732 switch (action) {
19733 case CPU_DYING:
19734 - atomic_inc(&ap_wfs_count);
19735 + atomic_inc_unchecked(&ap_wfs_count);
19736 if (num_online_cpus() == 1)
19737 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19738 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19739 return NOTIFY_BAD;
19740 break;
19741 }
19742 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19743
19744 tboot_create_trampoline();
19745
19746 - atomic_set(&ap_wfs_count, 0);
19747 + atomic_set_unchecked(&ap_wfs_count, 0);
19748 register_hotcpu_notifier(&tboot_cpu_notifier);
19749
19750 acpi_os_set_prepare_sleep(&tboot_sleep);
19751 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19752 index 24d3c91..d06b473 100644
19753 --- a/arch/x86/kernel/time.c
19754 +++ b/arch/x86/kernel/time.c
19755 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19756 {
19757 unsigned long pc = instruction_pointer(regs);
19758
19759 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19760 + if (!user_mode(regs) && in_lock_functions(pc)) {
19761 #ifdef CONFIG_FRAME_POINTER
19762 - return *(unsigned long *)(regs->bp + sizeof(long));
19763 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19764 #else
19765 unsigned long *sp =
19766 (unsigned long *)kernel_stack_pointer(regs);
19767 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19768 * or above a saved flags. Eflags has bits 22-31 zero,
19769 * kernel addresses don't.
19770 */
19771 +
19772 +#ifdef CONFIG_PAX_KERNEXEC
19773 + return ktla_ktva(sp[0]);
19774 +#else
19775 if (sp[0] >> 22)
19776 return sp[0];
19777 if (sp[1] >> 22)
19778 return sp[1];
19779 #endif
19780 +
19781 +#endif
19782 }
19783 return pc;
19784 }
19785 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19786 index 9d9d2f9..cad418a 100644
19787 --- a/arch/x86/kernel/tls.c
19788 +++ b/arch/x86/kernel/tls.c
19789 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19790 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19791 return -EINVAL;
19792
19793 +#ifdef CONFIG_PAX_SEGMEXEC
19794 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19795 + return -EINVAL;
19796 +#endif
19797 +
19798 set_tls_desc(p, idx, &info, 1);
19799
19800 return 0;
19801 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19802
19803 if (kbuf)
19804 info = kbuf;
19805 - else if (__copy_from_user(infobuf, ubuf, count))
19806 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19807 return -EFAULT;
19808 else
19809 info = infobuf;
19810 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19811 index b481341..5918bbe 100644
19812 --- a/arch/x86/kernel/traps.c
19813 +++ b/arch/x86/kernel/traps.c
19814 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19815
19816 /* Do we ignore FPU interrupts ? */
19817 char ignore_fpu_irq;
19818 -
19819 -/*
19820 - * The IDT has to be page-aligned to simplify the Pentium
19821 - * F0 0F bug workaround.
19822 - */
19823 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19824 #endif
19825
19826 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19827 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19828 }
19829
19830 static void __kprobes
19831 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19832 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19833 long error_code, siginfo_t *info)
19834 {
19835 struct task_struct *tsk = current;
19836
19837 #ifdef CONFIG_X86_32
19838 - if (regs->flags & X86_VM_MASK) {
19839 + if (v8086_mode(regs)) {
19840 /*
19841 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19842 * On nmi (interrupt 2), do_trap should not be called.
19843 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19844 }
19845 #endif
19846
19847 - if (!user_mode(regs))
19848 + if (!user_mode_novm(regs))
19849 goto kernel_trap;
19850
19851 #ifdef CONFIG_X86_32
19852 @@ -147,7 +141,7 @@ trap_signal:
19853 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19854 printk_ratelimit()) {
19855 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19856 - tsk->comm, tsk->pid, str,
19857 + tsk->comm, task_pid_nr(tsk), str,
19858 regs->ip, regs->sp, error_code);
19859 print_vma_addr(" in ", regs->ip);
19860 pr_cont("\n");
19861 @@ -164,8 +158,20 @@ kernel_trap:
19862 if (!fixup_exception(regs)) {
19863 tsk->thread.error_code = error_code;
19864 tsk->thread.trap_nr = trapnr;
19865 +
19866 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19867 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19868 + str = "PAX: suspicious stack segment fault";
19869 +#endif
19870 +
19871 die(str, regs, error_code);
19872 }
19873 +
19874 +#ifdef CONFIG_PAX_REFCOUNT
19875 + if (trapnr == 4)
19876 + pax_report_refcount_overflow(regs);
19877 +#endif
19878 +
19879 return;
19880
19881 #ifdef CONFIG_X86_32
19882 @@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19883 conditional_sti(regs);
19884
19885 #ifdef CONFIG_X86_32
19886 - if (regs->flags & X86_VM_MASK)
19887 + if (v8086_mode(regs))
19888 goto gp_in_vm86;
19889 #endif
19890
19891 tsk = current;
19892 - if (!user_mode(regs))
19893 + if (!user_mode_novm(regs))
19894 goto gp_in_kernel;
19895
19896 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19897 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19898 + struct mm_struct *mm = tsk->mm;
19899 + unsigned long limit;
19900 +
19901 + down_write(&mm->mmap_sem);
19902 + limit = mm->context.user_cs_limit;
19903 + if (limit < TASK_SIZE) {
19904 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19905 + up_write(&mm->mmap_sem);
19906 + return;
19907 + }
19908 + up_write(&mm->mmap_sem);
19909 + }
19910 +#endif
19911 +
19912 tsk->thread.error_code = error_code;
19913 tsk->thread.trap_nr = X86_TRAP_GP;
19914
19915 @@ -297,6 +319,13 @@ gp_in_kernel:
19916 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19917 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19918 return;
19919 +
19920 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19921 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19922 + die("PAX: suspicious general protection fault", regs, error_code);
19923 + else
19924 +#endif
19925 +
19926 die("general protection fault", regs, error_code);
19927 }
19928
19929 @@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19930 /* It's safe to allow irq's after DR6 has been saved */
19931 preempt_conditional_sti(regs);
19932
19933 - if (regs->flags & X86_VM_MASK) {
19934 + if (v8086_mode(regs)) {
19935 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19936 X86_TRAP_DB);
19937 preempt_conditional_cli(regs);
19938 @@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19939 * We already checked v86 mode above, so we can check for kernel mode
19940 * by just checking the CPL of CS.
19941 */
19942 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19943 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19944 tsk->thread.debugreg6 &= ~DR_STEP;
19945 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19946 regs->flags &= ~X86_EFLAGS_TF;
19947 @@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19948 return;
19949 conditional_sti(regs);
19950
19951 - if (!user_mode_vm(regs))
19952 + if (!user_mode(regs))
19953 {
19954 if (!fixup_exception(regs)) {
19955 task->thread.error_code = error_code;
19956 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19957 index 36fd420..7e5892d 100644
19958 --- a/arch/x86/kernel/uprobes.c
19959 +++ b/arch/x86/kernel/uprobes.c
19960 @@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19961 int ret = NOTIFY_DONE;
19962
19963 /* We are only interested in userspace traps */
19964 - if (regs && !user_mode_vm(regs))
19965 + if (regs && !user_mode(regs))
19966 return NOTIFY_DONE;
19967
19968 switch (val) {
19969 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19970 index b9242ba..50c5edd 100644
19971 --- a/arch/x86/kernel/verify_cpu.S
19972 +++ b/arch/x86/kernel/verify_cpu.S
19973 @@ -20,6 +20,7 @@
19974 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19975 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19976 * arch/x86/kernel/head_32.S: processor startup
19977 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19978 *
19979 * verify_cpu, returns the status of longmode and SSE in register %eax.
19980 * 0: Success 1: Failure
19981 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19982 index 54abcc0..eb6c848 100644
19983 --- a/arch/x86/kernel/vm86_32.c
19984 +++ b/arch/x86/kernel/vm86_32.c
19985 @@ -43,6 +43,7 @@
19986 #include <linux/ptrace.h>
19987 #include <linux/audit.h>
19988 #include <linux/stddef.h>
19989 +#include <linux/grsecurity.h>
19990
19991 #include <asm/uaccess.h>
19992 #include <asm/io.h>
19993 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19994 do_exit(SIGSEGV);
19995 }
19996
19997 - tss = &per_cpu(init_tss, get_cpu());
19998 + tss = init_tss + get_cpu();
19999 current->thread.sp0 = current->thread.saved_sp0;
20000 current->thread.sysenter_cs = __KERNEL_CS;
20001 load_sp0(tss, &current->thread);
20002 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
20003 struct task_struct *tsk;
20004 int tmp, ret = -EPERM;
20005
20006 +#ifdef CONFIG_GRKERNSEC_VM86
20007 + if (!capable(CAP_SYS_RAWIO)) {
20008 + gr_handle_vm86();
20009 + goto out;
20010 + }
20011 +#endif
20012 +
20013 tsk = current;
20014 if (tsk->thread.saved_sp0)
20015 goto out;
20016 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20017 int tmp, ret;
20018 struct vm86plus_struct __user *v86;
20019
20020 +#ifdef CONFIG_GRKERNSEC_VM86
20021 + if (!capable(CAP_SYS_RAWIO)) {
20022 + gr_handle_vm86();
20023 + ret = -EPERM;
20024 + goto out;
20025 + }
20026 +#endif
20027 +
20028 tsk = current;
20029 switch (cmd) {
20030 case VM86_REQUEST_IRQ:
20031 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20032 tsk->thread.saved_fs = info->regs32->fs;
20033 tsk->thread.saved_gs = get_user_gs(info->regs32);
20034
20035 - tss = &per_cpu(init_tss, get_cpu());
20036 + tss = init_tss + get_cpu();
20037 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20038 if (cpu_has_sep)
20039 tsk->thread.sysenter_cs = 0;
20040 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20041 goto cannot_handle;
20042 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20043 goto cannot_handle;
20044 - intr_ptr = (unsigned long __user *) (i << 2);
20045 + intr_ptr = (__force unsigned long __user *) (i << 2);
20046 if (get_user(segoffs, intr_ptr))
20047 goto cannot_handle;
20048 if ((segoffs >> 16) == BIOSSEG)
20049 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20050 index 22a1530..8fbaaad 100644
20051 --- a/arch/x86/kernel/vmlinux.lds.S
20052 +++ b/arch/x86/kernel/vmlinux.lds.S
20053 @@ -26,6 +26,13 @@
20054 #include <asm/page_types.h>
20055 #include <asm/cache.h>
20056 #include <asm/boot.h>
20057 +#include <asm/segment.h>
20058 +
20059 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20060 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20061 +#else
20062 +#define __KERNEL_TEXT_OFFSET 0
20063 +#endif
20064
20065 #undef i386 /* in case the preprocessor is a 32bit one */
20066
20067 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20068
20069 PHDRS {
20070 text PT_LOAD FLAGS(5); /* R_E */
20071 +#ifdef CONFIG_X86_32
20072 + module PT_LOAD FLAGS(5); /* R_E */
20073 +#endif
20074 +#ifdef CONFIG_XEN
20075 + rodata PT_LOAD FLAGS(5); /* R_E */
20076 +#else
20077 + rodata PT_LOAD FLAGS(4); /* R__ */
20078 +#endif
20079 data PT_LOAD FLAGS(6); /* RW_ */
20080 -#ifdef CONFIG_X86_64
20081 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20082 #ifdef CONFIG_SMP
20083 percpu PT_LOAD FLAGS(6); /* RW_ */
20084 #endif
20085 + text.init PT_LOAD FLAGS(5); /* R_E */
20086 + text.exit PT_LOAD FLAGS(5); /* R_E */
20087 init PT_LOAD FLAGS(7); /* RWE */
20088 -#endif
20089 note PT_NOTE FLAGS(0); /* ___ */
20090 }
20091
20092 SECTIONS
20093 {
20094 #ifdef CONFIG_X86_32
20095 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20096 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20097 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20098 #else
20099 - . = __START_KERNEL;
20100 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20101 + . = __START_KERNEL;
20102 #endif
20103
20104 /* Text and read-only data */
20105 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20106 - _text = .;
20107 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20108 /* bootstrapping code */
20109 +#ifdef CONFIG_X86_32
20110 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20111 +#else
20112 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20113 +#endif
20114 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20115 + _text = .;
20116 HEAD_TEXT
20117 #ifdef CONFIG_X86_32
20118 . = ALIGN(PAGE_SIZE);
20119 @@ -108,13 +128,48 @@ SECTIONS
20120 IRQENTRY_TEXT
20121 *(.fixup)
20122 *(.gnu.warning)
20123 - /* End of text section */
20124 - _etext = .;
20125 } :text = 0x9090
20126
20127 - NOTES :text :note
20128 + . += __KERNEL_TEXT_OFFSET;
20129
20130 - EXCEPTION_TABLE(16) :text = 0x9090
20131 +#ifdef CONFIG_X86_32
20132 + . = ALIGN(PAGE_SIZE);
20133 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20134 +
20135 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20136 + MODULES_EXEC_VADDR = .;
20137 + BYTE(0)
20138 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20139 + . = ALIGN(HPAGE_SIZE) - 1;
20140 + MODULES_EXEC_END = .;
20141 +#endif
20142 +
20143 + } :module
20144 +#endif
20145 +
20146 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20147 + /* End of text section */
20148 + BYTE(0)
20149 + _etext = . - __KERNEL_TEXT_OFFSET;
20150 + }
20151 +
20152 +#ifdef CONFIG_X86_32
20153 + . = ALIGN(PAGE_SIZE);
20154 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20155 + *(.idt)
20156 + . = ALIGN(PAGE_SIZE);
20157 + *(.empty_zero_page)
20158 + *(.initial_pg_fixmap)
20159 + *(.initial_pg_pmd)
20160 + *(.initial_page_table)
20161 + *(.swapper_pg_dir)
20162 + } :rodata
20163 +#endif
20164 +
20165 + . = ALIGN(PAGE_SIZE);
20166 + NOTES :rodata :note
20167 +
20168 + EXCEPTION_TABLE(16) :rodata
20169
20170 #if defined(CONFIG_DEBUG_RODATA)
20171 /* .text should occupy whole number of pages */
20172 @@ -126,16 +181,20 @@ SECTIONS
20173
20174 /* Data */
20175 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20176 +
20177 +#ifdef CONFIG_PAX_KERNEXEC
20178 + . = ALIGN(HPAGE_SIZE);
20179 +#else
20180 + . = ALIGN(PAGE_SIZE);
20181 +#endif
20182 +
20183 /* Start of data section */
20184 _sdata = .;
20185
20186 /* init_task */
20187 INIT_TASK_DATA(THREAD_SIZE)
20188
20189 -#ifdef CONFIG_X86_32
20190 - /* 32 bit has nosave before _edata */
20191 NOSAVE_DATA
20192 -#endif
20193
20194 PAGE_ALIGNED_DATA(PAGE_SIZE)
20195
20196 @@ -176,12 +235,19 @@ SECTIONS
20197 #endif /* CONFIG_X86_64 */
20198
20199 /* Init code and data - will be freed after init */
20200 - . = ALIGN(PAGE_SIZE);
20201 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20202 + BYTE(0)
20203 +
20204 +#ifdef CONFIG_PAX_KERNEXEC
20205 + . = ALIGN(HPAGE_SIZE);
20206 +#else
20207 + . = ALIGN(PAGE_SIZE);
20208 +#endif
20209 +
20210 __init_begin = .; /* paired with __init_end */
20211 - }
20212 + } :init.begin
20213
20214 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20215 +#ifdef CONFIG_SMP
20216 /*
20217 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20218 * output PHDR, so the next output section - .init.text - should
20219 @@ -190,12 +256,27 @@ SECTIONS
20220 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20221 #endif
20222
20223 - INIT_TEXT_SECTION(PAGE_SIZE)
20224 -#ifdef CONFIG_X86_64
20225 - :init
20226 -#endif
20227 + . = ALIGN(PAGE_SIZE);
20228 + init_begin = .;
20229 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20230 + VMLINUX_SYMBOL(_sinittext) = .;
20231 + INIT_TEXT
20232 + VMLINUX_SYMBOL(_einittext) = .;
20233 + . = ALIGN(PAGE_SIZE);
20234 + } :text.init
20235
20236 - INIT_DATA_SECTION(16)
20237 + /*
20238 + * .exit.text is discard at runtime, not link time, to deal with
20239 + * references from .altinstructions and .eh_frame
20240 + */
20241 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20242 + EXIT_TEXT
20243 + . = ALIGN(16);
20244 + } :text.exit
20245 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20246 +
20247 + . = ALIGN(PAGE_SIZE);
20248 + INIT_DATA_SECTION(16) :init
20249
20250 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20251 __x86_cpu_dev_start = .;
20252 @@ -257,19 +338,12 @@ SECTIONS
20253 }
20254
20255 . = ALIGN(8);
20256 - /*
20257 - * .exit.text is discard at runtime, not link time, to deal with
20258 - * references from .altinstructions and .eh_frame
20259 - */
20260 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20261 - EXIT_TEXT
20262 - }
20263
20264 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20265 EXIT_DATA
20266 }
20267
20268 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20269 +#ifndef CONFIG_SMP
20270 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20271 #endif
20272
20273 @@ -288,16 +362,10 @@ SECTIONS
20274 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20275 __smp_locks = .;
20276 *(.smp_locks)
20277 - . = ALIGN(PAGE_SIZE);
20278 __smp_locks_end = .;
20279 + . = ALIGN(PAGE_SIZE);
20280 }
20281
20282 -#ifdef CONFIG_X86_64
20283 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20284 - NOSAVE_DATA
20285 - }
20286 -#endif
20287 -
20288 /* BSS */
20289 . = ALIGN(PAGE_SIZE);
20290 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20291 @@ -313,6 +381,7 @@ SECTIONS
20292 __brk_base = .;
20293 . += 64 * 1024; /* 64k alignment slop space */
20294 *(.brk_reservation) /* areas brk users have reserved */
20295 + . = ALIGN(HPAGE_SIZE);
20296 __brk_limit = .;
20297 }
20298
20299 @@ -339,13 +408,12 @@ SECTIONS
20300 * for the boot processor.
20301 */
20302 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20303 -INIT_PER_CPU(gdt_page);
20304 INIT_PER_CPU(irq_stack_union);
20305
20306 /*
20307 * Build-time check on the image size:
20308 */
20309 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20310 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20311 "kernel image bigger than KERNEL_IMAGE_SIZE");
20312
20313 #ifdef CONFIG_SMP
20314 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20315 index 992f890..fc38904 100644
20316 --- a/arch/x86/kernel/vsmp_64.c
20317 +++ b/arch/x86/kernel/vsmp_64.c
20318 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20319 static void vsmp_apic_post_init(void)
20320 {
20321 /* need to update phys_pkg_id */
20322 - apic->phys_pkg_id = apicid_phys_pkg_id;
20323 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20324 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20325 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20326 }
20327
20328 void __init vsmp_init(void)
20329 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20330 index 8d141b3..40a0fe4 100644
20331 --- a/arch/x86/kernel/vsyscall_64.c
20332 +++ b/arch/x86/kernel/vsyscall_64.c
20333 @@ -56,15 +56,13 @@
20334 DEFINE_VVAR(int, vgetcpu_mode);
20335 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20336
20337 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20338 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20339
20340 static int __init vsyscall_setup(char *str)
20341 {
20342 if (str) {
20343 if (!strcmp("emulate", str))
20344 vsyscall_mode = EMULATE;
20345 - else if (!strcmp("native", str))
20346 - vsyscall_mode = NATIVE;
20347 else if (!strcmp("none", str))
20348 vsyscall_mode = NONE;
20349 else
20350 @@ -306,8 +304,7 @@ done:
20351 return true;
20352
20353 sigsegv:
20354 - force_sig(SIGSEGV, current);
20355 - return true;
20356 + do_group_exit(SIGKILL);
20357 }
20358
20359 /*
20360 @@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20361 extern char __vvar_page;
20362 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20363
20364 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20365 - vsyscall_mode == NATIVE
20366 - ? PAGE_KERNEL_VSYSCALL
20367 - : PAGE_KERNEL_VVAR);
20368 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20369 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20370 (unsigned long)VSYSCALL_START);
20371
20372 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20373 index 6020f6f..bedd6e3 100644
20374 --- a/arch/x86/kernel/x8664_ksyms_64.c
20375 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20376 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20377 EXPORT_SYMBOL(copy_user_generic_unrolled);
20378 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20379 EXPORT_SYMBOL(__copy_user_nocache);
20380 -EXPORT_SYMBOL(_copy_from_user);
20381 -EXPORT_SYMBOL(_copy_to_user);
20382
20383 EXPORT_SYMBOL(copy_page);
20384 EXPORT_SYMBOL(clear_page);
20385 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20386 index 3d3e207..1a73ab2 100644
20387 --- a/arch/x86/kernel/xsave.c
20388 +++ b/arch/x86/kernel/xsave.c
20389 @@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20390 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20391 return -EINVAL;
20392
20393 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20394 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20395 fx_sw_user->extended_size -
20396 FP_XSTATE_MAGIC2_SIZE));
20397 if (err)
20398 @@ -268,7 +268,7 @@ fx_only:
20399 * the other extended state.
20400 */
20401 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20402 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20403 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20404 }
20405
20406 /*
20407 @@ -297,7 +297,7 @@ int restore_i387_xstate(void __user *buf)
20408 if (use_xsave())
20409 err = restore_user_xstate(buf);
20410 else
20411 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20412 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20413 buf);
20414 if (unlikely(err)) {
20415 /*
20416 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20417 index 0595f13..b544fa3 100644
20418 --- a/arch/x86/kvm/cpuid.c
20419 +++ b/arch/x86/kvm/cpuid.c
20420 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20421 struct kvm_cpuid2 *cpuid,
20422 struct kvm_cpuid_entry2 __user *entries)
20423 {
20424 - int r;
20425 + int r, i;
20426
20427 r = -E2BIG;
20428 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20429 goto out;
20430 r = -EFAULT;
20431 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20432 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20433 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20434 goto out;
20435 + for (i = 0; i < cpuid->nent; ++i) {
20436 + struct kvm_cpuid_entry2 cpuid_entry;
20437 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20438 + goto out;
20439 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20440 + }
20441 vcpu->arch.cpuid_nent = cpuid->nent;
20442 kvm_apic_set_version(vcpu);
20443 kvm_x86_ops->cpuid_update(vcpu);
20444 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20445 struct kvm_cpuid2 *cpuid,
20446 struct kvm_cpuid_entry2 __user *entries)
20447 {
20448 - int r;
20449 + int r, i;
20450
20451 r = -E2BIG;
20452 if (cpuid->nent < vcpu->arch.cpuid_nent)
20453 goto out;
20454 r = -EFAULT;
20455 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20456 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20457 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20458 goto out;
20459 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20460 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20461 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20462 + goto out;
20463 + }
20464 return 0;
20465
20466 out:
20467 diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
20468 index a10e460..58fc514 100644
20469 --- a/arch/x86/kvm/cpuid.h
20470 +++ b/arch/x86/kvm/cpuid.h
20471 @@ -24,6 +24,9 @@ static inline bool guest_cpuid_has_xsave(struct kvm_vcpu *vcpu)
20472 {
20473 struct kvm_cpuid_entry2 *best;
20474
20475 + if (!static_cpu_has(X86_FEATURE_XSAVE))
20476 + return 0;
20477 +
20478 best = kvm_find_cpuid_entry(vcpu, 1, 0);
20479 return best && (best->ecx & bit(X86_FEATURE_XSAVE));
20480 }
20481 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20482 index a3b57a2..ebbe732 100644
20483 --- a/arch/x86/kvm/emulate.c
20484 +++ b/arch/x86/kvm/emulate.c
20485 @@ -256,6 +256,7 @@ struct gprefix {
20486
20487 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20488 do { \
20489 + unsigned long _tmp; \
20490 __asm__ __volatile__ ( \
20491 _PRE_EFLAGS("0", "4", "2") \
20492 _op _suffix " %"_x"3,%1; " \
20493 @@ -270,8 +271,6 @@ struct gprefix {
20494 /* Raw emulation: instruction has two explicit operands. */
20495 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20496 do { \
20497 - unsigned long _tmp; \
20498 - \
20499 switch ((ctxt)->dst.bytes) { \
20500 case 2: \
20501 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20502 @@ -287,7 +286,6 @@ struct gprefix {
20503
20504 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20505 do { \
20506 - unsigned long _tmp; \
20507 switch ((ctxt)->dst.bytes) { \
20508 case 1: \
20509 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20510 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20511 index ce87878..ab48aa3 100644
20512 --- a/arch/x86/kvm/lapic.c
20513 +++ b/arch/x86/kvm/lapic.c
20514 @@ -54,7 +54,7 @@
20515 #define APIC_BUS_CYCLE_NS 1
20516
20517 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20518 -#define apic_debug(fmt, arg...)
20519 +#define apic_debug(fmt, arg...) do {} while (0)
20520
20521 #define APIC_LVT_NUM 6
20522 /* 14 is the version for Xeon and Pentium 8.4.8*/
20523 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20524 index bb7cf01..0348a05 100644
20525 --- a/arch/x86/kvm/paging_tmpl.h
20526 +++ b/arch/x86/kvm/paging_tmpl.h
20527 @@ -196,7 +196,7 @@ retry_walk:
20528 if (unlikely(kvm_is_error_hva(host_addr)))
20529 goto error;
20530
20531 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20532 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20533 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20534 goto error;
20535
20536 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20537 index baead95..90feeb4 100644
20538 --- a/arch/x86/kvm/svm.c
20539 +++ b/arch/x86/kvm/svm.c
20540 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20541 int cpu = raw_smp_processor_id();
20542
20543 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20544 +
20545 + pax_open_kernel();
20546 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20547 + pax_close_kernel();
20548 +
20549 load_TR_desc();
20550 }
20551
20552 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20553 #endif
20554 #endif
20555
20556 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20557 + __set_fs(current_thread_info()->addr_limit);
20558 +#endif
20559 +
20560 reload_tss(vcpu);
20561
20562 local_irq_disable();
20563 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20564 index b1eb202..48ad872 100644
20565 --- a/arch/x86/kvm/vmx.c
20566 +++ b/arch/x86/kvm/vmx.c
20567 @@ -1331,7 +1331,11 @@ static void reload_tss(void)
20568 struct desc_struct *descs;
20569
20570 descs = (void *)gdt->address;
20571 +
20572 + pax_open_kernel();
20573 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20574 + pax_close_kernel();
20575 +
20576 load_TR_desc();
20577 }
20578
20579 @@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20580 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20581 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20582
20583 +#ifdef CONFIG_PAX_PER_CPU_PGD
20584 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20585 +#endif
20586 +
20587 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20588 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20589 vmx->loaded_vmcs->cpu = cpu;
20590 @@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20591 if (!cpu_has_vmx_flexpriority())
20592 flexpriority_enabled = 0;
20593
20594 - if (!cpu_has_vmx_tpr_shadow())
20595 - kvm_x86_ops->update_cr8_intercept = NULL;
20596 + if (!cpu_has_vmx_tpr_shadow()) {
20597 + pax_open_kernel();
20598 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20599 + pax_close_kernel();
20600 + }
20601
20602 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20603 kvm_disable_largepages();
20604 @@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20605
20606 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20607 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20608 +
20609 +#ifndef CONFIG_PAX_PER_CPU_PGD
20610 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20611 +#endif
20612
20613 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20614 #ifdef CONFIG_X86_64
20615 @@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20616 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20617
20618 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20619 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20620 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20621
20622 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20623 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20624 @@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20625 "jmp .Lkvm_vmx_return \n\t"
20626 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20627 ".Lkvm_vmx_return: "
20628 +
20629 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20630 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20631 + ".Lkvm_vmx_return2: "
20632 +#endif
20633 +
20634 /* Save guest registers, load host registers, keep flags */
20635 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20636 "pop %0 \n\t"
20637 @@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20638 #endif
20639 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20640 [wordsize]"i"(sizeof(ulong))
20641 +
20642 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20643 + ,[cs]"i"(__KERNEL_CS)
20644 +#endif
20645 +
20646 : "cc", "memory"
20647 , R"ax", R"bx", R"di", R"si"
20648 #ifdef CONFIG_X86_64
20649 @@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20650 #endif
20651 );
20652
20653 -#ifndef CONFIG_X86_64
20654 +#ifdef CONFIG_X86_32
20655 /*
20656 * The sysexit path does not restore ds/es, so we must set them to
20657 * a reasonable value ourselves.
20658 @@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20659 * may be executed in interrupt context, which saves and restore segments
20660 * around it, nullifying its effect.
20661 */
20662 - loadsegment(ds, __USER_DS);
20663 - loadsegment(es, __USER_DS);
20664 + loadsegment(ds, __KERNEL_DS);
20665 + loadsegment(es, __KERNEL_DS);
20666 + loadsegment(ss, __KERNEL_DS);
20667 +
20668 +#ifdef CONFIG_PAX_KERNEXEC
20669 + loadsegment(fs, __KERNEL_PERCPU);
20670 +#endif
20671 +
20672 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20673 + __set_fs(current_thread_info()->addr_limit);
20674 +#endif
20675 +
20676 #endif
20677
20678 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20679 @@ -6584,19 +6619,22 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
20680 }
20681 }
20682
20683 - exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
20684 /* Exposing INVPCID only when PCID is exposed */
20685 best = kvm_find_cpuid_entry(vcpu, 0x7, 0);
20686 if (vmx_invpcid_supported() &&
20687 best && (best->ebx & bit(X86_FEATURE_INVPCID)) &&
20688 guest_cpuid_has_pcid(vcpu)) {
20689 + exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
20690 exec_control |= SECONDARY_EXEC_ENABLE_INVPCID;
20691 vmcs_write32(SECONDARY_VM_EXEC_CONTROL,
20692 exec_control);
20693 } else {
20694 - exec_control &= ~SECONDARY_EXEC_ENABLE_INVPCID;
20695 - vmcs_write32(SECONDARY_VM_EXEC_CONTROL,
20696 - exec_control);
20697 + if (cpu_has_secondary_exec_ctrls()) {
20698 + exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
20699 + exec_control &= ~SECONDARY_EXEC_ENABLE_INVPCID;
20700 + vmcs_write32(SECONDARY_VM_EXEC_CONTROL,
20701 + exec_control);
20702 + }
20703 if (best)
20704 best->ebx &= ~bit(X86_FEATURE_INVPCID);
20705 }
20706 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20707 index 2966c84..9ac0c3c 100644
20708 --- a/arch/x86/kvm/x86.c
20709 +++ b/arch/x86/kvm/x86.c
20710 @@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20711 {
20712 struct kvm *kvm = vcpu->kvm;
20713 int lm = is_long_mode(vcpu);
20714 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20715 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20716 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20717 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20718 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20719 : kvm->arch.xen_hvm_config.blob_size_32;
20720 u32 page_num = data & ~PAGE_MASK;
20721 @@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20722 if (n < msr_list.nmsrs)
20723 goto out;
20724 r = -EFAULT;
20725 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20726 + goto out;
20727 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20728 num_msrs_to_save * sizeof(u32)))
20729 goto out;
20730 @@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20731 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20732 struct kvm_interrupt *irq)
20733 {
20734 - if (irq->irq < 0 || irq->irq >= 256)
20735 + if (irq->irq >= 256)
20736 return -EINVAL;
20737 if (irqchip_in_kernel(vcpu->kvm))
20738 return -ENXIO;
20739 @@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20740 kvm_mmu_set_mmio_spte_mask(mask);
20741 }
20742
20743 -int kvm_arch_init(void *opaque)
20744 +int kvm_arch_init(const void *opaque)
20745 {
20746 int r;
20747 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20748 @@ -5762,6 +5764,9 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
20749 int pending_vec, max_bits, idx;
20750 struct desc_ptr dt;
20751
20752 + if (!guest_cpuid_has_xsave(vcpu) && (sregs->cr4 & X86_CR4_OSXSAVE))
20753 + return -EINVAL;
20754 +
20755 dt.size = sregs->idt.limit;
20756 dt.address = sregs->idt.base;
20757 kvm_x86_ops->set_idt(vcpu, &dt);
20758 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20759 index 642d880..cc9ebac 100644
20760 --- a/arch/x86/lguest/boot.c
20761 +++ b/arch/x86/lguest/boot.c
20762 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20763
20764 static void set_lguest_basic_apic_ops(void)
20765 {
20766 - apic->read = lguest_apic_read;
20767 - apic->write = lguest_apic_write;
20768 - apic->icr_read = lguest_apic_icr_read;
20769 - apic->icr_write = lguest_apic_icr_write;
20770 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20771 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20772 + *(void **)&apic->read = lguest_apic_read;
20773 + *(void **)&apic->write = lguest_apic_write;
20774 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20775 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20776 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20777 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20778 };
20779 #endif
20780
20781 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20782 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20783 * Launcher to reboot us.
20784 */
20785 -static void lguest_restart(char *reason)
20786 +static __noreturn void lguest_restart(char *reason)
20787 {
20788 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20789 + BUG();
20790 }
20791
20792 /*G:050
20793 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20794 index 00933d5..3a64af9 100644
20795 --- a/arch/x86/lib/atomic64_386_32.S
20796 +++ b/arch/x86/lib/atomic64_386_32.S
20797 @@ -48,6 +48,10 @@ BEGIN(read)
20798 movl (v), %eax
20799 movl 4(v), %edx
20800 RET_ENDP
20801 +BEGIN(read_unchecked)
20802 + movl (v), %eax
20803 + movl 4(v), %edx
20804 +RET_ENDP
20805 #undef v
20806
20807 #define v %esi
20808 @@ -55,6 +59,10 @@ BEGIN(set)
20809 movl %ebx, (v)
20810 movl %ecx, 4(v)
20811 RET_ENDP
20812 +BEGIN(set_unchecked)
20813 + movl %ebx, (v)
20814 + movl %ecx, 4(v)
20815 +RET_ENDP
20816 #undef v
20817
20818 #define v %esi
20819 @@ -70,6 +78,20 @@ RET_ENDP
20820 BEGIN(add)
20821 addl %eax, (v)
20822 adcl %edx, 4(v)
20823 +
20824 +#ifdef CONFIG_PAX_REFCOUNT
20825 + jno 0f
20826 + subl %eax, (v)
20827 + sbbl %edx, 4(v)
20828 + int $4
20829 +0:
20830 + _ASM_EXTABLE(0b, 0b)
20831 +#endif
20832 +
20833 +RET_ENDP
20834 +BEGIN(add_unchecked)
20835 + addl %eax, (v)
20836 + adcl %edx, 4(v)
20837 RET_ENDP
20838 #undef v
20839
20840 @@ -77,6 +99,24 @@ RET_ENDP
20841 BEGIN(add_return)
20842 addl (v), %eax
20843 adcl 4(v), %edx
20844 +
20845 +#ifdef CONFIG_PAX_REFCOUNT
20846 + into
20847 +1234:
20848 + _ASM_EXTABLE(1234b, 2f)
20849 +#endif
20850 +
20851 + movl %eax, (v)
20852 + movl %edx, 4(v)
20853 +
20854 +#ifdef CONFIG_PAX_REFCOUNT
20855 +2:
20856 +#endif
20857 +
20858 +RET_ENDP
20859 +BEGIN(add_return_unchecked)
20860 + addl (v), %eax
20861 + adcl 4(v), %edx
20862 movl %eax, (v)
20863 movl %edx, 4(v)
20864 RET_ENDP
20865 @@ -86,6 +126,20 @@ RET_ENDP
20866 BEGIN(sub)
20867 subl %eax, (v)
20868 sbbl %edx, 4(v)
20869 +
20870 +#ifdef CONFIG_PAX_REFCOUNT
20871 + jno 0f
20872 + addl %eax, (v)
20873 + adcl %edx, 4(v)
20874 + int $4
20875 +0:
20876 + _ASM_EXTABLE(0b, 0b)
20877 +#endif
20878 +
20879 +RET_ENDP
20880 +BEGIN(sub_unchecked)
20881 + subl %eax, (v)
20882 + sbbl %edx, 4(v)
20883 RET_ENDP
20884 #undef v
20885
20886 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20887 sbbl $0, %edx
20888 addl (v), %eax
20889 adcl 4(v), %edx
20890 +
20891 +#ifdef CONFIG_PAX_REFCOUNT
20892 + into
20893 +1234:
20894 + _ASM_EXTABLE(1234b, 2f)
20895 +#endif
20896 +
20897 + movl %eax, (v)
20898 + movl %edx, 4(v)
20899 +
20900 +#ifdef CONFIG_PAX_REFCOUNT
20901 +2:
20902 +#endif
20903 +
20904 +RET_ENDP
20905 +BEGIN(sub_return_unchecked)
20906 + negl %edx
20907 + negl %eax
20908 + sbbl $0, %edx
20909 + addl (v), %eax
20910 + adcl 4(v), %edx
20911 movl %eax, (v)
20912 movl %edx, 4(v)
20913 RET_ENDP
20914 @@ -105,6 +180,20 @@ RET_ENDP
20915 BEGIN(inc)
20916 addl $1, (v)
20917 adcl $0, 4(v)
20918 +
20919 +#ifdef CONFIG_PAX_REFCOUNT
20920 + jno 0f
20921 + subl $1, (v)
20922 + sbbl $0, 4(v)
20923 + int $4
20924 +0:
20925 + _ASM_EXTABLE(0b, 0b)
20926 +#endif
20927 +
20928 +RET_ENDP
20929 +BEGIN(inc_unchecked)
20930 + addl $1, (v)
20931 + adcl $0, 4(v)
20932 RET_ENDP
20933 #undef v
20934
20935 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20936 movl 4(v), %edx
20937 addl $1, %eax
20938 adcl $0, %edx
20939 +
20940 +#ifdef CONFIG_PAX_REFCOUNT
20941 + into
20942 +1234:
20943 + _ASM_EXTABLE(1234b, 2f)
20944 +#endif
20945 +
20946 + movl %eax, (v)
20947 + movl %edx, 4(v)
20948 +
20949 +#ifdef CONFIG_PAX_REFCOUNT
20950 +2:
20951 +#endif
20952 +
20953 +RET_ENDP
20954 +BEGIN(inc_return_unchecked)
20955 + movl (v), %eax
20956 + movl 4(v), %edx
20957 + addl $1, %eax
20958 + adcl $0, %edx
20959 movl %eax, (v)
20960 movl %edx, 4(v)
20961 RET_ENDP
20962 @@ -123,6 +232,20 @@ RET_ENDP
20963 BEGIN(dec)
20964 subl $1, (v)
20965 sbbl $0, 4(v)
20966 +
20967 +#ifdef CONFIG_PAX_REFCOUNT
20968 + jno 0f
20969 + addl $1, (v)
20970 + adcl $0, 4(v)
20971 + int $4
20972 +0:
20973 + _ASM_EXTABLE(0b, 0b)
20974 +#endif
20975 +
20976 +RET_ENDP
20977 +BEGIN(dec_unchecked)
20978 + subl $1, (v)
20979 + sbbl $0, 4(v)
20980 RET_ENDP
20981 #undef v
20982
20983 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20984 movl 4(v), %edx
20985 subl $1, %eax
20986 sbbl $0, %edx
20987 +
20988 +#ifdef CONFIG_PAX_REFCOUNT
20989 + into
20990 +1234:
20991 + _ASM_EXTABLE(1234b, 2f)
20992 +#endif
20993 +
20994 + movl %eax, (v)
20995 + movl %edx, 4(v)
20996 +
20997 +#ifdef CONFIG_PAX_REFCOUNT
20998 +2:
20999 +#endif
21000 +
21001 +RET_ENDP
21002 +BEGIN(dec_return_unchecked)
21003 + movl (v), %eax
21004 + movl 4(v), %edx
21005 + subl $1, %eax
21006 + sbbl $0, %edx
21007 movl %eax, (v)
21008 movl %edx, 4(v)
21009 RET_ENDP
21010 @@ -143,6 +286,13 @@ BEGIN(add_unless)
21011 adcl %edx, %edi
21012 addl (v), %eax
21013 adcl 4(v), %edx
21014 +
21015 +#ifdef CONFIG_PAX_REFCOUNT
21016 + into
21017 +1234:
21018 + _ASM_EXTABLE(1234b, 2f)
21019 +#endif
21020 +
21021 cmpl %eax, %ecx
21022 je 3f
21023 1:
21024 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
21025 1:
21026 addl $1, %eax
21027 adcl $0, %edx
21028 +
21029 +#ifdef CONFIG_PAX_REFCOUNT
21030 + into
21031 +1234:
21032 + _ASM_EXTABLE(1234b, 2f)
21033 +#endif
21034 +
21035 movl %eax, (v)
21036 movl %edx, 4(v)
21037 movl $1, %eax
21038 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
21039 movl 4(v), %edx
21040 subl $1, %eax
21041 sbbl $0, %edx
21042 +
21043 +#ifdef CONFIG_PAX_REFCOUNT
21044 + into
21045 +1234:
21046 + _ASM_EXTABLE(1234b, 1f)
21047 +#endif
21048 +
21049 js 1f
21050 movl %eax, (v)
21051 movl %edx, 4(v)
21052 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21053 index f5cc9eb..51fa319 100644
21054 --- a/arch/x86/lib/atomic64_cx8_32.S
21055 +++ b/arch/x86/lib/atomic64_cx8_32.S
21056 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21057 CFI_STARTPROC
21058
21059 read64 %ecx
21060 + pax_force_retaddr
21061 ret
21062 CFI_ENDPROC
21063 ENDPROC(atomic64_read_cx8)
21064
21065 +ENTRY(atomic64_read_unchecked_cx8)
21066 + CFI_STARTPROC
21067 +
21068 + read64 %ecx
21069 + pax_force_retaddr
21070 + ret
21071 + CFI_ENDPROC
21072 +ENDPROC(atomic64_read_unchecked_cx8)
21073 +
21074 ENTRY(atomic64_set_cx8)
21075 CFI_STARTPROC
21076
21077 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21078 cmpxchg8b (%esi)
21079 jne 1b
21080
21081 + pax_force_retaddr
21082 ret
21083 CFI_ENDPROC
21084 ENDPROC(atomic64_set_cx8)
21085
21086 +ENTRY(atomic64_set_unchecked_cx8)
21087 + CFI_STARTPROC
21088 +
21089 +1:
21090 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
21091 + * are atomic on 586 and newer */
21092 + cmpxchg8b (%esi)
21093 + jne 1b
21094 +
21095 + pax_force_retaddr
21096 + ret
21097 + CFI_ENDPROC
21098 +ENDPROC(atomic64_set_unchecked_cx8)
21099 +
21100 ENTRY(atomic64_xchg_cx8)
21101 CFI_STARTPROC
21102
21103 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21104 cmpxchg8b (%esi)
21105 jne 1b
21106
21107 + pax_force_retaddr
21108 ret
21109 CFI_ENDPROC
21110 ENDPROC(atomic64_xchg_cx8)
21111
21112 -.macro addsub_return func ins insc
21113 -ENTRY(atomic64_\func\()_return_cx8)
21114 +.macro addsub_return func ins insc unchecked=""
21115 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21116 CFI_STARTPROC
21117 SAVE ebp
21118 SAVE ebx
21119 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21120 movl %edx, %ecx
21121 \ins\()l %esi, %ebx
21122 \insc\()l %edi, %ecx
21123 +
21124 +.ifb \unchecked
21125 +#ifdef CONFIG_PAX_REFCOUNT
21126 + into
21127 +2:
21128 + _ASM_EXTABLE(2b, 3f)
21129 +#endif
21130 +.endif
21131 +
21132 LOCK_PREFIX
21133 cmpxchg8b (%ebp)
21134 jne 1b
21135 -
21136 -10:
21137 movl %ebx, %eax
21138 movl %ecx, %edx
21139 +
21140 +.ifb \unchecked
21141 +#ifdef CONFIG_PAX_REFCOUNT
21142 +3:
21143 +#endif
21144 +.endif
21145 +
21146 RESTORE edi
21147 RESTORE esi
21148 RESTORE ebx
21149 RESTORE ebp
21150 + pax_force_retaddr
21151 ret
21152 CFI_ENDPROC
21153 -ENDPROC(atomic64_\func\()_return_cx8)
21154 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21155 .endm
21156
21157 addsub_return add add adc
21158 addsub_return sub sub sbb
21159 +addsub_return add add adc _unchecked
21160 +addsub_return sub sub sbb _unchecked
21161
21162 -.macro incdec_return func ins insc
21163 -ENTRY(atomic64_\func\()_return_cx8)
21164 +.macro incdec_return func ins insc unchecked=""
21165 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21166 CFI_STARTPROC
21167 SAVE ebx
21168
21169 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21170 movl %edx, %ecx
21171 \ins\()l $1, %ebx
21172 \insc\()l $0, %ecx
21173 +
21174 +.ifb \unchecked
21175 +#ifdef CONFIG_PAX_REFCOUNT
21176 + into
21177 +2:
21178 + _ASM_EXTABLE(2b, 3f)
21179 +#endif
21180 +.endif
21181 +
21182 LOCK_PREFIX
21183 cmpxchg8b (%esi)
21184 jne 1b
21185
21186 -10:
21187 movl %ebx, %eax
21188 movl %ecx, %edx
21189 +
21190 +.ifb \unchecked
21191 +#ifdef CONFIG_PAX_REFCOUNT
21192 +3:
21193 +#endif
21194 +.endif
21195 +
21196 RESTORE ebx
21197 + pax_force_retaddr
21198 ret
21199 CFI_ENDPROC
21200 -ENDPROC(atomic64_\func\()_return_cx8)
21201 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21202 .endm
21203
21204 incdec_return inc add adc
21205 incdec_return dec sub sbb
21206 +incdec_return inc add adc _unchecked
21207 +incdec_return dec sub sbb _unchecked
21208
21209 ENTRY(atomic64_dec_if_positive_cx8)
21210 CFI_STARTPROC
21211 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21212 movl %edx, %ecx
21213 subl $1, %ebx
21214 sbb $0, %ecx
21215 +
21216 +#ifdef CONFIG_PAX_REFCOUNT
21217 + into
21218 +1234:
21219 + _ASM_EXTABLE(1234b, 2f)
21220 +#endif
21221 +
21222 js 2f
21223 LOCK_PREFIX
21224 cmpxchg8b (%esi)
21225 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21226 movl %ebx, %eax
21227 movl %ecx, %edx
21228 RESTORE ebx
21229 + pax_force_retaddr
21230 ret
21231 CFI_ENDPROC
21232 ENDPROC(atomic64_dec_if_positive_cx8)
21233 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21234 movl %edx, %ecx
21235 addl %ebp, %ebx
21236 adcl %edi, %ecx
21237 +
21238 +#ifdef CONFIG_PAX_REFCOUNT
21239 + into
21240 +1234:
21241 + _ASM_EXTABLE(1234b, 3f)
21242 +#endif
21243 +
21244 LOCK_PREFIX
21245 cmpxchg8b (%esi)
21246 jne 1b
21247 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21248 CFI_ADJUST_CFA_OFFSET -8
21249 RESTORE ebx
21250 RESTORE ebp
21251 + pax_force_retaddr
21252 ret
21253 4:
21254 cmpl %edx, 4(%esp)
21255 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21256 xorl %ecx, %ecx
21257 addl $1, %ebx
21258 adcl %edx, %ecx
21259 +
21260 +#ifdef CONFIG_PAX_REFCOUNT
21261 + into
21262 +1234:
21263 + _ASM_EXTABLE(1234b, 3f)
21264 +#endif
21265 +
21266 LOCK_PREFIX
21267 cmpxchg8b (%esi)
21268 jne 1b
21269 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21270 movl $1, %eax
21271 3:
21272 RESTORE ebx
21273 + pax_force_retaddr
21274 ret
21275 CFI_ENDPROC
21276 ENDPROC(atomic64_inc_not_zero_cx8)
21277 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21278 index 2af5df3..62b1a5a 100644
21279 --- a/arch/x86/lib/checksum_32.S
21280 +++ b/arch/x86/lib/checksum_32.S
21281 @@ -29,7 +29,8 @@
21282 #include <asm/dwarf2.h>
21283 #include <asm/errno.h>
21284 #include <asm/asm.h>
21285 -
21286 +#include <asm/segment.h>
21287 +
21288 /*
21289 * computes a partial checksum, e.g. for TCP/UDP fragments
21290 */
21291 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21292
21293 #define ARGBASE 16
21294 #define FP 12
21295 -
21296 -ENTRY(csum_partial_copy_generic)
21297 +
21298 +ENTRY(csum_partial_copy_generic_to_user)
21299 CFI_STARTPROC
21300 +
21301 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21302 + pushl_cfi %gs
21303 + popl_cfi %es
21304 + jmp csum_partial_copy_generic
21305 +#endif
21306 +
21307 +ENTRY(csum_partial_copy_generic_from_user)
21308 +
21309 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21310 + pushl_cfi %gs
21311 + popl_cfi %ds
21312 +#endif
21313 +
21314 +ENTRY(csum_partial_copy_generic)
21315 subl $4,%esp
21316 CFI_ADJUST_CFA_OFFSET 4
21317 pushl_cfi %edi
21318 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21319 jmp 4f
21320 SRC(1: movw (%esi), %bx )
21321 addl $2, %esi
21322 -DST( movw %bx, (%edi) )
21323 +DST( movw %bx, %es:(%edi) )
21324 addl $2, %edi
21325 addw %bx, %ax
21326 adcl $0, %eax
21327 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21328 SRC(1: movl (%esi), %ebx )
21329 SRC( movl 4(%esi), %edx )
21330 adcl %ebx, %eax
21331 -DST( movl %ebx, (%edi) )
21332 +DST( movl %ebx, %es:(%edi) )
21333 adcl %edx, %eax
21334 -DST( movl %edx, 4(%edi) )
21335 +DST( movl %edx, %es:4(%edi) )
21336
21337 SRC( movl 8(%esi), %ebx )
21338 SRC( movl 12(%esi), %edx )
21339 adcl %ebx, %eax
21340 -DST( movl %ebx, 8(%edi) )
21341 +DST( movl %ebx, %es:8(%edi) )
21342 adcl %edx, %eax
21343 -DST( movl %edx, 12(%edi) )
21344 +DST( movl %edx, %es:12(%edi) )
21345
21346 SRC( movl 16(%esi), %ebx )
21347 SRC( movl 20(%esi), %edx )
21348 adcl %ebx, %eax
21349 -DST( movl %ebx, 16(%edi) )
21350 +DST( movl %ebx, %es:16(%edi) )
21351 adcl %edx, %eax
21352 -DST( movl %edx, 20(%edi) )
21353 +DST( movl %edx, %es:20(%edi) )
21354
21355 SRC( movl 24(%esi), %ebx )
21356 SRC( movl 28(%esi), %edx )
21357 adcl %ebx, %eax
21358 -DST( movl %ebx, 24(%edi) )
21359 +DST( movl %ebx, %es:24(%edi) )
21360 adcl %edx, %eax
21361 -DST( movl %edx, 28(%edi) )
21362 +DST( movl %edx, %es:28(%edi) )
21363
21364 lea 32(%esi), %esi
21365 lea 32(%edi), %edi
21366 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21367 shrl $2, %edx # This clears CF
21368 SRC(3: movl (%esi), %ebx )
21369 adcl %ebx, %eax
21370 -DST( movl %ebx, (%edi) )
21371 +DST( movl %ebx, %es:(%edi) )
21372 lea 4(%esi), %esi
21373 lea 4(%edi), %edi
21374 dec %edx
21375 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21376 jb 5f
21377 SRC( movw (%esi), %cx )
21378 leal 2(%esi), %esi
21379 -DST( movw %cx, (%edi) )
21380 +DST( movw %cx, %es:(%edi) )
21381 leal 2(%edi), %edi
21382 je 6f
21383 shll $16,%ecx
21384 SRC(5: movb (%esi), %cl )
21385 -DST( movb %cl, (%edi) )
21386 +DST( movb %cl, %es:(%edi) )
21387 6: addl %ecx, %eax
21388 adcl $0, %eax
21389 7:
21390 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21391
21392 6001:
21393 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21394 - movl $-EFAULT, (%ebx)
21395 + movl $-EFAULT, %ss:(%ebx)
21396
21397 # zero the complete destination - computing the rest
21398 # is too much work
21399 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21400
21401 6002:
21402 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21403 - movl $-EFAULT,(%ebx)
21404 + movl $-EFAULT,%ss:(%ebx)
21405 jmp 5000b
21406
21407 .previous
21408
21409 + pushl_cfi %ss
21410 + popl_cfi %ds
21411 + pushl_cfi %ss
21412 + popl_cfi %es
21413 popl_cfi %ebx
21414 CFI_RESTORE ebx
21415 popl_cfi %esi
21416 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21417 popl_cfi %ecx # equivalent to addl $4,%esp
21418 ret
21419 CFI_ENDPROC
21420 -ENDPROC(csum_partial_copy_generic)
21421 +ENDPROC(csum_partial_copy_generic_to_user)
21422
21423 #else
21424
21425 /* Version for PentiumII/PPro */
21426
21427 #define ROUND1(x) \
21428 + nop; nop; nop; \
21429 SRC(movl x(%esi), %ebx ) ; \
21430 addl %ebx, %eax ; \
21431 - DST(movl %ebx, x(%edi) ) ;
21432 + DST(movl %ebx, %es:x(%edi)) ;
21433
21434 #define ROUND(x) \
21435 + nop; nop; nop; \
21436 SRC(movl x(%esi), %ebx ) ; \
21437 adcl %ebx, %eax ; \
21438 - DST(movl %ebx, x(%edi) ) ;
21439 + DST(movl %ebx, %es:x(%edi)) ;
21440
21441 #define ARGBASE 12
21442 -
21443 -ENTRY(csum_partial_copy_generic)
21444 +
21445 +ENTRY(csum_partial_copy_generic_to_user)
21446 CFI_STARTPROC
21447 +
21448 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21449 + pushl_cfi %gs
21450 + popl_cfi %es
21451 + jmp csum_partial_copy_generic
21452 +#endif
21453 +
21454 +ENTRY(csum_partial_copy_generic_from_user)
21455 +
21456 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21457 + pushl_cfi %gs
21458 + popl_cfi %ds
21459 +#endif
21460 +
21461 +ENTRY(csum_partial_copy_generic)
21462 pushl_cfi %ebx
21463 CFI_REL_OFFSET ebx, 0
21464 pushl_cfi %edi
21465 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21466 subl %ebx, %edi
21467 lea -1(%esi),%edx
21468 andl $-32,%edx
21469 - lea 3f(%ebx,%ebx), %ebx
21470 + lea 3f(%ebx,%ebx,2), %ebx
21471 testl %esi, %esi
21472 jmp *%ebx
21473 1: addl $64,%esi
21474 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21475 jb 5f
21476 SRC( movw (%esi), %dx )
21477 leal 2(%esi), %esi
21478 -DST( movw %dx, (%edi) )
21479 +DST( movw %dx, %es:(%edi) )
21480 leal 2(%edi), %edi
21481 je 6f
21482 shll $16,%edx
21483 5:
21484 SRC( movb (%esi), %dl )
21485 -DST( movb %dl, (%edi) )
21486 +DST( movb %dl, %es:(%edi) )
21487 6: addl %edx, %eax
21488 adcl $0, %eax
21489 7:
21490 .section .fixup, "ax"
21491 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21492 - movl $-EFAULT, (%ebx)
21493 + movl $-EFAULT, %ss:(%ebx)
21494 # zero the complete destination (computing the rest is too much work)
21495 movl ARGBASE+8(%esp),%edi # dst
21496 movl ARGBASE+12(%esp),%ecx # len
21497 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21498 rep; stosb
21499 jmp 7b
21500 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21501 - movl $-EFAULT, (%ebx)
21502 + movl $-EFAULT, %ss:(%ebx)
21503 jmp 7b
21504 .previous
21505
21506 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21507 + pushl_cfi %ss
21508 + popl_cfi %ds
21509 + pushl_cfi %ss
21510 + popl_cfi %es
21511 +#endif
21512 +
21513 popl_cfi %esi
21514 CFI_RESTORE esi
21515 popl_cfi %edi
21516 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21517 CFI_RESTORE ebx
21518 ret
21519 CFI_ENDPROC
21520 -ENDPROC(csum_partial_copy_generic)
21521 +ENDPROC(csum_partial_copy_generic_to_user)
21522
21523 #undef ROUND
21524 #undef ROUND1
21525 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21526 index f2145cf..cea889d 100644
21527 --- a/arch/x86/lib/clear_page_64.S
21528 +++ b/arch/x86/lib/clear_page_64.S
21529 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21530 movl $4096/8,%ecx
21531 xorl %eax,%eax
21532 rep stosq
21533 + pax_force_retaddr
21534 ret
21535 CFI_ENDPROC
21536 ENDPROC(clear_page_c)
21537 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21538 movl $4096,%ecx
21539 xorl %eax,%eax
21540 rep stosb
21541 + pax_force_retaddr
21542 ret
21543 CFI_ENDPROC
21544 ENDPROC(clear_page_c_e)
21545 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21546 leaq 64(%rdi),%rdi
21547 jnz .Lloop
21548 nop
21549 + pax_force_retaddr
21550 ret
21551 CFI_ENDPROC
21552 .Lclear_page_end:
21553 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21554
21555 #include <asm/cpufeature.h>
21556
21557 - .section .altinstr_replacement,"ax"
21558 + .section .altinstr_replacement,"a"
21559 1: .byte 0xeb /* jmp <disp8> */
21560 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21561 2: .byte 0xeb /* jmp <disp8> */
21562 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21563 index 1e572c5..2a162cd 100644
21564 --- a/arch/x86/lib/cmpxchg16b_emu.S
21565 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21566 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21567
21568 popf
21569 mov $1, %al
21570 + pax_force_retaddr
21571 ret
21572
21573 not_same:
21574 popf
21575 xor %al,%al
21576 + pax_force_retaddr
21577 ret
21578
21579 CFI_ENDPROC
21580 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21581 index 6b34d04..dccb07f 100644
21582 --- a/arch/x86/lib/copy_page_64.S
21583 +++ b/arch/x86/lib/copy_page_64.S
21584 @@ -9,6 +9,7 @@ copy_page_c:
21585 CFI_STARTPROC
21586 movl $4096/8,%ecx
21587 rep movsq
21588 + pax_force_retaddr
21589 ret
21590 CFI_ENDPROC
21591 ENDPROC(copy_page_c)
21592 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21593
21594 ENTRY(copy_page)
21595 CFI_STARTPROC
21596 - subq $2*8,%rsp
21597 - CFI_ADJUST_CFA_OFFSET 2*8
21598 + subq $3*8,%rsp
21599 + CFI_ADJUST_CFA_OFFSET 3*8
21600 movq %rbx,(%rsp)
21601 CFI_REL_OFFSET rbx, 0
21602 movq %r12,1*8(%rsp)
21603 CFI_REL_OFFSET r12, 1*8
21604 + movq %r13,2*8(%rsp)
21605 + CFI_REL_OFFSET r13, 2*8
21606
21607 movl $(4096/64)-5,%ecx
21608 .p2align 4
21609 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21610 movq 16 (%rsi), %rdx
21611 movq 24 (%rsi), %r8
21612 movq 32 (%rsi), %r9
21613 - movq 40 (%rsi), %r10
21614 + movq 40 (%rsi), %r13
21615 movq 48 (%rsi), %r11
21616 movq 56 (%rsi), %r12
21617
21618 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21619 movq %rdx, 16 (%rdi)
21620 movq %r8, 24 (%rdi)
21621 movq %r9, 32 (%rdi)
21622 - movq %r10, 40 (%rdi)
21623 + movq %r13, 40 (%rdi)
21624 movq %r11, 48 (%rdi)
21625 movq %r12, 56 (%rdi)
21626
21627 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21628 movq 16 (%rsi), %rdx
21629 movq 24 (%rsi), %r8
21630 movq 32 (%rsi), %r9
21631 - movq 40 (%rsi), %r10
21632 + movq 40 (%rsi), %r13
21633 movq 48 (%rsi), %r11
21634 movq 56 (%rsi), %r12
21635
21636 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21637 movq %rdx, 16 (%rdi)
21638 movq %r8, 24 (%rdi)
21639 movq %r9, 32 (%rdi)
21640 - movq %r10, 40 (%rdi)
21641 + movq %r13, 40 (%rdi)
21642 movq %r11, 48 (%rdi)
21643 movq %r12, 56 (%rdi)
21644
21645 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21646 CFI_RESTORE rbx
21647 movq 1*8(%rsp),%r12
21648 CFI_RESTORE r12
21649 - addq $2*8,%rsp
21650 - CFI_ADJUST_CFA_OFFSET -2*8
21651 + movq 2*8(%rsp),%r13
21652 + CFI_RESTORE r13
21653 + addq $3*8,%rsp
21654 + CFI_ADJUST_CFA_OFFSET -3*8
21655 + pax_force_retaddr
21656 ret
21657 .Lcopy_page_end:
21658 CFI_ENDPROC
21659 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21660
21661 #include <asm/cpufeature.h>
21662
21663 - .section .altinstr_replacement,"ax"
21664 + .section .altinstr_replacement,"a"
21665 1: .byte 0xeb /* jmp <disp8> */
21666 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21667 2:
21668 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21669 index 5b2995f..78e7644 100644
21670 --- a/arch/x86/lib/copy_user_64.S
21671 +++ b/arch/x86/lib/copy_user_64.S
21672 @@ -17,6 +17,7 @@
21673 #include <asm/cpufeature.h>
21674 #include <asm/alternative-asm.h>
21675 #include <asm/asm.h>
21676 +#include <asm/pgtable.h>
21677
21678 /*
21679 * By placing feature2 after feature1 in altinstructions section, we logically
21680 @@ -30,7 +31,7 @@
21681 .byte 0xe9 /* 32bit jump */
21682 .long \orig-1f /* by default jump to orig */
21683 1:
21684 - .section .altinstr_replacement,"ax"
21685 + .section .altinstr_replacement,"a"
21686 2: .byte 0xe9 /* near jump with 32bit immediate */
21687 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21688 3: .byte 0xe9 /* near jump with 32bit immediate */
21689 @@ -69,47 +70,20 @@
21690 #endif
21691 .endm
21692
21693 -/* Standard copy_to_user with segment limit checking */
21694 -ENTRY(_copy_to_user)
21695 - CFI_STARTPROC
21696 - GET_THREAD_INFO(%rax)
21697 - movq %rdi,%rcx
21698 - addq %rdx,%rcx
21699 - jc bad_to_user
21700 - cmpq TI_addr_limit(%rax),%rcx
21701 - ja bad_to_user
21702 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21703 - copy_user_generic_unrolled,copy_user_generic_string, \
21704 - copy_user_enhanced_fast_string
21705 - CFI_ENDPROC
21706 -ENDPROC(_copy_to_user)
21707 -
21708 -/* Standard copy_from_user with segment limit checking */
21709 -ENTRY(_copy_from_user)
21710 - CFI_STARTPROC
21711 - GET_THREAD_INFO(%rax)
21712 - movq %rsi,%rcx
21713 - addq %rdx,%rcx
21714 - jc bad_from_user
21715 - cmpq TI_addr_limit(%rax),%rcx
21716 - ja bad_from_user
21717 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21718 - copy_user_generic_unrolled,copy_user_generic_string, \
21719 - copy_user_enhanced_fast_string
21720 - CFI_ENDPROC
21721 -ENDPROC(_copy_from_user)
21722 -
21723 .section .fixup,"ax"
21724 /* must zero dest */
21725 ENTRY(bad_from_user)
21726 bad_from_user:
21727 CFI_STARTPROC
21728 + testl %edx,%edx
21729 + js bad_to_user
21730 movl %edx,%ecx
21731 xorl %eax,%eax
21732 rep
21733 stosb
21734 bad_to_user:
21735 movl %edx,%eax
21736 + pax_force_retaddr
21737 ret
21738 CFI_ENDPROC
21739 ENDPROC(bad_from_user)
21740 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21741 jz 17f
21742 1: movq (%rsi),%r8
21743 2: movq 1*8(%rsi),%r9
21744 -3: movq 2*8(%rsi),%r10
21745 +3: movq 2*8(%rsi),%rax
21746 4: movq 3*8(%rsi),%r11
21747 5: movq %r8,(%rdi)
21748 6: movq %r9,1*8(%rdi)
21749 -7: movq %r10,2*8(%rdi)
21750 +7: movq %rax,2*8(%rdi)
21751 8: movq %r11,3*8(%rdi)
21752 9: movq 4*8(%rsi),%r8
21753 10: movq 5*8(%rsi),%r9
21754 -11: movq 6*8(%rsi),%r10
21755 +11: movq 6*8(%rsi),%rax
21756 12: movq 7*8(%rsi),%r11
21757 13: movq %r8,4*8(%rdi)
21758 14: movq %r9,5*8(%rdi)
21759 -15: movq %r10,6*8(%rdi)
21760 +15: movq %rax,6*8(%rdi)
21761 16: movq %r11,7*8(%rdi)
21762 leaq 64(%rsi),%rsi
21763 leaq 64(%rdi),%rdi
21764 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21765 decl %ecx
21766 jnz 21b
21767 23: xor %eax,%eax
21768 + pax_force_retaddr
21769 ret
21770
21771 .section .fixup,"ax"
21772 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21773 3: rep
21774 movsb
21775 4: xorl %eax,%eax
21776 + pax_force_retaddr
21777 ret
21778
21779 .section .fixup,"ax"
21780 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21781 1: rep
21782 movsb
21783 2: xorl %eax,%eax
21784 + pax_force_retaddr
21785 ret
21786
21787 .section .fixup,"ax"
21788 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21789 index cacddc7..09d49e4 100644
21790 --- a/arch/x86/lib/copy_user_nocache_64.S
21791 +++ b/arch/x86/lib/copy_user_nocache_64.S
21792 @@ -8,6 +8,7 @@
21793
21794 #include <linux/linkage.h>
21795 #include <asm/dwarf2.h>
21796 +#include <asm/alternative-asm.h>
21797
21798 #define FIX_ALIGNMENT 1
21799
21800 @@ -15,6 +16,7 @@
21801 #include <asm/asm-offsets.h>
21802 #include <asm/thread_info.h>
21803 #include <asm/asm.h>
21804 +#include <asm/pgtable.h>
21805
21806 .macro ALIGN_DESTINATION
21807 #ifdef FIX_ALIGNMENT
21808 @@ -48,6 +50,15 @@
21809 */
21810 ENTRY(__copy_user_nocache)
21811 CFI_STARTPROC
21812 +
21813 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21814 + mov $PAX_USER_SHADOW_BASE,%rcx
21815 + cmp %rcx,%rsi
21816 + jae 1f
21817 + add %rcx,%rsi
21818 +1:
21819 +#endif
21820 +
21821 cmpl $8,%edx
21822 jb 20f /* less then 8 bytes, go to byte copy loop */
21823 ALIGN_DESTINATION
21824 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21825 jz 17f
21826 1: movq (%rsi),%r8
21827 2: movq 1*8(%rsi),%r9
21828 -3: movq 2*8(%rsi),%r10
21829 +3: movq 2*8(%rsi),%rax
21830 4: movq 3*8(%rsi),%r11
21831 5: movnti %r8,(%rdi)
21832 6: movnti %r9,1*8(%rdi)
21833 -7: movnti %r10,2*8(%rdi)
21834 +7: movnti %rax,2*8(%rdi)
21835 8: movnti %r11,3*8(%rdi)
21836 9: movq 4*8(%rsi),%r8
21837 10: movq 5*8(%rsi),%r9
21838 -11: movq 6*8(%rsi),%r10
21839 +11: movq 6*8(%rsi),%rax
21840 12: movq 7*8(%rsi),%r11
21841 13: movnti %r8,4*8(%rdi)
21842 14: movnti %r9,5*8(%rdi)
21843 -15: movnti %r10,6*8(%rdi)
21844 +15: movnti %rax,6*8(%rdi)
21845 16: movnti %r11,7*8(%rdi)
21846 leaq 64(%rsi),%rsi
21847 leaq 64(%rdi),%rdi
21848 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21849 jnz 21b
21850 23: xorl %eax,%eax
21851 sfence
21852 + pax_force_retaddr
21853 ret
21854
21855 .section .fixup,"ax"
21856 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21857 index 2419d5f..953ee51 100644
21858 --- a/arch/x86/lib/csum-copy_64.S
21859 +++ b/arch/x86/lib/csum-copy_64.S
21860 @@ -9,6 +9,7 @@
21861 #include <asm/dwarf2.h>
21862 #include <asm/errno.h>
21863 #include <asm/asm.h>
21864 +#include <asm/alternative-asm.h>
21865
21866 /*
21867 * Checksum copy with exception handling.
21868 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21869 CFI_RESTORE rbp
21870 addq $7*8, %rsp
21871 CFI_ADJUST_CFA_OFFSET -7*8
21872 + pax_force_retaddr 0, 1
21873 ret
21874 CFI_RESTORE_STATE
21875
21876 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21877 index 25b7ae8..3b52ccd 100644
21878 --- a/arch/x86/lib/csum-wrappers_64.c
21879 +++ b/arch/x86/lib/csum-wrappers_64.c
21880 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21881 len -= 2;
21882 }
21883 }
21884 - isum = csum_partial_copy_generic((__force const void *)src,
21885 +
21886 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21887 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21888 + src += PAX_USER_SHADOW_BASE;
21889 +#endif
21890 +
21891 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21892 dst, len, isum, errp, NULL);
21893 if (unlikely(*errp))
21894 goto out_err;
21895 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21896 }
21897
21898 *errp = 0;
21899 - return csum_partial_copy_generic(src, (void __force *)dst,
21900 +
21901 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21902 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21903 + dst += PAX_USER_SHADOW_BASE;
21904 +#endif
21905 +
21906 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21907 len, isum, NULL, errp);
21908 }
21909 EXPORT_SYMBOL(csum_partial_copy_to_user);
21910 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21911 index b33b1fb..219f389 100644
21912 --- a/arch/x86/lib/getuser.S
21913 +++ b/arch/x86/lib/getuser.S
21914 @@ -33,15 +33,38 @@
21915 #include <asm/asm-offsets.h>
21916 #include <asm/thread_info.h>
21917 #include <asm/asm.h>
21918 +#include <asm/segment.h>
21919 +#include <asm/pgtable.h>
21920 +#include <asm/alternative-asm.h>
21921 +
21922 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21923 +#define __copyuser_seg gs;
21924 +#else
21925 +#define __copyuser_seg
21926 +#endif
21927
21928 .text
21929 ENTRY(__get_user_1)
21930 CFI_STARTPROC
21931 +
21932 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21933 GET_THREAD_INFO(%_ASM_DX)
21934 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21935 jae bad_get_user
21936 -1: movzb (%_ASM_AX),%edx
21937 +
21938 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21939 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21940 + cmp %_ASM_DX,%_ASM_AX
21941 + jae 1234f
21942 + add %_ASM_DX,%_ASM_AX
21943 +1234:
21944 +#endif
21945 +
21946 +#endif
21947 +
21948 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21949 xor %eax,%eax
21950 + pax_force_retaddr
21951 ret
21952 CFI_ENDPROC
21953 ENDPROC(__get_user_1)
21954 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21955 ENTRY(__get_user_2)
21956 CFI_STARTPROC
21957 add $1,%_ASM_AX
21958 +
21959 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21960 jc bad_get_user
21961 GET_THREAD_INFO(%_ASM_DX)
21962 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21963 jae bad_get_user
21964 -2: movzwl -1(%_ASM_AX),%edx
21965 +
21966 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21967 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21968 + cmp %_ASM_DX,%_ASM_AX
21969 + jae 1234f
21970 + add %_ASM_DX,%_ASM_AX
21971 +1234:
21972 +#endif
21973 +
21974 +#endif
21975 +
21976 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21977 xor %eax,%eax
21978 + pax_force_retaddr
21979 ret
21980 CFI_ENDPROC
21981 ENDPROC(__get_user_2)
21982 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21983 ENTRY(__get_user_4)
21984 CFI_STARTPROC
21985 add $3,%_ASM_AX
21986 +
21987 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21988 jc bad_get_user
21989 GET_THREAD_INFO(%_ASM_DX)
21990 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21991 jae bad_get_user
21992 -3: mov -3(%_ASM_AX),%edx
21993 +
21994 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21995 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21996 + cmp %_ASM_DX,%_ASM_AX
21997 + jae 1234f
21998 + add %_ASM_DX,%_ASM_AX
21999 +1234:
22000 +#endif
22001 +
22002 +#endif
22003 +
22004 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
22005 xor %eax,%eax
22006 + pax_force_retaddr
22007 ret
22008 CFI_ENDPROC
22009 ENDPROC(__get_user_4)
22010 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
22011 GET_THREAD_INFO(%_ASM_DX)
22012 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22013 jae bad_get_user
22014 +
22015 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22016 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22017 + cmp %_ASM_DX,%_ASM_AX
22018 + jae 1234f
22019 + add %_ASM_DX,%_ASM_AX
22020 +1234:
22021 +#endif
22022 +
22023 4: movq -7(%_ASM_AX),%_ASM_DX
22024 xor %eax,%eax
22025 + pax_force_retaddr
22026 ret
22027 CFI_ENDPROC
22028 ENDPROC(__get_user_8)
22029 @@ -91,6 +152,7 @@ bad_get_user:
22030 CFI_STARTPROC
22031 xor %edx,%edx
22032 mov $(-EFAULT),%_ASM_AX
22033 + pax_force_retaddr
22034 ret
22035 CFI_ENDPROC
22036 END(bad_get_user)
22037 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
22038 index b1e6c4b..21ae8fc 100644
22039 --- a/arch/x86/lib/insn.c
22040 +++ b/arch/x86/lib/insn.c
22041 @@ -21,6 +21,11 @@
22042 #include <linux/string.h>
22043 #include <asm/inat.h>
22044 #include <asm/insn.h>
22045 +#ifdef __KERNEL__
22046 +#include <asm/pgtable_types.h>
22047 +#else
22048 +#define ktla_ktva(addr) addr
22049 +#endif
22050
22051 /* Verify next sizeof(t) bytes can be on the same instruction */
22052 #define validate_next(t, insn, n) \
22053 @@ -49,8 +54,8 @@
22054 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22055 {
22056 memset(insn, 0, sizeof(*insn));
22057 - insn->kaddr = kaddr;
22058 - insn->next_byte = kaddr;
22059 + insn->kaddr = ktla_ktva(kaddr);
22060 + insn->next_byte = ktla_ktva(kaddr);
22061 insn->x86_64 = x86_64 ? 1 : 0;
22062 insn->opnd_bytes = 4;
22063 if (x86_64)
22064 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22065 index 05a95e7..326f2fa 100644
22066 --- a/arch/x86/lib/iomap_copy_64.S
22067 +++ b/arch/x86/lib/iomap_copy_64.S
22068 @@ -17,6 +17,7 @@
22069
22070 #include <linux/linkage.h>
22071 #include <asm/dwarf2.h>
22072 +#include <asm/alternative-asm.h>
22073
22074 /*
22075 * override generic version in lib/iomap_copy.c
22076 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22077 CFI_STARTPROC
22078 movl %edx,%ecx
22079 rep movsd
22080 + pax_force_retaddr
22081 ret
22082 CFI_ENDPROC
22083 ENDPROC(__iowrite32_copy)
22084 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22085 index 1c273be..da9cc0e 100644
22086 --- a/arch/x86/lib/memcpy_64.S
22087 +++ b/arch/x86/lib/memcpy_64.S
22088 @@ -33,6 +33,7 @@
22089 rep movsq
22090 movl %edx, %ecx
22091 rep movsb
22092 + pax_force_retaddr
22093 ret
22094 .Lmemcpy_e:
22095 .previous
22096 @@ -49,6 +50,7 @@
22097 movq %rdi, %rax
22098 movq %rdx, %rcx
22099 rep movsb
22100 + pax_force_retaddr
22101 ret
22102 .Lmemcpy_e_e:
22103 .previous
22104 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22105 */
22106 movq 0*8(%rsi), %r8
22107 movq 1*8(%rsi), %r9
22108 - movq 2*8(%rsi), %r10
22109 + movq 2*8(%rsi), %rcx
22110 movq 3*8(%rsi), %r11
22111 leaq 4*8(%rsi), %rsi
22112
22113 movq %r8, 0*8(%rdi)
22114 movq %r9, 1*8(%rdi)
22115 - movq %r10, 2*8(%rdi)
22116 + movq %rcx, 2*8(%rdi)
22117 movq %r11, 3*8(%rdi)
22118 leaq 4*8(%rdi), %rdi
22119 jae .Lcopy_forward_loop
22120 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22121 subq $0x20, %rdx
22122 movq -1*8(%rsi), %r8
22123 movq -2*8(%rsi), %r9
22124 - movq -3*8(%rsi), %r10
22125 + movq -3*8(%rsi), %rcx
22126 movq -4*8(%rsi), %r11
22127 leaq -4*8(%rsi), %rsi
22128 movq %r8, -1*8(%rdi)
22129 movq %r9, -2*8(%rdi)
22130 - movq %r10, -3*8(%rdi)
22131 + movq %rcx, -3*8(%rdi)
22132 movq %r11, -4*8(%rdi)
22133 leaq -4*8(%rdi), %rdi
22134 jae .Lcopy_backward_loop
22135 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22136 */
22137 movq 0*8(%rsi), %r8
22138 movq 1*8(%rsi), %r9
22139 - movq -2*8(%rsi, %rdx), %r10
22140 + movq -2*8(%rsi, %rdx), %rcx
22141 movq -1*8(%rsi, %rdx), %r11
22142 movq %r8, 0*8(%rdi)
22143 movq %r9, 1*8(%rdi)
22144 - movq %r10, -2*8(%rdi, %rdx)
22145 + movq %rcx, -2*8(%rdi, %rdx)
22146 movq %r11, -1*8(%rdi, %rdx)
22147 + pax_force_retaddr
22148 retq
22149 .p2align 4
22150 .Lless_16bytes:
22151 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22152 movq -1*8(%rsi, %rdx), %r9
22153 movq %r8, 0*8(%rdi)
22154 movq %r9, -1*8(%rdi, %rdx)
22155 + pax_force_retaddr
22156 retq
22157 .p2align 4
22158 .Lless_8bytes:
22159 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22160 movl -4(%rsi, %rdx), %r8d
22161 movl %ecx, (%rdi)
22162 movl %r8d, -4(%rdi, %rdx)
22163 + pax_force_retaddr
22164 retq
22165 .p2align 4
22166 .Lless_3bytes:
22167 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22168 movb %cl, (%rdi)
22169
22170 .Lend:
22171 + pax_force_retaddr
22172 retq
22173 CFI_ENDPROC
22174 ENDPROC(memcpy)
22175 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22176 index ee16461..c39c199 100644
22177 --- a/arch/x86/lib/memmove_64.S
22178 +++ b/arch/x86/lib/memmove_64.S
22179 @@ -61,13 +61,13 @@ ENTRY(memmove)
22180 5:
22181 sub $0x20, %rdx
22182 movq 0*8(%rsi), %r11
22183 - movq 1*8(%rsi), %r10
22184 + movq 1*8(%rsi), %rcx
22185 movq 2*8(%rsi), %r9
22186 movq 3*8(%rsi), %r8
22187 leaq 4*8(%rsi), %rsi
22188
22189 movq %r11, 0*8(%rdi)
22190 - movq %r10, 1*8(%rdi)
22191 + movq %rcx, 1*8(%rdi)
22192 movq %r9, 2*8(%rdi)
22193 movq %r8, 3*8(%rdi)
22194 leaq 4*8(%rdi), %rdi
22195 @@ -81,10 +81,10 @@ ENTRY(memmove)
22196 4:
22197 movq %rdx, %rcx
22198 movq -8(%rsi, %rdx), %r11
22199 - lea -8(%rdi, %rdx), %r10
22200 + lea -8(%rdi, %rdx), %r9
22201 shrq $3, %rcx
22202 rep movsq
22203 - movq %r11, (%r10)
22204 + movq %r11, (%r9)
22205 jmp 13f
22206 .Lmemmove_end_forward:
22207
22208 @@ -95,14 +95,14 @@ ENTRY(memmove)
22209 7:
22210 movq %rdx, %rcx
22211 movq (%rsi), %r11
22212 - movq %rdi, %r10
22213 + movq %rdi, %r9
22214 leaq -8(%rsi, %rdx), %rsi
22215 leaq -8(%rdi, %rdx), %rdi
22216 shrq $3, %rcx
22217 std
22218 rep movsq
22219 cld
22220 - movq %r11, (%r10)
22221 + movq %r11, (%r9)
22222 jmp 13f
22223
22224 /*
22225 @@ -127,13 +127,13 @@ ENTRY(memmove)
22226 8:
22227 subq $0x20, %rdx
22228 movq -1*8(%rsi), %r11
22229 - movq -2*8(%rsi), %r10
22230 + movq -2*8(%rsi), %rcx
22231 movq -3*8(%rsi), %r9
22232 movq -4*8(%rsi), %r8
22233 leaq -4*8(%rsi), %rsi
22234
22235 movq %r11, -1*8(%rdi)
22236 - movq %r10, -2*8(%rdi)
22237 + movq %rcx, -2*8(%rdi)
22238 movq %r9, -3*8(%rdi)
22239 movq %r8, -4*8(%rdi)
22240 leaq -4*8(%rdi), %rdi
22241 @@ -151,11 +151,11 @@ ENTRY(memmove)
22242 * Move data from 16 bytes to 31 bytes.
22243 */
22244 movq 0*8(%rsi), %r11
22245 - movq 1*8(%rsi), %r10
22246 + movq 1*8(%rsi), %rcx
22247 movq -2*8(%rsi, %rdx), %r9
22248 movq -1*8(%rsi, %rdx), %r8
22249 movq %r11, 0*8(%rdi)
22250 - movq %r10, 1*8(%rdi)
22251 + movq %rcx, 1*8(%rdi)
22252 movq %r9, -2*8(%rdi, %rdx)
22253 movq %r8, -1*8(%rdi, %rdx)
22254 jmp 13f
22255 @@ -167,9 +167,9 @@ ENTRY(memmove)
22256 * Move data from 8 bytes to 15 bytes.
22257 */
22258 movq 0*8(%rsi), %r11
22259 - movq -1*8(%rsi, %rdx), %r10
22260 + movq -1*8(%rsi, %rdx), %r9
22261 movq %r11, 0*8(%rdi)
22262 - movq %r10, -1*8(%rdi, %rdx)
22263 + movq %r9, -1*8(%rdi, %rdx)
22264 jmp 13f
22265 10:
22266 cmpq $4, %rdx
22267 @@ -178,9 +178,9 @@ ENTRY(memmove)
22268 * Move data from 4 bytes to 7 bytes.
22269 */
22270 movl (%rsi), %r11d
22271 - movl -4(%rsi, %rdx), %r10d
22272 + movl -4(%rsi, %rdx), %r9d
22273 movl %r11d, (%rdi)
22274 - movl %r10d, -4(%rdi, %rdx)
22275 + movl %r9d, -4(%rdi, %rdx)
22276 jmp 13f
22277 11:
22278 cmp $2, %rdx
22279 @@ -189,9 +189,9 @@ ENTRY(memmove)
22280 * Move data from 2 bytes to 3 bytes.
22281 */
22282 movw (%rsi), %r11w
22283 - movw -2(%rsi, %rdx), %r10w
22284 + movw -2(%rsi, %rdx), %r9w
22285 movw %r11w, (%rdi)
22286 - movw %r10w, -2(%rdi, %rdx)
22287 + movw %r9w, -2(%rdi, %rdx)
22288 jmp 13f
22289 12:
22290 cmp $1, %rdx
22291 @@ -202,6 +202,7 @@ ENTRY(memmove)
22292 movb (%rsi), %r11b
22293 movb %r11b, (%rdi)
22294 13:
22295 + pax_force_retaddr
22296 retq
22297 CFI_ENDPROC
22298
22299 @@ -210,6 +211,7 @@ ENTRY(memmove)
22300 /* Forward moving data. */
22301 movq %rdx, %rcx
22302 rep movsb
22303 + pax_force_retaddr
22304 retq
22305 .Lmemmove_end_forward_efs:
22306 .previous
22307 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22308 index 2dcb380..963660a 100644
22309 --- a/arch/x86/lib/memset_64.S
22310 +++ b/arch/x86/lib/memset_64.S
22311 @@ -30,6 +30,7 @@
22312 movl %edx,%ecx
22313 rep stosb
22314 movq %r9,%rax
22315 + pax_force_retaddr
22316 ret
22317 .Lmemset_e:
22318 .previous
22319 @@ -52,6 +53,7 @@
22320 movq %rdx,%rcx
22321 rep stosb
22322 movq %r9,%rax
22323 + pax_force_retaddr
22324 ret
22325 .Lmemset_e_e:
22326 .previous
22327 @@ -59,7 +61,7 @@
22328 ENTRY(memset)
22329 ENTRY(__memset)
22330 CFI_STARTPROC
22331 - movq %rdi,%r10
22332 + movq %rdi,%r11
22333
22334 /* expand byte value */
22335 movzbl %sil,%ecx
22336 @@ -117,7 +119,8 @@ ENTRY(__memset)
22337 jnz .Lloop_1
22338
22339 .Lende:
22340 - movq %r10,%rax
22341 + movq %r11,%rax
22342 + pax_force_retaddr
22343 ret
22344
22345 CFI_RESTORE_STATE
22346 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22347 index c9f2d9b..e7fd2c0 100644
22348 --- a/arch/x86/lib/mmx_32.c
22349 +++ b/arch/x86/lib/mmx_32.c
22350 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22351 {
22352 void *p;
22353 int i;
22354 + unsigned long cr0;
22355
22356 if (unlikely(in_interrupt()))
22357 return __memcpy(to, from, len);
22358 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22359 kernel_fpu_begin();
22360
22361 __asm__ __volatile__ (
22362 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22363 - " prefetch 64(%0)\n"
22364 - " prefetch 128(%0)\n"
22365 - " prefetch 192(%0)\n"
22366 - " prefetch 256(%0)\n"
22367 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22368 + " prefetch 64(%1)\n"
22369 + " prefetch 128(%1)\n"
22370 + " prefetch 192(%1)\n"
22371 + " prefetch 256(%1)\n"
22372 "2: \n"
22373 ".section .fixup, \"ax\"\n"
22374 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22375 + "3: \n"
22376 +
22377 +#ifdef CONFIG_PAX_KERNEXEC
22378 + " movl %%cr0, %0\n"
22379 + " movl %0, %%eax\n"
22380 + " andl $0xFFFEFFFF, %%eax\n"
22381 + " movl %%eax, %%cr0\n"
22382 +#endif
22383 +
22384 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22385 +
22386 +#ifdef CONFIG_PAX_KERNEXEC
22387 + " movl %0, %%cr0\n"
22388 +#endif
22389 +
22390 " jmp 2b\n"
22391 ".previous\n"
22392 _ASM_EXTABLE(1b, 3b)
22393 - : : "r" (from));
22394 + : "=&r" (cr0) : "r" (from) : "ax");
22395
22396 for ( ; i > 5; i--) {
22397 __asm__ __volatile__ (
22398 - "1: prefetch 320(%0)\n"
22399 - "2: movq (%0), %%mm0\n"
22400 - " movq 8(%0), %%mm1\n"
22401 - " movq 16(%0), %%mm2\n"
22402 - " movq 24(%0), %%mm3\n"
22403 - " movq %%mm0, (%1)\n"
22404 - " movq %%mm1, 8(%1)\n"
22405 - " movq %%mm2, 16(%1)\n"
22406 - " movq %%mm3, 24(%1)\n"
22407 - " movq 32(%0), %%mm0\n"
22408 - " movq 40(%0), %%mm1\n"
22409 - " movq 48(%0), %%mm2\n"
22410 - " movq 56(%0), %%mm3\n"
22411 - " movq %%mm0, 32(%1)\n"
22412 - " movq %%mm1, 40(%1)\n"
22413 - " movq %%mm2, 48(%1)\n"
22414 - " movq %%mm3, 56(%1)\n"
22415 + "1: prefetch 320(%1)\n"
22416 + "2: movq (%1), %%mm0\n"
22417 + " movq 8(%1), %%mm1\n"
22418 + " movq 16(%1), %%mm2\n"
22419 + " movq 24(%1), %%mm3\n"
22420 + " movq %%mm0, (%2)\n"
22421 + " movq %%mm1, 8(%2)\n"
22422 + " movq %%mm2, 16(%2)\n"
22423 + " movq %%mm3, 24(%2)\n"
22424 + " movq 32(%1), %%mm0\n"
22425 + " movq 40(%1), %%mm1\n"
22426 + " movq 48(%1), %%mm2\n"
22427 + " movq 56(%1), %%mm3\n"
22428 + " movq %%mm0, 32(%2)\n"
22429 + " movq %%mm1, 40(%2)\n"
22430 + " movq %%mm2, 48(%2)\n"
22431 + " movq %%mm3, 56(%2)\n"
22432 ".section .fixup, \"ax\"\n"
22433 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22434 + "3:\n"
22435 +
22436 +#ifdef CONFIG_PAX_KERNEXEC
22437 + " movl %%cr0, %0\n"
22438 + " movl %0, %%eax\n"
22439 + " andl $0xFFFEFFFF, %%eax\n"
22440 + " movl %%eax, %%cr0\n"
22441 +#endif
22442 +
22443 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22444 +
22445 +#ifdef CONFIG_PAX_KERNEXEC
22446 + " movl %0, %%cr0\n"
22447 +#endif
22448 +
22449 " jmp 2b\n"
22450 ".previous\n"
22451 _ASM_EXTABLE(1b, 3b)
22452 - : : "r" (from), "r" (to) : "memory");
22453 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22454
22455 from += 64;
22456 to += 64;
22457 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22458 static void fast_copy_page(void *to, void *from)
22459 {
22460 int i;
22461 + unsigned long cr0;
22462
22463 kernel_fpu_begin();
22464
22465 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22466 * but that is for later. -AV
22467 */
22468 __asm__ __volatile__(
22469 - "1: prefetch (%0)\n"
22470 - " prefetch 64(%0)\n"
22471 - " prefetch 128(%0)\n"
22472 - " prefetch 192(%0)\n"
22473 - " prefetch 256(%0)\n"
22474 + "1: prefetch (%1)\n"
22475 + " prefetch 64(%1)\n"
22476 + " prefetch 128(%1)\n"
22477 + " prefetch 192(%1)\n"
22478 + " prefetch 256(%1)\n"
22479 "2: \n"
22480 ".section .fixup, \"ax\"\n"
22481 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22482 + "3: \n"
22483 +
22484 +#ifdef CONFIG_PAX_KERNEXEC
22485 + " movl %%cr0, %0\n"
22486 + " movl %0, %%eax\n"
22487 + " andl $0xFFFEFFFF, %%eax\n"
22488 + " movl %%eax, %%cr0\n"
22489 +#endif
22490 +
22491 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22492 +
22493 +#ifdef CONFIG_PAX_KERNEXEC
22494 + " movl %0, %%cr0\n"
22495 +#endif
22496 +
22497 " jmp 2b\n"
22498 ".previous\n"
22499 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22500 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22501
22502 for (i = 0; i < (4096-320)/64; i++) {
22503 __asm__ __volatile__ (
22504 - "1: prefetch 320(%0)\n"
22505 - "2: movq (%0), %%mm0\n"
22506 - " movntq %%mm0, (%1)\n"
22507 - " movq 8(%0), %%mm1\n"
22508 - " movntq %%mm1, 8(%1)\n"
22509 - " movq 16(%0), %%mm2\n"
22510 - " movntq %%mm2, 16(%1)\n"
22511 - " movq 24(%0), %%mm3\n"
22512 - " movntq %%mm3, 24(%1)\n"
22513 - " movq 32(%0), %%mm4\n"
22514 - " movntq %%mm4, 32(%1)\n"
22515 - " movq 40(%0), %%mm5\n"
22516 - " movntq %%mm5, 40(%1)\n"
22517 - " movq 48(%0), %%mm6\n"
22518 - " movntq %%mm6, 48(%1)\n"
22519 - " movq 56(%0), %%mm7\n"
22520 - " movntq %%mm7, 56(%1)\n"
22521 + "1: prefetch 320(%1)\n"
22522 + "2: movq (%1), %%mm0\n"
22523 + " movntq %%mm0, (%2)\n"
22524 + " movq 8(%1), %%mm1\n"
22525 + " movntq %%mm1, 8(%2)\n"
22526 + " movq 16(%1), %%mm2\n"
22527 + " movntq %%mm2, 16(%2)\n"
22528 + " movq 24(%1), %%mm3\n"
22529 + " movntq %%mm3, 24(%2)\n"
22530 + " movq 32(%1), %%mm4\n"
22531 + " movntq %%mm4, 32(%2)\n"
22532 + " movq 40(%1), %%mm5\n"
22533 + " movntq %%mm5, 40(%2)\n"
22534 + " movq 48(%1), %%mm6\n"
22535 + " movntq %%mm6, 48(%2)\n"
22536 + " movq 56(%1), %%mm7\n"
22537 + " movntq %%mm7, 56(%2)\n"
22538 ".section .fixup, \"ax\"\n"
22539 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22540 + "3:\n"
22541 +
22542 +#ifdef CONFIG_PAX_KERNEXEC
22543 + " movl %%cr0, %0\n"
22544 + " movl %0, %%eax\n"
22545 + " andl $0xFFFEFFFF, %%eax\n"
22546 + " movl %%eax, %%cr0\n"
22547 +#endif
22548 +
22549 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22550 +
22551 +#ifdef CONFIG_PAX_KERNEXEC
22552 + " movl %0, %%cr0\n"
22553 +#endif
22554 +
22555 " jmp 2b\n"
22556 ".previous\n"
22557 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22558 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22559
22560 from += 64;
22561 to += 64;
22562 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22563 static void fast_copy_page(void *to, void *from)
22564 {
22565 int i;
22566 + unsigned long cr0;
22567
22568 kernel_fpu_begin();
22569
22570 __asm__ __volatile__ (
22571 - "1: prefetch (%0)\n"
22572 - " prefetch 64(%0)\n"
22573 - " prefetch 128(%0)\n"
22574 - " prefetch 192(%0)\n"
22575 - " prefetch 256(%0)\n"
22576 + "1: prefetch (%1)\n"
22577 + " prefetch 64(%1)\n"
22578 + " prefetch 128(%1)\n"
22579 + " prefetch 192(%1)\n"
22580 + " prefetch 256(%1)\n"
22581 "2: \n"
22582 ".section .fixup, \"ax\"\n"
22583 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22584 + "3: \n"
22585 +
22586 +#ifdef CONFIG_PAX_KERNEXEC
22587 + " movl %%cr0, %0\n"
22588 + " movl %0, %%eax\n"
22589 + " andl $0xFFFEFFFF, %%eax\n"
22590 + " movl %%eax, %%cr0\n"
22591 +#endif
22592 +
22593 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22594 +
22595 +#ifdef CONFIG_PAX_KERNEXEC
22596 + " movl %0, %%cr0\n"
22597 +#endif
22598 +
22599 " jmp 2b\n"
22600 ".previous\n"
22601 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22602 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22603
22604 for (i = 0; i < 4096/64; i++) {
22605 __asm__ __volatile__ (
22606 - "1: prefetch 320(%0)\n"
22607 - "2: movq (%0), %%mm0\n"
22608 - " movq 8(%0), %%mm1\n"
22609 - " movq 16(%0), %%mm2\n"
22610 - " movq 24(%0), %%mm3\n"
22611 - " movq %%mm0, (%1)\n"
22612 - " movq %%mm1, 8(%1)\n"
22613 - " movq %%mm2, 16(%1)\n"
22614 - " movq %%mm3, 24(%1)\n"
22615 - " movq 32(%0), %%mm0\n"
22616 - " movq 40(%0), %%mm1\n"
22617 - " movq 48(%0), %%mm2\n"
22618 - " movq 56(%0), %%mm3\n"
22619 - " movq %%mm0, 32(%1)\n"
22620 - " movq %%mm1, 40(%1)\n"
22621 - " movq %%mm2, 48(%1)\n"
22622 - " movq %%mm3, 56(%1)\n"
22623 + "1: prefetch 320(%1)\n"
22624 + "2: movq (%1), %%mm0\n"
22625 + " movq 8(%1), %%mm1\n"
22626 + " movq 16(%1), %%mm2\n"
22627 + " movq 24(%1), %%mm3\n"
22628 + " movq %%mm0, (%2)\n"
22629 + " movq %%mm1, 8(%2)\n"
22630 + " movq %%mm2, 16(%2)\n"
22631 + " movq %%mm3, 24(%2)\n"
22632 + " movq 32(%1), %%mm0\n"
22633 + " movq 40(%1), %%mm1\n"
22634 + " movq 48(%1), %%mm2\n"
22635 + " movq 56(%1), %%mm3\n"
22636 + " movq %%mm0, 32(%2)\n"
22637 + " movq %%mm1, 40(%2)\n"
22638 + " movq %%mm2, 48(%2)\n"
22639 + " movq %%mm3, 56(%2)\n"
22640 ".section .fixup, \"ax\"\n"
22641 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22642 + "3:\n"
22643 +
22644 +#ifdef CONFIG_PAX_KERNEXEC
22645 + " movl %%cr0, %0\n"
22646 + " movl %0, %%eax\n"
22647 + " andl $0xFFFEFFFF, %%eax\n"
22648 + " movl %%eax, %%cr0\n"
22649 +#endif
22650 +
22651 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22652 +
22653 +#ifdef CONFIG_PAX_KERNEXEC
22654 + " movl %0, %%cr0\n"
22655 +#endif
22656 +
22657 " jmp 2b\n"
22658 ".previous\n"
22659 _ASM_EXTABLE(1b, 3b)
22660 - : : "r" (from), "r" (to) : "memory");
22661 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22662
22663 from += 64;
22664 to += 64;
22665 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22666 index f6d13ee..aca5f0b 100644
22667 --- a/arch/x86/lib/msr-reg.S
22668 +++ b/arch/x86/lib/msr-reg.S
22669 @@ -3,6 +3,7 @@
22670 #include <asm/dwarf2.h>
22671 #include <asm/asm.h>
22672 #include <asm/msr.h>
22673 +#include <asm/alternative-asm.h>
22674
22675 #ifdef CONFIG_X86_64
22676 /*
22677 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22678 CFI_STARTPROC
22679 pushq_cfi %rbx
22680 pushq_cfi %rbp
22681 - movq %rdi, %r10 /* Save pointer */
22682 + movq %rdi, %r9 /* Save pointer */
22683 xorl %r11d, %r11d /* Return value */
22684 movl (%rdi), %eax
22685 movl 4(%rdi), %ecx
22686 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22687 movl 28(%rdi), %edi
22688 CFI_REMEMBER_STATE
22689 1: \op
22690 -2: movl %eax, (%r10)
22691 +2: movl %eax, (%r9)
22692 movl %r11d, %eax /* Return value */
22693 - movl %ecx, 4(%r10)
22694 - movl %edx, 8(%r10)
22695 - movl %ebx, 12(%r10)
22696 - movl %ebp, 20(%r10)
22697 - movl %esi, 24(%r10)
22698 - movl %edi, 28(%r10)
22699 + movl %ecx, 4(%r9)
22700 + movl %edx, 8(%r9)
22701 + movl %ebx, 12(%r9)
22702 + movl %ebp, 20(%r9)
22703 + movl %esi, 24(%r9)
22704 + movl %edi, 28(%r9)
22705 popq_cfi %rbp
22706 popq_cfi %rbx
22707 + pax_force_retaddr
22708 ret
22709 3:
22710 CFI_RESTORE_STATE
22711 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22712 index 7f951c8..ebd573a 100644
22713 --- a/arch/x86/lib/putuser.S
22714 +++ b/arch/x86/lib/putuser.S
22715 @@ -15,7 +15,9 @@
22716 #include <asm/thread_info.h>
22717 #include <asm/errno.h>
22718 #include <asm/asm.h>
22719 -
22720 +#include <asm/segment.h>
22721 +#include <asm/pgtable.h>
22722 +#include <asm/alternative-asm.h>
22723
22724 /*
22725 * __put_user_X
22726 @@ -29,52 +31,119 @@
22727 * as they get called from within inline assembly.
22728 */
22729
22730 -#define ENTER CFI_STARTPROC ; \
22731 - GET_THREAD_INFO(%_ASM_BX)
22732 -#define EXIT ret ; \
22733 +#define ENTER CFI_STARTPROC
22734 +#define EXIT pax_force_retaddr; ret ; \
22735 CFI_ENDPROC
22736
22737 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22738 +#define _DEST %_ASM_CX,%_ASM_BX
22739 +#else
22740 +#define _DEST %_ASM_CX
22741 +#endif
22742 +
22743 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22744 +#define __copyuser_seg gs;
22745 +#else
22746 +#define __copyuser_seg
22747 +#endif
22748 +
22749 .text
22750 ENTRY(__put_user_1)
22751 ENTER
22752 +
22753 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22754 + GET_THREAD_INFO(%_ASM_BX)
22755 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22756 jae bad_put_user
22757 -1: movb %al,(%_ASM_CX)
22758 +
22759 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22760 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22761 + cmp %_ASM_BX,%_ASM_CX
22762 + jb 1234f
22763 + xor %ebx,%ebx
22764 +1234:
22765 +#endif
22766 +
22767 +#endif
22768 +
22769 +1: __copyuser_seg movb %al,(_DEST)
22770 xor %eax,%eax
22771 EXIT
22772 ENDPROC(__put_user_1)
22773
22774 ENTRY(__put_user_2)
22775 ENTER
22776 +
22777 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22778 + GET_THREAD_INFO(%_ASM_BX)
22779 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22780 sub $1,%_ASM_BX
22781 cmp %_ASM_BX,%_ASM_CX
22782 jae bad_put_user
22783 -2: movw %ax,(%_ASM_CX)
22784 +
22785 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22786 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22787 + cmp %_ASM_BX,%_ASM_CX
22788 + jb 1234f
22789 + xor %ebx,%ebx
22790 +1234:
22791 +#endif
22792 +
22793 +#endif
22794 +
22795 +2: __copyuser_seg movw %ax,(_DEST)
22796 xor %eax,%eax
22797 EXIT
22798 ENDPROC(__put_user_2)
22799
22800 ENTRY(__put_user_4)
22801 ENTER
22802 +
22803 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22804 + GET_THREAD_INFO(%_ASM_BX)
22805 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22806 sub $3,%_ASM_BX
22807 cmp %_ASM_BX,%_ASM_CX
22808 jae bad_put_user
22809 -3: movl %eax,(%_ASM_CX)
22810 +
22811 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22812 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22813 + cmp %_ASM_BX,%_ASM_CX
22814 + jb 1234f
22815 + xor %ebx,%ebx
22816 +1234:
22817 +#endif
22818 +
22819 +#endif
22820 +
22821 +3: __copyuser_seg movl %eax,(_DEST)
22822 xor %eax,%eax
22823 EXIT
22824 ENDPROC(__put_user_4)
22825
22826 ENTRY(__put_user_8)
22827 ENTER
22828 +
22829 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22830 + GET_THREAD_INFO(%_ASM_BX)
22831 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22832 sub $7,%_ASM_BX
22833 cmp %_ASM_BX,%_ASM_CX
22834 jae bad_put_user
22835 -4: mov %_ASM_AX,(%_ASM_CX)
22836 +
22837 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22838 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22839 + cmp %_ASM_BX,%_ASM_CX
22840 + jb 1234f
22841 + xor %ebx,%ebx
22842 +1234:
22843 +#endif
22844 +
22845 +#endif
22846 +
22847 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22848 #ifdef CONFIG_X86_32
22849 -5: movl %edx,4(%_ASM_CX)
22850 +5: __copyuser_seg movl %edx,4(_DEST)
22851 #endif
22852 xor %eax,%eax
22853 EXIT
22854 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22855 index 1cad221..de671ee 100644
22856 --- a/arch/x86/lib/rwlock.S
22857 +++ b/arch/x86/lib/rwlock.S
22858 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22859 FRAME
22860 0: LOCK_PREFIX
22861 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22862 +
22863 +#ifdef CONFIG_PAX_REFCOUNT
22864 + jno 1234f
22865 + LOCK_PREFIX
22866 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22867 + int $4
22868 +1234:
22869 + _ASM_EXTABLE(1234b, 1234b)
22870 +#endif
22871 +
22872 1: rep; nop
22873 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22874 jne 1b
22875 LOCK_PREFIX
22876 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22877 +
22878 +#ifdef CONFIG_PAX_REFCOUNT
22879 + jno 1234f
22880 + LOCK_PREFIX
22881 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22882 + int $4
22883 +1234:
22884 + _ASM_EXTABLE(1234b, 1234b)
22885 +#endif
22886 +
22887 jnz 0b
22888 ENDFRAME
22889 + pax_force_retaddr
22890 ret
22891 CFI_ENDPROC
22892 END(__write_lock_failed)
22893 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22894 FRAME
22895 0: LOCK_PREFIX
22896 READ_LOCK_SIZE(inc) (%__lock_ptr)
22897 +
22898 +#ifdef CONFIG_PAX_REFCOUNT
22899 + jno 1234f
22900 + LOCK_PREFIX
22901 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22902 + int $4
22903 +1234:
22904 + _ASM_EXTABLE(1234b, 1234b)
22905 +#endif
22906 +
22907 1: rep; nop
22908 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22909 js 1b
22910 LOCK_PREFIX
22911 READ_LOCK_SIZE(dec) (%__lock_ptr)
22912 +
22913 +#ifdef CONFIG_PAX_REFCOUNT
22914 + jno 1234f
22915 + LOCK_PREFIX
22916 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22917 + int $4
22918 +1234:
22919 + _ASM_EXTABLE(1234b, 1234b)
22920 +#endif
22921 +
22922 js 0b
22923 ENDFRAME
22924 + pax_force_retaddr
22925 ret
22926 CFI_ENDPROC
22927 END(__read_lock_failed)
22928 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22929 index 5dff5f0..cadebf4 100644
22930 --- a/arch/x86/lib/rwsem.S
22931 +++ b/arch/x86/lib/rwsem.S
22932 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22933 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22934 CFI_RESTORE __ASM_REG(dx)
22935 restore_common_regs
22936 + pax_force_retaddr
22937 ret
22938 CFI_ENDPROC
22939 ENDPROC(call_rwsem_down_read_failed)
22940 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22941 movq %rax,%rdi
22942 call rwsem_down_write_failed
22943 restore_common_regs
22944 + pax_force_retaddr
22945 ret
22946 CFI_ENDPROC
22947 ENDPROC(call_rwsem_down_write_failed)
22948 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22949 movq %rax,%rdi
22950 call rwsem_wake
22951 restore_common_regs
22952 -1: ret
22953 +1: pax_force_retaddr
22954 + ret
22955 CFI_ENDPROC
22956 ENDPROC(call_rwsem_wake)
22957
22958 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22959 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22960 CFI_RESTORE __ASM_REG(dx)
22961 restore_common_regs
22962 + pax_force_retaddr
22963 ret
22964 CFI_ENDPROC
22965 ENDPROC(call_rwsem_downgrade_wake)
22966 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22967 index a63efd6..ccecad8 100644
22968 --- a/arch/x86/lib/thunk_64.S
22969 +++ b/arch/x86/lib/thunk_64.S
22970 @@ -8,6 +8,7 @@
22971 #include <linux/linkage.h>
22972 #include <asm/dwarf2.h>
22973 #include <asm/calling.h>
22974 +#include <asm/alternative-asm.h>
22975
22976 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22977 .macro THUNK name, func, put_ret_addr_in_rdi=0
22978 @@ -41,5 +42,6 @@
22979 SAVE_ARGS
22980 restore:
22981 RESTORE_ARGS
22982 + pax_force_retaddr
22983 ret
22984 CFI_ENDPROC
22985 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22986 index 1781b2f..90368dd 100644
22987 --- a/arch/x86/lib/usercopy_32.c
22988 +++ b/arch/x86/lib/usercopy_32.c
22989 @@ -42,10 +42,12 @@ do { \
22990 int __d0; \
22991 might_fault(); \
22992 __asm__ __volatile__( \
22993 + __COPYUSER_SET_ES \
22994 "0: rep; stosl\n" \
22995 " movl %2,%0\n" \
22996 "1: rep; stosb\n" \
22997 "2:\n" \
22998 + __COPYUSER_RESTORE_ES \
22999 ".section .fixup,\"ax\"\n" \
23000 "3: lea 0(%2,%0,4),%0\n" \
23001 " jmp 2b\n" \
23002 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
23003
23004 #ifdef CONFIG_X86_INTEL_USERCOPY
23005 static unsigned long
23006 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
23007 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
23008 {
23009 int d0, d1;
23010 __asm__ __volatile__(
23011 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23012 " .align 2,0x90\n"
23013 "3: movl 0(%4), %%eax\n"
23014 "4: movl 4(%4), %%edx\n"
23015 - "5: movl %%eax, 0(%3)\n"
23016 - "6: movl %%edx, 4(%3)\n"
23017 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
23018 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
23019 "7: movl 8(%4), %%eax\n"
23020 "8: movl 12(%4),%%edx\n"
23021 - "9: movl %%eax, 8(%3)\n"
23022 - "10: movl %%edx, 12(%3)\n"
23023 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
23024 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
23025 "11: movl 16(%4), %%eax\n"
23026 "12: movl 20(%4), %%edx\n"
23027 - "13: movl %%eax, 16(%3)\n"
23028 - "14: movl %%edx, 20(%3)\n"
23029 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
23030 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
23031 "15: movl 24(%4), %%eax\n"
23032 "16: movl 28(%4), %%edx\n"
23033 - "17: movl %%eax, 24(%3)\n"
23034 - "18: movl %%edx, 28(%3)\n"
23035 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
23036 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
23037 "19: movl 32(%4), %%eax\n"
23038 "20: movl 36(%4), %%edx\n"
23039 - "21: movl %%eax, 32(%3)\n"
23040 - "22: movl %%edx, 36(%3)\n"
23041 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
23042 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
23043 "23: movl 40(%4), %%eax\n"
23044 "24: movl 44(%4), %%edx\n"
23045 - "25: movl %%eax, 40(%3)\n"
23046 - "26: movl %%edx, 44(%3)\n"
23047 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23048 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23049 "27: movl 48(%4), %%eax\n"
23050 "28: movl 52(%4), %%edx\n"
23051 - "29: movl %%eax, 48(%3)\n"
23052 - "30: movl %%edx, 52(%3)\n"
23053 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23054 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23055 "31: movl 56(%4), %%eax\n"
23056 "32: movl 60(%4), %%edx\n"
23057 - "33: movl %%eax, 56(%3)\n"
23058 - "34: movl %%edx, 60(%3)\n"
23059 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23060 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23061 " addl $-64, %0\n"
23062 " addl $64, %4\n"
23063 " addl $64, %3\n"
23064 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23065 " shrl $2, %0\n"
23066 " andl $3, %%eax\n"
23067 " cld\n"
23068 + __COPYUSER_SET_ES
23069 "99: rep; movsl\n"
23070 "36: movl %%eax, %0\n"
23071 "37: rep; movsb\n"
23072 "100:\n"
23073 + __COPYUSER_RESTORE_ES
23074 ".section .fixup,\"ax\"\n"
23075 "101: lea 0(%%eax,%0,4),%0\n"
23076 " jmp 100b\n"
23077 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23078 }
23079
23080 static unsigned long
23081 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23082 +{
23083 + int d0, d1;
23084 + __asm__ __volatile__(
23085 + " .align 2,0x90\n"
23086 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23087 + " cmpl $67, %0\n"
23088 + " jbe 3f\n"
23089 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23090 + " .align 2,0x90\n"
23091 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23092 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23093 + "5: movl %%eax, 0(%3)\n"
23094 + "6: movl %%edx, 4(%3)\n"
23095 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23096 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23097 + "9: movl %%eax, 8(%3)\n"
23098 + "10: movl %%edx, 12(%3)\n"
23099 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23100 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23101 + "13: movl %%eax, 16(%3)\n"
23102 + "14: movl %%edx, 20(%3)\n"
23103 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23104 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23105 + "17: movl %%eax, 24(%3)\n"
23106 + "18: movl %%edx, 28(%3)\n"
23107 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23108 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23109 + "21: movl %%eax, 32(%3)\n"
23110 + "22: movl %%edx, 36(%3)\n"
23111 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23112 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23113 + "25: movl %%eax, 40(%3)\n"
23114 + "26: movl %%edx, 44(%3)\n"
23115 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23116 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23117 + "29: movl %%eax, 48(%3)\n"
23118 + "30: movl %%edx, 52(%3)\n"
23119 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23120 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23121 + "33: movl %%eax, 56(%3)\n"
23122 + "34: movl %%edx, 60(%3)\n"
23123 + " addl $-64, %0\n"
23124 + " addl $64, %4\n"
23125 + " addl $64, %3\n"
23126 + " cmpl $63, %0\n"
23127 + " ja 1b\n"
23128 + "35: movl %0, %%eax\n"
23129 + " shrl $2, %0\n"
23130 + " andl $3, %%eax\n"
23131 + " cld\n"
23132 + "99: rep; "__copyuser_seg" movsl\n"
23133 + "36: movl %%eax, %0\n"
23134 + "37: rep; "__copyuser_seg" movsb\n"
23135 + "100:\n"
23136 + ".section .fixup,\"ax\"\n"
23137 + "101: lea 0(%%eax,%0,4),%0\n"
23138 + " jmp 100b\n"
23139 + ".previous\n"
23140 + _ASM_EXTABLE(1b,100b)
23141 + _ASM_EXTABLE(2b,100b)
23142 + _ASM_EXTABLE(3b,100b)
23143 + _ASM_EXTABLE(4b,100b)
23144 + _ASM_EXTABLE(5b,100b)
23145 + _ASM_EXTABLE(6b,100b)
23146 + _ASM_EXTABLE(7b,100b)
23147 + _ASM_EXTABLE(8b,100b)
23148 + _ASM_EXTABLE(9b,100b)
23149 + _ASM_EXTABLE(10b,100b)
23150 + _ASM_EXTABLE(11b,100b)
23151 + _ASM_EXTABLE(12b,100b)
23152 + _ASM_EXTABLE(13b,100b)
23153 + _ASM_EXTABLE(14b,100b)
23154 + _ASM_EXTABLE(15b,100b)
23155 + _ASM_EXTABLE(16b,100b)
23156 + _ASM_EXTABLE(17b,100b)
23157 + _ASM_EXTABLE(18b,100b)
23158 + _ASM_EXTABLE(19b,100b)
23159 + _ASM_EXTABLE(20b,100b)
23160 + _ASM_EXTABLE(21b,100b)
23161 + _ASM_EXTABLE(22b,100b)
23162 + _ASM_EXTABLE(23b,100b)
23163 + _ASM_EXTABLE(24b,100b)
23164 + _ASM_EXTABLE(25b,100b)
23165 + _ASM_EXTABLE(26b,100b)
23166 + _ASM_EXTABLE(27b,100b)
23167 + _ASM_EXTABLE(28b,100b)
23168 + _ASM_EXTABLE(29b,100b)
23169 + _ASM_EXTABLE(30b,100b)
23170 + _ASM_EXTABLE(31b,100b)
23171 + _ASM_EXTABLE(32b,100b)
23172 + _ASM_EXTABLE(33b,100b)
23173 + _ASM_EXTABLE(34b,100b)
23174 + _ASM_EXTABLE(35b,100b)
23175 + _ASM_EXTABLE(36b,100b)
23176 + _ASM_EXTABLE(37b,100b)
23177 + _ASM_EXTABLE(99b,101b)
23178 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23179 + : "1"(to), "2"(from), "0"(size)
23180 + : "eax", "edx", "memory");
23181 + return size;
23182 +}
23183 +
23184 +static unsigned long __size_overflow(3)
23185 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23186 {
23187 int d0, d1;
23188 __asm__ __volatile__(
23189 " .align 2,0x90\n"
23190 - "0: movl 32(%4), %%eax\n"
23191 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23192 " cmpl $67, %0\n"
23193 " jbe 2f\n"
23194 - "1: movl 64(%4), %%eax\n"
23195 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23196 " .align 2,0x90\n"
23197 - "2: movl 0(%4), %%eax\n"
23198 - "21: movl 4(%4), %%edx\n"
23199 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23200 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23201 " movl %%eax, 0(%3)\n"
23202 " movl %%edx, 4(%3)\n"
23203 - "3: movl 8(%4), %%eax\n"
23204 - "31: movl 12(%4),%%edx\n"
23205 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23206 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23207 " movl %%eax, 8(%3)\n"
23208 " movl %%edx, 12(%3)\n"
23209 - "4: movl 16(%4), %%eax\n"
23210 - "41: movl 20(%4), %%edx\n"
23211 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23212 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23213 " movl %%eax, 16(%3)\n"
23214 " movl %%edx, 20(%3)\n"
23215 - "10: movl 24(%4), %%eax\n"
23216 - "51: movl 28(%4), %%edx\n"
23217 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23218 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23219 " movl %%eax, 24(%3)\n"
23220 " movl %%edx, 28(%3)\n"
23221 - "11: movl 32(%4), %%eax\n"
23222 - "61: movl 36(%4), %%edx\n"
23223 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23224 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23225 " movl %%eax, 32(%3)\n"
23226 " movl %%edx, 36(%3)\n"
23227 - "12: movl 40(%4), %%eax\n"
23228 - "71: movl 44(%4), %%edx\n"
23229 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23230 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23231 " movl %%eax, 40(%3)\n"
23232 " movl %%edx, 44(%3)\n"
23233 - "13: movl 48(%4), %%eax\n"
23234 - "81: movl 52(%4), %%edx\n"
23235 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23236 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23237 " movl %%eax, 48(%3)\n"
23238 " movl %%edx, 52(%3)\n"
23239 - "14: movl 56(%4), %%eax\n"
23240 - "91: movl 60(%4), %%edx\n"
23241 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23242 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23243 " movl %%eax, 56(%3)\n"
23244 " movl %%edx, 60(%3)\n"
23245 " addl $-64, %0\n"
23246 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23247 " shrl $2, %0\n"
23248 " andl $3, %%eax\n"
23249 " cld\n"
23250 - "6: rep; movsl\n"
23251 + "6: rep; "__copyuser_seg" movsl\n"
23252 " movl %%eax,%0\n"
23253 - "7: rep; movsb\n"
23254 + "7: rep; "__copyuser_seg" movsb\n"
23255 "8:\n"
23256 ".section .fixup,\"ax\"\n"
23257 "9: lea 0(%%eax,%0,4),%0\n"
23258 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23259 * hyoshiok@miraclelinux.com
23260 */
23261
23262 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23263 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23264 const void __user *from, unsigned long size)
23265 {
23266 int d0, d1;
23267
23268 __asm__ __volatile__(
23269 " .align 2,0x90\n"
23270 - "0: movl 32(%4), %%eax\n"
23271 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23272 " cmpl $67, %0\n"
23273 " jbe 2f\n"
23274 - "1: movl 64(%4), %%eax\n"
23275 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23276 " .align 2,0x90\n"
23277 - "2: movl 0(%4), %%eax\n"
23278 - "21: movl 4(%4), %%edx\n"
23279 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23280 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23281 " movnti %%eax, 0(%3)\n"
23282 " movnti %%edx, 4(%3)\n"
23283 - "3: movl 8(%4), %%eax\n"
23284 - "31: movl 12(%4),%%edx\n"
23285 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23286 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23287 " movnti %%eax, 8(%3)\n"
23288 " movnti %%edx, 12(%3)\n"
23289 - "4: movl 16(%4), %%eax\n"
23290 - "41: movl 20(%4), %%edx\n"
23291 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23292 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23293 " movnti %%eax, 16(%3)\n"
23294 " movnti %%edx, 20(%3)\n"
23295 - "10: movl 24(%4), %%eax\n"
23296 - "51: movl 28(%4), %%edx\n"
23297 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23298 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23299 " movnti %%eax, 24(%3)\n"
23300 " movnti %%edx, 28(%3)\n"
23301 - "11: movl 32(%4), %%eax\n"
23302 - "61: movl 36(%4), %%edx\n"
23303 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23304 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23305 " movnti %%eax, 32(%3)\n"
23306 " movnti %%edx, 36(%3)\n"
23307 - "12: movl 40(%4), %%eax\n"
23308 - "71: movl 44(%4), %%edx\n"
23309 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23310 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23311 " movnti %%eax, 40(%3)\n"
23312 " movnti %%edx, 44(%3)\n"
23313 - "13: movl 48(%4), %%eax\n"
23314 - "81: movl 52(%4), %%edx\n"
23315 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23316 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23317 " movnti %%eax, 48(%3)\n"
23318 " movnti %%edx, 52(%3)\n"
23319 - "14: movl 56(%4), %%eax\n"
23320 - "91: movl 60(%4), %%edx\n"
23321 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23322 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23323 " movnti %%eax, 56(%3)\n"
23324 " movnti %%edx, 60(%3)\n"
23325 " addl $-64, %0\n"
23326 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23327 " shrl $2, %0\n"
23328 " andl $3, %%eax\n"
23329 " cld\n"
23330 - "6: rep; movsl\n"
23331 + "6: rep; "__copyuser_seg" movsl\n"
23332 " movl %%eax,%0\n"
23333 - "7: rep; movsb\n"
23334 + "7: rep; "__copyuser_seg" movsb\n"
23335 "8:\n"
23336 ".section .fixup,\"ax\"\n"
23337 "9: lea 0(%%eax,%0,4),%0\n"
23338 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23339 return size;
23340 }
23341
23342 -static unsigned long __copy_user_intel_nocache(void *to,
23343 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23344 const void __user *from, unsigned long size)
23345 {
23346 int d0, d1;
23347
23348 __asm__ __volatile__(
23349 " .align 2,0x90\n"
23350 - "0: movl 32(%4), %%eax\n"
23351 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23352 " cmpl $67, %0\n"
23353 " jbe 2f\n"
23354 - "1: movl 64(%4), %%eax\n"
23355 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23356 " .align 2,0x90\n"
23357 - "2: movl 0(%4), %%eax\n"
23358 - "21: movl 4(%4), %%edx\n"
23359 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23360 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23361 " movnti %%eax, 0(%3)\n"
23362 " movnti %%edx, 4(%3)\n"
23363 - "3: movl 8(%4), %%eax\n"
23364 - "31: movl 12(%4),%%edx\n"
23365 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23366 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23367 " movnti %%eax, 8(%3)\n"
23368 " movnti %%edx, 12(%3)\n"
23369 - "4: movl 16(%4), %%eax\n"
23370 - "41: movl 20(%4), %%edx\n"
23371 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23372 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23373 " movnti %%eax, 16(%3)\n"
23374 " movnti %%edx, 20(%3)\n"
23375 - "10: movl 24(%4), %%eax\n"
23376 - "51: movl 28(%4), %%edx\n"
23377 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23378 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23379 " movnti %%eax, 24(%3)\n"
23380 " movnti %%edx, 28(%3)\n"
23381 - "11: movl 32(%4), %%eax\n"
23382 - "61: movl 36(%4), %%edx\n"
23383 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23384 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23385 " movnti %%eax, 32(%3)\n"
23386 " movnti %%edx, 36(%3)\n"
23387 - "12: movl 40(%4), %%eax\n"
23388 - "71: movl 44(%4), %%edx\n"
23389 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23390 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23391 " movnti %%eax, 40(%3)\n"
23392 " movnti %%edx, 44(%3)\n"
23393 - "13: movl 48(%4), %%eax\n"
23394 - "81: movl 52(%4), %%edx\n"
23395 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23396 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23397 " movnti %%eax, 48(%3)\n"
23398 " movnti %%edx, 52(%3)\n"
23399 - "14: movl 56(%4), %%eax\n"
23400 - "91: movl 60(%4), %%edx\n"
23401 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23402 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23403 " movnti %%eax, 56(%3)\n"
23404 " movnti %%edx, 60(%3)\n"
23405 " addl $-64, %0\n"
23406 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23407 " shrl $2, %0\n"
23408 " andl $3, %%eax\n"
23409 " cld\n"
23410 - "6: rep; movsl\n"
23411 + "6: rep; "__copyuser_seg" movsl\n"
23412 " movl %%eax,%0\n"
23413 - "7: rep; movsb\n"
23414 + "7: rep; "__copyuser_seg" movsb\n"
23415 "8:\n"
23416 ".section .fixup,\"ax\"\n"
23417 "9: lea 0(%%eax,%0,4),%0\n"
23418 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23419 */
23420 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23421 unsigned long size);
23422 -unsigned long __copy_user_intel(void __user *to, const void *from,
23423 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23424 + unsigned long size);
23425 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23426 unsigned long size);
23427 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23428 const void __user *from, unsigned long size);
23429 #endif /* CONFIG_X86_INTEL_USERCOPY */
23430
23431 /* Generic arbitrary sized copy. */
23432 -#define __copy_user(to, from, size) \
23433 +#define __copy_user(to, from, size, prefix, set, restore) \
23434 do { \
23435 int __d0, __d1, __d2; \
23436 __asm__ __volatile__( \
23437 + set \
23438 " cmp $7,%0\n" \
23439 " jbe 1f\n" \
23440 " movl %1,%0\n" \
23441 " negl %0\n" \
23442 " andl $7,%0\n" \
23443 " subl %0,%3\n" \
23444 - "4: rep; movsb\n" \
23445 + "4: rep; "prefix"movsb\n" \
23446 " movl %3,%0\n" \
23447 " shrl $2,%0\n" \
23448 " andl $3,%3\n" \
23449 " .align 2,0x90\n" \
23450 - "0: rep; movsl\n" \
23451 + "0: rep; "prefix"movsl\n" \
23452 " movl %3,%0\n" \
23453 - "1: rep; movsb\n" \
23454 + "1: rep; "prefix"movsb\n" \
23455 "2:\n" \
23456 + restore \
23457 ".section .fixup,\"ax\"\n" \
23458 "5: addl %3,%0\n" \
23459 " jmp 2b\n" \
23460 @@ -537,14 +649,14 @@ do { \
23461 " negl %0\n" \
23462 " andl $7,%0\n" \
23463 " subl %0,%3\n" \
23464 - "4: rep; movsb\n" \
23465 + "4: rep; "__copyuser_seg"movsb\n" \
23466 " movl %3,%0\n" \
23467 " shrl $2,%0\n" \
23468 " andl $3,%3\n" \
23469 " .align 2,0x90\n" \
23470 - "0: rep; movsl\n" \
23471 + "0: rep; "__copyuser_seg"movsl\n" \
23472 " movl %3,%0\n" \
23473 - "1: rep; movsb\n" \
23474 + "1: rep; "__copyuser_seg"movsb\n" \
23475 "2:\n" \
23476 ".section .fixup,\"ax\"\n" \
23477 "5: addl %3,%0\n" \
23478 @@ -627,9 +739,9 @@ survive:
23479 }
23480 #endif
23481 if (movsl_is_ok(to, from, n))
23482 - __copy_user(to, from, n);
23483 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23484 else
23485 - n = __copy_user_intel(to, from, n);
23486 + n = __generic_copy_to_user_intel(to, from, n);
23487 return n;
23488 }
23489 EXPORT_SYMBOL(__copy_to_user_ll);
23490 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23491 unsigned long n)
23492 {
23493 if (movsl_is_ok(to, from, n))
23494 - __copy_user(to, from, n);
23495 + __copy_user(to, from, n, __copyuser_seg, "", "");
23496 else
23497 - n = __copy_user_intel((void __user *)to,
23498 - (const void *)from, n);
23499 + n = __generic_copy_from_user_intel(to, from, n);
23500 return n;
23501 }
23502 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23503 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23504 if (n > 64 && cpu_has_xmm2)
23505 n = __copy_user_intel_nocache(to, from, n);
23506 else
23507 - __copy_user(to, from, n);
23508 + __copy_user(to, from, n, __copyuser_seg, "", "");
23509 #else
23510 - __copy_user(to, from, n);
23511 + __copy_user(to, from, n, __copyuser_seg, "", "");
23512 #endif
23513 return n;
23514 }
23515 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23516
23517 -/**
23518 - * copy_to_user: - Copy a block of data into user space.
23519 - * @to: Destination address, in user space.
23520 - * @from: Source address, in kernel space.
23521 - * @n: Number of bytes to copy.
23522 - *
23523 - * Context: User context only. This function may sleep.
23524 - *
23525 - * Copy data from kernel space to user space.
23526 - *
23527 - * Returns number of bytes that could not be copied.
23528 - * On success, this will be zero.
23529 - */
23530 -unsigned long
23531 -copy_to_user(void __user *to, const void *from, unsigned long n)
23532 -{
23533 - if (access_ok(VERIFY_WRITE, to, n))
23534 - n = __copy_to_user(to, from, n);
23535 - return n;
23536 -}
23537 -EXPORT_SYMBOL(copy_to_user);
23538 -
23539 -/**
23540 - * copy_from_user: - Copy a block of data from user space.
23541 - * @to: Destination address, in kernel space.
23542 - * @from: Source address, in user space.
23543 - * @n: Number of bytes to copy.
23544 - *
23545 - * Context: User context only. This function may sleep.
23546 - *
23547 - * Copy data from user space to kernel space.
23548 - *
23549 - * Returns number of bytes that could not be copied.
23550 - * On success, this will be zero.
23551 - *
23552 - * If some data could not be copied, this function will pad the copied
23553 - * data to the requested size using zero bytes.
23554 - */
23555 -unsigned long
23556 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23557 -{
23558 - if (access_ok(VERIFY_READ, from, n))
23559 - n = __copy_from_user(to, from, n);
23560 - else
23561 - memset(to, 0, n);
23562 - return n;
23563 -}
23564 -EXPORT_SYMBOL(_copy_from_user);
23565 -
23566 void copy_from_user_overflow(void)
23567 {
23568 WARN(1, "Buffer overflow detected!\n");
23569 }
23570 EXPORT_SYMBOL(copy_from_user_overflow);
23571 +
23572 +void copy_to_user_overflow(void)
23573 +{
23574 + WARN(1, "Buffer overflow detected!\n");
23575 +}
23576 +EXPORT_SYMBOL(copy_to_user_overflow);
23577 +
23578 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23579 +void __set_fs(mm_segment_t x)
23580 +{
23581 + switch (x.seg) {
23582 + case 0:
23583 + loadsegment(gs, 0);
23584 + break;
23585 + case TASK_SIZE_MAX:
23586 + loadsegment(gs, __USER_DS);
23587 + break;
23588 + case -1UL:
23589 + loadsegment(gs, __KERNEL_DS);
23590 + break;
23591 + default:
23592 + BUG();
23593 + }
23594 + return;
23595 +}
23596 +EXPORT_SYMBOL(__set_fs);
23597 +
23598 +void set_fs(mm_segment_t x)
23599 +{
23600 + current_thread_info()->addr_limit = x;
23601 + __set_fs(x);
23602 +}
23603 +EXPORT_SYMBOL(set_fs);
23604 +#endif
23605 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23606 index e5b130b..6690d31 100644
23607 --- a/arch/x86/lib/usercopy_64.c
23608 +++ b/arch/x86/lib/usercopy_64.c
23609 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23610 {
23611 long __d0;
23612 might_fault();
23613 +
23614 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23615 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23616 + addr += PAX_USER_SHADOW_BASE;
23617 +#endif
23618 +
23619 /* no memory constraint because it doesn't change any memory gcc knows
23620 about */
23621 asm volatile(
23622 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23623 }
23624 EXPORT_SYMBOL(clear_user);
23625
23626 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23627 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23628 {
23629 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23630 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23631 - }
23632 - return len;
23633 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23634 +
23635 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23636 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23637 + to += PAX_USER_SHADOW_BASE;
23638 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23639 + from += PAX_USER_SHADOW_BASE;
23640 +#endif
23641 +
23642 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23643 + }
23644 + return len;
23645 }
23646 EXPORT_SYMBOL(copy_in_user);
23647
23648 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23649 * it is not necessary to optimize tail handling.
23650 */
23651 unsigned long
23652 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23653 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23654 {
23655 char c;
23656 unsigned zero_len;
23657 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23658 break;
23659 return len;
23660 }
23661 +
23662 +void copy_from_user_overflow(void)
23663 +{
23664 + WARN(1, "Buffer overflow detected!\n");
23665 +}
23666 +EXPORT_SYMBOL(copy_from_user_overflow);
23667 +
23668 +void copy_to_user_overflow(void)
23669 +{
23670 + WARN(1, "Buffer overflow detected!\n");
23671 +}
23672 +EXPORT_SYMBOL(copy_to_user_overflow);
23673 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23674 index 903ec1e..c4166b2 100644
23675 --- a/arch/x86/mm/extable.c
23676 +++ b/arch/x86/mm/extable.c
23677 @@ -6,12 +6,24 @@
23678 static inline unsigned long
23679 ex_insn_addr(const struct exception_table_entry *x)
23680 {
23681 - return (unsigned long)&x->insn + x->insn;
23682 + unsigned long reloc = 0;
23683 +
23684 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23685 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23686 +#endif
23687 +
23688 + return (unsigned long)&x->insn + x->insn + reloc;
23689 }
23690 static inline unsigned long
23691 ex_fixup_addr(const struct exception_table_entry *x)
23692 {
23693 - return (unsigned long)&x->fixup + x->fixup;
23694 + unsigned long reloc = 0;
23695 +
23696 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23697 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23698 +#endif
23699 +
23700 + return (unsigned long)&x->fixup + x->fixup + reloc;
23701 }
23702
23703 int fixup_exception(struct pt_regs *regs)
23704 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23705 unsigned long new_ip;
23706
23707 #ifdef CONFIG_PNPBIOS
23708 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23709 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23710 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23711 extern u32 pnp_bios_is_utter_crap;
23712 pnp_bios_is_utter_crap = 1;
23713 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23714 i += 4;
23715 p->fixup -= i;
23716 i += 4;
23717 +
23718 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23719 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23720 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23721 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23722 +#endif
23723 +
23724 }
23725 }
23726
23727 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23728 index 76dcd9d..e9dffde 100644
23729 --- a/arch/x86/mm/fault.c
23730 +++ b/arch/x86/mm/fault.c
23731 @@ -13,11 +13,18 @@
23732 #include <linux/perf_event.h> /* perf_sw_event */
23733 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23734 #include <linux/prefetch.h> /* prefetchw */
23735 +#include <linux/unistd.h>
23736 +#include <linux/compiler.h>
23737
23738 #include <asm/traps.h> /* dotraplinkage, ... */
23739 #include <asm/pgalloc.h> /* pgd_*(), ... */
23740 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23741 #include <asm/fixmap.h> /* VSYSCALL_START */
23742 +#include <asm/tlbflush.h>
23743 +
23744 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23745 +#include <asm/stacktrace.h>
23746 +#endif
23747
23748 /*
23749 * Page fault error code bits:
23750 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23751 int ret = 0;
23752
23753 /* kprobe_running() needs smp_processor_id() */
23754 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23755 + if (kprobes_built_in() && !user_mode(regs)) {
23756 preempt_disable();
23757 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23758 ret = 1;
23759 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23760 return !instr_lo || (instr_lo>>1) == 1;
23761 case 0x00:
23762 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23763 - if (probe_kernel_address(instr, opcode))
23764 + if (user_mode(regs)) {
23765 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23766 + return 0;
23767 + } else if (probe_kernel_address(instr, opcode))
23768 return 0;
23769
23770 *prefetch = (instr_lo == 0xF) &&
23771 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23772 while (instr < max_instr) {
23773 unsigned char opcode;
23774
23775 - if (probe_kernel_address(instr, opcode))
23776 + if (user_mode(regs)) {
23777 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23778 + break;
23779 + } else if (probe_kernel_address(instr, opcode))
23780 break;
23781
23782 instr++;
23783 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23784 force_sig_info(si_signo, &info, tsk);
23785 }
23786
23787 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23788 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23789 +#endif
23790 +
23791 +#ifdef CONFIG_PAX_EMUTRAMP
23792 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23793 +#endif
23794 +
23795 +#ifdef CONFIG_PAX_PAGEEXEC
23796 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23797 +{
23798 + pgd_t *pgd;
23799 + pud_t *pud;
23800 + pmd_t *pmd;
23801 +
23802 + pgd = pgd_offset(mm, address);
23803 + if (!pgd_present(*pgd))
23804 + return NULL;
23805 + pud = pud_offset(pgd, address);
23806 + if (!pud_present(*pud))
23807 + return NULL;
23808 + pmd = pmd_offset(pud, address);
23809 + if (!pmd_present(*pmd))
23810 + return NULL;
23811 + return pmd;
23812 +}
23813 +#endif
23814 +
23815 DEFINE_SPINLOCK(pgd_lock);
23816 LIST_HEAD(pgd_list);
23817
23818 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23819 for (address = VMALLOC_START & PMD_MASK;
23820 address >= TASK_SIZE && address < FIXADDR_TOP;
23821 address += PMD_SIZE) {
23822 +
23823 +#ifdef CONFIG_PAX_PER_CPU_PGD
23824 + unsigned long cpu;
23825 +#else
23826 struct page *page;
23827 +#endif
23828
23829 spin_lock(&pgd_lock);
23830 +
23831 +#ifdef CONFIG_PAX_PER_CPU_PGD
23832 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23833 + pgd_t *pgd = get_cpu_pgd(cpu);
23834 + pmd_t *ret;
23835 +#else
23836 list_for_each_entry(page, &pgd_list, lru) {
23837 + pgd_t *pgd = page_address(page);
23838 spinlock_t *pgt_lock;
23839 pmd_t *ret;
23840
23841 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23842 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23843
23844 spin_lock(pgt_lock);
23845 - ret = vmalloc_sync_one(page_address(page), address);
23846 +#endif
23847 +
23848 + ret = vmalloc_sync_one(pgd, address);
23849 +
23850 +#ifndef CONFIG_PAX_PER_CPU_PGD
23851 spin_unlock(pgt_lock);
23852 +#endif
23853
23854 if (!ret)
23855 break;
23856 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23857 * an interrupt in the middle of a task switch..
23858 */
23859 pgd_paddr = read_cr3();
23860 +
23861 +#ifdef CONFIG_PAX_PER_CPU_PGD
23862 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23863 +#endif
23864 +
23865 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23866 if (!pmd_k)
23867 return -1;
23868 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23869 * happen within a race in page table update. In the later
23870 * case just flush:
23871 */
23872 +
23873 +#ifdef CONFIG_PAX_PER_CPU_PGD
23874 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23875 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23876 +#else
23877 pgd = pgd_offset(current->active_mm, address);
23878 +#endif
23879 +
23880 pgd_ref = pgd_offset_k(address);
23881 if (pgd_none(*pgd_ref))
23882 return -1;
23883 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23884 static int is_errata100(struct pt_regs *regs, unsigned long address)
23885 {
23886 #ifdef CONFIG_X86_64
23887 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23888 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23889 return 1;
23890 #endif
23891 return 0;
23892 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23893 }
23894
23895 static const char nx_warning[] = KERN_CRIT
23896 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23897 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23898
23899 static void
23900 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23901 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23902 if (!oops_may_print())
23903 return;
23904
23905 - if (error_code & PF_INSTR) {
23906 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23907 unsigned int level;
23908
23909 pte_t *pte = lookup_address(address, &level);
23910
23911 if (pte && pte_present(*pte) && !pte_exec(*pte))
23912 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23913 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23914 }
23915
23916 +#ifdef CONFIG_PAX_KERNEXEC
23917 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23918 + if (current->signal->curr_ip)
23919 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23920 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23921 + else
23922 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23923 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23924 + }
23925 +#endif
23926 +
23927 printk(KERN_ALERT "BUG: unable to handle kernel ");
23928 if (address < PAGE_SIZE)
23929 printk(KERN_CONT "NULL pointer dereference");
23930 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23931 }
23932 #endif
23933
23934 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23935 + if (pax_is_fetch_fault(regs, error_code, address)) {
23936 +
23937 +#ifdef CONFIG_PAX_EMUTRAMP
23938 + switch (pax_handle_fetch_fault(regs)) {
23939 + case 2:
23940 + return;
23941 + }
23942 +#endif
23943 +
23944 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23945 + do_group_exit(SIGKILL);
23946 + }
23947 +#endif
23948 +
23949 if (unlikely(show_unhandled_signals))
23950 show_signal_msg(regs, error_code, address, tsk);
23951
23952 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23953 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23954 printk(KERN_ERR
23955 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23956 - tsk->comm, tsk->pid, address);
23957 + tsk->comm, task_pid_nr(tsk), address);
23958 code = BUS_MCEERR_AR;
23959 }
23960 #endif
23961 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23962 return 1;
23963 }
23964
23965 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23966 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23967 +{
23968 + pte_t *pte;
23969 + pmd_t *pmd;
23970 + spinlock_t *ptl;
23971 + unsigned char pte_mask;
23972 +
23973 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23974 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23975 + return 0;
23976 +
23977 + /* PaX: it's our fault, let's handle it if we can */
23978 +
23979 + /* PaX: take a look at read faults before acquiring any locks */
23980 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23981 + /* instruction fetch attempt from a protected page in user mode */
23982 + up_read(&mm->mmap_sem);
23983 +
23984 +#ifdef CONFIG_PAX_EMUTRAMP
23985 + switch (pax_handle_fetch_fault(regs)) {
23986 + case 2:
23987 + return 1;
23988 + }
23989 +#endif
23990 +
23991 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23992 + do_group_exit(SIGKILL);
23993 + }
23994 +
23995 + pmd = pax_get_pmd(mm, address);
23996 + if (unlikely(!pmd))
23997 + return 0;
23998 +
23999 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
24000 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
24001 + pte_unmap_unlock(pte, ptl);
24002 + return 0;
24003 + }
24004 +
24005 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
24006 + /* write attempt to a protected page in user mode */
24007 + pte_unmap_unlock(pte, ptl);
24008 + return 0;
24009 + }
24010 +
24011 +#ifdef CONFIG_SMP
24012 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
24013 +#else
24014 + if (likely(address > get_limit(regs->cs)))
24015 +#endif
24016 + {
24017 + set_pte(pte, pte_mkread(*pte));
24018 + __flush_tlb_one(address);
24019 + pte_unmap_unlock(pte, ptl);
24020 + up_read(&mm->mmap_sem);
24021 + return 1;
24022 + }
24023 +
24024 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
24025 +
24026 + /*
24027 + * PaX: fill DTLB with user rights and retry
24028 + */
24029 + __asm__ __volatile__ (
24030 + "orb %2,(%1)\n"
24031 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
24032 +/*
24033 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
24034 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
24035 + * page fault when examined during a TLB load attempt. this is true not only
24036 + * for PTEs holding a non-present entry but also present entries that will
24037 + * raise a page fault (such as those set up by PaX, or the copy-on-write
24038 + * mechanism). in effect it means that we do *not* need to flush the TLBs
24039 + * for our target pages since their PTEs are simply not in the TLBs at all.
24040 +
24041 + * the best thing in omitting it is that we gain around 15-20% speed in the
24042 + * fast path of the page fault handler and can get rid of tracing since we
24043 + * can no longer flush unintended entries.
24044 + */
24045 + "invlpg (%0)\n"
24046 +#endif
24047 + __copyuser_seg"testb $0,(%0)\n"
24048 + "xorb %3,(%1)\n"
24049 + :
24050 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24051 + : "memory", "cc");
24052 + pte_unmap_unlock(pte, ptl);
24053 + up_read(&mm->mmap_sem);
24054 + return 1;
24055 +}
24056 +#endif
24057 +
24058 /*
24059 * Handle a spurious fault caused by a stale TLB entry.
24060 *
24061 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
24062 static inline int
24063 access_error(unsigned long error_code, struct vm_area_struct *vma)
24064 {
24065 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24066 + return 1;
24067 +
24068 if (error_code & PF_WRITE) {
24069 /* write, present and write, not present: */
24070 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24071 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24072 {
24073 struct vm_area_struct *vma;
24074 struct task_struct *tsk;
24075 - unsigned long address;
24076 struct mm_struct *mm;
24077 int fault;
24078 int write = error_code & PF_WRITE;
24079 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24080 (write ? FAULT_FLAG_WRITE : 0);
24081
24082 - tsk = current;
24083 - mm = tsk->mm;
24084 -
24085 /* Get the faulting address: */
24086 - address = read_cr2();
24087 + unsigned long address = read_cr2();
24088 +
24089 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24090 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24091 + if (!search_exception_tables(regs->ip)) {
24092 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24093 + bad_area_nosemaphore(regs, error_code, address);
24094 + return;
24095 + }
24096 + if (address < PAX_USER_SHADOW_BASE) {
24097 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24098 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24099 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24100 + } else
24101 + address -= PAX_USER_SHADOW_BASE;
24102 + }
24103 +#endif
24104 +
24105 + tsk = current;
24106 + mm = tsk->mm;
24107
24108 /*
24109 * Detect and handle instructions that would cause a page fault for
24110 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24111 * User-mode registers count as a user access even for any
24112 * potential system fault or CPU buglet:
24113 */
24114 - if (user_mode_vm(regs)) {
24115 + if (user_mode(regs)) {
24116 local_irq_enable();
24117 error_code |= PF_USER;
24118 } else {
24119 @@ -1132,6 +1339,11 @@ retry:
24120 might_sleep();
24121 }
24122
24123 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24124 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24125 + return;
24126 +#endif
24127 +
24128 vma = find_vma(mm, address);
24129 if (unlikely(!vma)) {
24130 bad_area(regs, error_code, address);
24131 @@ -1143,18 +1355,24 @@ retry:
24132 bad_area(regs, error_code, address);
24133 return;
24134 }
24135 - if (error_code & PF_USER) {
24136 - /*
24137 - * Accessing the stack below %sp is always a bug.
24138 - * The large cushion allows instructions like enter
24139 - * and pusha to work. ("enter $65535, $31" pushes
24140 - * 32 pointers and then decrements %sp by 65535.)
24141 - */
24142 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24143 - bad_area(regs, error_code, address);
24144 - return;
24145 - }
24146 + /*
24147 + * Accessing the stack below %sp is always a bug.
24148 + * The large cushion allows instructions like enter
24149 + * and pusha to work. ("enter $65535, $31" pushes
24150 + * 32 pointers and then decrements %sp by 65535.)
24151 + */
24152 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24153 + bad_area(regs, error_code, address);
24154 + return;
24155 }
24156 +
24157 +#ifdef CONFIG_PAX_SEGMEXEC
24158 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24159 + bad_area(regs, error_code, address);
24160 + return;
24161 + }
24162 +#endif
24163 +
24164 if (unlikely(expand_stack(vma, address))) {
24165 bad_area(regs, error_code, address);
24166 return;
24167 @@ -1209,3 +1427,292 @@ good_area:
24168
24169 up_read(&mm->mmap_sem);
24170 }
24171 +
24172 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24173 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24174 +{
24175 + struct mm_struct *mm = current->mm;
24176 + unsigned long ip = regs->ip;
24177 +
24178 + if (v8086_mode(regs))
24179 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24180 +
24181 +#ifdef CONFIG_PAX_PAGEEXEC
24182 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24183 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24184 + return true;
24185 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24186 + return true;
24187 + return false;
24188 + }
24189 +#endif
24190 +
24191 +#ifdef CONFIG_PAX_SEGMEXEC
24192 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24193 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24194 + return true;
24195 + return false;
24196 + }
24197 +#endif
24198 +
24199 + return false;
24200 +}
24201 +#endif
24202 +
24203 +#ifdef CONFIG_PAX_EMUTRAMP
24204 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24205 +{
24206 + int err;
24207 +
24208 + do { /* PaX: libffi trampoline emulation */
24209 + unsigned char mov, jmp;
24210 + unsigned int addr1, addr2;
24211 +
24212 +#ifdef CONFIG_X86_64
24213 + if ((regs->ip + 9) >> 32)
24214 + break;
24215 +#endif
24216 +
24217 + err = get_user(mov, (unsigned char __user *)regs->ip);
24218 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24219 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24220 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24221 +
24222 + if (err)
24223 + break;
24224 +
24225 + if (mov == 0xB8 && jmp == 0xE9) {
24226 + regs->ax = addr1;
24227 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24228 + return 2;
24229 + }
24230 + } while (0);
24231 +
24232 + do { /* PaX: gcc trampoline emulation #1 */
24233 + unsigned char mov1, mov2;
24234 + unsigned short jmp;
24235 + unsigned int addr1, addr2;
24236 +
24237 +#ifdef CONFIG_X86_64
24238 + if ((regs->ip + 11) >> 32)
24239 + break;
24240 +#endif
24241 +
24242 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24243 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24244 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24245 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24246 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24247 +
24248 + if (err)
24249 + break;
24250 +
24251 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24252 + regs->cx = addr1;
24253 + regs->ax = addr2;
24254 + regs->ip = addr2;
24255 + return 2;
24256 + }
24257 + } while (0);
24258 +
24259 + do { /* PaX: gcc trampoline emulation #2 */
24260 + unsigned char mov, jmp;
24261 + unsigned int addr1, addr2;
24262 +
24263 +#ifdef CONFIG_X86_64
24264 + if ((regs->ip + 9) >> 32)
24265 + break;
24266 +#endif
24267 +
24268 + err = get_user(mov, (unsigned char __user *)regs->ip);
24269 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24270 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24271 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24272 +
24273 + if (err)
24274 + break;
24275 +
24276 + if (mov == 0xB9 && jmp == 0xE9) {
24277 + regs->cx = addr1;
24278 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24279 + return 2;
24280 + }
24281 + } while (0);
24282 +
24283 + return 1; /* PaX in action */
24284 +}
24285 +
24286 +#ifdef CONFIG_X86_64
24287 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24288 +{
24289 + int err;
24290 +
24291 + do { /* PaX: libffi trampoline emulation */
24292 + unsigned short mov1, mov2, jmp1;
24293 + unsigned char stcclc, jmp2;
24294 + unsigned long addr1, addr2;
24295 +
24296 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24297 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24298 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24299 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24300 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24301 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24302 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24303 +
24304 + if (err)
24305 + break;
24306 +
24307 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24308 + regs->r11 = addr1;
24309 + regs->r10 = addr2;
24310 + if (stcclc == 0xF8)
24311 + regs->flags &= ~X86_EFLAGS_CF;
24312 + else
24313 + regs->flags |= X86_EFLAGS_CF;
24314 + regs->ip = addr1;
24315 + return 2;
24316 + }
24317 + } while (0);
24318 +
24319 + do { /* PaX: gcc trampoline emulation #1 */
24320 + unsigned short mov1, mov2, jmp1;
24321 + unsigned char jmp2;
24322 + unsigned int addr1;
24323 + unsigned long addr2;
24324 +
24325 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24326 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24327 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24328 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24329 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24330 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24331 +
24332 + if (err)
24333 + break;
24334 +
24335 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24336 + regs->r11 = addr1;
24337 + regs->r10 = addr2;
24338 + regs->ip = addr1;
24339 + return 2;
24340 + }
24341 + } while (0);
24342 +
24343 + do { /* PaX: gcc trampoline emulation #2 */
24344 + unsigned short mov1, mov2, jmp1;
24345 + unsigned char jmp2;
24346 + unsigned long addr1, addr2;
24347 +
24348 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24349 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24350 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24351 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24352 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24353 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24354 +
24355 + if (err)
24356 + break;
24357 +
24358 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24359 + regs->r11 = addr1;
24360 + regs->r10 = addr2;
24361 + regs->ip = addr1;
24362 + return 2;
24363 + }
24364 + } while (0);
24365 +
24366 + return 1; /* PaX in action */
24367 +}
24368 +#endif
24369 +
24370 +/*
24371 + * PaX: decide what to do with offenders (regs->ip = fault address)
24372 + *
24373 + * returns 1 when task should be killed
24374 + * 2 when gcc trampoline was detected
24375 + */
24376 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24377 +{
24378 + if (v8086_mode(regs))
24379 + return 1;
24380 +
24381 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24382 + return 1;
24383 +
24384 +#ifdef CONFIG_X86_32
24385 + return pax_handle_fetch_fault_32(regs);
24386 +#else
24387 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24388 + return pax_handle_fetch_fault_32(regs);
24389 + else
24390 + return pax_handle_fetch_fault_64(regs);
24391 +#endif
24392 +}
24393 +#endif
24394 +
24395 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24396 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24397 +{
24398 + long i;
24399 +
24400 + printk(KERN_ERR "PAX: bytes at PC: ");
24401 + for (i = 0; i < 20; i++) {
24402 + unsigned char c;
24403 + if (get_user(c, (unsigned char __force_user *)pc+i))
24404 + printk(KERN_CONT "?? ");
24405 + else
24406 + printk(KERN_CONT "%02x ", c);
24407 + }
24408 + printk("\n");
24409 +
24410 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24411 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24412 + unsigned long c;
24413 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24414 +#ifdef CONFIG_X86_32
24415 + printk(KERN_CONT "???????? ");
24416 +#else
24417 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24418 + printk(KERN_CONT "???????? ???????? ");
24419 + else
24420 + printk(KERN_CONT "???????????????? ");
24421 +#endif
24422 + } else {
24423 +#ifdef CONFIG_X86_64
24424 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24425 + printk(KERN_CONT "%08x ", (unsigned int)c);
24426 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24427 + } else
24428 +#endif
24429 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24430 + }
24431 + }
24432 + printk("\n");
24433 +}
24434 +#endif
24435 +
24436 +/**
24437 + * probe_kernel_write(): safely attempt to write to a location
24438 + * @dst: address to write to
24439 + * @src: pointer to the data that shall be written
24440 + * @size: size of the data chunk
24441 + *
24442 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24443 + * happens, handle that and return -EFAULT.
24444 + */
24445 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24446 +{
24447 + long ret;
24448 + mm_segment_t old_fs = get_fs();
24449 +
24450 + set_fs(KERNEL_DS);
24451 + pagefault_disable();
24452 + pax_open_kernel();
24453 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24454 + pax_close_kernel();
24455 + pagefault_enable();
24456 + set_fs(old_fs);
24457 +
24458 + return ret ? -EFAULT : 0;
24459 +}
24460 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24461 index dd74e46..7d26398 100644
24462 --- a/arch/x86/mm/gup.c
24463 +++ b/arch/x86/mm/gup.c
24464 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24465 addr = start;
24466 len = (unsigned long) nr_pages << PAGE_SHIFT;
24467 end = start + len;
24468 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24469 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24470 (void __user *)start, len)))
24471 return 0;
24472
24473 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24474 index 6f31ee5..8ee4164 100644
24475 --- a/arch/x86/mm/highmem_32.c
24476 +++ b/arch/x86/mm/highmem_32.c
24477 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24478 idx = type + KM_TYPE_NR*smp_processor_id();
24479 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24480 BUG_ON(!pte_none(*(kmap_pte-idx)));
24481 +
24482 + pax_open_kernel();
24483 set_pte(kmap_pte-idx, mk_pte(page, prot));
24484 + pax_close_kernel();
24485 +
24486 arch_flush_lazy_mmu_mode();
24487
24488 return (void *)vaddr;
24489 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24490 index b91e485..d00e7c9 100644
24491 --- a/arch/x86/mm/hugetlbpage.c
24492 +++ b/arch/x86/mm/hugetlbpage.c
24493 @@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24494 struct hstate *h = hstate_file(file);
24495 struct mm_struct *mm = current->mm;
24496 struct vm_area_struct *vma;
24497 - unsigned long start_addr;
24498 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24499 +
24500 +#ifdef CONFIG_PAX_SEGMEXEC
24501 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24502 + pax_task_size = SEGMEXEC_TASK_SIZE;
24503 +#endif
24504 +
24505 + pax_task_size -= PAGE_SIZE;
24506
24507 if (len > mm->cached_hole_size) {
24508 - start_addr = mm->free_area_cache;
24509 + start_addr = mm->free_area_cache;
24510 } else {
24511 - start_addr = TASK_UNMAPPED_BASE;
24512 - mm->cached_hole_size = 0;
24513 + start_addr = mm->mmap_base;
24514 + mm->cached_hole_size = 0;
24515 }
24516
24517 full_search:
24518 @@ -291,26 +298,27 @@ full_search:
24519
24520 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24521 /* At this point: (!vma || addr < vma->vm_end). */
24522 - if (TASK_SIZE - len < addr) {
24523 + if (pax_task_size - len < addr) {
24524 /*
24525 * Start a new search - just in case we missed
24526 * some holes.
24527 */
24528 - if (start_addr != TASK_UNMAPPED_BASE) {
24529 - start_addr = TASK_UNMAPPED_BASE;
24530 + if (start_addr != mm->mmap_base) {
24531 + start_addr = mm->mmap_base;
24532 mm->cached_hole_size = 0;
24533 goto full_search;
24534 }
24535 return -ENOMEM;
24536 }
24537 - if (!vma || addr + len <= vma->vm_start) {
24538 - mm->free_area_cache = addr + len;
24539 - return addr;
24540 - }
24541 + if (check_heap_stack_gap(vma, addr, len))
24542 + break;
24543 if (addr + mm->cached_hole_size < vma->vm_start)
24544 mm->cached_hole_size = vma->vm_start - addr;
24545 addr = ALIGN(vma->vm_end, huge_page_size(h));
24546 }
24547 +
24548 + mm->free_area_cache = addr + len;
24549 + return addr;
24550 }
24551
24552 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24553 @@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24554 struct mm_struct *mm = current->mm;
24555 struct vm_area_struct *vma;
24556 unsigned long base = mm->mmap_base;
24557 - unsigned long addr = addr0;
24558 + unsigned long addr;
24559 unsigned long largest_hole = mm->cached_hole_size;
24560 - unsigned long start_addr;
24561
24562 /* don't allow allocations above current base */
24563 if (mm->free_area_cache > base)
24564 @@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24565 largest_hole = 0;
24566 mm->free_area_cache = base;
24567 }
24568 -try_again:
24569 - start_addr = mm->free_area_cache;
24570
24571 /* make sure it can fit in the remaining address space */
24572 if (mm->free_area_cache < len)
24573 goto fail;
24574
24575 /* either no address requested or can't fit in requested address hole */
24576 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24577 + addr = mm->free_area_cache - len;
24578 do {
24579 + addr &= huge_page_mask(h);
24580 /*
24581 * Lookup failure means no vma is above this address,
24582 * i.e. return with success:
24583 @@ -351,10 +357,10 @@ try_again:
24584 if (!vma)
24585 return addr;
24586
24587 - if (addr + len <= vma->vm_start) {
24588 + if (check_heap_stack_gap(vma, addr, len)) {
24589 /* remember the address as a hint for next time */
24590 - mm->cached_hole_size = largest_hole;
24591 - return (mm->free_area_cache = addr);
24592 + mm->cached_hole_size = largest_hole;
24593 + return (mm->free_area_cache = addr);
24594 } else if (mm->free_area_cache == vma->vm_end) {
24595 /* pull free_area_cache down to the first hole */
24596 mm->free_area_cache = vma->vm_start;
24597 @@ -363,29 +369,34 @@ try_again:
24598
24599 /* remember the largest hole we saw so far */
24600 if (addr + largest_hole < vma->vm_start)
24601 - largest_hole = vma->vm_start - addr;
24602 + largest_hole = vma->vm_start - addr;
24603
24604 /* try just below the current vma->vm_start */
24605 - addr = (vma->vm_start - len) & huge_page_mask(h);
24606 - } while (len <= vma->vm_start);
24607 + addr = skip_heap_stack_gap(vma, len);
24608 + } while (!IS_ERR_VALUE(addr));
24609
24610 fail:
24611 /*
24612 - * if hint left us with no space for the requested
24613 - * mapping then try again:
24614 - */
24615 - if (start_addr != base) {
24616 - mm->free_area_cache = base;
24617 - largest_hole = 0;
24618 - goto try_again;
24619 - }
24620 - /*
24621 * A failed mmap() very likely causes application failure,
24622 * so fall back to the bottom-up function here. This scenario
24623 * can happen with large stack limits and large mmap()
24624 * allocations.
24625 */
24626 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24627 +
24628 +#ifdef CONFIG_PAX_SEGMEXEC
24629 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24630 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24631 + else
24632 +#endif
24633 +
24634 + mm->mmap_base = TASK_UNMAPPED_BASE;
24635 +
24636 +#ifdef CONFIG_PAX_RANDMMAP
24637 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24638 + mm->mmap_base += mm->delta_mmap;
24639 +#endif
24640 +
24641 + mm->free_area_cache = mm->mmap_base;
24642 mm->cached_hole_size = ~0UL;
24643 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24644 len, pgoff, flags);
24645 @@ -393,6 +404,7 @@ fail:
24646 /*
24647 * Restore the topdown base:
24648 */
24649 + mm->mmap_base = base;
24650 mm->free_area_cache = base;
24651 mm->cached_hole_size = ~0UL;
24652
24653 @@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24654 struct hstate *h = hstate_file(file);
24655 struct mm_struct *mm = current->mm;
24656 struct vm_area_struct *vma;
24657 + unsigned long pax_task_size = TASK_SIZE;
24658
24659 if (len & ~huge_page_mask(h))
24660 return -EINVAL;
24661 - if (len > TASK_SIZE)
24662 +
24663 +#ifdef CONFIG_PAX_SEGMEXEC
24664 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24665 + pax_task_size = SEGMEXEC_TASK_SIZE;
24666 +#endif
24667 +
24668 + pax_task_size -= PAGE_SIZE;
24669 +
24670 + if (len > pax_task_size)
24671 return -ENOMEM;
24672
24673 if (flags & MAP_FIXED) {
24674 @@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24675 if (addr) {
24676 addr = ALIGN(addr, huge_page_size(h));
24677 vma = find_vma(mm, addr);
24678 - if (TASK_SIZE - len >= addr &&
24679 - (!vma || addr + len <= vma->vm_start))
24680 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24681 return addr;
24682 }
24683 if (mm->get_unmapped_area == arch_get_unmapped_area)
24684 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24685 index d7aea41..0fc945b 100644
24686 --- a/arch/x86/mm/init.c
24687 +++ b/arch/x86/mm/init.c
24688 @@ -4,6 +4,7 @@
24689 #include <linux/swap.h>
24690 #include <linux/memblock.h>
24691 #include <linux/bootmem.h> /* for max_low_pfn */
24692 +#include <linux/tboot.h>
24693
24694 #include <asm/cacheflush.h>
24695 #include <asm/e820.h>
24696 @@ -16,6 +17,8 @@
24697 #include <asm/tlb.h>
24698 #include <asm/proto.h>
24699 #include <asm/dma.h> /* for MAX_DMA_PFN */
24700 +#include <asm/desc.h>
24701 +#include <asm/bios_ebda.h>
24702
24703 unsigned long __initdata pgt_buf_start;
24704 unsigned long __meminitdata pgt_buf_end;
24705 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24706 {
24707 int i;
24708 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24709 - unsigned long start = 0, good_end;
24710 + unsigned long start = 0x100000, good_end;
24711 phys_addr_t base;
24712
24713 for (i = 0; i < nr_range; i++) {
24714 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24715 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24716 * mmio resources as well as potential bios/acpi data regions.
24717 */
24718 +
24719 +#ifdef CONFIG_GRKERNSEC_KMEM
24720 +static unsigned int ebda_start __read_only;
24721 +static unsigned int ebda_end __read_only;
24722 +#endif
24723 +
24724 int devmem_is_allowed(unsigned long pagenr)
24725 {
24726 - if (pagenr < 256)
24727 +#ifdef CONFIG_GRKERNSEC_KMEM
24728 + /* allow BDA */
24729 + if (!pagenr)
24730 return 1;
24731 + /* allow EBDA */
24732 + if (pagenr >= ebda_start && pagenr < ebda_end)
24733 + return 1;
24734 + /* if tboot is in use, allow access to its hardcoded serial log range */
24735 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
24736 + return 1;
24737 +#else
24738 + if (!pagenr)
24739 + return 1;
24740 +#ifdef CONFIG_VM86
24741 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24742 + return 1;
24743 +#endif
24744 +#endif
24745 +
24746 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24747 + return 1;
24748 +#ifdef CONFIG_GRKERNSEC_KMEM
24749 + /* throw out everything else below 1MB */
24750 + if (pagenr <= 256)
24751 + return 0;
24752 +#endif
24753 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24754 return 0;
24755 if (!page_is_ram(pagenr))
24756 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24757 #endif
24758 }
24759
24760 +#ifdef CONFIG_GRKERNSEC_KMEM
24761 +static inline void gr_init_ebda(void)
24762 +{
24763 + unsigned int ebda_addr;
24764 + unsigned int ebda_size = 0;
24765 +
24766 + ebda_addr = get_bios_ebda();
24767 + if (ebda_addr) {
24768 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24769 + ebda_size <<= 10;
24770 + }
24771 + if (ebda_addr && ebda_size) {
24772 + ebda_start = ebda_addr >> PAGE_SHIFT;
24773 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24774 + } else {
24775 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24776 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24777 + }
24778 +}
24779 +#else
24780 +static inline void gr_init_ebda(void) { }
24781 +#endif
24782 +
24783 void free_initmem(void)
24784 {
24785 +#ifdef CONFIG_PAX_KERNEXEC
24786 +#ifdef CONFIG_X86_32
24787 + /* PaX: limit KERNEL_CS to actual size */
24788 + unsigned long addr, limit;
24789 + struct desc_struct d;
24790 + int cpu;
24791 +#else
24792 + pgd_t *pgd;
24793 + pud_t *pud;
24794 + pmd_t *pmd;
24795 + unsigned long addr, end;
24796 +#endif
24797 +#endif
24798 +
24799 + gr_init_ebda();
24800 +
24801 +#ifdef CONFIG_PAX_KERNEXEC
24802 +#ifdef CONFIG_X86_32
24803 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24804 + limit = (limit - 1UL) >> PAGE_SHIFT;
24805 +
24806 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24807 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24808 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24809 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24810 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24811 + }
24812 +
24813 + /* PaX: make KERNEL_CS read-only */
24814 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24815 + if (!paravirt_enabled())
24816 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24817 +/*
24818 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24819 + pgd = pgd_offset_k(addr);
24820 + pud = pud_offset(pgd, addr);
24821 + pmd = pmd_offset(pud, addr);
24822 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24823 + }
24824 +*/
24825 +#ifdef CONFIG_X86_PAE
24826 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24827 +/*
24828 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24829 + pgd = pgd_offset_k(addr);
24830 + pud = pud_offset(pgd, addr);
24831 + pmd = pmd_offset(pud, addr);
24832 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24833 + }
24834 +*/
24835 +#endif
24836 +
24837 +#ifdef CONFIG_MODULES
24838 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24839 +#endif
24840 +
24841 +#else
24842 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24843 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24844 + pgd = pgd_offset_k(addr);
24845 + pud = pud_offset(pgd, addr);
24846 + pmd = pmd_offset(pud, addr);
24847 + if (!pmd_present(*pmd))
24848 + continue;
24849 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24850 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24851 + else
24852 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24853 + }
24854 +
24855 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24856 + end = addr + KERNEL_IMAGE_SIZE;
24857 + for (; addr < end; addr += PMD_SIZE) {
24858 + pgd = pgd_offset_k(addr);
24859 + pud = pud_offset(pgd, addr);
24860 + pmd = pmd_offset(pud, addr);
24861 + if (!pmd_present(*pmd))
24862 + continue;
24863 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24864 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24865 + }
24866 +#endif
24867 +
24868 + flush_tlb_all();
24869 +#endif
24870 +
24871 free_init_pages("unused kernel memory",
24872 (unsigned long)(&__init_begin),
24873 (unsigned long)(&__init_end));
24874 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24875 index 575d86f..4987469 100644
24876 --- a/arch/x86/mm/init_32.c
24877 +++ b/arch/x86/mm/init_32.c
24878 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24879 }
24880
24881 /*
24882 - * Creates a middle page table and puts a pointer to it in the
24883 - * given global directory entry. This only returns the gd entry
24884 - * in non-PAE compilation mode, since the middle layer is folded.
24885 - */
24886 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24887 -{
24888 - pud_t *pud;
24889 - pmd_t *pmd_table;
24890 -
24891 -#ifdef CONFIG_X86_PAE
24892 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24893 - if (after_bootmem)
24894 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24895 - else
24896 - pmd_table = (pmd_t *)alloc_low_page();
24897 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24898 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24899 - pud = pud_offset(pgd, 0);
24900 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24901 -
24902 - return pmd_table;
24903 - }
24904 -#endif
24905 - pud = pud_offset(pgd, 0);
24906 - pmd_table = pmd_offset(pud, 0);
24907 -
24908 - return pmd_table;
24909 -}
24910 -
24911 -/*
24912 * Create a page table and place a pointer to it in a middle page
24913 * directory entry:
24914 */
24915 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24916 page_table = (pte_t *)alloc_low_page();
24917
24918 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24919 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24920 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24921 +#else
24922 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24923 +#endif
24924 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24925 }
24926
24927 return pte_offset_kernel(pmd, 0);
24928 }
24929
24930 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24931 +{
24932 + pud_t *pud;
24933 + pmd_t *pmd_table;
24934 +
24935 + pud = pud_offset(pgd, 0);
24936 + pmd_table = pmd_offset(pud, 0);
24937 +
24938 + return pmd_table;
24939 +}
24940 +
24941 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24942 {
24943 int pgd_idx = pgd_index(vaddr);
24944 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24945 int pgd_idx, pmd_idx;
24946 unsigned long vaddr;
24947 pgd_t *pgd;
24948 + pud_t *pud;
24949 pmd_t *pmd;
24950 pte_t *pte = NULL;
24951
24952 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24953 pgd = pgd_base + pgd_idx;
24954
24955 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24956 - pmd = one_md_table_init(pgd);
24957 - pmd = pmd + pmd_index(vaddr);
24958 + pud = pud_offset(pgd, vaddr);
24959 + pmd = pmd_offset(pud, vaddr);
24960 +
24961 +#ifdef CONFIG_X86_PAE
24962 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24963 +#endif
24964 +
24965 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24966 pmd++, pmd_idx++) {
24967 pte = page_table_kmap_check(one_page_table_init(pmd),
24968 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24969 }
24970 }
24971
24972 -static inline int is_kernel_text(unsigned long addr)
24973 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24974 {
24975 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24976 - return 1;
24977 - return 0;
24978 + if ((start > ktla_ktva((unsigned long)_etext) ||
24979 + end <= ktla_ktva((unsigned long)_stext)) &&
24980 + (start > ktla_ktva((unsigned long)_einittext) ||
24981 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24982 +
24983 +#ifdef CONFIG_ACPI_SLEEP
24984 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24985 +#endif
24986 +
24987 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24988 + return 0;
24989 + return 1;
24990 }
24991
24992 /*
24993 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24994 unsigned long last_map_addr = end;
24995 unsigned long start_pfn, end_pfn;
24996 pgd_t *pgd_base = swapper_pg_dir;
24997 - int pgd_idx, pmd_idx, pte_ofs;
24998 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24999 unsigned long pfn;
25000 pgd_t *pgd;
25001 + pud_t *pud;
25002 pmd_t *pmd;
25003 pte_t *pte;
25004 unsigned pages_2m, pages_4k;
25005 @@ -280,8 +281,13 @@ repeat:
25006 pfn = start_pfn;
25007 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25008 pgd = pgd_base + pgd_idx;
25009 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
25010 - pmd = one_md_table_init(pgd);
25011 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
25012 + pud = pud_offset(pgd, 0);
25013 + pmd = pmd_offset(pud, 0);
25014 +
25015 +#ifdef CONFIG_X86_PAE
25016 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25017 +#endif
25018
25019 if (pfn >= end_pfn)
25020 continue;
25021 @@ -293,14 +299,13 @@ repeat:
25022 #endif
25023 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
25024 pmd++, pmd_idx++) {
25025 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
25026 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
25027
25028 /*
25029 * Map with big pages if possible, otherwise
25030 * create normal page tables:
25031 */
25032 if (use_pse) {
25033 - unsigned int addr2;
25034 pgprot_t prot = PAGE_KERNEL_LARGE;
25035 /*
25036 * first pass will use the same initial
25037 @@ -310,11 +315,7 @@ repeat:
25038 __pgprot(PTE_IDENT_ATTR |
25039 _PAGE_PSE);
25040
25041 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
25042 - PAGE_OFFSET + PAGE_SIZE-1;
25043 -
25044 - if (is_kernel_text(addr) ||
25045 - is_kernel_text(addr2))
25046 + if (is_kernel_text(address, address + PMD_SIZE))
25047 prot = PAGE_KERNEL_LARGE_EXEC;
25048
25049 pages_2m++;
25050 @@ -331,7 +332,7 @@ repeat:
25051 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25052 pte += pte_ofs;
25053 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25054 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25055 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25056 pgprot_t prot = PAGE_KERNEL;
25057 /*
25058 * first pass will use the same initial
25059 @@ -339,7 +340,7 @@ repeat:
25060 */
25061 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25062
25063 - if (is_kernel_text(addr))
25064 + if (is_kernel_text(address, address + PAGE_SIZE))
25065 prot = PAGE_KERNEL_EXEC;
25066
25067 pages_4k++;
25068 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25069
25070 pud = pud_offset(pgd, va);
25071 pmd = pmd_offset(pud, va);
25072 - if (!pmd_present(*pmd))
25073 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
25074 break;
25075
25076 pte = pte_offset_kernel(pmd, va);
25077 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
25078
25079 static void __init pagetable_init(void)
25080 {
25081 - pgd_t *pgd_base = swapper_pg_dir;
25082 -
25083 - permanent_kmaps_init(pgd_base);
25084 + permanent_kmaps_init(swapper_pg_dir);
25085 }
25086
25087 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25088 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25089 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25090
25091 /* user-defined highmem size */
25092 @@ -734,6 +733,12 @@ void __init mem_init(void)
25093
25094 pci_iommu_alloc();
25095
25096 +#ifdef CONFIG_PAX_PER_CPU_PGD
25097 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25098 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25099 + KERNEL_PGD_PTRS);
25100 +#endif
25101 +
25102 #ifdef CONFIG_FLATMEM
25103 BUG_ON(!mem_map);
25104 #endif
25105 @@ -760,7 +765,7 @@ void __init mem_init(void)
25106 reservedpages++;
25107
25108 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25109 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25110 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25111 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25112
25113 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25114 @@ -801,10 +806,10 @@ void __init mem_init(void)
25115 ((unsigned long)&__init_end -
25116 (unsigned long)&__init_begin) >> 10,
25117
25118 - (unsigned long)&_etext, (unsigned long)&_edata,
25119 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25120 + (unsigned long)&_sdata, (unsigned long)&_edata,
25121 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25122
25123 - (unsigned long)&_text, (unsigned long)&_etext,
25124 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25125 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25126
25127 /*
25128 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25129 if (!kernel_set_to_readonly)
25130 return;
25131
25132 + start = ktla_ktva(start);
25133 pr_debug("Set kernel text: %lx - %lx for read write\n",
25134 start, start+size);
25135
25136 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25137 if (!kernel_set_to_readonly)
25138 return;
25139
25140 + start = ktla_ktva(start);
25141 pr_debug("Set kernel text: %lx - %lx for read only\n",
25142 start, start+size);
25143
25144 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25145 unsigned long start = PFN_ALIGN(_text);
25146 unsigned long size = PFN_ALIGN(_etext) - start;
25147
25148 + start = ktla_ktva(start);
25149 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25150 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25151 size >> 10);
25152 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25153 index 3baff25..8b37564 100644
25154 --- a/arch/x86/mm/init_64.c
25155 +++ b/arch/x86/mm/init_64.c
25156 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25157 * around without checking the pgd every time.
25158 */
25159
25160 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25161 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25162 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25163
25164 int force_personality32;
25165 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25166
25167 for (address = start; address <= end; address += PGDIR_SIZE) {
25168 const pgd_t *pgd_ref = pgd_offset_k(address);
25169 +
25170 +#ifdef CONFIG_PAX_PER_CPU_PGD
25171 + unsigned long cpu;
25172 +#else
25173 struct page *page;
25174 +#endif
25175
25176 if (pgd_none(*pgd_ref))
25177 continue;
25178
25179 spin_lock(&pgd_lock);
25180 +
25181 +#ifdef CONFIG_PAX_PER_CPU_PGD
25182 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25183 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25184 +#else
25185 list_for_each_entry(page, &pgd_list, lru) {
25186 pgd_t *pgd;
25187 spinlock_t *pgt_lock;
25188 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25189 /* the pgt_lock only for Xen */
25190 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25191 spin_lock(pgt_lock);
25192 +#endif
25193
25194 if (pgd_none(*pgd))
25195 set_pgd(pgd, *pgd_ref);
25196 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25197 BUG_ON(pgd_page_vaddr(*pgd)
25198 != pgd_page_vaddr(*pgd_ref));
25199
25200 +#ifndef CONFIG_PAX_PER_CPU_PGD
25201 spin_unlock(pgt_lock);
25202 +#endif
25203 +
25204 }
25205 spin_unlock(&pgd_lock);
25206 }
25207 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25208 {
25209 if (pgd_none(*pgd)) {
25210 pud_t *pud = (pud_t *)spp_getpage();
25211 - pgd_populate(&init_mm, pgd, pud);
25212 + pgd_populate_kernel(&init_mm, pgd, pud);
25213 if (pud != pud_offset(pgd, 0))
25214 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25215 pud, pud_offset(pgd, 0));
25216 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25217 {
25218 if (pud_none(*pud)) {
25219 pmd_t *pmd = (pmd_t *) spp_getpage();
25220 - pud_populate(&init_mm, pud, pmd);
25221 + pud_populate_kernel(&init_mm, pud, pmd);
25222 if (pmd != pmd_offset(pud, 0))
25223 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25224 pmd, pmd_offset(pud, 0));
25225 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25226 pmd = fill_pmd(pud, vaddr);
25227 pte = fill_pte(pmd, vaddr);
25228
25229 + pax_open_kernel();
25230 set_pte(pte, new_pte);
25231 + pax_close_kernel();
25232
25233 /*
25234 * It's enough to flush this one mapping.
25235 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25236 pgd = pgd_offset_k((unsigned long)__va(phys));
25237 if (pgd_none(*pgd)) {
25238 pud = (pud_t *) spp_getpage();
25239 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25240 - _PAGE_USER));
25241 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25242 }
25243 pud = pud_offset(pgd, (unsigned long)__va(phys));
25244 if (pud_none(*pud)) {
25245 pmd = (pmd_t *) spp_getpage();
25246 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25247 - _PAGE_USER));
25248 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25249 }
25250 pmd = pmd_offset(pud, phys);
25251 BUG_ON(!pmd_none(*pmd));
25252 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25253 if (pfn >= pgt_buf_top)
25254 panic("alloc_low_page: ran out of memory");
25255
25256 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25257 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25258 clear_page(adr);
25259 *phys = pfn * PAGE_SIZE;
25260 return adr;
25261 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25262
25263 phys = __pa(virt);
25264 left = phys & (PAGE_SIZE - 1);
25265 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25266 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25267 adr = (void *)(((unsigned long)adr) | left);
25268
25269 return adr;
25270 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25271 unmap_low_page(pmd);
25272
25273 spin_lock(&init_mm.page_table_lock);
25274 - pud_populate(&init_mm, pud, __va(pmd_phys));
25275 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25276 spin_unlock(&init_mm.page_table_lock);
25277 }
25278 __flush_tlb_all();
25279 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25280 unmap_low_page(pud);
25281
25282 spin_lock(&init_mm.page_table_lock);
25283 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25284 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25285 spin_unlock(&init_mm.page_table_lock);
25286 pgd_changed = true;
25287 }
25288 @@ -691,6 +705,12 @@ void __init mem_init(void)
25289
25290 pci_iommu_alloc();
25291
25292 +#ifdef CONFIG_PAX_PER_CPU_PGD
25293 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25294 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25295 + KERNEL_PGD_PTRS);
25296 +#endif
25297 +
25298 /* clear_bss() already clear the empty_zero_page */
25299
25300 reservedpages = 0;
25301 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25302 static struct vm_area_struct gate_vma = {
25303 .vm_start = VSYSCALL_START,
25304 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25305 - .vm_page_prot = PAGE_READONLY_EXEC,
25306 - .vm_flags = VM_READ | VM_EXEC
25307 + .vm_page_prot = PAGE_READONLY,
25308 + .vm_flags = VM_READ
25309 };
25310
25311 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25312 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25313
25314 const char *arch_vma_name(struct vm_area_struct *vma)
25315 {
25316 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25317 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25318 return "[vdso]";
25319 if (vma == &gate_vma)
25320 return "[vsyscall]";
25321 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25322 index 7b179b4..6bd1777 100644
25323 --- a/arch/x86/mm/iomap_32.c
25324 +++ b/arch/x86/mm/iomap_32.c
25325 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25326 type = kmap_atomic_idx_push();
25327 idx = type + KM_TYPE_NR * smp_processor_id();
25328 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25329 +
25330 + pax_open_kernel();
25331 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25332 + pax_close_kernel();
25333 +
25334 arch_flush_lazy_mmu_mode();
25335
25336 return (void *)vaddr;
25337 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25338 index 78fe3f1..8293b6f 100644
25339 --- a/arch/x86/mm/ioremap.c
25340 +++ b/arch/x86/mm/ioremap.c
25341 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25342 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25343 int is_ram = page_is_ram(pfn);
25344
25345 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25346 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25347 return NULL;
25348 WARN_ON_ONCE(is_ram);
25349 }
25350 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25351
25352 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25353 if (page_is_ram(start >> PAGE_SHIFT))
25354 +#ifdef CONFIG_HIGHMEM
25355 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25356 +#endif
25357 return __va(phys);
25358
25359 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25360 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25361 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25362
25363 static __initdata int after_paging_init;
25364 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25365 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25366
25367 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25368 {
25369 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25370 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25371
25372 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25373 - memset(bm_pte, 0, sizeof(bm_pte));
25374 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25375 + pmd_populate_user(&init_mm, pmd, bm_pte);
25376
25377 /*
25378 * The boot-ioremap range spans multiple pmds, for which
25379 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25380 index d87dd6d..bf3fa66 100644
25381 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25382 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25383 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25384 * memory (e.g. tracked pages)? For now, we need this to avoid
25385 * invoking kmemcheck for PnP BIOS calls.
25386 */
25387 - if (regs->flags & X86_VM_MASK)
25388 + if (v8086_mode(regs))
25389 return false;
25390 - if (regs->cs != __KERNEL_CS)
25391 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25392 return false;
25393
25394 pte = kmemcheck_pte_lookup(address);
25395 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25396 index 845df68..1d8d29f 100644
25397 --- a/arch/x86/mm/mmap.c
25398 +++ b/arch/x86/mm/mmap.c
25399 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25400 * Leave an at least ~128 MB hole with possible stack randomization.
25401 */
25402 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25403 -#define MAX_GAP (TASK_SIZE/6*5)
25404 +#define MAX_GAP (pax_task_size/6*5)
25405
25406 static int mmap_is_legacy(void)
25407 {
25408 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25409 return rnd << PAGE_SHIFT;
25410 }
25411
25412 -static unsigned long mmap_base(void)
25413 +static unsigned long mmap_base(struct mm_struct *mm)
25414 {
25415 unsigned long gap = rlimit(RLIMIT_STACK);
25416 + unsigned long pax_task_size = TASK_SIZE;
25417 +
25418 +#ifdef CONFIG_PAX_SEGMEXEC
25419 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25420 + pax_task_size = SEGMEXEC_TASK_SIZE;
25421 +#endif
25422
25423 if (gap < MIN_GAP)
25424 gap = MIN_GAP;
25425 else if (gap > MAX_GAP)
25426 gap = MAX_GAP;
25427
25428 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25429 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25430 }
25431
25432 /*
25433 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25434 * does, but not when emulating X86_32
25435 */
25436 -static unsigned long mmap_legacy_base(void)
25437 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25438 {
25439 - if (mmap_is_ia32())
25440 + if (mmap_is_ia32()) {
25441 +
25442 +#ifdef CONFIG_PAX_SEGMEXEC
25443 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25444 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25445 + else
25446 +#endif
25447 +
25448 return TASK_UNMAPPED_BASE;
25449 - else
25450 + } else
25451 return TASK_UNMAPPED_BASE + mmap_rnd();
25452 }
25453
25454 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25455 void arch_pick_mmap_layout(struct mm_struct *mm)
25456 {
25457 if (mmap_is_legacy()) {
25458 - mm->mmap_base = mmap_legacy_base();
25459 + mm->mmap_base = mmap_legacy_base(mm);
25460 +
25461 +#ifdef CONFIG_PAX_RANDMMAP
25462 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25463 + mm->mmap_base += mm->delta_mmap;
25464 +#endif
25465 +
25466 mm->get_unmapped_area = arch_get_unmapped_area;
25467 mm->unmap_area = arch_unmap_area;
25468 } else {
25469 - mm->mmap_base = mmap_base();
25470 + mm->mmap_base = mmap_base(mm);
25471 +
25472 +#ifdef CONFIG_PAX_RANDMMAP
25473 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25474 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25475 +#endif
25476 +
25477 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25478 mm->unmap_area = arch_unmap_area_topdown;
25479 }
25480 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25481 index dc0b727..dc9d71a 100644
25482 --- a/arch/x86/mm/mmio-mod.c
25483 +++ b/arch/x86/mm/mmio-mod.c
25484 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25485 break;
25486 default:
25487 {
25488 - unsigned char *ip = (unsigned char *)instptr;
25489 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25490 my_trace->opcode = MMIO_UNKNOWN_OP;
25491 my_trace->width = 0;
25492 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25493 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25494 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25495 void __iomem *addr)
25496 {
25497 - static atomic_t next_id;
25498 + static atomic_unchecked_t next_id;
25499 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25500 /* These are page-unaligned. */
25501 struct mmiotrace_map map = {
25502 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25503 .private = trace
25504 },
25505 .phys = offset,
25506 - .id = atomic_inc_return(&next_id)
25507 + .id = atomic_inc_return_unchecked(&next_id)
25508 };
25509 map.map_id = trace->id;
25510
25511 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25512 index b008656..773eac2 100644
25513 --- a/arch/x86/mm/pageattr-test.c
25514 +++ b/arch/x86/mm/pageattr-test.c
25515 @@ -36,7 +36,7 @@ enum {
25516
25517 static int pte_testbit(pte_t pte)
25518 {
25519 - return pte_flags(pte) & _PAGE_UNUSED1;
25520 + return pte_flags(pte) & _PAGE_CPA_TEST;
25521 }
25522
25523 struct split_state {
25524 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25525 index a718e0d..45efc32 100644
25526 --- a/arch/x86/mm/pageattr.c
25527 +++ b/arch/x86/mm/pageattr.c
25528 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25529 */
25530 #ifdef CONFIG_PCI_BIOS
25531 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25532 - pgprot_val(forbidden) |= _PAGE_NX;
25533 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25534 #endif
25535
25536 /*
25537 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25538 * Does not cover __inittext since that is gone later on. On
25539 * 64bit we do not enforce !NX on the low mapping
25540 */
25541 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25542 - pgprot_val(forbidden) |= _PAGE_NX;
25543 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25544 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25545
25546 +#ifdef CONFIG_DEBUG_RODATA
25547 /*
25548 * The .rodata section needs to be read-only. Using the pfn
25549 * catches all aliases.
25550 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25551 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25552 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25553 pgprot_val(forbidden) |= _PAGE_RW;
25554 +#endif
25555
25556 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25557 /*
25558 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25559 }
25560 #endif
25561
25562 +#ifdef CONFIG_PAX_KERNEXEC
25563 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25564 + pgprot_val(forbidden) |= _PAGE_RW;
25565 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25566 + }
25567 +#endif
25568 +
25569 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25570
25571 return prot;
25572 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25573 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25574 {
25575 /* change init_mm */
25576 + pax_open_kernel();
25577 set_pte_atomic(kpte, pte);
25578 +
25579 #ifdef CONFIG_X86_32
25580 if (!SHARED_KERNEL_PMD) {
25581 +
25582 +#ifdef CONFIG_PAX_PER_CPU_PGD
25583 + unsigned long cpu;
25584 +#else
25585 struct page *page;
25586 +#endif
25587
25588 +#ifdef CONFIG_PAX_PER_CPU_PGD
25589 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25590 + pgd_t *pgd = get_cpu_pgd(cpu);
25591 +#else
25592 list_for_each_entry(page, &pgd_list, lru) {
25593 - pgd_t *pgd;
25594 + pgd_t *pgd = (pgd_t *)page_address(page);
25595 +#endif
25596 +
25597 pud_t *pud;
25598 pmd_t *pmd;
25599
25600 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25601 + pgd += pgd_index(address);
25602 pud = pud_offset(pgd, address);
25603 pmd = pmd_offset(pud, address);
25604 set_pte_atomic((pte_t *)pmd, pte);
25605 }
25606 }
25607 #endif
25608 + pax_close_kernel();
25609 }
25610
25611 static int
25612 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25613 index 3d68ef6..7f69136 100644
25614 --- a/arch/x86/mm/pat.c
25615 +++ b/arch/x86/mm/pat.c
25616 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25617
25618 if (!entry) {
25619 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25620 - current->comm, current->pid, start, end - 1);
25621 + current->comm, task_pid_nr(current), start, end - 1);
25622 return -EINVAL;
25623 }
25624
25625 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25626
25627 while (cursor < to) {
25628 if (!devmem_is_allowed(pfn)) {
25629 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25630 - current->comm, from, to - 1);
25631 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25632 + current->comm, from, to - 1, cursor);
25633 return 0;
25634 }
25635 cursor += PAGE_SIZE;
25636 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25637 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25638 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25639 "for [mem %#010Lx-%#010Lx]\n",
25640 - current->comm, current->pid,
25641 + current->comm, task_pid_nr(current),
25642 cattr_name(flags),
25643 base, (unsigned long long)(base + size-1));
25644 return -EINVAL;
25645 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25646 flags = lookup_memtype(paddr);
25647 if (want_flags != flags) {
25648 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25649 - current->comm, current->pid,
25650 + current->comm, task_pid_nr(current),
25651 cattr_name(want_flags),
25652 (unsigned long long)paddr,
25653 (unsigned long long)(paddr + size - 1),
25654 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25655 free_memtype(paddr, paddr + size);
25656 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25657 " for [mem %#010Lx-%#010Lx], got %s\n",
25658 - current->comm, current->pid,
25659 + current->comm, task_pid_nr(current),
25660 cattr_name(want_flags),
25661 (unsigned long long)paddr,
25662 (unsigned long long)(paddr + size - 1),
25663 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25664 index 9f0614d..92ae64a 100644
25665 --- a/arch/x86/mm/pf_in.c
25666 +++ b/arch/x86/mm/pf_in.c
25667 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25668 int i;
25669 enum reason_type rv = OTHERS;
25670
25671 - p = (unsigned char *)ins_addr;
25672 + p = (unsigned char *)ktla_ktva(ins_addr);
25673 p += skip_prefix(p, &prf);
25674 p += get_opcode(p, &opcode);
25675
25676 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25677 struct prefix_bits prf;
25678 int i;
25679
25680 - p = (unsigned char *)ins_addr;
25681 + p = (unsigned char *)ktla_ktva(ins_addr);
25682 p += skip_prefix(p, &prf);
25683 p += get_opcode(p, &opcode);
25684
25685 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25686 struct prefix_bits prf;
25687 int i;
25688
25689 - p = (unsigned char *)ins_addr;
25690 + p = (unsigned char *)ktla_ktva(ins_addr);
25691 p += skip_prefix(p, &prf);
25692 p += get_opcode(p, &opcode);
25693
25694 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25695 struct prefix_bits prf;
25696 int i;
25697
25698 - p = (unsigned char *)ins_addr;
25699 + p = (unsigned char *)ktla_ktva(ins_addr);
25700 p += skip_prefix(p, &prf);
25701 p += get_opcode(p, &opcode);
25702 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25703 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25704 struct prefix_bits prf;
25705 int i;
25706
25707 - p = (unsigned char *)ins_addr;
25708 + p = (unsigned char *)ktla_ktva(ins_addr);
25709 p += skip_prefix(p, &prf);
25710 p += get_opcode(p, &opcode);
25711 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25712 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25713 index 8573b83..4f3ed7e 100644
25714 --- a/arch/x86/mm/pgtable.c
25715 +++ b/arch/x86/mm/pgtable.c
25716 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25717 list_del(&page->lru);
25718 }
25719
25720 -#define UNSHARED_PTRS_PER_PGD \
25721 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25722 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25723 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25724
25725 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25726 +{
25727 + unsigned int count = USER_PGD_PTRS;
25728
25729 + while (count--)
25730 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25731 +}
25732 +#endif
25733 +
25734 +#ifdef CONFIG_PAX_PER_CPU_PGD
25735 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25736 +{
25737 + unsigned int count = USER_PGD_PTRS;
25738 +
25739 + while (count--) {
25740 + pgd_t pgd;
25741 +
25742 +#ifdef CONFIG_X86_64
25743 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25744 +#else
25745 + pgd = *src++;
25746 +#endif
25747 +
25748 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25749 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25750 +#endif
25751 +
25752 + *dst++ = pgd;
25753 + }
25754 +
25755 +}
25756 +#endif
25757 +
25758 +#ifdef CONFIG_X86_64
25759 +#define pxd_t pud_t
25760 +#define pyd_t pgd_t
25761 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25762 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25763 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25764 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25765 +#define PYD_SIZE PGDIR_SIZE
25766 +#else
25767 +#define pxd_t pmd_t
25768 +#define pyd_t pud_t
25769 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25770 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25771 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25772 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25773 +#define PYD_SIZE PUD_SIZE
25774 +#endif
25775 +
25776 +#ifdef CONFIG_PAX_PER_CPU_PGD
25777 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25778 +static inline void pgd_dtor(pgd_t *pgd) {}
25779 +#else
25780 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25781 {
25782 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25783 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25784 pgd_list_del(pgd);
25785 spin_unlock(&pgd_lock);
25786 }
25787 +#endif
25788
25789 /*
25790 * List of all pgd's needed for non-PAE so it can invalidate entries
25791 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25792 * -- wli
25793 */
25794
25795 -#ifdef CONFIG_X86_PAE
25796 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25797 /*
25798 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25799 * updating the top-level pagetable entries to guarantee the
25800 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25801 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25802 * and initialize the kernel pmds here.
25803 */
25804 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25805 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25806
25807 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25808 {
25809 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25810 */
25811 flush_tlb_mm(mm);
25812 }
25813 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25814 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25815 #else /* !CONFIG_X86_PAE */
25816
25817 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25818 -#define PREALLOCATED_PMDS 0
25819 +#define PREALLOCATED_PXDS 0
25820
25821 #endif /* CONFIG_X86_PAE */
25822
25823 -static void free_pmds(pmd_t *pmds[])
25824 +static void free_pxds(pxd_t *pxds[])
25825 {
25826 int i;
25827
25828 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25829 - if (pmds[i])
25830 - free_page((unsigned long)pmds[i]);
25831 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25832 + if (pxds[i])
25833 + free_page((unsigned long)pxds[i]);
25834 }
25835
25836 -static int preallocate_pmds(pmd_t *pmds[])
25837 +static int preallocate_pxds(pxd_t *pxds[])
25838 {
25839 int i;
25840 bool failed = false;
25841
25842 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25843 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25844 - if (pmd == NULL)
25845 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25846 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25847 + if (pxd == NULL)
25848 failed = true;
25849 - pmds[i] = pmd;
25850 + pxds[i] = pxd;
25851 }
25852
25853 if (failed) {
25854 - free_pmds(pmds);
25855 + free_pxds(pxds);
25856 return -ENOMEM;
25857 }
25858
25859 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25860 * preallocate which never got a corresponding vma will need to be
25861 * freed manually.
25862 */
25863 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25864 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25865 {
25866 int i;
25867
25868 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25869 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25870 pgd_t pgd = pgdp[i];
25871
25872 if (pgd_val(pgd) != 0) {
25873 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25874 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25875
25876 - pgdp[i] = native_make_pgd(0);
25877 + set_pgd(pgdp + i, native_make_pgd(0));
25878
25879 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25880 - pmd_free(mm, pmd);
25881 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25882 + pxd_free(mm, pxd);
25883 }
25884 }
25885 }
25886
25887 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25888 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25889 {
25890 - pud_t *pud;
25891 + pyd_t *pyd;
25892 unsigned long addr;
25893 int i;
25894
25895 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25896 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25897 return;
25898
25899 - pud = pud_offset(pgd, 0);
25900 +#ifdef CONFIG_X86_64
25901 + pyd = pyd_offset(mm, 0L);
25902 +#else
25903 + pyd = pyd_offset(pgd, 0L);
25904 +#endif
25905
25906 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25907 - i++, pud++, addr += PUD_SIZE) {
25908 - pmd_t *pmd = pmds[i];
25909 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25910 + i++, pyd++, addr += PYD_SIZE) {
25911 + pxd_t *pxd = pxds[i];
25912
25913 if (i >= KERNEL_PGD_BOUNDARY)
25914 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25915 - sizeof(pmd_t) * PTRS_PER_PMD);
25916 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25917 + sizeof(pxd_t) * PTRS_PER_PMD);
25918
25919 - pud_populate(mm, pud, pmd);
25920 + pyd_populate(mm, pyd, pxd);
25921 }
25922 }
25923
25924 pgd_t *pgd_alloc(struct mm_struct *mm)
25925 {
25926 pgd_t *pgd;
25927 - pmd_t *pmds[PREALLOCATED_PMDS];
25928 + pxd_t *pxds[PREALLOCATED_PXDS];
25929
25930 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25931
25932 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25933
25934 mm->pgd = pgd;
25935
25936 - if (preallocate_pmds(pmds) != 0)
25937 + if (preallocate_pxds(pxds) != 0)
25938 goto out_free_pgd;
25939
25940 if (paravirt_pgd_alloc(mm) != 0)
25941 - goto out_free_pmds;
25942 + goto out_free_pxds;
25943
25944 /*
25945 * Make sure that pre-populating the pmds is atomic with
25946 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25947 spin_lock(&pgd_lock);
25948
25949 pgd_ctor(mm, pgd);
25950 - pgd_prepopulate_pmd(mm, pgd, pmds);
25951 + pgd_prepopulate_pxd(mm, pgd, pxds);
25952
25953 spin_unlock(&pgd_lock);
25954
25955 return pgd;
25956
25957 -out_free_pmds:
25958 - free_pmds(pmds);
25959 +out_free_pxds:
25960 + free_pxds(pxds);
25961 out_free_pgd:
25962 free_page((unsigned long)pgd);
25963 out:
25964 @@ -295,7 +356,7 @@ out:
25965
25966 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25967 {
25968 - pgd_mop_up_pmds(mm, pgd);
25969 + pgd_mop_up_pxds(mm, pgd);
25970 pgd_dtor(pgd);
25971 paravirt_pgd_free(mm, pgd);
25972 free_page((unsigned long)pgd);
25973 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25974 index a69bcb8..19068ab 100644
25975 --- a/arch/x86/mm/pgtable_32.c
25976 +++ b/arch/x86/mm/pgtable_32.c
25977 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25978 return;
25979 }
25980 pte = pte_offset_kernel(pmd, vaddr);
25981 +
25982 + pax_open_kernel();
25983 if (pte_val(pteval))
25984 set_pte_at(&init_mm, vaddr, pte, pteval);
25985 else
25986 pte_clear(&init_mm, vaddr, pte);
25987 + pax_close_kernel();
25988
25989 /*
25990 * It's enough to flush this one mapping.
25991 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25992 index 410531d..0f16030 100644
25993 --- a/arch/x86/mm/setup_nx.c
25994 +++ b/arch/x86/mm/setup_nx.c
25995 @@ -5,8 +5,10 @@
25996 #include <asm/pgtable.h>
25997 #include <asm/proto.h>
25998
25999 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26000 static int disable_nx __cpuinitdata;
26001
26002 +#ifndef CONFIG_PAX_PAGEEXEC
26003 /*
26004 * noexec = on|off
26005 *
26006 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
26007 return 0;
26008 }
26009 early_param("noexec", noexec_setup);
26010 +#endif
26011 +
26012 +#endif
26013
26014 void __cpuinit x86_configure_nx(void)
26015 {
26016 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26017 if (cpu_has_nx && !disable_nx)
26018 __supported_pte_mask |= _PAGE_NX;
26019 else
26020 +#endif
26021 __supported_pte_mask &= ~_PAGE_NX;
26022 }
26023
26024 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
26025 index 613cd83..3a21f1c 100644
26026 --- a/arch/x86/mm/tlb.c
26027 +++ b/arch/x86/mm/tlb.c
26028 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
26029 BUG();
26030 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
26031 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
26032 +
26033 +#ifndef CONFIG_PAX_PER_CPU_PGD
26034 load_cr3(swapper_pg_dir);
26035 +#endif
26036 +
26037 }
26038 }
26039 EXPORT_SYMBOL_GPL(leave_mm);
26040 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
26041 index 877b9a1..a8ecf42 100644
26042 --- a/arch/x86/net/bpf_jit.S
26043 +++ b/arch/x86/net/bpf_jit.S
26044 @@ -9,6 +9,7 @@
26045 */
26046 #include <linux/linkage.h>
26047 #include <asm/dwarf2.h>
26048 +#include <asm/alternative-asm.h>
26049
26050 /*
26051 * Calling convention :
26052 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
26053 jle bpf_slow_path_word
26054 mov (SKBDATA,%rsi),%eax
26055 bswap %eax /* ntohl() */
26056 + pax_force_retaddr
26057 ret
26058
26059 sk_load_half:
26060 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
26061 jle bpf_slow_path_half
26062 movzwl (SKBDATA,%rsi),%eax
26063 rol $8,%ax # ntohs()
26064 + pax_force_retaddr
26065 ret
26066
26067 sk_load_byte:
26068 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
26069 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26070 jle bpf_slow_path_byte
26071 movzbl (SKBDATA,%rsi),%eax
26072 + pax_force_retaddr
26073 ret
26074
26075 /**
26076 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
26077 movzbl (SKBDATA,%rsi),%ebx
26078 and $15,%bl
26079 shl $2,%bl
26080 + pax_force_retaddr
26081 ret
26082
26083 /* rsi contains offset and can be scratched */
26084 @@ -109,6 +114,7 @@ bpf_slow_path_word:
26085 js bpf_error
26086 mov -12(%rbp),%eax
26087 bswap %eax
26088 + pax_force_retaddr
26089 ret
26090
26091 bpf_slow_path_half:
26092 @@ -117,12 +123,14 @@ bpf_slow_path_half:
26093 mov -12(%rbp),%ax
26094 rol $8,%ax
26095 movzwl %ax,%eax
26096 + pax_force_retaddr
26097 ret
26098
26099 bpf_slow_path_byte:
26100 bpf_slow_path_common(1)
26101 js bpf_error
26102 movzbl -12(%rbp),%eax
26103 + pax_force_retaddr
26104 ret
26105
26106 bpf_slow_path_byte_msh:
26107 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26108 and $15,%al
26109 shl $2,%al
26110 xchg %eax,%ebx
26111 + pax_force_retaddr
26112 ret
26113
26114 #define sk_negative_common(SIZE) \
26115 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26116 sk_negative_common(4)
26117 mov (%rax), %eax
26118 bswap %eax
26119 + pax_force_retaddr
26120 ret
26121
26122 bpf_slow_path_half_neg:
26123 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26124 mov (%rax),%ax
26125 rol $8,%ax
26126 movzwl %ax,%eax
26127 + pax_force_retaddr
26128 ret
26129
26130 bpf_slow_path_byte_neg:
26131 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26132 .globl sk_load_byte_negative_offset
26133 sk_negative_common(1)
26134 movzbl (%rax), %eax
26135 + pax_force_retaddr
26136 ret
26137
26138 bpf_slow_path_byte_msh_neg:
26139 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26140 and $15,%al
26141 shl $2,%al
26142 xchg %eax,%ebx
26143 + pax_force_retaddr
26144 ret
26145
26146 bpf_error:
26147 @@ -197,4 +210,5 @@ bpf_error:
26148 xor %eax,%eax
26149 mov -8(%rbp),%rbx
26150 leaveq
26151 + pax_force_retaddr
26152 ret
26153 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26154 index 33643a8..f6211a0 100644
26155 --- a/arch/x86/net/bpf_jit_comp.c
26156 +++ b/arch/x86/net/bpf_jit_comp.c
26157 @@ -11,6 +11,7 @@
26158 #include <asm/cacheflush.h>
26159 #include <linux/netdevice.h>
26160 #include <linux/filter.h>
26161 +#include <linux/random.h>
26162
26163 /*
26164 * Conventions :
26165 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
26166 return ptr + len;
26167 }
26168
26169 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26170 +#define MAX_INSTR_CODE_SIZE 96
26171 +#else
26172 +#define MAX_INSTR_CODE_SIZE 64
26173 +#endif
26174 +
26175 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
26176
26177 #define EMIT1(b1) EMIT(b1, 1)
26178 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
26179 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
26180 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
26181 +
26182 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26183 +/* original constant will appear in ecx */
26184 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
26185 +do { \
26186 + /* mov ecx, randkey */ \
26187 + EMIT1(0xb9); \
26188 + EMIT(_key, 4); \
26189 + /* xor ecx, randkey ^ off */ \
26190 + EMIT2(0x81, 0xf1); \
26191 + EMIT((_key) ^ (_off), 4); \
26192 +} while (0)
26193 +
26194 +#define EMIT1_off32(b1, _off) \
26195 +do { \
26196 + switch (b1) { \
26197 + case 0x05: /* add eax, imm32 */ \
26198 + case 0x2d: /* sub eax, imm32 */ \
26199 + case 0x25: /* and eax, imm32 */ \
26200 + case 0x0d: /* or eax, imm32 */ \
26201 + case 0xb8: /* mov eax, imm32 */ \
26202 + case 0x3d: /* cmp eax, imm32 */ \
26203 + case 0xa9: /* test eax, imm32 */ \
26204 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26205 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
26206 + break; \
26207 + case 0xbb: /* mov ebx, imm32 */ \
26208 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26209 + /* mov ebx, ecx */ \
26210 + EMIT2(0x89, 0xcb); \
26211 + break; \
26212 + case 0xbe: /* mov esi, imm32 */ \
26213 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26214 + /* mov esi, ecx */ \
26215 + EMIT2(0x89, 0xce); \
26216 + break; \
26217 + case 0xe9: /* jmp rel imm32 */ \
26218 + EMIT1(b1); \
26219 + EMIT(_off, 4); \
26220 + /* prevent fall-through, we're not called if off = 0 */ \
26221 + EMIT(0xcccccccc, 4); \
26222 + EMIT(0xcccccccc, 4); \
26223 + break; \
26224 + default: \
26225 + EMIT1(b1); \
26226 + EMIT(_off, 4); \
26227 + } \
26228 +} while (0)
26229 +
26230 +#define EMIT2_off32(b1, b2, _off) \
26231 +do { \
26232 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
26233 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
26234 + EMIT(randkey, 4); \
26235 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
26236 + EMIT((_off) - randkey, 4); \
26237 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
26238 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26239 + /* imul eax, ecx */ \
26240 + EMIT3(0x0f, 0xaf, 0xc1); \
26241 + } else { \
26242 + EMIT2(b1, b2); \
26243 + EMIT(_off, 4); \
26244 + } \
26245 +} while (0)
26246 +#else
26247 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
26248 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
26249 +#endif
26250
26251 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
26252 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
26253 @@ -89,6 +164,24 @@ do { \
26254 #define X86_JBE 0x76
26255 #define X86_JA 0x77
26256
26257 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26258 +#define APPEND_FLOW_VERIFY() \
26259 +do { \
26260 + /* mov ecx, randkey */ \
26261 + EMIT1(0xb9); \
26262 + EMIT(randkey, 4); \
26263 + /* cmp ecx, randkey */ \
26264 + EMIT2(0x81, 0xf9); \
26265 + EMIT(randkey, 4); \
26266 + /* jz after 8 int 3s */ \
26267 + EMIT2(0x74, 0x08); \
26268 + EMIT(0xcccccccc, 4); \
26269 + EMIT(0xcccccccc, 4); \
26270 +} while (0)
26271 +#else
26272 +#define APPEND_FLOW_VERIFY() do { } while (0)
26273 +#endif
26274 +
26275 #define EMIT_COND_JMP(op, offset) \
26276 do { \
26277 if (is_near(offset)) \
26278 @@ -96,6 +189,7 @@ do { \
26279 else { \
26280 EMIT2(0x0f, op + 0x10); \
26281 EMIT(offset, 4); /* jxx .+off32 */ \
26282 + APPEND_FLOW_VERIFY(); \
26283 } \
26284 } while (0)
26285
26286 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
26287 set_fs(old_fs);
26288 }
26289
26290 +struct bpf_jit_work {
26291 + struct work_struct work;
26292 + void *image;
26293 +};
26294 +
26295 #define CHOOSE_LOAD_FUNC(K, func) \
26296 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26297
26298 void bpf_jit_compile(struct sk_filter *fp)
26299 {
26300 - u8 temp[64];
26301 + u8 temp[MAX_INSTR_CODE_SIZE];
26302 u8 *prog;
26303 unsigned int proglen, oldproglen = 0;
26304 int ilen, i;
26305 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
26306 unsigned int *addrs;
26307 const struct sock_filter *filter = fp->insns;
26308 int flen = fp->len;
26309 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26310 + unsigned int randkey;
26311 +#endif
26312
26313 if (!bpf_jit_enable)
26314 return;
26315 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
26316 if (addrs == NULL)
26317 return;
26318
26319 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26320 + if (!fp->work)
26321 + goto out;
26322 +
26323 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26324 + randkey = get_random_int();
26325 +#endif
26326 +
26327 /* Before first pass, make a rough estimation of addrs[]
26328 - * each bpf instruction is translated to less than 64 bytes
26329 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
26330 */
26331 for (proglen = 0, i = 0; i < flen; i++) {
26332 - proglen += 64;
26333 + proglen += MAX_INSTR_CODE_SIZE;
26334 addrs[i] = proglen;
26335 }
26336 cleanup_addr = proglen; /* epilogue address */
26337 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
26338 case BPF_S_ALU_MUL_K: /* A *= K */
26339 if (is_imm8(K))
26340 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
26341 - else {
26342 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
26343 - EMIT(K, 4);
26344 - }
26345 + else
26346 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
26347 break;
26348 case BPF_S_ALU_DIV_X: /* A /= X; */
26349 seen |= SEEN_XREG;
26350 @@ -281,8 +389,14 @@ void bpf_jit_compile(struct sk_filter *fp)
26351 EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */
26352 break;
26353 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
26354 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26355 + DILUTE_CONST_SEQUENCE(K, randkey);
26356 + // imul rax, rcx
26357 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
26358 +#else
26359 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
26360 EMIT(K, 4);
26361 +#endif
26362 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
26363 break;
26364 case BPF_S_ALU_AND_X:
26365 @@ -509,8 +623,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
26366 if (is_imm8(K)) {
26367 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
26368 } else {
26369 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
26370 - EMIT(K, 4);
26371 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
26372 }
26373 } else {
26374 EMIT2(0x89,0xde); /* mov %ebx,%esi */
26375 @@ -593,17 +706,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26376 break;
26377 default:
26378 /* hmm, too complex filter, give up with jit compiler */
26379 - goto out;
26380 + goto error;
26381 }
26382 ilen = prog - temp;
26383 if (image) {
26384 if (unlikely(proglen + ilen > oldproglen)) {
26385 pr_err("bpb_jit_compile fatal error\n");
26386 - kfree(addrs);
26387 - module_free(NULL, image);
26388 - return;
26389 + module_free_exec(NULL, image);
26390 + goto error;
26391 }
26392 + pax_open_kernel();
26393 memcpy(image + proglen, temp, ilen);
26394 + pax_close_kernel();
26395 }
26396 proglen += ilen;
26397 addrs[i] = proglen;
26398 @@ -624,11 +738,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26399 break;
26400 }
26401 if (proglen == oldproglen) {
26402 - image = module_alloc(max_t(unsigned int,
26403 - proglen,
26404 - sizeof(struct work_struct)));
26405 + image = module_alloc_exec(proglen);
26406 if (!image)
26407 - goto out;
26408 + goto error;
26409 }
26410 oldproglen = proglen;
26411 }
26412 @@ -644,7 +756,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26413 bpf_flush_icache(image, image + proglen);
26414
26415 fp->bpf_func = (void *)image;
26416 - }
26417 + } else
26418 +error:
26419 + kfree(fp->work);
26420 +
26421 out:
26422 kfree(addrs);
26423 return;
26424 @@ -652,18 +767,20 @@ out:
26425
26426 static void jit_free_defer(struct work_struct *arg)
26427 {
26428 - module_free(NULL, arg);
26429 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26430 + kfree(arg);
26431 }
26432
26433 /* run from softirq, we must use a work_struct to call
26434 - * module_free() from process context
26435 + * module_free_exec() from process context
26436 */
26437 void bpf_jit_free(struct sk_filter *fp)
26438 {
26439 if (fp->bpf_func != sk_run_filter) {
26440 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26441 + struct work_struct *work = &fp->work->work;
26442
26443 INIT_WORK(work, jit_free_defer);
26444 + fp->work->image = fp->bpf_func;
26445 schedule_work(work);
26446 }
26447 }
26448 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26449 index d6aa6e8..266395a 100644
26450 --- a/arch/x86/oprofile/backtrace.c
26451 +++ b/arch/x86/oprofile/backtrace.c
26452 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26453 struct stack_frame_ia32 *fp;
26454 unsigned long bytes;
26455
26456 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26457 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26458 if (bytes != sizeof(bufhead))
26459 return NULL;
26460
26461 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26462 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26463
26464 oprofile_add_trace(bufhead[0].return_address);
26465
26466 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26467 struct stack_frame bufhead[2];
26468 unsigned long bytes;
26469
26470 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26471 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26472 if (bytes != sizeof(bufhead))
26473 return NULL;
26474
26475 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26476 {
26477 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26478
26479 - if (!user_mode_vm(regs)) {
26480 + if (!user_mode(regs)) {
26481 unsigned long stack = kernel_stack_pointer(regs);
26482 if (depth)
26483 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26484 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26485 index e14a2ff..3fd6b58 100644
26486 --- a/arch/x86/pci/mrst.c
26487 +++ b/arch/x86/pci/mrst.c
26488 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26489 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26490 pci_mmcfg_late_init();
26491 pcibios_enable_irq = mrst_pci_irq_enable;
26492 - pci_root_ops = pci_mrst_ops;
26493 + pax_open_kernel();
26494 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26495 + pax_close_kernel();
26496 pci_soc_mode = 1;
26497 /* Continue with standard init */
26498 return 1;
26499 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26500 index da8fe05..7ee6704 100644
26501 --- a/arch/x86/pci/pcbios.c
26502 +++ b/arch/x86/pci/pcbios.c
26503 @@ -79,50 +79,93 @@ union bios32 {
26504 static struct {
26505 unsigned long address;
26506 unsigned short segment;
26507 -} bios32_indirect = { 0, __KERNEL_CS };
26508 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26509
26510 /*
26511 * Returns the entry point for the given service, NULL on error
26512 */
26513
26514 -static unsigned long bios32_service(unsigned long service)
26515 +static unsigned long __devinit bios32_service(unsigned long service)
26516 {
26517 unsigned char return_code; /* %al */
26518 unsigned long address; /* %ebx */
26519 unsigned long length; /* %ecx */
26520 unsigned long entry; /* %edx */
26521 unsigned long flags;
26522 + struct desc_struct d, *gdt;
26523
26524 local_irq_save(flags);
26525 - __asm__("lcall *(%%edi); cld"
26526 +
26527 + gdt = get_cpu_gdt_table(smp_processor_id());
26528 +
26529 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26530 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26531 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26532 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26533 +
26534 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26535 : "=a" (return_code),
26536 "=b" (address),
26537 "=c" (length),
26538 "=d" (entry)
26539 : "0" (service),
26540 "1" (0),
26541 - "D" (&bios32_indirect));
26542 + "D" (&bios32_indirect),
26543 + "r"(__PCIBIOS_DS)
26544 + : "memory");
26545 +
26546 + pax_open_kernel();
26547 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26548 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26549 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26550 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26551 + pax_close_kernel();
26552 +
26553 local_irq_restore(flags);
26554
26555 switch (return_code) {
26556 - case 0:
26557 - return address + entry;
26558 - case 0x80: /* Not present */
26559 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26560 - return 0;
26561 - default: /* Shouldn't happen */
26562 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26563 - service, return_code);
26564 + case 0: {
26565 + int cpu;
26566 + unsigned char flags;
26567 +
26568 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26569 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26570 + printk(KERN_WARNING "bios32_service: not valid\n");
26571 return 0;
26572 + }
26573 + address = address + PAGE_OFFSET;
26574 + length += 16UL; /* some BIOSs underreport this... */
26575 + flags = 4;
26576 + if (length >= 64*1024*1024) {
26577 + length >>= PAGE_SHIFT;
26578 + flags |= 8;
26579 + }
26580 +
26581 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26582 + gdt = get_cpu_gdt_table(cpu);
26583 + pack_descriptor(&d, address, length, 0x9b, flags);
26584 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26585 + pack_descriptor(&d, address, length, 0x93, flags);
26586 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26587 + }
26588 + return entry;
26589 + }
26590 + case 0x80: /* Not present */
26591 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26592 + return 0;
26593 + default: /* Shouldn't happen */
26594 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26595 + service, return_code);
26596 + return 0;
26597 }
26598 }
26599
26600 static struct {
26601 unsigned long address;
26602 unsigned short segment;
26603 -} pci_indirect = { 0, __KERNEL_CS };
26604 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26605
26606 -static int pci_bios_present;
26607 +static int pci_bios_present __read_only;
26608
26609 static int __devinit check_pcibios(void)
26610 {
26611 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26612 unsigned long flags, pcibios_entry;
26613
26614 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26615 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26616 + pci_indirect.address = pcibios_entry;
26617
26618 local_irq_save(flags);
26619 - __asm__(
26620 - "lcall *(%%edi); cld\n\t"
26621 + __asm__("movw %w6, %%ds\n\t"
26622 + "lcall *%%ss:(%%edi); cld\n\t"
26623 + "push %%ss\n\t"
26624 + "pop %%ds\n\t"
26625 "jc 1f\n\t"
26626 "xor %%ah, %%ah\n"
26627 "1:"
26628 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26629 "=b" (ebx),
26630 "=c" (ecx)
26631 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26632 - "D" (&pci_indirect)
26633 + "D" (&pci_indirect),
26634 + "r" (__PCIBIOS_DS)
26635 : "memory");
26636 local_irq_restore(flags);
26637
26638 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26639
26640 switch (len) {
26641 case 1:
26642 - __asm__("lcall *(%%esi); cld\n\t"
26643 + __asm__("movw %w6, %%ds\n\t"
26644 + "lcall *%%ss:(%%esi); cld\n\t"
26645 + "push %%ss\n\t"
26646 + "pop %%ds\n\t"
26647 "jc 1f\n\t"
26648 "xor %%ah, %%ah\n"
26649 "1:"
26650 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26651 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26652 "b" (bx),
26653 "D" ((long)reg),
26654 - "S" (&pci_indirect));
26655 + "S" (&pci_indirect),
26656 + "r" (__PCIBIOS_DS));
26657 /*
26658 * Zero-extend the result beyond 8 bits, do not trust the
26659 * BIOS having done it:
26660 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26661 *value &= 0xff;
26662 break;
26663 case 2:
26664 - __asm__("lcall *(%%esi); cld\n\t"
26665 + __asm__("movw %w6, %%ds\n\t"
26666 + "lcall *%%ss:(%%esi); cld\n\t"
26667 + "push %%ss\n\t"
26668 + "pop %%ds\n\t"
26669 "jc 1f\n\t"
26670 "xor %%ah, %%ah\n"
26671 "1:"
26672 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26673 : "1" (PCIBIOS_READ_CONFIG_WORD),
26674 "b" (bx),
26675 "D" ((long)reg),
26676 - "S" (&pci_indirect));
26677 + "S" (&pci_indirect),
26678 + "r" (__PCIBIOS_DS));
26679 /*
26680 * Zero-extend the result beyond 16 bits, do not trust the
26681 * BIOS having done it:
26682 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26683 *value &= 0xffff;
26684 break;
26685 case 4:
26686 - __asm__("lcall *(%%esi); cld\n\t"
26687 + __asm__("movw %w6, %%ds\n\t"
26688 + "lcall *%%ss:(%%esi); cld\n\t"
26689 + "push %%ss\n\t"
26690 + "pop %%ds\n\t"
26691 "jc 1f\n\t"
26692 "xor %%ah, %%ah\n"
26693 "1:"
26694 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26695 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26696 "b" (bx),
26697 "D" ((long)reg),
26698 - "S" (&pci_indirect));
26699 + "S" (&pci_indirect),
26700 + "r" (__PCIBIOS_DS));
26701 break;
26702 }
26703
26704 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26705
26706 switch (len) {
26707 case 1:
26708 - __asm__("lcall *(%%esi); cld\n\t"
26709 + __asm__("movw %w6, %%ds\n\t"
26710 + "lcall *%%ss:(%%esi); cld\n\t"
26711 + "push %%ss\n\t"
26712 + "pop %%ds\n\t"
26713 "jc 1f\n\t"
26714 "xor %%ah, %%ah\n"
26715 "1:"
26716 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26717 "c" (value),
26718 "b" (bx),
26719 "D" ((long)reg),
26720 - "S" (&pci_indirect));
26721 + "S" (&pci_indirect),
26722 + "r" (__PCIBIOS_DS));
26723 break;
26724 case 2:
26725 - __asm__("lcall *(%%esi); cld\n\t"
26726 + __asm__("movw %w6, %%ds\n\t"
26727 + "lcall *%%ss:(%%esi); cld\n\t"
26728 + "push %%ss\n\t"
26729 + "pop %%ds\n\t"
26730 "jc 1f\n\t"
26731 "xor %%ah, %%ah\n"
26732 "1:"
26733 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26734 "c" (value),
26735 "b" (bx),
26736 "D" ((long)reg),
26737 - "S" (&pci_indirect));
26738 + "S" (&pci_indirect),
26739 + "r" (__PCIBIOS_DS));
26740 break;
26741 case 4:
26742 - __asm__("lcall *(%%esi); cld\n\t"
26743 + __asm__("movw %w6, %%ds\n\t"
26744 + "lcall *%%ss:(%%esi); cld\n\t"
26745 + "push %%ss\n\t"
26746 + "pop %%ds\n\t"
26747 "jc 1f\n\t"
26748 "xor %%ah, %%ah\n"
26749 "1:"
26750 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26751 "c" (value),
26752 "b" (bx),
26753 "D" ((long)reg),
26754 - "S" (&pci_indirect));
26755 + "S" (&pci_indirect),
26756 + "r" (__PCIBIOS_DS));
26757 break;
26758 }
26759
26760 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26761
26762 DBG("PCI: Fetching IRQ routing table... ");
26763 __asm__("push %%es\n\t"
26764 + "movw %w8, %%ds\n\t"
26765 "push %%ds\n\t"
26766 "pop %%es\n\t"
26767 - "lcall *(%%esi); cld\n\t"
26768 + "lcall *%%ss:(%%esi); cld\n\t"
26769 "pop %%es\n\t"
26770 + "push %%ss\n\t"
26771 + "pop %%ds\n"
26772 "jc 1f\n\t"
26773 "xor %%ah, %%ah\n"
26774 "1:"
26775 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26776 "1" (0),
26777 "D" ((long) &opt),
26778 "S" (&pci_indirect),
26779 - "m" (opt)
26780 + "m" (opt),
26781 + "r" (__PCIBIOS_DS)
26782 : "memory");
26783 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26784 if (ret & 0xff00)
26785 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26786 {
26787 int ret;
26788
26789 - __asm__("lcall *(%%esi); cld\n\t"
26790 + __asm__("movw %w5, %%ds\n\t"
26791 + "lcall *%%ss:(%%esi); cld\n\t"
26792 + "push %%ss\n\t"
26793 + "pop %%ds\n"
26794 "jc 1f\n\t"
26795 "xor %%ah, %%ah\n"
26796 "1:"
26797 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26798 : "0" (PCIBIOS_SET_PCI_HW_INT),
26799 "b" ((dev->bus->number << 8) | dev->devfn),
26800 "c" ((irq << 8) | (pin + 10)),
26801 - "S" (&pci_indirect));
26802 + "S" (&pci_indirect),
26803 + "r" (__PCIBIOS_DS));
26804 return !(ret & 0xff00);
26805 }
26806 EXPORT_SYMBOL(pcibios_set_irq_routing);
26807 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26808 index 40e4469..1ab536e 100644
26809 --- a/arch/x86/platform/efi/efi_32.c
26810 +++ b/arch/x86/platform/efi/efi_32.c
26811 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26812 {
26813 struct desc_ptr gdt_descr;
26814
26815 +#ifdef CONFIG_PAX_KERNEXEC
26816 + struct desc_struct d;
26817 +#endif
26818 +
26819 local_irq_save(efi_rt_eflags);
26820
26821 load_cr3(initial_page_table);
26822 __flush_tlb_all();
26823
26824 +#ifdef CONFIG_PAX_KERNEXEC
26825 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26826 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26827 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26828 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26829 +#endif
26830 +
26831 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26832 gdt_descr.size = GDT_SIZE - 1;
26833 load_gdt(&gdt_descr);
26834 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26835 {
26836 struct desc_ptr gdt_descr;
26837
26838 +#ifdef CONFIG_PAX_KERNEXEC
26839 + struct desc_struct d;
26840 +
26841 + memset(&d, 0, sizeof d);
26842 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26843 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26844 +#endif
26845 +
26846 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26847 gdt_descr.size = GDT_SIZE - 1;
26848 load_gdt(&gdt_descr);
26849 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26850 index fbe66e6..eae5e38 100644
26851 --- a/arch/x86/platform/efi/efi_stub_32.S
26852 +++ b/arch/x86/platform/efi/efi_stub_32.S
26853 @@ -6,7 +6,9 @@
26854 */
26855
26856 #include <linux/linkage.h>
26857 +#include <linux/init.h>
26858 #include <asm/page_types.h>
26859 +#include <asm/segment.h>
26860
26861 /*
26862 * efi_call_phys(void *, ...) is a function with variable parameters.
26863 @@ -20,7 +22,7 @@
26864 * service functions will comply with gcc calling convention, too.
26865 */
26866
26867 -.text
26868 +__INIT
26869 ENTRY(efi_call_phys)
26870 /*
26871 * 0. The function can only be called in Linux kernel. So CS has been
26872 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26873 * The mapping of lower virtual memory has been created in prelog and
26874 * epilog.
26875 */
26876 - movl $1f, %edx
26877 - subl $__PAGE_OFFSET, %edx
26878 - jmp *%edx
26879 +#ifdef CONFIG_PAX_KERNEXEC
26880 + movl $(__KERNEXEC_EFI_DS), %edx
26881 + mov %edx, %ds
26882 + mov %edx, %es
26883 + mov %edx, %ss
26884 + addl $2f,(1f)
26885 + ljmp *(1f)
26886 +
26887 +__INITDATA
26888 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26889 +.previous
26890 +
26891 +2:
26892 + subl $2b,(1b)
26893 +#else
26894 + jmp 1f-__PAGE_OFFSET
26895 1:
26896 +#endif
26897
26898 /*
26899 * 2. Now on the top of stack is the return
26900 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26901 * parameter 2, ..., param n. To make things easy, we save the return
26902 * address of efi_call_phys in a global variable.
26903 */
26904 - popl %edx
26905 - movl %edx, saved_return_addr
26906 - /* get the function pointer into ECX*/
26907 - popl %ecx
26908 - movl %ecx, efi_rt_function_ptr
26909 - movl $2f, %edx
26910 - subl $__PAGE_OFFSET, %edx
26911 - pushl %edx
26912 + popl (saved_return_addr)
26913 + popl (efi_rt_function_ptr)
26914
26915 /*
26916 * 3. Clear PG bit in %CR0.
26917 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26918 /*
26919 * 5. Call the physical function.
26920 */
26921 - jmp *%ecx
26922 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26923
26924 -2:
26925 /*
26926 * 6. After EFI runtime service returns, control will return to
26927 * following instruction. We'd better readjust stack pointer first.
26928 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26929 movl %cr0, %edx
26930 orl $0x80000000, %edx
26931 movl %edx, %cr0
26932 - jmp 1f
26933 -1:
26934 +
26935 /*
26936 * 8. Now restore the virtual mode from flat mode by
26937 * adding EIP with PAGE_OFFSET.
26938 */
26939 - movl $1f, %edx
26940 - jmp *%edx
26941 +#ifdef CONFIG_PAX_KERNEXEC
26942 + movl $(__KERNEL_DS), %edx
26943 + mov %edx, %ds
26944 + mov %edx, %es
26945 + mov %edx, %ss
26946 + ljmp $(__KERNEL_CS),$1f
26947 +#else
26948 + jmp 1f+__PAGE_OFFSET
26949 +#endif
26950 1:
26951
26952 /*
26953 * 9. Balance the stack. And because EAX contain the return value,
26954 * we'd better not clobber it.
26955 */
26956 - leal efi_rt_function_ptr, %edx
26957 - movl (%edx), %ecx
26958 - pushl %ecx
26959 + pushl (efi_rt_function_ptr)
26960
26961 /*
26962 - * 10. Push the saved return address onto the stack and return.
26963 + * 10. Return to the saved return address.
26964 */
26965 - leal saved_return_addr, %edx
26966 - movl (%edx), %ecx
26967 - pushl %ecx
26968 - ret
26969 + jmpl *(saved_return_addr)
26970 ENDPROC(efi_call_phys)
26971 .previous
26972
26973 -.data
26974 +__INITDATA
26975 saved_return_addr:
26976 .long 0
26977 efi_rt_function_ptr:
26978 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26979 index 4c07cca..2c8427d 100644
26980 --- a/arch/x86/platform/efi/efi_stub_64.S
26981 +++ b/arch/x86/platform/efi/efi_stub_64.S
26982 @@ -7,6 +7,7 @@
26983 */
26984
26985 #include <linux/linkage.h>
26986 +#include <asm/alternative-asm.h>
26987
26988 #define SAVE_XMM \
26989 mov %rsp, %rax; \
26990 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26991 call *%rdi
26992 addq $32, %rsp
26993 RESTORE_XMM
26994 + pax_force_retaddr 0, 1
26995 ret
26996 ENDPROC(efi_call0)
26997
26998 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26999 call *%rdi
27000 addq $32, %rsp
27001 RESTORE_XMM
27002 + pax_force_retaddr 0, 1
27003 ret
27004 ENDPROC(efi_call1)
27005
27006 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
27007 call *%rdi
27008 addq $32, %rsp
27009 RESTORE_XMM
27010 + pax_force_retaddr 0, 1
27011 ret
27012 ENDPROC(efi_call2)
27013
27014 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
27015 call *%rdi
27016 addq $32, %rsp
27017 RESTORE_XMM
27018 + pax_force_retaddr 0, 1
27019 ret
27020 ENDPROC(efi_call3)
27021
27022 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
27023 call *%rdi
27024 addq $32, %rsp
27025 RESTORE_XMM
27026 + pax_force_retaddr 0, 1
27027 ret
27028 ENDPROC(efi_call4)
27029
27030 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
27031 call *%rdi
27032 addq $48, %rsp
27033 RESTORE_XMM
27034 + pax_force_retaddr 0, 1
27035 ret
27036 ENDPROC(efi_call5)
27037
27038 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
27039 call *%rdi
27040 addq $48, %rsp
27041 RESTORE_XMM
27042 + pax_force_retaddr 0, 1
27043 ret
27044 ENDPROC(efi_call6)
27045 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
27046 index fd41a92..9c33628 100644
27047 --- a/arch/x86/platform/mrst/mrst.c
27048 +++ b/arch/x86/platform/mrst/mrst.c
27049 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
27050 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
27051 int sfi_mrtc_num;
27052
27053 -static void mrst_power_off(void)
27054 +static __noreturn void mrst_power_off(void)
27055 {
27056 + BUG();
27057 }
27058
27059 -static void mrst_reboot(void)
27060 +static __noreturn void mrst_reboot(void)
27061 {
27062 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
27063 + BUG();
27064 }
27065
27066 /* parse all the mtimer info to a static mtimer array */
27067 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
27068 index 218cdb1..fd55c08 100644
27069 --- a/arch/x86/power/cpu.c
27070 +++ b/arch/x86/power/cpu.c
27071 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
27072 static void fix_processor_context(void)
27073 {
27074 int cpu = smp_processor_id();
27075 - struct tss_struct *t = &per_cpu(init_tss, cpu);
27076 + struct tss_struct *t = init_tss + cpu;
27077
27078 set_tss_desc(cpu, t); /*
27079 * This just modifies memory; should not be
27080 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
27081 */
27082
27083 #ifdef CONFIG_X86_64
27084 + pax_open_kernel();
27085 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
27086 + pax_close_kernel();
27087
27088 syscall_init(); /* This sets MSR_*STAR and related */
27089 #endif
27090 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
27091 index cbca565..bae7133 100644
27092 --- a/arch/x86/realmode/init.c
27093 +++ b/arch/x86/realmode/init.c
27094 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
27095 __va(real_mode_header->trampoline_header);
27096
27097 #ifdef CONFIG_X86_32
27098 - trampoline_header->start = __pa(startup_32_smp);
27099 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
27100 +
27101 +#ifdef CONFIG_PAX_KERNEXEC
27102 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
27103 +#endif
27104 +
27105 + trampoline_header->boot_cs = __BOOT_CS;
27106 trampoline_header->gdt_limit = __BOOT_DS + 7;
27107 trampoline_header->gdt_base = __pa(boot_gdt);
27108 #else
27109 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
27110 index 8869287..d577672 100644
27111 --- a/arch/x86/realmode/rm/Makefile
27112 +++ b/arch/x86/realmode/rm/Makefile
27113 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
27114 $(call cc-option, -fno-unit-at-a-time)) \
27115 $(call cc-option, -fno-stack-protector) \
27116 $(call cc-option, -mpreferred-stack-boundary=2)
27117 +ifdef CONSTIFY_PLUGIN
27118 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
27119 +endif
27120 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
27121 GCOV_PROFILE := n
27122 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
27123 index a28221d..93c40f1 100644
27124 --- a/arch/x86/realmode/rm/header.S
27125 +++ b/arch/x86/realmode/rm/header.S
27126 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
27127 #endif
27128 /* APM/BIOS reboot */
27129 .long pa_machine_real_restart_asm
27130 -#ifdef CONFIG_X86_64
27131 +#ifdef CONFIG_X86_32
27132 + .long __KERNEL_CS
27133 +#else
27134 .long __KERNEL32_CS
27135 #endif
27136 END(real_mode_header)
27137 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
27138 index c1b2791..f9e31c7 100644
27139 --- a/arch/x86/realmode/rm/trampoline_32.S
27140 +++ b/arch/x86/realmode/rm/trampoline_32.S
27141 @@ -25,6 +25,12 @@
27142 #include <asm/page_types.h>
27143 #include "realmode.h"
27144
27145 +#ifdef CONFIG_PAX_KERNEXEC
27146 +#define ta(X) (X)
27147 +#else
27148 +#define ta(X) (pa_ ## X)
27149 +#endif
27150 +
27151 .text
27152 .code16
27153
27154 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
27155
27156 cli # We should be safe anyway
27157
27158 - movl tr_start, %eax # where we need to go
27159 -
27160 movl $0xA5A5A5A5, trampoline_status
27161 # write marker for master knows we're running
27162
27163 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
27164 movw $1, %dx # protected mode (PE) bit
27165 lmsw %dx # into protected mode
27166
27167 - ljmpl $__BOOT_CS, $pa_startup_32
27168 + ljmpl *(trampoline_header)
27169
27170 .section ".text32","ax"
27171 .code32
27172 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
27173 .balign 8
27174 GLOBAL(trampoline_header)
27175 tr_start: .space 4
27176 - tr_gdt_pad: .space 2
27177 + tr_boot_cs: .space 2
27178 tr_gdt: .space 6
27179 END(trampoline_header)
27180
27181 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
27182 index bb360dc..3e5945f 100644
27183 --- a/arch/x86/realmode/rm/trampoline_64.S
27184 +++ b/arch/x86/realmode/rm/trampoline_64.S
27185 @@ -107,7 +107,7 @@ ENTRY(startup_32)
27186 wrmsr
27187
27188 # Enable paging and in turn activate Long Mode
27189 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
27190 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
27191 movl %eax, %cr0
27192
27193 /*
27194 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
27195 index 5a1847d..deccb30 100644
27196 --- a/arch/x86/tools/relocs.c
27197 +++ b/arch/x86/tools/relocs.c
27198 @@ -12,10 +12,13 @@
27199 #include <regex.h>
27200 #include <tools/le_byteshift.h>
27201
27202 +#include "../../../include/generated/autoconf.h"
27203 +
27204 static void die(char *fmt, ...);
27205
27206 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
27207 static Elf32_Ehdr ehdr;
27208 +static Elf32_Phdr *phdr;
27209 static unsigned long reloc_count, reloc_idx;
27210 static unsigned long *relocs;
27211 static unsigned long reloc16_count, reloc16_idx;
27212 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
27213 }
27214 }
27215
27216 +static void read_phdrs(FILE *fp)
27217 +{
27218 + unsigned int i;
27219 +
27220 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
27221 + if (!phdr) {
27222 + die("Unable to allocate %d program headers\n",
27223 + ehdr.e_phnum);
27224 + }
27225 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
27226 + die("Seek to %d failed: %s\n",
27227 + ehdr.e_phoff, strerror(errno));
27228 + }
27229 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
27230 + die("Cannot read ELF program headers: %s\n",
27231 + strerror(errno));
27232 + }
27233 + for(i = 0; i < ehdr.e_phnum; i++) {
27234 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
27235 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
27236 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
27237 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
27238 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
27239 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
27240 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
27241 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
27242 + }
27243 +
27244 +}
27245 +
27246 static void read_shdrs(FILE *fp)
27247 {
27248 - int i;
27249 + unsigned int i;
27250 Elf32_Shdr shdr;
27251
27252 secs = calloc(ehdr.e_shnum, sizeof(struct section));
27253 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
27254
27255 static void read_strtabs(FILE *fp)
27256 {
27257 - int i;
27258 + unsigned int i;
27259 for (i = 0; i < ehdr.e_shnum; i++) {
27260 struct section *sec = &secs[i];
27261 if (sec->shdr.sh_type != SHT_STRTAB) {
27262 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
27263
27264 static void read_symtabs(FILE *fp)
27265 {
27266 - int i,j;
27267 + unsigned int i,j;
27268 for (i = 0; i < ehdr.e_shnum; i++) {
27269 struct section *sec = &secs[i];
27270 if (sec->shdr.sh_type != SHT_SYMTAB) {
27271 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
27272 }
27273
27274
27275 -static void read_relocs(FILE *fp)
27276 +static void read_relocs(FILE *fp, int use_real_mode)
27277 {
27278 - int i,j;
27279 + unsigned int i,j;
27280 + uint32_t base;
27281 +
27282 for (i = 0; i < ehdr.e_shnum; i++) {
27283 struct section *sec = &secs[i];
27284 if (sec->shdr.sh_type != SHT_REL) {
27285 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
27286 die("Cannot read symbol table: %s\n",
27287 strerror(errno));
27288 }
27289 + base = 0;
27290 +
27291 +#ifdef CONFIG_X86_32
27292 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
27293 + if (phdr[j].p_type != PT_LOAD )
27294 + continue;
27295 + 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)
27296 + continue;
27297 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
27298 + break;
27299 + }
27300 +#endif
27301 +
27302 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
27303 Elf32_Rel *rel = &sec->reltab[j];
27304 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27305 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27306 rel->r_info = elf32_to_cpu(rel->r_info);
27307 }
27308 }
27309 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27310
27311 static void print_absolute_symbols(void)
27312 {
27313 - int i;
27314 + unsigned int i;
27315 printf("Absolute symbols\n");
27316 printf(" Num: Value Size Type Bind Visibility Name\n");
27317 for (i = 0; i < ehdr.e_shnum; i++) {
27318 struct section *sec = &secs[i];
27319 char *sym_strtab;
27320 - int j;
27321 + unsigned int j;
27322
27323 if (sec->shdr.sh_type != SHT_SYMTAB) {
27324 continue;
27325 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27326
27327 static void print_absolute_relocs(void)
27328 {
27329 - int i, printed = 0;
27330 + unsigned int i, printed = 0;
27331
27332 for (i = 0; i < ehdr.e_shnum; i++) {
27333 struct section *sec = &secs[i];
27334 struct section *sec_applies, *sec_symtab;
27335 char *sym_strtab;
27336 Elf32_Sym *sh_symtab;
27337 - int j;
27338 + unsigned int j;
27339 if (sec->shdr.sh_type != SHT_REL) {
27340 continue;
27341 }
27342 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27343 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27344 int use_real_mode)
27345 {
27346 - int i;
27347 + unsigned int i;
27348 /* Walk through the relocations */
27349 for (i = 0; i < ehdr.e_shnum; i++) {
27350 char *sym_strtab;
27351 Elf32_Sym *sh_symtab;
27352 struct section *sec_applies, *sec_symtab;
27353 - int j;
27354 + unsigned int j;
27355 struct section *sec = &secs[i];
27356
27357 if (sec->shdr.sh_type != SHT_REL) {
27358 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27359 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27360 r_type = ELF32_R_TYPE(rel->r_info);
27361
27362 + if (!use_real_mode) {
27363 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27364 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27365 + continue;
27366 +
27367 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27368 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27369 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27370 + continue;
27371 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27372 + continue;
27373 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27374 + continue;
27375 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27376 + continue;
27377 +#endif
27378 + }
27379 +
27380 shn_abs = sym->st_shndx == SHN_ABS;
27381
27382 switch (r_type) {
27383 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27384
27385 static void emit_relocs(int as_text, int use_real_mode)
27386 {
27387 - int i;
27388 + unsigned int i;
27389 /* Count how many relocations I have and allocate space for them. */
27390 reloc_count = 0;
27391 walk_relocs(count_reloc, use_real_mode);
27392 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27393 fname, strerror(errno));
27394 }
27395 read_ehdr(fp);
27396 + read_phdrs(fp);
27397 read_shdrs(fp);
27398 read_strtabs(fp);
27399 read_symtabs(fp);
27400 - read_relocs(fp);
27401 + read_relocs(fp, use_real_mode);
27402 if (show_absolute_syms) {
27403 print_absolute_symbols();
27404 return 0;
27405 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27406 index fd14be1..e3c79c0 100644
27407 --- a/arch/x86/vdso/Makefile
27408 +++ b/arch/x86/vdso/Makefile
27409 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27410 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27411 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27412
27413 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27414 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27415 GCOV_PROFILE := n
27416
27417 #
27418 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27419 index 0faad64..39ef157 100644
27420 --- a/arch/x86/vdso/vdso32-setup.c
27421 +++ b/arch/x86/vdso/vdso32-setup.c
27422 @@ -25,6 +25,7 @@
27423 #include <asm/tlbflush.h>
27424 #include <asm/vdso.h>
27425 #include <asm/proto.h>
27426 +#include <asm/mman.h>
27427
27428 enum {
27429 VDSO_DISABLED = 0,
27430 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27431 void enable_sep_cpu(void)
27432 {
27433 int cpu = get_cpu();
27434 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27435 + struct tss_struct *tss = init_tss + cpu;
27436
27437 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27438 put_cpu();
27439 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27440 gate_vma.vm_start = FIXADDR_USER_START;
27441 gate_vma.vm_end = FIXADDR_USER_END;
27442 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27443 - gate_vma.vm_page_prot = __P101;
27444 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27445
27446 return 0;
27447 }
27448 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27449 if (compat)
27450 addr = VDSO_HIGH_BASE;
27451 else {
27452 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27453 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27454 if (IS_ERR_VALUE(addr)) {
27455 ret = addr;
27456 goto up_fail;
27457 }
27458 }
27459
27460 - current->mm->context.vdso = (void *)addr;
27461 + current->mm->context.vdso = addr;
27462
27463 if (compat_uses_vma || !compat) {
27464 /*
27465 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27466 }
27467
27468 current_thread_info()->sysenter_return =
27469 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27470 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27471
27472 up_fail:
27473 if (ret)
27474 - current->mm->context.vdso = NULL;
27475 + current->mm->context.vdso = 0;
27476
27477 up_write(&mm->mmap_sem);
27478
27479 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27480
27481 const char *arch_vma_name(struct vm_area_struct *vma)
27482 {
27483 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27484 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27485 return "[vdso]";
27486 +
27487 +#ifdef CONFIG_PAX_SEGMEXEC
27488 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27489 + return "[vdso]";
27490 +#endif
27491 +
27492 return NULL;
27493 }
27494
27495 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27496 * Check to see if the corresponding task was created in compat vdso
27497 * mode.
27498 */
27499 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27500 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27501 return &gate_vma;
27502 return NULL;
27503 }
27504 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27505 index 00aaf04..4a26505 100644
27506 --- a/arch/x86/vdso/vma.c
27507 +++ b/arch/x86/vdso/vma.c
27508 @@ -16,8 +16,6 @@
27509 #include <asm/vdso.h>
27510 #include <asm/page.h>
27511
27512 -unsigned int __read_mostly vdso_enabled = 1;
27513 -
27514 extern char vdso_start[], vdso_end[];
27515 extern unsigned short vdso_sync_cpuid;
27516
27517 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27518 * unaligned here as a result of stack start randomization.
27519 */
27520 addr = PAGE_ALIGN(addr);
27521 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27522
27523 return addr;
27524 }
27525 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27526 unsigned size)
27527 {
27528 struct mm_struct *mm = current->mm;
27529 - unsigned long addr;
27530 + unsigned long addr = 0;
27531 int ret;
27532
27533 - if (!vdso_enabled)
27534 - return 0;
27535 -
27536 down_write(&mm->mmap_sem);
27537 +
27538 +#ifdef CONFIG_PAX_RANDMMAP
27539 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27540 +#endif
27541 +
27542 addr = vdso_addr(mm->start_stack, size);
27543 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27544 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27545 if (IS_ERR_VALUE(addr)) {
27546 ret = addr;
27547 goto up_fail;
27548 }
27549
27550 - current->mm->context.vdso = (void *)addr;
27551 + mm->context.vdso = addr;
27552
27553 ret = install_special_mapping(mm, addr, size,
27554 VM_READ|VM_EXEC|
27555 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27556 pages);
27557 - if (ret) {
27558 - current->mm->context.vdso = NULL;
27559 - goto up_fail;
27560 - }
27561 + if (ret)
27562 + mm->context.vdso = 0;
27563
27564 up_fail:
27565 up_write(&mm->mmap_sem);
27566 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27567 vdsox32_size);
27568 }
27569 #endif
27570 -
27571 -static __init int vdso_setup(char *s)
27572 -{
27573 - vdso_enabled = simple_strtoul(s, NULL, 0);
27574 - return 0;
27575 -}
27576 -__setup("vdso=", vdso_setup);
27577 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27578 index c1461de..355f120 100644
27579 --- a/arch/x86/xen/enlighten.c
27580 +++ b/arch/x86/xen/enlighten.c
27581 @@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27582
27583 struct shared_info xen_dummy_shared_info;
27584
27585 -void *xen_initial_gdt;
27586 -
27587 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27588 __read_mostly int xen_have_vector_callback;
27589 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27590 @@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27591
27592 static void set_xen_basic_apic_ops(void)
27593 {
27594 - apic->read = xen_apic_read;
27595 - apic->write = xen_apic_write;
27596 - apic->icr_read = xen_apic_icr_read;
27597 - apic->icr_write = xen_apic_icr_write;
27598 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27599 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27600 - apic->set_apic_id = xen_set_apic_id;
27601 - apic->get_apic_id = xen_get_apic_id;
27602 + *(void **)&apic->read = xen_apic_read;
27603 + *(void **)&apic->write = xen_apic_write;
27604 + *(void **)&apic->icr_read = xen_apic_icr_read;
27605 + *(void **)&apic->icr_write = xen_apic_icr_write;
27606 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27607 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27608 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27609 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27610
27611 #ifdef CONFIG_SMP
27612 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27613 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27614 - apic->send_IPI_mask = xen_send_IPI_mask;
27615 - apic->send_IPI_all = xen_send_IPI_all;
27616 - apic->send_IPI_self = xen_send_IPI_self;
27617 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27618 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27619 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27620 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27621 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27622 #endif
27623 }
27624
27625 @@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27626 #endif
27627 };
27628
27629 -static void xen_reboot(int reason)
27630 +static __noreturn void xen_reboot(int reason)
27631 {
27632 struct sched_shutdown r = { .reason = reason };
27633
27634 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27635 - BUG();
27636 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27637 + BUG();
27638 }
27639
27640 -static void xen_restart(char *msg)
27641 +static __noreturn void xen_restart(char *msg)
27642 {
27643 xen_reboot(SHUTDOWN_reboot);
27644 }
27645
27646 -static void xen_emergency_restart(void)
27647 +static __noreturn void xen_emergency_restart(void)
27648 {
27649 xen_reboot(SHUTDOWN_reboot);
27650 }
27651
27652 -static void xen_machine_halt(void)
27653 +static __noreturn void xen_machine_halt(void)
27654 {
27655 xen_reboot(SHUTDOWN_poweroff);
27656 }
27657
27658 -static void xen_machine_power_off(void)
27659 +static __noreturn void xen_machine_power_off(void)
27660 {
27661 if (pm_power_off)
27662 pm_power_off();
27663 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27664 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27665
27666 /* Work out if we support NX */
27667 - x86_configure_nx();
27668 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27669 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27670 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27671 + unsigned l, h;
27672 +
27673 + __supported_pte_mask |= _PAGE_NX;
27674 + rdmsr(MSR_EFER, l, h);
27675 + l |= EFER_NX;
27676 + wrmsr(MSR_EFER, l, h);
27677 + }
27678 +#endif
27679
27680 xen_setup_features();
27681
27682 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27683
27684 machine_ops = xen_machine_ops;
27685
27686 - /*
27687 - * The only reliable way to retain the initial address of the
27688 - * percpu gdt_page is to remember it here, so we can go and
27689 - * mark it RW later, when the initial percpu area is freed.
27690 - */
27691 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27692 -
27693 xen_smp_init();
27694
27695 #ifdef CONFIG_ACPI_NUMA
27696 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27697 index dde1a3f..6b663e6 100644
27698 --- a/arch/x86/xen/mmu.c
27699 +++ b/arch/x86/xen/mmu.c
27700 @@ -1784,6 +1784,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27701 convert_pfn_mfn(init_level4_pgt);
27702 convert_pfn_mfn(level3_ident_pgt);
27703 convert_pfn_mfn(level3_kernel_pgt);
27704 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27705 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27706 + convert_pfn_mfn(level3_vmemmap_pgt);
27707
27708 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27709 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27710 @@ -1802,7 +1805,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27711 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27712 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27713 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27714 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27715 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27716 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27717 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27718 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27719 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27720 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27721
27722 @@ -1986,6 +1993,7 @@ static void __init xen_post_allocator_init(void)
27723 pv_mmu_ops.set_pud = xen_set_pud;
27724 #if PAGETABLE_LEVELS == 4
27725 pv_mmu_ops.set_pgd = xen_set_pgd;
27726 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27727 #endif
27728
27729 /* This will work as long as patching hasn't happened yet
27730 @@ -2067,6 +2075,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27731 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27732 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27733 .set_pgd = xen_set_pgd_hyper,
27734 + .set_pgd_batched = xen_set_pgd_hyper,
27735
27736 .alloc_pud = xen_alloc_pmd_init,
27737 .release_pud = xen_release_pmd_init,
27738 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27739 index f58dca7..ad21f52 100644
27740 --- a/arch/x86/xen/smp.c
27741 +++ b/arch/x86/xen/smp.c
27742 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27743 {
27744 BUG_ON(smp_processor_id() != 0);
27745 native_smp_prepare_boot_cpu();
27746 -
27747 - /* We've switched to the "real" per-cpu gdt, so make sure the
27748 - old memory can be recycled */
27749 - make_lowmem_page_readwrite(xen_initial_gdt);
27750 -
27751 xen_filter_cpu_maps();
27752 xen_setup_vcpu_info_placement();
27753 }
27754 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27755 gdt = get_cpu_gdt_table(cpu);
27756
27757 ctxt->flags = VGCF_IN_KERNEL;
27758 - ctxt->user_regs.ds = __USER_DS;
27759 - ctxt->user_regs.es = __USER_DS;
27760 + ctxt->user_regs.ds = __KERNEL_DS;
27761 + ctxt->user_regs.es = __KERNEL_DS;
27762 ctxt->user_regs.ss = __KERNEL_DS;
27763 #ifdef CONFIG_X86_32
27764 ctxt->user_regs.fs = __KERNEL_PERCPU;
27765 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27766 + savesegment(gs, ctxt->user_regs.gs);
27767 #else
27768 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27769 #endif
27770 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27771 int rc;
27772
27773 per_cpu(current_task, cpu) = idle;
27774 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27775 #ifdef CONFIG_X86_32
27776 irq_ctx_init(cpu);
27777 #else
27778 clear_tsk_thread_flag(idle, TIF_FORK);
27779 - per_cpu(kernel_stack, cpu) =
27780 - (unsigned long)task_stack_page(idle) -
27781 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27782 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27783 #endif
27784 xen_setup_runstate_info(cpu);
27785 xen_setup_timer(cpu);
27786 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27787 index f9643fc..602e8af 100644
27788 --- a/arch/x86/xen/xen-asm_32.S
27789 +++ b/arch/x86/xen/xen-asm_32.S
27790 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27791 ESP_OFFSET=4 # bytes pushed onto stack
27792
27793 /*
27794 - * Store vcpu_info pointer for easy access. Do it this way to
27795 - * avoid having to reload %fs
27796 + * Store vcpu_info pointer for easy access.
27797 */
27798 #ifdef CONFIG_SMP
27799 - GET_THREAD_INFO(%eax)
27800 - movl TI_cpu(%eax), %eax
27801 - movl __per_cpu_offset(,%eax,4), %eax
27802 - mov xen_vcpu(%eax), %eax
27803 + push %fs
27804 + mov $(__KERNEL_PERCPU), %eax
27805 + mov %eax, %fs
27806 + mov PER_CPU_VAR(xen_vcpu), %eax
27807 + pop %fs
27808 #else
27809 movl xen_vcpu, %eax
27810 #endif
27811 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27812 index aaa7291..3f77960 100644
27813 --- a/arch/x86/xen/xen-head.S
27814 +++ b/arch/x86/xen/xen-head.S
27815 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27816 #ifdef CONFIG_X86_32
27817 mov %esi,xen_start_info
27818 mov $init_thread_union+THREAD_SIZE,%esp
27819 +#ifdef CONFIG_SMP
27820 + movl $cpu_gdt_table,%edi
27821 + movl $__per_cpu_load,%eax
27822 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27823 + rorl $16,%eax
27824 + movb %al,__KERNEL_PERCPU + 4(%edi)
27825 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27826 + movl $__per_cpu_end - 1,%eax
27827 + subl $__per_cpu_start,%eax
27828 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27829 +#endif
27830 #else
27831 mov %rsi,xen_start_info
27832 mov $init_thread_union+THREAD_SIZE,%rsp
27833 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27834 index 202d4c1..99b072a 100644
27835 --- a/arch/x86/xen/xen-ops.h
27836 +++ b/arch/x86/xen/xen-ops.h
27837 @@ -10,8 +10,6 @@
27838 extern const char xen_hypervisor_callback[];
27839 extern const char xen_failsafe_callback[];
27840
27841 -extern void *xen_initial_gdt;
27842 -
27843 struct trap_info;
27844 void xen_copy_trap_info(struct trap_info *traps);
27845
27846 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27847 index 525bd3d..ef888b1 100644
27848 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27849 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27850 @@ -119,9 +119,9 @@
27851 ----------------------------------------------------------------------*/
27852
27853 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27854 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27855 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27856 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27857 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27858
27859 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27860 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27861 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27862 index 2f33760..835e50a 100644
27863 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27864 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27865 @@ -11,6 +11,7 @@
27866 #ifndef _XTENSA_CORE_H
27867 #define _XTENSA_CORE_H
27868
27869 +#include <linux/const.h>
27870
27871 /****************************************************************************
27872 Parameters Useful for Any Code, USER or PRIVILEGED
27873 @@ -112,9 +113,9 @@
27874 ----------------------------------------------------------------------*/
27875
27876 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27877 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27878 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27879 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27880 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27881
27882 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27883 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27884 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27885 index af00795..2bb8105 100644
27886 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27887 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27888 @@ -11,6 +11,7 @@
27889 #ifndef _XTENSA_CORE_CONFIGURATION_H
27890 #define _XTENSA_CORE_CONFIGURATION_H
27891
27892 +#include <linux/const.h>
27893
27894 /****************************************************************************
27895 Parameters Useful for Any Code, USER or PRIVILEGED
27896 @@ -118,9 +119,9 @@
27897 ----------------------------------------------------------------------*/
27898
27899 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27900 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27901 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27902 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27903 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27904
27905 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27906 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27907 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27908 index 58916af..9cb880b 100644
27909 --- a/block/blk-iopoll.c
27910 +++ b/block/blk-iopoll.c
27911 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27912 }
27913 EXPORT_SYMBOL(blk_iopoll_complete);
27914
27915 -static void blk_iopoll_softirq(struct softirq_action *h)
27916 +static void blk_iopoll_softirq(void)
27917 {
27918 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27919 int rearm = 0, budget = blk_iopoll_budget;
27920 diff --git a/block/blk-map.c b/block/blk-map.c
27921 index 623e1cd..ca1e109 100644
27922 --- a/block/blk-map.c
27923 +++ b/block/blk-map.c
27924 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27925 if (!len || !kbuf)
27926 return -EINVAL;
27927
27928 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27929 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27930 if (do_copy)
27931 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27932 else
27933 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27934 index 467c8de..4bddc6d 100644
27935 --- a/block/blk-softirq.c
27936 +++ b/block/blk-softirq.c
27937 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27938 * Softirq action handler - move entries to local list and loop over them
27939 * while passing them to the queue registered handler.
27940 */
27941 -static void blk_done_softirq(struct softirq_action *h)
27942 +static void blk_done_softirq(void)
27943 {
27944 struct list_head *cpu_list, local_list;
27945
27946 diff --git a/block/bsg.c b/block/bsg.c
27947 index ff64ae3..593560c 100644
27948 --- a/block/bsg.c
27949 +++ b/block/bsg.c
27950 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27951 struct sg_io_v4 *hdr, struct bsg_device *bd,
27952 fmode_t has_write_perm)
27953 {
27954 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27955 + unsigned char *cmdptr;
27956 +
27957 if (hdr->request_len > BLK_MAX_CDB) {
27958 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27959 if (!rq->cmd)
27960 return -ENOMEM;
27961 - }
27962 + cmdptr = rq->cmd;
27963 + } else
27964 + cmdptr = tmpcmd;
27965
27966 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27967 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27968 hdr->request_len))
27969 return -EFAULT;
27970
27971 + if (cmdptr != rq->cmd)
27972 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27973 +
27974 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27975 if (blk_verify_command(rq->cmd, has_write_perm))
27976 return -EPERM;
27977 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27978 index 7c668c8..db3521c 100644
27979 --- a/block/compat_ioctl.c
27980 +++ b/block/compat_ioctl.c
27981 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27982 err |= __get_user(f->spec1, &uf->spec1);
27983 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27984 err |= __get_user(name, &uf->name);
27985 - f->name = compat_ptr(name);
27986 + f->name = (void __force_kernel *)compat_ptr(name);
27987 if (err) {
27988 err = -EFAULT;
27989 goto out;
27990 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27991 index 6296b40..417c00f 100644
27992 --- a/block/partitions/efi.c
27993 +++ b/block/partitions/efi.c
27994 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27995 if (!gpt)
27996 return NULL;
27997
27998 + if (!le32_to_cpu(gpt->num_partition_entries))
27999 + return NULL;
28000 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
28001 + if (!pte)
28002 + return NULL;
28003 +
28004 count = le32_to_cpu(gpt->num_partition_entries) *
28005 le32_to_cpu(gpt->sizeof_partition_entry);
28006 - if (!count)
28007 - return NULL;
28008 - pte = kzalloc(count, GFP_KERNEL);
28009 - if (!pte)
28010 - return NULL;
28011 -
28012 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
28013 (u8 *) pte,
28014 count) < count) {
28015 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
28016 index 9a87daa..fb17486 100644
28017 --- a/block/scsi_ioctl.c
28018 +++ b/block/scsi_ioctl.c
28019 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
28020 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
28021 struct sg_io_hdr *hdr, fmode_t mode)
28022 {
28023 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
28024 + unsigned char tmpcmd[sizeof(rq->__cmd)];
28025 + unsigned char *cmdptr;
28026 +
28027 + if (rq->cmd != rq->__cmd)
28028 + cmdptr = rq->cmd;
28029 + else
28030 + cmdptr = tmpcmd;
28031 +
28032 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
28033 return -EFAULT;
28034 +
28035 + if (cmdptr != rq->cmd)
28036 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
28037 +
28038 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
28039 return -EPERM;
28040
28041 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
28042 int err;
28043 unsigned int in_len, out_len, bytes, opcode, cmdlen;
28044 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
28045 + unsigned char tmpcmd[sizeof(rq->__cmd)];
28046 + unsigned char *cmdptr;
28047
28048 if (!sic)
28049 return -EINVAL;
28050 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
28051 */
28052 err = -EFAULT;
28053 rq->cmd_len = cmdlen;
28054 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
28055 +
28056 + if (rq->cmd != rq->__cmd)
28057 + cmdptr = rq->cmd;
28058 + else
28059 + cmdptr = tmpcmd;
28060 +
28061 + if (copy_from_user(cmdptr, sic->data, cmdlen))
28062 goto error;
28063
28064 + if (rq->cmd != cmdptr)
28065 + memcpy(rq->cmd, cmdptr, cmdlen);
28066 +
28067 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
28068 goto error;
28069
28070 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
28071 index 671d4d6..afec999 100644
28072 --- a/crypto/cryptd.c
28073 +++ b/crypto/cryptd.c
28074 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
28075
28076 struct cryptd_blkcipher_request_ctx {
28077 crypto_completion_t complete;
28078 -};
28079 +} __no_const;
28080
28081 struct cryptd_hash_ctx {
28082 struct crypto_shash *child;
28083 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
28084
28085 struct cryptd_aead_request_ctx {
28086 crypto_completion_t complete;
28087 -};
28088 +} __no_const;
28089
28090 static void cryptd_queue_worker(struct work_struct *work);
28091
28092 @@ -137,13 +137,18 @@ static void cryptd_queue_worker(struct work_struct *work)
28093 struct crypto_async_request *req, *backlog;
28094
28095 cpu_queue = container_of(work, struct cryptd_cpu_queue, work);
28096 - /* Only handle one request at a time to avoid hogging crypto
28097 - * workqueue. preempt_disable/enable is used to prevent
28098 - * being preempted by cryptd_enqueue_request() */
28099 + /*
28100 + * Only handle one request at a time to avoid hogging crypto workqueue.
28101 + * preempt_disable/enable is used to prevent being preempted by
28102 + * cryptd_enqueue_request(). local_bh_disable/enable is used to prevent
28103 + * cryptd_enqueue_request() being accessed from software interrupts.
28104 + */
28105 + local_bh_disable();
28106 preempt_disable();
28107 backlog = crypto_get_backlog(&cpu_queue->queue);
28108 req = crypto_dequeue_request(&cpu_queue->queue);
28109 preempt_enable();
28110 + local_bh_enable();
28111
28112 if (!req)
28113 return;
28114 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
28115 index e6defd8..c26a225 100644
28116 --- a/drivers/acpi/apei/cper.c
28117 +++ b/drivers/acpi/apei/cper.c
28118 @@ -38,12 +38,12 @@
28119 */
28120 u64 cper_next_record_id(void)
28121 {
28122 - static atomic64_t seq;
28123 + static atomic64_unchecked_t seq;
28124
28125 - if (!atomic64_read(&seq))
28126 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
28127 + if (!atomic64_read_unchecked(&seq))
28128 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
28129
28130 - return atomic64_inc_return(&seq);
28131 + return atomic64_inc_return_unchecked(&seq);
28132 }
28133 EXPORT_SYMBOL_GPL(cper_next_record_id);
28134
28135 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
28136 index 7586544..636a2f0 100644
28137 --- a/drivers/acpi/ec_sys.c
28138 +++ b/drivers/acpi/ec_sys.c
28139 @@ -12,6 +12,7 @@
28140 #include <linux/acpi.h>
28141 #include <linux/debugfs.h>
28142 #include <linux/module.h>
28143 +#include <linux/uaccess.h>
28144 #include "internal.h"
28145
28146 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
28147 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28148 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
28149 */
28150 unsigned int size = EC_SPACE_SIZE;
28151 - u8 *data = (u8 *) buf;
28152 + u8 data;
28153 loff_t init_off = *off;
28154 int err = 0;
28155
28156 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28157 size = count;
28158
28159 while (size) {
28160 - err = ec_read(*off, &data[*off - init_off]);
28161 + err = ec_read(*off, &data);
28162 if (err)
28163 return err;
28164 + if (put_user(data, &buf[*off - init_off]))
28165 + return -EFAULT;
28166 *off += 1;
28167 size--;
28168 }
28169 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28170
28171 unsigned int size = count;
28172 loff_t init_off = *off;
28173 - u8 *data = (u8 *) buf;
28174 int err = 0;
28175
28176 if (*off >= EC_SPACE_SIZE)
28177 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28178 }
28179
28180 while (size) {
28181 - u8 byte_write = data[*off - init_off];
28182 + u8 byte_write;
28183 + if (get_user(byte_write, &buf[*off - init_off]))
28184 + return -EFAULT;
28185 err = ec_write(*off, byte_write);
28186 if (err)
28187 return err;
28188 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
28189 index 251c7b62..000462d 100644
28190 --- a/drivers/acpi/proc.c
28191 +++ b/drivers/acpi/proc.c
28192 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
28193 size_t count, loff_t * ppos)
28194 {
28195 struct list_head *node, *next;
28196 - char strbuf[5];
28197 - char str[5] = "";
28198 - unsigned int len = count;
28199 + char strbuf[5] = {0};
28200
28201 - if (len > 4)
28202 - len = 4;
28203 - if (len < 0)
28204 + if (count > 4)
28205 + count = 4;
28206 + if (copy_from_user(strbuf, buffer, count))
28207 return -EFAULT;
28208 -
28209 - if (copy_from_user(strbuf, buffer, len))
28210 - return -EFAULT;
28211 - strbuf[len] = '\0';
28212 - sscanf(strbuf, "%s", str);
28213 + strbuf[count] = '\0';
28214
28215 mutex_lock(&acpi_device_lock);
28216 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
28217 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
28218 if (!dev->wakeup.flags.valid)
28219 continue;
28220
28221 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
28222 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
28223 if (device_can_wakeup(&dev->dev)) {
28224 bool enable = !device_may_wakeup(&dev->dev);
28225 device_set_wakeup_enable(&dev->dev, enable);
28226 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
28227 index bfc31cb..8213ce1 100644
28228 --- a/drivers/acpi/processor_driver.c
28229 +++ b/drivers/acpi/processor_driver.c
28230 @@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
28231 return 0;
28232 #endif
28233
28234 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
28235 + BUG_ON(pr->id >= nr_cpu_ids);
28236
28237 /*
28238 * Buggy BIOS check
28239 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
28240 index 8e1039c..ea9cbd4 100644
28241 --- a/drivers/ata/libata-core.c
28242 +++ b/drivers/ata/libata-core.c
28243 @@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
28244 struct ata_port *ap;
28245 unsigned int tag;
28246
28247 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28248 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28249 ap = qc->ap;
28250
28251 qc->flags = 0;
28252 @@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
28253 struct ata_port *ap;
28254 struct ata_link *link;
28255
28256 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28257 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28258 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
28259 ap = qc->ap;
28260 link = qc->dev->link;
28261 @@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28262 return;
28263
28264 spin_lock(&lock);
28265 + pax_open_kernel();
28266
28267 for (cur = ops->inherits; cur; cur = cur->inherits) {
28268 void **inherit = (void **)cur;
28269 @@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28270 if (IS_ERR(*pp))
28271 *pp = NULL;
28272
28273 - ops->inherits = NULL;
28274 + *(struct ata_port_operations **)&ops->inherits = NULL;
28275
28276 + pax_close_kernel();
28277 spin_unlock(&lock);
28278 }
28279
28280 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
28281 index bfaa5cb..3ba1cc3 100644
28282 --- a/drivers/ata/pata_arasan_cf.c
28283 +++ b/drivers/ata/pata_arasan_cf.c
28284 @@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
28285 /* Handle platform specific quirks */
28286 if (pdata->quirk) {
28287 if (pdata->quirk & CF_BROKEN_PIO) {
28288 - ap->ops->set_piomode = NULL;
28289 + pax_open_kernel();
28290 + *(void **)&ap->ops->set_piomode = NULL;
28291 + pax_close_kernel();
28292 ap->pio_mask = 0;
28293 }
28294 if (pdata->quirk & CF_BROKEN_MWDMA)
28295 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
28296 index f9b983a..887b9d8 100644
28297 --- a/drivers/atm/adummy.c
28298 +++ b/drivers/atm/adummy.c
28299 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
28300 vcc->pop(vcc, skb);
28301 else
28302 dev_kfree_skb_any(skb);
28303 - atomic_inc(&vcc->stats->tx);
28304 + atomic_inc_unchecked(&vcc->stats->tx);
28305
28306 return 0;
28307 }
28308 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
28309 index 89b30f3..7964211 100644
28310 --- a/drivers/atm/ambassador.c
28311 +++ b/drivers/atm/ambassador.c
28312 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
28313 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
28314
28315 // VC layer stats
28316 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28317 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28318
28319 // free the descriptor
28320 kfree (tx_descr);
28321 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28322 dump_skb ("<<<", vc, skb);
28323
28324 // VC layer stats
28325 - atomic_inc(&atm_vcc->stats->rx);
28326 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28327 __net_timestamp(skb);
28328 // end of our responsibility
28329 atm_vcc->push (atm_vcc, skb);
28330 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28331 } else {
28332 PRINTK (KERN_INFO, "dropped over-size frame");
28333 // should we count this?
28334 - atomic_inc(&atm_vcc->stats->rx_drop);
28335 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28336 }
28337
28338 } else {
28339 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28340 }
28341
28342 if (check_area (skb->data, skb->len)) {
28343 - atomic_inc(&atm_vcc->stats->tx_err);
28344 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28345 return -ENOMEM; // ?
28346 }
28347
28348 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28349 index b22d71c..d6e1049 100644
28350 --- a/drivers/atm/atmtcp.c
28351 +++ b/drivers/atm/atmtcp.c
28352 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28353 if (vcc->pop) vcc->pop(vcc,skb);
28354 else dev_kfree_skb(skb);
28355 if (dev_data) return 0;
28356 - atomic_inc(&vcc->stats->tx_err);
28357 + atomic_inc_unchecked(&vcc->stats->tx_err);
28358 return -ENOLINK;
28359 }
28360 size = skb->len+sizeof(struct atmtcp_hdr);
28361 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28362 if (!new_skb) {
28363 if (vcc->pop) vcc->pop(vcc,skb);
28364 else dev_kfree_skb(skb);
28365 - atomic_inc(&vcc->stats->tx_err);
28366 + atomic_inc_unchecked(&vcc->stats->tx_err);
28367 return -ENOBUFS;
28368 }
28369 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28370 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28371 if (vcc->pop) vcc->pop(vcc,skb);
28372 else dev_kfree_skb(skb);
28373 out_vcc->push(out_vcc,new_skb);
28374 - atomic_inc(&vcc->stats->tx);
28375 - atomic_inc(&out_vcc->stats->rx);
28376 + atomic_inc_unchecked(&vcc->stats->tx);
28377 + atomic_inc_unchecked(&out_vcc->stats->rx);
28378 return 0;
28379 }
28380
28381 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28382 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28383 read_unlock(&vcc_sklist_lock);
28384 if (!out_vcc) {
28385 - atomic_inc(&vcc->stats->tx_err);
28386 + atomic_inc_unchecked(&vcc->stats->tx_err);
28387 goto done;
28388 }
28389 skb_pull(skb,sizeof(struct atmtcp_hdr));
28390 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28391 __net_timestamp(new_skb);
28392 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28393 out_vcc->push(out_vcc,new_skb);
28394 - atomic_inc(&vcc->stats->tx);
28395 - atomic_inc(&out_vcc->stats->rx);
28396 + atomic_inc_unchecked(&vcc->stats->tx);
28397 + atomic_inc_unchecked(&out_vcc->stats->rx);
28398 done:
28399 if (vcc->pop) vcc->pop(vcc,skb);
28400 else dev_kfree_skb(skb);
28401 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28402 index 2059ee4..faf51c7 100644
28403 --- a/drivers/atm/eni.c
28404 +++ b/drivers/atm/eni.c
28405 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28406 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28407 vcc->dev->number);
28408 length = 0;
28409 - atomic_inc(&vcc->stats->rx_err);
28410 + atomic_inc_unchecked(&vcc->stats->rx_err);
28411 }
28412 else {
28413 length = ATM_CELL_SIZE-1; /* no HEC */
28414 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28415 size);
28416 }
28417 eff = length = 0;
28418 - atomic_inc(&vcc->stats->rx_err);
28419 + atomic_inc_unchecked(&vcc->stats->rx_err);
28420 }
28421 else {
28422 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28423 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28424 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28425 vcc->dev->number,vcc->vci,length,size << 2,descr);
28426 length = eff = 0;
28427 - atomic_inc(&vcc->stats->rx_err);
28428 + atomic_inc_unchecked(&vcc->stats->rx_err);
28429 }
28430 }
28431 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28432 @@ -767,7 +767,7 @@ rx_dequeued++;
28433 vcc->push(vcc,skb);
28434 pushed++;
28435 }
28436 - atomic_inc(&vcc->stats->rx);
28437 + atomic_inc_unchecked(&vcc->stats->rx);
28438 }
28439 wake_up(&eni_dev->rx_wait);
28440 }
28441 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28442 PCI_DMA_TODEVICE);
28443 if (vcc->pop) vcc->pop(vcc,skb);
28444 else dev_kfree_skb_irq(skb);
28445 - atomic_inc(&vcc->stats->tx);
28446 + atomic_inc_unchecked(&vcc->stats->tx);
28447 wake_up(&eni_dev->tx_wait);
28448 dma_complete++;
28449 }
28450 @@ -1567,7 +1567,7 @@ tx_complete++;
28451 /*--------------------------------- entries ---------------------------------*/
28452
28453
28454 -static const char *media_name[] __devinitdata = {
28455 +static const char *media_name[] __devinitconst = {
28456 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28457 "UTP", "05?", "06?", "07?", /* 4- 7 */
28458 "TAXI","09?", "10?", "11?", /* 8-11 */
28459 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28460 index 86fed1b..6dc4721 100644
28461 --- a/drivers/atm/firestream.c
28462 +++ b/drivers/atm/firestream.c
28463 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28464 }
28465 }
28466
28467 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28468 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28469
28470 fs_dprintk (FS_DEBUG_TXMEM, "i");
28471 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28472 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28473 #endif
28474 skb_put (skb, qe->p1 & 0xffff);
28475 ATM_SKB(skb)->vcc = atm_vcc;
28476 - atomic_inc(&atm_vcc->stats->rx);
28477 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28478 __net_timestamp(skb);
28479 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28480 atm_vcc->push (atm_vcc, skb);
28481 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28482 kfree (pe);
28483 }
28484 if (atm_vcc)
28485 - atomic_inc(&atm_vcc->stats->rx_drop);
28486 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28487 break;
28488 case 0x1f: /* Reassembly abort: no buffers. */
28489 /* Silently increment error counter. */
28490 if (atm_vcc)
28491 - atomic_inc(&atm_vcc->stats->rx_drop);
28492 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28493 break;
28494 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28495 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28496 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28497 index 361f5ae..7fc552d 100644
28498 --- a/drivers/atm/fore200e.c
28499 +++ b/drivers/atm/fore200e.c
28500 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28501 #endif
28502 /* check error condition */
28503 if (*entry->status & STATUS_ERROR)
28504 - atomic_inc(&vcc->stats->tx_err);
28505 + atomic_inc_unchecked(&vcc->stats->tx_err);
28506 else
28507 - atomic_inc(&vcc->stats->tx);
28508 + atomic_inc_unchecked(&vcc->stats->tx);
28509 }
28510 }
28511
28512 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28513 if (skb == NULL) {
28514 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28515
28516 - atomic_inc(&vcc->stats->rx_drop);
28517 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28518 return -ENOMEM;
28519 }
28520
28521 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28522
28523 dev_kfree_skb_any(skb);
28524
28525 - atomic_inc(&vcc->stats->rx_drop);
28526 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28527 return -ENOMEM;
28528 }
28529
28530 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28531
28532 vcc->push(vcc, skb);
28533 - atomic_inc(&vcc->stats->rx);
28534 + atomic_inc_unchecked(&vcc->stats->rx);
28535
28536 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28537
28538 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28539 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28540 fore200e->atm_dev->number,
28541 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28542 - atomic_inc(&vcc->stats->rx_err);
28543 + atomic_inc_unchecked(&vcc->stats->rx_err);
28544 }
28545 }
28546
28547 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28548 goto retry_here;
28549 }
28550
28551 - atomic_inc(&vcc->stats->tx_err);
28552 + atomic_inc_unchecked(&vcc->stats->tx_err);
28553
28554 fore200e->tx_sat++;
28555 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28556 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28557 index b182c2f..1c6fa8a 100644
28558 --- a/drivers/atm/he.c
28559 +++ b/drivers/atm/he.c
28560 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28561
28562 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28563 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28564 - atomic_inc(&vcc->stats->rx_drop);
28565 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28566 goto return_host_buffers;
28567 }
28568
28569 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28570 RBRQ_LEN_ERR(he_dev->rbrq_head)
28571 ? "LEN_ERR" : "",
28572 vcc->vpi, vcc->vci);
28573 - atomic_inc(&vcc->stats->rx_err);
28574 + atomic_inc_unchecked(&vcc->stats->rx_err);
28575 goto return_host_buffers;
28576 }
28577
28578 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28579 vcc->push(vcc, skb);
28580 spin_lock(&he_dev->global_lock);
28581
28582 - atomic_inc(&vcc->stats->rx);
28583 + atomic_inc_unchecked(&vcc->stats->rx);
28584
28585 return_host_buffers:
28586 ++pdus_assembled;
28587 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28588 tpd->vcc->pop(tpd->vcc, tpd->skb);
28589 else
28590 dev_kfree_skb_any(tpd->skb);
28591 - atomic_inc(&tpd->vcc->stats->tx_err);
28592 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28593 }
28594 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28595 return;
28596 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28597 vcc->pop(vcc, skb);
28598 else
28599 dev_kfree_skb_any(skb);
28600 - atomic_inc(&vcc->stats->tx_err);
28601 + atomic_inc_unchecked(&vcc->stats->tx_err);
28602 return -EINVAL;
28603 }
28604
28605 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28606 vcc->pop(vcc, skb);
28607 else
28608 dev_kfree_skb_any(skb);
28609 - atomic_inc(&vcc->stats->tx_err);
28610 + atomic_inc_unchecked(&vcc->stats->tx_err);
28611 return -EINVAL;
28612 }
28613 #endif
28614 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28615 vcc->pop(vcc, skb);
28616 else
28617 dev_kfree_skb_any(skb);
28618 - atomic_inc(&vcc->stats->tx_err);
28619 + atomic_inc_unchecked(&vcc->stats->tx_err);
28620 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28621 return -ENOMEM;
28622 }
28623 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28624 vcc->pop(vcc, skb);
28625 else
28626 dev_kfree_skb_any(skb);
28627 - atomic_inc(&vcc->stats->tx_err);
28628 + atomic_inc_unchecked(&vcc->stats->tx_err);
28629 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28630 return -ENOMEM;
28631 }
28632 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28633 __enqueue_tpd(he_dev, tpd, cid);
28634 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28635
28636 - atomic_inc(&vcc->stats->tx);
28637 + atomic_inc_unchecked(&vcc->stats->tx);
28638
28639 return 0;
28640 }
28641 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28642 index 7d01c2a..4e3ac01 100644
28643 --- a/drivers/atm/horizon.c
28644 +++ b/drivers/atm/horizon.c
28645 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28646 {
28647 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28648 // VC layer stats
28649 - atomic_inc(&vcc->stats->rx);
28650 + atomic_inc_unchecked(&vcc->stats->rx);
28651 __net_timestamp(skb);
28652 // end of our responsibility
28653 vcc->push (vcc, skb);
28654 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28655 dev->tx_iovec = NULL;
28656
28657 // VC layer stats
28658 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28659 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28660
28661 // free the skb
28662 hrz_kfree_skb (skb);
28663 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28664 index 8974bd2..b856f85 100644
28665 --- a/drivers/atm/idt77252.c
28666 +++ b/drivers/atm/idt77252.c
28667 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28668 else
28669 dev_kfree_skb(skb);
28670
28671 - atomic_inc(&vcc->stats->tx);
28672 + atomic_inc_unchecked(&vcc->stats->tx);
28673 }
28674
28675 atomic_dec(&scq->used);
28676 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28677 if ((sb = dev_alloc_skb(64)) == NULL) {
28678 printk("%s: Can't allocate buffers for aal0.\n",
28679 card->name);
28680 - atomic_add(i, &vcc->stats->rx_drop);
28681 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28682 break;
28683 }
28684 if (!atm_charge(vcc, sb->truesize)) {
28685 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28686 card->name);
28687 - atomic_add(i - 1, &vcc->stats->rx_drop);
28688 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28689 dev_kfree_skb(sb);
28690 break;
28691 }
28692 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28693 ATM_SKB(sb)->vcc = vcc;
28694 __net_timestamp(sb);
28695 vcc->push(vcc, sb);
28696 - atomic_inc(&vcc->stats->rx);
28697 + atomic_inc_unchecked(&vcc->stats->rx);
28698
28699 cell += ATM_CELL_PAYLOAD;
28700 }
28701 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28702 "(CDC: %08x)\n",
28703 card->name, len, rpp->len, readl(SAR_REG_CDC));
28704 recycle_rx_pool_skb(card, rpp);
28705 - atomic_inc(&vcc->stats->rx_err);
28706 + atomic_inc_unchecked(&vcc->stats->rx_err);
28707 return;
28708 }
28709 if (stat & SAR_RSQE_CRC) {
28710 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28711 recycle_rx_pool_skb(card, rpp);
28712 - atomic_inc(&vcc->stats->rx_err);
28713 + atomic_inc_unchecked(&vcc->stats->rx_err);
28714 return;
28715 }
28716 if (skb_queue_len(&rpp->queue) > 1) {
28717 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28718 RXPRINTK("%s: Can't alloc RX skb.\n",
28719 card->name);
28720 recycle_rx_pool_skb(card, rpp);
28721 - atomic_inc(&vcc->stats->rx_err);
28722 + atomic_inc_unchecked(&vcc->stats->rx_err);
28723 return;
28724 }
28725 if (!atm_charge(vcc, skb->truesize)) {
28726 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28727 __net_timestamp(skb);
28728
28729 vcc->push(vcc, skb);
28730 - atomic_inc(&vcc->stats->rx);
28731 + atomic_inc_unchecked(&vcc->stats->rx);
28732
28733 return;
28734 }
28735 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28736 __net_timestamp(skb);
28737
28738 vcc->push(vcc, skb);
28739 - atomic_inc(&vcc->stats->rx);
28740 + atomic_inc_unchecked(&vcc->stats->rx);
28741
28742 if (skb->truesize > SAR_FB_SIZE_3)
28743 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28744 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28745 if (vcc->qos.aal != ATM_AAL0) {
28746 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28747 card->name, vpi, vci);
28748 - atomic_inc(&vcc->stats->rx_drop);
28749 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28750 goto drop;
28751 }
28752
28753 if ((sb = dev_alloc_skb(64)) == NULL) {
28754 printk("%s: Can't allocate buffers for AAL0.\n",
28755 card->name);
28756 - atomic_inc(&vcc->stats->rx_err);
28757 + atomic_inc_unchecked(&vcc->stats->rx_err);
28758 goto drop;
28759 }
28760
28761 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28762 ATM_SKB(sb)->vcc = vcc;
28763 __net_timestamp(sb);
28764 vcc->push(vcc, sb);
28765 - atomic_inc(&vcc->stats->rx);
28766 + atomic_inc_unchecked(&vcc->stats->rx);
28767
28768 drop:
28769 skb_pull(queue, 64);
28770 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28771
28772 if (vc == NULL) {
28773 printk("%s: NULL connection in send().\n", card->name);
28774 - atomic_inc(&vcc->stats->tx_err);
28775 + atomic_inc_unchecked(&vcc->stats->tx_err);
28776 dev_kfree_skb(skb);
28777 return -EINVAL;
28778 }
28779 if (!test_bit(VCF_TX, &vc->flags)) {
28780 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28781 - atomic_inc(&vcc->stats->tx_err);
28782 + atomic_inc_unchecked(&vcc->stats->tx_err);
28783 dev_kfree_skb(skb);
28784 return -EINVAL;
28785 }
28786 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28787 break;
28788 default:
28789 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28790 - atomic_inc(&vcc->stats->tx_err);
28791 + atomic_inc_unchecked(&vcc->stats->tx_err);
28792 dev_kfree_skb(skb);
28793 return -EINVAL;
28794 }
28795
28796 if (skb_shinfo(skb)->nr_frags != 0) {
28797 printk("%s: No scatter-gather yet.\n", card->name);
28798 - atomic_inc(&vcc->stats->tx_err);
28799 + atomic_inc_unchecked(&vcc->stats->tx_err);
28800 dev_kfree_skb(skb);
28801 return -EINVAL;
28802 }
28803 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28804
28805 err = queue_skb(card, vc, skb, oam);
28806 if (err) {
28807 - atomic_inc(&vcc->stats->tx_err);
28808 + atomic_inc_unchecked(&vcc->stats->tx_err);
28809 dev_kfree_skb(skb);
28810 return err;
28811 }
28812 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28813 skb = dev_alloc_skb(64);
28814 if (!skb) {
28815 printk("%s: Out of memory in send_oam().\n", card->name);
28816 - atomic_inc(&vcc->stats->tx_err);
28817 + atomic_inc_unchecked(&vcc->stats->tx_err);
28818 return -ENOMEM;
28819 }
28820 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28821 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28822 index 96cce6d..62c3ec5 100644
28823 --- a/drivers/atm/iphase.c
28824 +++ b/drivers/atm/iphase.c
28825 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28826 status = (u_short) (buf_desc_ptr->desc_mode);
28827 if (status & (RX_CER | RX_PTE | RX_OFL))
28828 {
28829 - atomic_inc(&vcc->stats->rx_err);
28830 + atomic_inc_unchecked(&vcc->stats->rx_err);
28831 IF_ERR(printk("IA: bad packet, dropping it");)
28832 if (status & RX_CER) {
28833 IF_ERR(printk(" cause: packet CRC error\n");)
28834 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28835 len = dma_addr - buf_addr;
28836 if (len > iadev->rx_buf_sz) {
28837 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28838 - atomic_inc(&vcc->stats->rx_err);
28839 + atomic_inc_unchecked(&vcc->stats->rx_err);
28840 goto out_free_desc;
28841 }
28842
28843 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28844 ia_vcc = INPH_IA_VCC(vcc);
28845 if (ia_vcc == NULL)
28846 {
28847 - atomic_inc(&vcc->stats->rx_err);
28848 + atomic_inc_unchecked(&vcc->stats->rx_err);
28849 atm_return(vcc, skb->truesize);
28850 dev_kfree_skb_any(skb);
28851 goto INCR_DLE;
28852 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28853 if ((length > iadev->rx_buf_sz) || (length >
28854 (skb->len - sizeof(struct cpcs_trailer))))
28855 {
28856 - atomic_inc(&vcc->stats->rx_err);
28857 + atomic_inc_unchecked(&vcc->stats->rx_err);
28858 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28859 length, skb->len);)
28860 atm_return(vcc, skb->truesize);
28861 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28862
28863 IF_RX(printk("rx_dle_intr: skb push");)
28864 vcc->push(vcc,skb);
28865 - atomic_inc(&vcc->stats->rx);
28866 + atomic_inc_unchecked(&vcc->stats->rx);
28867 iadev->rx_pkt_cnt++;
28868 }
28869 INCR_DLE:
28870 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28871 {
28872 struct k_sonet_stats *stats;
28873 stats = &PRIV(_ia_dev[board])->sonet_stats;
28874 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28875 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28876 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28877 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28878 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28879 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28880 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28881 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28882 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28883 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28884 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28885 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28886 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28887 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28888 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28889 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28890 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28891 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28892 }
28893 ia_cmds.status = 0;
28894 break;
28895 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28896 if ((desc == 0) || (desc > iadev->num_tx_desc))
28897 {
28898 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28899 - atomic_inc(&vcc->stats->tx);
28900 + atomic_inc_unchecked(&vcc->stats->tx);
28901 if (vcc->pop)
28902 vcc->pop(vcc, skb);
28903 else
28904 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28905 ATM_DESC(skb) = vcc->vci;
28906 skb_queue_tail(&iadev->tx_dma_q, skb);
28907
28908 - atomic_inc(&vcc->stats->tx);
28909 + atomic_inc_unchecked(&vcc->stats->tx);
28910 iadev->tx_pkt_cnt++;
28911 /* Increment transaction counter */
28912 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28913
28914 #if 0
28915 /* add flow control logic */
28916 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28917 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28918 if (iavcc->vc_desc_cnt > 10) {
28919 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28920 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28921 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28922 index 68c7588..7036683 100644
28923 --- a/drivers/atm/lanai.c
28924 +++ b/drivers/atm/lanai.c
28925 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28926 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28927 lanai_endtx(lanai, lvcc);
28928 lanai_free_skb(lvcc->tx.atmvcc, skb);
28929 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28930 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28931 }
28932
28933 /* Try to fill the buffer - don't call unless there is backlog */
28934 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28935 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28936 __net_timestamp(skb);
28937 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28938 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28939 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28940 out:
28941 lvcc->rx.buf.ptr = end;
28942 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28943 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28944 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28945 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28946 lanai->stats.service_rxnotaal5++;
28947 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28948 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28949 return 0;
28950 }
28951 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28952 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28953 int bytes;
28954 read_unlock(&vcc_sklist_lock);
28955 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28956 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28957 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28958 lvcc->stats.x.aal5.service_trash++;
28959 bytes = (SERVICE_GET_END(s) * 16) -
28960 (((unsigned long) lvcc->rx.buf.ptr) -
28961 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28962 }
28963 if (s & SERVICE_STREAM) {
28964 read_unlock(&vcc_sklist_lock);
28965 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28966 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28967 lvcc->stats.x.aal5.service_stream++;
28968 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28969 "PDU on VCI %d!\n", lanai->number, vci);
28970 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28971 return 0;
28972 }
28973 DPRINTK("got rx crc error on vci %d\n", vci);
28974 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28975 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28976 lvcc->stats.x.aal5.service_rxcrc++;
28977 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28978 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28979 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28980 index 1c70c45..300718d 100644
28981 --- a/drivers/atm/nicstar.c
28982 +++ b/drivers/atm/nicstar.c
28983 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28984 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28985 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28986 card->index);
28987 - atomic_inc(&vcc->stats->tx_err);
28988 + atomic_inc_unchecked(&vcc->stats->tx_err);
28989 dev_kfree_skb_any(skb);
28990 return -EINVAL;
28991 }
28992 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28993 if (!vc->tx) {
28994 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28995 card->index);
28996 - atomic_inc(&vcc->stats->tx_err);
28997 + atomic_inc_unchecked(&vcc->stats->tx_err);
28998 dev_kfree_skb_any(skb);
28999 return -EINVAL;
29000 }
29001 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29002 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
29003 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
29004 card->index);
29005 - atomic_inc(&vcc->stats->tx_err);
29006 + atomic_inc_unchecked(&vcc->stats->tx_err);
29007 dev_kfree_skb_any(skb);
29008 return -EINVAL;
29009 }
29010
29011 if (skb_shinfo(skb)->nr_frags != 0) {
29012 printk("nicstar%d: No scatter-gather yet.\n", card->index);
29013 - atomic_inc(&vcc->stats->tx_err);
29014 + atomic_inc_unchecked(&vcc->stats->tx_err);
29015 dev_kfree_skb_any(skb);
29016 return -EINVAL;
29017 }
29018 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29019 }
29020
29021 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
29022 - atomic_inc(&vcc->stats->tx_err);
29023 + atomic_inc_unchecked(&vcc->stats->tx_err);
29024 dev_kfree_skb_any(skb);
29025 return -EIO;
29026 }
29027 - atomic_inc(&vcc->stats->tx);
29028 + atomic_inc_unchecked(&vcc->stats->tx);
29029
29030 return 0;
29031 }
29032 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29033 printk
29034 ("nicstar%d: Can't allocate buffers for aal0.\n",
29035 card->index);
29036 - atomic_add(i, &vcc->stats->rx_drop);
29037 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
29038 break;
29039 }
29040 if (!atm_charge(vcc, sb->truesize)) {
29041 RXPRINTK
29042 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
29043 card->index);
29044 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
29045 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
29046 dev_kfree_skb_any(sb);
29047 break;
29048 }
29049 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29050 ATM_SKB(sb)->vcc = vcc;
29051 __net_timestamp(sb);
29052 vcc->push(vcc, sb);
29053 - atomic_inc(&vcc->stats->rx);
29054 + atomic_inc_unchecked(&vcc->stats->rx);
29055 cell += ATM_CELL_PAYLOAD;
29056 }
29057
29058 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29059 if (iovb == NULL) {
29060 printk("nicstar%d: Out of iovec buffers.\n",
29061 card->index);
29062 - atomic_inc(&vcc->stats->rx_drop);
29063 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29064 recycle_rx_buf(card, skb);
29065 return;
29066 }
29067 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29068 small or large buffer itself. */
29069 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
29070 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
29071 - atomic_inc(&vcc->stats->rx_err);
29072 + atomic_inc_unchecked(&vcc->stats->rx_err);
29073 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29074 NS_MAX_IOVECS);
29075 NS_PRV_IOVCNT(iovb) = 0;
29076 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29077 ("nicstar%d: Expected a small buffer, and this is not one.\n",
29078 card->index);
29079 which_list(card, skb);
29080 - atomic_inc(&vcc->stats->rx_err);
29081 + atomic_inc_unchecked(&vcc->stats->rx_err);
29082 recycle_rx_buf(card, skb);
29083 vc->rx_iov = NULL;
29084 recycle_iov_buf(card, iovb);
29085 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29086 ("nicstar%d: Expected a large buffer, and this is not one.\n",
29087 card->index);
29088 which_list(card, skb);
29089 - atomic_inc(&vcc->stats->rx_err);
29090 + atomic_inc_unchecked(&vcc->stats->rx_err);
29091 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29092 NS_PRV_IOVCNT(iovb));
29093 vc->rx_iov = NULL;
29094 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29095 printk(" - PDU size mismatch.\n");
29096 else
29097 printk(".\n");
29098 - atomic_inc(&vcc->stats->rx_err);
29099 + atomic_inc_unchecked(&vcc->stats->rx_err);
29100 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29101 NS_PRV_IOVCNT(iovb));
29102 vc->rx_iov = NULL;
29103 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29104 /* skb points to a small buffer */
29105 if (!atm_charge(vcc, skb->truesize)) {
29106 push_rxbufs(card, skb);
29107 - atomic_inc(&vcc->stats->rx_drop);
29108 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29109 } else {
29110 skb_put(skb, len);
29111 dequeue_sm_buf(card, skb);
29112 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29113 ATM_SKB(skb)->vcc = vcc;
29114 __net_timestamp(skb);
29115 vcc->push(vcc, skb);
29116 - atomic_inc(&vcc->stats->rx);
29117 + atomic_inc_unchecked(&vcc->stats->rx);
29118 }
29119 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
29120 struct sk_buff *sb;
29121 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29122 if (len <= NS_SMBUFSIZE) {
29123 if (!atm_charge(vcc, sb->truesize)) {
29124 push_rxbufs(card, sb);
29125 - atomic_inc(&vcc->stats->rx_drop);
29126 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29127 } else {
29128 skb_put(sb, len);
29129 dequeue_sm_buf(card, sb);
29130 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29131 ATM_SKB(sb)->vcc = vcc;
29132 __net_timestamp(sb);
29133 vcc->push(vcc, sb);
29134 - atomic_inc(&vcc->stats->rx);
29135 + atomic_inc_unchecked(&vcc->stats->rx);
29136 }
29137
29138 push_rxbufs(card, skb);
29139 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29140
29141 if (!atm_charge(vcc, skb->truesize)) {
29142 push_rxbufs(card, skb);
29143 - atomic_inc(&vcc->stats->rx_drop);
29144 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29145 } else {
29146 dequeue_lg_buf(card, skb);
29147 #ifdef NS_USE_DESTRUCTORS
29148 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29149 ATM_SKB(skb)->vcc = vcc;
29150 __net_timestamp(skb);
29151 vcc->push(vcc, skb);
29152 - atomic_inc(&vcc->stats->rx);
29153 + atomic_inc_unchecked(&vcc->stats->rx);
29154 }
29155
29156 push_rxbufs(card, sb);
29157 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29158 printk
29159 ("nicstar%d: Out of huge buffers.\n",
29160 card->index);
29161 - atomic_inc(&vcc->stats->rx_drop);
29162 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29163 recycle_iovec_rx_bufs(card,
29164 (struct iovec *)
29165 iovb->data,
29166 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29167 card->hbpool.count++;
29168 } else
29169 dev_kfree_skb_any(hb);
29170 - atomic_inc(&vcc->stats->rx_drop);
29171 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29172 } else {
29173 /* Copy the small buffer to the huge buffer */
29174 sb = (struct sk_buff *)iov->iov_base;
29175 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29176 #endif /* NS_USE_DESTRUCTORS */
29177 __net_timestamp(hb);
29178 vcc->push(vcc, hb);
29179 - atomic_inc(&vcc->stats->rx);
29180 + atomic_inc_unchecked(&vcc->stats->rx);
29181 }
29182 }
29183
29184 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
29185 index 9851093..adb2b1e 100644
29186 --- a/drivers/atm/solos-pci.c
29187 +++ b/drivers/atm/solos-pci.c
29188 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
29189 }
29190 atm_charge(vcc, skb->truesize);
29191 vcc->push(vcc, skb);
29192 - atomic_inc(&vcc->stats->rx);
29193 + atomic_inc_unchecked(&vcc->stats->rx);
29194 break;
29195
29196 case PKT_STATUS:
29197 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
29198 vcc = SKB_CB(oldskb)->vcc;
29199
29200 if (vcc) {
29201 - atomic_inc(&vcc->stats->tx);
29202 + atomic_inc_unchecked(&vcc->stats->tx);
29203 solos_pop(vcc, oldskb);
29204 } else
29205 dev_kfree_skb_irq(oldskb);
29206 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
29207 index 0215934..ce9f5b1 100644
29208 --- a/drivers/atm/suni.c
29209 +++ b/drivers/atm/suni.c
29210 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
29211
29212
29213 #define ADD_LIMITED(s,v) \
29214 - atomic_add((v),&stats->s); \
29215 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
29216 + atomic_add_unchecked((v),&stats->s); \
29217 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
29218
29219
29220 static void suni_hz(unsigned long from_timer)
29221 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
29222 index 5120a96..e2572bd 100644
29223 --- a/drivers/atm/uPD98402.c
29224 +++ b/drivers/atm/uPD98402.c
29225 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
29226 struct sonet_stats tmp;
29227 int error = 0;
29228
29229 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29230 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29231 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
29232 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
29233 if (zero && !error) {
29234 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
29235
29236
29237 #define ADD_LIMITED(s,v) \
29238 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
29239 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
29240 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29241 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
29242 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
29243 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29244
29245
29246 static void stat_event(struct atm_dev *dev)
29247 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
29248 if (reason & uPD98402_INT_PFM) stat_event(dev);
29249 if (reason & uPD98402_INT_PCO) {
29250 (void) GET(PCOCR); /* clear interrupt cause */
29251 - atomic_add(GET(HECCT),
29252 + atomic_add_unchecked(GET(HECCT),
29253 &PRIV(dev)->sonet_stats.uncorr_hcs);
29254 }
29255 if ((reason & uPD98402_INT_RFO) &&
29256 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
29257 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
29258 uPD98402_INT_LOS),PIMR); /* enable them */
29259 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
29260 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29261 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
29262 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
29263 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29264 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
29265 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
29266 return 0;
29267 }
29268
29269 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
29270 index abe4e20..83c4727 100644
29271 --- a/drivers/atm/zatm.c
29272 +++ b/drivers/atm/zatm.c
29273 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29274 }
29275 if (!size) {
29276 dev_kfree_skb_irq(skb);
29277 - if (vcc) atomic_inc(&vcc->stats->rx_err);
29278 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
29279 continue;
29280 }
29281 if (!atm_charge(vcc,skb->truesize)) {
29282 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29283 skb->len = size;
29284 ATM_SKB(skb)->vcc = vcc;
29285 vcc->push(vcc,skb);
29286 - atomic_inc(&vcc->stats->rx);
29287 + atomic_inc_unchecked(&vcc->stats->rx);
29288 }
29289 zout(pos & 0xffff,MTA(mbx));
29290 #if 0 /* probably a stupid idea */
29291 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
29292 skb_queue_head(&zatm_vcc->backlog,skb);
29293 break;
29294 }
29295 - atomic_inc(&vcc->stats->tx);
29296 + atomic_inc_unchecked(&vcc->stats->tx);
29297 wake_up(&zatm_vcc->tx_wait);
29298 }
29299
29300 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
29301 index deb4a45..211eff2 100644
29302 --- a/drivers/base/devtmpfs.c
29303 +++ b/drivers/base/devtmpfs.c
29304 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
29305 if (!thread)
29306 return 0;
29307
29308 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
29309 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
29310 if (err)
29311 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
29312 else
29313 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
29314 index cbb463b..babe2cf 100644
29315 --- a/drivers/base/power/wakeup.c
29316 +++ b/drivers/base/power/wakeup.c
29317 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
29318 * They need to be modified together atomically, so it's better to use one
29319 * atomic variable to hold them both.
29320 */
29321 -static atomic_t combined_event_count = ATOMIC_INIT(0);
29322 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29323
29324 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29325 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29326
29327 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29328 {
29329 - unsigned int comb = atomic_read(&combined_event_count);
29330 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29331
29332 *cnt = (comb >> IN_PROGRESS_BITS);
29333 *inpr = comb & MAX_IN_PROGRESS;
29334 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29335 ws->start_prevent_time = ws->last_time;
29336
29337 /* Increment the counter of events in progress. */
29338 - cec = atomic_inc_return(&combined_event_count);
29339 + cec = atomic_inc_return_unchecked(&combined_event_count);
29340
29341 trace_wakeup_source_activate(ws->name, cec);
29342 }
29343 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29344 * Increment the counter of registered wakeup events and decrement the
29345 * couter of wakeup events in progress simultaneously.
29346 */
29347 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29348 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29349 trace_wakeup_source_deactivate(ws->name, cec);
29350
29351 split_counters(&cnt, &inpr);
29352 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29353 index b0f553b..77b928b 100644
29354 --- a/drivers/block/cciss.c
29355 +++ b/drivers/block/cciss.c
29356 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29357 int err;
29358 u32 cp;
29359
29360 + memset(&arg64, 0, sizeof(arg64));
29361 +
29362 err = 0;
29363 err |=
29364 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29365 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29366 while (!list_empty(&h->reqQ)) {
29367 c = list_entry(h->reqQ.next, CommandList_struct, list);
29368 /* can't do anything if fifo is full */
29369 - if ((h->access.fifo_full(h))) {
29370 + if ((h->access->fifo_full(h))) {
29371 dev_warn(&h->pdev->dev, "fifo full\n");
29372 break;
29373 }
29374 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29375 h->Qdepth--;
29376
29377 /* Tell the controller execute command */
29378 - h->access.submit_command(h, c);
29379 + h->access->submit_command(h, c);
29380
29381 /* Put job onto the completed Q */
29382 addQ(&h->cmpQ, c);
29383 @@ -3443,17 +3445,17 @@ startio:
29384
29385 static inline unsigned long get_next_completion(ctlr_info_t *h)
29386 {
29387 - return h->access.command_completed(h);
29388 + return h->access->command_completed(h);
29389 }
29390
29391 static inline int interrupt_pending(ctlr_info_t *h)
29392 {
29393 - return h->access.intr_pending(h);
29394 + return h->access->intr_pending(h);
29395 }
29396
29397 static inline long interrupt_not_for_us(ctlr_info_t *h)
29398 {
29399 - return ((h->access.intr_pending(h) == 0) ||
29400 + return ((h->access->intr_pending(h) == 0) ||
29401 (h->interrupts_enabled == 0));
29402 }
29403
29404 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29405 u32 a;
29406
29407 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29408 - return h->access.command_completed(h);
29409 + return h->access->command_completed(h);
29410
29411 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29412 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29413 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29414 trans_support & CFGTBL_Trans_use_short_tags);
29415
29416 /* Change the access methods to the performant access methods */
29417 - h->access = SA5_performant_access;
29418 + h->access = &SA5_performant_access;
29419 h->transMethod = CFGTBL_Trans_Performant;
29420
29421 return;
29422 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29423 if (prod_index < 0)
29424 return -ENODEV;
29425 h->product_name = products[prod_index].product_name;
29426 - h->access = *(products[prod_index].access);
29427 + h->access = products[prod_index].access;
29428
29429 if (cciss_board_disabled(h)) {
29430 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29431 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29432 }
29433
29434 /* make sure the board interrupts are off */
29435 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29436 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29437 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29438 if (rc)
29439 goto clean2;
29440 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29441 * fake ones to scoop up any residual completions.
29442 */
29443 spin_lock_irqsave(&h->lock, flags);
29444 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29445 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29446 spin_unlock_irqrestore(&h->lock, flags);
29447 free_irq(h->intr[h->intr_mode], h);
29448 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29449 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29450 dev_info(&h->pdev->dev, "Board READY.\n");
29451 dev_info(&h->pdev->dev,
29452 "Waiting for stale completions to drain.\n");
29453 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29454 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29455 msleep(10000);
29456 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29457 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29458
29459 rc = controller_reset_failed(h->cfgtable);
29460 if (rc)
29461 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29462 cciss_scsi_setup(h);
29463
29464 /* Turn the interrupts on so we can service requests */
29465 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29466 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29467
29468 /* Get the firmware version */
29469 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29470 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29471 kfree(flush_buf);
29472 if (return_code != IO_OK)
29473 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29474 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29475 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29476 free_irq(h->intr[h->intr_mode], h);
29477 }
29478
29479 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29480 index 7fda30e..eb5dfe0 100644
29481 --- a/drivers/block/cciss.h
29482 +++ b/drivers/block/cciss.h
29483 @@ -101,7 +101,7 @@ struct ctlr_info
29484 /* information about each logical volume */
29485 drive_info_struct *drv[CISS_MAX_LUN];
29486
29487 - struct access_method access;
29488 + struct access_method *access;
29489
29490 /* queue and queue Info */
29491 struct list_head reqQ;
29492 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29493 index 9125bbe..eede5c8 100644
29494 --- a/drivers/block/cpqarray.c
29495 +++ b/drivers/block/cpqarray.c
29496 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29497 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29498 goto Enomem4;
29499 }
29500 - hba[i]->access.set_intr_mask(hba[i], 0);
29501 + hba[i]->access->set_intr_mask(hba[i], 0);
29502 if (request_irq(hba[i]->intr, do_ida_intr,
29503 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29504 {
29505 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29506 add_timer(&hba[i]->timer);
29507
29508 /* Enable IRQ now that spinlock and rate limit timer are set up */
29509 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29510 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29511
29512 for(j=0; j<NWD; j++) {
29513 struct gendisk *disk = ida_gendisk[i][j];
29514 @@ -694,7 +694,7 @@ DBGINFO(
29515 for(i=0; i<NR_PRODUCTS; i++) {
29516 if (board_id == products[i].board_id) {
29517 c->product_name = products[i].product_name;
29518 - c->access = *(products[i].access);
29519 + c->access = products[i].access;
29520 break;
29521 }
29522 }
29523 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29524 hba[ctlr]->intr = intr;
29525 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29526 hba[ctlr]->product_name = products[j].product_name;
29527 - hba[ctlr]->access = *(products[j].access);
29528 + hba[ctlr]->access = products[j].access;
29529 hba[ctlr]->ctlr = ctlr;
29530 hba[ctlr]->board_id = board_id;
29531 hba[ctlr]->pci_dev = NULL; /* not PCI */
29532 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29533
29534 while((c = h->reqQ) != NULL) {
29535 /* Can't do anything if we're busy */
29536 - if (h->access.fifo_full(h) == 0)
29537 + if (h->access->fifo_full(h) == 0)
29538 return;
29539
29540 /* Get the first entry from the request Q */
29541 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29542 h->Qdepth--;
29543
29544 /* Tell the controller to do our bidding */
29545 - h->access.submit_command(h, c);
29546 + h->access->submit_command(h, c);
29547
29548 /* Get onto the completion Q */
29549 addQ(&h->cmpQ, c);
29550 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29551 unsigned long flags;
29552 __u32 a,a1;
29553
29554 - istat = h->access.intr_pending(h);
29555 + istat = h->access->intr_pending(h);
29556 /* Is this interrupt for us? */
29557 if (istat == 0)
29558 return IRQ_NONE;
29559 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29560 */
29561 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29562 if (istat & FIFO_NOT_EMPTY) {
29563 - while((a = h->access.command_completed(h))) {
29564 + while((a = h->access->command_completed(h))) {
29565 a1 = a; a &= ~3;
29566 if ((c = h->cmpQ) == NULL)
29567 {
29568 @@ -1449,11 +1449,11 @@ static int sendcmd(
29569 /*
29570 * Disable interrupt
29571 */
29572 - info_p->access.set_intr_mask(info_p, 0);
29573 + info_p->access->set_intr_mask(info_p, 0);
29574 /* Make sure there is room in the command FIFO */
29575 /* Actually it should be completely empty at this time. */
29576 for (i = 200000; i > 0; i--) {
29577 - temp = info_p->access.fifo_full(info_p);
29578 + temp = info_p->access->fifo_full(info_p);
29579 if (temp != 0) {
29580 break;
29581 }
29582 @@ -1466,7 +1466,7 @@ DBG(
29583 /*
29584 * Send the cmd
29585 */
29586 - info_p->access.submit_command(info_p, c);
29587 + info_p->access->submit_command(info_p, c);
29588 complete = pollcomplete(ctlr);
29589
29590 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29591 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29592 * we check the new geometry. Then turn interrupts back on when
29593 * we're done.
29594 */
29595 - host->access.set_intr_mask(host, 0);
29596 + host->access->set_intr_mask(host, 0);
29597 getgeometry(ctlr);
29598 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29599 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29600
29601 for(i=0; i<NWD; i++) {
29602 struct gendisk *disk = ida_gendisk[ctlr][i];
29603 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29604 /* Wait (up to 2 seconds) for a command to complete */
29605
29606 for (i = 200000; i > 0; i--) {
29607 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29608 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29609 if (done == 0) {
29610 udelay(10); /* a short fixed delay */
29611 } else
29612 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29613 index be73e9d..7fbf140 100644
29614 --- a/drivers/block/cpqarray.h
29615 +++ b/drivers/block/cpqarray.h
29616 @@ -99,7 +99,7 @@ struct ctlr_info {
29617 drv_info_t drv[NWD];
29618 struct proc_dir_entry *proc;
29619
29620 - struct access_method access;
29621 + struct access_method *access;
29622
29623 cmdlist_t *reqQ;
29624 cmdlist_t *cmpQ;
29625 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29626 index b953cc7..e3dc580 100644
29627 --- a/drivers/block/drbd/drbd_int.h
29628 +++ b/drivers/block/drbd/drbd_int.h
29629 @@ -735,7 +735,7 @@ struct drbd_request;
29630 struct drbd_epoch {
29631 struct list_head list;
29632 unsigned int barrier_nr;
29633 - atomic_t epoch_size; /* increased on every request added. */
29634 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29635 atomic_t active; /* increased on every req. added, and dec on every finished. */
29636 unsigned long flags;
29637 };
29638 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29639 void *int_dig_in;
29640 void *int_dig_vv;
29641 wait_queue_head_t seq_wait;
29642 - atomic_t packet_seq;
29643 + atomic_unchecked_t packet_seq;
29644 unsigned int peer_seq;
29645 spinlock_t peer_seq_lock;
29646 unsigned int minor;
29647 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29648
29649 static inline void drbd_tcp_cork(struct socket *sock)
29650 {
29651 - int __user val = 1;
29652 + int val = 1;
29653 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29654 - (char __user *)&val, sizeof(val));
29655 + (char __force_user *)&val, sizeof(val));
29656 }
29657
29658 static inline void drbd_tcp_uncork(struct socket *sock)
29659 {
29660 - int __user val = 0;
29661 + int val = 0;
29662 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29663 - (char __user *)&val, sizeof(val));
29664 + (char __force_user *)&val, sizeof(val));
29665 }
29666
29667 static inline void drbd_tcp_nodelay(struct socket *sock)
29668 {
29669 - int __user val = 1;
29670 + int val = 1;
29671 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29672 - (char __user *)&val, sizeof(val));
29673 + (char __force_user *)&val, sizeof(val));
29674 }
29675
29676 static inline void drbd_tcp_quickack(struct socket *sock)
29677 {
29678 - int __user val = 2;
29679 + int val = 2;
29680 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29681 - (char __user *)&val, sizeof(val));
29682 + (char __force_user *)&val, sizeof(val));
29683 }
29684
29685 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29686 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29687 index f93a032..71c87bf 100644
29688 --- a/drivers/block/drbd/drbd_main.c
29689 +++ b/drivers/block/drbd/drbd_main.c
29690 @@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29691 p.sector = sector;
29692 p.block_id = block_id;
29693 p.blksize = blksize;
29694 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29695 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29696
29697 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29698 return false;
29699 @@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29700
29701 p.sector = cpu_to_be64(req->sector);
29702 p.block_id = (unsigned long)req;
29703 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29704 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29705
29706 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29707
29708 @@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29709 atomic_set(&mdev->unacked_cnt, 0);
29710 atomic_set(&mdev->local_cnt, 0);
29711 atomic_set(&mdev->net_cnt, 0);
29712 - atomic_set(&mdev->packet_seq, 0);
29713 + atomic_set_unchecked(&mdev->packet_seq, 0);
29714 atomic_set(&mdev->pp_in_use, 0);
29715 atomic_set(&mdev->pp_in_use_by_net, 0);
29716 atomic_set(&mdev->rs_sect_in, 0);
29717 @@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29718 mdev->receiver.t_state);
29719
29720 /* no need to lock it, I'm the only thread alive */
29721 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29722 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29723 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29724 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29725 mdev->al_writ_cnt =
29726 mdev->bm_writ_cnt =
29727 mdev->read_cnt =
29728 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29729 index edb490a..ecd69da 100644
29730 --- a/drivers/block/drbd/drbd_nl.c
29731 +++ b/drivers/block/drbd/drbd_nl.c
29732 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29733 module_put(THIS_MODULE);
29734 }
29735
29736 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29737 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29738
29739 static unsigned short *
29740 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29741 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29742 cn_reply->id.idx = CN_IDX_DRBD;
29743 cn_reply->id.val = CN_VAL_DRBD;
29744
29745 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29746 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29747 cn_reply->ack = 0; /* not used here. */
29748 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29749 (int)((char *)tl - (char *)reply->tag_list);
29750 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29751 cn_reply->id.idx = CN_IDX_DRBD;
29752 cn_reply->id.val = CN_VAL_DRBD;
29753
29754 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29755 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29756 cn_reply->ack = 0; /* not used here. */
29757 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29758 (int)((char *)tl - (char *)reply->tag_list);
29759 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29760 cn_reply->id.idx = CN_IDX_DRBD;
29761 cn_reply->id.val = CN_VAL_DRBD;
29762
29763 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29764 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29765 cn_reply->ack = 0; // not used here.
29766 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29767 (int)((char*)tl - (char*)reply->tag_list);
29768 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29769 cn_reply->id.idx = CN_IDX_DRBD;
29770 cn_reply->id.val = CN_VAL_DRBD;
29771
29772 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29773 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29774 cn_reply->ack = 0; /* not used here. */
29775 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29776 (int)((char *)tl - (char *)reply->tag_list);
29777 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29778 index c74ca2d..860c819 100644
29779 --- a/drivers/block/drbd/drbd_receiver.c
29780 +++ b/drivers/block/drbd/drbd_receiver.c
29781 @@ -898,7 +898,7 @@ retry:
29782 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29783 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29784
29785 - atomic_set(&mdev->packet_seq, 0);
29786 + atomic_set_unchecked(&mdev->packet_seq, 0);
29787 mdev->peer_seq = 0;
29788
29789 if (drbd_send_protocol(mdev) == -1)
29790 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29791 do {
29792 next_epoch = NULL;
29793
29794 - epoch_size = atomic_read(&epoch->epoch_size);
29795 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29796
29797 switch (ev & ~EV_CLEANUP) {
29798 case EV_PUT:
29799 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29800 rv = FE_DESTROYED;
29801 } else {
29802 epoch->flags = 0;
29803 - atomic_set(&epoch->epoch_size, 0);
29804 + atomic_set_unchecked(&epoch->epoch_size, 0);
29805 /* atomic_set(&epoch->active, 0); is already zero */
29806 if (rv == FE_STILL_LIVE)
29807 rv = FE_RECYCLED;
29808 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29809 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29810 drbd_flush(mdev);
29811
29812 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29813 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29814 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29815 if (epoch)
29816 break;
29817 }
29818
29819 epoch = mdev->current_epoch;
29820 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29821 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29822
29823 D_ASSERT(atomic_read(&epoch->active) == 0);
29824 D_ASSERT(epoch->flags == 0);
29825 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29826 }
29827
29828 epoch->flags = 0;
29829 - atomic_set(&epoch->epoch_size, 0);
29830 + atomic_set_unchecked(&epoch->epoch_size, 0);
29831 atomic_set(&epoch->active, 0);
29832
29833 spin_lock(&mdev->epoch_lock);
29834 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29835 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29836 list_add(&epoch->list, &mdev->current_epoch->list);
29837 mdev->current_epoch = epoch;
29838 mdev->epochs++;
29839 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29840 spin_unlock(&mdev->peer_seq_lock);
29841
29842 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29843 - atomic_inc(&mdev->current_epoch->epoch_size);
29844 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29845 return drbd_drain_block(mdev, data_size);
29846 }
29847
29848 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29849
29850 spin_lock(&mdev->epoch_lock);
29851 e->epoch = mdev->current_epoch;
29852 - atomic_inc(&e->epoch->epoch_size);
29853 + atomic_inc_unchecked(&e->epoch->epoch_size);
29854 atomic_inc(&e->epoch->active);
29855 spin_unlock(&mdev->epoch_lock);
29856
29857 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29858 D_ASSERT(list_empty(&mdev->done_ee));
29859
29860 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29861 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29862 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29863 D_ASSERT(list_empty(&mdev->current_epoch->list));
29864 }
29865
29866 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29867 index 3bba655..6151b66 100644
29868 --- a/drivers/block/loop.c
29869 +++ b/drivers/block/loop.c
29870 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29871 mm_segment_t old_fs = get_fs();
29872
29873 set_fs(get_ds());
29874 - bw = file->f_op->write(file, buf, len, &pos);
29875 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29876 set_fs(old_fs);
29877 if (likely(bw == len))
29878 return 0;
29879 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29880 index ea6f632..eafb192 100644
29881 --- a/drivers/char/Kconfig
29882 +++ b/drivers/char/Kconfig
29883 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29884
29885 config DEVKMEM
29886 bool "/dev/kmem virtual device support"
29887 - default y
29888 + default n
29889 + depends on !GRKERNSEC_KMEM
29890 help
29891 Say Y here if you want to support the /dev/kmem device. The
29892 /dev/kmem device is rarely used, but can be used for certain
29893 @@ -581,6 +582,7 @@ config DEVPORT
29894 bool
29895 depends on !M68K
29896 depends on ISA || PCI
29897 + depends on !GRKERNSEC_KMEM
29898 default y
29899
29900 source "drivers/s390/char/Kconfig"
29901 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29902 index 2e04433..22afc64 100644
29903 --- a/drivers/char/agp/frontend.c
29904 +++ b/drivers/char/agp/frontend.c
29905 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29906 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29907 return -EFAULT;
29908
29909 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29910 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29911 return -EFAULT;
29912
29913 client = agp_find_client_by_pid(reserve.pid);
29914 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29915 index 21cb980..f15107c 100644
29916 --- a/drivers/char/genrtc.c
29917 +++ b/drivers/char/genrtc.c
29918 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29919 switch (cmd) {
29920
29921 case RTC_PLL_GET:
29922 + memset(&pll, 0, sizeof(pll));
29923 if (get_rtc_pll(&pll))
29924 return -EINVAL;
29925 else
29926 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29927 index dfd7876..c0b0885 100644
29928 --- a/drivers/char/hpet.c
29929 +++ b/drivers/char/hpet.c
29930 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29931 }
29932
29933 static int
29934 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29935 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29936 struct hpet_info *info)
29937 {
29938 struct hpet_timer __iomem *timer;
29939 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29940 index 2c29942..604c5ba 100644
29941 --- a/drivers/char/ipmi/ipmi_msghandler.c
29942 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29943 @@ -420,7 +420,7 @@ struct ipmi_smi {
29944 struct proc_dir_entry *proc_dir;
29945 char proc_dir_name[10];
29946
29947 - atomic_t stats[IPMI_NUM_STATS];
29948 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29949
29950 /*
29951 * run_to_completion duplicate of smb_info, smi_info
29952 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29953
29954
29955 #define ipmi_inc_stat(intf, stat) \
29956 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29957 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29958 #define ipmi_get_stat(intf, stat) \
29959 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29960 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29961
29962 static int is_lan_addr(struct ipmi_addr *addr)
29963 {
29964 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29965 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29966 init_waitqueue_head(&intf->waitq);
29967 for (i = 0; i < IPMI_NUM_STATS; i++)
29968 - atomic_set(&intf->stats[i], 0);
29969 + atomic_set_unchecked(&intf->stats[i], 0);
29970
29971 intf->proc_dir = NULL;
29972
29973 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29974 index 83f85cf..279e63f 100644
29975 --- a/drivers/char/ipmi/ipmi_si_intf.c
29976 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29977 @@ -275,7 +275,7 @@ struct smi_info {
29978 unsigned char slave_addr;
29979
29980 /* Counters and things for the proc filesystem. */
29981 - atomic_t stats[SI_NUM_STATS];
29982 + atomic_unchecked_t stats[SI_NUM_STATS];
29983
29984 struct task_struct *thread;
29985
29986 @@ -284,9 +284,9 @@ struct smi_info {
29987 };
29988
29989 #define smi_inc_stat(smi, stat) \
29990 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29991 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29992 #define smi_get_stat(smi, stat) \
29993 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29994 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29995
29996 #define SI_MAX_PARMS 4
29997
29998 @@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29999 atomic_set(&new_smi->req_events, 0);
30000 new_smi->run_to_completion = 0;
30001 for (i = 0; i < SI_NUM_STATS; i++)
30002 - atomic_set(&new_smi->stats[i], 0);
30003 + atomic_set_unchecked(&new_smi->stats[i], 0);
30004
30005 new_smi->interrupt_disabled = 1;
30006 atomic_set(&new_smi->stop_operation, 0);
30007 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
30008 index 47ff7e4..0c7d340 100644
30009 --- a/drivers/char/mbcs.c
30010 +++ b/drivers/char/mbcs.c
30011 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
30012 return 0;
30013 }
30014
30015 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
30016 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
30017 {
30018 .part_num = MBCS_PART_NUM,
30019 .mfg_num = MBCS_MFG_NUM,
30020 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
30021 index e5eedfa..fcab50ea 100644
30022 --- a/drivers/char/mem.c
30023 +++ b/drivers/char/mem.c
30024 @@ -18,6 +18,7 @@
30025 #include <linux/raw.h>
30026 #include <linux/tty.h>
30027 #include <linux/capability.h>
30028 +#include <linux/security.h>
30029 #include <linux/ptrace.h>
30030 #include <linux/device.h>
30031 #include <linux/highmem.h>
30032 @@ -37,6 +38,10 @@
30033
30034 #define DEVPORT_MINOR 4
30035
30036 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30037 +extern const struct file_operations grsec_fops;
30038 +#endif
30039 +
30040 static inline unsigned long size_inside_page(unsigned long start,
30041 unsigned long size)
30042 {
30043 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30044
30045 while (cursor < to) {
30046 if (!devmem_is_allowed(pfn)) {
30047 +#ifdef CONFIG_GRKERNSEC_KMEM
30048 + gr_handle_mem_readwrite(from, to);
30049 +#else
30050 printk(KERN_INFO
30051 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
30052 current->comm, from, to);
30053 +#endif
30054 return 0;
30055 }
30056 cursor += PAGE_SIZE;
30057 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30058 }
30059 return 1;
30060 }
30061 +#elif defined(CONFIG_GRKERNSEC_KMEM)
30062 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30063 +{
30064 + return 0;
30065 +}
30066 #else
30067 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30068 {
30069 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
30070
30071 while (count > 0) {
30072 unsigned long remaining;
30073 + char *temp;
30074
30075 sz = size_inside_page(p, count);
30076
30077 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
30078 if (!ptr)
30079 return -EFAULT;
30080
30081 - remaining = copy_to_user(buf, ptr, sz);
30082 +#ifdef CONFIG_PAX_USERCOPY
30083 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30084 + if (!temp) {
30085 + unxlate_dev_mem_ptr(p, ptr);
30086 + return -ENOMEM;
30087 + }
30088 + memcpy(temp, ptr, sz);
30089 +#else
30090 + temp = ptr;
30091 +#endif
30092 +
30093 + remaining = copy_to_user(buf, temp, sz);
30094 +
30095 +#ifdef CONFIG_PAX_USERCOPY
30096 + kfree(temp);
30097 +#endif
30098 +
30099 unxlate_dev_mem_ptr(p, ptr);
30100 if (remaining)
30101 return -EFAULT;
30102 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30103 size_t count, loff_t *ppos)
30104 {
30105 unsigned long p = *ppos;
30106 - ssize_t low_count, read, sz;
30107 + ssize_t low_count, read, sz, err = 0;
30108 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
30109 - int err = 0;
30110
30111 read = 0;
30112 if (p < (unsigned long) high_memory) {
30113 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30114 }
30115 #endif
30116 while (low_count > 0) {
30117 + char *temp;
30118 +
30119 sz = size_inside_page(p, low_count);
30120
30121 /*
30122 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30123 */
30124 kbuf = xlate_dev_kmem_ptr((char *)p);
30125
30126 - if (copy_to_user(buf, kbuf, sz))
30127 +#ifdef CONFIG_PAX_USERCOPY
30128 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30129 + if (!temp)
30130 + return -ENOMEM;
30131 + memcpy(temp, kbuf, sz);
30132 +#else
30133 + temp = kbuf;
30134 +#endif
30135 +
30136 + err = copy_to_user(buf, temp, sz);
30137 +
30138 +#ifdef CONFIG_PAX_USERCOPY
30139 + kfree(temp);
30140 +#endif
30141 +
30142 + if (err)
30143 return -EFAULT;
30144 buf += sz;
30145 p += sz;
30146 @@ -833,6 +880,9 @@ static const struct memdev {
30147 #ifdef CONFIG_CRASH_DUMP
30148 [12] = { "oldmem", 0, &oldmem_fops, NULL },
30149 #endif
30150 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30151 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
30152 +#endif
30153 };
30154
30155 static int memory_open(struct inode *inode, struct file *filp)
30156 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
30157 index 9df78e2..01ba9ae 100644
30158 --- a/drivers/char/nvram.c
30159 +++ b/drivers/char/nvram.c
30160 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
30161
30162 spin_unlock_irq(&rtc_lock);
30163
30164 - if (copy_to_user(buf, contents, tmp - contents))
30165 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
30166 return -EFAULT;
30167
30168 *ppos = i;
30169 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
30170 index 0a484b4..f48ccd1 100644
30171 --- a/drivers/char/pcmcia/synclink_cs.c
30172 +++ b/drivers/char/pcmcia/synclink_cs.c
30173 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30174
30175 if (debug_level >= DEBUG_LEVEL_INFO)
30176 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
30177 - __FILE__,__LINE__, info->device_name, port->count);
30178 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
30179
30180 - WARN_ON(!port->count);
30181 + WARN_ON(!atomic_read(&port->count));
30182
30183 if (tty_port_close_start(port, tty, filp) == 0)
30184 goto cleanup;
30185 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30186 cleanup:
30187 if (debug_level >= DEBUG_LEVEL_INFO)
30188 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
30189 - tty->driver->name, port->count);
30190 + tty->driver->name, atomic_read(&port->count));
30191 }
30192
30193 /* Wait until the transmitter is empty.
30194 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30195
30196 if (debug_level >= DEBUG_LEVEL_INFO)
30197 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
30198 - __FILE__,__LINE__,tty->driver->name, port->count);
30199 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
30200
30201 /* If port is closing, signal caller to try again */
30202 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
30203 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30204 goto cleanup;
30205 }
30206 spin_lock(&port->lock);
30207 - port->count++;
30208 + atomic_inc(&port->count);
30209 spin_unlock(&port->lock);
30210 spin_unlock_irqrestore(&info->netlock, flags);
30211
30212 - if (port->count == 1) {
30213 + if (atomic_read(&port->count) == 1) {
30214 /* 1st open on this device, init hardware */
30215 retval = startup(info, tty);
30216 if (retval < 0)
30217 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
30218 unsigned short new_crctype;
30219
30220 /* return error if TTY interface open */
30221 - if (info->port.count)
30222 + if (atomic_read(&info->port.count))
30223 return -EBUSY;
30224
30225 switch (encoding)
30226 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
30227
30228 /* arbitrate between network and tty opens */
30229 spin_lock_irqsave(&info->netlock, flags);
30230 - if (info->port.count != 0 || info->netcount != 0) {
30231 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
30232 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
30233 spin_unlock_irqrestore(&info->netlock, flags);
30234 return -EBUSY;
30235 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
30236 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
30237
30238 /* return error if TTY interface open */
30239 - if (info->port.count)
30240 + if (atomic_read(&info->port.count))
30241 return -EBUSY;
30242
30243 if (cmd != SIOCWANDEV)
30244 diff --git a/drivers/char/random.c b/drivers/char/random.c
30245 index b86eae9..4192a7a 100644
30246 --- a/drivers/char/random.c
30247 +++ b/drivers/char/random.c
30248 @@ -272,8 +272,13 @@
30249 /*
30250 * Configuration information
30251 */
30252 +#ifdef CONFIG_GRKERNSEC_RANDNET
30253 +#define INPUT_POOL_WORDS 512
30254 +#define OUTPUT_POOL_WORDS 128
30255 +#else
30256 #define INPUT_POOL_WORDS 128
30257 #define OUTPUT_POOL_WORDS 32
30258 +#endif
30259 #define SEC_XFER_SIZE 512
30260 #define EXTRACT_SIZE 10
30261
30262 @@ -313,10 +318,17 @@ static struct poolinfo {
30263 int poolwords;
30264 int tap1, tap2, tap3, tap4, tap5;
30265 } poolinfo_table[] = {
30266 +#ifdef CONFIG_GRKERNSEC_RANDNET
30267 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
30268 + { 512, 411, 308, 208, 104, 1 },
30269 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
30270 + { 128, 103, 76, 51, 25, 1 },
30271 +#else
30272 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
30273 { 128, 103, 76, 51, 25, 1 },
30274 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
30275 { 32, 26, 20, 14, 7, 1 },
30276 +#endif
30277 #if 0
30278 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
30279 { 2048, 1638, 1231, 819, 411, 1 },
30280 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
30281 input_rotate += i ? 7 : 14;
30282 }
30283
30284 - ACCESS_ONCE(r->input_rotate) = input_rotate;
30285 - ACCESS_ONCE(r->add_ptr) = i;
30286 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
30287 + ACCESS_ONCE_RW(r->add_ptr) = i;
30288 smp_wmb();
30289
30290 if (out)
30291 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
30292 }
30293 #endif
30294
30295 +#ifdef CONFIG_PAX_LATENT_ENTROPY
30296 +u64 latent_entropy;
30297 +
30298 +__init void transfer_latent_entropy(void)
30299 +{
30300 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30301 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30302 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
30303 +}
30304 +#endif
30305 +
30306 /*********************************************************************
30307 *
30308 * Entropy extraction routines
30309 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
30310
30311 extract_buf(r, tmp);
30312 i = min_t(int, nbytes, EXTRACT_SIZE);
30313 - if (copy_to_user(buf, tmp, i)) {
30314 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
30315 ret = -EFAULT;
30316 break;
30317 }
30318 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30319 #include <linux/sysctl.h>
30320
30321 static int min_read_thresh = 8, min_write_thresh;
30322 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
30323 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30324 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30325 static char sysctl_bootid[16];
30326
30327 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30328 index f877805..403375a 100644
30329 --- a/drivers/char/sonypi.c
30330 +++ b/drivers/char/sonypi.c
30331 @@ -54,6 +54,7 @@
30332
30333 #include <asm/uaccess.h>
30334 #include <asm/io.h>
30335 +#include <asm/local.h>
30336
30337 #include <linux/sonypi.h>
30338
30339 @@ -490,7 +491,7 @@ static struct sonypi_device {
30340 spinlock_t fifo_lock;
30341 wait_queue_head_t fifo_proc_list;
30342 struct fasync_struct *fifo_async;
30343 - int open_count;
30344 + local_t open_count;
30345 int model;
30346 struct input_dev *input_jog_dev;
30347 struct input_dev *input_key_dev;
30348 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30349 static int sonypi_misc_release(struct inode *inode, struct file *file)
30350 {
30351 mutex_lock(&sonypi_device.lock);
30352 - sonypi_device.open_count--;
30353 + local_dec(&sonypi_device.open_count);
30354 mutex_unlock(&sonypi_device.lock);
30355 return 0;
30356 }
30357 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30358 {
30359 mutex_lock(&sonypi_device.lock);
30360 /* Flush input queue on first open */
30361 - if (!sonypi_device.open_count)
30362 + if (!local_read(&sonypi_device.open_count))
30363 kfifo_reset(&sonypi_device.fifo);
30364 - sonypi_device.open_count++;
30365 + local_inc(&sonypi_device.open_count);
30366 mutex_unlock(&sonypi_device.lock);
30367
30368 return 0;
30369 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30370 index 4dc8024..90108d1 100644
30371 --- a/drivers/char/tpm/tpm.c
30372 +++ b/drivers/char/tpm/tpm.c
30373 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30374 chip->vendor.req_complete_val)
30375 goto out_recv;
30376
30377 - if ((status == chip->vendor.req_canceled)) {
30378 + if (status == chip->vendor.req_canceled) {
30379 dev_err(chip->dev, "Operation Canceled\n");
30380 rc = -ECANCELED;
30381 goto out;
30382 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30383 index 0636520..169c1d0 100644
30384 --- a/drivers/char/tpm/tpm_bios.c
30385 +++ b/drivers/char/tpm/tpm_bios.c
30386 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30387 event = addr;
30388
30389 if ((event->event_type == 0 && event->event_size == 0) ||
30390 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30391 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30392 return NULL;
30393
30394 return addr;
30395 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30396 return NULL;
30397
30398 if ((event->event_type == 0 && event->event_size == 0) ||
30399 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30400 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30401 return NULL;
30402
30403 (*pos)++;
30404 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30405 int i;
30406
30407 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30408 - seq_putc(m, data[i]);
30409 + if (!seq_putc(m, data[i]))
30410 + return -EFAULT;
30411
30412 return 0;
30413 }
30414 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30415 log->bios_event_log_end = log->bios_event_log + len;
30416
30417 virt = acpi_os_map_memory(start, len);
30418 + if (!virt) {
30419 + kfree(log->bios_event_log);
30420 + log->bios_event_log = NULL;
30421 + return -EFAULT;
30422 + }
30423
30424 - memcpy(log->bios_event_log, virt, len);
30425 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30426
30427 acpi_os_unmap_memory(virt, len);
30428 return 0;
30429 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30430 index cdf2f54..e55c197 100644
30431 --- a/drivers/char/virtio_console.c
30432 +++ b/drivers/char/virtio_console.c
30433 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30434 if (to_user) {
30435 ssize_t ret;
30436
30437 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30438 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30439 if (ret)
30440 return -EFAULT;
30441 } else {
30442 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30443 if (!port_has_data(port) && !port->host_connected)
30444 return 0;
30445
30446 - return fill_readbuf(port, ubuf, count, true);
30447 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30448 }
30449
30450 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30451 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30452 index e164c55..3aabb50 100644
30453 --- a/drivers/edac/edac_pci_sysfs.c
30454 +++ b/drivers/edac/edac_pci_sysfs.c
30455 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30456 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30457 static int edac_pci_poll_msec = 1000; /* one second workq period */
30458
30459 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30460 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30461 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30462 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30463
30464 static struct kobject *edac_pci_top_main_kobj;
30465 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30466 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30467 edac_printk(KERN_CRIT, EDAC_PCI,
30468 "Signaled System Error on %s\n",
30469 pci_name(dev));
30470 - atomic_inc(&pci_nonparity_count);
30471 + atomic_inc_unchecked(&pci_nonparity_count);
30472 }
30473
30474 if (status & (PCI_STATUS_PARITY)) {
30475 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30476 "Master Data Parity Error on %s\n",
30477 pci_name(dev));
30478
30479 - atomic_inc(&pci_parity_count);
30480 + atomic_inc_unchecked(&pci_parity_count);
30481 }
30482
30483 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30484 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30485 "Detected Parity Error on %s\n",
30486 pci_name(dev));
30487
30488 - atomic_inc(&pci_parity_count);
30489 + atomic_inc_unchecked(&pci_parity_count);
30490 }
30491 }
30492
30493 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30494 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30495 "Signaled System Error on %s\n",
30496 pci_name(dev));
30497 - atomic_inc(&pci_nonparity_count);
30498 + atomic_inc_unchecked(&pci_nonparity_count);
30499 }
30500
30501 if (status & (PCI_STATUS_PARITY)) {
30502 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30503 "Master Data Parity Error on "
30504 "%s\n", pci_name(dev));
30505
30506 - atomic_inc(&pci_parity_count);
30507 + atomic_inc_unchecked(&pci_parity_count);
30508 }
30509
30510 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30511 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30512 "Detected Parity Error on %s\n",
30513 pci_name(dev));
30514
30515 - atomic_inc(&pci_parity_count);
30516 + atomic_inc_unchecked(&pci_parity_count);
30517 }
30518 }
30519 }
30520 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30521 if (!check_pci_errors)
30522 return;
30523
30524 - before_count = atomic_read(&pci_parity_count);
30525 + before_count = atomic_read_unchecked(&pci_parity_count);
30526
30527 /* scan all PCI devices looking for a Parity Error on devices and
30528 * bridges.
30529 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30530 /* Only if operator has selected panic on PCI Error */
30531 if (edac_pci_get_panic_on_pe()) {
30532 /* If the count is different 'after' from 'before' */
30533 - if (before_count != atomic_read(&pci_parity_count))
30534 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30535 panic("EDAC: PCI Parity Error");
30536 }
30537 }
30538 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30539 index 8c87a5e..a19cbd7 100644
30540 --- a/drivers/edac/mce_amd.h
30541 +++ b/drivers/edac/mce_amd.h
30542 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30543 struct amd_decoder_ops {
30544 bool (*dc_mce)(u16, u8);
30545 bool (*ic_mce)(u16, u8);
30546 -};
30547 +} __no_const;
30548
30549 void amd_report_gart_errors(bool);
30550 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30551 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30552 index 57ea7f4..789e3c3 100644
30553 --- a/drivers/firewire/core-card.c
30554 +++ b/drivers/firewire/core-card.c
30555 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30556
30557 void fw_core_remove_card(struct fw_card *card)
30558 {
30559 - struct fw_card_driver dummy_driver = dummy_driver_template;
30560 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30561
30562 card->driver->update_phy_reg(card, 4,
30563 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30564 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30565 index f8d2287..5aaf4db 100644
30566 --- a/drivers/firewire/core-cdev.c
30567 +++ b/drivers/firewire/core-cdev.c
30568 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30569 int ret;
30570
30571 if ((request->channels == 0 && request->bandwidth == 0) ||
30572 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30573 - request->bandwidth < 0)
30574 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30575 return -EINVAL;
30576
30577 r = kmalloc(sizeof(*r), GFP_KERNEL);
30578 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30579 index 87d6f2d..5bf9d90 100644
30580 --- a/drivers/firewire/core-transaction.c
30581 +++ b/drivers/firewire/core-transaction.c
30582 @@ -37,6 +37,7 @@
30583 #include <linux/timer.h>
30584 #include <linux/types.h>
30585 #include <linux/workqueue.h>
30586 +#include <linux/sched.h>
30587
30588 #include <asm/byteorder.h>
30589
30590 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30591 index 515a42c..5ecf3ba 100644
30592 --- a/drivers/firewire/core.h
30593 +++ b/drivers/firewire/core.h
30594 @@ -111,6 +111,7 @@ struct fw_card_driver {
30595
30596 int (*stop_iso)(struct fw_iso_context *ctx);
30597 };
30598 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30599
30600 void fw_card_initialize(struct fw_card *card,
30601 const struct fw_card_driver *driver, struct device *device);
30602 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30603 index b298158..7ed8432 100644
30604 --- a/drivers/firmware/dmi_scan.c
30605 +++ b/drivers/firmware/dmi_scan.c
30606 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30607 }
30608 }
30609 else {
30610 - /*
30611 - * no iounmap() for that ioremap(); it would be a no-op, but
30612 - * it's so early in setup that sucker gets confused into doing
30613 - * what it shouldn't if we actually call it.
30614 - */
30615 p = dmi_ioremap(0xF0000, 0x10000);
30616 if (p == NULL)
30617 goto error;
30618 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30619 if (buf == NULL)
30620 return -1;
30621
30622 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30623 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30624
30625 iounmap(buf);
30626 return 0;
30627 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30628 index 82d5c20..44a7177 100644
30629 --- a/drivers/gpio/gpio-vr41xx.c
30630 +++ b/drivers/gpio/gpio-vr41xx.c
30631 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30632 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30633 maskl, pendl, maskh, pendh);
30634
30635 - atomic_inc(&irq_err_count);
30636 + atomic_inc_unchecked(&irq_err_count);
30637
30638 return -EINVAL;
30639 }
30640 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30641 index 3252e70..b5314ace 100644
30642 --- a/drivers/gpu/drm/drm_crtc_helper.c
30643 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30644 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30645 struct drm_crtc *tmp;
30646 int crtc_mask = 1;
30647
30648 - WARN(!crtc, "checking null crtc?\n");
30649 + BUG_ON(!crtc);
30650
30651 dev = crtc->dev;
30652
30653 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30654 index 9238de4..a27c72a 100644
30655 --- a/drivers/gpu/drm/drm_drv.c
30656 +++ b/drivers/gpu/drm/drm_drv.c
30657 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30658 /**
30659 * Copy and IOCTL return string to user space
30660 */
30661 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30662 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30663 {
30664 int len;
30665
30666 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30667 return -ENODEV;
30668
30669 atomic_inc(&dev->ioctl_count);
30670 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30671 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30672 ++file_priv->ioctl_count;
30673
30674 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30675 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30676 index 7aff5c7..bee6c27 100644
30677 --- a/drivers/gpu/drm/drm_fops.c
30678 +++ b/drivers/gpu/drm/drm_fops.c
30679 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30680 }
30681
30682 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30683 - atomic_set(&dev->counts[i], 0);
30684 + atomic_set_unchecked(&dev->counts[i], 0);
30685
30686 dev->sigdata.lock = NULL;
30687
30688 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
30689 if (drm_device_is_unplugged(dev))
30690 return -ENODEV;
30691
30692 - if (!dev->open_count++)
30693 + if (local_inc_return(&dev->open_count) == 1)
30694 need_setup = 1;
30695 mutex_lock(&dev->struct_mutex);
30696 old_mapping = dev->dev_mapping;
30697 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
30698 retcode = drm_open_helper(inode, filp, dev);
30699 if (retcode)
30700 goto err_undo;
30701 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30702 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30703 if (need_setup) {
30704 retcode = drm_setup(dev);
30705 if (retcode)
30706 @@ -164,7 +164,7 @@ err_undo:
30707 iput(container_of(dev->dev_mapping, struct inode, i_data));
30708 dev->dev_mapping = old_mapping;
30709 mutex_unlock(&dev->struct_mutex);
30710 - dev->open_count--;
30711 + local_dec(&dev->open_count);
30712 return retcode;
30713 }
30714 EXPORT_SYMBOL(drm_open);
30715 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
30716
30717 mutex_lock(&drm_global_mutex);
30718
30719 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30720 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30721
30722 if (dev->driver->preclose)
30723 dev->driver->preclose(dev, file_priv);
30724 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
30725 * Begin inline drm_release
30726 */
30727
30728 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30729 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30730 task_pid_nr(current),
30731 (long)old_encode_dev(file_priv->minor->device),
30732 - dev->open_count);
30733 + local_read(&dev->open_count));
30734
30735 /* Release any auth tokens that might point to this file_priv,
30736 (do that under the drm_global_mutex) */
30737 @@ -546,8 +546,8 @@ int drm_release(struct inode *inode, struct file *filp)
30738 * End inline drm_release
30739 */
30740
30741 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30742 - if (!--dev->open_count) {
30743 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30744 + if (local_dec_and_test(&dev->open_count)) {
30745 if (atomic_read(&dev->ioctl_count)) {
30746 DRM_ERROR("Device busy: %d\n",
30747 atomic_read(&dev->ioctl_count));
30748 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30749 index c87dc96..326055d 100644
30750 --- a/drivers/gpu/drm/drm_global.c
30751 +++ b/drivers/gpu/drm/drm_global.c
30752 @@ -36,7 +36,7 @@
30753 struct drm_global_item {
30754 struct mutex mutex;
30755 void *object;
30756 - int refcount;
30757 + atomic_t refcount;
30758 };
30759
30760 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30761 @@ -49,7 +49,7 @@ void drm_global_init(void)
30762 struct drm_global_item *item = &glob[i];
30763 mutex_init(&item->mutex);
30764 item->object = NULL;
30765 - item->refcount = 0;
30766 + atomic_set(&item->refcount, 0);
30767 }
30768 }
30769
30770 @@ -59,7 +59,7 @@ void drm_global_release(void)
30771 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30772 struct drm_global_item *item = &glob[i];
30773 BUG_ON(item->object != NULL);
30774 - BUG_ON(item->refcount != 0);
30775 + BUG_ON(atomic_read(&item->refcount) != 0);
30776 }
30777 }
30778
30779 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30780 void *object;
30781
30782 mutex_lock(&item->mutex);
30783 - if (item->refcount == 0) {
30784 + if (atomic_read(&item->refcount) == 0) {
30785 item->object = kzalloc(ref->size, GFP_KERNEL);
30786 if (unlikely(item->object == NULL)) {
30787 ret = -ENOMEM;
30788 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30789 goto out_err;
30790
30791 }
30792 - ++item->refcount;
30793 + atomic_inc(&item->refcount);
30794 ref->object = item->object;
30795 object = item->object;
30796 mutex_unlock(&item->mutex);
30797 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30798 struct drm_global_item *item = &glob[ref->global_type];
30799
30800 mutex_lock(&item->mutex);
30801 - BUG_ON(item->refcount == 0);
30802 + BUG_ON(atomic_read(&item->refcount) == 0);
30803 BUG_ON(ref->object != item->object);
30804 - if (--item->refcount == 0) {
30805 + if (atomic_dec_and_test(&item->refcount)) {
30806 ref->release(ref);
30807 item->object = NULL;
30808 }
30809 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30810 index 8928edb..0c79258 100644
30811 --- a/drivers/gpu/drm/drm_info.c
30812 +++ b/drivers/gpu/drm/drm_info.c
30813 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30814 struct drm_local_map *map;
30815 struct drm_map_list *r_list;
30816
30817 - /* Hardcoded from _DRM_FRAME_BUFFER,
30818 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30819 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30820 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30821 + static const char * const types[] = {
30822 + [_DRM_FRAME_BUFFER] = "FB",
30823 + [_DRM_REGISTERS] = "REG",
30824 + [_DRM_SHM] = "SHM",
30825 + [_DRM_AGP] = "AGP",
30826 + [_DRM_SCATTER_GATHER] = "SG",
30827 + [_DRM_CONSISTENT] = "PCI",
30828 + [_DRM_GEM] = "GEM" };
30829 const char *type;
30830 int i;
30831
30832 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30833 map = r_list->map;
30834 if (!map)
30835 continue;
30836 - if (map->type < 0 || map->type > 5)
30837 + if (map->type >= ARRAY_SIZE(types))
30838 type = "??";
30839 else
30840 type = types[map->type];
30841 @@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30842 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30843 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30844 vma->vm_flags & VM_IO ? 'i' : '-',
30845 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30846 + 0);
30847 +#else
30848 vma->vm_pgoff);
30849 +#endif
30850
30851 #if defined(__i386__)
30852 pgprot = pgprot_val(vma->vm_page_prot);
30853 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30854 index 637fcc3..e890b33 100644
30855 --- a/drivers/gpu/drm/drm_ioc32.c
30856 +++ b/drivers/gpu/drm/drm_ioc32.c
30857 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30858 request = compat_alloc_user_space(nbytes);
30859 if (!access_ok(VERIFY_WRITE, request, nbytes))
30860 return -EFAULT;
30861 - list = (struct drm_buf_desc *) (request + 1);
30862 + list = (struct drm_buf_desc __user *) (request + 1);
30863
30864 if (__put_user(count, &request->count)
30865 || __put_user(list, &request->list))
30866 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30867 request = compat_alloc_user_space(nbytes);
30868 if (!access_ok(VERIFY_WRITE, request, nbytes))
30869 return -EFAULT;
30870 - list = (struct drm_buf_pub *) (request + 1);
30871 + list = (struct drm_buf_pub __user *) (request + 1);
30872
30873 if (__put_user(count, &request->count)
30874 || __put_user(list, &request->list))
30875 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30876 index 64a62c6..ceab35e 100644
30877 --- a/drivers/gpu/drm/drm_ioctl.c
30878 +++ b/drivers/gpu/drm/drm_ioctl.c
30879 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30880 stats->data[i].value =
30881 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30882 else
30883 - stats->data[i].value = atomic_read(&dev->counts[i]);
30884 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30885 stats->data[i].type = dev->types[i];
30886 }
30887
30888 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30889 index 3203955..c8090af 100644
30890 --- a/drivers/gpu/drm/drm_lock.c
30891 +++ b/drivers/gpu/drm/drm_lock.c
30892 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30893 if (drm_lock_take(&master->lock, lock->context)) {
30894 master->lock.file_priv = file_priv;
30895 master->lock.lock_time = jiffies;
30896 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30897 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30898 break; /* Got lock */
30899 }
30900
30901 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30902 return -EINVAL;
30903 }
30904
30905 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30906 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30907
30908 if (drm_lock_free(&master->lock, lock->context)) {
30909 /* FIXME: Should really bail out here. */
30910 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30911 index 21bcd4a..8e074e0 100644
30912 --- a/drivers/gpu/drm/drm_stub.c
30913 +++ b/drivers/gpu/drm/drm_stub.c
30914 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30915
30916 drm_device_set_unplugged(dev);
30917
30918 - if (dev->open_count == 0) {
30919 + if (local_read(&dev->open_count) == 0) {
30920 drm_put_dev(dev);
30921 }
30922 mutex_unlock(&drm_global_mutex);
30923 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30924 index 463ec68..f5bd2b5 100644
30925 --- a/drivers/gpu/drm/i810/i810_dma.c
30926 +++ b/drivers/gpu/drm/i810/i810_dma.c
30927 @@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30928 dma->buflist[vertex->idx],
30929 vertex->discard, vertex->used);
30930
30931 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30932 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30933 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30934 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30935 sarea_priv->last_enqueue = dev_priv->counter - 1;
30936 sarea_priv->last_dispatch = (int)hw_status[5];
30937
30938 @@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30939 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30940 mc->last_render);
30941
30942 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30943 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30944 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30945 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30946 sarea_priv->last_enqueue = dev_priv->counter - 1;
30947 sarea_priv->last_dispatch = (int)hw_status[5];
30948
30949 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30950 index 6e0acad..93c8289 100644
30951 --- a/drivers/gpu/drm/i810/i810_drv.h
30952 +++ b/drivers/gpu/drm/i810/i810_drv.h
30953 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30954 int page_flipping;
30955
30956 wait_queue_head_t irq_queue;
30957 - atomic_t irq_received;
30958 - atomic_t irq_emitted;
30959 + atomic_unchecked_t irq_received;
30960 + atomic_unchecked_t irq_emitted;
30961
30962 int front_offset;
30963 } drm_i810_private_t;
30964 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30965 index 359f6e8..ada68fd 100644
30966 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30967 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30968 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30969 I915_READ(GTIMR));
30970 }
30971 seq_printf(m, "Interrupts received: %d\n",
30972 - atomic_read(&dev_priv->irq_received));
30973 + atomic_read_unchecked(&dev_priv->irq_received));
30974 for (i = 0; i < I915_NUM_RINGS; i++) {
30975 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30976 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30977 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30978 index 0969a7c..b9ffa45 100644
30979 --- a/drivers/gpu/drm/i915/i915_dma.c
30980 +++ b/drivers/gpu/drm/i915/i915_dma.c
30981 @@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30982 bool can_switch;
30983
30984 spin_lock(&dev->count_lock);
30985 - can_switch = (dev->open_count == 0);
30986 + can_switch = (local_read(&dev->open_count) == 0);
30987 spin_unlock(&dev->count_lock);
30988 return can_switch;
30989 }
30990 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30991 index 627fe35..c9a7346 100644
30992 --- a/drivers/gpu/drm/i915/i915_drv.h
30993 +++ b/drivers/gpu/drm/i915/i915_drv.h
30994 @@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30995 /* render clock increase/decrease */
30996 /* display clock increase/decrease */
30997 /* pll clock increase/decrease */
30998 -};
30999 +} __no_const;
31000
31001 struct drm_i915_gt_funcs {
31002 void (*force_wake_get)(struct drm_i915_private *dev_priv);
31003 void (*force_wake_put)(struct drm_i915_private *dev_priv);
31004 -};
31005 +} __no_const;
31006
31007 struct intel_device_info {
31008 u8 gen;
31009 @@ -408,7 +408,7 @@ typedef struct drm_i915_private {
31010 int current_page;
31011 int page_flipping;
31012
31013 - atomic_t irq_received;
31014 + atomic_unchecked_t irq_received;
31015
31016 /* protects the irq masks */
31017 spinlock_t irq_lock;
31018 @@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
31019 * will be page flipped away on the next vblank. When it
31020 * reaches 0, dev_priv->pending_flip_queue will be woken up.
31021 */
31022 - atomic_t pending_flip;
31023 + atomic_unchecked_t pending_flip;
31024 };
31025
31026 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
31027 @@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
31028 struct drm_i915_private *dev_priv, unsigned port);
31029 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
31030 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
31031 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
31032 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
31033 {
31034 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
31035 }
31036 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31037 index cdf46b5..e785624 100644
31038 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31039 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31040 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
31041 i915_gem_clflush_object(obj);
31042
31043 if (obj->base.pending_write_domain)
31044 - cd->flips |= atomic_read(&obj->pending_flip);
31045 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
31046
31047 /* The actual obj->write_domain will be updated with
31048 * pending_write_domain after we emit the accumulated flush for all
31049 @@ -907,9 +907,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
31050
31051 static int
31052 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
31053 - int count)
31054 + unsigned int count)
31055 {
31056 - int i;
31057 + unsigned int i;
31058
31059 for (i = 0; i < count; i++) {
31060 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
31061 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
31062 index 73fa3e1..ab2e9b9 100644
31063 --- a/drivers/gpu/drm/i915/i915_irq.c
31064 +++ b/drivers/gpu/drm/i915/i915_irq.c
31065 @@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
31066 u32 pipe_stats[I915_MAX_PIPES];
31067 bool blc_event;
31068
31069 - atomic_inc(&dev_priv->irq_received);
31070 + atomic_inc_unchecked(&dev_priv->irq_received);
31071
31072 while (true) {
31073 iir = I915_READ(VLV_IIR);
31074 @@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
31075 irqreturn_t ret = IRQ_NONE;
31076 int i;
31077
31078 - atomic_inc(&dev_priv->irq_received);
31079 + atomic_inc_unchecked(&dev_priv->irq_received);
31080
31081 /* disable master interrupt before clearing iir */
31082 de_ier = I915_READ(DEIER);
31083 @@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
31084 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
31085 u32 hotplug_mask;
31086
31087 - atomic_inc(&dev_priv->irq_received);
31088 + atomic_inc_unchecked(&dev_priv->irq_received);
31089
31090 /* disable master interrupt before clearing iir */
31091 de_ier = I915_READ(DEIER);
31092 @@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
31093 {
31094 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31095
31096 - atomic_set(&dev_priv->irq_received, 0);
31097 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31098
31099 I915_WRITE(HWSTAM, 0xeffe);
31100
31101 @@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
31102 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31103 int pipe;
31104
31105 - atomic_set(&dev_priv->irq_received, 0);
31106 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31107
31108 /* VLV magic */
31109 I915_WRITE(VLV_IMR, 0);
31110 @@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
31111 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31112 int pipe;
31113
31114 - atomic_set(&dev_priv->irq_received, 0);
31115 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31116
31117 for_each_pipe(pipe)
31118 I915_WRITE(PIPESTAT(pipe), 0);
31119 @@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
31120 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
31121 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
31122
31123 - atomic_inc(&dev_priv->irq_received);
31124 + atomic_inc_unchecked(&dev_priv->irq_received);
31125
31126 iir = I915_READ16(IIR);
31127 if (iir == 0)
31128 @@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
31129 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31130 int pipe;
31131
31132 - atomic_set(&dev_priv->irq_received, 0);
31133 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31134
31135 if (I915_HAS_HOTPLUG(dev)) {
31136 I915_WRITE(PORT_HOTPLUG_EN, 0);
31137 @@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
31138 };
31139 int pipe, ret = IRQ_NONE;
31140
31141 - atomic_inc(&dev_priv->irq_received);
31142 + atomic_inc_unchecked(&dev_priv->irq_received);
31143
31144 iir = I915_READ(IIR);
31145 do {
31146 @@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
31147 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31148 int pipe;
31149
31150 - atomic_set(&dev_priv->irq_received, 0);
31151 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31152
31153 I915_WRITE(PORT_HOTPLUG_EN, 0);
31154 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
31155 @@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
31156 int irq_received;
31157 int ret = IRQ_NONE, pipe;
31158
31159 - atomic_inc(&dev_priv->irq_received);
31160 + atomic_inc_unchecked(&dev_priv->irq_received);
31161
31162 iir = I915_READ(IIR);
31163
31164 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
31165 index b634f6f..43c62f5 100644
31166 --- a/drivers/gpu/drm/i915/intel_display.c
31167 +++ b/drivers/gpu/drm/i915/intel_display.c
31168 @@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
31169
31170 wait_event(dev_priv->pending_flip_queue,
31171 atomic_read(&dev_priv->mm.wedged) ||
31172 - atomic_read(&obj->pending_flip) == 0);
31173 + atomic_read_unchecked(&obj->pending_flip) == 0);
31174
31175 /* Big Hammer, we also need to ensure that any pending
31176 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
31177 @@ -6168,8 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
31178
31179 obj = work->old_fb_obj;
31180
31181 - atomic_clear_mask(1 << intel_crtc->plane,
31182 - &obj->pending_flip.counter);
31183 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
31184
31185 wake_up(&dev_priv->pending_flip_queue);
31186 schedule_work(&work->work);
31187 @@ -6515,7 +6514,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31188 /* Block clients from rendering to the new back buffer until
31189 * the flip occurs and the object is no longer visible.
31190 */
31191 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31192 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31193
31194 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
31195 if (ret)
31196 @@ -6530,7 +6529,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31197 return 0;
31198
31199 cleanup_pending:
31200 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31201 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31202 drm_gem_object_unreference(&work->old_fb_obj->base);
31203 drm_gem_object_unreference(&obj->base);
31204 mutex_unlock(&dev->struct_mutex);
31205 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
31206 index 54558a0..2d97005 100644
31207 --- a/drivers/gpu/drm/mga/mga_drv.h
31208 +++ b/drivers/gpu/drm/mga/mga_drv.h
31209 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
31210 u32 clear_cmd;
31211 u32 maccess;
31212
31213 - atomic_t vbl_received; /**< Number of vblanks received. */
31214 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
31215 wait_queue_head_t fence_queue;
31216 - atomic_t last_fence_retired;
31217 + atomic_unchecked_t last_fence_retired;
31218 u32 next_fence_to_post;
31219
31220 unsigned int fb_cpp;
31221 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
31222 index 2581202..f230a8d9 100644
31223 --- a/drivers/gpu/drm/mga/mga_irq.c
31224 +++ b/drivers/gpu/drm/mga/mga_irq.c
31225 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
31226 if (crtc != 0)
31227 return 0;
31228
31229 - return atomic_read(&dev_priv->vbl_received);
31230 + return atomic_read_unchecked(&dev_priv->vbl_received);
31231 }
31232
31233
31234 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31235 /* VBLANK interrupt */
31236 if (status & MGA_VLINEPEN) {
31237 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
31238 - atomic_inc(&dev_priv->vbl_received);
31239 + atomic_inc_unchecked(&dev_priv->vbl_received);
31240 drm_handle_vblank(dev, 0);
31241 handled = 1;
31242 }
31243 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31244 if ((prim_start & ~0x03) != (prim_end & ~0x03))
31245 MGA_WRITE(MGA_PRIMEND, prim_end);
31246
31247 - atomic_inc(&dev_priv->last_fence_retired);
31248 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
31249 DRM_WAKEUP(&dev_priv->fence_queue);
31250 handled = 1;
31251 }
31252 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
31253 * using fences.
31254 */
31255 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
31256 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
31257 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
31258 - *sequence) <= (1 << 23)));
31259
31260 *sequence = cur_fence;
31261 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
31262 index a0a3fe3..209bf10 100644
31263 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
31264 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
31265 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
31266 struct bit_table {
31267 const char id;
31268 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
31269 -};
31270 +} __no_const;
31271
31272 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
31273
31274 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
31275 index 4f2cc95..9c6c510 100644
31276 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
31277 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
31278 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
31279 u32 handle, u16 class);
31280 void (*set_tile_region)(struct drm_device *dev, int i);
31281 void (*tlb_flush)(struct drm_device *, int engine);
31282 -};
31283 +} __no_const;
31284
31285 struct nouveau_instmem_engine {
31286 void *priv;
31287 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
31288 struct nouveau_mc_engine {
31289 int (*init)(struct drm_device *dev);
31290 void (*takedown)(struct drm_device *dev);
31291 -};
31292 +} __no_const;
31293
31294 struct nouveau_timer_engine {
31295 int (*init)(struct drm_device *dev);
31296 void (*takedown)(struct drm_device *dev);
31297 uint64_t (*read)(struct drm_device *dev);
31298 -};
31299 +} __no_const;
31300
31301 struct nouveau_fb_engine {
31302 int num_tiles;
31303 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
31304 void (*put)(struct drm_device *, struct nouveau_mem **);
31305
31306 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
31307 -};
31308 +} __no_const;
31309
31310 struct nouveau_engine {
31311 struct nouveau_instmem_engine instmem;
31312 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
31313 struct drm_global_reference mem_global_ref;
31314 struct ttm_bo_global_ref bo_global_ref;
31315 struct ttm_bo_device bdev;
31316 - atomic_t validate_sequence;
31317 + atomic_unchecked_t validate_sequence;
31318 int (*move)(struct nouveau_channel *,
31319 struct ttm_buffer_object *,
31320 struct ttm_mem_reg *, struct ttm_mem_reg *);
31321 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
31322 index af7cfb8..aadc2a3 100644
31323 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
31324 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
31325 @@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
31326 int trycnt = 0;
31327 int ret, i;
31328
31329 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
31330 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
31331 retry:
31332 if (++trycnt > 100000) {
31333 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
31334 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
31335 index f5e9584..05934ba 100644
31336 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
31337 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
31338 @@ -492,7 +492,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31339 bool can_switch;
31340
31341 spin_lock(&dev->count_lock);
31342 - can_switch = (dev->open_count == 0);
31343 + can_switch = (local_read(&dev->open_count) == 0);
31344 spin_unlock(&dev->count_lock);
31345 return can_switch;
31346 }
31347 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31348 index 93240bd..c490f60 100644
31349 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31350 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31351 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31352 }
31353
31354 if (nv_encoder->dcb->type == OUTPUT_DP) {
31355 - struct dp_train_func func = {
31356 + static struct dp_train_func func = {
31357 .link_set = nv50_sor_dp_link_set,
31358 .train_set = nv50_sor_dp_train_set,
31359 .train_adj = nv50_sor_dp_train_adj
31360 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31361 index 8a2fc89..3a5cf40 100644
31362 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31363 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31364 @@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31365 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31366
31367 if (nv_encoder->dcb->type == OUTPUT_DP) {
31368 - struct dp_train_func func = {
31369 + static struct dp_train_func func = {
31370 .link_set = nvd0_sor_dp_link_set,
31371 .train_set = nvd0_sor_dp_train_set,
31372 .train_adj = nvd0_sor_dp_train_adj
31373 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31374 index bcac90b..53bfc76 100644
31375 --- a/drivers/gpu/drm/r128/r128_cce.c
31376 +++ b/drivers/gpu/drm/r128/r128_cce.c
31377 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31378
31379 /* GH: Simple idle check.
31380 */
31381 - atomic_set(&dev_priv->idle_count, 0);
31382 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31383
31384 /* We don't support anything other than bus-mastering ring mode,
31385 * but the ring can be in either AGP or PCI space for the ring
31386 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31387 index 930c71b..499aded 100644
31388 --- a/drivers/gpu/drm/r128/r128_drv.h
31389 +++ b/drivers/gpu/drm/r128/r128_drv.h
31390 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31391 int is_pci;
31392 unsigned long cce_buffers_offset;
31393
31394 - atomic_t idle_count;
31395 + atomic_unchecked_t idle_count;
31396
31397 int page_flipping;
31398 int current_page;
31399 u32 crtc_offset;
31400 u32 crtc_offset_cntl;
31401
31402 - atomic_t vbl_received;
31403 + atomic_unchecked_t vbl_received;
31404
31405 u32 color_fmt;
31406 unsigned int front_offset;
31407 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31408 index 429d5a0..7e899ed 100644
31409 --- a/drivers/gpu/drm/r128/r128_irq.c
31410 +++ b/drivers/gpu/drm/r128/r128_irq.c
31411 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31412 if (crtc != 0)
31413 return 0;
31414
31415 - return atomic_read(&dev_priv->vbl_received);
31416 + return atomic_read_unchecked(&dev_priv->vbl_received);
31417 }
31418
31419 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31420 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31421 /* VBLANK interrupt */
31422 if (status & R128_CRTC_VBLANK_INT) {
31423 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31424 - atomic_inc(&dev_priv->vbl_received);
31425 + atomic_inc_unchecked(&dev_priv->vbl_received);
31426 drm_handle_vblank(dev, 0);
31427 return IRQ_HANDLED;
31428 }
31429 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31430 index a9e33ce..09edd4b 100644
31431 --- a/drivers/gpu/drm/r128/r128_state.c
31432 +++ b/drivers/gpu/drm/r128/r128_state.c
31433 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31434
31435 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31436 {
31437 - if (atomic_read(&dev_priv->idle_count) == 0)
31438 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31439 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31440 else
31441 - atomic_set(&dev_priv->idle_count, 0);
31442 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31443 }
31444
31445 #endif
31446 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31447 index 5a82b6b..9e69c73 100644
31448 --- a/drivers/gpu/drm/radeon/mkregtable.c
31449 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31450 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31451 regex_t mask_rex;
31452 regmatch_t match[4];
31453 char buf[1024];
31454 - size_t end;
31455 + long end;
31456 int len;
31457 int done = 0;
31458 int r;
31459 unsigned o;
31460 struct offset *offset;
31461 char last_reg_s[10];
31462 - int last_reg;
31463 + unsigned long last_reg;
31464
31465 if (regcomp
31466 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31467 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31468 index 59a1531..3bab49b 100644
31469 --- a/drivers/gpu/drm/radeon/radeon.h
31470 +++ b/drivers/gpu/drm/radeon/radeon.h
31471 @@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31472 int x2, int y2);
31473 void (*draw_auto)(struct radeon_device *rdev);
31474 void (*set_default_state)(struct radeon_device *rdev);
31475 -};
31476 +} __no_const;
31477
31478 struct r600_blit {
31479 struct radeon_bo *shader_obj;
31480 @@ -1216,7 +1216,7 @@ struct radeon_asic {
31481 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31482 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31483 } pflip;
31484 -};
31485 +} __no_const;
31486
31487 /*
31488 * Asic structures
31489 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31490 index 7a3daeb..5016171 100644
31491 --- a/drivers/gpu/drm/radeon/radeon_device.c
31492 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31493 @@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31494 bool can_switch;
31495
31496 spin_lock(&dev->count_lock);
31497 - can_switch = (dev->open_count == 0);
31498 + can_switch = (local_read(&dev->open_count) == 0);
31499 spin_unlock(&dev->count_lock);
31500 return can_switch;
31501 }
31502 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31503 index a1b59ca..86f2d44 100644
31504 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31505 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31506 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31507
31508 /* SW interrupt */
31509 wait_queue_head_t swi_queue;
31510 - atomic_t swi_emitted;
31511 + atomic_unchecked_t swi_emitted;
31512 int vblank_crtc;
31513 uint32_t irq_enable_reg;
31514 uint32_t r500_disp_irq_reg;
31515 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31516 index 48b7cea..342236f 100644
31517 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31518 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31519 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31520 request = compat_alloc_user_space(sizeof(*request));
31521 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31522 || __put_user(req32.param, &request->param)
31523 - || __put_user((void __user *)(unsigned long)req32.value,
31524 + || __put_user((unsigned long)req32.value,
31525 &request->value))
31526 return -EFAULT;
31527
31528 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31529 index 00da384..32f972d 100644
31530 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31531 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31532 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31533 unsigned int ret;
31534 RING_LOCALS;
31535
31536 - atomic_inc(&dev_priv->swi_emitted);
31537 - ret = atomic_read(&dev_priv->swi_emitted);
31538 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31539 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31540
31541 BEGIN_RING(4);
31542 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31543 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31544 drm_radeon_private_t *dev_priv =
31545 (drm_radeon_private_t *) dev->dev_private;
31546
31547 - atomic_set(&dev_priv->swi_emitted, 0);
31548 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31549 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31550
31551 dev->max_vblank_count = 0x001fffff;
31552 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31553 index e8422ae..d22d4a8 100644
31554 --- a/drivers/gpu/drm/radeon/radeon_state.c
31555 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31556 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31557 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31558 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31559
31560 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31561 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31562 sarea_priv->nbox * sizeof(depth_boxes[0])))
31563 return -EFAULT;
31564
31565 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31566 {
31567 drm_radeon_private_t *dev_priv = dev->dev_private;
31568 drm_radeon_getparam_t *param = data;
31569 - int value;
31570 + int value = 0;
31571
31572 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31573
31574 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31575 index 5b71c71..650f9e4 100644
31576 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31577 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31578 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31579 }
31580 if (unlikely(ttm_vm_ops == NULL)) {
31581 ttm_vm_ops = vma->vm_ops;
31582 - radeon_ttm_vm_ops = *ttm_vm_ops;
31583 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31584 + pax_open_kernel();
31585 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31586 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31587 + pax_close_kernel();
31588 }
31589 vma->vm_ops = &radeon_ttm_vm_ops;
31590 return 0;
31591 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31592 index 3b663fc..57850f4 100644
31593 --- a/drivers/gpu/drm/radeon/rs690.c
31594 +++ b/drivers/gpu/drm/radeon/rs690.c
31595 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31596 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31597 rdev->pm.sideport_bandwidth.full)
31598 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31599 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31600 + read_delay_latency.full = dfixed_const(800 * 1000);
31601 read_delay_latency.full = dfixed_div(read_delay_latency,
31602 rdev->pm.igp_sideport_mclk);
31603 + a.full = dfixed_const(370);
31604 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31605 } else {
31606 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31607 rdev->pm.k8_bandwidth.full)
31608 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31609 index ebc6fac..a8313ed 100644
31610 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31611 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31612 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31613 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31614 struct shrink_control *sc)
31615 {
31616 - static atomic_t start_pool = ATOMIC_INIT(0);
31617 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31618 unsigned i;
31619 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31620 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31621 struct ttm_page_pool *pool;
31622 int shrink_pages = sc->nr_to_scan;
31623
31624 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31625 index 88edacc..1e5412b 100644
31626 --- a/drivers/gpu/drm/via/via_drv.h
31627 +++ b/drivers/gpu/drm/via/via_drv.h
31628 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31629 typedef uint32_t maskarray_t[5];
31630
31631 typedef struct drm_via_irq {
31632 - atomic_t irq_received;
31633 + atomic_unchecked_t irq_received;
31634 uint32_t pending_mask;
31635 uint32_t enable_mask;
31636 wait_queue_head_t irq_queue;
31637 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31638 struct timeval last_vblank;
31639 int last_vblank_valid;
31640 unsigned usec_per_vblank;
31641 - atomic_t vbl_received;
31642 + atomic_unchecked_t vbl_received;
31643 drm_via_state_t hc_state;
31644 char pci_buf[VIA_PCI_BUF_SIZE];
31645 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31646 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31647 index d391f48..10c8ca3 100644
31648 --- a/drivers/gpu/drm/via/via_irq.c
31649 +++ b/drivers/gpu/drm/via/via_irq.c
31650 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31651 if (crtc != 0)
31652 return 0;
31653
31654 - return atomic_read(&dev_priv->vbl_received);
31655 + return atomic_read_unchecked(&dev_priv->vbl_received);
31656 }
31657
31658 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31659 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31660
31661 status = VIA_READ(VIA_REG_INTERRUPT);
31662 if (status & VIA_IRQ_VBLANK_PENDING) {
31663 - atomic_inc(&dev_priv->vbl_received);
31664 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31665 + atomic_inc_unchecked(&dev_priv->vbl_received);
31666 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31667 do_gettimeofday(&cur_vblank);
31668 if (dev_priv->last_vblank_valid) {
31669 dev_priv->usec_per_vblank =
31670 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31671 dev_priv->last_vblank = cur_vblank;
31672 dev_priv->last_vblank_valid = 1;
31673 }
31674 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31675 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31676 DRM_DEBUG("US per vblank is: %u\n",
31677 dev_priv->usec_per_vblank);
31678 }
31679 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31680
31681 for (i = 0; i < dev_priv->num_irqs; ++i) {
31682 if (status & cur_irq->pending_mask) {
31683 - atomic_inc(&cur_irq->irq_received);
31684 + atomic_inc_unchecked(&cur_irq->irq_received);
31685 DRM_WAKEUP(&cur_irq->irq_queue);
31686 handled = 1;
31687 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31688 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31689 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31690 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31691 masks[irq][4]));
31692 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31693 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31694 } else {
31695 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31696 (((cur_irq_sequence =
31697 - atomic_read(&cur_irq->irq_received)) -
31698 + atomic_read_unchecked(&cur_irq->irq_received)) -
31699 *sequence) <= (1 << 23)));
31700 }
31701 *sequence = cur_irq_sequence;
31702 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31703 }
31704
31705 for (i = 0; i < dev_priv->num_irqs; ++i) {
31706 - atomic_set(&cur_irq->irq_received, 0);
31707 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31708 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31709 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31710 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31711 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31712 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31713 case VIA_IRQ_RELATIVE:
31714 irqwait->request.sequence +=
31715 - atomic_read(&cur_irq->irq_received);
31716 + atomic_read_unchecked(&cur_irq->irq_received);
31717 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31718 case VIA_IRQ_ABSOLUTE:
31719 break;
31720 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31721 index 29c984f..4084f1a 100644
31722 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31723 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31724 @@ -263,7 +263,7 @@ struct vmw_private {
31725 * Fencing and IRQs.
31726 */
31727
31728 - atomic_t marker_seq;
31729 + atomic_unchecked_t marker_seq;
31730 wait_queue_head_t fence_queue;
31731 wait_queue_head_t fifo_queue;
31732 int fence_queue_waiters; /* Protected by hw_mutex */
31733 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31734 index a0c2f12..68ae6cb 100644
31735 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31736 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31737 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31738 (unsigned int) min,
31739 (unsigned int) fifo->capabilities);
31740
31741 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31742 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31743 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31744 vmw_marker_queue_init(&fifo->marker_queue);
31745 return vmw_fifo_send_fence(dev_priv, &dummy);
31746 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31747 if (reserveable)
31748 iowrite32(bytes, fifo_mem +
31749 SVGA_FIFO_RESERVED);
31750 - return fifo_mem + (next_cmd >> 2);
31751 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31752 } else {
31753 need_bounce = true;
31754 }
31755 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31756
31757 fm = vmw_fifo_reserve(dev_priv, bytes);
31758 if (unlikely(fm == NULL)) {
31759 - *seqno = atomic_read(&dev_priv->marker_seq);
31760 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31761 ret = -ENOMEM;
31762 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31763 false, 3*HZ);
31764 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31765 }
31766
31767 do {
31768 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31769 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31770 } while (*seqno == 0);
31771
31772 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31773 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31774 index cabc95f..14b3d77 100644
31775 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31776 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31777 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31778 * emitted. Then the fence is stale and signaled.
31779 */
31780
31781 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31782 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31783 > VMW_FENCE_WRAP);
31784
31785 return ret;
31786 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31787
31788 if (fifo_idle)
31789 down_read(&fifo_state->rwsem);
31790 - signal_seq = atomic_read(&dev_priv->marker_seq);
31791 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31792 ret = 0;
31793
31794 for (;;) {
31795 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31796 index 8a8725c..afed796 100644
31797 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31798 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31799 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31800 while (!vmw_lag_lt(queue, us)) {
31801 spin_lock(&queue->lock);
31802 if (list_empty(&queue->head))
31803 - seqno = atomic_read(&dev_priv->marker_seq);
31804 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31805 else {
31806 marker = list_first_entry(&queue->head,
31807 struct vmw_marker, head);
31808 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31809 index 5de3bb3..08e5063 100644
31810 --- a/drivers/hid/hid-core.c
31811 +++ b/drivers/hid/hid-core.c
31812 @@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31813
31814 int hid_add_device(struct hid_device *hdev)
31815 {
31816 - static atomic_t id = ATOMIC_INIT(0);
31817 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31818 int ret;
31819
31820 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31821 @@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31822 /* XXX hack, any other cleaner solution after the driver core
31823 * is converted to allow more than 20 bytes as the device name? */
31824 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31825 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31826 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31827
31828 hid_debug_register(hdev, dev_name(&hdev->dev));
31829 ret = device_add(&hdev->dev);
31830 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31831 index eec3291..8ed706b 100644
31832 --- a/drivers/hid/hid-wiimote-debug.c
31833 +++ b/drivers/hid/hid-wiimote-debug.c
31834 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31835 else if (size == 0)
31836 return -EIO;
31837
31838 - if (copy_to_user(u, buf, size))
31839 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31840 return -EFAULT;
31841
31842 *off += size;
31843 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31844 index 14599e2..711c965 100644
31845 --- a/drivers/hid/usbhid/hiddev.c
31846 +++ b/drivers/hid/usbhid/hiddev.c
31847 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31848 break;
31849
31850 case HIDIOCAPPLICATION:
31851 - if (arg < 0 || arg >= hid->maxapplication)
31852 + if (arg >= hid->maxapplication)
31853 break;
31854
31855 for (i = 0; i < hid->maxcollection; i++)
31856 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31857 index f4c3d28..82f45a9 100644
31858 --- a/drivers/hv/channel.c
31859 +++ b/drivers/hv/channel.c
31860 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31861 int ret = 0;
31862 int t;
31863
31864 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31865 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31866 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31867 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31868
31869 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31870 if (ret)
31871 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31872 index 86f8885..ab9cb2b 100644
31873 --- a/drivers/hv/hv.c
31874 +++ b/drivers/hv/hv.c
31875 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31876 u64 output_address = (output) ? virt_to_phys(output) : 0;
31877 u32 output_address_hi = output_address >> 32;
31878 u32 output_address_lo = output_address & 0xFFFFFFFF;
31879 - void *hypercall_page = hv_context.hypercall_page;
31880 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31881
31882 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31883 "=a"(hv_status_lo) : "d" (control_hi),
31884 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31885 index 0614ff3..f0b2b5c 100644
31886 --- a/drivers/hv/hyperv_vmbus.h
31887 +++ b/drivers/hv/hyperv_vmbus.h
31888 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31889 struct vmbus_connection {
31890 enum vmbus_connect_state conn_state;
31891
31892 - atomic_t next_gpadl_handle;
31893 + atomic_unchecked_t next_gpadl_handle;
31894
31895 /*
31896 * Represents channel interrupts. Each bit position represents a
31897 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31898 index 4748086..3abf845 100644
31899 --- a/drivers/hv/vmbus_drv.c
31900 +++ b/drivers/hv/vmbus_drv.c
31901 @@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31902 {
31903 int ret = 0;
31904
31905 - static atomic_t device_num = ATOMIC_INIT(0);
31906 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31907
31908 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31909 - atomic_inc_return(&device_num));
31910 + atomic_inc_return_unchecked(&device_num));
31911
31912 child_device_obj->device.bus = &hv_bus;
31913 child_device_obj->device.parent = &hv_acpi_dev->dev;
31914 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31915 index 8b011d0..3de24a1 100644
31916 --- a/drivers/hwmon/sht15.c
31917 +++ b/drivers/hwmon/sht15.c
31918 @@ -166,7 +166,7 @@ struct sht15_data {
31919 int supply_uV;
31920 bool supply_uV_valid;
31921 struct work_struct update_supply_work;
31922 - atomic_t interrupt_handled;
31923 + atomic_unchecked_t interrupt_handled;
31924 };
31925
31926 /**
31927 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31928 return ret;
31929
31930 gpio_direction_input(data->pdata->gpio_data);
31931 - atomic_set(&data->interrupt_handled, 0);
31932 + atomic_set_unchecked(&data->interrupt_handled, 0);
31933
31934 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31935 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31936 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31937 /* Only relevant if the interrupt hasn't occurred. */
31938 - if (!atomic_read(&data->interrupt_handled))
31939 + if (!atomic_read_unchecked(&data->interrupt_handled))
31940 schedule_work(&data->read_work);
31941 }
31942 ret = wait_event_timeout(data->wait_queue,
31943 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31944
31945 /* First disable the interrupt */
31946 disable_irq_nosync(irq);
31947 - atomic_inc(&data->interrupt_handled);
31948 + atomic_inc_unchecked(&data->interrupt_handled);
31949 /* Then schedule a reading work struct */
31950 if (data->state != SHT15_READING_NOTHING)
31951 schedule_work(&data->read_work);
31952 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31953 * If not, then start the interrupt again - care here as could
31954 * have gone low in meantime so verify it hasn't!
31955 */
31956 - atomic_set(&data->interrupt_handled, 0);
31957 + atomic_set_unchecked(&data->interrupt_handled, 0);
31958 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31959 /* If still not occurred or another handler was scheduled */
31960 if (gpio_get_value(data->pdata->gpio_data)
31961 - || atomic_read(&data->interrupt_handled))
31962 + || atomic_read_unchecked(&data->interrupt_handled))
31963 return;
31964 }
31965
31966 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31967 index 378fcb5..5e91fa8 100644
31968 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31969 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31970 @@ -43,7 +43,7 @@
31971 extern struct i2c_adapter amd756_smbus;
31972
31973 static struct i2c_adapter *s4882_adapter;
31974 -static struct i2c_algorithm *s4882_algo;
31975 +static i2c_algorithm_no_const *s4882_algo;
31976
31977 /* Wrapper access functions for multiplexed SMBus */
31978 static DEFINE_MUTEX(amd756_lock);
31979 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31980 index 29015eb..af2d8e9 100644
31981 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31982 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31983 @@ -41,7 +41,7 @@
31984 extern struct i2c_adapter *nforce2_smbus;
31985
31986 static struct i2c_adapter *s4985_adapter;
31987 -static struct i2c_algorithm *s4985_algo;
31988 +static i2c_algorithm_no_const *s4985_algo;
31989
31990 /* Wrapper access functions for multiplexed SMBus */
31991 static DEFINE_MUTEX(nforce2_lock);
31992 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31993 index 1038c38..eb92f51 100644
31994 --- a/drivers/i2c/i2c-mux.c
31995 +++ b/drivers/i2c/i2c-mux.c
31996 @@ -30,7 +30,7 @@
31997 /* multiplexer per channel data */
31998 struct i2c_mux_priv {
31999 struct i2c_adapter adap;
32000 - struct i2c_algorithm algo;
32001 + i2c_algorithm_no_const algo;
32002
32003 struct i2c_adapter *parent;
32004 void *mux_priv; /* the mux chip/device */
32005 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
32006 index 57d00ca..0145194 100644
32007 --- a/drivers/ide/aec62xx.c
32008 +++ b/drivers/ide/aec62xx.c
32009 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
32010 .cable_detect = atp86x_cable_detect,
32011 };
32012
32013 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
32014 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
32015 { /* 0: AEC6210 */
32016 .name = DRV_NAME,
32017 .init_chipset = init_chipset_aec62xx,
32018 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
32019 index 2c8016a..911a27c 100644
32020 --- a/drivers/ide/alim15x3.c
32021 +++ b/drivers/ide/alim15x3.c
32022 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
32023 .dma_sff_read_status = ide_dma_sff_read_status,
32024 };
32025
32026 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
32027 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
32028 .name = DRV_NAME,
32029 .init_chipset = init_chipset_ali15x3,
32030 .init_hwif = init_hwif_ali15x3,
32031 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
32032 index 3747b25..56fc995 100644
32033 --- a/drivers/ide/amd74xx.c
32034 +++ b/drivers/ide/amd74xx.c
32035 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
32036 .udma_mask = udma, \
32037 }
32038
32039 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
32040 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
32041 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
32042 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
32043 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
32044 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
32045 index 15f0ead..cb43480 100644
32046 --- a/drivers/ide/atiixp.c
32047 +++ b/drivers/ide/atiixp.c
32048 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
32049 .cable_detect = atiixp_cable_detect,
32050 };
32051
32052 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
32053 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
32054 { /* 0: IXP200/300/400/700 */
32055 .name = DRV_NAME,
32056 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
32057 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
32058 index 5f80312..d1fc438 100644
32059 --- a/drivers/ide/cmd64x.c
32060 +++ b/drivers/ide/cmd64x.c
32061 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
32062 .dma_sff_read_status = ide_dma_sff_read_status,
32063 };
32064
32065 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
32066 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
32067 { /* 0: CMD643 */
32068 .name = DRV_NAME,
32069 .init_chipset = init_chipset_cmd64x,
32070 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
32071 index 2c1e5f7..1444762 100644
32072 --- a/drivers/ide/cs5520.c
32073 +++ b/drivers/ide/cs5520.c
32074 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
32075 .set_dma_mode = cs5520_set_dma_mode,
32076 };
32077
32078 -static const struct ide_port_info cyrix_chipset __devinitdata = {
32079 +static const struct ide_port_info cyrix_chipset __devinitconst = {
32080 .name = DRV_NAME,
32081 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
32082 .port_ops = &cs5520_port_ops,
32083 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
32084 index 4dc4eb9..49b40ad 100644
32085 --- a/drivers/ide/cs5530.c
32086 +++ b/drivers/ide/cs5530.c
32087 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
32088 .udma_filter = cs5530_udma_filter,
32089 };
32090
32091 -static const struct ide_port_info cs5530_chipset __devinitdata = {
32092 +static const struct ide_port_info cs5530_chipset __devinitconst = {
32093 .name = DRV_NAME,
32094 .init_chipset = init_chipset_cs5530,
32095 .init_hwif = init_hwif_cs5530,
32096 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
32097 index 5059faf..18d4c85 100644
32098 --- a/drivers/ide/cs5535.c
32099 +++ b/drivers/ide/cs5535.c
32100 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
32101 .cable_detect = cs5535_cable_detect,
32102 };
32103
32104 -static const struct ide_port_info cs5535_chipset __devinitdata = {
32105 +static const struct ide_port_info cs5535_chipset __devinitconst = {
32106 .name = DRV_NAME,
32107 .port_ops = &cs5535_port_ops,
32108 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
32109 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
32110 index 847553f..3ffb49d 100644
32111 --- a/drivers/ide/cy82c693.c
32112 +++ b/drivers/ide/cy82c693.c
32113 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
32114 .set_dma_mode = cy82c693_set_dma_mode,
32115 };
32116
32117 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
32118 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
32119 .name = DRV_NAME,
32120 .init_iops = init_iops_cy82c693,
32121 .port_ops = &cy82c693_port_ops,
32122 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
32123 index 58c51cd..4aec3b8 100644
32124 --- a/drivers/ide/hpt366.c
32125 +++ b/drivers/ide/hpt366.c
32126 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
32127 }
32128 };
32129
32130 -static const struct hpt_info hpt36x __devinitdata = {
32131 +static const struct hpt_info hpt36x __devinitconst = {
32132 .chip_name = "HPT36x",
32133 .chip_type = HPT36x,
32134 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
32135 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
32136 .timings = &hpt36x_timings
32137 };
32138
32139 -static const struct hpt_info hpt370 __devinitdata = {
32140 +static const struct hpt_info hpt370 __devinitconst = {
32141 .chip_name = "HPT370",
32142 .chip_type = HPT370,
32143 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
32144 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
32145 .timings = &hpt37x_timings
32146 };
32147
32148 -static const struct hpt_info hpt370a __devinitdata = {
32149 +static const struct hpt_info hpt370a __devinitconst = {
32150 .chip_name = "HPT370A",
32151 .chip_type = HPT370A,
32152 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
32153 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
32154 .timings = &hpt37x_timings
32155 };
32156
32157 -static const struct hpt_info hpt374 __devinitdata = {
32158 +static const struct hpt_info hpt374 __devinitconst = {
32159 .chip_name = "HPT374",
32160 .chip_type = HPT374,
32161 .udma_mask = ATA_UDMA5,
32162 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
32163 .timings = &hpt37x_timings
32164 };
32165
32166 -static const struct hpt_info hpt372 __devinitdata = {
32167 +static const struct hpt_info hpt372 __devinitconst = {
32168 .chip_name = "HPT372",
32169 .chip_type = HPT372,
32170 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32171 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
32172 .timings = &hpt37x_timings
32173 };
32174
32175 -static const struct hpt_info hpt372a __devinitdata = {
32176 +static const struct hpt_info hpt372a __devinitconst = {
32177 .chip_name = "HPT372A",
32178 .chip_type = HPT372A,
32179 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32180 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
32181 .timings = &hpt37x_timings
32182 };
32183
32184 -static const struct hpt_info hpt302 __devinitdata = {
32185 +static const struct hpt_info hpt302 __devinitconst = {
32186 .chip_name = "HPT302",
32187 .chip_type = HPT302,
32188 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32189 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
32190 .timings = &hpt37x_timings
32191 };
32192
32193 -static const struct hpt_info hpt371 __devinitdata = {
32194 +static const struct hpt_info hpt371 __devinitconst = {
32195 .chip_name = "HPT371",
32196 .chip_type = HPT371,
32197 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32198 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
32199 .timings = &hpt37x_timings
32200 };
32201
32202 -static const struct hpt_info hpt372n __devinitdata = {
32203 +static const struct hpt_info hpt372n __devinitconst = {
32204 .chip_name = "HPT372N",
32205 .chip_type = HPT372N,
32206 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32207 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
32208 .timings = &hpt37x_timings
32209 };
32210
32211 -static const struct hpt_info hpt302n __devinitdata = {
32212 +static const struct hpt_info hpt302n __devinitconst = {
32213 .chip_name = "HPT302N",
32214 .chip_type = HPT302N,
32215 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32216 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
32217 .timings = &hpt37x_timings
32218 };
32219
32220 -static const struct hpt_info hpt371n __devinitdata = {
32221 +static const struct hpt_info hpt371n __devinitconst = {
32222 .chip_name = "HPT371N",
32223 .chip_type = HPT371N,
32224 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32225 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
32226 .dma_sff_read_status = ide_dma_sff_read_status,
32227 };
32228
32229 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
32230 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
32231 { /* 0: HPT36x */
32232 .name = DRV_NAME,
32233 .init_chipset = init_chipset_hpt366,
32234 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
32235 index 8126824..55a2798 100644
32236 --- a/drivers/ide/ide-cd.c
32237 +++ b/drivers/ide/ide-cd.c
32238 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
32239 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
32240 if ((unsigned long)buf & alignment
32241 || blk_rq_bytes(rq) & q->dma_pad_mask
32242 - || object_is_on_stack(buf))
32243 + || object_starts_on_stack(buf))
32244 drive->dma = 0;
32245 }
32246 }
32247 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
32248 index 7f56b73..dab5b67 100644
32249 --- a/drivers/ide/ide-pci-generic.c
32250 +++ b/drivers/ide/ide-pci-generic.c
32251 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
32252 .udma_mask = ATA_UDMA6, \
32253 }
32254
32255 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
32256 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
32257 /* 0: Unknown */
32258 DECLARE_GENERIC_PCI_DEV(0),
32259
32260 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
32261 index 560e66d..d5dd180 100644
32262 --- a/drivers/ide/it8172.c
32263 +++ b/drivers/ide/it8172.c
32264 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
32265 .set_dma_mode = it8172_set_dma_mode,
32266 };
32267
32268 -static const struct ide_port_info it8172_port_info __devinitdata = {
32269 +static const struct ide_port_info it8172_port_info __devinitconst = {
32270 .name = DRV_NAME,
32271 .port_ops = &it8172_port_ops,
32272 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
32273 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
32274 index 46816ba..1847aeb 100644
32275 --- a/drivers/ide/it8213.c
32276 +++ b/drivers/ide/it8213.c
32277 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
32278 .cable_detect = it8213_cable_detect,
32279 };
32280
32281 -static const struct ide_port_info it8213_chipset __devinitdata = {
32282 +static const struct ide_port_info it8213_chipset __devinitconst = {
32283 .name = DRV_NAME,
32284 .enablebits = { {0x41, 0x80, 0x80} },
32285 .port_ops = &it8213_port_ops,
32286 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
32287 index 2e3169f..c5611db 100644
32288 --- a/drivers/ide/it821x.c
32289 +++ b/drivers/ide/it821x.c
32290 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
32291 .cable_detect = it821x_cable_detect,
32292 };
32293
32294 -static const struct ide_port_info it821x_chipset __devinitdata = {
32295 +static const struct ide_port_info it821x_chipset __devinitconst = {
32296 .name = DRV_NAME,
32297 .init_chipset = init_chipset_it821x,
32298 .init_hwif = init_hwif_it821x,
32299 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
32300 index 74c2c4a..efddd7d 100644
32301 --- a/drivers/ide/jmicron.c
32302 +++ b/drivers/ide/jmicron.c
32303 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
32304 .cable_detect = jmicron_cable_detect,
32305 };
32306
32307 -static const struct ide_port_info jmicron_chipset __devinitdata = {
32308 +static const struct ide_port_info jmicron_chipset __devinitconst = {
32309 .name = DRV_NAME,
32310 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
32311 .port_ops = &jmicron_port_ops,
32312 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
32313 index 95327a2..73f78d8 100644
32314 --- a/drivers/ide/ns87415.c
32315 +++ b/drivers/ide/ns87415.c
32316 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
32317 .dma_sff_read_status = superio_dma_sff_read_status,
32318 };
32319
32320 -static const struct ide_port_info ns87415_chipset __devinitdata = {
32321 +static const struct ide_port_info ns87415_chipset __devinitconst = {
32322 .name = DRV_NAME,
32323 .init_hwif = init_hwif_ns87415,
32324 .tp_ops = &ns87415_tp_ops,
32325 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
32326 index 1a53a4c..39edc66 100644
32327 --- a/drivers/ide/opti621.c
32328 +++ b/drivers/ide/opti621.c
32329 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
32330 .set_pio_mode = opti621_set_pio_mode,
32331 };
32332
32333 -static const struct ide_port_info opti621_chipset __devinitdata = {
32334 +static const struct ide_port_info opti621_chipset __devinitconst = {
32335 .name = DRV_NAME,
32336 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
32337 .port_ops = &opti621_port_ops,
32338 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
32339 index 9546fe2..2e5ceb6 100644
32340 --- a/drivers/ide/pdc202xx_new.c
32341 +++ b/drivers/ide/pdc202xx_new.c
32342 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
32343 .udma_mask = udma, \
32344 }
32345
32346 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32347 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32348 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32349 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32350 };
32351 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32352 index 3a35ec6..5634510 100644
32353 --- a/drivers/ide/pdc202xx_old.c
32354 +++ b/drivers/ide/pdc202xx_old.c
32355 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32356 .max_sectors = sectors, \
32357 }
32358
32359 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32360 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32361 { /* 0: PDC20246 */
32362 .name = DRV_NAME,
32363 .init_chipset = init_chipset_pdc202xx,
32364 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32365 index 1892e81..fe0fd60 100644
32366 --- a/drivers/ide/piix.c
32367 +++ b/drivers/ide/piix.c
32368 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32369 .udma_mask = udma, \
32370 }
32371
32372 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32373 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32374 /* 0: MPIIX */
32375 { /*
32376 * MPIIX actually has only a single IDE channel mapped to
32377 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32378 index a6414a8..c04173e 100644
32379 --- a/drivers/ide/rz1000.c
32380 +++ b/drivers/ide/rz1000.c
32381 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32382 }
32383 }
32384
32385 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32386 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32387 .name = DRV_NAME,
32388 .host_flags = IDE_HFLAG_NO_DMA,
32389 };
32390 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32391 index 356b9b5..d4758eb 100644
32392 --- a/drivers/ide/sc1200.c
32393 +++ b/drivers/ide/sc1200.c
32394 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32395 .dma_sff_read_status = ide_dma_sff_read_status,
32396 };
32397
32398 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32399 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32400 .name = DRV_NAME,
32401 .port_ops = &sc1200_port_ops,
32402 .dma_ops = &sc1200_dma_ops,
32403 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32404 index b7f5b0c..9701038 100644
32405 --- a/drivers/ide/scc_pata.c
32406 +++ b/drivers/ide/scc_pata.c
32407 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32408 .dma_sff_read_status = scc_dma_sff_read_status,
32409 };
32410
32411 -static const struct ide_port_info scc_chipset __devinitdata = {
32412 +static const struct ide_port_info scc_chipset __devinitconst = {
32413 .name = "sccIDE",
32414 .init_iops = init_iops_scc,
32415 .init_dma = scc_init_dma,
32416 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32417 index 35fb8da..24d72ef 100644
32418 --- a/drivers/ide/serverworks.c
32419 +++ b/drivers/ide/serverworks.c
32420 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32421 .cable_detect = svwks_cable_detect,
32422 };
32423
32424 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32425 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32426 { /* 0: OSB4 */
32427 .name = DRV_NAME,
32428 .init_chipset = init_chipset_svwks,
32429 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32430 index ddeda44..46f7e30 100644
32431 --- a/drivers/ide/siimage.c
32432 +++ b/drivers/ide/siimage.c
32433 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32434 .udma_mask = ATA_UDMA6, \
32435 }
32436
32437 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32438 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32439 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32440 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32441 };
32442 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32443 index 4a00225..09e61b4 100644
32444 --- a/drivers/ide/sis5513.c
32445 +++ b/drivers/ide/sis5513.c
32446 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32447 .cable_detect = sis_cable_detect,
32448 };
32449
32450 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32451 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32452 .name = DRV_NAME,
32453 .init_chipset = init_chipset_sis5513,
32454 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32455 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32456 index f21dc2a..d051cd2 100644
32457 --- a/drivers/ide/sl82c105.c
32458 +++ b/drivers/ide/sl82c105.c
32459 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32460 .dma_sff_read_status = ide_dma_sff_read_status,
32461 };
32462
32463 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32464 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32465 .name = DRV_NAME,
32466 .init_chipset = init_chipset_sl82c105,
32467 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32468 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32469 index 864ffe0..863a5e9 100644
32470 --- a/drivers/ide/slc90e66.c
32471 +++ b/drivers/ide/slc90e66.c
32472 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32473 .cable_detect = slc90e66_cable_detect,
32474 };
32475
32476 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32477 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32478 .name = DRV_NAME,
32479 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32480 .port_ops = &slc90e66_port_ops,
32481 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32482 index 4799d5c..1794678 100644
32483 --- a/drivers/ide/tc86c001.c
32484 +++ b/drivers/ide/tc86c001.c
32485 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32486 .dma_sff_read_status = ide_dma_sff_read_status,
32487 };
32488
32489 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32490 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32491 .name = DRV_NAME,
32492 .init_hwif = init_hwif_tc86c001,
32493 .port_ops = &tc86c001_port_ops,
32494 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32495 index 281c914..55ce1b8 100644
32496 --- a/drivers/ide/triflex.c
32497 +++ b/drivers/ide/triflex.c
32498 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32499 .set_dma_mode = triflex_set_mode,
32500 };
32501
32502 -static const struct ide_port_info triflex_device __devinitdata = {
32503 +static const struct ide_port_info triflex_device __devinitconst = {
32504 .name = DRV_NAME,
32505 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32506 .port_ops = &triflex_port_ops,
32507 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32508 index 4b42ca0..e494a98 100644
32509 --- a/drivers/ide/trm290.c
32510 +++ b/drivers/ide/trm290.c
32511 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32512 .dma_check = trm290_dma_check,
32513 };
32514
32515 -static const struct ide_port_info trm290_chipset __devinitdata = {
32516 +static const struct ide_port_info trm290_chipset __devinitconst = {
32517 .name = DRV_NAME,
32518 .init_hwif = init_hwif_trm290,
32519 .tp_ops = &trm290_tp_ops,
32520 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32521 index f46f49c..eb77678 100644
32522 --- a/drivers/ide/via82cxxx.c
32523 +++ b/drivers/ide/via82cxxx.c
32524 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32525 .cable_detect = via82cxxx_cable_detect,
32526 };
32527
32528 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32529 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32530 .name = DRV_NAME,
32531 .init_chipset = init_chipset_via82cxxx,
32532 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32533 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32534 index 73d4531..c90cd2d 100644
32535 --- a/drivers/ieee802154/fakehard.c
32536 +++ b/drivers/ieee802154/fakehard.c
32537 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32538 phy->transmit_power = 0xbf;
32539
32540 dev->netdev_ops = &fake_ops;
32541 - dev->ml_priv = &fake_mlme;
32542 + dev->ml_priv = (void *)&fake_mlme;
32543
32544 priv = netdev_priv(dev);
32545 priv->phy = phy;
32546 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32547 index d67999f..4c5d083 100644
32548 --- a/drivers/infiniband/core/cm.c
32549 +++ b/drivers/infiniband/core/cm.c
32550 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32551
32552 struct cm_counter_group {
32553 struct kobject obj;
32554 - atomic_long_t counter[CM_ATTR_COUNT];
32555 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32556 };
32557
32558 struct cm_counter_attribute {
32559 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32560 struct ib_mad_send_buf *msg = NULL;
32561 int ret;
32562
32563 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32564 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32565 counter[CM_REQ_COUNTER]);
32566
32567 /* Quick state check to discard duplicate REQs. */
32568 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32569 if (!cm_id_priv)
32570 return;
32571
32572 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32573 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32574 counter[CM_REP_COUNTER]);
32575 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32576 if (ret)
32577 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32578 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32579 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32580 spin_unlock_irq(&cm_id_priv->lock);
32581 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32582 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32583 counter[CM_RTU_COUNTER]);
32584 goto out;
32585 }
32586 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32587 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32588 dreq_msg->local_comm_id);
32589 if (!cm_id_priv) {
32590 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32591 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32592 counter[CM_DREQ_COUNTER]);
32593 cm_issue_drep(work->port, work->mad_recv_wc);
32594 return -EINVAL;
32595 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32596 case IB_CM_MRA_REP_RCVD:
32597 break;
32598 case IB_CM_TIMEWAIT:
32599 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32600 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32601 counter[CM_DREQ_COUNTER]);
32602 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32603 goto unlock;
32604 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32605 cm_free_msg(msg);
32606 goto deref;
32607 case IB_CM_DREQ_RCVD:
32608 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32609 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32610 counter[CM_DREQ_COUNTER]);
32611 goto unlock;
32612 default:
32613 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32614 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32615 cm_id_priv->msg, timeout)) {
32616 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32617 - atomic_long_inc(&work->port->
32618 + atomic_long_inc_unchecked(&work->port->
32619 counter_group[CM_RECV_DUPLICATES].
32620 counter[CM_MRA_COUNTER]);
32621 goto out;
32622 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32623 break;
32624 case IB_CM_MRA_REQ_RCVD:
32625 case IB_CM_MRA_REP_RCVD:
32626 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32627 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32628 counter[CM_MRA_COUNTER]);
32629 /* fall through */
32630 default:
32631 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32632 case IB_CM_LAP_IDLE:
32633 break;
32634 case IB_CM_MRA_LAP_SENT:
32635 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32636 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32637 counter[CM_LAP_COUNTER]);
32638 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32639 goto unlock;
32640 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32641 cm_free_msg(msg);
32642 goto deref;
32643 case IB_CM_LAP_RCVD:
32644 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32645 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32646 counter[CM_LAP_COUNTER]);
32647 goto unlock;
32648 default:
32649 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32650 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32651 if (cur_cm_id_priv) {
32652 spin_unlock_irq(&cm.lock);
32653 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32654 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32655 counter[CM_SIDR_REQ_COUNTER]);
32656 goto out; /* Duplicate message. */
32657 }
32658 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32659 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32660 msg->retries = 1;
32661
32662 - atomic_long_add(1 + msg->retries,
32663 + atomic_long_add_unchecked(1 + msg->retries,
32664 &port->counter_group[CM_XMIT].counter[attr_index]);
32665 if (msg->retries)
32666 - atomic_long_add(msg->retries,
32667 + atomic_long_add_unchecked(msg->retries,
32668 &port->counter_group[CM_XMIT_RETRIES].
32669 counter[attr_index]);
32670
32671 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32672 }
32673
32674 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32675 - atomic_long_inc(&port->counter_group[CM_RECV].
32676 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32677 counter[attr_id - CM_ATTR_ID_OFFSET]);
32678
32679 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32680 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32681 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32682
32683 return sprintf(buf, "%ld\n",
32684 - atomic_long_read(&group->counter[cm_attr->index]));
32685 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32686 }
32687
32688 static const struct sysfs_ops cm_counter_ops = {
32689 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32690 index 176c8f9..2627b62 100644
32691 --- a/drivers/infiniband/core/fmr_pool.c
32692 +++ b/drivers/infiniband/core/fmr_pool.c
32693 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32694
32695 struct task_struct *thread;
32696
32697 - atomic_t req_ser;
32698 - atomic_t flush_ser;
32699 + atomic_unchecked_t req_ser;
32700 + atomic_unchecked_t flush_ser;
32701
32702 wait_queue_head_t force_wait;
32703 };
32704 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32705 struct ib_fmr_pool *pool = pool_ptr;
32706
32707 do {
32708 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32709 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32710 ib_fmr_batch_release(pool);
32711
32712 - atomic_inc(&pool->flush_ser);
32713 + atomic_inc_unchecked(&pool->flush_ser);
32714 wake_up_interruptible(&pool->force_wait);
32715
32716 if (pool->flush_function)
32717 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32718 }
32719
32720 set_current_state(TASK_INTERRUPTIBLE);
32721 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32722 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32723 !kthread_should_stop())
32724 schedule();
32725 __set_current_state(TASK_RUNNING);
32726 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32727 pool->dirty_watermark = params->dirty_watermark;
32728 pool->dirty_len = 0;
32729 spin_lock_init(&pool->pool_lock);
32730 - atomic_set(&pool->req_ser, 0);
32731 - atomic_set(&pool->flush_ser, 0);
32732 + atomic_set_unchecked(&pool->req_ser, 0);
32733 + atomic_set_unchecked(&pool->flush_ser, 0);
32734 init_waitqueue_head(&pool->force_wait);
32735
32736 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32737 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32738 }
32739 spin_unlock_irq(&pool->pool_lock);
32740
32741 - serial = atomic_inc_return(&pool->req_ser);
32742 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32743 wake_up_process(pool->thread);
32744
32745 if (wait_event_interruptible(pool->force_wait,
32746 - atomic_read(&pool->flush_ser) - serial >= 0))
32747 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32748 return -EINTR;
32749
32750 return 0;
32751 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32752 } else {
32753 list_add_tail(&fmr->list, &pool->dirty_list);
32754 if (++pool->dirty_len >= pool->dirty_watermark) {
32755 - atomic_inc(&pool->req_ser);
32756 + atomic_inc_unchecked(&pool->req_ser);
32757 wake_up_process(pool->thread);
32758 }
32759 }
32760 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32761 index 57e07c6..56d09d4 100644
32762 --- a/drivers/infiniband/hw/cxgb4/mem.c
32763 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32764 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32765 int err;
32766 struct fw_ri_tpte tpt;
32767 u32 stag_idx;
32768 - static atomic_t key;
32769 + static atomic_unchecked_t key;
32770
32771 if (c4iw_fatal_error(rdev))
32772 return -EIO;
32773 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32774 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32775 rdev->stats.stag.max = rdev->stats.stag.cur;
32776 mutex_unlock(&rdev->stats.lock);
32777 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32778 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32779 }
32780 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32781 __func__, stag_state, type, pdid, stag_idx);
32782 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32783 index 79b3dbc..96e5fcc 100644
32784 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32785 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32786 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32787 struct ib_atomic_eth *ateth;
32788 struct ipath_ack_entry *e;
32789 u64 vaddr;
32790 - atomic64_t *maddr;
32791 + atomic64_unchecked_t *maddr;
32792 u64 sdata;
32793 u32 rkey;
32794 u8 next;
32795 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32796 IB_ACCESS_REMOTE_ATOMIC)))
32797 goto nack_acc_unlck;
32798 /* Perform atomic OP and save result. */
32799 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32800 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32801 sdata = be64_to_cpu(ateth->swap_data);
32802 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32803 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32804 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32805 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32806 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32807 be64_to_cpu(ateth->compare_data),
32808 sdata);
32809 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32810 index 1f95bba..9530f87 100644
32811 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32812 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32813 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32814 unsigned long flags;
32815 struct ib_wc wc;
32816 u64 sdata;
32817 - atomic64_t *maddr;
32818 + atomic64_unchecked_t *maddr;
32819 enum ib_wc_status send_status;
32820
32821 /*
32822 @@ -382,11 +382,11 @@ again:
32823 IB_ACCESS_REMOTE_ATOMIC)))
32824 goto acc_err;
32825 /* Perform atomic OP and save result. */
32826 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32827 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32828 sdata = wqe->wr.wr.atomic.compare_add;
32829 *(u64 *) sqp->s_sge.sge.vaddr =
32830 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32831 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32832 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32833 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32834 sdata, wqe->wr.wr.atomic.swap);
32835 goto send_comp;
32836 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32837 index 7140199..da60063 100644
32838 --- a/drivers/infiniband/hw/nes/nes.c
32839 +++ b/drivers/infiniband/hw/nes/nes.c
32840 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32841 LIST_HEAD(nes_adapter_list);
32842 static LIST_HEAD(nes_dev_list);
32843
32844 -atomic_t qps_destroyed;
32845 +atomic_unchecked_t qps_destroyed;
32846
32847 static unsigned int ee_flsh_adapter;
32848 static unsigned int sysfs_nonidx_addr;
32849 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32850 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32851 struct nes_adapter *nesadapter = nesdev->nesadapter;
32852
32853 - atomic_inc(&qps_destroyed);
32854 + atomic_inc_unchecked(&qps_destroyed);
32855
32856 /* Free the control structures */
32857
32858 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32859 index c438e46..ca30356 100644
32860 --- a/drivers/infiniband/hw/nes/nes.h
32861 +++ b/drivers/infiniband/hw/nes/nes.h
32862 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32863 extern unsigned int wqm_quanta;
32864 extern struct list_head nes_adapter_list;
32865
32866 -extern atomic_t cm_connects;
32867 -extern atomic_t cm_accepts;
32868 -extern atomic_t cm_disconnects;
32869 -extern atomic_t cm_closes;
32870 -extern atomic_t cm_connecteds;
32871 -extern atomic_t cm_connect_reqs;
32872 -extern atomic_t cm_rejects;
32873 -extern atomic_t mod_qp_timouts;
32874 -extern atomic_t qps_created;
32875 -extern atomic_t qps_destroyed;
32876 -extern atomic_t sw_qps_destroyed;
32877 +extern atomic_unchecked_t cm_connects;
32878 +extern atomic_unchecked_t cm_accepts;
32879 +extern atomic_unchecked_t cm_disconnects;
32880 +extern atomic_unchecked_t cm_closes;
32881 +extern atomic_unchecked_t cm_connecteds;
32882 +extern atomic_unchecked_t cm_connect_reqs;
32883 +extern atomic_unchecked_t cm_rejects;
32884 +extern atomic_unchecked_t mod_qp_timouts;
32885 +extern atomic_unchecked_t qps_created;
32886 +extern atomic_unchecked_t qps_destroyed;
32887 +extern atomic_unchecked_t sw_qps_destroyed;
32888 extern u32 mh_detected;
32889 extern u32 mh_pauses_sent;
32890 extern u32 cm_packets_sent;
32891 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32892 extern u32 cm_packets_received;
32893 extern u32 cm_packets_dropped;
32894 extern u32 cm_packets_retrans;
32895 -extern atomic_t cm_listens_created;
32896 -extern atomic_t cm_listens_destroyed;
32897 +extern atomic_unchecked_t cm_listens_created;
32898 +extern atomic_unchecked_t cm_listens_destroyed;
32899 extern u32 cm_backlog_drops;
32900 -extern atomic_t cm_loopbacks;
32901 -extern atomic_t cm_nodes_created;
32902 -extern atomic_t cm_nodes_destroyed;
32903 -extern atomic_t cm_accel_dropped_pkts;
32904 -extern atomic_t cm_resets_recvd;
32905 -extern atomic_t pau_qps_created;
32906 -extern atomic_t pau_qps_destroyed;
32907 +extern atomic_unchecked_t cm_loopbacks;
32908 +extern atomic_unchecked_t cm_nodes_created;
32909 +extern atomic_unchecked_t cm_nodes_destroyed;
32910 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32911 +extern atomic_unchecked_t cm_resets_recvd;
32912 +extern atomic_unchecked_t pau_qps_created;
32913 +extern atomic_unchecked_t pau_qps_destroyed;
32914
32915 extern u32 int_mod_timer_init;
32916 extern u32 int_mod_cq_depth_256;
32917 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32918 index 020e95c..fbb3450 100644
32919 --- a/drivers/infiniband/hw/nes/nes_cm.c
32920 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32921 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32922 u32 cm_packets_retrans;
32923 u32 cm_packets_created;
32924 u32 cm_packets_received;
32925 -atomic_t cm_listens_created;
32926 -atomic_t cm_listens_destroyed;
32927 +atomic_unchecked_t cm_listens_created;
32928 +atomic_unchecked_t cm_listens_destroyed;
32929 u32 cm_backlog_drops;
32930 -atomic_t cm_loopbacks;
32931 -atomic_t cm_nodes_created;
32932 -atomic_t cm_nodes_destroyed;
32933 -atomic_t cm_accel_dropped_pkts;
32934 -atomic_t cm_resets_recvd;
32935 +atomic_unchecked_t cm_loopbacks;
32936 +atomic_unchecked_t cm_nodes_created;
32937 +atomic_unchecked_t cm_nodes_destroyed;
32938 +atomic_unchecked_t cm_accel_dropped_pkts;
32939 +atomic_unchecked_t cm_resets_recvd;
32940
32941 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32942 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32943 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32944
32945 static struct nes_cm_core *g_cm_core;
32946
32947 -atomic_t cm_connects;
32948 -atomic_t cm_accepts;
32949 -atomic_t cm_disconnects;
32950 -atomic_t cm_closes;
32951 -atomic_t cm_connecteds;
32952 -atomic_t cm_connect_reqs;
32953 -atomic_t cm_rejects;
32954 +atomic_unchecked_t cm_connects;
32955 +atomic_unchecked_t cm_accepts;
32956 +atomic_unchecked_t cm_disconnects;
32957 +atomic_unchecked_t cm_closes;
32958 +atomic_unchecked_t cm_connecteds;
32959 +atomic_unchecked_t cm_connect_reqs;
32960 +atomic_unchecked_t cm_rejects;
32961
32962 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32963 {
32964 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32965 kfree(listener);
32966 listener = NULL;
32967 ret = 0;
32968 - atomic_inc(&cm_listens_destroyed);
32969 + atomic_inc_unchecked(&cm_listens_destroyed);
32970 } else {
32971 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32972 }
32973 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32974 cm_node->rem_mac);
32975
32976 add_hte_node(cm_core, cm_node);
32977 - atomic_inc(&cm_nodes_created);
32978 + atomic_inc_unchecked(&cm_nodes_created);
32979
32980 return cm_node;
32981 }
32982 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32983 }
32984
32985 atomic_dec(&cm_core->node_cnt);
32986 - atomic_inc(&cm_nodes_destroyed);
32987 + atomic_inc_unchecked(&cm_nodes_destroyed);
32988 nesqp = cm_node->nesqp;
32989 if (nesqp) {
32990 nesqp->cm_node = NULL;
32991 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32992
32993 static void drop_packet(struct sk_buff *skb)
32994 {
32995 - atomic_inc(&cm_accel_dropped_pkts);
32996 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32997 dev_kfree_skb_any(skb);
32998 }
32999
33000 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
33001 {
33002
33003 int reset = 0; /* whether to send reset in case of err.. */
33004 - atomic_inc(&cm_resets_recvd);
33005 + atomic_inc_unchecked(&cm_resets_recvd);
33006 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
33007 " refcnt=%d\n", cm_node, cm_node->state,
33008 atomic_read(&cm_node->ref_count));
33009 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
33010 rem_ref_cm_node(cm_node->cm_core, cm_node);
33011 return NULL;
33012 }
33013 - atomic_inc(&cm_loopbacks);
33014 + atomic_inc_unchecked(&cm_loopbacks);
33015 loopbackremotenode->loopbackpartner = cm_node;
33016 loopbackremotenode->tcp_cntxt.rcv_wscale =
33017 NES_CM_DEFAULT_RCV_WND_SCALE;
33018 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
33019 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
33020 else {
33021 rem_ref_cm_node(cm_core, cm_node);
33022 - atomic_inc(&cm_accel_dropped_pkts);
33023 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
33024 dev_kfree_skb_any(skb);
33025 }
33026 break;
33027 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
33028
33029 if ((cm_id) && (cm_id->event_handler)) {
33030 if (issue_disconn) {
33031 - atomic_inc(&cm_disconnects);
33032 + atomic_inc_unchecked(&cm_disconnects);
33033 cm_event.event = IW_CM_EVENT_DISCONNECT;
33034 cm_event.status = disconn_status;
33035 cm_event.local_addr = cm_id->local_addr;
33036 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
33037 }
33038
33039 if (issue_close) {
33040 - atomic_inc(&cm_closes);
33041 + atomic_inc_unchecked(&cm_closes);
33042 nes_disconnect(nesqp, 1);
33043
33044 cm_id->provider_data = nesqp;
33045 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
33046
33047 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
33048 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
33049 - atomic_inc(&cm_accepts);
33050 + atomic_inc_unchecked(&cm_accepts);
33051
33052 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
33053 netdev_refcnt_read(nesvnic->netdev));
33054 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
33055 struct nes_cm_core *cm_core;
33056 u8 *start_buff;
33057
33058 - atomic_inc(&cm_rejects);
33059 + atomic_inc_unchecked(&cm_rejects);
33060 cm_node = (struct nes_cm_node *)cm_id->provider_data;
33061 loopback = cm_node->loopbackpartner;
33062 cm_core = cm_node->cm_core;
33063 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
33064 ntohl(cm_id->local_addr.sin_addr.s_addr),
33065 ntohs(cm_id->local_addr.sin_port));
33066
33067 - atomic_inc(&cm_connects);
33068 + atomic_inc_unchecked(&cm_connects);
33069 nesqp->active_conn = 1;
33070
33071 /* cache the cm_id in the qp */
33072 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
33073 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
33074 return err;
33075 }
33076 - atomic_inc(&cm_listens_created);
33077 + atomic_inc_unchecked(&cm_listens_created);
33078 }
33079
33080 cm_id->add_ref(cm_id);
33081 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
33082
33083 if (nesqp->destroyed)
33084 return;
33085 - atomic_inc(&cm_connecteds);
33086 + atomic_inc_unchecked(&cm_connecteds);
33087 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
33088 " local port 0x%04X. jiffies = %lu.\n",
33089 nesqp->hwqp.qp_id,
33090 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
33091
33092 cm_id->add_ref(cm_id);
33093 ret = cm_id->event_handler(cm_id, &cm_event);
33094 - atomic_inc(&cm_closes);
33095 + atomic_inc_unchecked(&cm_closes);
33096 cm_event.event = IW_CM_EVENT_CLOSE;
33097 cm_event.status = 0;
33098 cm_event.provider_data = cm_id->provider_data;
33099 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
33100 return;
33101 cm_id = cm_node->cm_id;
33102
33103 - atomic_inc(&cm_connect_reqs);
33104 + atomic_inc_unchecked(&cm_connect_reqs);
33105 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33106 cm_node, cm_id, jiffies);
33107
33108 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
33109 return;
33110 cm_id = cm_node->cm_id;
33111
33112 - atomic_inc(&cm_connect_reqs);
33113 + atomic_inc_unchecked(&cm_connect_reqs);
33114 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33115 cm_node, cm_id, jiffies);
33116
33117 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
33118 index 3ba7be3..c81f6ff 100644
33119 --- a/drivers/infiniband/hw/nes/nes_mgt.c
33120 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
33121 @@ -40,8 +40,8 @@
33122 #include "nes.h"
33123 #include "nes_mgt.h"
33124
33125 -atomic_t pau_qps_created;
33126 -atomic_t pau_qps_destroyed;
33127 +atomic_unchecked_t pau_qps_created;
33128 +atomic_unchecked_t pau_qps_destroyed;
33129
33130 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
33131 {
33132 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
33133 {
33134 struct sk_buff *skb;
33135 unsigned long flags;
33136 - atomic_inc(&pau_qps_destroyed);
33137 + atomic_inc_unchecked(&pau_qps_destroyed);
33138
33139 /* Free packets that have not yet been forwarded */
33140 /* Lock is acquired by skb_dequeue when removing the skb */
33141 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
33142 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
33143 skb_queue_head_init(&nesqp->pau_list);
33144 spin_lock_init(&nesqp->pau_lock);
33145 - atomic_inc(&pau_qps_created);
33146 + atomic_inc_unchecked(&pau_qps_created);
33147 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
33148 }
33149
33150 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
33151 index f3a3ecf..57d311d 100644
33152 --- a/drivers/infiniband/hw/nes/nes_nic.c
33153 +++ b/drivers/infiniband/hw/nes/nes_nic.c
33154 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
33155 target_stat_values[++index] = mh_detected;
33156 target_stat_values[++index] = mh_pauses_sent;
33157 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
33158 - target_stat_values[++index] = atomic_read(&cm_connects);
33159 - target_stat_values[++index] = atomic_read(&cm_accepts);
33160 - target_stat_values[++index] = atomic_read(&cm_disconnects);
33161 - target_stat_values[++index] = atomic_read(&cm_connecteds);
33162 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
33163 - target_stat_values[++index] = atomic_read(&cm_rejects);
33164 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
33165 - target_stat_values[++index] = atomic_read(&qps_created);
33166 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
33167 - target_stat_values[++index] = atomic_read(&qps_destroyed);
33168 - target_stat_values[++index] = atomic_read(&cm_closes);
33169 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
33170 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
33171 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
33172 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
33173 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
33174 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
33175 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
33176 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
33177 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
33178 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
33179 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
33180 target_stat_values[++index] = cm_packets_sent;
33181 target_stat_values[++index] = cm_packets_bounced;
33182 target_stat_values[++index] = cm_packets_created;
33183 target_stat_values[++index] = cm_packets_received;
33184 target_stat_values[++index] = cm_packets_dropped;
33185 target_stat_values[++index] = cm_packets_retrans;
33186 - target_stat_values[++index] = atomic_read(&cm_listens_created);
33187 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
33188 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
33189 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
33190 target_stat_values[++index] = cm_backlog_drops;
33191 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
33192 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
33193 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
33194 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
33195 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
33196 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
33197 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
33198 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
33199 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
33200 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
33201 target_stat_values[++index] = nesadapter->free_4kpbl;
33202 target_stat_values[++index] = nesadapter->free_256pbl;
33203 target_stat_values[++index] = int_mod_timer_init;
33204 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
33205 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
33206 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
33207 - target_stat_values[++index] = atomic_read(&pau_qps_created);
33208 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
33209 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
33210 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
33211 }
33212
33213 /**
33214 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
33215 index 8b8812d..a5e1133 100644
33216 --- a/drivers/infiniband/hw/nes/nes_verbs.c
33217 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
33218 @@ -46,9 +46,9 @@
33219
33220 #include <rdma/ib_umem.h>
33221
33222 -atomic_t mod_qp_timouts;
33223 -atomic_t qps_created;
33224 -atomic_t sw_qps_destroyed;
33225 +atomic_unchecked_t mod_qp_timouts;
33226 +atomic_unchecked_t qps_created;
33227 +atomic_unchecked_t sw_qps_destroyed;
33228
33229 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
33230
33231 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
33232 if (init_attr->create_flags)
33233 return ERR_PTR(-EINVAL);
33234
33235 - atomic_inc(&qps_created);
33236 + atomic_inc_unchecked(&qps_created);
33237 switch (init_attr->qp_type) {
33238 case IB_QPT_RC:
33239 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
33240 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
33241 struct iw_cm_event cm_event;
33242 int ret = 0;
33243
33244 - atomic_inc(&sw_qps_destroyed);
33245 + atomic_inc_unchecked(&sw_qps_destroyed);
33246 nesqp->destroyed = 1;
33247
33248 /* Blow away the connection if it exists. */
33249 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
33250 index 7b1b8669..4b69f85 100644
33251 --- a/drivers/infiniband/hw/qib/qib.h
33252 +++ b/drivers/infiniband/hw/qib/qib.h
33253 @@ -51,6 +51,7 @@
33254 #include <linux/completion.h>
33255 #include <linux/kref.h>
33256 #include <linux/sched.h>
33257 +#include <linux/slab.h>
33258
33259 #include "qib_common.h"
33260 #include "qib_verbs.h"
33261 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
33262 index da739d9..da1c7f4 100644
33263 --- a/drivers/input/gameport/gameport.c
33264 +++ b/drivers/input/gameport/gameport.c
33265 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
33266 */
33267 static void gameport_init_port(struct gameport *gameport)
33268 {
33269 - static atomic_t gameport_no = ATOMIC_INIT(0);
33270 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
33271
33272 __module_get(THIS_MODULE);
33273
33274 mutex_init(&gameport->drv_mutex);
33275 device_initialize(&gameport->dev);
33276 dev_set_name(&gameport->dev, "gameport%lu",
33277 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
33278 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
33279 gameport->dev.bus = &gameport_bus;
33280 gameport->dev.release = gameport_release_port;
33281 if (gameport->parent)
33282 diff --git a/drivers/input/input.c b/drivers/input/input.c
33283 index 8921c61..f5cd63d 100644
33284 --- a/drivers/input/input.c
33285 +++ b/drivers/input/input.c
33286 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
33287 */
33288 int input_register_device(struct input_dev *dev)
33289 {
33290 - static atomic_t input_no = ATOMIC_INIT(0);
33291 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
33292 struct input_handler *handler;
33293 const char *path;
33294 int error;
33295 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
33296 dev->setkeycode = input_default_setkeycode;
33297
33298 dev_set_name(&dev->dev, "input%ld",
33299 - (unsigned long) atomic_inc_return(&input_no) - 1);
33300 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
33301
33302 error = device_add(&dev->dev);
33303 if (error)
33304 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
33305 index 04c69af..5f92d00 100644
33306 --- a/drivers/input/joystick/sidewinder.c
33307 +++ b/drivers/input/joystick/sidewinder.c
33308 @@ -30,6 +30,7 @@
33309 #include <linux/kernel.h>
33310 #include <linux/module.h>
33311 #include <linux/slab.h>
33312 +#include <linux/sched.h>
33313 #include <linux/init.h>
33314 #include <linux/input.h>
33315 #include <linux/gameport.h>
33316 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
33317 index 83811e4..0822b90 100644
33318 --- a/drivers/input/joystick/xpad.c
33319 +++ b/drivers/input/joystick/xpad.c
33320 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
33321
33322 static int xpad_led_probe(struct usb_xpad *xpad)
33323 {
33324 - static atomic_t led_seq = ATOMIC_INIT(0);
33325 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
33326 long led_no;
33327 struct xpad_led *led;
33328 struct led_classdev *led_cdev;
33329 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
33330 if (!led)
33331 return -ENOMEM;
33332
33333 - led_no = (long)atomic_inc_return(&led_seq) - 1;
33334 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
33335
33336 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
33337 led->xpad = xpad;
33338 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
33339 index 0110b5a..d3ad144 100644
33340 --- a/drivers/input/mousedev.c
33341 +++ b/drivers/input/mousedev.c
33342 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33343
33344 spin_unlock_irq(&client->packet_lock);
33345
33346 - if (copy_to_user(buffer, data, count))
33347 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
33348 return -EFAULT;
33349
33350 return count;
33351 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33352 index d0f7533..fb8215b 100644
33353 --- a/drivers/input/serio/serio.c
33354 +++ b/drivers/input/serio/serio.c
33355 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33356 */
33357 static void serio_init_port(struct serio *serio)
33358 {
33359 - static atomic_t serio_no = ATOMIC_INIT(0);
33360 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33361
33362 __module_get(THIS_MODULE);
33363
33364 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33365 mutex_init(&serio->drv_mutex);
33366 device_initialize(&serio->dev);
33367 dev_set_name(&serio->dev, "serio%ld",
33368 - (long)atomic_inc_return(&serio_no) - 1);
33369 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33370 serio->dev.bus = &serio_bus;
33371 serio->dev.release = serio_release_port;
33372 serio->dev.groups = serio_device_attr_groups;
33373 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33374 index 38c4bd8..58965d9 100644
33375 --- a/drivers/isdn/capi/capi.c
33376 +++ b/drivers/isdn/capi/capi.c
33377 @@ -83,8 +83,8 @@ struct capiminor {
33378
33379 struct capi20_appl *ap;
33380 u32 ncci;
33381 - atomic_t datahandle;
33382 - atomic_t msgid;
33383 + atomic_unchecked_t datahandle;
33384 + atomic_unchecked_t msgid;
33385
33386 struct tty_port port;
33387 int ttyinstop;
33388 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33389 capimsg_setu16(s, 2, mp->ap->applid);
33390 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33391 capimsg_setu8 (s, 5, CAPI_RESP);
33392 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33393 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33394 capimsg_setu32(s, 8, mp->ncci);
33395 capimsg_setu16(s, 12, datahandle);
33396 }
33397 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33398 mp->outbytes -= len;
33399 spin_unlock_bh(&mp->outlock);
33400
33401 - datahandle = atomic_inc_return(&mp->datahandle);
33402 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33403 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33404 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33405 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33406 capimsg_setu16(skb->data, 2, mp->ap->applid);
33407 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33408 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33409 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33410 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33411 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33412 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33413 capimsg_setu16(skb->data, 16, len); /* Data length */
33414 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33415 index a6d9fd2..afdb8a3 100644
33416 --- a/drivers/isdn/gigaset/interface.c
33417 +++ b/drivers/isdn/gigaset/interface.c
33418 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33419 }
33420 tty->driver_data = cs;
33421
33422 - ++cs->port.count;
33423 + atomic_inc(&cs->port.count);
33424
33425 - if (cs->port.count == 1) {
33426 + if (atomic_read(&cs->port.count) == 1) {
33427 tty_port_tty_set(&cs->port, tty);
33428 tty->low_latency = 1;
33429 }
33430 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33431
33432 if (!cs->connected)
33433 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33434 - else if (!cs->port.count)
33435 + else if (!atomic_read(&cs->port.count))
33436 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33437 - else if (!--cs->port.count)
33438 + else if (!atomic_dec_return(&cs->port.count))
33439 tty_port_tty_set(&cs->port, NULL);
33440
33441 mutex_unlock(&cs->mutex);
33442 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33443 index 821f7ac..28d4030 100644
33444 --- a/drivers/isdn/hardware/avm/b1.c
33445 +++ b/drivers/isdn/hardware/avm/b1.c
33446 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33447 }
33448 if (left) {
33449 if (t4file->user) {
33450 - if (copy_from_user(buf, dp, left))
33451 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33452 return -EFAULT;
33453 } else {
33454 memcpy(buf, dp, left);
33455 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33456 }
33457 if (left) {
33458 if (config->user) {
33459 - if (copy_from_user(buf, dp, left))
33460 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33461 return -EFAULT;
33462 } else {
33463 memcpy(buf, dp, left);
33464 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33465 index dd6b53a..19d9ee6 100644
33466 --- a/drivers/isdn/hardware/eicon/divasync.h
33467 +++ b/drivers/isdn/hardware/eicon/divasync.h
33468 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33469 } diva_didd_add_adapter_t;
33470 typedef struct _diva_didd_remove_adapter {
33471 IDI_CALL p_request;
33472 -} diva_didd_remove_adapter_t;
33473 +} __no_const diva_didd_remove_adapter_t;
33474 typedef struct _diva_didd_read_adapter_array {
33475 void *buffer;
33476 dword length;
33477 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33478 index d303e65..28bcb7b 100644
33479 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33480 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33481 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33482 typedef struct _diva_os_idi_adapter_interface {
33483 diva_init_card_proc_t cleanup_adapter_proc;
33484 diva_cmd_card_proc_t cmd_proc;
33485 -} diva_os_idi_adapter_interface_t;
33486 +} __no_const diva_os_idi_adapter_interface_t;
33487
33488 typedef struct _diva_os_xdi_adapter {
33489 struct list_head link;
33490 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33491 index 7bc5067..fd36232 100644
33492 --- a/drivers/isdn/i4l/isdn_tty.c
33493 +++ b/drivers/isdn/i4l/isdn_tty.c
33494 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33495 port = &info->port;
33496 #ifdef ISDN_DEBUG_MODEM_OPEN
33497 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33498 - port->count);
33499 + atomic_read(&port->count))
33500 #endif
33501 - port->count++;
33502 + atomic_inc(&port->count);
33503 tty->driver_data = info;
33504 port->tty = tty;
33505 tty->port = port;
33506 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33507 #endif
33508 return;
33509 }
33510 - if ((tty->count == 1) && (port->count != 1)) {
33511 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33512 /*
33513 * Uh, oh. tty->count is 1, which means that the tty
33514 * structure will be freed. Info->count should always
33515 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33516 * serial port won't be shutdown.
33517 */
33518 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33519 - "info->count is %d\n", port->count);
33520 - port->count = 1;
33521 + "info->count is %d\n", atomic_read(&port->count));
33522 + atomic_set(&port->count, 1);
33523 }
33524 - if (--port->count < 0) {
33525 + if (atomic_dec_return(&port->count) < 0) {
33526 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33527 - info->line, port->count);
33528 - port->count = 0;
33529 + info->line, atomic_read(&port->count));
33530 + atomic_set(&port->count, 0);
33531 }
33532 - if (port->count) {
33533 + if (atomic_read(&port->count)) {
33534 #ifdef ISDN_DEBUG_MODEM_OPEN
33535 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33536 #endif
33537 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33538 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33539 return;
33540 isdn_tty_shutdown(info);
33541 - port->count = 0;
33542 + atomic_set(&port->count, 0);
33543 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33544 port->tty = NULL;
33545 wake_up_interruptible(&port->open_wait);
33546 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33547 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33548 modem_info *info = &dev->mdm.info[i];
33549
33550 - if (info->port.count == 0)
33551 + if (atomic_read(&info->port.count) == 0)
33552 continue;
33553 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33554 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33555 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33556 index e74df7c..03a03ba 100644
33557 --- a/drivers/isdn/icn/icn.c
33558 +++ b/drivers/isdn/icn/icn.c
33559 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33560 if (count > len)
33561 count = len;
33562 if (user) {
33563 - if (copy_from_user(msg, buf, count))
33564 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33565 return -EFAULT;
33566 } else
33567 memcpy(msg, buf, count);
33568 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33569 index b5fdcb7..5b6c59f 100644
33570 --- a/drivers/lguest/core.c
33571 +++ b/drivers/lguest/core.c
33572 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33573 * it's worked so far. The end address needs +1 because __get_vm_area
33574 * allocates an extra guard page, so we need space for that.
33575 */
33576 +
33577 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33578 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33579 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33580 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33581 +#else
33582 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33583 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33584 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33585 +#endif
33586 +
33587 if (!switcher_vma) {
33588 err = -ENOMEM;
33589 printk("lguest: could not map switcher pages high\n");
33590 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33591 * Now the Switcher is mapped at the right address, we can't fail!
33592 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33593 */
33594 - memcpy(switcher_vma->addr, start_switcher_text,
33595 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33596 end_switcher_text - start_switcher_text);
33597
33598 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33599 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33600 index 39809035..ce25c5e 100644
33601 --- a/drivers/lguest/x86/core.c
33602 +++ b/drivers/lguest/x86/core.c
33603 @@ -59,7 +59,7 @@ static struct {
33604 /* Offset from where switcher.S was compiled to where we've copied it */
33605 static unsigned long switcher_offset(void)
33606 {
33607 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33608 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33609 }
33610
33611 /* This cpu's struct lguest_pages. */
33612 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33613 * These copies are pretty cheap, so we do them unconditionally: */
33614 /* Save the current Host top-level page directory.
33615 */
33616 +
33617 +#ifdef CONFIG_PAX_PER_CPU_PGD
33618 + pages->state.host_cr3 = read_cr3();
33619 +#else
33620 pages->state.host_cr3 = __pa(current->mm->pgd);
33621 +#endif
33622 +
33623 /*
33624 * Set up the Guest's page tables to see this CPU's pages (and no
33625 * other CPU's pages).
33626 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33627 * compiled-in switcher code and the high-mapped copy we just made.
33628 */
33629 for (i = 0; i < IDT_ENTRIES; i++)
33630 - default_idt_entries[i] += switcher_offset();
33631 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33632
33633 /*
33634 * Set up the Switcher's per-cpu areas.
33635 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33636 * it will be undisturbed when we switch. To change %cs and jump we
33637 * need this structure to feed to Intel's "lcall" instruction.
33638 */
33639 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33640 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33641 lguest_entry.segment = LGUEST_CS;
33642
33643 /*
33644 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33645 index 40634b0..4f5855e 100644
33646 --- a/drivers/lguest/x86/switcher_32.S
33647 +++ b/drivers/lguest/x86/switcher_32.S
33648 @@ -87,6 +87,7 @@
33649 #include <asm/page.h>
33650 #include <asm/segment.h>
33651 #include <asm/lguest.h>
33652 +#include <asm/processor-flags.h>
33653
33654 // We mark the start of the code to copy
33655 // It's placed in .text tho it's never run here
33656 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33657 // Changes type when we load it: damn Intel!
33658 // For after we switch over our page tables
33659 // That entry will be read-only: we'd crash.
33660 +
33661 +#ifdef CONFIG_PAX_KERNEXEC
33662 + mov %cr0, %edx
33663 + xor $X86_CR0_WP, %edx
33664 + mov %edx, %cr0
33665 +#endif
33666 +
33667 movl $(GDT_ENTRY_TSS*8), %edx
33668 ltr %dx
33669
33670 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33671 // Let's clear it again for our return.
33672 // The GDT descriptor of the Host
33673 // Points to the table after two "size" bytes
33674 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33675 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33676 // Clear "used" from type field (byte 5, bit 2)
33677 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33678 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33679 +
33680 +#ifdef CONFIG_PAX_KERNEXEC
33681 + mov %cr0, %eax
33682 + xor $X86_CR0_WP, %eax
33683 + mov %eax, %cr0
33684 +#endif
33685
33686 // Once our page table's switched, the Guest is live!
33687 // The Host fades as we run this final step.
33688 @@ -295,13 +309,12 @@ deliver_to_host:
33689 // I consulted gcc, and it gave
33690 // These instructions, which I gladly credit:
33691 leal (%edx,%ebx,8), %eax
33692 - movzwl (%eax),%edx
33693 - movl 4(%eax), %eax
33694 - xorw %ax, %ax
33695 - orl %eax, %edx
33696 + movl 4(%eax), %edx
33697 + movw (%eax), %dx
33698 // Now the address of the handler's in %edx
33699 // We call it now: its "iret" drops us home.
33700 - jmp *%edx
33701 + ljmp $__KERNEL_CS, $1f
33702 +1: jmp *%edx
33703
33704 // Every interrupt can come to us here
33705 // But we must truly tell each apart.
33706 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33707 index 20e5c2c..9e849a9 100644
33708 --- a/drivers/macintosh/macio_asic.c
33709 +++ b/drivers/macintosh/macio_asic.c
33710 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33711 * MacIO is matched against any Apple ID, it's probe() function
33712 * will then decide wether it applies or not
33713 */
33714 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33715 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33716 .vendor = PCI_VENDOR_ID_APPLE,
33717 .device = PCI_ANY_ID,
33718 .subvendor = PCI_ANY_ID,
33719 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33720 index 94e7f6b..2f4a0d8 100644
33721 --- a/drivers/md/bitmap.c
33722 +++ b/drivers/md/bitmap.c
33723 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33724 chunk_kb ? "KB" : "B");
33725 if (bitmap->storage.file) {
33726 seq_printf(seq, ", file: ");
33727 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33728 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33729 }
33730
33731 seq_printf(seq, "\n");
33732 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33733 index afd9598..528d8f9 100644
33734 --- a/drivers/md/dm-ioctl.c
33735 +++ b/drivers/md/dm-ioctl.c
33736 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33737 cmd == DM_LIST_VERSIONS_CMD)
33738 return 0;
33739
33740 - if ((cmd == DM_DEV_CREATE_CMD)) {
33741 + if (cmd == DM_DEV_CREATE_CMD) {
33742 if (!*param->name) {
33743 DMWARN("name not supplied when creating device");
33744 return -EINVAL;
33745 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33746 index bc5ddba8..b961159 100644
33747 --- a/drivers/md/dm-raid1.c
33748 +++ b/drivers/md/dm-raid1.c
33749 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33750
33751 struct mirror {
33752 struct mirror_set *ms;
33753 - atomic_t error_count;
33754 + atomic_unchecked_t error_count;
33755 unsigned long error_type;
33756 struct dm_dev *dev;
33757 sector_t offset;
33758 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33759 struct mirror *m;
33760
33761 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33762 - if (!atomic_read(&m->error_count))
33763 + if (!atomic_read_unchecked(&m->error_count))
33764 return m;
33765
33766 return NULL;
33767 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33768 * simple way to tell if a device has encountered
33769 * errors.
33770 */
33771 - atomic_inc(&m->error_count);
33772 + atomic_inc_unchecked(&m->error_count);
33773
33774 if (test_and_set_bit(error_type, &m->error_type))
33775 return;
33776 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33777 struct mirror *m = get_default_mirror(ms);
33778
33779 do {
33780 - if (likely(!atomic_read(&m->error_count)))
33781 + if (likely(!atomic_read_unchecked(&m->error_count)))
33782 return m;
33783
33784 if (m-- == ms->mirror)
33785 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33786 {
33787 struct mirror *default_mirror = get_default_mirror(m->ms);
33788
33789 - return !atomic_read(&default_mirror->error_count);
33790 + return !atomic_read_unchecked(&default_mirror->error_count);
33791 }
33792
33793 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33794 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33795 */
33796 if (likely(region_in_sync(ms, region, 1)))
33797 m = choose_mirror(ms, bio->bi_sector);
33798 - else if (m && atomic_read(&m->error_count))
33799 + else if (m && atomic_read_unchecked(&m->error_count))
33800 m = NULL;
33801
33802 if (likely(m))
33803 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33804 }
33805
33806 ms->mirror[mirror].ms = ms;
33807 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33808 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33809 ms->mirror[mirror].error_type = 0;
33810 ms->mirror[mirror].offset = offset;
33811
33812 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33813 */
33814 static char device_status_char(struct mirror *m)
33815 {
33816 - if (!atomic_read(&(m->error_count)))
33817 + if (!atomic_read_unchecked(&(m->error_count)))
33818 return 'A';
33819
33820 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33821 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33822 index a087bf2..4c94786 100644
33823 --- a/drivers/md/dm-stripe.c
33824 +++ b/drivers/md/dm-stripe.c
33825 @@ -20,7 +20,7 @@ struct stripe {
33826 struct dm_dev *dev;
33827 sector_t physical_start;
33828
33829 - atomic_t error_count;
33830 + atomic_unchecked_t error_count;
33831 };
33832
33833 struct stripe_c {
33834 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33835 kfree(sc);
33836 return r;
33837 }
33838 - atomic_set(&(sc->stripe[i].error_count), 0);
33839 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33840 }
33841
33842 ti->private = sc;
33843 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33844 DMEMIT("%d ", sc->stripes);
33845 for (i = 0; i < sc->stripes; i++) {
33846 DMEMIT("%s ", sc->stripe[i].dev->name);
33847 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33848 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33849 'D' : 'A';
33850 }
33851 buffer[i] = '\0';
33852 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33853 */
33854 for (i = 0; i < sc->stripes; i++)
33855 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33856 - atomic_inc(&(sc->stripe[i].error_count));
33857 - if (atomic_read(&(sc->stripe[i].error_count)) <
33858 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33859 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33860 DM_IO_ERROR_THRESHOLD)
33861 schedule_work(&sc->trigger_event);
33862 }
33863 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33864 index 100368e..64262ce 100644
33865 --- a/drivers/md/dm-table.c
33866 +++ b/drivers/md/dm-table.c
33867 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33868 if (!dev_size)
33869 return 0;
33870
33871 - if ((start >= dev_size) || (start + len > dev_size)) {
33872 + if ((start >= dev_size) || (len > dev_size - start)) {
33873 DMWARN("%s: %s too small for target: "
33874 "start=%llu, len=%llu, dev_size=%llu",
33875 dm_device_name(ti->table->md), bdevname(bdev, b),
33876 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33877 index 693e149..b7e0fde 100644
33878 --- a/drivers/md/dm-thin-metadata.c
33879 +++ b/drivers/md/dm-thin-metadata.c
33880 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33881 {
33882 pmd->info.tm = pmd->tm;
33883 pmd->info.levels = 2;
33884 - pmd->info.value_type.context = pmd->data_sm;
33885 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33886 pmd->info.value_type.size = sizeof(__le64);
33887 pmd->info.value_type.inc = data_block_inc;
33888 pmd->info.value_type.dec = data_block_dec;
33889 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33890
33891 pmd->bl_info.tm = pmd->tm;
33892 pmd->bl_info.levels = 1;
33893 - pmd->bl_info.value_type.context = pmd->data_sm;
33894 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33895 pmd->bl_info.value_type.size = sizeof(__le64);
33896 pmd->bl_info.value_type.inc = data_block_inc;
33897 pmd->bl_info.value_type.dec = data_block_dec;
33898 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33899 index 67ffa39..cb3b1dd 100644
33900 --- a/drivers/md/dm.c
33901 +++ b/drivers/md/dm.c
33902 @@ -176,9 +176,9 @@ struct mapped_device {
33903 /*
33904 * Event handling.
33905 */
33906 - atomic_t event_nr;
33907 + atomic_unchecked_t event_nr;
33908 wait_queue_head_t eventq;
33909 - atomic_t uevent_seq;
33910 + atomic_unchecked_t uevent_seq;
33911 struct list_head uevent_list;
33912 spinlock_t uevent_lock; /* Protect access to uevent_list */
33913
33914 @@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33915 rwlock_init(&md->map_lock);
33916 atomic_set(&md->holders, 1);
33917 atomic_set(&md->open_count, 0);
33918 - atomic_set(&md->event_nr, 0);
33919 - atomic_set(&md->uevent_seq, 0);
33920 + atomic_set_unchecked(&md->event_nr, 0);
33921 + atomic_set_unchecked(&md->uevent_seq, 0);
33922 INIT_LIST_HEAD(&md->uevent_list);
33923 spin_lock_init(&md->uevent_lock);
33924
33925 @@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33926
33927 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33928
33929 - atomic_inc(&md->event_nr);
33930 + atomic_inc_unchecked(&md->event_nr);
33931 wake_up(&md->eventq);
33932 }
33933
33934 @@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33935
33936 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33937 {
33938 - return atomic_add_return(1, &md->uevent_seq);
33939 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33940 }
33941
33942 uint32_t dm_get_event_nr(struct mapped_device *md)
33943 {
33944 - return atomic_read(&md->event_nr);
33945 + return atomic_read_unchecked(&md->event_nr);
33946 }
33947
33948 int dm_wait_event(struct mapped_device *md, int event_nr)
33949 {
33950 return wait_event_interruptible(md->eventq,
33951 - (event_nr != atomic_read(&md->event_nr)));
33952 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33953 }
33954
33955 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33956 diff --git a/drivers/md/md.c b/drivers/md/md.c
33957 index 308e87b..7f365d6 100644
33958 --- a/drivers/md/md.c
33959 +++ b/drivers/md/md.c
33960 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33961 * start build, activate spare
33962 */
33963 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33964 -static atomic_t md_event_count;
33965 +static atomic_unchecked_t md_event_count;
33966 void md_new_event(struct mddev *mddev)
33967 {
33968 - atomic_inc(&md_event_count);
33969 + atomic_inc_unchecked(&md_event_count);
33970 wake_up(&md_event_waiters);
33971 }
33972 EXPORT_SYMBOL_GPL(md_new_event);
33973 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33974 */
33975 static void md_new_event_inintr(struct mddev *mddev)
33976 {
33977 - atomic_inc(&md_event_count);
33978 + atomic_inc_unchecked(&md_event_count);
33979 wake_up(&md_event_waiters);
33980 }
33981
33982 @@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33983 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33984 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33985 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33986 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33987 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33988
33989 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33990 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33991 @@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33992 else
33993 sb->resync_offset = cpu_to_le64(0);
33994
33995 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33996 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33997
33998 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33999 sb->size = cpu_to_le64(mddev->dev_sectors);
34000 @@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
34001 static ssize_t
34002 errors_show(struct md_rdev *rdev, char *page)
34003 {
34004 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
34005 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
34006 }
34007
34008 static ssize_t
34009 @@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
34010 char *e;
34011 unsigned long n = simple_strtoul(buf, &e, 10);
34012 if (*buf && (*e == 0 || *e == '\n')) {
34013 - atomic_set(&rdev->corrected_errors, n);
34014 + atomic_set_unchecked(&rdev->corrected_errors, n);
34015 return len;
34016 }
34017 return -EINVAL;
34018 @@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
34019 rdev->sb_loaded = 0;
34020 rdev->bb_page = NULL;
34021 atomic_set(&rdev->nr_pending, 0);
34022 - atomic_set(&rdev->read_errors, 0);
34023 - atomic_set(&rdev->corrected_errors, 0);
34024 + atomic_set_unchecked(&rdev->read_errors, 0);
34025 + atomic_set_unchecked(&rdev->corrected_errors, 0);
34026
34027 INIT_LIST_HEAD(&rdev->same_set);
34028 init_waitqueue_head(&rdev->blocked_wait);
34029 @@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
34030
34031 spin_unlock(&pers_lock);
34032 seq_printf(seq, "\n");
34033 - seq->poll_event = atomic_read(&md_event_count);
34034 + seq->poll_event = atomic_read_unchecked(&md_event_count);
34035 return 0;
34036 }
34037 if (v == (void*)2) {
34038 @@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
34039 return error;
34040
34041 seq = file->private_data;
34042 - seq->poll_event = atomic_read(&md_event_count);
34043 + seq->poll_event = atomic_read_unchecked(&md_event_count);
34044 return error;
34045 }
34046
34047 @@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
34048 /* always allow read */
34049 mask = POLLIN | POLLRDNORM;
34050
34051 - if (seq->poll_event != atomic_read(&md_event_count))
34052 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
34053 mask |= POLLERR | POLLPRI;
34054 return mask;
34055 }
34056 @@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
34057 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
34058 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
34059 (int)part_stat_read(&disk->part0, sectors[1]) -
34060 - atomic_read(&disk->sync_io);
34061 + atomic_read_unchecked(&disk->sync_io);
34062 /* sync IO will cause sync_io to increase before the disk_stats
34063 * as sync_io is counted when a request starts, and
34064 * disk_stats is counted when it completes.
34065 diff --git a/drivers/md/md.h b/drivers/md/md.h
34066 index f385b03..b600be8 100644
34067 --- a/drivers/md/md.h
34068 +++ b/drivers/md/md.h
34069 @@ -94,13 +94,13 @@ struct md_rdev {
34070 * only maintained for arrays that
34071 * support hot removal
34072 */
34073 - atomic_t read_errors; /* number of consecutive read errors that
34074 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
34075 * we have tried to ignore.
34076 */
34077 struct timespec last_read_error; /* monotonic time since our
34078 * last read error
34079 */
34080 - atomic_t corrected_errors; /* number of corrected read errors,
34081 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
34082 * for reporting to userspace and storing
34083 * in superblock.
34084 */
34085 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
34086
34087 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
34088 {
34089 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34090 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34091 }
34092
34093 struct md_personality
34094 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
34095 index f6d29e6..7917f5e 100644
34096 --- a/drivers/md/persistent-data/dm-space-map-disk.c
34097 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
34098 @@ -22,7 +22,7 @@
34099 * Space map interface.
34100 */
34101 struct sm_disk {
34102 - struct dm_space_map sm;
34103 + dm_space_map_no_const sm;
34104
34105 struct ll_disk ll;
34106 struct ll_disk old_ll;
34107 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
34108 index e89ae5e..062e4c2 100644
34109 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
34110 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
34111 @@ -43,7 +43,7 @@ struct block_op {
34112 };
34113
34114 struct sm_metadata {
34115 - struct dm_space_map sm;
34116 + dm_space_map_no_const sm;
34117
34118 struct ll_disk ll;
34119 struct ll_disk old_ll;
34120 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
34121 index 1cbfc6b..56e1dbb 100644
34122 --- a/drivers/md/persistent-data/dm-space-map.h
34123 +++ b/drivers/md/persistent-data/dm-space-map.h
34124 @@ -60,6 +60,7 @@ struct dm_space_map {
34125 int (*root_size)(struct dm_space_map *sm, size_t *result);
34126 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
34127 };
34128 +typedef struct dm_space_map __no_const dm_space_map_no_const;
34129
34130 /*----------------------------------------------------------------*/
34131
34132 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
34133 index 05bb49e..84d7ce6 100644
34134 --- a/drivers/md/raid1.c
34135 +++ b/drivers/md/raid1.c
34136 @@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
34137 if (r1_sync_page_io(rdev, sect, s,
34138 bio->bi_io_vec[idx].bv_page,
34139 READ) != 0)
34140 - atomic_add(s, &rdev->corrected_errors);
34141 + atomic_add_unchecked(s, &rdev->corrected_errors);
34142 }
34143 sectors -= s;
34144 sect += s;
34145 @@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
34146 test_bit(In_sync, &rdev->flags)) {
34147 if (r1_sync_page_io(rdev, sect, s,
34148 conf->tmppage, READ)) {
34149 - atomic_add(s, &rdev->corrected_errors);
34150 + atomic_add_unchecked(s, &rdev->corrected_errors);
34151 printk(KERN_INFO
34152 "md/raid1:%s: read error corrected "
34153 "(%d sectors at %llu on %s)\n",
34154 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
34155 index a48c215..6bda6f4 100644
34156 --- a/drivers/md/raid10.c
34157 +++ b/drivers/md/raid10.c
34158 @@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
34159 /* The write handler will notice the lack of
34160 * R10BIO_Uptodate and record any errors etc
34161 */
34162 - atomic_add(r10_bio->sectors,
34163 + atomic_add_unchecked(r10_bio->sectors,
34164 &conf->mirrors[d].rdev->corrected_errors);
34165
34166 /* for reconstruct, we always reschedule after a read.
34167 @@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34168 {
34169 struct timespec cur_time_mon;
34170 unsigned long hours_since_last;
34171 - unsigned int read_errors = atomic_read(&rdev->read_errors);
34172 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
34173
34174 ktime_get_ts(&cur_time_mon);
34175
34176 @@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34177 * overflowing the shift of read_errors by hours_since_last.
34178 */
34179 if (hours_since_last >= 8 * sizeof(read_errors))
34180 - atomic_set(&rdev->read_errors, 0);
34181 + atomic_set_unchecked(&rdev->read_errors, 0);
34182 else
34183 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
34184 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
34185 }
34186
34187 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
34188 @@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34189 return;
34190
34191 check_decay_read_errors(mddev, rdev);
34192 - atomic_inc(&rdev->read_errors);
34193 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
34194 + atomic_inc_unchecked(&rdev->read_errors);
34195 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
34196 char b[BDEVNAME_SIZE];
34197 bdevname(rdev->bdev, b);
34198
34199 @@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34200 "md/raid10:%s: %s: Raid device exceeded "
34201 "read_error threshold [cur %d:max %d]\n",
34202 mdname(mddev), b,
34203 - atomic_read(&rdev->read_errors), max_read_errors);
34204 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
34205 printk(KERN_NOTICE
34206 "md/raid10:%s: %s: Failing raid device\n",
34207 mdname(mddev), b);
34208 @@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34209 sect +
34210 choose_data_offset(r10_bio, rdev)),
34211 bdevname(rdev->bdev, b));
34212 - atomic_add(s, &rdev->corrected_errors);
34213 + atomic_add_unchecked(s, &rdev->corrected_errors);
34214 }
34215
34216 rdev_dec_pending(rdev, mddev);
34217 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
34218 index 0689173..35df76c 100644
34219 --- a/drivers/md/raid5.c
34220 +++ b/drivers/md/raid5.c
34221 @@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
34222 mdname(conf->mddev), STRIPE_SECTORS,
34223 (unsigned long long)s,
34224 bdevname(rdev->bdev, b));
34225 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
34226 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
34227 clear_bit(R5_ReadError, &sh->dev[i].flags);
34228 clear_bit(R5_ReWrite, &sh->dev[i].flags);
34229 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
34230 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
34231
34232 - if (atomic_read(&rdev->read_errors))
34233 - atomic_set(&rdev->read_errors, 0);
34234 + if (atomic_read_unchecked(&rdev->read_errors))
34235 + atomic_set_unchecked(&rdev->read_errors, 0);
34236 } else {
34237 const char *bdn = bdevname(rdev->bdev, b);
34238 int retry = 0;
34239 int set_bad = 0;
34240
34241 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
34242 - atomic_inc(&rdev->read_errors);
34243 + atomic_inc_unchecked(&rdev->read_errors);
34244 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
34245 printk_ratelimited(
34246 KERN_WARNING
34247 @@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
34248 mdname(conf->mddev),
34249 (unsigned long long)s,
34250 bdn);
34251 - } else if (atomic_read(&rdev->read_errors)
34252 + } else if (atomic_read_unchecked(&rdev->read_errors)
34253 > conf->max_nr_stripes)
34254 printk(KERN_WARNING
34255 "md/raid:%s: Too many read errors, failing device %s.\n",
34256 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
34257 index ebf3f05..b1f3e77 100644
34258 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
34259 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
34260 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
34261 .subvendor = _subvend, .subdevice = _subdev, \
34262 .driver_data = (unsigned long)&_driverdata }
34263
34264 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
34265 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
34266 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
34267 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
34268 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
34269 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
34270 index fa7188a..04a045e 100644
34271 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
34272 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
34273 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
34274 union {
34275 dmx_ts_cb ts;
34276 dmx_section_cb sec;
34277 - } cb;
34278 + } __no_const cb;
34279
34280 struct dvb_demux *demux;
34281 void *priv;
34282 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
34283 index 39eab73..60033e7 100644
34284 --- a/drivers/media/dvb/dvb-core/dvbdev.c
34285 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
34286 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
34287 const struct dvb_device *template, void *priv, int type)
34288 {
34289 struct dvb_device *dvbdev;
34290 - struct file_operations *dvbdevfops;
34291 + file_operations_no_const *dvbdevfops;
34292 struct device *clsdev;
34293 int minor;
34294 int id;
34295 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
34296 index 3940bb0..fb3952a 100644
34297 --- a/drivers/media/dvb/dvb-usb/cxusb.c
34298 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
34299 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
34300
34301 struct dib0700_adapter_state {
34302 int (*set_param_save) (struct dvb_frontend *);
34303 -};
34304 +} __no_const;
34305
34306 static int dib7070_set_param_override(struct dvb_frontend *fe)
34307 {
34308 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
34309 index 9382895..ac8093c 100644
34310 --- a/drivers/media/dvb/dvb-usb/dw2102.c
34311 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
34312 @@ -95,7 +95,7 @@ struct su3000_state {
34313
34314 struct s6x0_state {
34315 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
34316 -};
34317 +} __no_const;
34318
34319 /* debug */
34320 static int dvb_usb_dw2102_debug;
34321 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
34322 index 404f63a..4796533 100644
34323 --- a/drivers/media/dvb/frontends/dib3000.h
34324 +++ b/drivers/media/dvb/frontends/dib3000.h
34325 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34326 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34327 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34328 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34329 -};
34330 +} __no_const;
34331
34332 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34333 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34334 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34335 index 72ee8de..eae0c80 100644
34336 --- a/drivers/media/dvb/ngene/ngene-cards.c
34337 +++ b/drivers/media/dvb/ngene/ngene-cards.c
34338 @@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
34339
34340 /****************************************************************************/
34341
34342 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34343 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34344 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34345 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34346 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34347 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34348 index 697a421..16c5a5f 100644
34349 --- a/drivers/media/radio/radio-cadet.c
34350 +++ b/drivers/media/radio/radio-cadet.c
34351 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34352 unsigned char readbuf[RDS_BUFFER];
34353 int i = 0;
34354
34355 + if (count > RDS_BUFFER)
34356 + return -EFAULT;
34357 mutex_lock(&dev->lock);
34358 if (dev->rdsstat == 0)
34359 cadet_start_rds(dev);
34360 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34361 while (i < count && dev->rdsin != dev->rdsout)
34362 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34363
34364 - if (i && copy_to_user(data, readbuf, i))
34365 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34366 i = -EFAULT;
34367 unlock:
34368 mutex_unlock(&dev->lock);
34369 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34370 index 55cbd78..428b0da 100644
34371 --- a/drivers/media/radio/radio-tea5777.h
34372 +++ b/drivers/media/radio/radio-tea5777.h
34373 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34374
34375 struct radio_tea5777 {
34376 struct v4l2_device *v4l2_dev;
34377 - struct v4l2_file_operations fops;
34378 + v4l2_file_operations_no_const fops;
34379 struct video_device vd; /* video device */
34380 bool has_am; /* Device can tune to AM freqs */
34381 bool write_before_read; /* must write before read quirk */
34382 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34383 index 9cde353..8c6a1c3 100644
34384 --- a/drivers/media/video/au0828/au0828.h
34385 +++ b/drivers/media/video/au0828/au0828.h
34386 @@ -191,7 +191,7 @@ struct au0828_dev {
34387
34388 /* I2C */
34389 struct i2c_adapter i2c_adap;
34390 - struct i2c_algorithm i2c_algo;
34391 + i2c_algorithm_no_const i2c_algo;
34392 struct i2c_client i2c_client;
34393 u32 i2c_rc;
34394
34395 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34396 index dfac6e3..c26de31 100644
34397 --- a/drivers/media/video/cx88/cx88-alsa.c
34398 +++ b/drivers/media/video/cx88/cx88-alsa.c
34399 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34400 * Only boards with eeprom and byte 1 at eeprom=1 have it
34401 */
34402
34403 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34404 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34405 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34406 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34407 {0, }
34408 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34409 index 88cf9d9..bbc4b2c 100644
34410 --- a/drivers/media/video/omap/omap_vout.c
34411 +++ b/drivers/media/video/omap/omap_vout.c
34412 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34413 OMAP_VIDEO2,
34414 };
34415
34416 -static struct videobuf_queue_ops video_vbq_ops;
34417 /* Variables configurable through module params*/
34418 static u32 video1_numbuffers = 3;
34419 static u32 video2_numbuffers = 3;
34420 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34421 {
34422 struct videobuf_queue *q;
34423 struct omap_vout_device *vout = NULL;
34424 + static struct videobuf_queue_ops video_vbq_ops = {
34425 + .buf_setup = omap_vout_buffer_setup,
34426 + .buf_prepare = omap_vout_buffer_prepare,
34427 + .buf_release = omap_vout_buffer_release,
34428 + .buf_queue = omap_vout_buffer_queue,
34429 + };
34430
34431 vout = video_drvdata(file);
34432 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34433 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34434 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34435
34436 q = &vout->vbq;
34437 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34438 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34439 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34440 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34441 spin_lock_init(&vout->vbq_lock);
34442
34443 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34444 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34445 index 036952f..80d356d 100644
34446 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34447 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34448 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34449
34450 /* I2C stuff */
34451 struct i2c_adapter i2c_adap;
34452 - struct i2c_algorithm i2c_algo;
34453 + i2c_algorithm_no_const i2c_algo;
34454 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34455 int i2c_cx25840_hack_state;
34456 int i2c_linked;
34457 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34458 index 02194c0..091733b 100644
34459 --- a/drivers/media/video/timblogiw.c
34460 +++ b/drivers/media/video/timblogiw.c
34461 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34462
34463 /* Platform device functions */
34464
34465 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34466 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34467 .vidioc_querycap = timblogiw_querycap,
34468 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34469 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34470 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34471 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34472 };
34473
34474 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34475 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34476 .owner = THIS_MODULE,
34477 .open = timblogiw_open,
34478 .release = timblogiw_close,
34479 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34480 index d99db56..a16b959 100644
34481 --- a/drivers/message/fusion/mptbase.c
34482 +++ b/drivers/message/fusion/mptbase.c
34483 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34484 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34485 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34486
34487 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34488 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34489 +#else
34490 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34491 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34492 +#endif
34493 +
34494 /*
34495 * Rounding UP to nearest 4-kB boundary here...
34496 */
34497 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34498 index 551262e..7551198 100644
34499 --- a/drivers/message/fusion/mptsas.c
34500 +++ b/drivers/message/fusion/mptsas.c
34501 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34502 return 0;
34503 }
34504
34505 +static inline void
34506 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34507 +{
34508 + if (phy_info->port_details) {
34509 + phy_info->port_details->rphy = rphy;
34510 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34511 + ioc->name, rphy));
34512 + }
34513 +
34514 + if (rphy) {
34515 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34516 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34517 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34518 + ioc->name, rphy, rphy->dev.release));
34519 + }
34520 +}
34521 +
34522 /* no mutex */
34523 static void
34524 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34525 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34526 return NULL;
34527 }
34528
34529 -static inline void
34530 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34531 -{
34532 - if (phy_info->port_details) {
34533 - phy_info->port_details->rphy = rphy;
34534 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34535 - ioc->name, rphy));
34536 - }
34537 -
34538 - if (rphy) {
34539 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34540 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34541 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34542 - ioc->name, rphy, rphy->dev.release));
34543 - }
34544 -}
34545 -
34546 static inline struct sas_port *
34547 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34548 {
34549 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34550 index 0c3ced7..1fe34ec 100644
34551 --- a/drivers/message/fusion/mptscsih.c
34552 +++ b/drivers/message/fusion/mptscsih.c
34553 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34554
34555 h = shost_priv(SChost);
34556
34557 - if (h) {
34558 - if (h->info_kbuf == NULL)
34559 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34560 - return h->info_kbuf;
34561 - h->info_kbuf[0] = '\0';
34562 + if (!h)
34563 + return NULL;
34564
34565 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34566 - h->info_kbuf[size-1] = '\0';
34567 - }
34568 + if (h->info_kbuf == NULL)
34569 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34570 + return h->info_kbuf;
34571 + h->info_kbuf[0] = '\0';
34572 +
34573 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34574 + h->info_kbuf[size-1] = '\0';
34575
34576 return h->info_kbuf;
34577 }
34578 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34579 index 8001aa6..b137580 100644
34580 --- a/drivers/message/i2o/i2o_proc.c
34581 +++ b/drivers/message/i2o/i2o_proc.c
34582 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34583 "Array Controller Device"
34584 };
34585
34586 -static char *chtostr(char *tmp, u8 *chars, int n)
34587 -{
34588 - tmp[0] = 0;
34589 - return strncat(tmp, (char *)chars, n);
34590 -}
34591 -
34592 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34593 char *group)
34594 {
34595 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34596 } *result;
34597
34598 i2o_exec_execute_ddm_table ddm_table;
34599 - char tmp[28 + 1];
34600
34601 result = kmalloc(sizeof(*result), GFP_KERNEL);
34602 if (!result)
34603 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34604
34605 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34606 seq_printf(seq, "%-#8x", ddm_table.module_id);
34607 - seq_printf(seq, "%-29s",
34608 - chtostr(tmp, ddm_table.module_name_version, 28));
34609 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34610 seq_printf(seq, "%9d ", ddm_table.data_size);
34611 seq_printf(seq, "%8d", ddm_table.code_size);
34612
34613 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34614
34615 i2o_driver_result_table *result;
34616 i2o_driver_store_table *dst;
34617 - char tmp[28 + 1];
34618
34619 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34620 if (result == NULL)
34621 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34622
34623 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34624 seq_printf(seq, "%-#8x", dst->module_id);
34625 - seq_printf(seq, "%-29s",
34626 - chtostr(tmp, dst->module_name_version, 28));
34627 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34628 + seq_printf(seq, "%-.28s", dst->module_name_version);
34629 + seq_printf(seq, "%-.8s", dst->date);
34630 seq_printf(seq, "%8d ", dst->module_size);
34631 seq_printf(seq, "%8d ", dst->mpb_size);
34632 seq_printf(seq, "0x%04x", dst->module_flags);
34633 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34634 // == (allow) 512d bytes (max)
34635 static u16 *work16 = (u16 *) work32;
34636 int token;
34637 - char tmp[16 + 1];
34638
34639 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34640
34641 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34642 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34643 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34644 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34645 - seq_printf(seq, "Vendor info : %s\n",
34646 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34647 - seq_printf(seq, "Product info : %s\n",
34648 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34649 - seq_printf(seq, "Description : %s\n",
34650 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34651 - seq_printf(seq, "Product rev. : %s\n",
34652 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34653 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34654 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34655 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34656 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34657
34658 seq_printf(seq, "Serial number : ");
34659 print_serial_number(seq, (u8 *) (work32 + 16),
34660 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34661 u8 pad[256]; // allow up to 256 byte (max) serial number
34662 } result;
34663
34664 - char tmp[24 + 1];
34665 -
34666 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34667
34668 if (token < 0) {
34669 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34670 }
34671
34672 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34673 - seq_printf(seq, "Module name : %s\n",
34674 - chtostr(tmp, result.module_name, 24));
34675 - seq_printf(seq, "Module revision : %s\n",
34676 - chtostr(tmp, result.module_rev, 8));
34677 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34678 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34679
34680 seq_printf(seq, "Serial number : ");
34681 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34682 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34683 u8 instance_number[4];
34684 } result;
34685
34686 - char tmp[64 + 1];
34687 -
34688 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34689
34690 if (token < 0) {
34691 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34692 return 0;
34693 }
34694
34695 - seq_printf(seq, "Device name : %s\n",
34696 - chtostr(tmp, result.device_name, 64));
34697 - seq_printf(seq, "Service name : %s\n",
34698 - chtostr(tmp, result.service_name, 64));
34699 - seq_printf(seq, "Physical name : %s\n",
34700 - chtostr(tmp, result.physical_location, 64));
34701 - seq_printf(seq, "Instance number : %s\n",
34702 - chtostr(tmp, result.instance_number, 4));
34703 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34704 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34705 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34706 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34707
34708 return 0;
34709 }
34710 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34711 index a8c08f3..155fe3d 100644
34712 --- a/drivers/message/i2o/iop.c
34713 +++ b/drivers/message/i2o/iop.c
34714 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34715
34716 spin_lock_irqsave(&c->context_list_lock, flags);
34717
34718 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34719 - atomic_inc(&c->context_list_counter);
34720 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34721 + atomic_inc_unchecked(&c->context_list_counter);
34722
34723 - entry->context = atomic_read(&c->context_list_counter);
34724 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34725
34726 list_add(&entry->list, &c->context_list);
34727
34728 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34729
34730 #if BITS_PER_LONG == 64
34731 spin_lock_init(&c->context_list_lock);
34732 - atomic_set(&c->context_list_counter, 0);
34733 + atomic_set_unchecked(&c->context_list_counter, 0);
34734 INIT_LIST_HEAD(&c->context_list);
34735 #endif
34736
34737 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34738 index 7ce65f4..e66e9bc 100644
34739 --- a/drivers/mfd/abx500-core.c
34740 +++ b/drivers/mfd/abx500-core.c
34741 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34742
34743 struct abx500_device_entry {
34744 struct list_head list;
34745 - struct abx500_ops ops;
34746 + abx500_ops_no_const ops;
34747 struct device *dev;
34748 };
34749
34750 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34751 index 965c480..71f2db9 100644
34752 --- a/drivers/mfd/janz-cmodio.c
34753 +++ b/drivers/mfd/janz-cmodio.c
34754 @@ -13,6 +13,7 @@
34755
34756 #include <linux/kernel.h>
34757 #include <linux/module.h>
34758 +#include <linux/slab.h>
34759 #include <linux/init.h>
34760 #include <linux/pci.h>
34761 #include <linux/interrupt.h>
34762 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34763 index a981e2a..5ca0c8b 100644
34764 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34765 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34766 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34767 * the lid is closed. This leads to interrupts as soon as a little move
34768 * is done.
34769 */
34770 - atomic_inc(&lis3->count);
34771 + atomic_inc_unchecked(&lis3->count);
34772
34773 wake_up_interruptible(&lis3->misc_wait);
34774 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34775 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34776 if (lis3->pm_dev)
34777 pm_runtime_get_sync(lis3->pm_dev);
34778
34779 - atomic_set(&lis3->count, 0);
34780 + atomic_set_unchecked(&lis3->count, 0);
34781 return 0;
34782 }
34783
34784 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34785 add_wait_queue(&lis3->misc_wait, &wait);
34786 while (true) {
34787 set_current_state(TASK_INTERRUPTIBLE);
34788 - data = atomic_xchg(&lis3->count, 0);
34789 + data = atomic_xchg_unchecked(&lis3->count, 0);
34790 if (data)
34791 break;
34792
34793 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34794 struct lis3lv02d, miscdev);
34795
34796 poll_wait(file, &lis3->misc_wait, wait);
34797 - if (atomic_read(&lis3->count))
34798 + if (atomic_read_unchecked(&lis3->count))
34799 return POLLIN | POLLRDNORM;
34800 return 0;
34801 }
34802 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34803 index 2b1482a..5d33616 100644
34804 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34805 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34806 @@ -266,7 +266,7 @@ struct lis3lv02d {
34807 struct input_polled_dev *idev; /* input device */
34808 struct platform_device *pdev; /* platform device */
34809 struct regulator_bulk_data regulators[2];
34810 - atomic_t count; /* interrupt count after last read */
34811 + atomic_unchecked_t count; /* interrupt count after last read */
34812 union axis_conversion ac; /* hw -> logical axis */
34813 int mapped_btns[3];
34814
34815 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34816 index 2f30bad..c4c13d0 100644
34817 --- a/drivers/misc/sgi-gru/gruhandles.c
34818 +++ b/drivers/misc/sgi-gru/gruhandles.c
34819 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34820 unsigned long nsec;
34821
34822 nsec = CLKS2NSEC(clks);
34823 - atomic_long_inc(&mcs_op_statistics[op].count);
34824 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34825 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34826 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34827 if (mcs_op_statistics[op].max < nsec)
34828 mcs_op_statistics[op].max = nsec;
34829 }
34830 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34831 index 950dbe9..eeef0f8 100644
34832 --- a/drivers/misc/sgi-gru/gruprocfs.c
34833 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34834 @@ -32,9 +32,9 @@
34835
34836 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34837
34838 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34839 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34840 {
34841 - unsigned long val = atomic_long_read(v);
34842 + unsigned long val = atomic_long_read_unchecked(v);
34843
34844 seq_printf(s, "%16lu %s\n", val, id);
34845 }
34846 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34847
34848 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34849 for (op = 0; op < mcsop_last; op++) {
34850 - count = atomic_long_read(&mcs_op_statistics[op].count);
34851 - total = atomic_long_read(&mcs_op_statistics[op].total);
34852 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34853 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34854 max = mcs_op_statistics[op].max;
34855 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34856 count ? total / count : 0, max);
34857 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34858 index 5c3ce24..4915ccb 100644
34859 --- a/drivers/misc/sgi-gru/grutables.h
34860 +++ b/drivers/misc/sgi-gru/grutables.h
34861 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34862 * GRU statistics.
34863 */
34864 struct gru_stats_s {
34865 - atomic_long_t vdata_alloc;
34866 - atomic_long_t vdata_free;
34867 - atomic_long_t gts_alloc;
34868 - atomic_long_t gts_free;
34869 - atomic_long_t gms_alloc;
34870 - atomic_long_t gms_free;
34871 - atomic_long_t gts_double_allocate;
34872 - atomic_long_t assign_context;
34873 - atomic_long_t assign_context_failed;
34874 - atomic_long_t free_context;
34875 - atomic_long_t load_user_context;
34876 - atomic_long_t load_kernel_context;
34877 - atomic_long_t lock_kernel_context;
34878 - atomic_long_t unlock_kernel_context;
34879 - atomic_long_t steal_user_context;
34880 - atomic_long_t steal_kernel_context;
34881 - atomic_long_t steal_context_failed;
34882 - atomic_long_t nopfn;
34883 - atomic_long_t asid_new;
34884 - atomic_long_t asid_next;
34885 - atomic_long_t asid_wrap;
34886 - atomic_long_t asid_reuse;
34887 - atomic_long_t intr;
34888 - atomic_long_t intr_cbr;
34889 - atomic_long_t intr_tfh;
34890 - atomic_long_t intr_spurious;
34891 - atomic_long_t intr_mm_lock_failed;
34892 - atomic_long_t call_os;
34893 - atomic_long_t call_os_wait_queue;
34894 - atomic_long_t user_flush_tlb;
34895 - atomic_long_t user_unload_context;
34896 - atomic_long_t user_exception;
34897 - atomic_long_t set_context_option;
34898 - atomic_long_t check_context_retarget_intr;
34899 - atomic_long_t check_context_unload;
34900 - atomic_long_t tlb_dropin;
34901 - atomic_long_t tlb_preload_page;
34902 - atomic_long_t tlb_dropin_fail_no_asid;
34903 - atomic_long_t tlb_dropin_fail_upm;
34904 - atomic_long_t tlb_dropin_fail_invalid;
34905 - atomic_long_t tlb_dropin_fail_range_active;
34906 - atomic_long_t tlb_dropin_fail_idle;
34907 - atomic_long_t tlb_dropin_fail_fmm;
34908 - atomic_long_t tlb_dropin_fail_no_exception;
34909 - atomic_long_t tfh_stale_on_fault;
34910 - atomic_long_t mmu_invalidate_range;
34911 - atomic_long_t mmu_invalidate_page;
34912 - atomic_long_t flush_tlb;
34913 - atomic_long_t flush_tlb_gru;
34914 - atomic_long_t flush_tlb_gru_tgh;
34915 - atomic_long_t flush_tlb_gru_zero_asid;
34916 + atomic_long_unchecked_t vdata_alloc;
34917 + atomic_long_unchecked_t vdata_free;
34918 + atomic_long_unchecked_t gts_alloc;
34919 + atomic_long_unchecked_t gts_free;
34920 + atomic_long_unchecked_t gms_alloc;
34921 + atomic_long_unchecked_t gms_free;
34922 + atomic_long_unchecked_t gts_double_allocate;
34923 + atomic_long_unchecked_t assign_context;
34924 + atomic_long_unchecked_t assign_context_failed;
34925 + atomic_long_unchecked_t free_context;
34926 + atomic_long_unchecked_t load_user_context;
34927 + atomic_long_unchecked_t load_kernel_context;
34928 + atomic_long_unchecked_t lock_kernel_context;
34929 + atomic_long_unchecked_t unlock_kernel_context;
34930 + atomic_long_unchecked_t steal_user_context;
34931 + atomic_long_unchecked_t steal_kernel_context;
34932 + atomic_long_unchecked_t steal_context_failed;
34933 + atomic_long_unchecked_t nopfn;
34934 + atomic_long_unchecked_t asid_new;
34935 + atomic_long_unchecked_t asid_next;
34936 + atomic_long_unchecked_t asid_wrap;
34937 + atomic_long_unchecked_t asid_reuse;
34938 + atomic_long_unchecked_t intr;
34939 + atomic_long_unchecked_t intr_cbr;
34940 + atomic_long_unchecked_t intr_tfh;
34941 + atomic_long_unchecked_t intr_spurious;
34942 + atomic_long_unchecked_t intr_mm_lock_failed;
34943 + atomic_long_unchecked_t call_os;
34944 + atomic_long_unchecked_t call_os_wait_queue;
34945 + atomic_long_unchecked_t user_flush_tlb;
34946 + atomic_long_unchecked_t user_unload_context;
34947 + atomic_long_unchecked_t user_exception;
34948 + atomic_long_unchecked_t set_context_option;
34949 + atomic_long_unchecked_t check_context_retarget_intr;
34950 + atomic_long_unchecked_t check_context_unload;
34951 + atomic_long_unchecked_t tlb_dropin;
34952 + atomic_long_unchecked_t tlb_preload_page;
34953 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34954 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34955 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34956 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34957 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34958 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34959 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34960 + atomic_long_unchecked_t tfh_stale_on_fault;
34961 + atomic_long_unchecked_t mmu_invalidate_range;
34962 + atomic_long_unchecked_t mmu_invalidate_page;
34963 + atomic_long_unchecked_t flush_tlb;
34964 + atomic_long_unchecked_t flush_tlb_gru;
34965 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34966 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34967
34968 - atomic_long_t copy_gpa;
34969 - atomic_long_t read_gpa;
34970 + atomic_long_unchecked_t copy_gpa;
34971 + atomic_long_unchecked_t read_gpa;
34972
34973 - atomic_long_t mesq_receive;
34974 - atomic_long_t mesq_receive_none;
34975 - atomic_long_t mesq_send;
34976 - atomic_long_t mesq_send_failed;
34977 - atomic_long_t mesq_noop;
34978 - atomic_long_t mesq_send_unexpected_error;
34979 - atomic_long_t mesq_send_lb_overflow;
34980 - atomic_long_t mesq_send_qlimit_reached;
34981 - atomic_long_t mesq_send_amo_nacked;
34982 - atomic_long_t mesq_send_put_nacked;
34983 - atomic_long_t mesq_page_overflow;
34984 - atomic_long_t mesq_qf_locked;
34985 - atomic_long_t mesq_qf_noop_not_full;
34986 - atomic_long_t mesq_qf_switch_head_failed;
34987 - atomic_long_t mesq_qf_unexpected_error;
34988 - atomic_long_t mesq_noop_unexpected_error;
34989 - atomic_long_t mesq_noop_lb_overflow;
34990 - atomic_long_t mesq_noop_qlimit_reached;
34991 - atomic_long_t mesq_noop_amo_nacked;
34992 - atomic_long_t mesq_noop_put_nacked;
34993 - atomic_long_t mesq_noop_page_overflow;
34994 + atomic_long_unchecked_t mesq_receive;
34995 + atomic_long_unchecked_t mesq_receive_none;
34996 + atomic_long_unchecked_t mesq_send;
34997 + atomic_long_unchecked_t mesq_send_failed;
34998 + atomic_long_unchecked_t mesq_noop;
34999 + atomic_long_unchecked_t mesq_send_unexpected_error;
35000 + atomic_long_unchecked_t mesq_send_lb_overflow;
35001 + atomic_long_unchecked_t mesq_send_qlimit_reached;
35002 + atomic_long_unchecked_t mesq_send_amo_nacked;
35003 + atomic_long_unchecked_t mesq_send_put_nacked;
35004 + atomic_long_unchecked_t mesq_page_overflow;
35005 + atomic_long_unchecked_t mesq_qf_locked;
35006 + atomic_long_unchecked_t mesq_qf_noop_not_full;
35007 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
35008 + atomic_long_unchecked_t mesq_qf_unexpected_error;
35009 + atomic_long_unchecked_t mesq_noop_unexpected_error;
35010 + atomic_long_unchecked_t mesq_noop_lb_overflow;
35011 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
35012 + atomic_long_unchecked_t mesq_noop_amo_nacked;
35013 + atomic_long_unchecked_t mesq_noop_put_nacked;
35014 + atomic_long_unchecked_t mesq_noop_page_overflow;
35015
35016 };
35017
35018 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
35019 tghop_invalidate, mcsop_last};
35020
35021 struct mcs_op_statistic {
35022 - atomic_long_t count;
35023 - atomic_long_t total;
35024 + atomic_long_unchecked_t count;
35025 + atomic_long_unchecked_t total;
35026 unsigned long max;
35027 };
35028
35029 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
35030
35031 #define STAT(id) do { \
35032 if (gru_options & OPT_STATS) \
35033 - atomic_long_inc(&gru_stats.id); \
35034 + atomic_long_inc_unchecked(&gru_stats.id); \
35035 } while (0)
35036
35037 #ifdef CONFIG_SGI_GRU_DEBUG
35038 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
35039 index c862cd4..0d176fe 100644
35040 --- a/drivers/misc/sgi-xp/xp.h
35041 +++ b/drivers/misc/sgi-xp/xp.h
35042 @@ -288,7 +288,7 @@ struct xpc_interface {
35043 xpc_notify_func, void *);
35044 void (*received) (short, int, void *);
35045 enum xp_retval (*partid_to_nasids) (short, void *);
35046 -};
35047 +} __no_const;
35048
35049 extern struct xpc_interface xpc_interface;
35050
35051 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
35052 index b94d5f7..7f494c5 100644
35053 --- a/drivers/misc/sgi-xp/xpc.h
35054 +++ b/drivers/misc/sgi-xp/xpc.h
35055 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
35056 void (*received_payload) (struct xpc_channel *, void *);
35057 void (*notify_senders_of_disconnect) (struct xpc_channel *);
35058 };
35059 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
35060
35061 /* struct xpc_partition act_state values (for XPC HB) */
35062
35063 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
35064 /* found in xpc_main.c */
35065 extern struct device *xpc_part;
35066 extern struct device *xpc_chan;
35067 -extern struct xpc_arch_operations xpc_arch_ops;
35068 +extern xpc_arch_operations_no_const xpc_arch_ops;
35069 extern int xpc_disengage_timelimit;
35070 extern int xpc_disengage_timedout;
35071 extern int xpc_activate_IRQ_rcvd;
35072 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
35073 index 8d082b4..aa749ae 100644
35074 --- a/drivers/misc/sgi-xp/xpc_main.c
35075 +++ b/drivers/misc/sgi-xp/xpc_main.c
35076 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
35077 .notifier_call = xpc_system_die,
35078 };
35079
35080 -struct xpc_arch_operations xpc_arch_ops;
35081 +xpc_arch_operations_no_const xpc_arch_ops;
35082
35083 /*
35084 * Timer function to enforce the timelimit on the partition disengage.
35085 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
35086 index 504da71..9722d43 100644
35087 --- a/drivers/mmc/host/sdhci-pci.c
35088 +++ b/drivers/mmc/host/sdhci-pci.c
35089 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
35090 .probe = via_probe,
35091 };
35092
35093 -static const struct pci_device_id pci_ids[] __devinitdata = {
35094 +static const struct pci_device_id pci_ids[] __devinitconst = {
35095 {
35096 .vendor = PCI_VENDOR_ID_RICOH,
35097 .device = PCI_DEVICE_ID_RICOH_R5C822,
35098 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
35099 index a4eb8b5..8c0628f 100644
35100 --- a/drivers/mtd/devices/doc2000.c
35101 +++ b/drivers/mtd/devices/doc2000.c
35102 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
35103
35104 /* The ECC will not be calculated correctly if less than 512 is written */
35105 /* DBB-
35106 - if (len != 0x200 && eccbuf)
35107 + if (len != 0x200)
35108 printk(KERN_WARNING
35109 "ECC needs a full sector write (adr: %lx size %lx)\n",
35110 (long) to, (long) len);
35111 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
35112 index 0650aaf..7718762 100644
35113 --- a/drivers/mtd/nand/denali.c
35114 +++ b/drivers/mtd/nand/denali.c
35115 @@ -26,6 +26,7 @@
35116 #include <linux/pci.h>
35117 #include <linux/mtd/mtd.h>
35118 #include <linux/module.h>
35119 +#include <linux/slab.h>
35120
35121 #include "denali.h"
35122
35123 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
35124 index 51b9d6a..52af9a7 100644
35125 --- a/drivers/mtd/nftlmount.c
35126 +++ b/drivers/mtd/nftlmount.c
35127 @@ -24,6 +24,7 @@
35128 #include <asm/errno.h>
35129 #include <linux/delay.h>
35130 #include <linux/slab.h>
35131 +#include <linux/sched.h>
35132 #include <linux/mtd/mtd.h>
35133 #include <linux/mtd/nand.h>
35134 #include <linux/mtd/nftl.h>
35135 diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
35136 index dc15d24..ef8d2a0 100644
35137 --- a/drivers/net/bonding/bond_sysfs.c
35138 +++ b/drivers/net/bonding/bond_sysfs.c
35139 @@ -1060,7 +1060,7 @@ static ssize_t bonding_store_primary(struct device *d,
35140 goto out;
35141 }
35142
35143 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
35144 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
35145
35146 /* check to see if we are clearing primary */
35147 if (!strlen(ifname) || buf[0] == '\n') {
35148 @@ -1237,7 +1237,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
35149 goto out;
35150 }
35151
35152 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
35153 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
35154
35155 /* check to see if we are clearing active */
35156 if (!strlen(ifname) || buf[0] == '\n') {
35157 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
35158 index 57d64b8..623dd86 100644
35159 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
35160 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
35161 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
35162 */
35163
35164 #define ATL2_PARAM(X, desc) \
35165 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
35166 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
35167 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
35168 MODULE_PARM_DESC(X, desc);
35169 #else
35170 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35171 index 0875ecf..794cdf3 100644
35172 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35173 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35174 @@ -3051,9 +3051,8 @@ static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
35175 struct eth_stats_info *ether_stat =
35176 &bp->slowpath->drv_info_to_mcp.ether_stat;
35177
35178 - /* leave last char as NULL */
35179 - memcpy(ether_stat->version, DRV_MODULE_VERSION,
35180 - ETH_STAT_INFO_VERSION_LEN - 1);
35181 + strlcpy(ether_stat->version, DRV_MODULE_VERSION,
35182 + ETH_STAT_INFO_VERSION_LEN);
35183
35184 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
35185 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
35186 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35187 index f83e033..8b4f43a 100644
35188 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35189 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35190 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
35191
35192 int (*wait_comp)(struct bnx2x *bp,
35193 struct bnx2x_rx_mode_ramrod_params *p);
35194 -};
35195 +} __no_const;
35196
35197 /********************** Set multicast group ***********************************/
35198
35199 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
35200 index 6d52cb2..bc95640 100644
35201 --- a/drivers/net/ethernet/broadcom/tg3.h
35202 +++ b/drivers/net/ethernet/broadcom/tg3.h
35203 @@ -140,6 +140,7 @@
35204 #define CHIPREV_ID_5750_A0 0x4000
35205 #define CHIPREV_ID_5750_A1 0x4001
35206 #define CHIPREV_ID_5750_A3 0x4003
35207 +#define CHIPREV_ID_5750_C1 0x4201
35208 #define CHIPREV_ID_5750_C2 0x4202
35209 #define CHIPREV_ID_5752_A0_HW 0x5000
35210 #define CHIPREV_ID_5752_A0 0x6000
35211 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35212 index 8cffcdf..aadf043 100644
35213 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35214 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35215 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
35216 */
35217 struct l2t_skb_cb {
35218 arp_failure_handler_func arp_failure_handler;
35219 -};
35220 +} __no_const;
35221
35222 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
35223
35224 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
35225 index f879e92..726f20f 100644
35226 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
35227 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
35228 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35229 for (i=0; i<ETH_ALEN; i++) {
35230 tmp.addr[i] = dev->dev_addr[i];
35231 }
35232 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35233 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35234 break;
35235
35236 case DE4X5_SET_HWADDR: /* Set the hardware address */
35237 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35238 spin_lock_irqsave(&lp->lock, flags);
35239 memcpy(&statbuf, &lp->pktStats, ioc->len);
35240 spin_unlock_irqrestore(&lp->lock, flags);
35241 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
35242 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35243 return -EFAULT;
35244 break;
35245 }
35246 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
35247 index ed7d1dc..d426748 100644
35248 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
35249 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
35250 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
35251 {NULL}};
35252
35253
35254 -static const char *block_name[] __devinitdata = {
35255 +static const char *block_name[] __devinitconst = {
35256 "21140 non-MII",
35257 "21140 MII PHY",
35258 "21142 Serial PHY",
35259 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
35260 index 75d45f8..3d9c55b 100644
35261 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
35262 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
35263 @@ -129,7 +129,7 @@ struct uli526x_board_info {
35264 struct uli_phy_ops {
35265 void (*write)(struct uli526x_board_info *, u8, u8, u16);
35266 u16 (*read)(struct uli526x_board_info *, u8, u8);
35267 - } phy;
35268 + } __no_const phy;
35269 struct net_device *next_dev; /* next device */
35270 struct pci_dev *pdev; /* PCI device */
35271 spinlock_t lock;
35272 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
35273 index 4d1ffca..7c1ec4d 100644
35274 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
35275 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
35276 @@ -236,7 +236,7 @@ struct pci_id_info {
35277 int drv_flags; /* Driver use, intended as capability flags. */
35278 };
35279
35280 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35281 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35282 { /* Sometime a Level-One switch card. */
35283 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
35284 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
35285 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
35286 index d7bb52a..3b83588 100644
35287 --- a/drivers/net/ethernet/dlink/sundance.c
35288 +++ b/drivers/net/ethernet/dlink/sundance.c
35289 @@ -218,7 +218,7 @@ enum {
35290 struct pci_id_info {
35291 const char *name;
35292 };
35293 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35294 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35295 {"D-Link DFE-550TX FAST Ethernet Adapter"},
35296 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
35297 {"D-Link DFE-580TX 4 port Server Adapter"},
35298 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
35299 index 78b8aa8..dd6323a 100644
35300 --- a/drivers/net/ethernet/emulex/benet/be_main.c
35301 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
35302 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
35303
35304 if (wrapped)
35305 newacc += 65536;
35306 - ACCESS_ONCE(*acc) = newacc;
35307 + ACCESS_ONCE_RW(*acc) = newacc;
35308 }
35309
35310 void be_parse_stats(struct be_adapter *adapter)
35311 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
35312 index 74d749e..eefb1bd 100644
35313 --- a/drivers/net/ethernet/faraday/ftgmac100.c
35314 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
35315 @@ -31,6 +31,8 @@
35316 #include <linux/netdevice.h>
35317 #include <linux/phy.h>
35318 #include <linux/platform_device.h>
35319 +#include <linux/interrupt.h>
35320 +#include <linux/irqreturn.h>
35321 #include <net/ip.h>
35322
35323 #include "ftgmac100.h"
35324 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
35325 index b901a01..1ff32ee 100644
35326 --- a/drivers/net/ethernet/faraday/ftmac100.c
35327 +++ b/drivers/net/ethernet/faraday/ftmac100.c
35328 @@ -31,6 +31,8 @@
35329 #include <linux/module.h>
35330 #include <linux/netdevice.h>
35331 #include <linux/platform_device.h>
35332 +#include <linux/interrupt.h>
35333 +#include <linux/irqreturn.h>
35334
35335 #include "ftmac100.h"
35336
35337 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
35338 index 9d71c9c..0e4a0ac 100644
35339 --- a/drivers/net/ethernet/fealnx.c
35340 +++ b/drivers/net/ethernet/fealnx.c
35341 @@ -150,7 +150,7 @@ struct chip_info {
35342 int flags;
35343 };
35344
35345 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35346 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35347 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35348 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35349 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35350 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35351 index ed5b409..ec37828 100644
35352 --- a/drivers/net/ethernet/intel/e1000e/hw.h
35353 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
35354 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
35355 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35356 s32 (*read_mac_addr)(struct e1000_hw *);
35357 };
35358 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35359
35360 /*
35361 * When to use various PHY register access functions:
35362 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
35363 void (*power_up)(struct e1000_hw *);
35364 void (*power_down)(struct e1000_hw *);
35365 };
35366 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35367
35368 /* Function pointers for the NVM. */
35369 struct e1000_nvm_operations {
35370 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35371 s32 (*validate)(struct e1000_hw *);
35372 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35373 };
35374 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35375
35376 struct e1000_mac_info {
35377 - struct e1000_mac_operations ops;
35378 + e1000_mac_operations_no_const ops;
35379 u8 addr[ETH_ALEN];
35380 u8 perm_addr[ETH_ALEN];
35381
35382 @@ -892,7 +895,7 @@ struct e1000_mac_info {
35383 };
35384
35385 struct e1000_phy_info {
35386 - struct e1000_phy_operations ops;
35387 + e1000_phy_operations_no_const ops;
35388
35389 enum e1000_phy_type type;
35390
35391 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35392 };
35393
35394 struct e1000_nvm_info {
35395 - struct e1000_nvm_operations ops;
35396 + e1000_nvm_operations_no_const ops;
35397
35398 enum e1000_nvm_type type;
35399 enum e1000_nvm_override override;
35400 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35401 index c2a51dc..c2bd262 100644
35402 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35403 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35404 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35405 void (*release_swfw_sync)(struct e1000_hw *, u16);
35406
35407 };
35408 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35409
35410 struct e1000_phy_operations {
35411 s32 (*acquire)(struct e1000_hw *);
35412 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35413 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35414 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35415 };
35416 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35417
35418 struct e1000_nvm_operations {
35419 s32 (*acquire)(struct e1000_hw *);
35420 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35421 s32 (*validate)(struct e1000_hw *);
35422 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35423 };
35424 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35425
35426 struct e1000_info {
35427 s32 (*get_invariants)(struct e1000_hw *);
35428 @@ -364,7 +367,7 @@ struct e1000_info {
35429 extern const struct e1000_info e1000_82575_info;
35430
35431 struct e1000_mac_info {
35432 - struct e1000_mac_operations ops;
35433 + e1000_mac_operations_no_const ops;
35434
35435 u8 addr[6];
35436 u8 perm_addr[6];
35437 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35438 };
35439
35440 struct e1000_phy_info {
35441 - struct e1000_phy_operations ops;
35442 + e1000_phy_operations_no_const ops;
35443
35444 enum e1000_phy_type type;
35445
35446 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35447 };
35448
35449 struct e1000_nvm_info {
35450 - struct e1000_nvm_operations ops;
35451 + e1000_nvm_operations_no_const ops;
35452 enum e1000_nvm_type type;
35453 enum e1000_nvm_override override;
35454
35455 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35456 s32 (*check_for_ack)(struct e1000_hw *, u16);
35457 s32 (*check_for_rst)(struct e1000_hw *, u16);
35458 };
35459 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35460
35461 struct e1000_mbx_stats {
35462 u32 msgs_tx;
35463 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35464 };
35465
35466 struct e1000_mbx_info {
35467 - struct e1000_mbx_operations ops;
35468 + e1000_mbx_operations_no_const ops;
35469 struct e1000_mbx_stats stats;
35470 u32 timeout;
35471 u32 usec_delay;
35472 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35473 index 57db3c6..aa825fc 100644
35474 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35475 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35476 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35477 s32 (*read_mac_addr)(struct e1000_hw *);
35478 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35479 };
35480 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35481
35482 struct e1000_mac_info {
35483 - struct e1000_mac_operations ops;
35484 + e1000_mac_operations_no_const ops;
35485 u8 addr[6];
35486 u8 perm_addr[6];
35487
35488 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35489 s32 (*check_for_ack)(struct e1000_hw *);
35490 s32 (*check_for_rst)(struct e1000_hw *);
35491 };
35492 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35493
35494 struct e1000_mbx_stats {
35495 u32 msgs_tx;
35496 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35497 };
35498
35499 struct e1000_mbx_info {
35500 - struct e1000_mbx_operations ops;
35501 + e1000_mbx_operations_no_const ops;
35502 struct e1000_mbx_stats stats;
35503 u32 timeout;
35504 u32 usec_delay;
35505 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35506 index 3456d56..b688d81 100644
35507 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35508 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35509 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35510 /* store the new cycle speed */
35511 adapter->cycle_speed = cycle_speed;
35512
35513 - ACCESS_ONCE(adapter->base_incval) = incval;
35514 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35515 smp_mb();
35516
35517 /* grab the ptp lock */
35518 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35519 index 400f86a..7f2e062 100644
35520 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35521 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35522 @@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35523 s32 (*update_checksum)(struct ixgbe_hw *);
35524 u16 (*calc_checksum)(struct ixgbe_hw *);
35525 };
35526 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35527
35528 struct ixgbe_mac_operations {
35529 s32 (*init_hw)(struct ixgbe_hw *);
35530 @@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35531 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35532 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35533 };
35534 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35535
35536 struct ixgbe_phy_operations {
35537 s32 (*identify)(struct ixgbe_hw *);
35538 @@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35539 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35540 s32 (*check_overtemp)(struct ixgbe_hw *);
35541 };
35542 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35543
35544 struct ixgbe_eeprom_info {
35545 - struct ixgbe_eeprom_operations ops;
35546 + ixgbe_eeprom_operations_no_const ops;
35547 enum ixgbe_eeprom_type type;
35548 u32 semaphore_delay;
35549 u16 word_size;
35550 @@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35551
35552 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35553 struct ixgbe_mac_info {
35554 - struct ixgbe_mac_operations ops;
35555 + ixgbe_mac_operations_no_const ops;
35556 enum ixgbe_mac_type type;
35557 u8 addr[ETH_ALEN];
35558 u8 perm_addr[ETH_ALEN];
35559 @@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35560 };
35561
35562 struct ixgbe_phy_info {
35563 - struct ixgbe_phy_operations ops;
35564 + ixgbe_phy_operations_no_const ops;
35565 struct mdio_if_info mdio;
35566 enum ixgbe_phy_type type;
35567 u32 id;
35568 @@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35569 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35570 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35571 };
35572 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35573
35574 struct ixgbe_mbx_stats {
35575 u32 msgs_tx;
35576 @@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35577 };
35578
35579 struct ixgbe_mbx_info {
35580 - struct ixgbe_mbx_operations ops;
35581 + ixgbe_mbx_operations_no_const ops;
35582 struct ixgbe_mbx_stats stats;
35583 u32 timeout;
35584 u32 usec_delay;
35585 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35586 index 25c951d..cc7cf33 100644
35587 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35588 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35589 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35590 s32 (*clear_vfta)(struct ixgbe_hw *);
35591 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35592 };
35593 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35594
35595 enum ixgbe_mac_type {
35596 ixgbe_mac_unknown = 0,
35597 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35598 };
35599
35600 struct ixgbe_mac_info {
35601 - struct ixgbe_mac_operations ops;
35602 + ixgbe_mac_operations_no_const ops;
35603 u8 addr[6];
35604 u8 perm_addr[6];
35605
35606 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35607 s32 (*check_for_ack)(struct ixgbe_hw *);
35608 s32 (*check_for_rst)(struct ixgbe_hw *);
35609 };
35610 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35611
35612 struct ixgbe_mbx_stats {
35613 u32 msgs_tx;
35614 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35615 };
35616
35617 struct ixgbe_mbx_info {
35618 - struct ixgbe_mbx_operations ops;
35619 + ixgbe_mbx_operations_no_const ops;
35620 struct ixgbe_mbx_stats stats;
35621 u32 timeout;
35622 u32 udelay;
35623 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35624 index 9e0c1ee..8471f77 100644
35625 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35626 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35627 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35628 void (*link_down)(struct __vxge_hw_device *devh);
35629 void (*crit_err)(struct __vxge_hw_device *devh,
35630 enum vxge_hw_event type, u64 ext_data);
35631 -};
35632 +} __no_const;
35633
35634 /*
35635 * struct __vxge_hw_blockpool_entry - Block private data structure
35636 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35637 index 4a518a3..936b334 100644
35638 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35639 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35640 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35641 struct vxge_hw_mempool_dma *dma_object,
35642 u32 index,
35643 u32 is_last);
35644 -};
35645 +} __no_const;
35646
35647 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35648 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35649 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35650 index b47d5b3..273a516 100644
35651 --- a/drivers/net/ethernet/realtek/r8169.c
35652 +++ b/drivers/net/ethernet/realtek/r8169.c
35653 @@ -745,22 +745,22 @@ struct rtl8169_private {
35654 struct mdio_ops {
35655 void (*write)(struct rtl8169_private *, int, int);
35656 int (*read)(struct rtl8169_private *, int);
35657 - } mdio_ops;
35658 + } __no_const mdio_ops;
35659
35660 struct pll_power_ops {
35661 void (*down)(struct rtl8169_private *);
35662 void (*up)(struct rtl8169_private *);
35663 - } pll_power_ops;
35664 + } __no_const pll_power_ops;
35665
35666 struct jumbo_ops {
35667 void (*enable)(struct rtl8169_private *);
35668 void (*disable)(struct rtl8169_private *);
35669 - } jumbo_ops;
35670 + } __no_const jumbo_ops;
35671
35672 struct csi_ops {
35673 void (*write)(struct rtl8169_private *, int, int);
35674 u32 (*read)(struct rtl8169_private *, int);
35675 - } csi_ops;
35676 + } __no_const csi_ops;
35677
35678 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35679 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35680 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35681 index 4613591..d816601 100644
35682 --- a/drivers/net/ethernet/sis/sis190.c
35683 +++ b/drivers/net/ethernet/sis/sis190.c
35684 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35685 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35686 struct net_device *dev)
35687 {
35688 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35689 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35690 struct sis190_private *tp = netdev_priv(dev);
35691 struct pci_dev *isa_bridge;
35692 u8 reg, tmp8;
35693 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35694 index 0c74a70..3bc6f68 100644
35695 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35696 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35697 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35698
35699 writel(value, ioaddr + MMC_CNTRL);
35700
35701 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35702 - MMC_CNTRL, value);
35703 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35704 +// MMC_CNTRL, value);
35705 }
35706
35707 /* To mask all all interrupts.*/
35708 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35709 index 95ceb35..318fc12 100644
35710 --- a/drivers/net/hyperv/hyperv_net.h
35711 +++ b/drivers/net/hyperv/hyperv_net.h
35712 @@ -99,7 +99,7 @@ struct rndis_device {
35713
35714 enum rndis_device_state state;
35715 bool link_state;
35716 - atomic_t new_req_id;
35717 + atomic_unchecked_t new_req_id;
35718
35719 spinlock_t request_lock;
35720 struct list_head req_list;
35721 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35722 index 1e88a10..1b01736 100644
35723 --- a/drivers/net/hyperv/rndis_filter.c
35724 +++ b/drivers/net/hyperv/rndis_filter.c
35725 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35726 * template
35727 */
35728 set = &rndis_msg->msg.set_req;
35729 - set->req_id = atomic_inc_return(&dev->new_req_id);
35730 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35731
35732 /* Add to the request list */
35733 spin_lock_irqsave(&dev->request_lock, flags);
35734 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35735
35736 /* Setup the rndis set */
35737 halt = &request->request_msg.msg.halt_req;
35738 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35739 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35740
35741 /* Ignore return since this msg is optional. */
35742 rndis_filter_send_request(dev, request);
35743 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35744 index daec9b0..6428fcb 100644
35745 --- a/drivers/net/phy/mdio-bitbang.c
35746 +++ b/drivers/net/phy/mdio-bitbang.c
35747 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35748 struct mdiobb_ctrl *ctrl = bus->priv;
35749
35750 module_put(ctrl->ops->owner);
35751 + mdiobus_unregister(bus);
35752 mdiobus_free(bus);
35753 }
35754 EXPORT_SYMBOL(free_mdio_bitbang);
35755 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35756 index 5c05572..389610b 100644
35757 --- a/drivers/net/ppp/ppp_generic.c
35758 +++ b/drivers/net/ppp/ppp_generic.c
35759 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35760 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35761 struct ppp_stats stats;
35762 struct ppp_comp_stats cstats;
35763 - char *vers;
35764
35765 switch (cmd) {
35766 case SIOCGPPPSTATS:
35767 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35768 break;
35769
35770 case SIOCGPPPVER:
35771 - vers = PPP_VERSION;
35772 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35773 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35774 break;
35775 err = 0;
35776 break;
35777 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35778 index 3a16d4f..a311cec 100644
35779 --- a/drivers/net/tun.c
35780 +++ b/drivers/net/tun.c
35781 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35782 }
35783
35784 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35785 - unsigned long arg, int ifreq_len)
35786 + unsigned long arg, size_t ifreq_len)
35787 {
35788 struct tun_file *tfile = file->private_data;
35789 struct tun_struct *tun;
35790 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35791 int vnet_hdr_sz;
35792 int ret;
35793
35794 + if (ifreq_len > sizeof ifr)
35795 + return -EFAULT;
35796 +
35797 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35798 if (copy_from_user(&ifr, argp, ifreq_len))
35799 return -EFAULT;
35800 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35801 index 62f30b4..ff99dfd 100644
35802 --- a/drivers/net/usb/hso.c
35803 +++ b/drivers/net/usb/hso.c
35804 @@ -71,7 +71,7 @@
35805 #include <asm/byteorder.h>
35806 #include <linux/serial_core.h>
35807 #include <linux/serial.h>
35808 -
35809 +#include <asm/local.h>
35810
35811 #define MOD_AUTHOR "Option Wireless"
35812 #define MOD_DESCRIPTION "USB High Speed Option driver"
35813 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35814 struct urb *urb;
35815
35816 urb = serial->rx_urb[0];
35817 - if (serial->port.count > 0) {
35818 + if (atomic_read(&serial->port.count) > 0) {
35819 count = put_rxbuf_data(urb, serial);
35820 if (count == -1)
35821 return;
35822 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35823 DUMP1(urb->transfer_buffer, urb->actual_length);
35824
35825 /* Anyone listening? */
35826 - if (serial->port.count == 0)
35827 + if (atomic_read(&serial->port.count) == 0)
35828 return;
35829
35830 if (status == 0) {
35831 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35832 tty_port_tty_set(&serial->port, tty);
35833
35834 /* check for port already opened, if not set the termios */
35835 - serial->port.count++;
35836 - if (serial->port.count == 1) {
35837 + if (atomic_inc_return(&serial->port.count) == 1) {
35838 serial->rx_state = RX_IDLE;
35839 /* Force default termio settings */
35840 _hso_serial_set_termios(tty, NULL);
35841 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35842 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35843 if (result) {
35844 hso_stop_serial_device(serial->parent);
35845 - serial->port.count--;
35846 + atomic_dec(&serial->port.count);
35847 kref_put(&serial->parent->ref, hso_serial_ref_free);
35848 }
35849 } else {
35850 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35851
35852 /* reset the rts and dtr */
35853 /* do the actual close */
35854 - serial->port.count--;
35855 + atomic_dec(&serial->port.count);
35856
35857 - if (serial->port.count <= 0) {
35858 - serial->port.count = 0;
35859 + if (atomic_read(&serial->port.count) <= 0) {
35860 + atomic_set(&serial->port.count, 0);
35861 tty_port_tty_set(&serial->port, NULL);
35862 if (!usb_gone)
35863 hso_stop_serial_device(serial->parent);
35864 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35865
35866 /* the actual setup */
35867 spin_lock_irqsave(&serial->serial_lock, flags);
35868 - if (serial->port.count)
35869 + if (atomic_read(&serial->port.count))
35870 _hso_serial_set_termios(tty, old);
35871 else
35872 tty->termios = old;
35873 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35874 D1("Pending read interrupt on port %d\n", i);
35875 spin_lock(&serial->serial_lock);
35876 if (serial->rx_state == RX_IDLE &&
35877 - serial->port.count > 0) {
35878 + atomic_read(&serial->port.count) > 0) {
35879 /* Setup and send a ctrl req read on
35880 * port i */
35881 if (!serial->rx_urb_filled[0]) {
35882 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35883 /* Start all serial ports */
35884 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35885 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35886 - if (dev2ser(serial_table[i])->port.count) {
35887 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35888 result =
35889 hso_start_serial_device(serial_table[i], GFP_NOIO);
35890 hso_kick_transmit(dev2ser(serial_table[i]));
35891 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35892 index 6169fbd..40e8422 100644
35893 --- a/drivers/net/wireless/ath/ath.h
35894 +++ b/drivers/net/wireless/ath/ath.h
35895 @@ -119,6 +119,7 @@ struct ath_ops {
35896 void (*write_flush) (void *);
35897 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35898 };
35899 +typedef struct ath_ops __no_const ath_ops_no_const;
35900
35901 struct ath_common;
35902 struct ath_bus_ops;
35903 diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
35904 index 2aab20e..b761ef8 100644
35905 --- a/drivers/net/wireless/ath/ath5k/base.c
35906 +++ b/drivers/net/wireless/ath/ath5k/base.c
35907 @@ -1803,7 +1803,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35908 {
35909 int ret;
35910 struct ath5k_hw *ah = hw->priv;
35911 - struct ath5k_vif *avf = (void *)vif->drv_priv;
35912 + struct ath5k_vif *avf;
35913 struct sk_buff *skb;
35914
35915 if (WARN_ON(!vif)) {
35916 @@ -1818,6 +1818,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35917 goto out;
35918 }
35919
35920 + avf = (void *)vif->drv_priv;
35921 ath5k_txbuf_free_skb(ah, avf->bbuf);
35922 avf->bbuf->skb = skb;
35923 ret = ath5k_beacon_setup(ah, avf->bbuf);
35924 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35925 index 8d78253..bebbb68 100644
35926 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35927 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35928 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35929 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35930 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35931
35932 - ACCESS_ONCE(ads->ds_link) = i->link;
35933 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35934 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35935 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35936
35937 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35938 ctl6 = SM(i->keytype, AR_EncrType);
35939 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35940
35941 if ((i->is_first || i->is_last) &&
35942 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35943 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35944 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35945 | set11nTries(i->rates, 1)
35946 | set11nTries(i->rates, 2)
35947 | set11nTries(i->rates, 3)
35948 | (i->dur_update ? AR_DurUpdateEna : 0)
35949 | SM(0, AR_BurstDur);
35950
35951 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35952 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35953 | set11nRate(i->rates, 1)
35954 | set11nRate(i->rates, 2)
35955 | set11nRate(i->rates, 3);
35956 } else {
35957 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35958 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35959 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35960 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35961 }
35962
35963 if (!i->is_first) {
35964 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35965 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35966 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35967 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35968 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35969 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35970 return;
35971 }
35972
35973 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35974 break;
35975 }
35976
35977 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35978 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35979 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35980 | SM(i->txpower, AR_XmitPower)
35981 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35982 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35983 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35984 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35985
35986 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35987 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35988 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35989 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35990
35991 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35992 return;
35993
35994 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35995 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35996 | set11nPktDurRTSCTS(i->rates, 1);
35997
35998 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35999 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36000 | set11nPktDurRTSCTS(i->rates, 3);
36001
36002 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36003 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36004 | set11nRateFlags(i->rates, 1)
36005 | set11nRateFlags(i->rates, 2)
36006 | set11nRateFlags(i->rates, 3)
36007 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36008 index 78816b8..1fcdfae 100644
36009 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36010 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36011 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36012 (i->qcu << AR_TxQcuNum_S) | desc_len;
36013
36014 checksum += val;
36015 - ACCESS_ONCE(ads->info) = val;
36016 + ACCESS_ONCE_RW(ads->info) = val;
36017
36018 checksum += i->link;
36019 - ACCESS_ONCE(ads->link) = i->link;
36020 + ACCESS_ONCE_RW(ads->link) = i->link;
36021
36022 checksum += i->buf_addr[0];
36023 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
36024 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
36025 checksum += i->buf_addr[1];
36026 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
36027 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
36028 checksum += i->buf_addr[2];
36029 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
36030 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
36031 checksum += i->buf_addr[3];
36032 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
36033 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
36034
36035 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
36036 - ACCESS_ONCE(ads->ctl3) = val;
36037 + ACCESS_ONCE_RW(ads->ctl3) = val;
36038 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
36039 - ACCESS_ONCE(ads->ctl5) = val;
36040 + ACCESS_ONCE_RW(ads->ctl5) = val;
36041 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
36042 - ACCESS_ONCE(ads->ctl7) = val;
36043 + ACCESS_ONCE_RW(ads->ctl7) = val;
36044 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
36045 - ACCESS_ONCE(ads->ctl9) = val;
36046 + ACCESS_ONCE_RW(ads->ctl9) = val;
36047
36048 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
36049 - ACCESS_ONCE(ads->ctl10) = checksum;
36050 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
36051
36052 if (i->is_first || i->is_last) {
36053 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
36054 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
36055 | set11nTries(i->rates, 1)
36056 | set11nTries(i->rates, 2)
36057 | set11nTries(i->rates, 3)
36058 | (i->dur_update ? AR_DurUpdateEna : 0)
36059 | SM(0, AR_BurstDur);
36060
36061 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
36062 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
36063 | set11nRate(i->rates, 1)
36064 | set11nRate(i->rates, 2)
36065 | set11nRate(i->rates, 3);
36066 } else {
36067 - ACCESS_ONCE(ads->ctl13) = 0;
36068 - ACCESS_ONCE(ads->ctl14) = 0;
36069 + ACCESS_ONCE_RW(ads->ctl13) = 0;
36070 + ACCESS_ONCE_RW(ads->ctl14) = 0;
36071 }
36072
36073 ads->ctl20 = 0;
36074 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36075
36076 ctl17 = SM(i->keytype, AR_EncrType);
36077 if (!i->is_first) {
36078 - ACCESS_ONCE(ads->ctl11) = 0;
36079 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36080 - ACCESS_ONCE(ads->ctl15) = 0;
36081 - ACCESS_ONCE(ads->ctl16) = 0;
36082 - ACCESS_ONCE(ads->ctl17) = ctl17;
36083 - ACCESS_ONCE(ads->ctl18) = 0;
36084 - ACCESS_ONCE(ads->ctl19) = 0;
36085 + ACCESS_ONCE_RW(ads->ctl11) = 0;
36086 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36087 + ACCESS_ONCE_RW(ads->ctl15) = 0;
36088 + ACCESS_ONCE_RW(ads->ctl16) = 0;
36089 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36090 + ACCESS_ONCE_RW(ads->ctl18) = 0;
36091 + ACCESS_ONCE_RW(ads->ctl19) = 0;
36092 return;
36093 }
36094
36095 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36096 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36097 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36098 | SM(i->txpower, AR_XmitPower)
36099 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36100 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36101 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
36102 ctl12 |= SM(val, AR_PAPRDChainMask);
36103
36104 - ACCESS_ONCE(ads->ctl12) = ctl12;
36105 - ACCESS_ONCE(ads->ctl17) = ctl17;
36106 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
36107 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36108
36109 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36110 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36111 | set11nPktDurRTSCTS(i->rates, 1);
36112
36113 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36114 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36115 | set11nPktDurRTSCTS(i->rates, 3);
36116
36117 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
36118 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
36119 | set11nRateFlags(i->rates, 1)
36120 | set11nRateFlags(i->rates, 2)
36121 | set11nRateFlags(i->rates, 3)
36122 | SM(i->rtscts_rate, AR_RTSCTSRate);
36123
36124 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
36125 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
36126 }
36127
36128 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
36129 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
36130 index de6968f..29ac4c1 100644
36131 --- a/drivers/net/wireless/ath/ath9k/hw.h
36132 +++ b/drivers/net/wireless/ath/ath9k/hw.h
36133 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
36134
36135 /* ANI */
36136 void (*ani_cache_ini_regs)(struct ath_hw *ah);
36137 -};
36138 +} __no_const;
36139
36140 /**
36141 * struct ath_hw_ops - callbacks used by hardware code and driver code
36142 @@ -686,7 +686,7 @@ struct ath_hw_ops {
36143 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
36144 struct ath_hw_antcomb_conf *antconf);
36145
36146 -};
36147 +} __no_const;
36148
36149 struct ath_nf_limits {
36150 s16 max;
36151 @@ -706,7 +706,7 @@ enum ath_cal_list {
36152 #define AH_FASTCC 0x4
36153
36154 struct ath_hw {
36155 - struct ath_ops reg_ops;
36156 + ath_ops_no_const reg_ops;
36157
36158 struct ieee80211_hw *hw;
36159 struct ath_common common;
36160 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36161 index af00e2c..ab04d34 100644
36162 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36163 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36164 @@ -545,7 +545,7 @@ struct phy_func_ptr {
36165 void (*carrsuppr)(struct brcms_phy *);
36166 s32 (*rxsigpwr)(struct brcms_phy *, s32);
36167 void (*detach)(struct brcms_phy *);
36168 -};
36169 +} __no_const;
36170
36171 struct brcms_phy {
36172 struct brcms_phy_pub pubpi_ro;
36173 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
36174 index faec404..a5277f1 100644
36175 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
36176 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
36177 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
36178 */
36179 if (il3945_mod_params.disable_hw_scan) {
36180 D_INFO("Disabling hw_scan\n");
36181 - il3945_mac_ops.hw_scan = NULL;
36182 + pax_open_kernel();
36183 + *(void **)&il3945_mac_ops.hw_scan = NULL;
36184 + pax_close_kernel();
36185 }
36186
36187 D_INFO("*** LOAD DRIVER ***\n");
36188 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36189 index a47b306..297daf2 100644
36190 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36191 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36192 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
36193 {
36194 struct iwl_priv *priv = file->private_data;
36195 char buf[64];
36196 - int buf_size;
36197 + size_t buf_size;
36198 u32 offset, len;
36199
36200 memset(buf, 0, sizeof(buf));
36201 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
36202 struct iwl_priv *priv = file->private_data;
36203
36204 char buf[8];
36205 - int buf_size;
36206 + size_t buf_size;
36207 u32 reset_flag;
36208
36209 memset(buf, 0, sizeof(buf));
36210 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
36211 {
36212 struct iwl_priv *priv = file->private_data;
36213 char buf[8];
36214 - int buf_size;
36215 + size_t buf_size;
36216 int ht40;
36217
36218 memset(buf, 0, sizeof(buf));
36219 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
36220 {
36221 struct iwl_priv *priv = file->private_data;
36222 char buf[8];
36223 - int buf_size;
36224 + size_t buf_size;
36225 int value;
36226
36227 memset(buf, 0, sizeof(buf));
36228 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
36229 {
36230 struct iwl_priv *priv = file->private_data;
36231 char buf[8];
36232 - int buf_size;
36233 + size_t buf_size;
36234 int clear;
36235
36236 memset(buf, 0, sizeof(buf));
36237 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
36238 {
36239 struct iwl_priv *priv = file->private_data;
36240 char buf[8];
36241 - int buf_size;
36242 + size_t buf_size;
36243 int trace;
36244
36245 memset(buf, 0, sizeof(buf));
36246 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
36247 {
36248 struct iwl_priv *priv = file->private_data;
36249 char buf[8];
36250 - int buf_size;
36251 + size_t buf_size;
36252 int missed;
36253
36254 memset(buf, 0, sizeof(buf));
36255 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
36256
36257 struct iwl_priv *priv = file->private_data;
36258 char buf[8];
36259 - int buf_size;
36260 + size_t buf_size;
36261 int plcp;
36262
36263 memset(buf, 0, sizeof(buf));
36264 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
36265
36266 struct iwl_priv *priv = file->private_data;
36267 char buf[8];
36268 - int buf_size;
36269 + size_t buf_size;
36270 int flush;
36271
36272 memset(buf, 0, sizeof(buf));
36273 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
36274
36275 struct iwl_priv *priv = file->private_data;
36276 char buf[8];
36277 - int buf_size;
36278 + size_t buf_size;
36279 int rts;
36280
36281 if (!priv->cfg->ht_params)
36282 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
36283 {
36284 struct iwl_priv *priv = file->private_data;
36285 char buf[8];
36286 - int buf_size;
36287 + size_t buf_size;
36288
36289 memset(buf, 0, sizeof(buf));
36290 buf_size = min(count, sizeof(buf) - 1);
36291 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
36292 struct iwl_priv *priv = file->private_data;
36293 u32 event_log_flag;
36294 char buf[8];
36295 - int buf_size;
36296 + size_t buf_size;
36297
36298 /* check that the interface is up */
36299 if (!iwl_is_ready(priv))
36300 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
36301 struct iwl_priv *priv = file->private_data;
36302 char buf[8];
36303 u32 calib_disabled;
36304 - int buf_size;
36305 + size_t buf_size;
36306
36307 memset(buf, 0, sizeof(buf));
36308 buf_size = min(count, sizeof(buf) - 1);
36309 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
36310 index dbeebef..b45a152 100644
36311 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
36312 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
36313 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
36314 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
36315
36316 char buf[8];
36317 - int buf_size;
36318 + size_t buf_size;
36319 u32 reset_flag;
36320
36321 memset(buf, 0, sizeof(buf));
36322 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36323 {
36324 struct iwl_trans *trans = file->private_data;
36325 char buf[8];
36326 - int buf_size;
36327 + size_t buf_size;
36328 int csr;
36329
36330 memset(buf, 0, sizeof(buf));
36331 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36332 index 0083839..fcb7225 100644
36333 --- a/drivers/net/wireless/mac80211_hwsim.c
36334 +++ b/drivers/net/wireless/mac80211_hwsim.c
36335 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
36336 return -EINVAL;
36337
36338 if (fake_hw_scan) {
36339 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36340 - mac80211_hwsim_ops.sw_scan_start = NULL;
36341 - mac80211_hwsim_ops.sw_scan_complete = NULL;
36342 + pax_open_kernel();
36343 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36344 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36345 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36346 + pax_close_kernel();
36347 }
36348
36349 spin_lock_init(&hwsim_radio_lock);
36350 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36351 index e7c2a82..582e228 100644
36352 --- a/drivers/net/wireless/mwifiex/main.h
36353 +++ b/drivers/net/wireless/mwifiex/main.h
36354 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
36355 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36356 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
36357 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
36358 -};
36359 +} __no_const;
36360
36361 struct mwifiex_adapter {
36362 u8 iface_type;
36363 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36364 index 7a4ae9e..56e00bd 100644
36365 --- a/drivers/net/wireless/rndis_wlan.c
36366 +++ b/drivers/net/wireless/rndis_wlan.c
36367 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36368
36369 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36370
36371 - if (rts_threshold < 0 || rts_threshold > 2347)
36372 + if (rts_threshold > 2347)
36373 rts_threshold = 2347;
36374
36375 tmp = cpu_to_le32(rts_threshold);
36376 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36377 index 8afb546..0c0dc5c 100644
36378 --- a/drivers/net/wireless/rt2x00/rt2x00.h
36379 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
36380 @@ -397,7 +397,7 @@ struct rt2x00_intf {
36381 * for hardware which doesn't support hardware
36382 * sequence counting.
36383 */
36384 - atomic_t seqno;
36385 + atomic_unchecked_t seqno;
36386 };
36387
36388 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36389 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36390 index f7e74a0..da71431 100644
36391 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36392 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36393 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36394 * sequence counter given by mac80211.
36395 */
36396 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36397 - seqno = atomic_add_return(0x10, &intf->seqno);
36398 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36399 else
36400 - seqno = atomic_read(&intf->seqno);
36401 + seqno = atomic_read_unchecked(&intf->seqno);
36402
36403 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36404 hdr->seq_ctrl |= cpu_to_le16(seqno);
36405 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36406 index fd02060..74ee481 100644
36407 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
36408 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36409 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
36410 void (*reset)(struct wl1251 *wl);
36411 void (*enable_irq)(struct wl1251 *wl);
36412 void (*disable_irq)(struct wl1251 *wl);
36413 -};
36414 +} __no_const;
36415
36416 struct wl1251 {
36417 struct ieee80211_hw *hw;
36418 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36419 index 0ce7a8e..56a0ccf 100644
36420 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36421 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36422 @@ -81,7 +81,7 @@ struct wlcore_ops {
36423 struct ieee80211_sta *sta,
36424 struct ieee80211_key_conf *key_conf);
36425 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36426 -};
36427 +} __no_const;
36428
36429 enum wlcore_partitions {
36430 PART_DOWN,
36431 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36432 index f34b5b2..b5abb9f 100644
36433 --- a/drivers/oprofile/buffer_sync.c
36434 +++ b/drivers/oprofile/buffer_sync.c
36435 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36436 if (cookie == NO_COOKIE)
36437 offset = pc;
36438 if (cookie == INVALID_COOKIE) {
36439 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36440 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36441 offset = pc;
36442 }
36443 if (cookie != last_cookie) {
36444 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36445 /* add userspace sample */
36446
36447 if (!mm) {
36448 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36449 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36450 return 0;
36451 }
36452
36453 cookie = lookup_dcookie(mm, s->eip, &offset);
36454
36455 if (cookie == INVALID_COOKIE) {
36456 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36457 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36458 return 0;
36459 }
36460
36461 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36462 /* ignore backtraces if failed to add a sample */
36463 if (state == sb_bt_start) {
36464 state = sb_bt_ignore;
36465 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36466 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36467 }
36468 }
36469 release_mm(mm);
36470 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36471 index c0cc4e7..44d4e54 100644
36472 --- a/drivers/oprofile/event_buffer.c
36473 +++ b/drivers/oprofile/event_buffer.c
36474 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36475 }
36476
36477 if (buffer_pos == buffer_size) {
36478 - atomic_inc(&oprofile_stats.event_lost_overflow);
36479 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36480 return;
36481 }
36482
36483 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36484 index ed2c3ec..deda85a 100644
36485 --- a/drivers/oprofile/oprof.c
36486 +++ b/drivers/oprofile/oprof.c
36487 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36488 if (oprofile_ops.switch_events())
36489 return;
36490
36491 - atomic_inc(&oprofile_stats.multiplex_counter);
36492 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36493 start_switch_worker();
36494 }
36495
36496 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36497 index 917d28e..d62d981 100644
36498 --- a/drivers/oprofile/oprofile_stats.c
36499 +++ b/drivers/oprofile/oprofile_stats.c
36500 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36501 cpu_buf->sample_invalid_eip = 0;
36502 }
36503
36504 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36505 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36506 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36507 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36508 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36509 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36510 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36511 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36512 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36513 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36514 }
36515
36516
36517 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36518 index 38b6fc0..b5cbfce 100644
36519 --- a/drivers/oprofile/oprofile_stats.h
36520 +++ b/drivers/oprofile/oprofile_stats.h
36521 @@ -13,11 +13,11 @@
36522 #include <linux/atomic.h>
36523
36524 struct oprofile_stat_struct {
36525 - atomic_t sample_lost_no_mm;
36526 - atomic_t sample_lost_no_mapping;
36527 - atomic_t bt_lost_no_mapping;
36528 - atomic_t event_lost_overflow;
36529 - atomic_t multiplex_counter;
36530 + atomic_unchecked_t sample_lost_no_mm;
36531 + atomic_unchecked_t sample_lost_no_mapping;
36532 + atomic_unchecked_t bt_lost_no_mapping;
36533 + atomic_unchecked_t event_lost_overflow;
36534 + atomic_unchecked_t multiplex_counter;
36535 };
36536
36537 extern struct oprofile_stat_struct oprofile_stats;
36538 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36539 index 849357c..b83c1e0 100644
36540 --- a/drivers/oprofile/oprofilefs.c
36541 +++ b/drivers/oprofile/oprofilefs.c
36542 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36543
36544
36545 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36546 - char const *name, atomic_t *val)
36547 + char const *name, atomic_unchecked_t *val)
36548 {
36549 return __oprofilefs_create_file(sb, root, name,
36550 &atomic_ro_fops, 0444, val);
36551 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36552 index 3f56bc0..707d642 100644
36553 --- a/drivers/parport/procfs.c
36554 +++ b/drivers/parport/procfs.c
36555 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36556
36557 *ppos += len;
36558
36559 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36560 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36561 }
36562
36563 #ifdef CONFIG_PARPORT_1284
36564 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36565
36566 *ppos += len;
36567
36568 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36569 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36570 }
36571 #endif /* IEEE1284.3 support. */
36572
36573 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36574 index 9fff878..ad0ad53 100644
36575 --- a/drivers/pci/hotplug/cpci_hotplug.h
36576 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36577 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36578 int (*hardware_test) (struct slot* slot, u32 value);
36579 u8 (*get_power) (struct slot* slot);
36580 int (*set_power) (struct slot* slot, int value);
36581 -};
36582 +} __no_const;
36583
36584 struct cpci_hp_controller {
36585 unsigned int irq;
36586 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36587 index 76ba8a1..20ca857 100644
36588 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36589 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36590 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36591
36592 void compaq_nvram_init (void __iomem *rom_start)
36593 {
36594 +
36595 +#ifndef CONFIG_PAX_KERNEXEC
36596 if (rom_start) {
36597 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36598 }
36599 +#endif
36600 +
36601 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36602
36603 /* initialize our int15 lock */
36604 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36605 index b500840..d7159d3 100644
36606 --- a/drivers/pci/pcie/aspm.c
36607 +++ b/drivers/pci/pcie/aspm.c
36608 @@ -27,9 +27,9 @@
36609 #define MODULE_PARAM_PREFIX "pcie_aspm."
36610
36611 /* Note: those are not register definitions */
36612 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36613 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36614 -#define ASPM_STATE_L1 (4) /* L1 state */
36615 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36616 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36617 +#define ASPM_STATE_L1 (4U) /* L1 state */
36618 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36619 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36620
36621 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36622 index 61859d0..124539e 100644
36623 --- a/drivers/pci/probe.c
36624 +++ b/drivers/pci/probe.c
36625 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36626 struct pci_bus_region region;
36627 bool bar_too_big = false, bar_disabled = false;
36628
36629 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36630 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36631
36632 /* No printks while decoding is disabled! */
36633 if (!dev->mmio_always_on) {
36634 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36635 index 27911b5..5b6db88 100644
36636 --- a/drivers/pci/proc.c
36637 +++ b/drivers/pci/proc.c
36638 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36639 static int __init pci_proc_init(void)
36640 {
36641 struct pci_dev *dev = NULL;
36642 +
36643 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36644 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36645 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36646 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36647 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36648 +#endif
36649 +#else
36650 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36651 +#endif
36652 proc_create("devices", 0, proc_bus_pci_dir,
36653 &proc_bus_pci_dev_operations);
36654 proc_initialized = 1;
36655 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36656 index 52daaa8..d6b81eb 100644
36657 --- a/drivers/platform/x86/thinkpad_acpi.c
36658 +++ b/drivers/platform/x86/thinkpad_acpi.c
36659 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36660 return 0;
36661 }
36662
36663 -void static hotkey_mask_warn_incomplete_mask(void)
36664 +static void hotkey_mask_warn_incomplete_mask(void)
36665 {
36666 /* log only what the user can fix... */
36667 const u32 wantedmask = hotkey_driver_mask &
36668 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36669 }
36670 }
36671
36672 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36673 - struct tp_nvram_state *newn,
36674 - const u32 event_mask)
36675 -{
36676 -
36677 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36678 do { \
36679 if ((event_mask & (1 << __scancode)) && \
36680 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36681 tpacpi_hotkey_send_key(__scancode); \
36682 } while (0)
36683
36684 - void issue_volchange(const unsigned int oldvol,
36685 - const unsigned int newvol)
36686 - {
36687 - unsigned int i = oldvol;
36688 +static void issue_volchange(const unsigned int oldvol,
36689 + const unsigned int newvol,
36690 + const u32 event_mask)
36691 +{
36692 + unsigned int i = oldvol;
36693
36694 - while (i > newvol) {
36695 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36696 - i--;
36697 - }
36698 - while (i < newvol) {
36699 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36700 - i++;
36701 - }
36702 + while (i > newvol) {
36703 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36704 + i--;
36705 }
36706 + while (i < newvol) {
36707 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36708 + i++;
36709 + }
36710 +}
36711
36712 - void issue_brightnesschange(const unsigned int oldbrt,
36713 - const unsigned int newbrt)
36714 - {
36715 - unsigned int i = oldbrt;
36716 +static void issue_brightnesschange(const unsigned int oldbrt,
36717 + const unsigned int newbrt,
36718 + const u32 event_mask)
36719 +{
36720 + unsigned int i = oldbrt;
36721
36722 - while (i > newbrt) {
36723 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36724 - i--;
36725 - }
36726 - while (i < newbrt) {
36727 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36728 - i++;
36729 - }
36730 + while (i > newbrt) {
36731 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36732 + i--;
36733 + }
36734 + while (i < newbrt) {
36735 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36736 + i++;
36737 }
36738 +}
36739
36740 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36741 + struct tp_nvram_state *newn,
36742 + const u32 event_mask)
36743 +{
36744 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36745 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36746 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36747 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36748 oldn->volume_level != newn->volume_level) {
36749 /* recently muted, or repeated mute keypress, or
36750 * multiple presses ending in mute */
36751 - issue_volchange(oldn->volume_level, newn->volume_level);
36752 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36753 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36754 }
36755 } else {
36756 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36757 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36758 }
36759 if (oldn->volume_level != newn->volume_level) {
36760 - issue_volchange(oldn->volume_level, newn->volume_level);
36761 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36762 } else if (oldn->volume_toggle != newn->volume_toggle) {
36763 /* repeated vol up/down keypress at end of scale ? */
36764 if (newn->volume_level == 0)
36765 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36766 /* handle brightness */
36767 if (oldn->brightness_level != newn->brightness_level) {
36768 issue_brightnesschange(oldn->brightness_level,
36769 - newn->brightness_level);
36770 + newn->brightness_level,
36771 + event_mask);
36772 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36773 /* repeated key presses that didn't change state */
36774 if (newn->brightness_level == 0)
36775 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36776 && !tp_features.bright_unkfw)
36777 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36778 }
36779 +}
36780
36781 #undef TPACPI_COMPARE_KEY
36782 #undef TPACPI_MAY_SEND_KEY
36783 -}
36784
36785 /*
36786 * Polling driver
36787 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36788 index 769d265..a3a05ca 100644
36789 --- a/drivers/pnp/pnpbios/bioscalls.c
36790 +++ b/drivers/pnp/pnpbios/bioscalls.c
36791 @@ -58,7 +58,7 @@ do { \
36792 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36793 } while(0)
36794
36795 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36796 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36797 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36798
36799 /*
36800 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36801
36802 cpu = get_cpu();
36803 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36804 +
36805 + pax_open_kernel();
36806 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36807 + pax_close_kernel();
36808
36809 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36810 spin_lock_irqsave(&pnp_bios_lock, flags);
36811 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36812 :"memory");
36813 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36814
36815 + pax_open_kernel();
36816 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36817 + pax_close_kernel();
36818 +
36819 put_cpu();
36820
36821 /* If we get here and this is set then the PnP BIOS faulted on us. */
36822 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36823 return status;
36824 }
36825
36826 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36827 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36828 {
36829 int i;
36830
36831 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36832 pnp_bios_callpoint.offset = header->fields.pm16offset;
36833 pnp_bios_callpoint.segment = PNP_CS16;
36834
36835 + pax_open_kernel();
36836 +
36837 for_each_possible_cpu(i) {
36838 struct desc_struct *gdt = get_cpu_gdt_table(i);
36839 if (!gdt)
36840 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36841 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36842 (unsigned long)__va(header->fields.pm16dseg));
36843 }
36844 +
36845 + pax_close_kernel();
36846 }
36847 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36848 index b0ecacb..7c9da2e 100644
36849 --- a/drivers/pnp/resource.c
36850 +++ b/drivers/pnp/resource.c
36851 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36852 return 1;
36853
36854 /* check if the resource is valid */
36855 - if (*irq < 0 || *irq > 15)
36856 + if (*irq > 15)
36857 return 0;
36858
36859 /* check if the resource is reserved */
36860 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36861 return 1;
36862
36863 /* check if the resource is valid */
36864 - if (*dma < 0 || *dma == 4 || *dma > 7)
36865 + if (*dma == 4 || *dma > 7)
36866 return 0;
36867
36868 /* check if the resource is reserved */
36869 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36870 index 181ddec..774b6da 100644
36871 --- a/drivers/power/bq27x00_battery.c
36872 +++ b/drivers/power/bq27x00_battery.c
36873 @@ -80,7 +80,7 @@
36874 struct bq27x00_device_info;
36875 struct bq27x00_access_methods {
36876 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36877 -};
36878 +} __no_const;
36879
36880 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36881
36882 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36883 index 8d53174..04c65de 100644
36884 --- a/drivers/regulator/max8660.c
36885 +++ b/drivers/regulator/max8660.c
36886 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36887 max8660->shadow_regs[MAX8660_OVER1] = 5;
36888 } else {
36889 /* Otherwise devices can be toggled via software */
36890 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36891 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36892 + pax_open_kernel();
36893 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36894 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36895 + pax_close_kernel();
36896 }
36897
36898 /*
36899 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36900 index b388b74..ed82573 100644
36901 --- a/drivers/regulator/mc13892-regulator.c
36902 +++ b/drivers/regulator/mc13892-regulator.c
36903 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36904 }
36905 mc13xxx_unlock(mc13892);
36906
36907 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36908 + pax_open_kernel();
36909 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36910 = mc13892_vcam_set_mode;
36911 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36912 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36913 = mc13892_vcam_get_mode;
36914 + pax_close_kernel();
36915
36916 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36917 ARRAY_SIZE(mc13892_regulators));
36918 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36919 index cace6d3..f623fda 100644
36920 --- a/drivers/rtc/rtc-dev.c
36921 +++ b/drivers/rtc/rtc-dev.c
36922 @@ -14,6 +14,7 @@
36923 #include <linux/module.h>
36924 #include <linux/rtc.h>
36925 #include <linux/sched.h>
36926 +#include <linux/grsecurity.h>
36927 #include "rtc-core.h"
36928
36929 static dev_t rtc_devt;
36930 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36931 if (copy_from_user(&tm, uarg, sizeof(tm)))
36932 return -EFAULT;
36933
36934 + gr_log_timechange();
36935 +
36936 return rtc_set_time(rtc, &tm);
36937
36938 case RTC_PIE_ON:
36939 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36940 index 9e933a8..4f969f7 100644
36941 --- a/drivers/scsi/aacraid/aacraid.h
36942 +++ b/drivers/scsi/aacraid/aacraid.h
36943 @@ -503,7 +503,7 @@ struct adapter_ops
36944 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36945 /* Administrative operations */
36946 int (*adapter_comm)(struct aac_dev * dev, int comm);
36947 -};
36948 +} __no_const;
36949
36950 /*
36951 * Define which interrupt handler needs to be installed
36952 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36953 index 7199534..cb7f158 100644
36954 --- a/drivers/scsi/aacraid/linit.c
36955 +++ b/drivers/scsi/aacraid/linit.c
36956 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36957 #elif defined(__devinitconst)
36958 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36959 #else
36960 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36961 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36962 #endif
36963 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36964 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36965 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36966 index ff80552..1c4120c 100644
36967 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36968 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36969 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36970 .lldd_ata_set_dmamode = asd_set_dmamode,
36971 };
36972
36973 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36974 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36975 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36976 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36977 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36978 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36979 index 4ad7e36..d004679 100644
36980 --- a/drivers/scsi/bfa/bfa.h
36981 +++ b/drivers/scsi/bfa/bfa.h
36982 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36983 u32 *end);
36984 int cpe_vec_q0;
36985 int rme_vec_q0;
36986 -};
36987 +} __no_const;
36988 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36989
36990 struct bfa_faa_cbfn_s {
36991 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36992 index f0f80e2..8ec946b 100644
36993 --- a/drivers/scsi/bfa/bfa_fcpim.c
36994 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36995 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36996
36997 bfa_iotag_attach(fcp);
36998
36999 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
37000 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
37001 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
37002 (fcp->num_itns * sizeof(struct bfa_itn_s));
37003 memset(fcp->itn_arr, 0,
37004 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
37005 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
37006 {
37007 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
37008 - struct bfa_itn_s *itn;
37009 + bfa_itn_s_no_const *itn;
37010
37011 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
37012 itn->isr = isr;
37013 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
37014 index 36f26da..38a34a8 100644
37015 --- a/drivers/scsi/bfa/bfa_fcpim.h
37016 +++ b/drivers/scsi/bfa/bfa_fcpim.h
37017 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
37018 struct bfa_itn_s {
37019 bfa_isr_func_t isr;
37020 };
37021 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
37022
37023 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
37024 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
37025 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
37026 struct list_head iotag_tio_free_q; /* free IO resources */
37027 struct list_head iotag_unused_q; /* unused IO resources*/
37028 struct bfa_iotag_s *iotag_arr;
37029 - struct bfa_itn_s *itn_arr;
37030 + bfa_itn_s_no_const *itn_arr;
37031 int num_ioim_reqs;
37032 int num_fwtio_reqs;
37033 int num_itns;
37034 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
37035 index 1a99d4b..e85d64b 100644
37036 --- a/drivers/scsi/bfa/bfa_ioc.h
37037 +++ b/drivers/scsi/bfa/bfa_ioc.h
37038 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
37039 bfa_ioc_disable_cbfn_t disable_cbfn;
37040 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
37041 bfa_ioc_reset_cbfn_t reset_cbfn;
37042 -};
37043 +} __no_const;
37044
37045 /*
37046 * IOC event notification mechanism.
37047 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
37048 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
37049 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
37050 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
37051 -};
37052 +} __no_const;
37053
37054 /*
37055 * Queue element to wait for room in request queue. FIFO order is
37056 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
37057 index 593085a..47aa999 100644
37058 --- a/drivers/scsi/hosts.c
37059 +++ b/drivers/scsi/hosts.c
37060 @@ -42,7 +42,7 @@
37061 #include "scsi_logging.h"
37062
37063
37064 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37065 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37066
37067
37068 static void scsi_host_cls_release(struct device *dev)
37069 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
37070 * subtract one because we increment first then return, but we need to
37071 * know what the next host number was before increment
37072 */
37073 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
37074 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
37075 shost->dma_channel = 0xff;
37076
37077 /* These three are default values which can be overridden */
37078 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
37079 index f9823f2..7bc3e81 100644
37080 --- a/drivers/scsi/hpsa.c
37081 +++ b/drivers/scsi/hpsa.c
37082 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
37083 unsigned long flags;
37084
37085 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37086 - return h->access.command_completed(h, q);
37087 + return h->access->command_completed(h, q);
37088
37089 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
37090 a = rq->head[rq->current_entry];
37091 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
37092 while (!list_empty(&h->reqQ)) {
37093 c = list_entry(h->reqQ.next, struct CommandList, list);
37094 /* can't do anything if fifo is full */
37095 - if ((h->access.fifo_full(h))) {
37096 + if ((h->access->fifo_full(h))) {
37097 dev_warn(&h->pdev->dev, "fifo full\n");
37098 break;
37099 }
37100 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
37101
37102 /* Tell the controller execute command */
37103 spin_unlock_irqrestore(&h->lock, flags);
37104 - h->access.submit_command(h, c);
37105 + h->access->submit_command(h, c);
37106 spin_lock_irqsave(&h->lock, flags);
37107 }
37108 spin_unlock_irqrestore(&h->lock, flags);
37109 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
37110
37111 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
37112 {
37113 - return h->access.command_completed(h, q);
37114 + return h->access->command_completed(h, q);
37115 }
37116
37117 static inline bool interrupt_pending(struct ctlr_info *h)
37118 {
37119 - return h->access.intr_pending(h);
37120 + return h->access->intr_pending(h);
37121 }
37122
37123 static inline long interrupt_not_for_us(struct ctlr_info *h)
37124 {
37125 - return (h->access.intr_pending(h) == 0) ||
37126 + return (h->access->intr_pending(h) == 0) ||
37127 (h->interrupts_enabled == 0);
37128 }
37129
37130 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
37131 if (prod_index < 0)
37132 return -ENODEV;
37133 h->product_name = products[prod_index].product_name;
37134 - h->access = *(products[prod_index].access);
37135 + h->access = products[prod_index].access;
37136
37137 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
37138 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
37139 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
37140
37141 assert_spin_locked(&lockup_detector_lock);
37142 remove_ctlr_from_lockup_detector_list(h);
37143 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37144 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37145 spin_lock_irqsave(&h->lock, flags);
37146 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
37147 spin_unlock_irqrestore(&h->lock, flags);
37148 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
37149 }
37150
37151 /* make sure the board interrupts are off */
37152 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37153 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37154
37155 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
37156 goto clean2;
37157 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
37158 * fake ones to scoop up any residual completions.
37159 */
37160 spin_lock_irqsave(&h->lock, flags);
37161 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37162 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37163 spin_unlock_irqrestore(&h->lock, flags);
37164 free_irqs(h);
37165 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
37166 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
37167 dev_info(&h->pdev->dev, "Board READY.\n");
37168 dev_info(&h->pdev->dev,
37169 "Waiting for stale completions to drain.\n");
37170 - h->access.set_intr_mask(h, HPSA_INTR_ON);
37171 + h->access->set_intr_mask(h, HPSA_INTR_ON);
37172 msleep(10000);
37173 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37174 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37175
37176 rc = controller_reset_failed(h->cfgtable);
37177 if (rc)
37178 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
37179 }
37180
37181 /* Turn the interrupts on so we can service requests */
37182 - h->access.set_intr_mask(h, HPSA_INTR_ON);
37183 + h->access->set_intr_mask(h, HPSA_INTR_ON);
37184
37185 hpsa_hba_inquiry(h);
37186 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
37187 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
37188 * To write all data in the battery backed cache to disks
37189 */
37190 hpsa_flush_cache(h);
37191 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37192 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37193 hpsa_free_irqs_and_disable_msix(h);
37194 }
37195
37196 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
37197 return;
37198 }
37199 /* Change the access methods to the performant access methods */
37200 - h->access = SA5_performant_access;
37201 + h->access = &SA5_performant_access;
37202 h->transMethod = CFGTBL_Trans_Performant;
37203 }
37204
37205 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
37206 index 9816479..c5d4e97 100644
37207 --- a/drivers/scsi/hpsa.h
37208 +++ b/drivers/scsi/hpsa.h
37209 @@ -79,7 +79,7 @@ struct ctlr_info {
37210 unsigned int msix_vector;
37211 unsigned int msi_vector;
37212 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
37213 - struct access_method access;
37214 + struct access_method *access;
37215
37216 /* queue and queue Info */
37217 struct list_head reqQ;
37218 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
37219 index f2df059..a3a9930 100644
37220 --- a/drivers/scsi/ips.h
37221 +++ b/drivers/scsi/ips.h
37222 @@ -1027,7 +1027,7 @@ typedef struct {
37223 int (*intr)(struct ips_ha *);
37224 void (*enableint)(struct ips_ha *);
37225 uint32_t (*statupd)(struct ips_ha *);
37226 -} ips_hw_func_t;
37227 +} __no_const ips_hw_func_t;
37228
37229 typedef struct ips_ha {
37230 uint8_t ha_id[IPS_MAX_CHANNELS+1];
37231 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
37232 index c772d8d..35c362c 100644
37233 --- a/drivers/scsi/libfc/fc_exch.c
37234 +++ b/drivers/scsi/libfc/fc_exch.c
37235 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
37236 u16 pool_max_index;
37237
37238 struct {
37239 - atomic_t no_free_exch;
37240 - atomic_t no_free_exch_xid;
37241 - atomic_t xid_not_found;
37242 - atomic_t xid_busy;
37243 - atomic_t seq_not_found;
37244 - atomic_t non_bls_resp;
37245 + atomic_unchecked_t no_free_exch;
37246 + atomic_unchecked_t no_free_exch_xid;
37247 + atomic_unchecked_t xid_not_found;
37248 + atomic_unchecked_t xid_busy;
37249 + atomic_unchecked_t seq_not_found;
37250 + atomic_unchecked_t non_bls_resp;
37251 } stats;
37252 };
37253
37254 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
37255 /* allocate memory for exchange */
37256 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37257 if (!ep) {
37258 - atomic_inc(&mp->stats.no_free_exch);
37259 + atomic_inc_unchecked(&mp->stats.no_free_exch);
37260 goto out;
37261 }
37262 memset(ep, 0, sizeof(*ep));
37263 @@ -786,7 +786,7 @@ out:
37264 return ep;
37265 err:
37266 spin_unlock_bh(&pool->lock);
37267 - atomic_inc(&mp->stats.no_free_exch_xid);
37268 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37269 mempool_free(ep, mp->ep_pool);
37270 return NULL;
37271 }
37272 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37273 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37274 ep = fc_exch_find(mp, xid);
37275 if (!ep) {
37276 - atomic_inc(&mp->stats.xid_not_found);
37277 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37278 reject = FC_RJT_OX_ID;
37279 goto out;
37280 }
37281 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37282 ep = fc_exch_find(mp, xid);
37283 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37284 if (ep) {
37285 - atomic_inc(&mp->stats.xid_busy);
37286 + atomic_inc_unchecked(&mp->stats.xid_busy);
37287 reject = FC_RJT_RX_ID;
37288 goto rel;
37289 }
37290 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37291 }
37292 xid = ep->xid; /* get our XID */
37293 } else if (!ep) {
37294 - atomic_inc(&mp->stats.xid_not_found);
37295 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37296 reject = FC_RJT_RX_ID; /* XID not found */
37297 goto out;
37298 }
37299 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37300 } else {
37301 sp = &ep->seq;
37302 if (sp->id != fh->fh_seq_id) {
37303 - atomic_inc(&mp->stats.seq_not_found);
37304 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37305 if (f_ctl & FC_FC_END_SEQ) {
37306 /*
37307 * Update sequence_id based on incoming last
37308 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37309
37310 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37311 if (!ep) {
37312 - atomic_inc(&mp->stats.xid_not_found);
37313 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37314 goto out;
37315 }
37316 if (ep->esb_stat & ESB_ST_COMPLETE) {
37317 - atomic_inc(&mp->stats.xid_not_found);
37318 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37319 goto rel;
37320 }
37321 if (ep->rxid == FC_XID_UNKNOWN)
37322 ep->rxid = ntohs(fh->fh_rx_id);
37323 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37324 - atomic_inc(&mp->stats.xid_not_found);
37325 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37326 goto rel;
37327 }
37328 if (ep->did != ntoh24(fh->fh_s_id) &&
37329 ep->did != FC_FID_FLOGI) {
37330 - atomic_inc(&mp->stats.xid_not_found);
37331 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37332 goto rel;
37333 }
37334 sof = fr_sof(fp);
37335 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37336 sp->ssb_stat |= SSB_ST_RESP;
37337 sp->id = fh->fh_seq_id;
37338 } else if (sp->id != fh->fh_seq_id) {
37339 - atomic_inc(&mp->stats.seq_not_found);
37340 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37341 goto rel;
37342 }
37343
37344 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37345 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37346
37347 if (!sp)
37348 - atomic_inc(&mp->stats.xid_not_found);
37349 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37350 else
37351 - atomic_inc(&mp->stats.non_bls_resp);
37352 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37353
37354 fc_frame_free(fp);
37355 }
37356 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
37357
37358 list_for_each_entry(ema, &lport->ema_list, ema_list) {
37359 mp = ema->mp;
37360 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
37361 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
37362 st->fc_no_free_exch_xid +=
37363 - atomic_read(&mp->stats.no_free_exch_xid);
37364 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
37365 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
37366 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
37367 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
37368 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
37369 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
37370 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
37371 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
37372 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
37373 }
37374 }
37375 EXPORT_SYMBOL(fc_exch_update_stats);
37376 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37377 index a59fcdc..abe55f3 100644
37378 --- a/drivers/scsi/libsas/sas_ata.c
37379 +++ b/drivers/scsi/libsas/sas_ata.c
37380 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
37381 .postreset = ata_std_postreset,
37382 .error_handler = ata_std_error_handler,
37383 .post_internal_cmd = sas_ata_post_internal,
37384 - .qc_defer = ata_std_qc_defer,
37385 + .qc_defer = ata_std_qc_defer,
37386 .qc_prep = ata_noop_qc_prep,
37387 .qc_issue = sas_ata_qc_issue,
37388 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37389 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37390 index a65c05a..a39e402 100644
37391 --- a/drivers/scsi/lpfc/lpfc.h
37392 +++ b/drivers/scsi/lpfc/lpfc.h
37393 @@ -420,7 +420,7 @@ struct lpfc_vport {
37394 struct dentry *debug_nodelist;
37395 struct dentry *vport_debugfs_root;
37396 struct lpfc_debugfs_trc *disc_trc;
37397 - atomic_t disc_trc_cnt;
37398 + atomic_unchecked_t disc_trc_cnt;
37399 #endif
37400 uint8_t stat_data_enabled;
37401 uint8_t stat_data_blocked;
37402 @@ -834,8 +834,8 @@ struct lpfc_hba {
37403 struct timer_list fabric_block_timer;
37404 unsigned long bit_flags;
37405 #define FABRIC_COMANDS_BLOCKED 0
37406 - atomic_t num_rsrc_err;
37407 - atomic_t num_cmd_success;
37408 + atomic_unchecked_t num_rsrc_err;
37409 + atomic_unchecked_t num_cmd_success;
37410 unsigned long last_rsrc_error_time;
37411 unsigned long last_ramp_down_time;
37412 unsigned long last_ramp_up_time;
37413 @@ -871,7 +871,7 @@ struct lpfc_hba {
37414
37415 struct dentry *debug_slow_ring_trc;
37416 struct lpfc_debugfs_trc *slow_ring_trc;
37417 - atomic_t slow_ring_trc_cnt;
37418 + atomic_unchecked_t slow_ring_trc_cnt;
37419 /* iDiag debugfs sub-directory */
37420 struct dentry *idiag_root;
37421 struct dentry *idiag_pci_cfg;
37422 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37423 index 3217d63..c417981 100644
37424 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37425 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37426 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37427
37428 #include <linux/debugfs.h>
37429
37430 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37431 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37432 static unsigned long lpfc_debugfs_start_time = 0L;
37433
37434 /* iDiag */
37435 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37436 lpfc_debugfs_enable = 0;
37437
37438 len = 0;
37439 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37440 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37441 (lpfc_debugfs_max_disc_trc - 1);
37442 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37443 dtp = vport->disc_trc + i;
37444 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37445 lpfc_debugfs_enable = 0;
37446
37447 len = 0;
37448 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37449 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37450 (lpfc_debugfs_max_slow_ring_trc - 1);
37451 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37452 dtp = phba->slow_ring_trc + i;
37453 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37454 !vport || !vport->disc_trc)
37455 return;
37456
37457 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37458 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37459 (lpfc_debugfs_max_disc_trc - 1);
37460 dtp = vport->disc_trc + index;
37461 dtp->fmt = fmt;
37462 dtp->data1 = data1;
37463 dtp->data2 = data2;
37464 dtp->data3 = data3;
37465 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37466 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37467 dtp->jif = jiffies;
37468 #endif
37469 return;
37470 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37471 !phba || !phba->slow_ring_trc)
37472 return;
37473
37474 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37475 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37476 (lpfc_debugfs_max_slow_ring_trc - 1);
37477 dtp = phba->slow_ring_trc + index;
37478 dtp->fmt = fmt;
37479 dtp->data1 = data1;
37480 dtp->data2 = data2;
37481 dtp->data3 = data3;
37482 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37483 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37484 dtp->jif = jiffies;
37485 #endif
37486 return;
37487 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37488 "slow_ring buffer\n");
37489 goto debug_failed;
37490 }
37491 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37492 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37493 memset(phba->slow_ring_trc, 0,
37494 (sizeof(struct lpfc_debugfs_trc) *
37495 lpfc_debugfs_max_slow_ring_trc));
37496 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37497 "buffer\n");
37498 goto debug_failed;
37499 }
37500 - atomic_set(&vport->disc_trc_cnt, 0);
37501 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37502
37503 snprintf(name, sizeof(name), "discovery_trace");
37504 vport->debug_disc_trc =
37505 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37506 index 45c1520..35ba744 100644
37507 --- a/drivers/scsi/lpfc/lpfc_init.c
37508 +++ b/drivers/scsi/lpfc/lpfc_init.c
37509 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37510 "misc_register returned with status %d", error);
37511
37512 if (lpfc_enable_npiv) {
37513 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37514 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37515 + pax_open_kernel();
37516 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37517 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37518 + pax_close_kernel();
37519 }
37520 lpfc_transport_template =
37521 fc_attach_transport(&lpfc_transport_functions);
37522 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37523 index 925975d..0f1fc07 100644
37524 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37525 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37526 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37527 uint32_t evt_posted;
37528
37529 spin_lock_irqsave(&phba->hbalock, flags);
37530 - atomic_inc(&phba->num_rsrc_err);
37531 + atomic_inc_unchecked(&phba->num_rsrc_err);
37532 phba->last_rsrc_error_time = jiffies;
37533
37534 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37535 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37536 unsigned long flags;
37537 struct lpfc_hba *phba = vport->phba;
37538 uint32_t evt_posted;
37539 - atomic_inc(&phba->num_cmd_success);
37540 + atomic_inc_unchecked(&phba->num_cmd_success);
37541
37542 if (vport->cfg_lun_queue_depth <= queue_depth)
37543 return;
37544 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37545 unsigned long num_rsrc_err, num_cmd_success;
37546 int i;
37547
37548 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37549 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37550 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37551 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37552
37553 /*
37554 * The error and success command counters are global per
37555 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37556 }
37557 }
37558 lpfc_destroy_vport_work_array(phba, vports);
37559 - atomic_set(&phba->num_rsrc_err, 0);
37560 - atomic_set(&phba->num_cmd_success, 0);
37561 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37562 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37563 }
37564
37565 /**
37566 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37567 }
37568 }
37569 lpfc_destroy_vport_work_array(phba, vports);
37570 - atomic_set(&phba->num_rsrc_err, 0);
37571 - atomic_set(&phba->num_cmd_success, 0);
37572 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37573 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37574 }
37575
37576 /**
37577 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37578 index ea8a0b4..812a124 100644
37579 --- a/drivers/scsi/pmcraid.c
37580 +++ b/drivers/scsi/pmcraid.c
37581 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37582 res->scsi_dev = scsi_dev;
37583 scsi_dev->hostdata = res;
37584 res->change_detected = 0;
37585 - atomic_set(&res->read_failures, 0);
37586 - atomic_set(&res->write_failures, 0);
37587 + atomic_set_unchecked(&res->read_failures, 0);
37588 + atomic_set_unchecked(&res->write_failures, 0);
37589 rc = 0;
37590 }
37591 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37592 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37593
37594 /* If this was a SCSI read/write command keep count of errors */
37595 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37596 - atomic_inc(&res->read_failures);
37597 + atomic_inc_unchecked(&res->read_failures);
37598 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37599 - atomic_inc(&res->write_failures);
37600 + atomic_inc_unchecked(&res->write_failures);
37601
37602 if (!RES_IS_GSCSI(res->cfg_entry) &&
37603 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37604 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37605 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37606 * hrrq_id assigned here in queuecommand
37607 */
37608 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37609 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37610 pinstance->num_hrrq;
37611 cmd->cmd_done = pmcraid_io_done;
37612
37613 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37614 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37615 * hrrq_id assigned here in queuecommand
37616 */
37617 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37618 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37619 pinstance->num_hrrq;
37620
37621 if (request_size) {
37622 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37623
37624 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37625 /* add resources only after host is added into system */
37626 - if (!atomic_read(&pinstance->expose_resources))
37627 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37628 return;
37629
37630 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37631 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37632 init_waitqueue_head(&pinstance->reset_wait_q);
37633
37634 atomic_set(&pinstance->outstanding_cmds, 0);
37635 - atomic_set(&pinstance->last_message_id, 0);
37636 - atomic_set(&pinstance->expose_resources, 0);
37637 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37638 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37639
37640 INIT_LIST_HEAD(&pinstance->free_res_q);
37641 INIT_LIST_HEAD(&pinstance->used_res_q);
37642 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37643 /* Schedule worker thread to handle CCN and take care of adding and
37644 * removing devices to OS
37645 */
37646 - atomic_set(&pinstance->expose_resources, 1);
37647 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37648 schedule_work(&pinstance->worker_q);
37649 return rc;
37650
37651 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37652 index e1d150f..6c6df44 100644
37653 --- a/drivers/scsi/pmcraid.h
37654 +++ b/drivers/scsi/pmcraid.h
37655 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37656 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37657
37658 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37659 - atomic_t last_message_id;
37660 + atomic_unchecked_t last_message_id;
37661
37662 /* configuration table */
37663 struct pmcraid_config_table *cfg_table;
37664 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37665 atomic_t outstanding_cmds;
37666
37667 /* should add/delete resources to mid-layer now ?*/
37668 - atomic_t expose_resources;
37669 + atomic_unchecked_t expose_resources;
37670
37671
37672
37673 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37674 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37675 };
37676 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37677 - atomic_t read_failures; /* count of failed READ commands */
37678 - atomic_t write_failures; /* count of failed WRITE commands */
37679 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37680 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37681
37682 /* To indicate add/delete/modify during CCN */
37683 u8 change_detected;
37684 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37685 index 5ab9530..2dd80f7 100644
37686 --- a/drivers/scsi/qla2xxx/qla_attr.c
37687 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37688 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37689 return 0;
37690 }
37691
37692 -struct fc_function_template qla2xxx_transport_functions = {
37693 +fc_function_template_no_const qla2xxx_transport_functions = {
37694
37695 .show_host_node_name = 1,
37696 .show_host_port_name = 1,
37697 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37698 .bsg_timeout = qla24xx_bsg_timeout,
37699 };
37700
37701 -struct fc_function_template qla2xxx_transport_vport_functions = {
37702 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37703
37704 .show_host_node_name = 1,
37705 .show_host_port_name = 1,
37706 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37707 index 39007f5..7fafc64 100644
37708 --- a/drivers/scsi/qla2xxx/qla_def.h
37709 +++ b/drivers/scsi/qla2xxx/qla_def.h
37710 @@ -2284,7 +2284,7 @@ struct isp_operations {
37711 int (*start_scsi) (srb_t *);
37712 int (*abort_isp) (struct scsi_qla_host *);
37713 int (*iospace_config)(struct qla_hw_data*);
37714 -};
37715 +} __no_const;
37716
37717 /* MSI-X Support *************************************************************/
37718
37719 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37720 index 9eacd2d..d79629c 100644
37721 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37722 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37723 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37724 struct device_attribute;
37725 extern struct device_attribute *qla2x00_host_attrs[];
37726 struct fc_function_template;
37727 -extern struct fc_function_template qla2xxx_transport_functions;
37728 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37729 +extern fc_function_template_no_const qla2xxx_transport_functions;
37730 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37731 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37732 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37733 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37734 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37735 index 7fdba7f..1b4b2c2 100644
37736 --- a/drivers/scsi/qla4xxx/ql4_def.h
37737 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37738 @@ -268,7 +268,7 @@ struct ddb_entry {
37739 * (4000 only) */
37740 atomic_t relogin_timer; /* Max Time to wait for
37741 * relogin to complete */
37742 - atomic_t relogin_retry_count; /* Num of times relogin has been
37743 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37744 * retried */
37745 uint32_t default_time2wait; /* Default Min time between
37746 * relogins (+aens) */
37747 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37748 index 9da4266..377b3b6 100644
37749 --- a/drivers/scsi/qla4xxx/ql4_os.c
37750 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37751 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37752 */
37753 if (!iscsi_is_session_online(cls_sess)) {
37754 /* Reset retry relogin timer */
37755 - atomic_inc(&ddb_entry->relogin_retry_count);
37756 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37757 DEBUG2(ql4_printk(KERN_INFO, ha,
37758 "%s: index[%d] relogin timed out-retrying"
37759 " relogin (%d), retry (%d)\n", __func__,
37760 ddb_entry->fw_ddb_index,
37761 - atomic_read(&ddb_entry->relogin_retry_count),
37762 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37763 ddb_entry->default_time2wait + 4));
37764 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37765 atomic_set(&ddb_entry->retry_relogin_timer,
37766 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37767
37768 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37769 atomic_set(&ddb_entry->relogin_timer, 0);
37770 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37771 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37772 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37773 ddb_entry->default_relogin_timeout =
37774 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37775 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37776 index 2936b44..546ecdb 100644
37777 --- a/drivers/scsi/scsi.c
37778 +++ b/drivers/scsi/scsi.c
37779 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37780 unsigned long timeout;
37781 int rtn = 0;
37782
37783 - atomic_inc(&cmd->device->iorequest_cnt);
37784 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37785
37786 /* check if the device is still usable */
37787 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37788 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37789 index faa790f..7e351ddd 100644
37790 --- a/drivers/scsi/scsi_lib.c
37791 +++ b/drivers/scsi/scsi_lib.c
37792 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37793 shost = sdev->host;
37794 scsi_init_cmd_errh(cmd);
37795 cmd->result = DID_NO_CONNECT << 16;
37796 - atomic_inc(&cmd->device->iorequest_cnt);
37797 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37798
37799 /*
37800 * SCSI request completion path will do scsi_device_unbusy(),
37801 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37802
37803 INIT_LIST_HEAD(&cmd->eh_entry);
37804
37805 - atomic_inc(&cmd->device->iodone_cnt);
37806 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37807 if (cmd->result)
37808 - atomic_inc(&cmd->device->ioerr_cnt);
37809 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37810
37811 disposition = scsi_decide_disposition(cmd);
37812 if (disposition != SUCCESS &&
37813 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37814 index ce5224c..8c6d071 100644
37815 --- a/drivers/scsi/scsi_sysfs.c
37816 +++ b/drivers/scsi/scsi_sysfs.c
37817 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37818 char *buf) \
37819 { \
37820 struct scsi_device *sdev = to_scsi_device(dev); \
37821 - unsigned long long count = atomic_read(&sdev->field); \
37822 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37823 return snprintf(buf, 20, "0x%llx\n", count); \
37824 } \
37825 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37826 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37827 index 84a1fdf..693b0d6 100644
37828 --- a/drivers/scsi/scsi_tgt_lib.c
37829 +++ b/drivers/scsi/scsi_tgt_lib.c
37830 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37831 int err;
37832
37833 dprintk("%lx %u\n", uaddr, len);
37834 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37835 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37836 if (err) {
37837 /*
37838 * TODO: need to fixup sg_tablesize, max_segment_size,
37839 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37840 index e894ca7..de9d7660 100644
37841 --- a/drivers/scsi/scsi_transport_fc.c
37842 +++ b/drivers/scsi/scsi_transport_fc.c
37843 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37844 * Netlink Infrastructure
37845 */
37846
37847 -static atomic_t fc_event_seq;
37848 +static atomic_unchecked_t fc_event_seq;
37849
37850 /**
37851 * fc_get_event_number - Obtain the next sequential FC event number
37852 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37853 u32
37854 fc_get_event_number(void)
37855 {
37856 - return atomic_add_return(1, &fc_event_seq);
37857 + return atomic_add_return_unchecked(1, &fc_event_seq);
37858 }
37859 EXPORT_SYMBOL(fc_get_event_number);
37860
37861 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37862 {
37863 int error;
37864
37865 - atomic_set(&fc_event_seq, 0);
37866 + atomic_set_unchecked(&fc_event_seq, 0);
37867
37868 error = transport_class_register(&fc_host_class);
37869 if (error)
37870 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37871 char *cp;
37872
37873 *val = simple_strtoul(buf, &cp, 0);
37874 - if ((*cp && (*cp != '\n')) || (*val < 0))
37875 + if (*cp && (*cp != '\n'))
37876 return -EINVAL;
37877 /*
37878 * Check for overflow; dev_loss_tmo is u32
37879 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37880 index fa1dfaa..4bb620c 100644
37881 --- a/drivers/scsi/scsi_transport_iscsi.c
37882 +++ b/drivers/scsi/scsi_transport_iscsi.c
37883 @@ -79,7 +79,7 @@ struct iscsi_internal {
37884 struct transport_container session_cont;
37885 };
37886
37887 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37888 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37889 static struct workqueue_struct *iscsi_eh_timer_workq;
37890
37891 static DEFINE_IDA(iscsi_sess_ida);
37892 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37893 int err;
37894
37895 ihost = shost->shost_data;
37896 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37897 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37898
37899 if (target_id == ISCSI_MAX_TARGET) {
37900 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37901 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37902 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37903 ISCSI_TRANSPORT_VERSION);
37904
37905 - atomic_set(&iscsi_session_nr, 0);
37906 + atomic_set_unchecked(&iscsi_session_nr, 0);
37907
37908 err = class_register(&iscsi_transport_class);
37909 if (err)
37910 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37911 index 21a045e..ec89e03 100644
37912 --- a/drivers/scsi/scsi_transport_srp.c
37913 +++ b/drivers/scsi/scsi_transport_srp.c
37914 @@ -33,7 +33,7 @@
37915 #include "scsi_transport_srp_internal.h"
37916
37917 struct srp_host_attrs {
37918 - atomic_t next_port_id;
37919 + atomic_unchecked_t next_port_id;
37920 };
37921 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37922
37923 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37924 struct Scsi_Host *shost = dev_to_shost(dev);
37925 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37926
37927 - atomic_set(&srp_host->next_port_id, 0);
37928 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37929 return 0;
37930 }
37931
37932 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37933 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37934 rport->roles = ids->roles;
37935
37936 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37937 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37938 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37939
37940 transport_setup_device(&rport->dev);
37941 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37942 index 4df73e5..b691c58 100644
37943 --- a/drivers/scsi/sd.c
37944 +++ b/drivers/scsi/sd.c
37945 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37946 sdkp->disk = gd;
37947 sdkp->index = index;
37948 atomic_set(&sdkp->openers, 0);
37949 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37950 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37951
37952 if (!sdp->request_queue->rq_timeout) {
37953 if (sdp->type != TYPE_MOD)
37954 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37955 index 9c5c5f2..8414557 100644
37956 --- a/drivers/scsi/sg.c
37957 +++ b/drivers/scsi/sg.c
37958 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37959 sdp->disk->disk_name,
37960 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37961 NULL,
37962 - (char *)arg);
37963 + (char __user *)arg);
37964 case BLKTRACESTART:
37965 return blk_trace_startstop(sdp->device->request_queue, 1);
37966 case BLKTRACESTOP:
37967 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37968 index 84c2861..ece0a31 100644
37969 --- a/drivers/spi/spi.c
37970 +++ b/drivers/spi/spi.c
37971 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37972 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37973
37974 /* portable code must never pass more than 32 bytes */
37975 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37976 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37977
37978 static u8 *buf;
37979
37980 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37981 index 34afc16..ffe44dd 100644
37982 --- a/drivers/staging/octeon/ethernet-rx.c
37983 +++ b/drivers/staging/octeon/ethernet-rx.c
37984 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37985 /* Increment RX stats for virtual ports */
37986 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37987 #ifdef CONFIG_64BIT
37988 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37989 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37990 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37991 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37992 #else
37993 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37994 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37995 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37996 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37997 #endif
37998 }
37999 netif_receive_skb(skb);
38000 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38001 dev->name);
38002 */
38003 #ifdef CONFIG_64BIT
38004 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
38005 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38006 #else
38007 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
38008 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
38009 #endif
38010 dev_kfree_skb_irq(skb);
38011 }
38012 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
38013 index 683bedc..86dba9a 100644
38014 --- a/drivers/staging/octeon/ethernet.c
38015 +++ b/drivers/staging/octeon/ethernet.c
38016 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
38017 * since the RX tasklet also increments it.
38018 */
38019 #ifdef CONFIG_64BIT
38020 - atomic64_add(rx_status.dropped_packets,
38021 - (atomic64_t *)&priv->stats.rx_dropped);
38022 + atomic64_add_unchecked(rx_status.dropped_packets,
38023 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38024 #else
38025 - atomic_add(rx_status.dropped_packets,
38026 - (atomic_t *)&priv->stats.rx_dropped);
38027 + atomic_add_unchecked(rx_status.dropped_packets,
38028 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
38029 #endif
38030 }
38031
38032 diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c
38033 index 4beab94..44149ee 100644
38034 --- a/drivers/staging/omapdrm/omap_drv.c
38035 +++ b/drivers/staging/omapdrm/omap_drv.c
38036 @@ -761,7 +761,6 @@ static struct drm_driver omap_drm_driver = {
38037 .irq_postinstall = dev_irq_postinstall,
38038 .irq_uninstall = dev_irq_uninstall,
38039 .irq_handler = dev_irq_handler,
38040 - .reclaim_buffers = drm_core_reclaim_buffers,
38041 #ifdef CONFIG_DEBUG_FS
38042 .debugfs_init = omap_debugfs_init,
38043 .debugfs_cleanup = omap_debugfs_cleanup,
38044 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
38045 index dc23395..cf7e9b1 100644
38046 --- a/drivers/staging/rtl8712/rtl871x_io.h
38047 +++ b/drivers/staging/rtl8712/rtl871x_io.h
38048 @@ -108,7 +108,7 @@ struct _io_ops {
38049 u8 *pmem);
38050 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
38051 u8 *pmem);
38052 -};
38053 +} __no_const;
38054
38055 struct io_req {
38056 struct list_head list;
38057 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
38058 index c7b5e8b..783d6cb 100644
38059 --- a/drivers/staging/sbe-2t3e3/netdev.c
38060 +++ b/drivers/staging/sbe-2t3e3/netdev.c
38061 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38062 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
38063
38064 if (rlen)
38065 - if (copy_to_user(data, &resp, rlen))
38066 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
38067 return -EFAULT;
38068
38069 return 0;
38070 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
38071 index 5d89c0f..9261317 100644
38072 --- a/drivers/staging/usbip/usbip_common.h
38073 +++ b/drivers/staging/usbip/usbip_common.h
38074 @@ -289,7 +289,7 @@ struct usbip_device {
38075 void (*shutdown)(struct usbip_device *);
38076 void (*reset)(struct usbip_device *);
38077 void (*unusable)(struct usbip_device *);
38078 - } eh_ops;
38079 + } __no_const eh_ops;
38080 };
38081
38082 #define kthread_get_run(threadfn, data, namefmt, ...) \
38083 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
38084 index c66b8b3..a4a035b 100644
38085 --- a/drivers/staging/usbip/vhci.h
38086 +++ b/drivers/staging/usbip/vhci.h
38087 @@ -83,7 +83,7 @@ struct vhci_hcd {
38088 unsigned resuming:1;
38089 unsigned long re_timeout;
38090
38091 - atomic_t seqnum;
38092 + atomic_unchecked_t seqnum;
38093
38094 /*
38095 * NOTE:
38096 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
38097 index 12a9a5f..afd8295 100644
38098 --- a/drivers/staging/usbip/vhci_hcd.c
38099 +++ b/drivers/staging/usbip/vhci_hcd.c
38100 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
38101 return;
38102 }
38103
38104 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
38105 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38106 if (priv->seqnum == 0xffff)
38107 dev_info(&urb->dev->dev, "seqnum max\n");
38108
38109 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
38110 return -ENOMEM;
38111 }
38112
38113 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
38114 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38115 if (unlink->seqnum == 0xffff)
38116 pr_info("seqnum max\n");
38117
38118 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
38119 vdev->rhport = rhport;
38120 }
38121
38122 - atomic_set(&vhci->seqnum, 0);
38123 + atomic_set_unchecked(&vhci->seqnum, 0);
38124 spin_lock_init(&vhci->lock);
38125
38126 hcd->power_budget = 0; /* no limit */
38127 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
38128 index f0eaf04..5a82e06 100644
38129 --- a/drivers/staging/usbip/vhci_rx.c
38130 +++ b/drivers/staging/usbip/vhci_rx.c
38131 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
38132 if (!urb) {
38133 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
38134 pr_info("max seqnum %d\n",
38135 - atomic_read(&the_controller->seqnum));
38136 + atomic_read_unchecked(&the_controller->seqnum));
38137 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
38138 return;
38139 }
38140 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
38141 index 6ac6f45..1b208ba 100644
38142 --- a/drivers/staging/vt6655/hostap.c
38143 +++ b/drivers/staging/vt6655/hostap.c
38144 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
38145 *
38146 */
38147
38148 +static net_device_ops_no_const apdev_netdev_ops;
38149 +
38150 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38151 {
38152 PSDevice apdev_priv;
38153 struct net_device *dev = pDevice->dev;
38154 int ret;
38155 - const struct net_device_ops apdev_netdev_ops = {
38156 - .ndo_start_xmit = pDevice->tx_80211,
38157 - };
38158
38159 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38160
38161 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38162 *apdev_priv = *pDevice;
38163 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38164
38165 + /* only half broken now */
38166 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38167 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38168
38169 pDevice->apdev->type = ARPHRD_IEEE80211;
38170 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
38171 index 682002a..35ed5cf 100644
38172 --- a/drivers/staging/vt6656/hostap.c
38173 +++ b/drivers/staging/vt6656/hostap.c
38174 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
38175 *
38176 */
38177
38178 +static net_device_ops_no_const apdev_netdev_ops;
38179 +
38180 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38181 {
38182 PSDevice apdev_priv;
38183 struct net_device *dev = pDevice->dev;
38184 int ret;
38185 - const struct net_device_ops apdev_netdev_ops = {
38186 - .ndo_start_xmit = pDevice->tx_80211,
38187 - };
38188
38189 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38190
38191 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38192 *apdev_priv = *pDevice;
38193 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38194
38195 + /* only half broken now */
38196 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38197 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38198
38199 pDevice->apdev->type = ARPHRD_IEEE80211;
38200 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
38201 index 7843dfd..3db105f 100644
38202 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
38203 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
38204 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
38205
38206 struct usbctlx_completor {
38207 int (*complete) (struct usbctlx_completor *);
38208 -};
38209 +} __no_const;
38210
38211 static int
38212 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
38213 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
38214 index eaa9021..43f023b 100644
38215 --- a/drivers/staging/zcache/tmem.c
38216 +++ b/drivers/staging/zcache/tmem.c
38217 @@ -39,7 +39,7 @@
38218 * A tmem host implementation must use this function to register callbacks
38219 * for memory allocation.
38220 */
38221 -static struct tmem_hostops tmem_hostops;
38222 +static tmem_hostops_no_const tmem_hostops;
38223
38224 static void tmem_objnode_tree_init(void);
38225
38226 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
38227 * A tmem host implementation must use this function to register
38228 * callbacks for a page-accessible memory (PAM) implementation
38229 */
38230 -static struct tmem_pamops tmem_pamops;
38231 +static tmem_pamops_no_const tmem_pamops;
38232
38233 void tmem_register_pamops(struct tmem_pamops *m)
38234 {
38235 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
38236 index 0d4aa82..f7832d4 100644
38237 --- a/drivers/staging/zcache/tmem.h
38238 +++ b/drivers/staging/zcache/tmem.h
38239 @@ -180,6 +180,7 @@ struct tmem_pamops {
38240 void (*new_obj)(struct tmem_obj *);
38241 int (*replace_in_obj)(void *, struct tmem_obj *);
38242 };
38243 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
38244 extern void tmem_register_pamops(struct tmem_pamops *m);
38245
38246 /* memory allocation methods provided by the host implementation */
38247 @@ -189,6 +190,7 @@ struct tmem_hostops {
38248 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
38249 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
38250 };
38251 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
38252 extern void tmem_register_hostops(struct tmem_hostops *m);
38253
38254 /* core tmem accessor functions */
38255 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
38256 index 7502660..f214d9f 100644
38257 --- a/drivers/target/target_core_transport.c
38258 +++ b/drivers/target/target_core_transport.c
38259 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
38260 spin_lock_init(&dev->se_port_lock);
38261 spin_lock_init(&dev->se_tmr_lock);
38262 spin_lock_init(&dev->qf_cmd_lock);
38263 - atomic_set(&dev->dev_ordered_id, 0);
38264 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
38265
38266 se_dev_set_default_attribs(dev, dev_limits);
38267
38268 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
38269 * Used to determine when ORDERED commands should go from
38270 * Dormant to Active status.
38271 */
38272 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
38273 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
38274 smp_mb__after_atomic_inc();
38275 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
38276 cmd->se_ordered_id, cmd->sam_task_attr,
38277 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
38278 index e61cabd..7617d26 100644
38279 --- a/drivers/tty/cyclades.c
38280 +++ b/drivers/tty/cyclades.c
38281 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
38282 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
38283 info->port.count);
38284 #endif
38285 - info->port.count++;
38286 + atomic_inc(&info->port.count);
38287 #ifdef CY_DEBUG_COUNT
38288 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
38289 - current->pid, info->port.count);
38290 + current->pid, atomic_read(&info->port.count));
38291 #endif
38292
38293 /*
38294 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
38295 for (j = 0; j < cy_card[i].nports; j++) {
38296 info = &cy_card[i].ports[j];
38297
38298 - if (info->port.count) {
38299 + if (atomic_read(&info->port.count)) {
38300 /* XXX is the ldisc num worth this? */
38301 struct tty_struct *tty;
38302 struct tty_ldisc *ld;
38303 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
38304 index 2d691eb..be02ebd 100644
38305 --- a/drivers/tty/hvc/hvc_console.c
38306 +++ b/drivers/tty/hvc/hvc_console.c
38307 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
38308
38309 spin_lock_irqsave(&hp->port.lock, flags);
38310 /* Check and then increment for fast path open. */
38311 - if (hp->port.count++ > 0) {
38312 + if (atomic_inc_return(&hp->port.count) > 1) {
38313 spin_unlock_irqrestore(&hp->port.lock, flags);
38314 hvc_kick();
38315 return 0;
38316 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38317
38318 spin_lock_irqsave(&hp->port.lock, flags);
38319
38320 - if (--hp->port.count == 0) {
38321 + if (atomic_dec_return(&hp->port.count) == 0) {
38322 spin_unlock_irqrestore(&hp->port.lock, flags);
38323 /* We are done with the tty pointer now. */
38324 tty_port_tty_set(&hp->port, NULL);
38325 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38326 */
38327 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
38328 } else {
38329 - if (hp->port.count < 0)
38330 + if (atomic_read(&hp->port.count) < 0)
38331 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38332 - hp->vtermno, hp->port.count);
38333 + hp->vtermno, atomic_read(&hp->port.count));
38334 spin_unlock_irqrestore(&hp->port.lock, flags);
38335 }
38336
38337 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
38338 * open->hangup case this can be called after the final close so prevent
38339 * that from happening for now.
38340 */
38341 - if (hp->port.count <= 0) {
38342 + if (atomic_read(&hp->port.count) <= 0) {
38343 spin_unlock_irqrestore(&hp->port.lock, flags);
38344 return;
38345 }
38346
38347 - temp_open_count = hp->port.count;
38348 - hp->port.count = 0;
38349 + temp_open_count = atomic_read(&hp->port.count);
38350 + atomic_set(&hp->port.count, 0);
38351 spin_unlock_irqrestore(&hp->port.lock, flags);
38352 tty_port_tty_set(&hp->port, NULL);
38353
38354 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38355 return -EPIPE;
38356
38357 /* FIXME what's this (unprotected) check for? */
38358 - if (hp->port.count <= 0)
38359 + if (atomic_read(&hp->port.count) <= 0)
38360 return -EIO;
38361
38362 spin_lock_irqsave(&hp->lock, flags);
38363 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38364 index d56788c..12d8f85 100644
38365 --- a/drivers/tty/hvc/hvcs.c
38366 +++ b/drivers/tty/hvc/hvcs.c
38367 @@ -83,6 +83,7 @@
38368 #include <asm/hvcserver.h>
38369 #include <asm/uaccess.h>
38370 #include <asm/vio.h>
38371 +#include <asm/local.h>
38372
38373 /*
38374 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38375 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38376
38377 spin_lock_irqsave(&hvcsd->lock, flags);
38378
38379 - if (hvcsd->port.count > 0) {
38380 + if (atomic_read(&hvcsd->port.count) > 0) {
38381 spin_unlock_irqrestore(&hvcsd->lock, flags);
38382 printk(KERN_INFO "HVCS: vterm state unchanged. "
38383 "The hvcs device node is still in use.\n");
38384 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38385 if ((retval = hvcs_partner_connect(hvcsd)))
38386 goto error_release;
38387
38388 - hvcsd->port.count = 1;
38389 + atomic_set(&hvcsd->port.count, 1);
38390 hvcsd->port.tty = tty;
38391 tty->driver_data = hvcsd;
38392
38393 @@ -1168,7 +1169,7 @@ fast_open:
38394
38395 spin_lock_irqsave(&hvcsd->lock, flags);
38396 tty_port_get(&hvcsd->port);
38397 - hvcsd->port.count++;
38398 + atomic_inc(&hvcsd->port.count);
38399 hvcsd->todo_mask |= HVCS_SCHED_READ;
38400 spin_unlock_irqrestore(&hvcsd->lock, flags);
38401
38402 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38403 hvcsd = tty->driver_data;
38404
38405 spin_lock_irqsave(&hvcsd->lock, flags);
38406 - if (--hvcsd->port.count == 0) {
38407 + if (atomic_dec_and_test(&hvcsd->port.count)) {
38408
38409 vio_disable_interrupts(hvcsd->vdev);
38410
38411 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38412 free_irq(irq, hvcsd);
38413 tty_port_put(&hvcsd->port);
38414 return;
38415 - } else if (hvcsd->port.count < 0) {
38416 + } else if (atomic_read(&hvcsd->port.count) < 0) {
38417 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38418 " is missmanaged.\n",
38419 - hvcsd->vdev->unit_address, hvcsd->port.count);
38420 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38421 }
38422
38423 spin_unlock_irqrestore(&hvcsd->lock, flags);
38424 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38425
38426 spin_lock_irqsave(&hvcsd->lock, flags);
38427 /* Preserve this so that we know how many kref refs to put */
38428 - temp_open_count = hvcsd->port.count;
38429 + temp_open_count = atomic_read(&hvcsd->port.count);
38430
38431 /*
38432 * Don't kref put inside the spinlock because the destruction
38433 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38434 tty->driver_data = NULL;
38435 hvcsd->port.tty = NULL;
38436
38437 - hvcsd->port.count = 0;
38438 + atomic_set(&hvcsd->port.count, 0);
38439
38440 /* This will drop any buffered data on the floor which is OK in a hangup
38441 * scenario. */
38442 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38443 * the middle of a write operation? This is a crummy place to do this
38444 * but we want to keep it all in the spinlock.
38445 */
38446 - if (hvcsd->port.count <= 0) {
38447 + if (atomic_read(&hvcsd->port.count) <= 0) {
38448 spin_unlock_irqrestore(&hvcsd->lock, flags);
38449 return -ENODEV;
38450 }
38451 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38452 {
38453 struct hvcs_struct *hvcsd = tty->driver_data;
38454
38455 - if (!hvcsd || hvcsd->port.count <= 0)
38456 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38457 return 0;
38458
38459 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38460 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38461 index f8b5fa0..4ba9f89 100644
38462 --- a/drivers/tty/ipwireless/tty.c
38463 +++ b/drivers/tty/ipwireless/tty.c
38464 @@ -29,6 +29,7 @@
38465 #include <linux/tty_driver.h>
38466 #include <linux/tty_flip.h>
38467 #include <linux/uaccess.h>
38468 +#include <asm/local.h>
38469
38470 #include "tty.h"
38471 #include "network.h"
38472 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38473 mutex_unlock(&tty->ipw_tty_mutex);
38474 return -ENODEV;
38475 }
38476 - if (tty->port.count == 0)
38477 + if (atomic_read(&tty->port.count) == 0)
38478 tty->tx_bytes_queued = 0;
38479
38480 - tty->port.count++;
38481 + atomic_inc(&tty->port.count);
38482
38483 tty->port.tty = linux_tty;
38484 linux_tty->driver_data = tty;
38485 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38486
38487 static void do_ipw_close(struct ipw_tty *tty)
38488 {
38489 - tty->port.count--;
38490 -
38491 - if (tty->port.count == 0) {
38492 + if (atomic_dec_return(&tty->port.count) == 0) {
38493 struct tty_struct *linux_tty = tty->port.tty;
38494
38495 if (linux_tty != NULL) {
38496 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38497 return;
38498
38499 mutex_lock(&tty->ipw_tty_mutex);
38500 - if (tty->port.count == 0) {
38501 + if (atomic_read(&tty->port.count) == 0) {
38502 mutex_unlock(&tty->ipw_tty_mutex);
38503 return;
38504 }
38505 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38506 return;
38507 }
38508
38509 - if (!tty->port.count) {
38510 + if (!atomic_read(&tty->port.count)) {
38511 mutex_unlock(&tty->ipw_tty_mutex);
38512 return;
38513 }
38514 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38515 return -ENODEV;
38516
38517 mutex_lock(&tty->ipw_tty_mutex);
38518 - if (!tty->port.count) {
38519 + if (!atomic_read(&tty->port.count)) {
38520 mutex_unlock(&tty->ipw_tty_mutex);
38521 return -EINVAL;
38522 }
38523 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38524 if (!tty)
38525 return -ENODEV;
38526
38527 - if (!tty->port.count)
38528 + if (!atomic_read(&tty->port.count))
38529 return -EINVAL;
38530
38531 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38532 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38533 if (!tty)
38534 return 0;
38535
38536 - if (!tty->port.count)
38537 + if (!atomic_read(&tty->port.count))
38538 return 0;
38539
38540 return tty->tx_bytes_queued;
38541 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38542 if (!tty)
38543 return -ENODEV;
38544
38545 - if (!tty->port.count)
38546 + if (!atomic_read(&tty->port.count))
38547 return -EINVAL;
38548
38549 return get_control_lines(tty);
38550 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38551 if (!tty)
38552 return -ENODEV;
38553
38554 - if (!tty->port.count)
38555 + if (!atomic_read(&tty->port.count))
38556 return -EINVAL;
38557
38558 return set_control_lines(tty, set, clear);
38559 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38560 if (!tty)
38561 return -ENODEV;
38562
38563 - if (!tty->port.count)
38564 + if (!atomic_read(&tty->port.count))
38565 return -EINVAL;
38566
38567 /* FIXME: Exactly how is the tty object locked here .. */
38568 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38569 * are gone */
38570 mutex_lock(&ttyj->ipw_tty_mutex);
38571 }
38572 - while (ttyj->port.count)
38573 + while (atomic_read(&ttyj->port.count))
38574 do_ipw_close(ttyj);
38575 ipwireless_disassociate_network_ttys(network,
38576 ttyj->channel_idx);
38577 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38578 index 324467d..504cc25 100644
38579 --- a/drivers/tty/moxa.c
38580 +++ b/drivers/tty/moxa.c
38581 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38582 }
38583
38584 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38585 - ch->port.count++;
38586 + atomic_inc(&ch->port.count);
38587 tty->driver_data = ch;
38588 tty_port_tty_set(&ch->port, tty);
38589 mutex_lock(&ch->port.mutex);
38590 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38591 index 90dff82..08119c3 100644
38592 --- a/drivers/tty/n_gsm.c
38593 +++ b/drivers/tty/n_gsm.c
38594 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38595 kref_init(&dlci->ref);
38596 mutex_init(&dlci->mutex);
38597 dlci->fifo = &dlci->_fifo;
38598 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38599 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38600 kfree(dlci);
38601 return NULL;
38602 }
38603 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38604 if (dlci == NULL)
38605 return -ENOMEM;
38606 port = &dlci->port;
38607 - port->count++;
38608 + atomic_inc(&port->count);
38609 tty->driver_data = dlci;
38610 dlci_get(dlci);
38611 dlci_get(dlci->gsm->dlci[0]);
38612 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38613 index 26f0d0e..b7c4273 100644
38614 --- a/drivers/tty/n_tty.c
38615 +++ b/drivers/tty/n_tty.c
38616 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38617 {
38618 *ops = tty_ldisc_N_TTY;
38619 ops->owner = NULL;
38620 - ops->refcount = ops->flags = 0;
38621 + atomic_set(&ops->refcount, 0);
38622 + ops->flags = 0;
38623 }
38624 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38625 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38626 index 5505ffc..7affff9 100644
38627 --- a/drivers/tty/pty.c
38628 +++ b/drivers/tty/pty.c
38629 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38630 panic("Couldn't register Unix98 pts driver");
38631
38632 /* Now create the /dev/ptmx special device */
38633 + pax_open_kernel();
38634 tty_default_fops(&ptmx_fops);
38635 - ptmx_fops.open = ptmx_open;
38636 + *(void **)&ptmx_fops.open = ptmx_open;
38637 + pax_close_kernel();
38638
38639 cdev_init(&ptmx_cdev, &ptmx_fops);
38640 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38641 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38642 index 777d5f9..56d67ca 100644
38643 --- a/drivers/tty/rocket.c
38644 +++ b/drivers/tty/rocket.c
38645 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38646 tty->driver_data = info;
38647 tty_port_tty_set(port, tty);
38648
38649 - if (port->count++ == 0) {
38650 + if (atomic_inc_return(&port->count) == 1) {
38651 atomic_inc(&rp_num_ports_open);
38652
38653 #ifdef ROCKET_DEBUG_OPEN
38654 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38655 #endif
38656 }
38657 #ifdef ROCKET_DEBUG_OPEN
38658 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38659 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38660 #endif
38661
38662 /*
38663 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38664 spin_unlock_irqrestore(&info->port.lock, flags);
38665 return;
38666 }
38667 - if (info->port.count)
38668 + if (atomic_read(&info->port.count))
38669 atomic_dec(&rp_num_ports_open);
38670 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38671 spin_unlock_irqrestore(&info->port.lock, flags);
38672 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38673 index 2b42a01..32a2ed3 100644
38674 --- a/drivers/tty/serial/kgdboc.c
38675 +++ b/drivers/tty/serial/kgdboc.c
38676 @@ -24,8 +24,9 @@
38677 #define MAX_CONFIG_LEN 40
38678
38679 static struct kgdb_io kgdboc_io_ops;
38680 +static struct kgdb_io kgdboc_io_ops_console;
38681
38682 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38683 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38684 static int configured = -1;
38685
38686 static char config[MAX_CONFIG_LEN];
38687 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38688 kgdboc_unregister_kbd();
38689 if (configured == 1)
38690 kgdb_unregister_io_module(&kgdboc_io_ops);
38691 + else if (configured == 2)
38692 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38693 }
38694
38695 static int configure_kgdboc(void)
38696 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38697 int err;
38698 char *cptr = config;
38699 struct console *cons;
38700 + int is_console = 0;
38701
38702 err = kgdboc_option_setup(config);
38703 if (err || !strlen(config) || isspace(config[0]))
38704 goto noconfig;
38705
38706 err = -ENODEV;
38707 - kgdboc_io_ops.is_console = 0;
38708 kgdb_tty_driver = NULL;
38709
38710 kgdboc_use_kms = 0;
38711 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38712 int idx;
38713 if (cons->device && cons->device(cons, &idx) == p &&
38714 idx == tty_line) {
38715 - kgdboc_io_ops.is_console = 1;
38716 + is_console = 1;
38717 break;
38718 }
38719 cons = cons->next;
38720 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38721 kgdb_tty_line = tty_line;
38722
38723 do_register:
38724 - err = kgdb_register_io_module(&kgdboc_io_ops);
38725 + if (is_console) {
38726 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38727 + configured = 2;
38728 + } else {
38729 + err = kgdb_register_io_module(&kgdboc_io_ops);
38730 + configured = 1;
38731 + }
38732 if (err)
38733 goto noconfig;
38734
38735 - configured = 1;
38736 -
38737 return 0;
38738
38739 noconfig:
38740 @@ -213,7 +220,7 @@ noconfig:
38741 static int __init init_kgdboc(void)
38742 {
38743 /* Already configured? */
38744 - if (configured == 1)
38745 + if (configured >= 1)
38746 return 0;
38747
38748 return configure_kgdboc();
38749 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38750 if (config[len - 1] == '\n')
38751 config[len - 1] = '\0';
38752
38753 - if (configured == 1)
38754 + if (configured >= 1)
38755 cleanup_kgdboc();
38756
38757 /* Go and configure with the new params. */
38758 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38759 .post_exception = kgdboc_post_exp_handler,
38760 };
38761
38762 +static struct kgdb_io kgdboc_io_ops_console = {
38763 + .name = "kgdboc",
38764 + .read_char = kgdboc_get_char,
38765 + .write_char = kgdboc_put_char,
38766 + .pre_exception = kgdboc_pre_exp_handler,
38767 + .post_exception = kgdboc_post_exp_handler,
38768 + .is_console = 1
38769 +};
38770 +
38771 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38772 /* This is only available if kgdboc is a built in for early debugging */
38773 static int __init kgdboc_early_init(char *opt)
38774 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38775 index a21dc8e..fe43e9e 100644
38776 --- a/drivers/tty/serial/serial_core.c
38777 +++ b/drivers/tty/serial/serial_core.c
38778 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38779 uart_flush_buffer(tty);
38780 uart_shutdown(tty, state);
38781 spin_lock_irqsave(&port->lock, flags);
38782 - port->count = 0;
38783 + atomic_set(&port->count, 0);
38784 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38785 spin_unlock_irqrestore(&port->lock, flags);
38786 tty_port_tty_set(port, NULL);
38787 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38788 goto end;
38789 }
38790
38791 - port->count++;
38792 + atomic_inc(&port->count);
38793 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38794 retval = -ENXIO;
38795 goto err_dec_count;
38796 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38797 /*
38798 * Make sure the device is in D0 state.
38799 */
38800 - if (port->count == 1)
38801 + if (atomic_read(&port->count) == 1)
38802 uart_change_pm(state, 0);
38803
38804 /*
38805 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38806 end:
38807 return retval;
38808 err_dec_count:
38809 - port->count--;
38810 + atomic_inc(&port->count);
38811 mutex_unlock(&port->mutex);
38812 goto end;
38813 }
38814 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38815 index 593d40a..bdc61f3 100644
38816 --- a/drivers/tty/synclink.c
38817 +++ b/drivers/tty/synclink.c
38818 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38819
38820 if (debug_level >= DEBUG_LEVEL_INFO)
38821 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38822 - __FILE__,__LINE__, info->device_name, info->port.count);
38823 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38824
38825 if (tty_port_close_start(&info->port, tty, filp) == 0)
38826 goto cleanup;
38827 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38828 cleanup:
38829 if (debug_level >= DEBUG_LEVEL_INFO)
38830 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38831 - tty->driver->name, info->port.count);
38832 + tty->driver->name, atomic_read(&info->port.count));
38833
38834 } /* end of mgsl_close() */
38835
38836 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38837
38838 mgsl_flush_buffer(tty);
38839 shutdown(info);
38840 -
38841 - info->port.count = 0;
38842 +
38843 + atomic_set(&info->port.count, 0);
38844 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38845 info->port.tty = NULL;
38846
38847 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38848
38849 if (debug_level >= DEBUG_LEVEL_INFO)
38850 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38851 - __FILE__,__LINE__, tty->driver->name, port->count );
38852 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38853
38854 spin_lock_irqsave(&info->irq_spinlock, flags);
38855 if (!tty_hung_up_p(filp)) {
38856 extra_count = true;
38857 - port->count--;
38858 + atomic_dec(&port->count);
38859 }
38860 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38861 port->blocked_open++;
38862 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38863
38864 if (debug_level >= DEBUG_LEVEL_INFO)
38865 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38866 - __FILE__,__LINE__, tty->driver->name, port->count );
38867 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38868
38869 tty_unlock();
38870 schedule();
38871 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38872
38873 /* FIXME: Racy on hangup during close wait */
38874 if (extra_count)
38875 - port->count++;
38876 + atomic_inc(&port->count);
38877 port->blocked_open--;
38878
38879 if (debug_level >= DEBUG_LEVEL_INFO)
38880 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38881 - __FILE__,__LINE__, tty->driver->name, port->count );
38882 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38883
38884 if (!retval)
38885 port->flags |= ASYNC_NORMAL_ACTIVE;
38886 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38887
38888 if (debug_level >= DEBUG_LEVEL_INFO)
38889 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38890 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38891 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38892
38893 /* If port is closing, signal caller to try again */
38894 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38895 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38896 spin_unlock_irqrestore(&info->netlock, flags);
38897 goto cleanup;
38898 }
38899 - info->port.count++;
38900 + atomic_inc(&info->port.count);
38901 spin_unlock_irqrestore(&info->netlock, flags);
38902
38903 - if (info->port.count == 1) {
38904 + if (atomic_read(&info->port.count) == 1) {
38905 /* 1st open on this device, init hardware */
38906 retval = startup(info);
38907 if (retval < 0)
38908 @@ -3444,8 +3444,8 @@ cleanup:
38909 if (retval) {
38910 if (tty->count == 1)
38911 info->port.tty = NULL; /* tty layer will release tty struct */
38912 - if(info->port.count)
38913 - info->port.count--;
38914 + if (atomic_read(&info->port.count))
38915 + atomic_dec(&info->port.count);
38916 }
38917
38918 return retval;
38919 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38920 unsigned short new_crctype;
38921
38922 /* return error if TTY interface open */
38923 - if (info->port.count)
38924 + if (atomic_read(&info->port.count))
38925 return -EBUSY;
38926
38927 switch (encoding)
38928 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38929
38930 /* arbitrate between network and tty opens */
38931 spin_lock_irqsave(&info->netlock, flags);
38932 - if (info->port.count != 0 || info->netcount != 0) {
38933 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38934 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38935 spin_unlock_irqrestore(&info->netlock, flags);
38936 return -EBUSY;
38937 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38938 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38939
38940 /* return error if TTY interface open */
38941 - if (info->port.count)
38942 + if (atomic_read(&info->port.count))
38943 return -EBUSY;
38944
38945 if (cmd != SIOCWANDEV)
38946 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38947 index aa1debf..9297a16 100644
38948 --- a/drivers/tty/synclink_gt.c
38949 +++ b/drivers/tty/synclink_gt.c
38950 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38951 tty->driver_data = info;
38952 info->port.tty = tty;
38953
38954 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38955 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38956
38957 /* If port is closing, signal caller to try again */
38958 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38959 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38960 mutex_unlock(&info->port.mutex);
38961 goto cleanup;
38962 }
38963 - info->port.count++;
38964 + atomic_inc(&info->port.count);
38965 spin_unlock_irqrestore(&info->netlock, flags);
38966
38967 - if (info->port.count == 1) {
38968 + if (atomic_read(&info->port.count) == 1) {
38969 /* 1st open on this device, init hardware */
38970 retval = startup(info);
38971 if (retval < 0) {
38972 @@ -716,8 +716,8 @@ cleanup:
38973 if (retval) {
38974 if (tty->count == 1)
38975 info->port.tty = NULL; /* tty layer will release tty struct */
38976 - if(info->port.count)
38977 - info->port.count--;
38978 + if(atomic_read(&info->port.count))
38979 + atomic_dec(&info->port.count);
38980 }
38981
38982 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38983 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38984
38985 if (sanity_check(info, tty->name, "close"))
38986 return;
38987 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38988 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38989
38990 if (tty_port_close_start(&info->port, tty, filp) == 0)
38991 goto cleanup;
38992 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38993 tty_port_close_end(&info->port, tty);
38994 info->port.tty = NULL;
38995 cleanup:
38996 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38997 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38998 }
38999
39000 static void hangup(struct tty_struct *tty)
39001 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
39002 shutdown(info);
39003
39004 spin_lock_irqsave(&info->port.lock, flags);
39005 - info->port.count = 0;
39006 + atomic_set(&info->port.count, 0);
39007 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39008 info->port.tty = NULL;
39009 spin_unlock_irqrestore(&info->port.lock, flags);
39010 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39011 unsigned short new_crctype;
39012
39013 /* return error if TTY interface open */
39014 - if (info->port.count)
39015 + if (atomic_read(&info->port.count))
39016 return -EBUSY;
39017
39018 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
39019 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
39020
39021 /* arbitrate between network and tty opens */
39022 spin_lock_irqsave(&info->netlock, flags);
39023 - if (info->port.count != 0 || info->netcount != 0) {
39024 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39025 DBGINFO(("%s hdlc_open busy\n", dev->name));
39026 spin_unlock_irqrestore(&info->netlock, flags);
39027 return -EBUSY;
39028 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39029 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
39030
39031 /* return error if TTY interface open */
39032 - if (info->port.count)
39033 + if (atomic_read(&info->port.count))
39034 return -EBUSY;
39035
39036 if (cmd != SIOCWANDEV)
39037 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
39038 if (port == NULL)
39039 continue;
39040 spin_lock(&port->lock);
39041 - if ((port->port.count || port->netcount) &&
39042 + if ((atomic_read(&port->port.count) || port->netcount) &&
39043 port->pending_bh && !port->bh_running &&
39044 !port->bh_requested) {
39045 DBGISR(("%s bh queued\n", port->device_name));
39046 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39047 spin_lock_irqsave(&info->lock, flags);
39048 if (!tty_hung_up_p(filp)) {
39049 extra_count = true;
39050 - port->count--;
39051 + atomic_dec(&port->count);
39052 }
39053 spin_unlock_irqrestore(&info->lock, flags);
39054 port->blocked_open++;
39055 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39056 remove_wait_queue(&port->open_wait, &wait);
39057
39058 if (extra_count)
39059 - port->count++;
39060 + atomic_inc(&port->count);
39061 port->blocked_open--;
39062
39063 if (!retval)
39064 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
39065 index a3dddc1..8905ab2 100644
39066 --- a/drivers/tty/synclinkmp.c
39067 +++ b/drivers/tty/synclinkmp.c
39068 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
39069
39070 if (debug_level >= DEBUG_LEVEL_INFO)
39071 printk("%s(%d):%s open(), old ref count = %d\n",
39072 - __FILE__,__LINE__,tty->driver->name, info->port.count);
39073 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
39074
39075 /* If port is closing, signal caller to try again */
39076 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
39077 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
39078 spin_unlock_irqrestore(&info->netlock, flags);
39079 goto cleanup;
39080 }
39081 - info->port.count++;
39082 + atomic_inc(&info->port.count);
39083 spin_unlock_irqrestore(&info->netlock, flags);
39084
39085 - if (info->port.count == 1) {
39086 + if (atomic_read(&info->port.count) == 1) {
39087 /* 1st open on this device, init hardware */
39088 retval = startup(info);
39089 if (retval < 0)
39090 @@ -788,8 +788,8 @@ cleanup:
39091 if (retval) {
39092 if (tty->count == 1)
39093 info->port.tty = NULL; /* tty layer will release tty struct */
39094 - if(info->port.count)
39095 - info->port.count--;
39096 + if(atomic_read(&info->port.count))
39097 + atomic_dec(&info->port.count);
39098 }
39099
39100 return retval;
39101 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39102
39103 if (debug_level >= DEBUG_LEVEL_INFO)
39104 printk("%s(%d):%s close() entry, count=%d\n",
39105 - __FILE__,__LINE__, info->device_name, info->port.count);
39106 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
39107
39108 if (tty_port_close_start(&info->port, tty, filp) == 0)
39109 goto cleanup;
39110 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39111 cleanup:
39112 if (debug_level >= DEBUG_LEVEL_INFO)
39113 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
39114 - tty->driver->name, info->port.count);
39115 + tty->driver->name, atomic_read(&info->port.count));
39116 }
39117
39118 /* Called by tty_hangup() when a hangup is signaled.
39119 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
39120 shutdown(info);
39121
39122 spin_lock_irqsave(&info->port.lock, flags);
39123 - info->port.count = 0;
39124 + atomic_set(&info->port.count, 0);
39125 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39126 info->port.tty = NULL;
39127 spin_unlock_irqrestore(&info->port.lock, flags);
39128 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39129 unsigned short new_crctype;
39130
39131 /* return error if TTY interface open */
39132 - if (info->port.count)
39133 + if (atomic_read(&info->port.count))
39134 return -EBUSY;
39135
39136 switch (encoding)
39137 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
39138
39139 /* arbitrate between network and tty opens */
39140 spin_lock_irqsave(&info->netlock, flags);
39141 - if (info->port.count != 0 || info->netcount != 0) {
39142 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39143 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39144 spin_unlock_irqrestore(&info->netlock, flags);
39145 return -EBUSY;
39146 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39147 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
39148
39149 /* return error if TTY interface open */
39150 - if (info->port.count)
39151 + if (atomic_read(&info->port.count))
39152 return -EBUSY;
39153
39154 if (cmd != SIOCWANDEV)
39155 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
39156 * do not request bottom half processing if the
39157 * device is not open in a normal mode.
39158 */
39159 - if ( port && (port->port.count || port->netcount) &&
39160 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
39161 port->pending_bh && !port->bh_running &&
39162 !port->bh_requested ) {
39163 if ( debug_level >= DEBUG_LEVEL_ISR )
39164 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39165
39166 if (debug_level >= DEBUG_LEVEL_INFO)
39167 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
39168 - __FILE__,__LINE__, tty->driver->name, port->count );
39169 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39170
39171 spin_lock_irqsave(&info->lock, flags);
39172 if (!tty_hung_up_p(filp)) {
39173 extra_count = true;
39174 - port->count--;
39175 + atomic_dec(&port->count);
39176 }
39177 spin_unlock_irqrestore(&info->lock, flags);
39178 port->blocked_open++;
39179 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39180
39181 if (debug_level >= DEBUG_LEVEL_INFO)
39182 printk("%s(%d):%s block_til_ready() count=%d\n",
39183 - __FILE__,__LINE__, tty->driver->name, port->count );
39184 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39185
39186 tty_unlock();
39187 schedule();
39188 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39189 remove_wait_queue(&port->open_wait, &wait);
39190
39191 if (extra_count)
39192 - port->count++;
39193 + atomic_inc(&port->count);
39194 port->blocked_open--;
39195
39196 if (debug_level >= DEBUG_LEVEL_INFO)
39197 printk("%s(%d):%s block_til_ready() after, count=%d\n",
39198 - __FILE__,__LINE__, tty->driver->name, port->count );
39199 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39200
39201 if (!retval)
39202 port->flags |= ASYNC_NORMAL_ACTIVE;
39203 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
39204 index 05728894..b9d44c6 100644
39205 --- a/drivers/tty/sysrq.c
39206 +++ b/drivers/tty/sysrq.c
39207 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
39208 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
39209 size_t count, loff_t *ppos)
39210 {
39211 - if (count) {
39212 + if (count && capable(CAP_SYS_ADMIN)) {
39213 char c;
39214
39215 if (get_user(c, buf))
39216 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
39217 index b425c79..08a3f06 100644
39218 --- a/drivers/tty/tty_io.c
39219 +++ b/drivers/tty/tty_io.c
39220 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
39221
39222 void tty_default_fops(struct file_operations *fops)
39223 {
39224 - *fops = tty_fops;
39225 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
39226 }
39227
39228 /*
39229 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
39230 index 6f99c99..8947bc4 100644
39231 --- a/drivers/tty/tty_ldisc.c
39232 +++ b/drivers/tty/tty_ldisc.c
39233 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
39234 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
39235 struct tty_ldisc_ops *ldo = ld->ops;
39236
39237 - ldo->refcount--;
39238 + atomic_dec(&ldo->refcount);
39239 module_put(ldo->owner);
39240 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39241
39242 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
39243 spin_lock_irqsave(&tty_ldisc_lock, flags);
39244 tty_ldiscs[disc] = new_ldisc;
39245 new_ldisc->num = disc;
39246 - new_ldisc->refcount = 0;
39247 + atomic_set(&new_ldisc->refcount, 0);
39248 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39249
39250 return ret;
39251 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
39252 return -EINVAL;
39253
39254 spin_lock_irqsave(&tty_ldisc_lock, flags);
39255 - if (tty_ldiscs[disc]->refcount)
39256 + if (atomic_read(&tty_ldiscs[disc]->refcount))
39257 ret = -EBUSY;
39258 else
39259 tty_ldiscs[disc] = NULL;
39260 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
39261 if (ldops) {
39262 ret = ERR_PTR(-EAGAIN);
39263 if (try_module_get(ldops->owner)) {
39264 - ldops->refcount++;
39265 + atomic_inc(&ldops->refcount);
39266 ret = ldops;
39267 }
39268 }
39269 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
39270 unsigned long flags;
39271
39272 spin_lock_irqsave(&tty_ldisc_lock, flags);
39273 - ldops->refcount--;
39274 + atomic_dec(&ldops->refcount);
39275 module_put(ldops->owner);
39276 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39277 }
39278 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
39279 index bf6e238..d401c04 100644
39280 --- a/drivers/tty/tty_port.c
39281 +++ b/drivers/tty/tty_port.c
39282 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
39283 unsigned long flags;
39284
39285 spin_lock_irqsave(&port->lock, flags);
39286 - port->count = 0;
39287 + atomic_set(&port->count, 0);
39288 port->flags &= ~ASYNC_NORMAL_ACTIVE;
39289 if (port->tty) {
39290 set_bit(TTY_IO_ERROR, &port->tty->flags);
39291 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39292 /* The port lock protects the port counts */
39293 spin_lock_irqsave(&port->lock, flags);
39294 if (!tty_hung_up_p(filp))
39295 - port->count--;
39296 + atomic_dec(&port->count);
39297 port->blocked_open++;
39298 spin_unlock_irqrestore(&port->lock, flags);
39299
39300 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39301 we must not mess that up further */
39302 spin_lock_irqsave(&port->lock, flags);
39303 if (!tty_hung_up_p(filp))
39304 - port->count++;
39305 + atomic_inc(&port->count);
39306 port->blocked_open--;
39307 if (retval == 0)
39308 port->flags |= ASYNC_NORMAL_ACTIVE;
39309 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
39310 return 0;
39311 }
39312
39313 - if (tty->count == 1 && port->count != 1) {
39314 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
39315 printk(KERN_WARNING
39316 "tty_port_close_start: tty->count = 1 port count = %d.\n",
39317 - port->count);
39318 - port->count = 1;
39319 + atomic_read(&port->count));
39320 + atomic_set(&port->count, 1);
39321 }
39322 - if (--port->count < 0) {
39323 + if (atomic_dec_return(&port->count) < 0) {
39324 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
39325 - port->count);
39326 - port->count = 0;
39327 + atomic_read(&port->count));
39328 + atomic_set(&port->count, 0);
39329 }
39330
39331 - if (port->count) {
39332 + if (atomic_read(&port->count)) {
39333 spin_unlock_irqrestore(&port->lock, flags);
39334 if (port->ops->drop)
39335 port->ops->drop(port);
39336 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39337 {
39338 spin_lock_irq(&port->lock);
39339 if (!tty_hung_up_p(filp))
39340 - ++port->count;
39341 + atomic_inc(&port->count);
39342 spin_unlock_irq(&port->lock);
39343 tty_port_tty_set(port, tty);
39344
39345 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39346 index 770a854..e5d3db3 100644
39347 --- a/drivers/tty/vt/keyboard.c
39348 +++ b/drivers/tty/vt/keyboard.c
39349 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39350 kbd->kbdmode == VC_OFF) &&
39351 value != KVAL(K_SAK))
39352 return; /* SAK is allowed even in raw mode */
39353 +
39354 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39355 + {
39356 + void *func = fn_handler[value];
39357 + if (func == fn_show_state || func == fn_show_ptregs ||
39358 + func == fn_show_mem)
39359 + return;
39360 + }
39361 +#endif
39362 +
39363 fn_handler[value](vc);
39364 }
39365
39366 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39367 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39368 return -EFAULT;
39369
39370 - if (!capable(CAP_SYS_TTY_CONFIG))
39371 - perm = 0;
39372 -
39373 switch (cmd) {
39374 case KDGKBENT:
39375 /* Ensure another thread doesn't free it under us */
39376 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39377 spin_unlock_irqrestore(&kbd_event_lock, flags);
39378 return put_user(val, &user_kbe->kb_value);
39379 case KDSKBENT:
39380 + if (!capable(CAP_SYS_TTY_CONFIG))
39381 + perm = 0;
39382 +
39383 if (!perm)
39384 return -EPERM;
39385 if (!i && v == K_NOSUCHMAP) {
39386 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39387 int i, j, k;
39388 int ret;
39389
39390 - if (!capable(CAP_SYS_TTY_CONFIG))
39391 - perm = 0;
39392 -
39393 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39394 if (!kbs) {
39395 ret = -ENOMEM;
39396 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39397 kfree(kbs);
39398 return ((p && *p) ? -EOVERFLOW : 0);
39399 case KDSKBSENT:
39400 + if (!capable(CAP_SYS_TTY_CONFIG))
39401 + perm = 0;
39402 +
39403 if (!perm) {
39404 ret = -EPERM;
39405 goto reterr;
39406 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39407 index a783d53..cb30d94 100644
39408 --- a/drivers/uio/uio.c
39409 +++ b/drivers/uio/uio.c
39410 @@ -25,6 +25,7 @@
39411 #include <linux/kobject.h>
39412 #include <linux/cdev.h>
39413 #include <linux/uio_driver.h>
39414 +#include <asm/local.h>
39415
39416 #define UIO_MAX_DEVICES (1U << MINORBITS)
39417
39418 @@ -32,10 +33,10 @@ struct uio_device {
39419 struct module *owner;
39420 struct device *dev;
39421 int minor;
39422 - atomic_t event;
39423 + atomic_unchecked_t event;
39424 struct fasync_struct *async_queue;
39425 wait_queue_head_t wait;
39426 - int vma_count;
39427 + local_t vma_count;
39428 struct uio_info *info;
39429 struct kobject *map_dir;
39430 struct kobject *portio_dir;
39431 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39432 struct device_attribute *attr, char *buf)
39433 {
39434 struct uio_device *idev = dev_get_drvdata(dev);
39435 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39436 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39437 }
39438
39439 static struct device_attribute uio_class_attributes[] = {
39440 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39441 {
39442 struct uio_device *idev = info->uio_dev;
39443
39444 - atomic_inc(&idev->event);
39445 + atomic_inc_unchecked(&idev->event);
39446 wake_up_interruptible(&idev->wait);
39447 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39448 }
39449 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39450 }
39451
39452 listener->dev = idev;
39453 - listener->event_count = atomic_read(&idev->event);
39454 + listener->event_count = atomic_read_unchecked(&idev->event);
39455 filep->private_data = listener;
39456
39457 if (idev->info->open) {
39458 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39459 return -EIO;
39460
39461 poll_wait(filep, &idev->wait, wait);
39462 - if (listener->event_count != atomic_read(&idev->event))
39463 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39464 return POLLIN | POLLRDNORM;
39465 return 0;
39466 }
39467 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39468 do {
39469 set_current_state(TASK_INTERRUPTIBLE);
39470
39471 - event_count = atomic_read(&idev->event);
39472 + event_count = atomic_read_unchecked(&idev->event);
39473 if (event_count != listener->event_count) {
39474 if (copy_to_user(buf, &event_count, count))
39475 retval = -EFAULT;
39476 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39477 static void uio_vma_open(struct vm_area_struct *vma)
39478 {
39479 struct uio_device *idev = vma->vm_private_data;
39480 - idev->vma_count++;
39481 + local_inc(&idev->vma_count);
39482 }
39483
39484 static void uio_vma_close(struct vm_area_struct *vma)
39485 {
39486 struct uio_device *idev = vma->vm_private_data;
39487 - idev->vma_count--;
39488 + local_dec(&idev->vma_count);
39489 }
39490
39491 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39492 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39493 idev->owner = owner;
39494 idev->info = info;
39495 init_waitqueue_head(&idev->wait);
39496 - atomic_set(&idev->event, 0);
39497 + atomic_set_unchecked(&idev->event, 0);
39498
39499 ret = uio_get_minor(idev);
39500 if (ret)
39501 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39502 index b7eb86a..36d28af 100644
39503 --- a/drivers/usb/atm/cxacru.c
39504 +++ b/drivers/usb/atm/cxacru.c
39505 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39506 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39507 if (ret < 2)
39508 return -EINVAL;
39509 - if (index < 0 || index > 0x7f)
39510 + if (index > 0x7f)
39511 return -EINVAL;
39512 pos += tmp;
39513
39514 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39515 index ee62b35..b663594 100644
39516 --- a/drivers/usb/atm/usbatm.c
39517 +++ b/drivers/usb/atm/usbatm.c
39518 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39519 if (printk_ratelimit())
39520 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39521 __func__, vpi, vci);
39522 - atomic_inc(&vcc->stats->rx_err);
39523 + atomic_inc_unchecked(&vcc->stats->rx_err);
39524 return;
39525 }
39526
39527 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39528 if (length > ATM_MAX_AAL5_PDU) {
39529 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39530 __func__, length, vcc);
39531 - atomic_inc(&vcc->stats->rx_err);
39532 + atomic_inc_unchecked(&vcc->stats->rx_err);
39533 goto out;
39534 }
39535
39536 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39537 if (sarb->len < pdu_length) {
39538 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39539 __func__, pdu_length, sarb->len, vcc);
39540 - atomic_inc(&vcc->stats->rx_err);
39541 + atomic_inc_unchecked(&vcc->stats->rx_err);
39542 goto out;
39543 }
39544
39545 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39546 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39547 __func__, vcc);
39548 - atomic_inc(&vcc->stats->rx_err);
39549 + atomic_inc_unchecked(&vcc->stats->rx_err);
39550 goto out;
39551 }
39552
39553 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39554 if (printk_ratelimit())
39555 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39556 __func__, length);
39557 - atomic_inc(&vcc->stats->rx_drop);
39558 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39559 goto out;
39560 }
39561
39562 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39563
39564 vcc->push(vcc, skb);
39565
39566 - atomic_inc(&vcc->stats->rx);
39567 + atomic_inc_unchecked(&vcc->stats->rx);
39568 out:
39569 skb_trim(sarb, 0);
39570 }
39571 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39572 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39573
39574 usbatm_pop(vcc, skb);
39575 - atomic_inc(&vcc->stats->tx);
39576 + atomic_inc_unchecked(&vcc->stats->tx);
39577
39578 skb = skb_dequeue(&instance->sndqueue);
39579 }
39580 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39581 if (!left--)
39582 return sprintf(page,
39583 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39584 - atomic_read(&atm_dev->stats.aal5.tx),
39585 - atomic_read(&atm_dev->stats.aal5.tx_err),
39586 - atomic_read(&atm_dev->stats.aal5.rx),
39587 - atomic_read(&atm_dev->stats.aal5.rx_err),
39588 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39589 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39590 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39591 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39592 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39593 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39594
39595 if (!left--) {
39596 if (instance->disconnected)
39597 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39598 index 3440812..2a4ef1f 100644
39599 --- a/drivers/usb/core/devices.c
39600 +++ b/drivers/usb/core/devices.c
39601 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39602 * time it gets called.
39603 */
39604 static struct device_connect_event {
39605 - atomic_t count;
39606 + atomic_unchecked_t count;
39607 wait_queue_head_t wait;
39608 } device_event = {
39609 .count = ATOMIC_INIT(1),
39610 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39611
39612 void usbfs_conn_disc_event(void)
39613 {
39614 - atomic_add(2, &device_event.count);
39615 + atomic_add_unchecked(2, &device_event.count);
39616 wake_up(&device_event.wait);
39617 }
39618
39619 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39620
39621 poll_wait(file, &device_event.wait, wait);
39622
39623 - event_count = atomic_read(&device_event.count);
39624 + event_count = atomic_read_unchecked(&device_event.count);
39625 if (file->f_version != event_count) {
39626 file->f_version = event_count;
39627 return POLLIN | POLLRDNORM;
39628 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39629 index 89dcf15..481800b 100644
39630 --- a/drivers/usb/early/ehci-dbgp.c
39631 +++ b/drivers/usb/early/ehci-dbgp.c
39632 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39633
39634 #ifdef CONFIG_KGDB
39635 static struct kgdb_io kgdbdbgp_io_ops;
39636 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39637 +static struct kgdb_io kgdbdbgp_io_ops_console;
39638 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39639 #else
39640 #define dbgp_kgdb_mode (0)
39641 #endif
39642 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39643 .write_char = kgdbdbgp_write_char,
39644 };
39645
39646 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39647 + .name = "kgdbdbgp",
39648 + .read_char = kgdbdbgp_read_char,
39649 + .write_char = kgdbdbgp_write_char,
39650 + .is_console = 1
39651 +};
39652 +
39653 static int kgdbdbgp_wait_time;
39654
39655 static int __init kgdbdbgp_parse_config(char *str)
39656 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39657 ptr++;
39658 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39659 }
39660 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39661 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39662 + if (early_dbgp_console.index != -1)
39663 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39664 + else
39665 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39666
39667 return 0;
39668 }
39669 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39670 index da6d479..80ed10b 100644
39671 --- a/drivers/usb/gadget/u_serial.c
39672 +++ b/drivers/usb/gadget/u_serial.c
39673 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39674 spin_lock_irq(&port->port_lock);
39675
39676 /* already open? Great. */
39677 - if (port->port.count) {
39678 + if (atomic_read(&port->port.count)) {
39679 status = 0;
39680 - port->port.count++;
39681 + atomic_inc(&port->port.count);
39682
39683 /* currently opening/closing? wait ... */
39684 } else if (port->openclose) {
39685 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39686 tty->driver_data = port;
39687 port->port.tty = tty;
39688
39689 - port->port.count = 1;
39690 + atomic_set(&port->port.count, 1);
39691 port->openclose = false;
39692
39693 /* if connected, start the I/O stream */
39694 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39695
39696 spin_lock_irq(&port->port_lock);
39697
39698 - if (port->port.count != 1) {
39699 - if (port->port.count == 0)
39700 + if (atomic_read(&port->port.count) != 1) {
39701 + if (atomic_read(&port->port.count) == 0)
39702 WARN_ON(1);
39703 else
39704 - --port->port.count;
39705 + atomic_dec(&port->port.count);
39706 goto exit;
39707 }
39708
39709 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39710 * and sleep if necessary
39711 */
39712 port->openclose = true;
39713 - port->port.count = 0;
39714 + atomic_set(&port->port.count, 0);
39715
39716 gser = port->port_usb;
39717 if (gser && gser->disconnect)
39718 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39719 int cond;
39720
39721 spin_lock_irq(&port->port_lock);
39722 - cond = (port->port.count == 0) && !port->openclose;
39723 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39724 spin_unlock_irq(&port->port_lock);
39725 return cond;
39726 }
39727 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39728 /* if it's already open, start I/O ... and notify the serial
39729 * protocol about open/close status (connect/disconnect).
39730 */
39731 - if (port->port.count) {
39732 + if (atomic_read(&port->port.count)) {
39733 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39734 gs_start_io(port);
39735 if (gser->connect)
39736 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39737
39738 port->port_usb = NULL;
39739 gser->ioport = NULL;
39740 - if (port->port.count > 0 || port->openclose) {
39741 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39742 wake_up_interruptible(&port->drain_wait);
39743 if (port->port.tty)
39744 tty_hangup(port->port.tty);
39745 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39746
39747 /* finally, free any unused/unusable I/O buffers */
39748 spin_lock_irqsave(&port->port_lock, flags);
39749 - if (port->port.count == 0 && !port->openclose)
39750 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39751 gs_buf_free(&port->port_write_buf);
39752 gs_free_requests(gser->out, &port->read_pool, NULL);
39753 gs_free_requests(gser->out, &port->read_queue, NULL);
39754 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39755 index b9cca6d..75c75df 100644
39756 --- a/drivers/usb/serial/console.c
39757 +++ b/drivers/usb/serial/console.c
39758 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39759
39760 info->port = port;
39761
39762 - ++port->port.count;
39763 + atomic_inc(&port->port.count);
39764 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39765 if (serial->type->set_termios) {
39766 /*
39767 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39768 }
39769 /* Now that any required fake tty operations are completed restore
39770 * the tty port count */
39771 - --port->port.count;
39772 + atomic_dec(&port->port.count);
39773 /* The console is special in terms of closing the device so
39774 * indicate this port is now acting as a system console. */
39775 port->port.console = 1;
39776 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39777 free_tty:
39778 kfree(tty);
39779 reset_open_count:
39780 - port->port.count = 0;
39781 + atomic_set(&port->port.count, 0);
39782 usb_autopm_put_interface(serial->interface);
39783 error_get_interface:
39784 usb_serial_put(serial);
39785 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39786 index d6bea3e..60b250e 100644
39787 --- a/drivers/usb/wusbcore/wa-hc.h
39788 +++ b/drivers/usb/wusbcore/wa-hc.h
39789 @@ -192,7 +192,7 @@ struct wahc {
39790 struct list_head xfer_delayed_list;
39791 spinlock_t xfer_list_lock;
39792 struct work_struct xfer_work;
39793 - atomic_t xfer_id_count;
39794 + atomic_unchecked_t xfer_id_count;
39795 };
39796
39797
39798 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39799 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39800 spin_lock_init(&wa->xfer_list_lock);
39801 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39802 - atomic_set(&wa->xfer_id_count, 1);
39803 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39804 }
39805
39806 /**
39807 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39808 index 57c01ab..8a05959 100644
39809 --- a/drivers/usb/wusbcore/wa-xfer.c
39810 +++ b/drivers/usb/wusbcore/wa-xfer.c
39811 @@ -296,7 +296,7 @@ out:
39812 */
39813 static void wa_xfer_id_init(struct wa_xfer *xfer)
39814 {
39815 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39816 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39817 }
39818
39819 /*
39820 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39821 index ef82a0d..da8a0b3 100644
39822 --- a/drivers/vhost/vhost.c
39823 +++ b/drivers/vhost/vhost.c
39824 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39825 return 0;
39826 }
39827
39828 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39829 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39830 {
39831 struct file *eventfp, *filep = NULL,
39832 *pollstart = NULL, *pollstop = NULL;
39833 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39834 index 747442d..7c0c434 100644
39835 --- a/drivers/video/aty/aty128fb.c
39836 +++ b/drivers/video/aty/aty128fb.c
39837 @@ -149,7 +149,7 @@ enum {
39838 };
39839
39840 /* Must match above enum */
39841 -static const char *r128_family[] __devinitdata = {
39842 +static const char *r128_family[] __devinitconst = {
39843 "AGP",
39844 "PCI",
39845 "PRO AGP",
39846 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39847 index 5c3960d..15cf8fc 100644
39848 --- a/drivers/video/fbcmap.c
39849 +++ b/drivers/video/fbcmap.c
39850 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39851 rc = -ENODEV;
39852 goto out;
39853 }
39854 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39855 - !info->fbops->fb_setcmap)) {
39856 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39857 rc = -EINVAL;
39858 goto out1;
39859 }
39860 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39861 index 0dff12a..2ef47b3 100644
39862 --- a/drivers/video/fbmem.c
39863 +++ b/drivers/video/fbmem.c
39864 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39865 image->dx += image->width + 8;
39866 }
39867 } else if (rotate == FB_ROTATE_UD) {
39868 - for (x = 0; x < num && image->dx >= 0; x++) {
39869 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39870 info->fbops->fb_imageblit(info, image);
39871 image->dx -= image->width + 8;
39872 }
39873 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39874 image->dy += image->height + 8;
39875 }
39876 } else if (rotate == FB_ROTATE_CCW) {
39877 - for (x = 0; x < num && image->dy >= 0; x++) {
39878 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39879 info->fbops->fb_imageblit(info, image);
39880 image->dy -= image->height + 8;
39881 }
39882 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39883 return -EFAULT;
39884 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39885 return -EINVAL;
39886 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39887 + if (con2fb.framebuffer >= FB_MAX)
39888 return -EINVAL;
39889 if (!registered_fb[con2fb.framebuffer])
39890 request_module("fb%d", con2fb.framebuffer);
39891 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39892 index 5a5d092..265c5ed 100644
39893 --- a/drivers/video/geode/gx1fb_core.c
39894 +++ b/drivers/video/geode/gx1fb_core.c
39895 @@ -29,7 +29,7 @@ static int crt_option = 1;
39896 static char panel_option[32] = "";
39897
39898 /* Modes relevant to the GX1 (taken from modedb.c) */
39899 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39900 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39901 /* 640x480-60 VESA */
39902 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39903 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39904 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39905 index 0fad23f..0e9afa4 100644
39906 --- a/drivers/video/gxt4500.c
39907 +++ b/drivers/video/gxt4500.c
39908 @@ -156,7 +156,7 @@ struct gxt4500_par {
39909 static char *mode_option;
39910
39911 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39912 -static const struct fb_videomode defaultmode __devinitdata = {
39913 +static const struct fb_videomode defaultmode __devinitconst = {
39914 .refresh = 60,
39915 .xres = 1280,
39916 .yres = 1024,
39917 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39918 return 0;
39919 }
39920
39921 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39922 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39923 .id = "IBM GXT4500P",
39924 .type = FB_TYPE_PACKED_PIXELS,
39925 .visual = FB_VISUAL_PSEUDOCOLOR,
39926 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39927 index 7672d2e..b56437f 100644
39928 --- a/drivers/video/i810/i810_accel.c
39929 +++ b/drivers/video/i810/i810_accel.c
39930 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39931 }
39932 }
39933 printk("ringbuffer lockup!!!\n");
39934 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39935 i810_report_error(mmio);
39936 par->dev_flags |= LOCKUP;
39937 info->pixmap.scan_align = 1;
39938 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39939 index b83f361..2b05a91 100644
39940 --- a/drivers/video/i810/i810_main.c
39941 +++ b/drivers/video/i810/i810_main.c
39942 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39943 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39944
39945 /* PCI */
39946 -static const char *i810_pci_list[] __devinitdata = {
39947 +static const char *i810_pci_list[] __devinitconst = {
39948 "Intel(R) 810 Framebuffer Device" ,
39949 "Intel(R) 810-DC100 Framebuffer Device" ,
39950 "Intel(R) 810E Framebuffer Device" ,
39951 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39952 index de36693..3c63fc2 100644
39953 --- a/drivers/video/jz4740_fb.c
39954 +++ b/drivers/video/jz4740_fb.c
39955 @@ -136,7 +136,7 @@ struct jzfb {
39956 uint32_t pseudo_palette[16];
39957 };
39958
39959 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39960 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39961 .id = "JZ4740 FB",
39962 .type = FB_TYPE_PACKED_PIXELS,
39963 .visual = FB_VISUAL_TRUECOLOR,
39964 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39965 index 3c14e43..eafa544 100644
39966 --- a/drivers/video/logo/logo_linux_clut224.ppm
39967 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39968 @@ -1,1604 +1,1123 @@
39969 P3
39970 -# Standard 224-color Linux logo
39971 80 80
39972 255
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 - 6 6 6 6 6 6 10 10 10 10 10 10
39983 - 10 10 10 6 6 6 6 6 6 6 6 6
39984 - 0 0 0 0 0 0 0 0 0 0 0 0
39985 - 0 0 0 0 0 0 0 0 0 0 0 0
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 0 0 0
39988 - 0 0 0 0 0 0 0 0 0 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
40002 - 22 22 22 26 26 26 30 30 30 34 34 34
40003 - 30 30 30 30 30 30 26 26 26 18 18 18
40004 - 14 14 14 10 10 10 6 6 6 0 0 0
40005 - 0 0 0 0 0 0 0 0 0 0 0 0
40006 - 0 0 0 0 0 0 0 0 0 0 0 0
40007 - 0 0 0 0 0 0 0 0 0 0 0 0
40008 - 0 0 0 0 0 0 0 0 0 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 0 0 0 0 0 0 0 0 0 0 0 0
40014 - 0 0 0 0 0 1 0 0 1 0 0 0
40015 - 0 0 0 0 0 0 0 0 0 0 0 0
40016 - 0 0 0 0 0 0 0 0 0 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 0 0 0
40018 - 0 0 0 0 0 0 0 0 0 0 0 0
40019 - 0 0 0 0 0 0 0 0 0 0 0 0
40020 - 0 0 0 0 0 0 0 0 0 0 0 0
40021 - 6 6 6 14 14 14 26 26 26 42 42 42
40022 - 54 54 54 66 66 66 78 78 78 78 78 78
40023 - 78 78 78 74 74 74 66 66 66 54 54 54
40024 - 42 42 42 26 26 26 18 18 18 10 10 10
40025 - 6 6 6 0 0 0 0 0 0 0 0 0
40026 - 0 0 0 0 0 0 0 0 0 0 0 0
40027 - 0 0 0 0 0 0 0 0 0 0 0 0
40028 - 0 0 0 0 0 0 0 0 0 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 0 0 0
40032 - 0 0 0 0 0 0 0 0 0 0 0 0
40033 - 0 0 0 0 0 0 0 0 0 0 0 0
40034 - 0 0 1 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 10 10 10
40041 - 22 22 22 42 42 42 66 66 66 86 86 86
40042 - 66 66 66 38 38 38 38 38 38 22 22 22
40043 - 26 26 26 34 34 34 54 54 54 66 66 66
40044 - 86 86 86 70 70 70 46 46 46 26 26 26
40045 - 14 14 14 6 6 6 0 0 0 0 0 0
40046 - 0 0 0 0 0 0 0 0 0 0 0 0
40047 - 0 0 0 0 0 0 0 0 0 0 0 0
40048 - 0 0 0 0 0 0 0 0 0 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 0 0 0
40053 - 0 0 0 0 0 0 0 0 0 0 0 0
40054 - 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
40061 - 50 50 50 82 82 82 58 58 58 6 6 6
40062 - 2 2 6 2 2 6 2 2 6 2 2 6
40063 - 2 2 6 2 2 6 2 2 6 2 2 6
40064 - 6 6 6 54 54 54 86 86 86 66 66 66
40065 - 38 38 38 18 18 18 6 6 6 0 0 0
40066 - 0 0 0 0 0 0 0 0 0 0 0 0
40067 - 0 0 0 0 0 0 0 0 0 0 0 0
40068 - 0 0 0 0 0 0 0 0 0 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 0 0 0
40072 - 0 0 0 0 0 0 0 0 0 0 0 0
40073 - 0 0 0 0 0 0 0 0 0 0 0 0
40074 - 0 0 0 0 0 0 0 0 0 0 0 0
40075 - 0 0 0 0 0 0 0 0 0 0 0 0
40076 - 0 0 0 0 0 0 0 0 0 0 0 0
40077 - 0 0 0 0 0 0 0 0 0 0 0 0
40078 - 0 0 0 0 0 0 0 0 0 0 0 0
40079 - 0 0 0 0 0 0 0 0 0 0 0 0
40080 - 0 0 0 6 6 6 22 22 22 50 50 50
40081 - 78 78 78 34 34 34 2 2 6 2 2 6
40082 - 2 2 6 2 2 6 2 2 6 2 2 6
40083 - 2 2 6 2 2 6 2 2 6 2 2 6
40084 - 2 2 6 2 2 6 6 6 6 70 70 70
40085 - 78 78 78 46 46 46 22 22 22 6 6 6
40086 - 0 0 0 0 0 0 0 0 0 0 0 0
40087 - 0 0 0 0 0 0 0 0 0 0 0 0
40088 - 0 0 0 0 0 0 0 0 0 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 0 0 0 0 0 0
40093 - 0 0 0 0 0 0 0 0 0 0 0 0
40094 - 0 0 1 0 0 1 0 0 1 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 - 6 6 6 18 18 18 42 42 42 82 82 82
40101 - 26 26 26 2 2 6 2 2 6 2 2 6
40102 - 2 2 6 2 2 6 2 2 6 2 2 6
40103 - 2 2 6 2 2 6 2 2 6 14 14 14
40104 - 46 46 46 34 34 34 6 6 6 2 2 6
40105 - 42 42 42 78 78 78 42 42 42 18 18 18
40106 - 6 6 6 0 0 0 0 0 0 0 0 0
40107 - 0 0 0 0 0 0 0 0 0 0 0 0
40108 - 0 0 0 0 0 0 0 0 0 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 0 0 0 0 0 0
40113 - 0 0 0 0 0 0 0 0 0 0 0 0
40114 - 0 0 1 0 0 0 0 0 1 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 - 10 10 10 30 30 30 66 66 66 58 58 58
40121 - 2 2 6 2 2 6 2 2 6 2 2 6
40122 - 2 2 6 2 2 6 2 2 6 2 2 6
40123 - 2 2 6 2 2 6 2 2 6 26 26 26
40124 - 86 86 86 101 101 101 46 46 46 10 10 10
40125 - 2 2 6 58 58 58 70 70 70 34 34 34
40126 - 10 10 10 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 0 0 0 0 0 0
40128 - 0 0 0 0 0 0 0 0 0 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 0 0 0 0 0 0
40133 - 0 0 0 0 0 0 0 0 0 0 0 0
40134 - 0 0 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
40141 - 2 2 6 2 2 6 2 2 6 2 2 6
40142 - 2 2 6 2 2 6 2 2 6 2 2 6
40143 - 2 2 6 2 2 6 2 2 6 30 30 30
40144 - 94 94 94 94 94 94 58 58 58 26 26 26
40145 - 2 2 6 6 6 6 78 78 78 54 54 54
40146 - 22 22 22 6 6 6 0 0 0 0 0 0
40147 - 0 0 0 0 0 0 0 0 0 0 0 0
40148 - 0 0 0 0 0 0 0 0 0 0 0 0
40149 - 0 0 0 0 0 0 0 0 0 0 0 0
40150 - 0 0 0 0 0 0 0 0 0 0 0 0
40151 - 0 0 0 0 0 0 0 0 0 0 0 0
40152 - 0 0 0 0 0 0 0 0 0 0 0 0
40153 - 0 0 0 0 0 0 0 0 0 0 0 0
40154 - 0 0 0 0 0 0 0 0 0 0 0 0
40155 - 0 0 0 0 0 0 0 0 0 0 0 0
40156 - 0 0 0 0 0 0 0 0 0 0 0 0
40157 - 0 0 0 0 0 0 0 0 0 0 0 0
40158 - 0 0 0 0 0 0 0 0 0 0 0 0
40159 - 0 0 0 0 0 0 0 0 0 6 6 6
40160 - 22 22 22 62 62 62 62 62 62 2 2 6
40161 - 2 2 6 2 2 6 2 2 6 2 2 6
40162 - 2 2 6 2 2 6 2 2 6 2 2 6
40163 - 2 2 6 2 2 6 2 2 6 26 26 26
40164 - 54 54 54 38 38 38 18 18 18 10 10 10
40165 - 2 2 6 2 2 6 34 34 34 82 82 82
40166 - 38 38 38 14 14 14 0 0 0 0 0 0
40167 - 0 0 0 0 0 0 0 0 0 0 0 0
40168 - 0 0 0 0 0 0 0 0 0 0 0 0
40169 - 0 0 0 0 0 0 0 0 0 0 0 0
40170 - 0 0 0 0 0 0 0 0 0 0 0 0
40171 - 0 0 0 0 0 0 0 0 0 0 0 0
40172 - 0 0 0 0 0 0 0 0 0 0 0 0
40173 - 0 0 0 0 0 0 0 0 0 0 0 0
40174 - 0 0 0 0 0 1 0 0 1 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 6 6 6
40180 - 30 30 30 78 78 78 30 30 30 2 2 6
40181 - 2 2 6 2 2 6 2 2 6 2 2 6
40182 - 2 2 6 2 2 6 2 2 6 2 2 6
40183 - 2 2 6 2 2 6 2 2 6 10 10 10
40184 - 10 10 10 2 2 6 2 2 6 2 2 6
40185 - 2 2 6 2 2 6 2 2 6 78 78 78
40186 - 50 50 50 18 18 18 6 6 6 0 0 0
40187 - 0 0 0 0 0 0 0 0 0 0 0 0
40188 - 0 0 0 0 0 0 0 0 0 0 0 0
40189 - 0 0 0 0 0 0 0 0 0 0 0 0
40190 - 0 0 0 0 0 0 0 0 0 0 0 0
40191 - 0 0 0 0 0 0 0 0 0 0 0 0
40192 - 0 0 0 0 0 0 0 0 0 0 0 0
40193 - 0 0 0 0 0 0 0 0 0 0 0 0
40194 - 0 0 1 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 10 10 10
40200 - 38 38 38 86 86 86 14 14 14 2 2 6
40201 - 2 2 6 2 2 6 2 2 6 2 2 6
40202 - 2 2 6 2 2 6 2 2 6 2 2 6
40203 - 2 2 6 2 2 6 2 2 6 2 2 6
40204 - 2 2 6 2 2 6 2 2 6 2 2 6
40205 - 2 2 6 2 2 6 2 2 6 54 54 54
40206 - 66 66 66 26 26 26 6 6 6 0 0 0
40207 - 0 0 0 0 0 0 0 0 0 0 0 0
40208 - 0 0 0 0 0 0 0 0 0 0 0 0
40209 - 0 0 0 0 0 0 0 0 0 0 0 0
40210 - 0 0 0 0 0 0 0 0 0 0 0 0
40211 - 0 0 0 0 0 0 0 0 0 0 0 0
40212 - 0 0 0 0 0 0 0 0 0 0 0 0
40213 - 0 0 0 0 0 0 0 0 0 0 0 0
40214 - 0 0 0 0 0 1 0 0 1 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 14 14 14
40220 - 42 42 42 82 82 82 2 2 6 2 2 6
40221 - 2 2 6 6 6 6 10 10 10 2 2 6
40222 - 2 2 6 2 2 6 2 2 6 2 2 6
40223 - 2 2 6 2 2 6 2 2 6 6 6 6
40224 - 14 14 14 10 10 10 2 2 6 2 2 6
40225 - 2 2 6 2 2 6 2 2 6 18 18 18
40226 - 82 82 82 34 34 34 10 10 10 0 0 0
40227 - 0 0 0 0 0 0 0 0 0 0 0 0
40228 - 0 0 0 0 0 0 0 0 0 0 0 0
40229 - 0 0 0 0 0 0 0 0 0 0 0 0
40230 - 0 0 0 0 0 0 0 0 0 0 0 0
40231 - 0 0 0 0 0 0 0 0 0 0 0 0
40232 - 0 0 0 0 0 0 0 0 0 0 0 0
40233 - 0 0 0 0 0 0 0 0 0 0 0 0
40234 - 0 0 1 0 0 0 0 0 0 0 0 0
40235 - 0 0 0 0 0 0 0 0 0 0 0 0
40236 - 0 0 0 0 0 0 0 0 0 0 0 0
40237 - 0 0 0 0 0 0 0 0 0 0 0 0
40238 - 0 0 0 0 0 0 0 0 0 0 0 0
40239 - 0 0 0 0 0 0 0 0 0 14 14 14
40240 - 46 46 46 86 86 86 2 2 6 2 2 6
40241 - 6 6 6 6 6 6 22 22 22 34 34 34
40242 - 6 6 6 2 2 6 2 2 6 2 2 6
40243 - 2 2 6 2 2 6 18 18 18 34 34 34
40244 - 10 10 10 50 50 50 22 22 22 2 2 6
40245 - 2 2 6 2 2 6 2 2 6 10 10 10
40246 - 86 86 86 42 42 42 14 14 14 0 0 0
40247 - 0 0 0 0 0 0 0 0 0 0 0 0
40248 - 0 0 0 0 0 0 0 0 0 0 0 0
40249 - 0 0 0 0 0 0 0 0 0 0 0 0
40250 - 0 0 0 0 0 0 0 0 0 0 0 0
40251 - 0 0 0 0 0 0 0 0 0 0 0 0
40252 - 0 0 0 0 0 0 0 0 0 0 0 0
40253 - 0 0 0 0 0 0 0 0 0 0 0 0
40254 - 0 0 1 0 0 1 0 0 1 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 14 14 14
40260 - 46 46 46 86 86 86 2 2 6 2 2 6
40261 - 38 38 38 116 116 116 94 94 94 22 22 22
40262 - 22 22 22 2 2 6 2 2 6 2 2 6
40263 - 14 14 14 86 86 86 138 138 138 162 162 162
40264 -154 154 154 38 38 38 26 26 26 6 6 6
40265 - 2 2 6 2 2 6 2 2 6 2 2 6
40266 - 86 86 86 46 46 46 14 14 14 0 0 0
40267 - 0 0 0 0 0 0 0 0 0 0 0 0
40268 - 0 0 0 0 0 0 0 0 0 0 0 0
40269 - 0 0 0 0 0 0 0 0 0 0 0 0
40270 - 0 0 0 0 0 0 0 0 0 0 0 0
40271 - 0 0 0 0 0 0 0 0 0 0 0 0
40272 - 0 0 0 0 0 0 0 0 0 0 0 0
40273 - 0 0 0 0 0 0 0 0 0 0 0 0
40274 - 0 0 0 0 0 0 0 0 0 0 0 0
40275 - 0 0 0 0 0 0 0 0 0 0 0 0
40276 - 0 0 0 0 0 0 0 0 0 0 0 0
40277 - 0 0 0 0 0 0 0 0 0 0 0 0
40278 - 0 0 0 0 0 0 0 0 0 0 0 0
40279 - 0 0 0 0 0 0 0 0 0 14 14 14
40280 - 46 46 46 86 86 86 2 2 6 14 14 14
40281 -134 134 134 198 198 198 195 195 195 116 116 116
40282 - 10 10 10 2 2 6 2 2 6 6 6 6
40283 -101 98 89 187 187 187 210 210 210 218 218 218
40284 -214 214 214 134 134 134 14 14 14 6 6 6
40285 - 2 2 6 2 2 6 2 2 6 2 2 6
40286 - 86 86 86 50 50 50 18 18 18 6 6 6
40287 - 0 0 0 0 0 0 0 0 0 0 0 0
40288 - 0 0 0 0 0 0 0 0 0 0 0 0
40289 - 0 0 0 0 0 0 0 0 0 0 0 0
40290 - 0 0 0 0 0 0 0 0 0 0 0 0
40291 - 0 0 0 0 0 0 0 0 0 0 0 0
40292 - 0 0 0 0 0 0 0 0 0 0 0 0
40293 - 0 0 0 0 0 0 0 0 1 0 0 0
40294 - 0 0 1 0 0 1 0 0 1 0 0 0
40295 - 0 0 0 0 0 0 0 0 0 0 0 0
40296 - 0 0 0 0 0 0 0 0 0 0 0 0
40297 - 0 0 0 0 0 0 0 0 0 0 0 0
40298 - 0 0 0 0 0 0 0 0 0 0 0 0
40299 - 0 0 0 0 0 0 0 0 0 14 14 14
40300 - 46 46 46 86 86 86 2 2 6 54 54 54
40301 -218 218 218 195 195 195 226 226 226 246 246 246
40302 - 58 58 58 2 2 6 2 2 6 30 30 30
40303 -210 210 210 253 253 253 174 174 174 123 123 123
40304 -221 221 221 234 234 234 74 74 74 2 2 6
40305 - 2 2 6 2 2 6 2 2 6 2 2 6
40306 - 70 70 70 58 58 58 22 22 22 6 6 6
40307 - 0 0 0 0 0 0 0 0 0 0 0 0
40308 - 0 0 0 0 0 0 0 0 0 0 0 0
40309 - 0 0 0 0 0 0 0 0 0 0 0 0
40310 - 0 0 0 0 0 0 0 0 0 0 0 0
40311 - 0 0 0 0 0 0 0 0 0 0 0 0
40312 - 0 0 0 0 0 0 0 0 0 0 0 0
40313 - 0 0 0 0 0 0 0 0 0 0 0 0
40314 - 0 0 0 0 0 0 0 0 0 0 0 0
40315 - 0 0 0 0 0 0 0 0 0 0 0 0
40316 - 0 0 0 0 0 0 0 0 0 0 0 0
40317 - 0 0 0 0 0 0 0 0 0 0 0 0
40318 - 0 0 0 0 0 0 0 0 0 0 0 0
40319 - 0 0 0 0 0 0 0 0 0 14 14 14
40320 - 46 46 46 82 82 82 2 2 6 106 106 106
40321 -170 170 170 26 26 26 86 86 86 226 226 226
40322 -123 123 123 10 10 10 14 14 14 46 46 46
40323 -231 231 231 190 190 190 6 6 6 70 70 70
40324 - 90 90 90 238 238 238 158 158 158 2 2 6
40325 - 2 2 6 2 2 6 2 2 6 2 2 6
40326 - 70 70 70 58 58 58 22 22 22 6 6 6
40327 - 0 0 0 0 0 0 0 0 0 0 0 0
40328 - 0 0 0 0 0 0 0 0 0 0 0 0
40329 - 0 0 0 0 0 0 0 0 0 0 0 0
40330 - 0 0 0 0 0 0 0 0 0 0 0 0
40331 - 0 0 0 0 0 0 0 0 0 0 0 0
40332 - 0 0 0 0 0 0 0 0 0 0 0 0
40333 - 0 0 0 0 0 0 0 0 1 0 0 0
40334 - 0 0 1 0 0 1 0 0 1 0 0 0
40335 - 0 0 0 0 0 0 0 0 0 0 0 0
40336 - 0 0 0 0 0 0 0 0 0 0 0 0
40337 - 0 0 0 0 0 0 0 0 0 0 0 0
40338 - 0 0 0 0 0 0 0 0 0 0 0 0
40339 - 0 0 0 0 0 0 0 0 0 14 14 14
40340 - 42 42 42 86 86 86 6 6 6 116 116 116
40341 -106 106 106 6 6 6 70 70 70 149 149 149
40342 -128 128 128 18 18 18 38 38 38 54 54 54
40343 -221 221 221 106 106 106 2 2 6 14 14 14
40344 - 46 46 46 190 190 190 198 198 198 2 2 6
40345 - 2 2 6 2 2 6 2 2 6 2 2 6
40346 - 74 74 74 62 62 62 22 22 22 6 6 6
40347 - 0 0 0 0 0 0 0 0 0 0 0 0
40348 - 0 0 0 0 0 0 0 0 0 0 0 0
40349 - 0 0 0 0 0 0 0 0 0 0 0 0
40350 - 0 0 0 0 0 0 0 0 0 0 0 0
40351 - 0 0 0 0 0 0 0 0 0 0 0 0
40352 - 0 0 0 0 0 0 0 0 0 0 0 0
40353 - 0 0 0 0 0 0 0 0 1 0 0 0
40354 - 0 0 1 0 0 0 0 0 1 0 0 0
40355 - 0 0 0 0 0 0 0 0 0 0 0 0
40356 - 0 0 0 0 0 0 0 0 0 0 0 0
40357 - 0 0 0 0 0 0 0 0 0 0 0 0
40358 - 0 0 0 0 0 0 0 0 0 0 0 0
40359 - 0 0 0 0 0 0 0 0 0 14 14 14
40360 - 42 42 42 94 94 94 14 14 14 101 101 101
40361 -128 128 128 2 2 6 18 18 18 116 116 116
40362 -118 98 46 121 92 8 121 92 8 98 78 10
40363 -162 162 162 106 106 106 2 2 6 2 2 6
40364 - 2 2 6 195 195 195 195 195 195 6 6 6
40365 - 2 2 6 2 2 6 2 2 6 2 2 6
40366 - 74 74 74 62 62 62 22 22 22 6 6 6
40367 - 0 0 0 0 0 0 0 0 0 0 0 0
40368 - 0 0 0 0 0 0 0 0 0 0 0 0
40369 - 0 0 0 0 0 0 0 0 0 0 0 0
40370 - 0 0 0 0 0 0 0 0 0 0 0 0
40371 - 0 0 0 0 0 0 0 0 0 0 0 0
40372 - 0 0 0 0 0 0 0 0 0 0 0 0
40373 - 0 0 0 0 0 0 0 0 1 0 0 1
40374 - 0 0 1 0 0 0 0 0 1 0 0 0
40375 - 0 0 0 0 0 0 0 0 0 0 0 0
40376 - 0 0 0 0 0 0 0 0 0 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 10 10 10
40380 - 38 38 38 90 90 90 14 14 14 58 58 58
40381 -210 210 210 26 26 26 54 38 6 154 114 10
40382 -226 170 11 236 186 11 225 175 15 184 144 12
40383 -215 174 15 175 146 61 37 26 9 2 2 6
40384 - 70 70 70 246 246 246 138 138 138 2 2 6
40385 - 2 2 6 2 2 6 2 2 6 2 2 6
40386 - 70 70 70 66 66 66 26 26 26 6 6 6
40387 - 0 0 0 0 0 0 0 0 0 0 0 0
40388 - 0 0 0 0 0 0 0 0 0 0 0 0
40389 - 0 0 0 0 0 0 0 0 0 0 0 0
40390 - 0 0 0 0 0 0 0 0 0 0 0 0
40391 - 0 0 0 0 0 0 0 0 0 0 0 0
40392 - 0 0 0 0 0 0 0 0 0 0 0 0
40393 - 0 0 0 0 0 0 0 0 0 0 0 0
40394 - 0 0 0 0 0 0 0 0 0 0 0 0
40395 - 0 0 0 0 0 0 0 0 0 0 0 0
40396 - 0 0 0 0 0 0 0 0 0 0 0 0
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 10 10 10
40400 - 38 38 38 86 86 86 14 14 14 10 10 10
40401 -195 195 195 188 164 115 192 133 9 225 175 15
40402 -239 182 13 234 190 10 232 195 16 232 200 30
40403 -245 207 45 241 208 19 232 195 16 184 144 12
40404 -218 194 134 211 206 186 42 42 42 2 2 6
40405 - 2 2 6 2 2 6 2 2 6 2 2 6
40406 - 50 50 50 74 74 74 30 30 30 6 6 6
40407 - 0 0 0 0 0 0 0 0 0 0 0 0
40408 - 0 0 0 0 0 0 0 0 0 0 0 0
40409 - 0 0 0 0 0 0 0 0 0 0 0 0
40410 - 0 0 0 0 0 0 0 0 0 0 0 0
40411 - 0 0 0 0 0 0 0 0 0 0 0 0
40412 - 0 0 0 0 0 0 0 0 0 0 0 0
40413 - 0 0 0 0 0 0 0 0 0 0 0 0
40414 - 0 0 0 0 0 0 0 0 0 0 0 0
40415 - 0 0 0 0 0 0 0 0 0 0 0 0
40416 - 0 0 0 0 0 0 0 0 0 0 0 0
40417 - 0 0 0 0 0 0 0 0 0 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 10 10 10
40420 - 34 34 34 86 86 86 14 14 14 2 2 6
40421 -121 87 25 192 133 9 219 162 10 239 182 13
40422 -236 186 11 232 195 16 241 208 19 244 214 54
40423 -246 218 60 246 218 38 246 215 20 241 208 19
40424 -241 208 19 226 184 13 121 87 25 2 2 6
40425 - 2 2 6 2 2 6 2 2 6 2 2 6
40426 - 50 50 50 82 82 82 34 34 34 10 10 10
40427 - 0 0 0 0 0 0 0 0 0 0 0 0
40428 - 0 0 0 0 0 0 0 0 0 0 0 0
40429 - 0 0 0 0 0 0 0 0 0 0 0 0
40430 - 0 0 0 0 0 0 0 0 0 0 0 0
40431 - 0 0 0 0 0 0 0 0 0 0 0 0
40432 - 0 0 0 0 0 0 0 0 0 0 0 0
40433 - 0 0 0 0 0 0 0 0 0 0 0 0
40434 - 0 0 0 0 0 0 0 0 0 0 0 0
40435 - 0 0 0 0 0 0 0 0 0 0 0 0
40436 - 0 0 0 0 0 0 0 0 0 0 0 0
40437 - 0 0 0 0 0 0 0 0 0 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 10 10 10
40440 - 34 34 34 82 82 82 30 30 30 61 42 6
40441 -180 123 7 206 145 10 230 174 11 239 182 13
40442 -234 190 10 238 202 15 241 208 19 246 218 74
40443 -246 218 38 246 215 20 246 215 20 246 215 20
40444 -226 184 13 215 174 15 184 144 12 6 6 6
40445 - 2 2 6 2 2 6 2 2 6 2 2 6
40446 - 26 26 26 94 94 94 42 42 42 14 14 14
40447 - 0 0 0 0 0 0 0 0 0 0 0 0
40448 - 0 0 0 0 0 0 0 0 0 0 0 0
40449 - 0 0 0 0 0 0 0 0 0 0 0 0
40450 - 0 0 0 0 0 0 0 0 0 0 0 0
40451 - 0 0 0 0 0 0 0 0 0 0 0 0
40452 - 0 0 0 0 0 0 0 0 0 0 0 0
40453 - 0 0 0 0 0 0 0 0 0 0 0 0
40454 - 0 0 0 0 0 0 0 0 0 0 0 0
40455 - 0 0 0 0 0 0 0 0 0 0 0 0
40456 - 0 0 0 0 0 0 0 0 0 0 0 0
40457 - 0 0 0 0 0 0 0 0 0 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 10 10 10
40460 - 30 30 30 78 78 78 50 50 50 104 69 6
40461 -192 133 9 216 158 10 236 178 12 236 186 11
40462 -232 195 16 241 208 19 244 214 54 245 215 43
40463 -246 215 20 246 215 20 241 208 19 198 155 10
40464 -200 144 11 216 158 10 156 118 10 2 2 6
40465 - 2 2 6 2 2 6 2 2 6 2 2 6
40466 - 6 6 6 90 90 90 54 54 54 18 18 18
40467 - 6 6 6 0 0 0 0 0 0 0 0 0
40468 - 0 0 0 0 0 0 0 0 0 0 0 0
40469 - 0 0 0 0 0 0 0 0 0 0 0 0
40470 - 0 0 0 0 0 0 0 0 0 0 0 0
40471 - 0 0 0 0 0 0 0 0 0 0 0 0
40472 - 0 0 0 0 0 0 0 0 0 0 0 0
40473 - 0 0 0 0 0 0 0 0 0 0 0 0
40474 - 0 0 0 0 0 0 0 0 0 0 0 0
40475 - 0 0 0 0 0 0 0 0 0 0 0 0
40476 - 0 0 0 0 0 0 0 0 0 0 0 0
40477 - 0 0 0 0 0 0 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 10 10 10
40480 - 30 30 30 78 78 78 46 46 46 22 22 22
40481 -137 92 6 210 162 10 239 182 13 238 190 10
40482 -238 202 15 241 208 19 246 215 20 246 215 20
40483 -241 208 19 203 166 17 185 133 11 210 150 10
40484 -216 158 10 210 150 10 102 78 10 2 2 6
40485 - 6 6 6 54 54 54 14 14 14 2 2 6
40486 - 2 2 6 62 62 62 74 74 74 30 30 30
40487 - 10 10 10 0 0 0 0 0 0 0 0 0
40488 - 0 0 0 0 0 0 0 0 0 0 0 0
40489 - 0 0 0 0 0 0 0 0 0 0 0 0
40490 - 0 0 0 0 0 0 0 0 0 0 0 0
40491 - 0 0 0 0 0 0 0 0 0 0 0 0
40492 - 0 0 0 0 0 0 0 0 0 0 0 0
40493 - 0 0 0 0 0 0 0 0 0 0 0 0
40494 - 0 0 0 0 0 0 0 0 0 0 0 0
40495 - 0 0 0 0 0 0 0 0 0 0 0 0
40496 - 0 0 0 0 0 0 0 0 0 0 0 0
40497 - 0 0 0 0 0 0 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 10 10 10
40500 - 34 34 34 78 78 78 50 50 50 6 6 6
40501 - 94 70 30 139 102 15 190 146 13 226 184 13
40502 -232 200 30 232 195 16 215 174 15 190 146 13
40503 -168 122 10 192 133 9 210 150 10 213 154 11
40504 -202 150 34 182 157 106 101 98 89 2 2 6
40505 - 2 2 6 78 78 78 116 116 116 58 58 58
40506 - 2 2 6 22 22 22 90 90 90 46 46 46
40507 - 18 18 18 6 6 6 0 0 0 0 0 0
40508 - 0 0 0 0 0 0 0 0 0 0 0 0
40509 - 0 0 0 0 0 0 0 0 0 0 0 0
40510 - 0 0 0 0 0 0 0 0 0 0 0 0
40511 - 0 0 0 0 0 0 0 0 0 0 0 0
40512 - 0 0 0 0 0 0 0 0 0 0 0 0
40513 - 0 0 0 0 0 0 0 0 0 0 0 0
40514 - 0 0 0 0 0 0 0 0 0 0 0 0
40515 - 0 0 0 0 0 0 0 0 0 0 0 0
40516 - 0 0 0 0 0 0 0 0 0 0 0 0
40517 - 0 0 0 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 10 10 10
40520 - 38 38 38 86 86 86 50 50 50 6 6 6
40521 -128 128 128 174 154 114 156 107 11 168 122 10
40522 -198 155 10 184 144 12 197 138 11 200 144 11
40523 -206 145 10 206 145 10 197 138 11 188 164 115
40524 -195 195 195 198 198 198 174 174 174 14 14 14
40525 - 2 2 6 22 22 22 116 116 116 116 116 116
40526 - 22 22 22 2 2 6 74 74 74 70 70 70
40527 - 30 30 30 10 10 10 0 0 0 0 0 0
40528 - 0 0 0 0 0 0 0 0 0 0 0 0
40529 - 0 0 0 0 0 0 0 0 0 0 0 0
40530 - 0 0 0 0 0 0 0 0 0 0 0 0
40531 - 0 0 0 0 0 0 0 0 0 0 0 0
40532 - 0 0 0 0 0 0 0 0 0 0 0 0
40533 - 0 0 0 0 0 0 0 0 0 0 0 0
40534 - 0 0 0 0 0 0 0 0 0 0 0 0
40535 - 0 0 0 0 0 0 0 0 0 0 0 0
40536 - 0 0 0 0 0 0 0 0 0 0 0 0
40537 - 0 0 0 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 6 6 6 18 18 18
40540 - 50 50 50 101 101 101 26 26 26 10 10 10
40541 -138 138 138 190 190 190 174 154 114 156 107 11
40542 -197 138 11 200 144 11 197 138 11 192 133 9
40543 -180 123 7 190 142 34 190 178 144 187 187 187
40544 -202 202 202 221 221 221 214 214 214 66 66 66
40545 - 2 2 6 2 2 6 50 50 50 62 62 62
40546 - 6 6 6 2 2 6 10 10 10 90 90 90
40547 - 50 50 50 18 18 18 6 6 6 0 0 0
40548 - 0 0 0 0 0 0 0 0 0 0 0 0
40549 - 0 0 0 0 0 0 0 0 0 0 0 0
40550 - 0 0 0 0 0 0 0 0 0 0 0 0
40551 - 0 0 0 0 0 0 0 0 0 0 0 0
40552 - 0 0 0 0 0 0 0 0 0 0 0 0
40553 - 0 0 0 0 0 0 0 0 0 0 0 0
40554 - 0 0 0 0 0 0 0 0 0 0 0 0
40555 - 0 0 0 0 0 0 0 0 0 0 0 0
40556 - 0 0 0 0 0 0 0 0 0 0 0 0
40557 - 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 10 10 10 34 34 34
40560 - 74 74 74 74 74 74 2 2 6 6 6 6
40561 -144 144 144 198 198 198 190 190 190 178 166 146
40562 -154 121 60 156 107 11 156 107 11 168 124 44
40563 -174 154 114 187 187 187 190 190 190 210 210 210
40564 -246 246 246 253 253 253 253 253 253 182 182 182
40565 - 6 6 6 2 2 6 2 2 6 2 2 6
40566 - 2 2 6 2 2 6 2 2 6 62 62 62
40567 - 74 74 74 34 34 34 14 14 14 0 0 0
40568 - 0 0 0 0 0 0 0 0 0 0 0 0
40569 - 0 0 0 0 0 0 0 0 0 0 0 0
40570 - 0 0 0 0 0 0 0 0 0 0 0 0
40571 - 0 0 0 0 0 0 0 0 0 0 0 0
40572 - 0 0 0 0 0 0 0 0 0 0 0 0
40573 - 0 0 0 0 0 0 0 0 0 0 0 0
40574 - 0 0 0 0 0 0 0 0 0 0 0 0
40575 - 0 0 0 0 0 0 0 0 0 0 0 0
40576 - 0 0 0 0 0 0 0 0 0 0 0 0
40577 - 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 10 10 10 22 22 22 54 54 54
40580 - 94 94 94 18 18 18 2 2 6 46 46 46
40581 -234 234 234 221 221 221 190 190 190 190 190 190
40582 -190 190 190 187 187 187 187 187 187 190 190 190
40583 -190 190 190 195 195 195 214 214 214 242 242 242
40584 -253 253 253 253 253 253 253 253 253 253 253 253
40585 - 82 82 82 2 2 6 2 2 6 2 2 6
40586 - 2 2 6 2 2 6 2 2 6 14 14 14
40587 - 86 86 86 54 54 54 22 22 22 6 6 6
40588 - 0 0 0 0 0 0 0 0 0 0 0 0
40589 - 0 0 0 0 0 0 0 0 0 0 0 0
40590 - 0 0 0 0 0 0 0 0 0 0 0 0
40591 - 0 0 0 0 0 0 0 0 0 0 0 0
40592 - 0 0 0 0 0 0 0 0 0 0 0 0
40593 - 0 0 0 0 0 0 0 0 0 0 0 0
40594 - 0 0 0 0 0 0 0 0 0 0 0 0
40595 - 0 0 0 0 0 0 0 0 0 0 0 0
40596 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
40600 - 46 46 46 18 18 18 6 6 6 182 182 182
40601 -253 253 253 246 246 246 206 206 206 190 190 190
40602 -190 190 190 190 190 190 190 190 190 190 190 190
40603 -206 206 206 231 231 231 250 250 250 253 253 253
40604 -253 253 253 253 253 253 253 253 253 253 253 253
40605 -202 202 202 14 14 14 2 2 6 2 2 6
40606 - 2 2 6 2 2 6 2 2 6 2 2 6
40607 - 42 42 42 86 86 86 42 42 42 18 18 18
40608 - 6 6 6 0 0 0 0 0 0 0 0 0
40609 - 0 0 0 0 0 0 0 0 0 0 0 0
40610 - 0 0 0 0 0 0 0 0 0 0 0 0
40611 - 0 0 0 0 0 0 0 0 0 0 0 0
40612 - 0 0 0 0 0 0 0 0 0 0 0 0
40613 - 0 0 0 0 0 0 0 0 0 0 0 0
40614 - 0 0 0 0 0 0 0 0 0 0 0 0
40615 - 0 0 0 0 0 0 0 0 0 0 0 0
40616 - 0 0 0 0 0 0 0 0 0 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 6 6 6
40619 - 14 14 14 38 38 38 74 74 74 66 66 66
40620 - 2 2 6 6 6 6 90 90 90 250 250 250
40621 -253 253 253 253 253 253 238 238 238 198 198 198
40622 -190 190 190 190 190 190 195 195 195 221 221 221
40623 -246 246 246 253 253 253 253 253 253 253 253 253
40624 -253 253 253 253 253 253 253 253 253 253 253 253
40625 -253 253 253 82 82 82 2 2 6 2 2 6
40626 - 2 2 6 2 2 6 2 2 6 2 2 6
40627 - 2 2 6 78 78 78 70 70 70 34 34 34
40628 - 14 14 14 6 6 6 0 0 0 0 0 0
40629 - 0 0 0 0 0 0 0 0 0 0 0 0
40630 - 0 0 0 0 0 0 0 0 0 0 0 0
40631 - 0 0 0 0 0 0 0 0 0 0 0 0
40632 - 0 0 0 0 0 0 0 0 0 0 0 0
40633 - 0 0 0 0 0 0 0 0 0 0 0 0
40634 - 0 0 0 0 0 0 0 0 0 0 0 0
40635 - 0 0 0 0 0 0 0 0 0 0 0 0
40636 - 0 0 0 0 0 0 0 0 0 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 14 14 14
40639 - 34 34 34 66 66 66 78 78 78 6 6 6
40640 - 2 2 6 18 18 18 218 218 218 253 253 253
40641 -253 253 253 253 253 253 253 253 253 246 246 246
40642 -226 226 226 231 231 231 246 246 246 253 253 253
40643 -253 253 253 253 253 253 253 253 253 253 253 253
40644 -253 253 253 253 253 253 253 253 253 253 253 253
40645 -253 253 253 178 178 178 2 2 6 2 2 6
40646 - 2 2 6 2 2 6 2 2 6 2 2 6
40647 - 2 2 6 18 18 18 90 90 90 62 62 62
40648 - 30 30 30 10 10 10 0 0 0 0 0 0
40649 - 0 0 0 0 0 0 0 0 0 0 0 0
40650 - 0 0 0 0 0 0 0 0 0 0 0 0
40651 - 0 0 0 0 0 0 0 0 0 0 0 0
40652 - 0 0 0 0 0 0 0 0 0 0 0 0
40653 - 0 0 0 0 0 0 0 0 0 0 0 0
40654 - 0 0 0 0 0 0 0 0 0 0 0 0
40655 - 0 0 0 0 0 0 0 0 0 0 0 0
40656 - 0 0 0 0 0 0 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 10 10 10 26 26 26
40659 - 58 58 58 90 90 90 18 18 18 2 2 6
40660 - 2 2 6 110 110 110 253 253 253 253 253 253
40661 -253 253 253 253 253 253 253 253 253 253 253 253
40662 -250 250 250 253 253 253 253 253 253 253 253 253
40663 -253 253 253 253 253 253 253 253 253 253 253 253
40664 -253 253 253 253 253 253 253 253 253 253 253 253
40665 -253 253 253 231 231 231 18 18 18 2 2 6
40666 - 2 2 6 2 2 6 2 2 6 2 2 6
40667 - 2 2 6 2 2 6 18 18 18 94 94 94
40668 - 54 54 54 26 26 26 10 10 10 0 0 0
40669 - 0 0 0 0 0 0 0 0 0 0 0 0
40670 - 0 0 0 0 0 0 0 0 0 0 0 0
40671 - 0 0 0 0 0 0 0 0 0 0 0 0
40672 - 0 0 0 0 0 0 0 0 0 0 0 0
40673 - 0 0 0 0 0 0 0 0 0 0 0 0
40674 - 0 0 0 0 0 0 0 0 0 0 0 0
40675 - 0 0 0 0 0 0 0 0 0 0 0 0
40676 - 0 0 0 0 0 0 0 0 0 0 0 0
40677 - 0 0 0 0 0 0 0 0 0 0 0 0
40678 - 0 0 0 6 6 6 22 22 22 50 50 50
40679 - 90 90 90 26 26 26 2 2 6 2 2 6
40680 - 14 14 14 195 195 195 250 250 250 253 253 253
40681 -253 253 253 253 253 253 253 253 253 253 253 253
40682 -253 253 253 253 253 253 253 253 253 253 253 253
40683 -253 253 253 253 253 253 253 253 253 253 253 253
40684 -253 253 253 253 253 253 253 253 253 253 253 253
40685 -250 250 250 242 242 242 54 54 54 2 2 6
40686 - 2 2 6 2 2 6 2 2 6 2 2 6
40687 - 2 2 6 2 2 6 2 2 6 38 38 38
40688 - 86 86 86 50 50 50 22 22 22 6 6 6
40689 - 0 0 0 0 0 0 0 0 0 0 0 0
40690 - 0 0 0 0 0 0 0 0 0 0 0 0
40691 - 0 0 0 0 0 0 0 0 0 0 0 0
40692 - 0 0 0 0 0 0 0 0 0 0 0 0
40693 - 0 0 0 0 0 0 0 0 0 0 0 0
40694 - 0 0 0 0 0 0 0 0 0 0 0 0
40695 - 0 0 0 0 0 0 0 0 0 0 0 0
40696 - 0 0 0 0 0 0 0 0 0 0 0 0
40697 - 0 0 0 0 0 0 0 0 0 0 0 0
40698 - 6 6 6 14 14 14 38 38 38 82 82 82
40699 - 34 34 34 2 2 6 2 2 6 2 2 6
40700 - 42 42 42 195 195 195 246 246 246 253 253 253
40701 -253 253 253 253 253 253 253 253 253 250 250 250
40702 -242 242 242 242 242 242 250 250 250 253 253 253
40703 -253 253 253 253 253 253 253 253 253 253 253 253
40704 -253 253 253 250 250 250 246 246 246 238 238 238
40705 -226 226 226 231 231 231 101 101 101 6 6 6
40706 - 2 2 6 2 2 6 2 2 6 2 2 6
40707 - 2 2 6 2 2 6 2 2 6 2 2 6
40708 - 38 38 38 82 82 82 42 42 42 14 14 14
40709 - 6 6 6 0 0 0 0 0 0 0 0 0
40710 - 0 0 0 0 0 0 0 0 0 0 0 0
40711 - 0 0 0 0 0 0 0 0 0 0 0 0
40712 - 0 0 0 0 0 0 0 0 0 0 0 0
40713 - 0 0 0 0 0 0 0 0 0 0 0 0
40714 - 0 0 0 0 0 0 0 0 0 0 0 0
40715 - 0 0 0 0 0 0 0 0 0 0 0 0
40716 - 0 0 0 0 0 0 0 0 0 0 0 0
40717 - 0 0 0 0 0 0 0 0 0 0 0 0
40718 - 10 10 10 26 26 26 62 62 62 66 66 66
40719 - 2 2 6 2 2 6 2 2 6 6 6 6
40720 - 70 70 70 170 170 170 206 206 206 234 234 234
40721 -246 246 246 250 250 250 250 250 250 238 238 238
40722 -226 226 226 231 231 231 238 238 238 250 250 250
40723 -250 250 250 250 250 250 246 246 246 231 231 231
40724 -214 214 214 206 206 206 202 202 202 202 202 202
40725 -198 198 198 202 202 202 182 182 182 18 18 18
40726 - 2 2 6 2 2 6 2 2 6 2 2 6
40727 - 2 2 6 2 2 6 2 2 6 2 2 6
40728 - 2 2 6 62 62 62 66 66 66 30 30 30
40729 - 10 10 10 0 0 0 0 0 0 0 0 0
40730 - 0 0 0 0 0 0 0 0 0 0 0 0
40731 - 0 0 0 0 0 0 0 0 0 0 0 0
40732 - 0 0 0 0 0 0 0 0 0 0 0 0
40733 - 0 0 0 0 0 0 0 0 0 0 0 0
40734 - 0 0 0 0 0 0 0 0 0 0 0 0
40735 - 0 0 0 0 0 0 0 0 0 0 0 0
40736 - 0 0 0 0 0 0 0 0 0 0 0 0
40737 - 0 0 0 0 0 0 0 0 0 0 0 0
40738 - 14 14 14 42 42 42 82 82 82 18 18 18
40739 - 2 2 6 2 2 6 2 2 6 10 10 10
40740 - 94 94 94 182 182 182 218 218 218 242 242 242
40741 -250 250 250 253 253 253 253 253 253 250 250 250
40742 -234 234 234 253 253 253 253 253 253 253 253 253
40743 -253 253 253 253 253 253 253 253 253 246 246 246
40744 -238 238 238 226 226 226 210 210 210 202 202 202
40745 -195 195 195 195 195 195 210 210 210 158 158 158
40746 - 6 6 6 14 14 14 50 50 50 14 14 14
40747 - 2 2 6 2 2 6 2 2 6 2 2 6
40748 - 2 2 6 6 6 6 86 86 86 46 46 46
40749 - 18 18 18 6 6 6 0 0 0 0 0 0
40750 - 0 0 0 0 0 0 0 0 0 0 0 0
40751 - 0 0 0 0 0 0 0 0 0 0 0 0
40752 - 0 0 0 0 0 0 0 0 0 0 0 0
40753 - 0 0 0 0 0 0 0 0 0 0 0 0
40754 - 0 0 0 0 0 0 0 0 0 0 0 0
40755 - 0 0 0 0 0 0 0 0 0 0 0 0
40756 - 0 0 0 0 0 0 0 0 0 0 0 0
40757 - 0 0 0 0 0 0 0 0 0 6 6 6
40758 - 22 22 22 54 54 54 70 70 70 2 2 6
40759 - 2 2 6 10 10 10 2 2 6 22 22 22
40760 -166 166 166 231 231 231 250 250 250 253 253 253
40761 -253 253 253 253 253 253 253 253 253 250 250 250
40762 -242 242 242 253 253 253 253 253 253 253 253 253
40763 -253 253 253 253 253 253 253 253 253 253 253 253
40764 -253 253 253 253 253 253 253 253 253 246 246 246
40765 -231 231 231 206 206 206 198 198 198 226 226 226
40766 - 94 94 94 2 2 6 6 6 6 38 38 38
40767 - 30 30 30 2 2 6 2 2 6 2 2 6
40768 - 2 2 6 2 2 6 62 62 62 66 66 66
40769 - 26 26 26 10 10 10 0 0 0 0 0 0
40770 - 0 0 0 0 0 0 0 0 0 0 0 0
40771 - 0 0 0 0 0 0 0 0 0 0 0 0
40772 - 0 0 0 0 0 0 0 0 0 0 0 0
40773 - 0 0 0 0 0 0 0 0 0 0 0 0
40774 - 0 0 0 0 0 0 0 0 0 0 0 0
40775 - 0 0 0 0 0 0 0 0 0 0 0 0
40776 - 0 0 0 0 0 0 0 0 0 0 0 0
40777 - 0 0 0 0 0 0 0 0 0 10 10 10
40778 - 30 30 30 74 74 74 50 50 50 2 2 6
40779 - 26 26 26 26 26 26 2 2 6 106 106 106
40780 -238 238 238 253 253 253 253 253 253 253 253 253
40781 -253 253 253 253 253 253 253 253 253 253 253 253
40782 -253 253 253 253 253 253 253 253 253 253 253 253
40783 -253 253 253 253 253 253 253 253 253 253 253 253
40784 -253 253 253 253 253 253 253 253 253 253 253 253
40785 -253 253 253 246 246 246 218 218 218 202 202 202
40786 -210 210 210 14 14 14 2 2 6 2 2 6
40787 - 30 30 30 22 22 22 2 2 6 2 2 6
40788 - 2 2 6 2 2 6 18 18 18 86 86 86
40789 - 42 42 42 14 14 14 0 0 0 0 0 0
40790 - 0 0 0 0 0 0 0 0 0 0 0 0
40791 - 0 0 0 0 0 0 0 0 0 0 0 0
40792 - 0 0 0 0 0 0 0 0 0 0 0 0
40793 - 0 0 0 0 0 0 0 0 0 0 0 0
40794 - 0 0 0 0 0 0 0 0 0 0 0 0
40795 - 0 0 0 0 0 0 0 0 0 0 0 0
40796 - 0 0 0 0 0 0 0 0 0 0 0 0
40797 - 0 0 0 0 0 0 0 0 0 14 14 14
40798 - 42 42 42 90 90 90 22 22 22 2 2 6
40799 - 42 42 42 2 2 6 18 18 18 218 218 218
40800 -253 253 253 253 253 253 253 253 253 253 253 253
40801 -253 253 253 253 253 253 253 253 253 253 253 253
40802 -253 253 253 253 253 253 253 253 253 253 253 253
40803 -253 253 253 253 253 253 253 253 253 253 253 253
40804 -253 253 253 253 253 253 253 253 253 253 253 253
40805 -253 253 253 253 253 253 250 250 250 221 221 221
40806 -218 218 218 101 101 101 2 2 6 14 14 14
40807 - 18 18 18 38 38 38 10 10 10 2 2 6
40808 - 2 2 6 2 2 6 2 2 6 78 78 78
40809 - 58 58 58 22 22 22 6 6 6 0 0 0
40810 - 0 0 0 0 0 0 0 0 0 0 0 0
40811 - 0 0 0 0 0 0 0 0 0 0 0 0
40812 - 0 0 0 0 0 0 0 0 0 0 0 0
40813 - 0 0 0 0 0 0 0 0 0 0 0 0
40814 - 0 0 0 0 0 0 0 0 0 0 0 0
40815 - 0 0 0 0 0 0 0 0 0 0 0 0
40816 - 0 0 0 0 0 0 0 0 0 0 0 0
40817 - 0 0 0 0 0 0 6 6 6 18 18 18
40818 - 54 54 54 82 82 82 2 2 6 26 26 26
40819 - 22 22 22 2 2 6 123 123 123 253 253 253
40820 -253 253 253 253 253 253 253 253 253 253 253 253
40821 -253 253 253 253 253 253 253 253 253 253 253 253
40822 -253 253 253 253 253 253 253 253 253 253 253 253
40823 -253 253 253 253 253 253 253 253 253 253 253 253
40824 -253 253 253 253 253 253 253 253 253 253 253 253
40825 -253 253 253 253 253 253 253 253 253 250 250 250
40826 -238 238 238 198 198 198 6 6 6 38 38 38
40827 - 58 58 58 26 26 26 38 38 38 2 2 6
40828 - 2 2 6 2 2 6 2 2 6 46 46 46
40829 - 78 78 78 30 30 30 10 10 10 0 0 0
40830 - 0 0 0 0 0 0 0 0 0 0 0 0
40831 - 0 0 0 0 0 0 0 0 0 0 0 0
40832 - 0 0 0 0 0 0 0 0 0 0 0 0
40833 - 0 0 0 0 0 0 0 0 0 0 0 0
40834 - 0 0 0 0 0 0 0 0 0 0 0 0
40835 - 0 0 0 0 0 0 0 0 0 0 0 0
40836 - 0 0 0 0 0 0 0 0 0 0 0 0
40837 - 0 0 0 0 0 0 10 10 10 30 30 30
40838 - 74 74 74 58 58 58 2 2 6 42 42 42
40839 - 2 2 6 22 22 22 231 231 231 253 253 253
40840 -253 253 253 253 253 253 253 253 253 253 253 253
40841 -253 253 253 253 253 253 253 253 253 250 250 250
40842 -253 253 253 253 253 253 253 253 253 253 253 253
40843 -253 253 253 253 253 253 253 253 253 253 253 253
40844 -253 253 253 253 253 253 253 253 253 253 253 253
40845 -253 253 253 253 253 253 253 253 253 253 253 253
40846 -253 253 253 246 246 246 46 46 46 38 38 38
40847 - 42 42 42 14 14 14 38 38 38 14 14 14
40848 - 2 2 6 2 2 6 2 2 6 6 6 6
40849 - 86 86 86 46 46 46 14 14 14 0 0 0
40850 - 0 0 0 0 0 0 0 0 0 0 0 0
40851 - 0 0 0 0 0 0 0 0 0 0 0 0
40852 - 0 0 0 0 0 0 0 0 0 0 0 0
40853 - 0 0 0 0 0 0 0 0 0 0 0 0
40854 - 0 0 0 0 0 0 0 0 0 0 0 0
40855 - 0 0 0 0 0 0 0 0 0 0 0 0
40856 - 0 0 0 0 0 0 0 0 0 0 0 0
40857 - 0 0 0 6 6 6 14 14 14 42 42 42
40858 - 90 90 90 18 18 18 18 18 18 26 26 26
40859 - 2 2 6 116 116 116 253 253 253 253 253 253
40860 -253 253 253 253 253 253 253 253 253 253 253 253
40861 -253 253 253 253 253 253 250 250 250 238 238 238
40862 -253 253 253 253 253 253 253 253 253 253 253 253
40863 -253 253 253 253 253 253 253 253 253 253 253 253
40864 -253 253 253 253 253 253 253 253 253 253 253 253
40865 -253 253 253 253 253 253 253 253 253 253 253 253
40866 -253 253 253 253 253 253 94 94 94 6 6 6
40867 - 2 2 6 2 2 6 10 10 10 34 34 34
40868 - 2 2 6 2 2 6 2 2 6 2 2 6
40869 - 74 74 74 58 58 58 22 22 22 6 6 6
40870 - 0 0 0 0 0 0 0 0 0 0 0 0
40871 - 0 0 0 0 0 0 0 0 0 0 0 0
40872 - 0 0 0 0 0 0 0 0 0 0 0 0
40873 - 0 0 0 0 0 0 0 0 0 0 0 0
40874 - 0 0 0 0 0 0 0 0 0 0 0 0
40875 - 0 0 0 0 0 0 0 0 0 0 0 0
40876 - 0 0 0 0 0 0 0 0 0 0 0 0
40877 - 0 0 0 10 10 10 26 26 26 66 66 66
40878 - 82 82 82 2 2 6 38 38 38 6 6 6
40879 - 14 14 14 210 210 210 253 253 253 253 253 253
40880 -253 253 253 253 253 253 253 253 253 253 253 253
40881 -253 253 253 253 253 253 246 246 246 242 242 242
40882 -253 253 253 253 253 253 253 253 253 253 253 253
40883 -253 253 253 253 253 253 253 253 253 253 253 253
40884 -253 253 253 253 253 253 253 253 253 253 253 253
40885 -253 253 253 253 253 253 253 253 253 253 253 253
40886 -253 253 253 253 253 253 144 144 144 2 2 6
40887 - 2 2 6 2 2 6 2 2 6 46 46 46
40888 - 2 2 6 2 2 6 2 2 6 2 2 6
40889 - 42 42 42 74 74 74 30 30 30 10 10 10
40890 - 0 0 0 0 0 0 0 0 0 0 0 0
40891 - 0 0 0 0 0 0 0 0 0 0 0 0
40892 - 0 0 0 0 0 0 0 0 0 0 0 0
40893 - 0 0 0 0 0 0 0 0 0 0 0 0
40894 - 0 0 0 0 0 0 0 0 0 0 0 0
40895 - 0 0 0 0 0 0 0 0 0 0 0 0
40896 - 0 0 0 0 0 0 0 0 0 0 0 0
40897 - 6 6 6 14 14 14 42 42 42 90 90 90
40898 - 26 26 26 6 6 6 42 42 42 2 2 6
40899 - 74 74 74 250 250 250 253 253 253 253 253 253
40900 -253 253 253 253 253 253 253 253 253 253 253 253
40901 -253 253 253 253 253 253 242 242 242 242 242 242
40902 -253 253 253 253 253 253 253 253 253 253 253 253
40903 -253 253 253 253 253 253 253 253 253 253 253 253
40904 -253 253 253 253 253 253 253 253 253 253 253 253
40905 -253 253 253 253 253 253 253 253 253 253 253 253
40906 -253 253 253 253 253 253 182 182 182 2 2 6
40907 - 2 2 6 2 2 6 2 2 6 46 46 46
40908 - 2 2 6 2 2 6 2 2 6 2 2 6
40909 - 10 10 10 86 86 86 38 38 38 10 10 10
40910 - 0 0 0 0 0 0 0 0 0 0 0 0
40911 - 0 0 0 0 0 0 0 0 0 0 0 0
40912 - 0 0 0 0 0 0 0 0 0 0 0 0
40913 - 0 0 0 0 0 0 0 0 0 0 0 0
40914 - 0 0 0 0 0 0 0 0 0 0 0 0
40915 - 0 0 0 0 0 0 0 0 0 0 0 0
40916 - 0 0 0 0 0 0 0 0 0 0 0 0
40917 - 10 10 10 26 26 26 66 66 66 82 82 82
40918 - 2 2 6 22 22 22 18 18 18 2 2 6
40919 -149 149 149 253 253 253 253 253 253 253 253 253
40920 -253 253 253 253 253 253 253 253 253 253 253 253
40921 -253 253 253 253 253 253 234 234 234 242 242 242
40922 -253 253 253 253 253 253 253 253 253 253 253 253
40923 -253 253 253 253 253 253 253 253 253 253 253 253
40924 -253 253 253 253 253 253 253 253 253 253 253 253
40925 -253 253 253 253 253 253 253 253 253 253 253 253
40926 -253 253 253 253 253 253 206 206 206 2 2 6
40927 - 2 2 6 2 2 6 2 2 6 38 38 38
40928 - 2 2 6 2 2 6 2 2 6 2 2 6
40929 - 6 6 6 86 86 86 46 46 46 14 14 14
40930 - 0 0 0 0 0 0 0 0 0 0 0 0
40931 - 0 0 0 0 0 0 0 0 0 0 0 0
40932 - 0 0 0 0 0 0 0 0 0 0 0 0
40933 - 0 0 0 0 0 0 0 0 0 0 0 0
40934 - 0 0 0 0 0 0 0 0 0 0 0 0
40935 - 0 0 0 0 0 0 0 0 0 0 0 0
40936 - 0 0 0 0 0 0 0 0 0 6 6 6
40937 - 18 18 18 46 46 46 86 86 86 18 18 18
40938 - 2 2 6 34 34 34 10 10 10 6 6 6
40939 -210 210 210 253 253 253 253 253 253 253 253 253
40940 -253 253 253 253 253 253 253 253 253 253 253 253
40941 -253 253 253 253 253 253 234 234 234 242 242 242
40942 -253 253 253 253 253 253 253 253 253 253 253 253
40943 -253 253 253 253 253 253 253 253 253 253 253 253
40944 -253 253 253 253 253 253 253 253 253 253 253 253
40945 -253 253 253 253 253 253 253 253 253 253 253 253
40946 -253 253 253 253 253 253 221 221 221 6 6 6
40947 - 2 2 6 2 2 6 6 6 6 30 30 30
40948 - 2 2 6 2 2 6 2 2 6 2 2 6
40949 - 2 2 6 82 82 82 54 54 54 18 18 18
40950 - 6 6 6 0 0 0 0 0 0 0 0 0
40951 - 0 0 0 0 0 0 0 0 0 0 0 0
40952 - 0 0 0 0 0 0 0 0 0 0 0 0
40953 - 0 0 0 0 0 0 0 0 0 0 0 0
40954 - 0 0 0 0 0 0 0 0 0 0 0 0
40955 - 0 0 0 0 0 0 0 0 0 0 0 0
40956 - 0 0 0 0 0 0 0 0 0 10 10 10
40957 - 26 26 26 66 66 66 62 62 62 2 2 6
40958 - 2 2 6 38 38 38 10 10 10 26 26 26
40959 -238 238 238 253 253 253 253 253 253 253 253 253
40960 -253 253 253 253 253 253 253 253 253 253 253 253
40961 -253 253 253 253 253 253 231 231 231 238 238 238
40962 -253 253 253 253 253 253 253 253 253 253 253 253
40963 -253 253 253 253 253 253 253 253 253 253 253 253
40964 -253 253 253 253 253 253 253 253 253 253 253 253
40965 -253 253 253 253 253 253 253 253 253 253 253 253
40966 -253 253 253 253 253 253 231 231 231 6 6 6
40967 - 2 2 6 2 2 6 10 10 10 30 30 30
40968 - 2 2 6 2 2 6 2 2 6 2 2 6
40969 - 2 2 6 66 66 66 58 58 58 22 22 22
40970 - 6 6 6 0 0 0 0 0 0 0 0 0
40971 - 0 0 0 0 0 0 0 0 0 0 0 0
40972 - 0 0 0 0 0 0 0 0 0 0 0 0
40973 - 0 0 0 0 0 0 0 0 0 0 0 0
40974 - 0 0 0 0 0 0 0 0 0 0 0 0
40975 - 0 0 0 0 0 0 0 0 0 0 0 0
40976 - 0 0 0 0 0 0 0 0 0 10 10 10
40977 - 38 38 38 78 78 78 6 6 6 2 2 6
40978 - 2 2 6 46 46 46 14 14 14 42 42 42
40979 -246 246 246 253 253 253 253 253 253 253 253 253
40980 -253 253 253 253 253 253 253 253 253 253 253 253
40981 -253 253 253 253 253 253 231 231 231 242 242 242
40982 -253 253 253 253 253 253 253 253 253 253 253 253
40983 -253 253 253 253 253 253 253 253 253 253 253 253
40984 -253 253 253 253 253 253 253 253 253 253 253 253
40985 -253 253 253 253 253 253 253 253 253 253 253 253
40986 -253 253 253 253 253 253 234 234 234 10 10 10
40987 - 2 2 6 2 2 6 22 22 22 14 14 14
40988 - 2 2 6 2 2 6 2 2 6 2 2 6
40989 - 2 2 6 66 66 66 62 62 62 22 22 22
40990 - 6 6 6 0 0 0 0 0 0 0 0 0
40991 - 0 0 0 0 0 0 0 0 0 0 0 0
40992 - 0 0 0 0 0 0 0 0 0 0 0 0
40993 - 0 0 0 0 0 0 0 0 0 0 0 0
40994 - 0 0 0 0 0 0 0 0 0 0 0 0
40995 - 0 0 0 0 0 0 0 0 0 0 0 0
40996 - 0 0 0 0 0 0 6 6 6 18 18 18
40997 - 50 50 50 74 74 74 2 2 6 2 2 6
40998 - 14 14 14 70 70 70 34 34 34 62 62 62
40999 -250 250 250 253 253 253 253 253 253 253 253 253
41000 -253 253 253 253 253 253 253 253 253 253 253 253
41001 -253 253 253 253 253 253 231 231 231 246 246 246
41002 -253 253 253 253 253 253 253 253 253 253 253 253
41003 -253 253 253 253 253 253 253 253 253 253 253 253
41004 -253 253 253 253 253 253 253 253 253 253 253 253
41005 -253 253 253 253 253 253 253 253 253 253 253 253
41006 -253 253 253 253 253 253 234 234 234 14 14 14
41007 - 2 2 6 2 2 6 30 30 30 2 2 6
41008 - 2 2 6 2 2 6 2 2 6 2 2 6
41009 - 2 2 6 66 66 66 62 62 62 22 22 22
41010 - 6 6 6 0 0 0 0 0 0 0 0 0
41011 - 0 0 0 0 0 0 0 0 0 0 0 0
41012 - 0 0 0 0 0 0 0 0 0 0 0 0
41013 - 0 0 0 0 0 0 0 0 0 0 0 0
41014 - 0 0 0 0 0 0 0 0 0 0 0 0
41015 - 0 0 0 0 0 0 0 0 0 0 0 0
41016 - 0 0 0 0 0 0 6 6 6 18 18 18
41017 - 54 54 54 62 62 62 2 2 6 2 2 6
41018 - 2 2 6 30 30 30 46 46 46 70 70 70
41019 -250 250 250 253 253 253 253 253 253 253 253 253
41020 -253 253 253 253 253 253 253 253 253 253 253 253
41021 -253 253 253 253 253 253 231 231 231 246 246 246
41022 -253 253 253 253 253 253 253 253 253 253 253 253
41023 -253 253 253 253 253 253 253 253 253 253 253 253
41024 -253 253 253 253 253 253 253 253 253 253 253 253
41025 -253 253 253 253 253 253 253 253 253 253 253 253
41026 -253 253 253 253 253 253 226 226 226 10 10 10
41027 - 2 2 6 6 6 6 30 30 30 2 2 6
41028 - 2 2 6 2 2 6 2 2 6 2 2 6
41029 - 2 2 6 66 66 66 58 58 58 22 22 22
41030 - 6 6 6 0 0 0 0 0 0 0 0 0
41031 - 0 0 0 0 0 0 0 0 0 0 0 0
41032 - 0 0 0 0 0 0 0 0 0 0 0 0
41033 - 0 0 0 0 0 0 0 0 0 0 0 0
41034 - 0 0 0 0 0 0 0 0 0 0 0 0
41035 - 0 0 0 0 0 0 0 0 0 0 0 0
41036 - 0 0 0 0 0 0 6 6 6 22 22 22
41037 - 58 58 58 62 62 62 2 2 6 2 2 6
41038 - 2 2 6 2 2 6 30 30 30 78 78 78
41039 -250 250 250 253 253 253 253 253 253 253 253 253
41040 -253 253 253 253 253 253 253 253 253 253 253 253
41041 -253 253 253 253 253 253 231 231 231 246 246 246
41042 -253 253 253 253 253 253 253 253 253 253 253 253
41043 -253 253 253 253 253 253 253 253 253 253 253 253
41044 -253 253 253 253 253 253 253 253 253 253 253 253
41045 -253 253 253 253 253 253 253 253 253 253 253 253
41046 -253 253 253 253 253 253 206 206 206 2 2 6
41047 - 22 22 22 34 34 34 18 14 6 22 22 22
41048 - 26 26 26 18 18 18 6 6 6 2 2 6
41049 - 2 2 6 82 82 82 54 54 54 18 18 18
41050 - 6 6 6 0 0 0 0 0 0 0 0 0
41051 - 0 0 0 0 0 0 0 0 0 0 0 0
41052 - 0 0 0 0 0 0 0 0 0 0 0 0
41053 - 0 0 0 0 0 0 0 0 0 0 0 0
41054 - 0 0 0 0 0 0 0 0 0 0 0 0
41055 - 0 0 0 0 0 0 0 0 0 0 0 0
41056 - 0 0 0 0 0 0 6 6 6 26 26 26
41057 - 62 62 62 106 106 106 74 54 14 185 133 11
41058 -210 162 10 121 92 8 6 6 6 62 62 62
41059 -238 238 238 253 253 253 253 253 253 253 253 253
41060 -253 253 253 253 253 253 253 253 253 253 253 253
41061 -253 253 253 253 253 253 231 231 231 246 246 246
41062 -253 253 253 253 253 253 253 253 253 253 253 253
41063 -253 253 253 253 253 253 253 253 253 253 253 253
41064 -253 253 253 253 253 253 253 253 253 253 253 253
41065 -253 253 253 253 253 253 253 253 253 253 253 253
41066 -253 253 253 253 253 253 158 158 158 18 18 18
41067 - 14 14 14 2 2 6 2 2 6 2 2 6
41068 - 6 6 6 18 18 18 66 66 66 38 38 38
41069 - 6 6 6 94 94 94 50 50 50 18 18 18
41070 - 6 6 6 0 0 0 0 0 0 0 0 0
41071 - 0 0 0 0 0 0 0 0 0 0 0 0
41072 - 0 0 0 0 0 0 0 0 0 0 0 0
41073 - 0 0 0 0 0 0 0 0 0 0 0 0
41074 - 0 0 0 0 0 0 0 0 0 0 0 0
41075 - 0 0 0 0 0 0 0 0 0 6 6 6
41076 - 10 10 10 10 10 10 18 18 18 38 38 38
41077 - 78 78 78 142 134 106 216 158 10 242 186 14
41078 -246 190 14 246 190 14 156 118 10 10 10 10
41079 - 90 90 90 238 238 238 253 253 253 253 253 253
41080 -253 253 253 253 253 253 253 253 253 253 253 253
41081 -253 253 253 253 253 253 231 231 231 250 250 250
41082 -253 253 253 253 253 253 253 253 253 253 253 253
41083 -253 253 253 253 253 253 253 253 253 253 253 253
41084 -253 253 253 253 253 253 253 253 253 253 253 253
41085 -253 253 253 253 253 253 253 253 253 246 230 190
41086 -238 204 91 238 204 91 181 142 44 37 26 9
41087 - 2 2 6 2 2 6 2 2 6 2 2 6
41088 - 2 2 6 2 2 6 38 38 38 46 46 46
41089 - 26 26 26 106 106 106 54 54 54 18 18 18
41090 - 6 6 6 0 0 0 0 0 0 0 0 0
41091 - 0 0 0 0 0 0 0 0 0 0 0 0
41092 - 0 0 0 0 0 0 0 0 0 0 0 0
41093 - 0 0 0 0 0 0 0 0 0 0 0 0
41094 - 0 0 0 0 0 0 0 0 0 0 0 0
41095 - 0 0 0 6 6 6 14 14 14 22 22 22
41096 - 30 30 30 38 38 38 50 50 50 70 70 70
41097 -106 106 106 190 142 34 226 170 11 242 186 14
41098 -246 190 14 246 190 14 246 190 14 154 114 10
41099 - 6 6 6 74 74 74 226 226 226 253 253 253
41100 -253 253 253 253 253 253 253 253 253 253 253 253
41101 -253 253 253 253 253 253 231 231 231 250 250 250
41102 -253 253 253 253 253 253 253 253 253 253 253 253
41103 -253 253 253 253 253 253 253 253 253 253 253 253
41104 -253 253 253 253 253 253 253 253 253 253 253 253
41105 -253 253 253 253 253 253 253 253 253 228 184 62
41106 -241 196 14 241 208 19 232 195 16 38 30 10
41107 - 2 2 6 2 2 6 2 2 6 2 2 6
41108 - 2 2 6 6 6 6 30 30 30 26 26 26
41109 -203 166 17 154 142 90 66 66 66 26 26 26
41110 - 6 6 6 0 0 0 0 0 0 0 0 0
41111 - 0 0 0 0 0 0 0 0 0 0 0 0
41112 - 0 0 0 0 0 0 0 0 0 0 0 0
41113 - 0 0 0 0 0 0 0 0 0 0 0 0
41114 - 0 0 0 0 0 0 0 0 0 0 0 0
41115 - 6 6 6 18 18 18 38 38 38 58 58 58
41116 - 78 78 78 86 86 86 101 101 101 123 123 123
41117 -175 146 61 210 150 10 234 174 13 246 186 14
41118 -246 190 14 246 190 14 246 190 14 238 190 10
41119 -102 78 10 2 2 6 46 46 46 198 198 198
41120 -253 253 253 253 253 253 253 253 253 253 253 253
41121 -253 253 253 253 253 253 234 234 234 242 242 242
41122 -253 253 253 253 253 253 253 253 253 253 253 253
41123 -253 253 253 253 253 253 253 253 253 253 253 253
41124 -253 253 253 253 253 253 253 253 253 253 253 253
41125 -253 253 253 253 253 253 253 253 253 224 178 62
41126 -242 186 14 241 196 14 210 166 10 22 18 6
41127 - 2 2 6 2 2 6 2 2 6 2 2 6
41128 - 2 2 6 2 2 6 6 6 6 121 92 8
41129 -238 202 15 232 195 16 82 82 82 34 34 34
41130 - 10 10 10 0 0 0 0 0 0 0 0 0
41131 - 0 0 0 0 0 0 0 0 0 0 0 0
41132 - 0 0 0 0 0 0 0 0 0 0 0 0
41133 - 0 0 0 0 0 0 0 0 0 0 0 0
41134 - 0 0 0 0 0 0 0 0 0 0 0 0
41135 - 14 14 14 38 38 38 70 70 70 154 122 46
41136 -190 142 34 200 144 11 197 138 11 197 138 11
41137 -213 154 11 226 170 11 242 186 14 246 190 14
41138 -246 190 14 246 190 14 246 190 14 246 190 14
41139 -225 175 15 46 32 6 2 2 6 22 22 22
41140 -158 158 158 250 250 250 253 253 253 253 253 253
41141 -253 253 253 253 253 253 253 253 253 253 253 253
41142 -253 253 253 253 253 253 253 253 253 253 253 253
41143 -253 253 253 253 253 253 253 253 253 253 253 253
41144 -253 253 253 253 253 253 253 253 253 253 253 253
41145 -253 253 253 250 250 250 242 242 242 224 178 62
41146 -239 182 13 236 186 11 213 154 11 46 32 6
41147 - 2 2 6 2 2 6 2 2 6 2 2 6
41148 - 2 2 6 2 2 6 61 42 6 225 175 15
41149 -238 190 10 236 186 11 112 100 78 42 42 42
41150 - 14 14 14 0 0 0 0 0 0 0 0 0
41151 - 0 0 0 0 0 0 0 0 0 0 0 0
41152 - 0 0 0 0 0 0 0 0 0 0 0 0
41153 - 0 0 0 0 0 0 0 0 0 0 0 0
41154 - 0 0 0 0 0 0 0 0 0 6 6 6
41155 - 22 22 22 54 54 54 154 122 46 213 154 11
41156 -226 170 11 230 174 11 226 170 11 226 170 11
41157 -236 178 12 242 186 14 246 190 14 246 190 14
41158 -246 190 14 246 190 14 246 190 14 246 190 14
41159 -241 196 14 184 144 12 10 10 10 2 2 6
41160 - 6 6 6 116 116 116 242 242 242 253 253 253
41161 -253 253 253 253 253 253 253 253 253 253 253 253
41162 -253 253 253 253 253 253 253 253 253 253 253 253
41163 -253 253 253 253 253 253 253 253 253 253 253 253
41164 -253 253 253 253 253 253 253 253 253 253 253 253
41165 -253 253 253 231 231 231 198 198 198 214 170 54
41166 -236 178 12 236 178 12 210 150 10 137 92 6
41167 - 18 14 6 2 2 6 2 2 6 2 2 6
41168 - 6 6 6 70 47 6 200 144 11 236 178 12
41169 -239 182 13 239 182 13 124 112 88 58 58 58
41170 - 22 22 22 6 6 6 0 0 0 0 0 0
41171 - 0 0 0 0 0 0 0 0 0 0 0 0
41172 - 0 0 0 0 0 0 0 0 0 0 0 0
41173 - 0 0 0 0 0 0 0 0 0 0 0 0
41174 - 0 0 0 0 0 0 0 0 0 10 10 10
41175 - 30 30 30 70 70 70 180 133 36 226 170 11
41176 -239 182 13 242 186 14 242 186 14 246 186 14
41177 -246 190 14 246 190 14 246 190 14 246 190 14
41178 -246 190 14 246 190 14 246 190 14 246 190 14
41179 -246 190 14 232 195 16 98 70 6 2 2 6
41180 - 2 2 6 2 2 6 66 66 66 221 221 221
41181 -253 253 253 253 253 253 253 253 253 253 253 253
41182 -253 253 253 253 253 253 253 253 253 253 253 253
41183 -253 253 253 253 253 253 253 253 253 253 253 253
41184 -253 253 253 253 253 253 253 253 253 253 253 253
41185 -253 253 253 206 206 206 198 198 198 214 166 58
41186 -230 174 11 230 174 11 216 158 10 192 133 9
41187 -163 110 8 116 81 8 102 78 10 116 81 8
41188 -167 114 7 197 138 11 226 170 11 239 182 13
41189 -242 186 14 242 186 14 162 146 94 78 78 78
41190 - 34 34 34 14 14 14 6 6 6 0 0 0
41191 - 0 0 0 0 0 0 0 0 0 0 0 0
41192 - 0 0 0 0 0 0 0 0 0 0 0 0
41193 - 0 0 0 0 0 0 0 0 0 0 0 0
41194 - 0 0 0 0 0 0 0 0 0 6 6 6
41195 - 30 30 30 78 78 78 190 142 34 226 170 11
41196 -239 182 13 246 190 14 246 190 14 246 190 14
41197 -246 190 14 246 190 14 246 190 14 246 190 14
41198 -246 190 14 246 190 14 246 190 14 246 190 14
41199 -246 190 14 241 196 14 203 166 17 22 18 6
41200 - 2 2 6 2 2 6 2 2 6 38 38 38
41201 -218 218 218 253 253 253 253 253 253 253 253 253
41202 -253 253 253 253 253 253 253 253 253 253 253 253
41203 -253 253 253 253 253 253 253 253 253 253 253 253
41204 -253 253 253 253 253 253 253 253 253 253 253 253
41205 -250 250 250 206 206 206 198 198 198 202 162 69
41206 -226 170 11 236 178 12 224 166 10 210 150 10
41207 -200 144 11 197 138 11 192 133 9 197 138 11
41208 -210 150 10 226 170 11 242 186 14 246 190 14
41209 -246 190 14 246 186 14 225 175 15 124 112 88
41210 - 62 62 62 30 30 30 14 14 14 6 6 6
41211 - 0 0 0 0 0 0 0 0 0 0 0 0
41212 - 0 0 0 0 0 0 0 0 0 0 0 0
41213 - 0 0 0 0 0 0 0 0 0 0 0 0
41214 - 0 0 0 0 0 0 0 0 0 10 10 10
41215 - 30 30 30 78 78 78 174 135 50 224 166 10
41216 -239 182 13 246 190 14 246 190 14 246 190 14
41217 -246 190 14 246 190 14 246 190 14 246 190 14
41218 -246 190 14 246 190 14 246 190 14 246 190 14
41219 -246 190 14 246 190 14 241 196 14 139 102 15
41220 - 2 2 6 2 2 6 2 2 6 2 2 6
41221 - 78 78 78 250 250 250 253 253 253 253 253 253
41222 -253 253 253 253 253 253 253 253 253 253 253 253
41223 -253 253 253 253 253 253 253 253 253 253 253 253
41224 -253 253 253 253 253 253 253 253 253 253 253 253
41225 -250 250 250 214 214 214 198 198 198 190 150 46
41226 -219 162 10 236 178 12 234 174 13 224 166 10
41227 -216 158 10 213 154 11 213 154 11 216 158 10
41228 -226 170 11 239 182 13 246 190 14 246 190 14
41229 -246 190 14 246 190 14 242 186 14 206 162 42
41230 -101 101 101 58 58 58 30 30 30 14 14 14
41231 - 6 6 6 0 0 0 0 0 0 0 0 0
41232 - 0 0 0 0 0 0 0 0 0 0 0 0
41233 - 0 0 0 0 0 0 0 0 0 0 0 0
41234 - 0 0 0 0 0 0 0 0 0 10 10 10
41235 - 30 30 30 74 74 74 174 135 50 216 158 10
41236 -236 178 12 246 190 14 246 190 14 246 190 14
41237 -246 190 14 246 190 14 246 190 14 246 190 14
41238 -246 190 14 246 190 14 246 190 14 246 190 14
41239 -246 190 14 246 190 14 241 196 14 226 184 13
41240 - 61 42 6 2 2 6 2 2 6 2 2 6
41241 - 22 22 22 238 238 238 253 253 253 253 253 253
41242 -253 253 253 253 253 253 253 253 253 253 253 253
41243 -253 253 253 253 253 253 253 253 253 253 253 253
41244 -253 253 253 253 253 253 253 253 253 253 253 253
41245 -253 253 253 226 226 226 187 187 187 180 133 36
41246 -216 158 10 236 178 12 239 182 13 236 178 12
41247 -230 174 11 226 170 11 226 170 11 230 174 11
41248 -236 178 12 242 186 14 246 190 14 246 190 14
41249 -246 190 14 246 190 14 246 186 14 239 182 13
41250 -206 162 42 106 106 106 66 66 66 34 34 34
41251 - 14 14 14 6 6 6 0 0 0 0 0 0
41252 - 0 0 0 0 0 0 0 0 0 0 0 0
41253 - 0 0 0 0 0 0 0 0 0 0 0 0
41254 - 0 0 0 0 0 0 0 0 0 6 6 6
41255 - 26 26 26 70 70 70 163 133 67 213 154 11
41256 -236 178 12 246 190 14 246 190 14 246 190 14
41257 -246 190 14 246 190 14 246 190 14 246 190 14
41258 -246 190 14 246 190 14 246 190 14 246 190 14
41259 -246 190 14 246 190 14 246 190 14 241 196 14
41260 -190 146 13 18 14 6 2 2 6 2 2 6
41261 - 46 46 46 246 246 246 253 253 253 253 253 253
41262 -253 253 253 253 253 253 253 253 253 253 253 253
41263 -253 253 253 253 253 253 253 253 253 253 253 253
41264 -253 253 253 253 253 253 253 253 253 253 253 253
41265 -253 253 253 221 221 221 86 86 86 156 107 11
41266 -216 158 10 236 178 12 242 186 14 246 186 14
41267 -242 186 14 239 182 13 239 182 13 242 186 14
41268 -242 186 14 246 186 14 246 190 14 246 190 14
41269 -246 190 14 246 190 14 246 190 14 246 190 14
41270 -242 186 14 225 175 15 142 122 72 66 66 66
41271 - 30 30 30 10 10 10 0 0 0 0 0 0
41272 - 0 0 0 0 0 0 0 0 0 0 0 0
41273 - 0 0 0 0 0 0 0 0 0 0 0 0
41274 - 0 0 0 0 0 0 0 0 0 6 6 6
41275 - 26 26 26 70 70 70 163 133 67 210 150 10
41276 -236 178 12 246 190 14 246 190 14 246 190 14
41277 -246 190 14 246 190 14 246 190 14 246 190 14
41278 -246 190 14 246 190 14 246 190 14 246 190 14
41279 -246 190 14 246 190 14 246 190 14 246 190 14
41280 -232 195 16 121 92 8 34 34 34 106 106 106
41281 -221 221 221 253 253 253 253 253 253 253 253 253
41282 -253 253 253 253 253 253 253 253 253 253 253 253
41283 -253 253 253 253 253 253 253 253 253 253 253 253
41284 -253 253 253 253 253 253 253 253 253 253 253 253
41285 -242 242 242 82 82 82 18 14 6 163 110 8
41286 -216 158 10 236 178 12 242 186 14 246 190 14
41287 -246 190 14 246 190 14 246 190 14 246 190 14
41288 -246 190 14 246 190 14 246 190 14 246 190 14
41289 -246 190 14 246 190 14 246 190 14 246 190 14
41290 -246 190 14 246 190 14 242 186 14 163 133 67
41291 - 46 46 46 18 18 18 6 6 6 0 0 0
41292 - 0 0 0 0 0 0 0 0 0 0 0 0
41293 - 0 0 0 0 0 0 0 0 0 0 0 0
41294 - 0 0 0 0 0 0 0 0 0 10 10 10
41295 - 30 30 30 78 78 78 163 133 67 210 150 10
41296 -236 178 12 246 186 14 246 190 14 246 190 14
41297 -246 190 14 246 190 14 246 190 14 246 190 14
41298 -246 190 14 246 190 14 246 190 14 246 190 14
41299 -246 190 14 246 190 14 246 190 14 246 190 14
41300 -241 196 14 215 174 15 190 178 144 253 253 253
41301 -253 253 253 253 253 253 253 253 253 253 253 253
41302 -253 253 253 253 253 253 253 253 253 253 253 253
41303 -253 253 253 253 253 253 253 253 253 253 253 253
41304 -253 253 253 253 253 253 253 253 253 218 218 218
41305 - 58 58 58 2 2 6 22 18 6 167 114 7
41306 -216 158 10 236 178 12 246 186 14 246 190 14
41307 -246 190 14 246 190 14 246 190 14 246 190 14
41308 -246 190 14 246 190 14 246 190 14 246 190 14
41309 -246 190 14 246 190 14 246 190 14 246 190 14
41310 -246 190 14 246 186 14 242 186 14 190 150 46
41311 - 54 54 54 22 22 22 6 6 6 0 0 0
41312 - 0 0 0 0 0 0 0 0 0 0 0 0
41313 - 0 0 0 0 0 0 0 0 0 0 0 0
41314 - 0 0 0 0 0 0 0 0 0 14 14 14
41315 - 38 38 38 86 86 86 180 133 36 213 154 11
41316 -236 178 12 246 186 14 246 190 14 246 190 14
41317 -246 190 14 246 190 14 246 190 14 246 190 14
41318 -246 190 14 246 190 14 246 190 14 246 190 14
41319 -246 190 14 246 190 14 246 190 14 246 190 14
41320 -246 190 14 232 195 16 190 146 13 214 214 214
41321 -253 253 253 253 253 253 253 253 253 253 253 253
41322 -253 253 253 253 253 253 253 253 253 253 253 253
41323 -253 253 253 253 253 253 253 253 253 253 253 253
41324 -253 253 253 250 250 250 170 170 170 26 26 26
41325 - 2 2 6 2 2 6 37 26 9 163 110 8
41326 -219 162 10 239 182 13 246 186 14 246 190 14
41327 -246 190 14 246 190 14 246 190 14 246 190 14
41328 -246 190 14 246 190 14 246 190 14 246 190 14
41329 -246 190 14 246 190 14 246 190 14 246 190 14
41330 -246 186 14 236 178 12 224 166 10 142 122 72
41331 - 46 46 46 18 18 18 6 6 6 0 0 0
41332 - 0 0 0 0 0 0 0 0 0 0 0 0
41333 - 0 0 0 0 0 0 0 0 0 0 0 0
41334 - 0 0 0 0 0 0 6 6 6 18 18 18
41335 - 50 50 50 109 106 95 192 133 9 224 166 10
41336 -242 186 14 246 190 14 246 190 14 246 190 14
41337 -246 190 14 246 190 14 246 190 14 246 190 14
41338 -246 190 14 246 190 14 246 190 14 246 190 14
41339 -246 190 14 246 190 14 246 190 14 246 190 14
41340 -242 186 14 226 184 13 210 162 10 142 110 46
41341 -226 226 226 253 253 253 253 253 253 253 253 253
41342 -253 253 253 253 253 253 253 253 253 253 253 253
41343 -253 253 253 253 253 253 253 253 253 253 253 253
41344 -198 198 198 66 66 66 2 2 6 2 2 6
41345 - 2 2 6 2 2 6 50 34 6 156 107 11
41346 -219 162 10 239 182 13 246 186 14 246 190 14
41347 -246 190 14 246 190 14 246 190 14 246 190 14
41348 -246 190 14 246 190 14 246 190 14 246 190 14
41349 -246 190 14 246 190 14 246 190 14 242 186 14
41350 -234 174 13 213 154 11 154 122 46 66 66 66
41351 - 30 30 30 10 10 10 0 0 0 0 0 0
41352 - 0 0 0 0 0 0 0 0 0 0 0 0
41353 - 0 0 0 0 0 0 0 0 0 0 0 0
41354 - 0 0 0 0 0 0 6 6 6 22 22 22
41355 - 58 58 58 154 121 60 206 145 10 234 174 13
41356 -242 186 14 246 186 14 246 190 14 246 190 14
41357 -246 190 14 246 190 14 246 190 14 246 190 14
41358 -246 190 14 246 190 14 246 190 14 246 190 14
41359 -246 190 14 246 190 14 246 190 14 246 190 14
41360 -246 186 14 236 178 12 210 162 10 163 110 8
41361 - 61 42 6 138 138 138 218 218 218 250 250 250
41362 -253 253 253 253 253 253 253 253 253 250 250 250
41363 -242 242 242 210 210 210 144 144 144 66 66 66
41364 - 6 6 6 2 2 6 2 2 6 2 2 6
41365 - 2 2 6 2 2 6 61 42 6 163 110 8
41366 -216 158 10 236 178 12 246 190 14 246 190 14
41367 -246 190 14 246 190 14 246 190 14 246 190 14
41368 -246 190 14 246 190 14 246 190 14 246 190 14
41369 -246 190 14 239 182 13 230 174 11 216 158 10
41370 -190 142 34 124 112 88 70 70 70 38 38 38
41371 - 18 18 18 6 6 6 0 0 0 0 0 0
41372 - 0 0 0 0 0 0 0 0 0 0 0 0
41373 - 0 0 0 0 0 0 0 0 0 0 0 0
41374 - 0 0 0 0 0 0 6 6 6 22 22 22
41375 - 62 62 62 168 124 44 206 145 10 224 166 10
41376 -236 178 12 239 182 13 242 186 14 242 186 14
41377 -246 186 14 246 190 14 246 190 14 246 190 14
41378 -246 190 14 246 190 14 246 190 14 246 190 14
41379 -246 190 14 246 190 14 246 190 14 246 190 14
41380 -246 190 14 236 178 12 216 158 10 175 118 6
41381 - 80 54 7 2 2 6 6 6 6 30 30 30
41382 - 54 54 54 62 62 62 50 50 50 38 38 38
41383 - 14 14 14 2 2 6 2 2 6 2 2 6
41384 - 2 2 6 2 2 6 2 2 6 2 2 6
41385 - 2 2 6 6 6 6 80 54 7 167 114 7
41386 -213 154 11 236 178 12 246 190 14 246 190 14
41387 -246 190 14 246 190 14 246 190 14 246 190 14
41388 -246 190 14 242 186 14 239 182 13 239 182 13
41389 -230 174 11 210 150 10 174 135 50 124 112 88
41390 - 82 82 82 54 54 54 34 34 34 18 18 18
41391 - 6 6 6 0 0 0 0 0 0 0 0 0
41392 - 0 0 0 0 0 0 0 0 0 0 0 0
41393 - 0 0 0 0 0 0 0 0 0 0 0 0
41394 - 0 0 0 0 0 0 6 6 6 18 18 18
41395 - 50 50 50 158 118 36 192 133 9 200 144 11
41396 -216 158 10 219 162 10 224 166 10 226 170 11
41397 -230 174 11 236 178 12 239 182 13 239 182 13
41398 -242 186 14 246 186 14 246 190 14 246 190 14
41399 -246 190 14 246 190 14 246 190 14 246 190 14
41400 -246 186 14 230 174 11 210 150 10 163 110 8
41401 -104 69 6 10 10 10 2 2 6 2 2 6
41402 - 2 2 6 2 2 6 2 2 6 2 2 6
41403 - 2 2 6 2 2 6 2 2 6 2 2 6
41404 - 2 2 6 2 2 6 2 2 6 2 2 6
41405 - 2 2 6 6 6 6 91 60 6 167 114 7
41406 -206 145 10 230 174 11 242 186 14 246 190 14
41407 -246 190 14 246 190 14 246 186 14 242 186 14
41408 -239 182 13 230 174 11 224 166 10 213 154 11
41409 -180 133 36 124 112 88 86 86 86 58 58 58
41410 - 38 38 38 22 22 22 10 10 10 6 6 6
41411 - 0 0 0 0 0 0 0 0 0 0 0 0
41412 - 0 0 0 0 0 0 0 0 0 0 0 0
41413 - 0 0 0 0 0 0 0 0 0 0 0 0
41414 - 0 0 0 0 0 0 0 0 0 14 14 14
41415 - 34 34 34 70 70 70 138 110 50 158 118 36
41416 -167 114 7 180 123 7 192 133 9 197 138 11
41417 -200 144 11 206 145 10 213 154 11 219 162 10
41418 -224 166 10 230 174 11 239 182 13 242 186 14
41419 -246 186 14 246 186 14 246 186 14 246 186 14
41420 -239 182 13 216 158 10 185 133 11 152 99 6
41421 -104 69 6 18 14 6 2 2 6 2 2 6
41422 - 2 2 6 2 2 6 2 2 6 2 2 6
41423 - 2 2 6 2 2 6 2 2 6 2 2 6
41424 - 2 2 6 2 2 6 2 2 6 2 2 6
41425 - 2 2 6 6 6 6 80 54 7 152 99 6
41426 -192 133 9 219 162 10 236 178 12 239 182 13
41427 -246 186 14 242 186 14 239 182 13 236 178 12
41428 -224 166 10 206 145 10 192 133 9 154 121 60
41429 - 94 94 94 62 62 62 42 42 42 22 22 22
41430 - 14 14 14 6 6 6 0 0 0 0 0 0
41431 - 0 0 0 0 0 0 0 0 0 0 0 0
41432 - 0 0 0 0 0 0 0 0 0 0 0 0
41433 - 0 0 0 0 0 0 0 0 0 0 0 0
41434 - 0 0 0 0 0 0 0 0 0 6 6 6
41435 - 18 18 18 34 34 34 58 58 58 78 78 78
41436 -101 98 89 124 112 88 142 110 46 156 107 11
41437 -163 110 8 167 114 7 175 118 6 180 123 7
41438 -185 133 11 197 138 11 210 150 10 219 162 10
41439 -226 170 11 236 178 12 236 178 12 234 174 13
41440 -219 162 10 197 138 11 163 110 8 130 83 6
41441 - 91 60 6 10 10 10 2 2 6 2 2 6
41442 - 18 18 18 38 38 38 38 38 38 38 38 38
41443 - 38 38 38 38 38 38 38 38 38 38 38 38
41444 - 38 38 38 38 38 38 26 26 26 2 2 6
41445 - 2 2 6 6 6 6 70 47 6 137 92 6
41446 -175 118 6 200 144 11 219 162 10 230 174 11
41447 -234 174 13 230 174 11 219 162 10 210 150 10
41448 -192 133 9 163 110 8 124 112 88 82 82 82
41449 - 50 50 50 30 30 30 14 14 14 6 6 6
41450 - 0 0 0 0 0 0 0 0 0 0 0 0
41451 - 0 0 0 0 0 0 0 0 0 0 0 0
41452 - 0 0 0 0 0 0 0 0 0 0 0 0
41453 - 0 0 0 0 0 0 0 0 0 0 0 0
41454 - 0 0 0 0 0 0 0 0 0 0 0 0
41455 - 6 6 6 14 14 14 22 22 22 34 34 34
41456 - 42 42 42 58 58 58 74 74 74 86 86 86
41457 -101 98 89 122 102 70 130 98 46 121 87 25
41458 -137 92 6 152 99 6 163 110 8 180 123 7
41459 -185 133 11 197 138 11 206 145 10 200 144 11
41460 -180 123 7 156 107 11 130 83 6 104 69 6
41461 - 50 34 6 54 54 54 110 110 110 101 98 89
41462 - 86 86 86 82 82 82 78 78 78 78 78 78
41463 - 78 78 78 78 78 78 78 78 78 78 78 78
41464 - 78 78 78 82 82 82 86 86 86 94 94 94
41465 -106 106 106 101 101 101 86 66 34 124 80 6
41466 -156 107 11 180 123 7 192 133 9 200 144 11
41467 -206 145 10 200 144 11 192 133 9 175 118 6
41468 -139 102 15 109 106 95 70 70 70 42 42 42
41469 - 22 22 22 10 10 10 0 0 0 0 0 0
41470 - 0 0 0 0 0 0 0 0 0 0 0 0
41471 - 0 0 0 0 0 0 0 0 0 0 0 0
41472 - 0 0 0 0 0 0 0 0 0 0 0 0
41473 - 0 0 0 0 0 0 0 0 0 0 0 0
41474 - 0 0 0 0 0 0 0 0 0 0 0 0
41475 - 0 0 0 0 0 0 6 6 6 10 10 10
41476 - 14 14 14 22 22 22 30 30 30 38 38 38
41477 - 50 50 50 62 62 62 74 74 74 90 90 90
41478 -101 98 89 112 100 78 121 87 25 124 80 6
41479 -137 92 6 152 99 6 152 99 6 152 99 6
41480 -138 86 6 124 80 6 98 70 6 86 66 30
41481 -101 98 89 82 82 82 58 58 58 46 46 46
41482 - 38 38 38 34 34 34 34 34 34 34 34 34
41483 - 34 34 34 34 34 34 34 34 34 34 34 34
41484 - 34 34 34 34 34 34 38 38 38 42 42 42
41485 - 54 54 54 82 82 82 94 86 76 91 60 6
41486 -134 86 6 156 107 11 167 114 7 175 118 6
41487 -175 118 6 167 114 7 152 99 6 121 87 25
41488 -101 98 89 62 62 62 34 34 34 18 18 18
41489 - 6 6 6 0 0 0 0 0 0 0 0 0
41490 - 0 0 0 0 0 0 0 0 0 0 0 0
41491 - 0 0 0 0 0 0 0 0 0 0 0 0
41492 - 0 0 0 0 0 0 0 0 0 0 0 0
41493 - 0 0 0 0 0 0 0 0 0 0 0 0
41494 - 0 0 0 0 0 0 0 0 0 0 0 0
41495 - 0 0 0 0 0 0 0 0 0 0 0 0
41496 - 0 0 0 6 6 6 6 6 6 10 10 10
41497 - 18 18 18 22 22 22 30 30 30 42 42 42
41498 - 50 50 50 66 66 66 86 86 86 101 98 89
41499 -106 86 58 98 70 6 104 69 6 104 69 6
41500 -104 69 6 91 60 6 82 62 34 90 90 90
41501 - 62 62 62 38 38 38 22 22 22 14 14 14
41502 - 10 10 10 10 10 10 10 10 10 10 10 10
41503 - 10 10 10 10 10 10 6 6 6 10 10 10
41504 - 10 10 10 10 10 10 10 10 10 14 14 14
41505 - 22 22 22 42 42 42 70 70 70 89 81 66
41506 - 80 54 7 104 69 6 124 80 6 137 92 6
41507 -134 86 6 116 81 8 100 82 52 86 86 86
41508 - 58 58 58 30 30 30 14 14 14 6 6 6
41509 - 0 0 0 0 0 0 0 0 0 0 0 0
41510 - 0 0 0 0 0 0 0 0 0 0 0 0
41511 - 0 0 0 0 0 0 0 0 0 0 0 0
41512 - 0 0 0 0 0 0 0 0 0 0 0 0
41513 - 0 0 0 0 0 0 0 0 0 0 0 0
41514 - 0 0 0 0 0 0 0 0 0 0 0 0
41515 - 0 0 0 0 0 0 0 0 0 0 0 0
41516 - 0 0 0 0 0 0 0 0 0 0 0 0
41517 - 0 0 0 6 6 6 10 10 10 14 14 14
41518 - 18 18 18 26 26 26 38 38 38 54 54 54
41519 - 70 70 70 86 86 86 94 86 76 89 81 66
41520 - 89 81 66 86 86 86 74 74 74 50 50 50
41521 - 30 30 30 14 14 14 6 6 6 0 0 0
41522 - 0 0 0 0 0 0 0 0 0 0 0 0
41523 - 0 0 0 0 0 0 0 0 0 0 0 0
41524 - 0 0 0 0 0 0 0 0 0 0 0 0
41525 - 6 6 6 18 18 18 34 34 34 58 58 58
41526 - 82 82 82 89 81 66 89 81 66 89 81 66
41527 - 94 86 66 94 86 76 74 74 74 50 50 50
41528 - 26 26 26 14 14 14 6 6 6 0 0 0
41529 - 0 0 0 0 0 0 0 0 0 0 0 0
41530 - 0 0 0 0 0 0 0 0 0 0 0 0
41531 - 0 0 0 0 0 0 0 0 0 0 0 0
41532 - 0 0 0 0 0 0 0 0 0 0 0 0
41533 - 0 0 0 0 0 0 0 0 0 0 0 0
41534 - 0 0 0 0 0 0 0 0 0 0 0 0
41535 - 0 0 0 0 0 0 0 0 0 0 0 0
41536 - 0 0 0 0 0 0 0 0 0 0 0 0
41537 - 0 0 0 0 0 0 0 0 0 0 0 0
41538 - 6 6 6 6 6 6 14 14 14 18 18 18
41539 - 30 30 30 38 38 38 46 46 46 54 54 54
41540 - 50 50 50 42 42 42 30 30 30 18 18 18
41541 - 10 10 10 0 0 0 0 0 0 0 0 0
41542 - 0 0 0 0 0 0 0 0 0 0 0 0
41543 - 0 0 0 0 0 0 0 0 0 0 0 0
41544 - 0 0 0 0 0 0 0 0 0 0 0 0
41545 - 0 0 0 6 6 6 14 14 14 26 26 26
41546 - 38 38 38 50 50 50 58 58 58 58 58 58
41547 - 54 54 54 42 42 42 30 30 30 18 18 18
41548 - 10 10 10 0 0 0 0 0 0 0 0 0
41549 - 0 0 0 0 0 0 0 0 0 0 0 0
41550 - 0 0 0 0 0 0 0 0 0 0 0 0
41551 - 0 0 0 0 0 0 0 0 0 0 0 0
41552 - 0 0 0 0 0 0 0 0 0 0 0 0
41553 - 0 0 0 0 0 0 0 0 0 0 0 0
41554 - 0 0 0 0 0 0 0 0 0 0 0 0
41555 - 0 0 0 0 0 0 0 0 0 0 0 0
41556 - 0 0 0 0 0 0 0 0 0 0 0 0
41557 - 0 0 0 0 0 0 0 0 0 0 0 0
41558 - 0 0 0 0 0 0 0 0 0 6 6 6
41559 - 6 6 6 10 10 10 14 14 14 18 18 18
41560 - 18 18 18 14 14 14 10 10 10 6 6 6
41561 - 0 0 0 0 0 0 0 0 0 0 0 0
41562 - 0 0 0 0 0 0 0 0 0 0 0 0
41563 - 0 0 0 0 0 0 0 0 0 0 0 0
41564 - 0 0 0 0 0 0 0 0 0 0 0 0
41565 - 0 0 0 0 0 0 0 0 0 6 6 6
41566 - 14 14 14 18 18 18 22 22 22 22 22 22
41567 - 18 18 18 14 14 14 10 10 10 6 6 6
41568 - 0 0 0 0 0 0 0 0 0 0 0 0
41569 - 0 0 0 0 0 0 0 0 0 0 0 0
41570 - 0 0 0 0 0 0 0 0 0 0 0 0
41571 - 0 0 0 0 0 0 0 0 0 0 0 0
41572 - 0 0 0 0 0 0 0 0 0 0 0 0
41573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41576 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41586 +4 4 4 4 4 4
41587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41590 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41600 +4 4 4 4 4 4
41601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41614 +4 4 4 4 4 4
41615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41617 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41628 +4 4 4 4 4 4
41629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41631 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41642 +4 4 4 4 4 4
41643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41645 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41656 +4 4 4 4 4 4
41657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41659 +4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0
41662 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41666 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41667 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41668 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41670 +4 4 4 4 4 4
41671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41673 +4 4 4 4 4 4 4 4 4 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 2 2 2 0 0 0 3 4 3 26 28 28
41676 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41677 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41680 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41681 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41682 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41683 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41684 +4 4 4 4 4 4
41685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41687 +4 4 4 4 4 4 4 4 4 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 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41690 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41691 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41694 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41695 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41696 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41697 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41698 +4 4 4 4 4 4
41699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41702 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41703 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41704 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41705 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41707 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41708 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41709 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41710 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41711 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41712 +4 4 4 4 4 4
41713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41716 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41717 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41718 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41719 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41720 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41721 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41722 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41723 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41724 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41725 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41726 +4 4 4 4 4 4
41727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41730 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41731 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41732 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41733 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41734 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41735 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41736 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41737 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41738 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41739 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41740 +4 4 4 4 4 4
41741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41743 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41744 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41745 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41746 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41747 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41748 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41749 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41750 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41751 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41752 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41753 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41754 +4 4 4 4 4 4
41755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41757 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41758 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41759 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41760 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41761 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41762 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41763 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41764 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41765 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41766 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41767 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41768 +4 4 4 4 4 4
41769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41771 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41772 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41773 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41774 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41775 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41776 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41777 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41778 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41779 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41780 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41781 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41782 +4 4 4 4 4 4
41783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41785 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41786 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41787 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41788 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41789 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41790 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41791 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41792 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41793 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41794 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41795 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41796 +4 4 4 4 4 4
41797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41798 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41799 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41800 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41801 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41802 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41803 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41804 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41805 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41806 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41807 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41808 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41809 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41810 +4 4 4 4 4 4
41811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41812 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41813 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41814 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41815 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41816 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41817 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41818 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41819 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41820 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41821 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41822 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41823 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41824 +0 0 0 4 4 4
41825 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41826 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41827 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41828 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41829 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41830 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41831 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41832 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41833 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41834 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41835 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41836 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41837 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41838 +2 0 0 0 0 0
41839 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41840 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41841 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41842 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41843 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41844 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41845 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41846 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41847 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41848 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41849 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41850 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41851 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41852 +37 38 37 0 0 0
41853 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41854 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41855 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41856 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41857 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41858 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41859 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41860 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41861 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41862 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41863 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41864 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41865 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41866 +85 115 134 4 0 0
41867 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41868 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41869 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41870 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41871 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41872 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41873 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41874 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41875 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41876 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41877 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41878 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41879 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41880 +60 73 81 4 0 0
41881 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41882 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41883 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41884 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41885 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41886 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41887 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41888 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41889 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41890 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41891 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41892 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41893 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41894 +16 19 21 4 0 0
41895 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41896 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41897 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41898 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41899 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41900 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41901 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41902 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41903 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41904 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41905 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41906 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41907 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41908 +4 0 0 4 3 3
41909 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41910 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41911 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41913 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41914 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41915 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41916 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41917 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41918 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41919 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41920 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41921 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41922 +3 2 2 4 4 4
41923 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41924 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41925 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41926 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41927 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41928 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41929 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41930 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41931 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41932 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41933 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41934 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41935 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41936 +4 4 4 4 4 4
41937 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41938 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41939 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41940 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41941 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41942 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41943 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41944 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41945 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41946 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41947 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41948 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41949 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41950 +4 4 4 4 4 4
41951 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41952 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41953 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41954 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41955 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41956 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41957 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41958 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41959 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41960 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41961 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41962 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41963 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41964 +5 5 5 5 5 5
41965 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41966 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41967 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41968 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41969 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41970 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41971 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41972 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41973 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41974 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41975 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41976 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41977 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41978 +5 5 5 4 4 4
41979 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41980 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41981 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41982 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41983 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41984 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41985 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41986 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41987 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41988 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41989 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41990 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41992 +4 4 4 4 4 4
41993 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41994 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41995 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41996 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41997 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41998 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41999 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42000 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
42001 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
42002 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
42003 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
42004 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
42005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42006 +4 4 4 4 4 4
42007 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
42008 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
42009 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
42010 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
42011 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
42012 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
42013 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
42014 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
42015 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
42016 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
42017 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
42018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42020 +4 4 4 4 4 4
42021 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
42022 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
42023 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
42024 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
42025 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42026 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42027 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42028 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
42029 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
42030 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
42031 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
42032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42034 +4 4 4 4 4 4
42035 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
42036 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
42037 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
42038 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
42039 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42040 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
42041 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
42042 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
42043 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
42044 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
42045 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42048 +4 4 4 4 4 4
42049 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
42050 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
42051 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
42052 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
42053 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42054 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
42055 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
42056 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
42057 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
42058 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
42059 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
42060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42062 +4 4 4 4 4 4
42063 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
42064 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
42065 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
42066 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
42067 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
42068 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
42069 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
42070 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
42071 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
42072 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
42073 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
42074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42076 +4 4 4 4 4 4
42077 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
42078 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
42079 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
42080 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
42081 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
42082 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
42083 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
42084 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
42085 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
42086 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
42087 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42090 +4 4 4 4 4 4
42091 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
42092 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
42093 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
42094 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
42095 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42096 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
42097 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
42098 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
42099 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
42100 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
42101 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42104 +4 4 4 4 4 4
42105 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
42106 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
42107 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
42108 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
42109 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42110 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
42111 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
42112 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
42113 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
42114 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
42115 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42118 +4 4 4 4 4 4
42119 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
42120 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
42121 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
42122 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
42123 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42124 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
42125 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
42126 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
42127 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
42128 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42129 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42132 +4 4 4 4 4 4
42133 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
42134 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
42135 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
42136 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
42137 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
42138 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
42139 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
42140 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
42141 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42142 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42143 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42146 +4 4 4 4 4 4
42147 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
42148 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
42149 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
42150 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
42151 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42152 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
42153 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
42154 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
42155 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42156 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42157 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42160 +4 4 4 4 4 4
42161 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
42162 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
42163 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
42164 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
42165 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
42166 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
42167 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
42168 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
42169 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42170 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42171 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42174 +4 4 4 4 4 4
42175 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
42176 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
42177 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42178 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
42179 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
42180 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
42181 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
42182 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
42183 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
42184 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42185 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42188 +4 4 4 4 4 4
42189 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
42190 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
42191 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
42192 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
42193 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
42194 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
42195 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
42196 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
42197 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42198 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42199 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42202 +4 4 4 4 4 4
42203 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
42204 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
42205 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42206 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
42207 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
42208 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
42209 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
42210 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
42211 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
42212 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42213 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42216 +4 4 4 4 4 4
42217 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
42218 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
42219 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
42220 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
42221 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
42222 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
42223 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
42224 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
42225 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42226 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42227 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42230 +4 4 4 4 4 4
42231 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42232 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
42233 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42234 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
42235 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
42236 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
42237 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
42238 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
42239 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42240 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42241 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42244 +4 4 4 4 4 4
42245 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42246 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
42247 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
42248 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
42249 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
42250 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
42251 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42252 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
42253 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42254 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42255 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42258 +4 4 4 4 4 4
42259 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42260 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
42261 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
42262 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42263 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
42264 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
42265 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42266 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
42267 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42268 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42269 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42272 +4 4 4 4 4 4
42273 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42274 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
42275 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
42276 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
42277 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
42278 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
42279 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
42280 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
42281 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
42282 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42283 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42286 +4 4 4 4 4 4
42287 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42288 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
42289 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
42290 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
42291 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
42292 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
42293 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
42294 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
42295 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
42296 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42297 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42300 +4 4 4 4 4 4
42301 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
42302 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
42303 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
42304 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
42305 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42306 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
42307 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
42308 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
42309 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
42310 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42311 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42314 +4 4 4 4 4 4
42315 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42316 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42317 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42318 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42319 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42320 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42321 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42322 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42323 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42324 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42325 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42328 +4 4 4 4 4 4
42329 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42330 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42331 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42332 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42333 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42334 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42335 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42336 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42337 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42338 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42339 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42342 +4 4 4 4 4 4
42343 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42344 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42345 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42346 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42347 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42348 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42349 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42350 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42351 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42352 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42353 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42356 +4 4 4 4 4 4
42357 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42358 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42359 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42360 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42361 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42362 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42363 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42364 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42365 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42366 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42367 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42370 +4 4 4 4 4 4
42371 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42372 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42373 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42374 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42375 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42376 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42377 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42378 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42379 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42380 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42381 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42384 +4 4 4 4 4 4
42385 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42386 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42387 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42388 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42389 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42390 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42391 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42392 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42393 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42394 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42398 +4 4 4 4 4 4
42399 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42400 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42401 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42402 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42403 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42404 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42405 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42406 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42407 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42408 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42412 +4 4 4 4 4 4
42413 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42414 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42415 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42416 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42417 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42418 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42419 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42420 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42421 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42422 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42426 +4 4 4 4 4 4
42427 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42428 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42429 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42430 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42431 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42432 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42433 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42434 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42435 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42436 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42440 +4 4 4 4 4 4
42441 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42442 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42443 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42444 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42445 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42446 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42447 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42448 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42449 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42454 +4 4 4 4 4 4
42455 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42456 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42457 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42458 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42459 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42460 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42461 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42462 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42463 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42468 +4 4 4 4 4 4
42469 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42470 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42471 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42472 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42473 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42474 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42475 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42476 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42477 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42482 +4 4 4 4 4 4
42483 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42484 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42485 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42486 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42487 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42488 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42489 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42490 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42496 +4 4 4 4 4 4
42497 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42498 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42499 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42500 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42501 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42502 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42503 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42504 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42510 +4 4 4 4 4 4
42511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42512 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42513 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42514 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42515 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42516 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42517 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42518 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42524 +4 4 4 4 4 4
42525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42526 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42527 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42528 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42529 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42530 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42531 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42532 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42538 +4 4 4 4 4 4
42539 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42540 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42541 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42542 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42543 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42544 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42545 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42546 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42552 +4 4 4 4 4 4
42553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42555 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42556 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42557 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42558 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42559 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42560 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42566 +4 4 4 4 4 4
42567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42570 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42571 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42572 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42573 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42580 +4 4 4 4 4 4
42581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42584 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42585 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42586 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42587 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42594 +4 4 4 4 4 4
42595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42598 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42599 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42600 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42601 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42608 +4 4 4 4 4 4
42609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42612 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42613 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42614 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42615 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42622 +4 4 4 4 4 4
42623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42627 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42628 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42629 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42636 +4 4 4 4 4 4
42637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42641 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42642 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42643 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42650 +4 4 4 4 4 4
42651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42655 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42656 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42657 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42664 +4 4 4 4 4 4
42665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42669 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42670 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42678 +4 4 4 4 4 4
42679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42683 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42684 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42692 +4 4 4 4 4 4
42693 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42694 index 38fcfff..0072dcd 100644
42695 --- a/drivers/video/udlfb.c
42696 +++ b/drivers/video/udlfb.c
42697 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42698 dlfb_urb_completion(urb);
42699
42700 error:
42701 - atomic_add(bytes_sent, &dev->bytes_sent);
42702 - atomic_add(bytes_identical, &dev->bytes_identical);
42703 - atomic_add(width*height*2, &dev->bytes_rendered);
42704 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42705 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42706 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42707 end_cycles = get_cycles();
42708 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42709 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42710 >> 10)), /* Kcycles */
42711 &dev->cpu_kcycles_used);
42712
42713 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42714 dlfb_urb_completion(urb);
42715
42716 error:
42717 - atomic_add(bytes_sent, &dev->bytes_sent);
42718 - atomic_add(bytes_identical, &dev->bytes_identical);
42719 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42720 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42721 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42722 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42723 end_cycles = get_cycles();
42724 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42725 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42726 >> 10)), /* Kcycles */
42727 &dev->cpu_kcycles_used);
42728 }
42729 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42730 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42731 struct dlfb_data *dev = fb_info->par;
42732 return snprintf(buf, PAGE_SIZE, "%u\n",
42733 - atomic_read(&dev->bytes_rendered));
42734 + atomic_read_unchecked(&dev->bytes_rendered));
42735 }
42736
42737 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42738 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42739 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42740 struct dlfb_data *dev = fb_info->par;
42741 return snprintf(buf, PAGE_SIZE, "%u\n",
42742 - atomic_read(&dev->bytes_identical));
42743 + atomic_read_unchecked(&dev->bytes_identical));
42744 }
42745
42746 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42747 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42748 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42749 struct dlfb_data *dev = fb_info->par;
42750 return snprintf(buf, PAGE_SIZE, "%u\n",
42751 - atomic_read(&dev->bytes_sent));
42752 + atomic_read_unchecked(&dev->bytes_sent));
42753 }
42754
42755 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42756 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42757 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42758 struct dlfb_data *dev = fb_info->par;
42759 return snprintf(buf, PAGE_SIZE, "%u\n",
42760 - atomic_read(&dev->cpu_kcycles_used));
42761 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42762 }
42763
42764 static ssize_t edid_show(
42765 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42766 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42767 struct dlfb_data *dev = fb_info->par;
42768
42769 - atomic_set(&dev->bytes_rendered, 0);
42770 - atomic_set(&dev->bytes_identical, 0);
42771 - atomic_set(&dev->bytes_sent, 0);
42772 - atomic_set(&dev->cpu_kcycles_used, 0);
42773 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42774 + atomic_set_unchecked(&dev->bytes_identical, 0);
42775 + atomic_set_unchecked(&dev->bytes_sent, 0);
42776 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42777
42778 return count;
42779 }
42780 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42781 index b0e2a42..e2df3ad 100644
42782 --- a/drivers/video/uvesafb.c
42783 +++ b/drivers/video/uvesafb.c
42784 @@ -19,6 +19,7 @@
42785 #include <linux/io.h>
42786 #include <linux/mutex.h>
42787 #include <linux/slab.h>
42788 +#include <linux/moduleloader.h>
42789 #include <video/edid.h>
42790 #include <video/uvesafb.h>
42791 #ifdef CONFIG_X86
42792 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42793 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42794 par->pmi_setpal = par->ypan = 0;
42795 } else {
42796 +
42797 +#ifdef CONFIG_PAX_KERNEXEC
42798 +#ifdef CONFIG_MODULES
42799 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42800 +#endif
42801 + if (!par->pmi_code) {
42802 + par->pmi_setpal = par->ypan = 0;
42803 + return 0;
42804 + }
42805 +#endif
42806 +
42807 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42808 + task->t.regs.edi);
42809 +
42810 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42811 + pax_open_kernel();
42812 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42813 + pax_close_kernel();
42814 +
42815 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42816 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42817 +#else
42818 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42819 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42820 +#endif
42821 +
42822 printk(KERN_INFO "uvesafb: protected mode interface info at "
42823 "%04x:%04x\n",
42824 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42825 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42826 par->ypan = ypan;
42827
42828 if (par->pmi_setpal || par->ypan) {
42829 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42830 if (__supported_pte_mask & _PAGE_NX) {
42831 par->pmi_setpal = par->ypan = 0;
42832 printk(KERN_WARNING "uvesafb: NX protection is actively."
42833 "We have better not to use the PMI.\n");
42834 - } else {
42835 + } else
42836 +#endif
42837 uvesafb_vbe_getpmi(task, par);
42838 - }
42839 }
42840 #else
42841 /* The protected mode interface is not available on non-x86. */
42842 @@ -1836,6 +1860,11 @@ out:
42843 if (par->vbe_modes)
42844 kfree(par->vbe_modes);
42845
42846 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42847 + if (par->pmi_code)
42848 + module_free_exec(NULL, par->pmi_code);
42849 +#endif
42850 +
42851 framebuffer_release(info);
42852 return err;
42853 }
42854 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42855 kfree(par->vbe_state_orig);
42856 if (par->vbe_state_saved)
42857 kfree(par->vbe_state_saved);
42858 +
42859 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42860 + if (par->pmi_code)
42861 + module_free_exec(NULL, par->pmi_code);
42862 +#endif
42863 +
42864 }
42865
42866 framebuffer_release(info);
42867 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42868 index 501b340..86bd4cf 100644
42869 --- a/drivers/video/vesafb.c
42870 +++ b/drivers/video/vesafb.c
42871 @@ -9,6 +9,7 @@
42872 */
42873
42874 #include <linux/module.h>
42875 +#include <linux/moduleloader.h>
42876 #include <linux/kernel.h>
42877 #include <linux/errno.h>
42878 #include <linux/string.h>
42879 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42880 static int vram_total __initdata; /* Set total amount of memory */
42881 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42882 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42883 -static void (*pmi_start)(void) __read_mostly;
42884 -static void (*pmi_pal) (void) __read_mostly;
42885 +static void (*pmi_start)(void) __read_only;
42886 +static void (*pmi_pal) (void) __read_only;
42887 static int depth __read_mostly;
42888 static int vga_compat __read_mostly;
42889 /* --------------------------------------------------------------------- */
42890 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42891 unsigned int size_vmode;
42892 unsigned int size_remap;
42893 unsigned int size_total;
42894 + void *pmi_code = NULL;
42895
42896 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42897 return -ENODEV;
42898 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42899 size_remap = size_total;
42900 vesafb_fix.smem_len = size_remap;
42901
42902 -#ifndef __i386__
42903 - screen_info.vesapm_seg = 0;
42904 -#endif
42905 -
42906 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42907 printk(KERN_WARNING
42908 "vesafb: cannot reserve video memory at 0x%lx\n",
42909 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42910 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42911 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42912
42913 +#ifdef __i386__
42914 +
42915 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42916 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42917 + if (!pmi_code)
42918 +#elif !defined(CONFIG_PAX_KERNEXEC)
42919 + if (0)
42920 +#endif
42921 +
42922 +#endif
42923 + screen_info.vesapm_seg = 0;
42924 +
42925 if (screen_info.vesapm_seg) {
42926 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42927 - screen_info.vesapm_seg,screen_info.vesapm_off);
42928 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42929 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42930 }
42931
42932 if (screen_info.vesapm_seg < 0xc000)
42933 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42934
42935 if (ypan || pmi_setpal) {
42936 unsigned short *pmi_base;
42937 +
42938 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42939 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42940 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42941 +
42942 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42943 + pax_open_kernel();
42944 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42945 +#else
42946 + pmi_code = pmi_base;
42947 +#endif
42948 +
42949 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42950 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42951 +
42952 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42953 + pmi_start = ktva_ktla(pmi_start);
42954 + pmi_pal = ktva_ktla(pmi_pal);
42955 + pax_close_kernel();
42956 +#endif
42957 +
42958 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42959 if (pmi_base[3]) {
42960 printk(KERN_INFO "vesafb: pmi: ports = ");
42961 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42962 info->node, info->fix.id);
42963 return 0;
42964 err:
42965 +
42966 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42967 + module_free_exec(NULL, pmi_code);
42968 +#endif
42969 +
42970 if (info->screen_base)
42971 iounmap(info->screen_base);
42972 framebuffer_release(info);
42973 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42974 index 88714ae..16c2e11 100644
42975 --- a/drivers/video/via/via_clock.h
42976 +++ b/drivers/video/via/via_clock.h
42977 @@ -56,7 +56,7 @@ struct via_clock {
42978
42979 void (*set_engine_pll_state)(u8 state);
42980 void (*set_engine_pll)(struct via_pll_config config);
42981 -};
42982 +} __no_const;
42983
42984
42985 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42986 diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
42987 index c3b3f7f..abd47c7 100644
42988 --- a/drivers/virtio/virtio.c
42989 +++ b/drivers/virtio/virtio.c
42990 @@ -225,8 +225,10 @@ EXPORT_SYMBOL_GPL(register_virtio_device);
42991
42992 void unregister_virtio_device(struct virtio_device *dev)
42993 {
42994 + int index = dev->index; /* save for after device release */
42995 +
42996 device_unregister(&dev->dev);
42997 - ida_simple_remove(&virtio_index_ida, dev->index);
42998 + ida_simple_remove(&virtio_index_ida, index);
42999 }
43000 EXPORT_SYMBOL_GPL(unregister_virtio_device);
43001
43002 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
43003 index 453db0c..604973e 100644
43004 --- a/drivers/virtio/virtio_mmio.c
43005 +++ b/drivers/virtio/virtio_mmio.c
43006 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
43007
43008 resources[0].end = memparse(device, &str) - 1;
43009
43010 - processed = sscanf(str, "@%lli:%u%n:%d%n",
43011 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
43012 &base, &resources[1].start, &consumed,
43013 &vm_cmdline_id, &consumed);
43014
43015 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
43016 index e56c934..fc22f4b 100644
43017 --- a/drivers/xen/xen-pciback/conf_space.h
43018 +++ b/drivers/xen/xen-pciback/conf_space.h
43019 @@ -44,15 +44,15 @@ struct config_field {
43020 struct {
43021 conf_dword_write write;
43022 conf_dword_read read;
43023 - } dw;
43024 + } __no_const dw;
43025 struct {
43026 conf_word_write write;
43027 conf_word_read read;
43028 - } w;
43029 + } __no_const w;
43030 struct {
43031 conf_byte_write write;
43032 conf_byte_read read;
43033 - } b;
43034 + } __no_const b;
43035 } u;
43036 struct list_head list;
43037 };
43038 diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
43039 index 89f7625..ac72702 100644
43040 --- a/drivers/xen/xenbus/xenbus_dev_frontend.c
43041 +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
43042 @@ -458,7 +458,7 @@ static ssize_t xenbus_file_write(struct file *filp,
43043 goto out;
43044
43045 /* Can't write a xenbus message larger we can buffer */
43046 - if ((len + u->len) > sizeof(u->u.buffer)) {
43047 + if (len > sizeof(u->u.buffer) - u->len) {
43048 /* On error, dump existing buffer */
43049 u->len = 0;
43050 rc = -EINVAL;
43051 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
43052 index fef20db..d28b1ab 100644
43053 --- a/drivers/xen/xenfs/xenstored.c
43054 +++ b/drivers/xen/xenfs/xenstored.c
43055 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
43056 static int xsd_kva_open(struct inode *inode, struct file *file)
43057 {
43058 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
43059 +#ifdef CONFIG_GRKERNSEC_HIDESYM
43060 + NULL);
43061 +#else
43062 xen_store_interface);
43063 +#endif
43064 +
43065 if (!file->private_data)
43066 return -ENOMEM;
43067 return 0;
43068 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
43069 index cbf9dbb..35c3af7 100644
43070 --- a/fs/9p/vfs_inode.c
43071 +++ b/fs/9p/vfs_inode.c
43072 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43073 void
43074 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43075 {
43076 - char *s = nd_get_link(nd);
43077 + const char *s = nd_get_link(nd);
43078
43079 p9_debug(P9_DEBUG_VFS, " %s %s\n",
43080 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
43081 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
43082 index 0225742..1cd4732 100644
43083 --- a/fs/Kconfig.binfmt
43084 +++ b/fs/Kconfig.binfmt
43085 @@ -89,7 +89,7 @@ config HAVE_AOUT
43086
43087 config BINFMT_AOUT
43088 tristate "Kernel support for a.out and ECOFF binaries"
43089 - depends on HAVE_AOUT
43090 + depends on HAVE_AOUT && BROKEN
43091 ---help---
43092 A.out (Assembler.OUTput) is a set of formats for libraries and
43093 executables used in the earliest versions of UNIX. Linux used
43094 diff --git a/fs/aio.c b/fs/aio.c
43095 index 71f613c..9d01f1f 100644
43096 --- a/fs/aio.c
43097 +++ b/fs/aio.c
43098 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
43099 size += sizeof(struct io_event) * nr_events;
43100 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
43101
43102 - if (nr_pages < 0)
43103 + if (nr_pages <= 0)
43104 return -EINVAL;
43105
43106 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
43107 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
43108 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43109 {
43110 ssize_t ret;
43111 + struct iovec iovstack;
43112
43113 #ifdef CONFIG_COMPAT
43114 if (compat)
43115 ret = compat_rw_copy_check_uvector(type,
43116 (struct compat_iovec __user *)kiocb->ki_buf,
43117 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43118 + kiocb->ki_nbytes, 1, &iovstack,
43119 &kiocb->ki_iovec);
43120 else
43121 #endif
43122 ret = rw_copy_check_uvector(type,
43123 (struct iovec __user *)kiocb->ki_buf,
43124 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43125 + kiocb->ki_nbytes, 1, &iovstack,
43126 &kiocb->ki_iovec);
43127 if (ret < 0)
43128 goto out;
43129 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43130 if (ret < 0)
43131 goto out;
43132
43133 + if (kiocb->ki_iovec == &iovstack) {
43134 + kiocb->ki_inline_vec = iovstack;
43135 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
43136 + }
43137 kiocb->ki_nr_segs = kiocb->ki_nbytes;
43138 kiocb->ki_cur_seg = 0;
43139 /* ki_nbytes/left now reflect bytes instead of segs */
43140 diff --git a/fs/attr.c b/fs/attr.c
43141 index 29e38a1..2bc037b 100644
43142 --- a/fs/attr.c
43143 +++ b/fs/attr.c
43144 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
43145 unsigned long limit;
43146
43147 limit = rlimit(RLIMIT_FSIZE);
43148 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
43149 if (limit != RLIM_INFINITY && offset > limit)
43150 goto out_sig;
43151 if (offset > inode->i_sb->s_maxbytes)
43152 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
43153 index da8876d..4456166 100644
43154 --- a/fs/autofs4/waitq.c
43155 +++ b/fs/autofs4/waitq.c
43156 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
43157 {
43158 unsigned long sigpipe, flags;
43159 mm_segment_t fs;
43160 - const char *data = (const char *)addr;
43161 + const char __user *data = (const char __force_user *)addr;
43162 ssize_t wr = 0;
43163
43164 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
43165 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
43166 return 1;
43167 }
43168
43169 +#ifdef CONFIG_GRKERNSEC_HIDESYM
43170 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
43171 +#endif
43172 +
43173 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
43174 enum autofs_notify notify)
43175 {
43176 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
43177
43178 /* If this is a direct mount request create a dummy name */
43179 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
43180 +#ifdef CONFIG_GRKERNSEC_HIDESYM
43181 + /* this name does get written to userland via autofs4_write() */
43182 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
43183 +#else
43184 qstr.len = sprintf(name, "%p", dentry);
43185 +#endif
43186 else {
43187 qstr.len = autofs4_getpath(sbi, dentry, &name);
43188 if (!qstr.len) {
43189 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
43190 index cf7f3c6..f61080d 100644
43191 --- a/fs/befs/linuxvfs.c
43192 +++ b/fs/befs/linuxvfs.c
43193 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43194 {
43195 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
43196 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
43197 - char *link = nd_get_link(nd);
43198 + const char *link = nd_get_link(nd);
43199 if (!IS_ERR(link))
43200 kfree(link);
43201 }
43202 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
43203 index d146e18..12d1bd1 100644
43204 --- a/fs/binfmt_aout.c
43205 +++ b/fs/binfmt_aout.c
43206 @@ -16,6 +16,7 @@
43207 #include <linux/string.h>
43208 #include <linux/fs.h>
43209 #include <linux/file.h>
43210 +#include <linux/security.h>
43211 #include <linux/stat.h>
43212 #include <linux/fcntl.h>
43213 #include <linux/ptrace.h>
43214 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
43215 #endif
43216 # define START_STACK(u) ((void __user *)u.start_stack)
43217
43218 + memset(&dump, 0, sizeof(dump));
43219 +
43220 fs = get_fs();
43221 set_fs(KERNEL_DS);
43222 has_dumped = 1;
43223 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
43224
43225 /* If the size of the dump file exceeds the rlimit, then see what would happen
43226 if we wrote the stack, but not the data area. */
43227 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
43228 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
43229 dump.u_dsize = 0;
43230
43231 /* Make sure we have enough room to write the stack and data areas. */
43232 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
43233 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
43234 dump.u_ssize = 0;
43235
43236 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43237 rlim = rlimit(RLIMIT_DATA);
43238 if (rlim >= RLIM_INFINITY)
43239 rlim = ~0;
43240 +
43241 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
43242 if (ex.a_data + ex.a_bss > rlim)
43243 return -ENOMEM;
43244
43245 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43246
43247 install_exec_creds(bprm);
43248
43249 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43250 + current->mm->pax_flags = 0UL;
43251 +#endif
43252 +
43253 +#ifdef CONFIG_PAX_PAGEEXEC
43254 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
43255 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
43256 +
43257 +#ifdef CONFIG_PAX_EMUTRAMP
43258 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
43259 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
43260 +#endif
43261 +
43262 +#ifdef CONFIG_PAX_MPROTECT
43263 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
43264 + current->mm->pax_flags |= MF_PAX_MPROTECT;
43265 +#endif
43266 +
43267 + }
43268 +#endif
43269 +
43270 if (N_MAGIC(ex) == OMAGIC) {
43271 unsigned long text_addr, map_size;
43272 loff_t pos;
43273 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43274 }
43275
43276 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
43277 - PROT_READ | PROT_WRITE | PROT_EXEC,
43278 + PROT_READ | PROT_WRITE,
43279 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
43280 fd_offset + ex.a_text);
43281 if (error != N_DATADDR(ex)) {
43282 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
43283 index 0225fdd..0c0d35d 100644
43284 --- a/fs/binfmt_elf.c
43285 +++ b/fs/binfmt_elf.c
43286 @@ -32,6 +32,7 @@
43287 #include <linux/elf.h>
43288 #include <linux/utsname.h>
43289 #include <linux/coredump.h>
43290 +#include <linux/xattr.h>
43291 #include <asm/uaccess.h>
43292 #include <asm/param.h>
43293 #include <asm/page.h>
43294 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
43295 #define elf_core_dump NULL
43296 #endif
43297
43298 +#ifdef CONFIG_PAX_MPROTECT
43299 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43300 +#endif
43301 +
43302 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43303 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43304 #else
43305 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
43306 .load_binary = load_elf_binary,
43307 .load_shlib = load_elf_library,
43308 .core_dump = elf_core_dump,
43309 +
43310 +#ifdef CONFIG_PAX_MPROTECT
43311 + .handle_mprotect= elf_handle_mprotect,
43312 +#endif
43313 +
43314 .min_coredump = ELF_EXEC_PAGESIZE,
43315 };
43316
43317 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
43318
43319 static int set_brk(unsigned long start, unsigned long end)
43320 {
43321 + unsigned long e = end;
43322 +
43323 start = ELF_PAGEALIGN(start);
43324 end = ELF_PAGEALIGN(end);
43325 if (end > start) {
43326 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
43327 if (BAD_ADDR(addr))
43328 return addr;
43329 }
43330 - current->mm->start_brk = current->mm->brk = end;
43331 + current->mm->start_brk = current->mm->brk = e;
43332 return 0;
43333 }
43334
43335 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43336 elf_addr_t __user *u_rand_bytes;
43337 const char *k_platform = ELF_PLATFORM;
43338 const char *k_base_platform = ELF_BASE_PLATFORM;
43339 - unsigned char k_rand_bytes[16];
43340 + u32 k_rand_bytes[4];
43341 int items;
43342 elf_addr_t *elf_info;
43343 int ei_index = 0;
43344 const struct cred *cred = current_cred();
43345 struct vm_area_struct *vma;
43346 + unsigned long saved_auxv[AT_VECTOR_SIZE];
43347
43348 /*
43349 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43350 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43351 * Generate 16 random bytes for userspace PRNG seeding.
43352 */
43353 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43354 - u_rand_bytes = (elf_addr_t __user *)
43355 - STACK_ALLOC(p, sizeof(k_rand_bytes));
43356 + srandom32(k_rand_bytes[0] ^ random32());
43357 + srandom32(k_rand_bytes[1] ^ random32());
43358 + srandom32(k_rand_bytes[2] ^ random32());
43359 + srandom32(k_rand_bytes[3] ^ random32());
43360 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43361 + u_rand_bytes = (elf_addr_t __user *) p;
43362 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43363 return -EFAULT;
43364
43365 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43366 return -EFAULT;
43367 current->mm->env_end = p;
43368
43369 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43370 +
43371 /* Put the elf_info on the stack in the right place. */
43372 sp = (elf_addr_t __user *)envp + 1;
43373 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43374 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43375 return -EFAULT;
43376 return 0;
43377 }
43378 @@ -373,15 +392,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
43379 an ELF header */
43380
43381 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43382 - struct file *interpreter, unsigned long *interp_map_addr,
43383 - unsigned long no_base)
43384 + struct file *interpreter, unsigned long no_base)
43385 {
43386 struct elf_phdr *elf_phdata;
43387 struct elf_phdr *eppnt;
43388 - unsigned long load_addr = 0;
43389 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43390 int load_addr_set = 0;
43391 unsigned long last_bss = 0, elf_bss = 0;
43392 - unsigned long error = ~0UL;
43393 + unsigned long error = -EINVAL;
43394 unsigned long total_size;
43395 int retval, i, size;
43396
43397 @@ -427,6 +445,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43398 goto out_close;
43399 }
43400
43401 +#ifdef CONFIG_PAX_SEGMEXEC
43402 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43403 + pax_task_size = SEGMEXEC_TASK_SIZE;
43404 +#endif
43405 +
43406 eppnt = elf_phdata;
43407 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43408 if (eppnt->p_type == PT_LOAD) {
43409 @@ -450,8 +473,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43410 map_addr = elf_map(interpreter, load_addr + vaddr,
43411 eppnt, elf_prot, elf_type, total_size);
43412 total_size = 0;
43413 - if (!*interp_map_addr)
43414 - *interp_map_addr = map_addr;
43415 error = map_addr;
43416 if (BAD_ADDR(map_addr))
43417 goto out_close;
43418 @@ -470,8 +491,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43419 k = load_addr + eppnt->p_vaddr;
43420 if (BAD_ADDR(k) ||
43421 eppnt->p_filesz > eppnt->p_memsz ||
43422 - eppnt->p_memsz > TASK_SIZE ||
43423 - TASK_SIZE - eppnt->p_memsz < k) {
43424 + eppnt->p_memsz > pax_task_size ||
43425 + pax_task_size - eppnt->p_memsz < k) {
43426 error = -ENOMEM;
43427 goto out_close;
43428 }
43429 @@ -523,6 +544,315 @@ out:
43430 return error;
43431 }
43432
43433 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43434 +#ifdef CONFIG_PAX_SOFTMODE
43435 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43436 +{
43437 + unsigned long pax_flags = 0UL;
43438 +
43439 +#ifdef CONFIG_PAX_PAGEEXEC
43440 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43441 + pax_flags |= MF_PAX_PAGEEXEC;
43442 +#endif
43443 +
43444 +#ifdef CONFIG_PAX_SEGMEXEC
43445 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43446 + pax_flags |= MF_PAX_SEGMEXEC;
43447 +#endif
43448 +
43449 +#ifdef CONFIG_PAX_EMUTRAMP
43450 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43451 + pax_flags |= MF_PAX_EMUTRAMP;
43452 +#endif
43453 +
43454 +#ifdef CONFIG_PAX_MPROTECT
43455 + if (elf_phdata->p_flags & PF_MPROTECT)
43456 + pax_flags |= MF_PAX_MPROTECT;
43457 +#endif
43458 +
43459 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43460 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43461 + pax_flags |= MF_PAX_RANDMMAP;
43462 +#endif
43463 +
43464 + return pax_flags;
43465 +}
43466 +#endif
43467 +
43468 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43469 +{
43470 + unsigned long pax_flags = 0UL;
43471 +
43472 +#ifdef CONFIG_PAX_PAGEEXEC
43473 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43474 + pax_flags |= MF_PAX_PAGEEXEC;
43475 +#endif
43476 +
43477 +#ifdef CONFIG_PAX_SEGMEXEC
43478 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43479 + pax_flags |= MF_PAX_SEGMEXEC;
43480 +#endif
43481 +
43482 +#ifdef CONFIG_PAX_EMUTRAMP
43483 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43484 + pax_flags |= MF_PAX_EMUTRAMP;
43485 +#endif
43486 +
43487 +#ifdef CONFIG_PAX_MPROTECT
43488 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43489 + pax_flags |= MF_PAX_MPROTECT;
43490 +#endif
43491 +
43492 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43493 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43494 + pax_flags |= MF_PAX_RANDMMAP;
43495 +#endif
43496 +
43497 + return pax_flags;
43498 +}
43499 +#endif
43500 +
43501 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43502 +#ifdef CONFIG_PAX_SOFTMODE
43503 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43504 +{
43505 + unsigned long pax_flags = 0UL;
43506 +
43507 +#ifdef CONFIG_PAX_PAGEEXEC
43508 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43509 + pax_flags |= MF_PAX_PAGEEXEC;
43510 +#endif
43511 +
43512 +#ifdef CONFIG_PAX_SEGMEXEC
43513 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43514 + pax_flags |= MF_PAX_SEGMEXEC;
43515 +#endif
43516 +
43517 +#ifdef CONFIG_PAX_EMUTRAMP
43518 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43519 + pax_flags |= MF_PAX_EMUTRAMP;
43520 +#endif
43521 +
43522 +#ifdef CONFIG_PAX_MPROTECT
43523 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43524 + pax_flags |= MF_PAX_MPROTECT;
43525 +#endif
43526 +
43527 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43528 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43529 + pax_flags |= MF_PAX_RANDMMAP;
43530 +#endif
43531 +
43532 + return pax_flags;
43533 +}
43534 +#endif
43535 +
43536 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43537 +{
43538 + unsigned long pax_flags = 0UL;
43539 +
43540 +#ifdef CONFIG_PAX_PAGEEXEC
43541 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43542 + pax_flags |= MF_PAX_PAGEEXEC;
43543 +#endif
43544 +
43545 +#ifdef CONFIG_PAX_SEGMEXEC
43546 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43547 + pax_flags |= MF_PAX_SEGMEXEC;
43548 +#endif
43549 +
43550 +#ifdef CONFIG_PAX_EMUTRAMP
43551 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43552 + pax_flags |= MF_PAX_EMUTRAMP;
43553 +#endif
43554 +
43555 +#ifdef CONFIG_PAX_MPROTECT
43556 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43557 + pax_flags |= MF_PAX_MPROTECT;
43558 +#endif
43559 +
43560 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43561 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43562 + pax_flags |= MF_PAX_RANDMMAP;
43563 +#endif
43564 +
43565 + return pax_flags;
43566 +}
43567 +#endif
43568 +
43569 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43570 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43571 +{
43572 + unsigned long pax_flags = 0UL;
43573 +
43574 +#ifdef CONFIG_PAX_EI_PAX
43575 +
43576 +#ifdef CONFIG_PAX_PAGEEXEC
43577 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43578 + pax_flags |= MF_PAX_PAGEEXEC;
43579 +#endif
43580 +
43581 +#ifdef CONFIG_PAX_SEGMEXEC
43582 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43583 + pax_flags |= MF_PAX_SEGMEXEC;
43584 +#endif
43585 +
43586 +#ifdef CONFIG_PAX_EMUTRAMP
43587 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43588 + pax_flags |= MF_PAX_EMUTRAMP;
43589 +#endif
43590 +
43591 +#ifdef CONFIG_PAX_MPROTECT
43592 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43593 + pax_flags |= MF_PAX_MPROTECT;
43594 +#endif
43595 +
43596 +#ifdef CONFIG_PAX_ASLR
43597 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43598 + pax_flags |= MF_PAX_RANDMMAP;
43599 +#endif
43600 +
43601 +#else
43602 +
43603 +#ifdef CONFIG_PAX_PAGEEXEC
43604 + pax_flags |= MF_PAX_PAGEEXEC;
43605 +#endif
43606 +
43607 +#ifdef CONFIG_PAX_SEGMEXEC
43608 + pax_flags |= MF_PAX_SEGMEXEC;
43609 +#endif
43610 +
43611 +#ifdef CONFIG_PAX_MPROTECT
43612 + pax_flags |= MF_PAX_MPROTECT;
43613 +#endif
43614 +
43615 +#ifdef CONFIG_PAX_RANDMMAP
43616 + if (randomize_va_space)
43617 + pax_flags |= MF_PAX_RANDMMAP;
43618 +#endif
43619 +
43620 +#endif
43621 +
43622 + return pax_flags;
43623 +}
43624 +
43625 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43626 +{
43627 +
43628 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43629 + unsigned long i;
43630 +
43631 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43632 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43633 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43634 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43635 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43636 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43637 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43638 + return ~0UL;
43639 +
43640 +#ifdef CONFIG_PAX_SOFTMODE
43641 + if (pax_softmode)
43642 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43643 + else
43644 +#endif
43645 +
43646 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43647 + break;
43648 + }
43649 +#endif
43650 +
43651 + return ~0UL;
43652 +}
43653 +
43654 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43655 +{
43656 +
43657 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43658 + ssize_t xattr_size, i;
43659 + unsigned char xattr_value[5];
43660 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43661 +
43662 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43663 + if (xattr_size <= 0 || xattr_size > 5)
43664 + return ~0UL;
43665 +
43666 + for (i = 0; i < xattr_size; i++)
43667 + switch (xattr_value[i]) {
43668 + default:
43669 + return ~0UL;
43670 +
43671 +#define parse_flag(option1, option2, flag) \
43672 + case option1: \
43673 + if (pax_flags_hardmode & MF_PAX_##flag) \
43674 + return ~0UL; \
43675 + pax_flags_hardmode |= MF_PAX_##flag; \
43676 + break; \
43677 + case option2: \
43678 + if (pax_flags_softmode & MF_PAX_##flag) \
43679 + return ~0UL; \
43680 + pax_flags_softmode |= MF_PAX_##flag; \
43681 + break;
43682 +
43683 + parse_flag('p', 'P', PAGEEXEC);
43684 + parse_flag('e', 'E', EMUTRAMP);
43685 + parse_flag('m', 'M', MPROTECT);
43686 + parse_flag('r', 'R', RANDMMAP);
43687 + parse_flag('s', 'S', SEGMEXEC);
43688 +
43689 +#undef parse_flag
43690 + }
43691 +
43692 + if (pax_flags_hardmode & pax_flags_softmode)
43693 + return ~0UL;
43694 +
43695 +#ifdef CONFIG_PAX_SOFTMODE
43696 + if (pax_softmode)
43697 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43698 + else
43699 +#endif
43700 +
43701 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43702 +#else
43703 + return ~0UL;
43704 +#endif
43705 +
43706 +}
43707 +
43708 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43709 +{
43710 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43711 +
43712 + pax_flags = pax_parse_ei_pax(elf_ex);
43713 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43714 + xattr_pax_flags = pax_parse_xattr_pax(file);
43715 +
43716 + if (pt_pax_flags == ~0UL)
43717 + pt_pax_flags = xattr_pax_flags;
43718 + else if (xattr_pax_flags == ~0UL)
43719 + xattr_pax_flags = pt_pax_flags;
43720 + if (pt_pax_flags != xattr_pax_flags)
43721 + return -EINVAL;
43722 + if (pt_pax_flags != ~0UL)
43723 + pax_flags = pt_pax_flags;
43724 +
43725 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43726 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43727 + if ((__supported_pte_mask & _PAGE_NX))
43728 + pax_flags &= ~MF_PAX_SEGMEXEC;
43729 + else
43730 + pax_flags &= ~MF_PAX_PAGEEXEC;
43731 + }
43732 +#endif
43733 +
43734 + if (0 > pax_check_flags(&pax_flags))
43735 + return -EINVAL;
43736 +
43737 + current->mm->pax_flags = pax_flags;
43738 + return 0;
43739 +}
43740 +#endif
43741 +
43742 /*
43743 * These are the functions used to load ELF style executables and shared
43744 * libraries. There is no binary dependent code anywhere else.
43745 @@ -539,6 +869,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43746 {
43747 unsigned int random_variable = 0;
43748
43749 +#ifdef CONFIG_PAX_RANDUSTACK
43750 + if (randomize_va_space)
43751 + return stack_top - current->mm->delta_stack;
43752 +#endif
43753 +
43754 if ((current->flags & PF_RANDOMIZE) &&
43755 !(current->personality & ADDR_NO_RANDOMIZE)) {
43756 random_variable = get_random_int() & STACK_RND_MASK;
43757 @@ -557,7 +892,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43758 unsigned long load_addr = 0, load_bias = 0;
43759 int load_addr_set = 0;
43760 char * elf_interpreter = NULL;
43761 - unsigned long error;
43762 + unsigned long error = 0;
43763 struct elf_phdr *elf_ppnt, *elf_phdata;
43764 unsigned long elf_bss, elf_brk;
43765 int retval, i;
43766 @@ -567,11 +902,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43767 unsigned long start_code, end_code, start_data, end_data;
43768 unsigned long reloc_func_desc __maybe_unused = 0;
43769 int executable_stack = EXSTACK_DEFAULT;
43770 - unsigned long def_flags = 0;
43771 struct {
43772 struct elfhdr elf_ex;
43773 struct elfhdr interp_elf_ex;
43774 } *loc;
43775 + unsigned long pax_task_size = TASK_SIZE;
43776
43777 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43778 if (!loc) {
43779 @@ -707,11 +1042,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43780 goto out_free_dentry;
43781
43782 /* OK, This is the point of no return */
43783 - current->mm->def_flags = def_flags;
43784 +
43785 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43786 + current->mm->pax_flags = 0UL;
43787 +#endif
43788 +
43789 +#ifdef CONFIG_PAX_DLRESOLVE
43790 + current->mm->call_dl_resolve = 0UL;
43791 +#endif
43792 +
43793 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43794 + current->mm->call_syscall = 0UL;
43795 +#endif
43796 +
43797 +#ifdef CONFIG_PAX_ASLR
43798 + current->mm->delta_mmap = 0UL;
43799 + current->mm->delta_stack = 0UL;
43800 +#endif
43801 +
43802 + current->mm->def_flags = 0;
43803 +
43804 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43805 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43806 + send_sig(SIGKILL, current, 0);
43807 + goto out_free_dentry;
43808 + }
43809 +#endif
43810 +
43811 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43812 + pax_set_initial_flags(bprm);
43813 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43814 + if (pax_set_initial_flags_func)
43815 + (pax_set_initial_flags_func)(bprm);
43816 +#endif
43817 +
43818 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43819 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43820 + current->mm->context.user_cs_limit = PAGE_SIZE;
43821 + current->mm->def_flags |= VM_PAGEEXEC;
43822 + }
43823 +#endif
43824 +
43825 +#ifdef CONFIG_PAX_SEGMEXEC
43826 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43827 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43828 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43829 + pax_task_size = SEGMEXEC_TASK_SIZE;
43830 + current->mm->def_flags |= VM_NOHUGEPAGE;
43831 + }
43832 +#endif
43833 +
43834 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43835 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43836 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43837 + put_cpu();
43838 + }
43839 +#endif
43840
43841 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43842 may depend on the personality. */
43843 SET_PERSONALITY(loc->elf_ex);
43844 +
43845 +#ifdef CONFIG_PAX_ASLR
43846 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43847 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43848 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43849 + }
43850 +#endif
43851 +
43852 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43853 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43854 + executable_stack = EXSTACK_DISABLE_X;
43855 + current->personality &= ~READ_IMPLIES_EXEC;
43856 + } else
43857 +#endif
43858 +
43859 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43860 current->personality |= READ_IMPLIES_EXEC;
43861
43862 @@ -802,6 +1207,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43863 #else
43864 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43865 #endif
43866 +
43867 +#ifdef CONFIG_PAX_RANDMMAP
43868 + /* PaX: randomize base address at the default exe base if requested */
43869 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43870 +#ifdef CONFIG_SPARC64
43871 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43872 +#else
43873 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43874 +#endif
43875 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43876 + elf_flags |= MAP_FIXED;
43877 + }
43878 +#endif
43879 +
43880 }
43881
43882 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43883 @@ -834,9 +1253,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43884 * allowed task size. Note that p_filesz must always be
43885 * <= p_memsz so it is only necessary to check p_memsz.
43886 */
43887 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43888 - elf_ppnt->p_memsz > TASK_SIZE ||
43889 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43890 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43891 + elf_ppnt->p_memsz > pax_task_size ||
43892 + pax_task_size - elf_ppnt->p_memsz < k) {
43893 /* set_brk can never work. Avoid overflows. */
43894 send_sig(SIGKILL, current, 0);
43895 retval = -EINVAL;
43896 @@ -875,17 +1294,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43897 goto out_free_dentry;
43898 }
43899 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43900 - send_sig(SIGSEGV, current, 0);
43901 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43902 - goto out_free_dentry;
43903 + /*
43904 + * This bss-zeroing can fail if the ELF
43905 + * file specifies odd protections. So
43906 + * we don't check the return value
43907 + */
43908 }
43909
43910 +#ifdef CONFIG_PAX_RANDMMAP
43911 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43912 + unsigned long start, size;
43913 +
43914 + start = ELF_PAGEALIGN(elf_brk);
43915 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43916 + down_read(&current->mm->mmap_sem);
43917 + retval = -ENOMEM;
43918 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43919 + unsigned long prot = PROT_NONE;
43920 +
43921 + up_read(&current->mm->mmap_sem);
43922 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43923 +// if (current->personality & ADDR_NO_RANDOMIZE)
43924 +// prot = PROT_READ;
43925 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43926 + retval = IS_ERR_VALUE(start) ? start : 0;
43927 + } else
43928 + up_read(&current->mm->mmap_sem);
43929 + if (retval == 0)
43930 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43931 + if (retval < 0) {
43932 + send_sig(SIGKILL, current, 0);
43933 + goto out_free_dentry;
43934 + }
43935 + }
43936 +#endif
43937 +
43938 if (elf_interpreter) {
43939 - unsigned long uninitialized_var(interp_map_addr);
43940 -
43941 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43942 interpreter,
43943 - &interp_map_addr,
43944 load_bias);
43945 if (!IS_ERR((void *)elf_entry)) {
43946 /*
43947 @@ -1107,7 +1553,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43948 * Decide what to dump of a segment, part, all or none.
43949 */
43950 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43951 - unsigned long mm_flags)
43952 + unsigned long mm_flags, long signr)
43953 {
43954 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43955
43956 @@ -1144,7 +1590,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43957 if (vma->vm_file == NULL)
43958 return 0;
43959
43960 - if (FILTER(MAPPED_PRIVATE))
43961 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43962 goto whole;
43963
43964 /*
43965 @@ -1366,9 +1812,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43966 {
43967 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43968 int i = 0;
43969 - do
43970 + do {
43971 i += 2;
43972 - while (auxv[i - 2] != AT_NULL);
43973 + } while (auxv[i - 2] != AT_NULL);
43974 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43975 }
43976
43977 @@ -1879,14 +2325,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43978 }
43979
43980 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43981 - unsigned long mm_flags)
43982 + struct coredump_params *cprm)
43983 {
43984 struct vm_area_struct *vma;
43985 size_t size = 0;
43986
43987 for (vma = first_vma(current, gate_vma); vma != NULL;
43988 vma = next_vma(vma, gate_vma))
43989 - size += vma_dump_size(vma, mm_flags);
43990 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43991 return size;
43992 }
43993
43994 @@ -1980,7 +2426,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43995
43996 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43997
43998 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43999 + offset += elf_core_vma_data_size(gate_vma, cprm);
44000 offset += elf_core_extra_data_size();
44001 e_shoff = offset;
44002
44003 @@ -1994,10 +2440,12 @@ static int elf_core_dump(struct coredump_params *cprm)
44004 offset = dataoff;
44005
44006 size += sizeof(*elf);
44007 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44008 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
44009 goto end_coredump;
44010
44011 size += sizeof(*phdr4note);
44012 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44013 if (size > cprm->limit
44014 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
44015 goto end_coredump;
44016 @@ -2011,7 +2459,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44017 phdr.p_offset = offset;
44018 phdr.p_vaddr = vma->vm_start;
44019 phdr.p_paddr = 0;
44020 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
44021 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
44022 phdr.p_memsz = vma->vm_end - vma->vm_start;
44023 offset += phdr.p_filesz;
44024 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
44025 @@ -2022,6 +2470,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44026 phdr.p_align = ELF_EXEC_PAGESIZE;
44027
44028 size += sizeof(phdr);
44029 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44030 if (size > cprm->limit
44031 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
44032 goto end_coredump;
44033 @@ -2046,7 +2495,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44034 unsigned long addr;
44035 unsigned long end;
44036
44037 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
44038 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
44039
44040 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
44041 struct page *page;
44042 @@ -2055,6 +2504,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44043 page = get_dump_page(addr);
44044 if (page) {
44045 void *kaddr = kmap(page);
44046 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
44047 stop = ((size += PAGE_SIZE) > cprm->limit) ||
44048 !dump_write(cprm->file, kaddr,
44049 PAGE_SIZE);
44050 @@ -2072,6 +2522,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44051
44052 if (e_phnum == PN_XNUM) {
44053 size += sizeof(*shdr4extnum);
44054 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44055 if (size > cprm->limit
44056 || !dump_write(cprm->file, shdr4extnum,
44057 sizeof(*shdr4extnum)))
44058 @@ -2092,6 +2543,97 @@ out:
44059
44060 #endif /* CONFIG_ELF_CORE */
44061
44062 +#ifdef CONFIG_PAX_MPROTECT
44063 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
44064 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
44065 + * we'll remove VM_MAYWRITE for good on RELRO segments.
44066 + *
44067 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
44068 + * basis because we want to allow the common case and not the special ones.
44069 + */
44070 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
44071 +{
44072 + struct elfhdr elf_h;
44073 + struct elf_phdr elf_p;
44074 + unsigned long i;
44075 + unsigned long oldflags;
44076 + bool is_textrel_rw, is_textrel_rx, is_relro;
44077 +
44078 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
44079 + return;
44080 +
44081 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
44082 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
44083 +
44084 +#ifdef CONFIG_PAX_ELFRELOCS
44085 + /* possible TEXTREL */
44086 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
44087 + 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);
44088 +#else
44089 + is_textrel_rw = false;
44090 + is_textrel_rx = false;
44091 +#endif
44092 +
44093 + /* possible RELRO */
44094 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
44095 +
44096 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
44097 + return;
44098 +
44099 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
44100 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
44101 +
44102 +#ifdef CONFIG_PAX_ETEXECRELOCS
44103 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44104 +#else
44105 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
44106 +#endif
44107 +
44108 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44109 + !elf_check_arch(&elf_h) ||
44110 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
44111 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
44112 + return;
44113 +
44114 + for (i = 0UL; i < elf_h.e_phnum; i++) {
44115 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
44116 + return;
44117 + switch (elf_p.p_type) {
44118 + case PT_DYNAMIC:
44119 + if (!is_textrel_rw && !is_textrel_rx)
44120 + continue;
44121 + i = 0UL;
44122 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
44123 + elf_dyn dyn;
44124 +
44125 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
44126 + return;
44127 + if (dyn.d_tag == DT_NULL)
44128 + return;
44129 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
44130 + gr_log_textrel(vma);
44131 + if (is_textrel_rw)
44132 + vma->vm_flags |= VM_MAYWRITE;
44133 + else
44134 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
44135 + vma->vm_flags &= ~VM_MAYWRITE;
44136 + return;
44137 + }
44138 + i++;
44139 + }
44140 + return;
44141 +
44142 + case PT_GNU_RELRO:
44143 + if (!is_relro)
44144 + continue;
44145 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
44146 + vma->vm_flags &= ~VM_MAYWRITE;
44147 + return;
44148 + }
44149 + }
44150 +}
44151 +#endif
44152 +
44153 static int __init init_elf_binfmt(void)
44154 {
44155 register_binfmt(&elf_format);
44156 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
44157 index 178cb70..8972997 100644
44158 --- a/fs/binfmt_flat.c
44159 +++ b/fs/binfmt_flat.c
44160 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
44161 realdatastart = (unsigned long) -ENOMEM;
44162 printk("Unable to allocate RAM for process data, errno %d\n",
44163 (int)-realdatastart);
44164 + down_write(&current->mm->mmap_sem);
44165 vm_munmap(textpos, text_len);
44166 + up_write(&current->mm->mmap_sem);
44167 ret = realdatastart;
44168 goto err;
44169 }
44170 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
44171 }
44172 if (IS_ERR_VALUE(result)) {
44173 printk("Unable to read data+bss, errno %d\n", (int)-result);
44174 + down_write(&current->mm->mmap_sem);
44175 vm_munmap(textpos, text_len);
44176 vm_munmap(realdatastart, len);
44177 + up_write(&current->mm->mmap_sem);
44178 ret = result;
44179 goto err;
44180 }
44181 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
44182 }
44183 if (IS_ERR_VALUE(result)) {
44184 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
44185 + down_write(&current->mm->mmap_sem);
44186 vm_munmap(textpos, text_len + data_len + extra +
44187 MAX_SHARED_LIBS * sizeof(unsigned long));
44188 + up_write(&current->mm->mmap_sem);
44189 ret = result;
44190 goto err;
44191 }
44192 diff --git a/fs/bio.c b/fs/bio.c
44193 index 71072ab..439851b 100644
44194 --- a/fs/bio.c
44195 +++ b/fs/bio.c
44196 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
44197 /*
44198 * Overflow, abort
44199 */
44200 - if (end < start)
44201 + if (end < start || end - start > INT_MAX - nr_pages)
44202 return ERR_PTR(-EINVAL);
44203
44204 nr_pages += end - start;
44205 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
44206 /*
44207 * Overflow, abort
44208 */
44209 - if (end < start)
44210 + if (end < start || end - start > INT_MAX - nr_pages)
44211 return ERR_PTR(-EINVAL);
44212
44213 nr_pages += end - start;
44214 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
44215 const int read = bio_data_dir(bio) == READ;
44216 struct bio_map_data *bmd = bio->bi_private;
44217 int i;
44218 - char *p = bmd->sgvecs[0].iov_base;
44219 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
44220
44221 __bio_for_each_segment(bvec, bio, i, 0) {
44222 char *addr = page_address(bvec->bv_page);
44223 diff --git a/fs/block_dev.c b/fs/block_dev.c
44224 index 38e721b..7a9c5bc 100644
44225 --- a/fs/block_dev.c
44226 +++ b/fs/block_dev.c
44227 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
44228 else if (bdev->bd_contains == bdev)
44229 return true; /* is a whole device which isn't held */
44230
44231 - else if (whole->bd_holder == bd_may_claim)
44232 + else if (whole->bd_holder == (void *)bd_may_claim)
44233 return true; /* is a partition of a device that is being partitioned */
44234 else if (whole->bd_holder != NULL)
44235 return false; /* is a partition of a held device */
44236 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
44237 index 9197e2e..7f731f8 100644
44238 --- a/fs/btrfs/check-integrity.c
44239 +++ b/fs/btrfs/check-integrity.c
44240 @@ -155,7 +155,7 @@ struct btrfsic_block {
44241 union {
44242 bio_end_io_t *bio;
44243 bh_end_io_t *bh;
44244 - } orig_bio_bh_end_io;
44245 + } __no_const orig_bio_bh_end_io;
44246 int submit_bio_bh_rw;
44247 u64 flush_gen; /* only valid if !never_written */
44248 };
44249 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
44250 index 6d183f6..f47cc7a 100644
44251 --- a/fs/btrfs/ctree.c
44252 +++ b/fs/btrfs/ctree.c
44253 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
44254 free_extent_buffer(buf);
44255 add_root_to_dirty_list(root);
44256 } else {
44257 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
44258 - parent_start = parent->start;
44259 - else
44260 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
44261 + if (parent)
44262 + parent_start = parent->start;
44263 + else
44264 + parent_start = 0;
44265 + } else
44266 parent_start = 0;
44267
44268 WARN_ON(trans->transid != btrfs_header_generation(parent));
44269 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
44270 index ec154f9..bf617a7 100644
44271 --- a/fs/btrfs/inode.c
44272 +++ b/fs/btrfs/inode.c
44273 @@ -7126,7 +7126,7 @@ fail:
44274 return -ENOMEM;
44275 }
44276
44277 -static int btrfs_getattr(struct vfsmount *mnt,
44278 +int btrfs_getattr(struct vfsmount *mnt,
44279 struct dentry *dentry, struct kstat *stat)
44280 {
44281 struct inode *inode = dentry->d_inode;
44282 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
44283 return 0;
44284 }
44285
44286 +EXPORT_SYMBOL(btrfs_getattr);
44287 +
44288 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
44289 +{
44290 + return BTRFS_I(inode)->root->anon_dev;
44291 +}
44292 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
44293 +
44294 /*
44295 * If a file is moved, it will inherit the cow and compression flags of the new
44296 * directory.
44297 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
44298 index 9df50fa..6cd20d0 100644
44299 --- a/fs/btrfs/ioctl.c
44300 +++ b/fs/btrfs/ioctl.c
44301 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44302 for (i = 0; i < num_types; i++) {
44303 struct btrfs_space_info *tmp;
44304
44305 + /* Don't copy in more than we allocated */
44306 if (!slot_count)
44307 break;
44308
44309 + slot_count--;
44310 +
44311 info = NULL;
44312 rcu_read_lock();
44313 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44314 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44315 memcpy(dest, &space, sizeof(space));
44316 dest++;
44317 space_args.total_spaces++;
44318 - slot_count--;
44319 }
44320 - if (!slot_count)
44321 - break;
44322 }
44323 up_read(&info->groups_sem);
44324 }
44325 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
44326 index 4da0865..01c4778 100644
44327 --- a/fs/btrfs/relocation.c
44328 +++ b/fs/btrfs/relocation.c
44329 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
44330 }
44331 spin_unlock(&rc->reloc_root_tree.lock);
44332
44333 - BUG_ON((struct btrfs_root *)node->data != root);
44334 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
44335
44336 if (!del) {
44337 spin_lock(&rc->reloc_root_tree.lock);
44338 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
44339 index 622f469..e8d2d55 100644
44340 --- a/fs/cachefiles/bind.c
44341 +++ b/fs/cachefiles/bind.c
44342 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
44343 args);
44344
44345 /* start by checking things over */
44346 - ASSERT(cache->fstop_percent >= 0 &&
44347 - cache->fstop_percent < cache->fcull_percent &&
44348 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
44349 cache->fcull_percent < cache->frun_percent &&
44350 cache->frun_percent < 100);
44351
44352 - ASSERT(cache->bstop_percent >= 0 &&
44353 - cache->bstop_percent < cache->bcull_percent &&
44354 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
44355 cache->bcull_percent < cache->brun_percent &&
44356 cache->brun_percent < 100);
44357
44358 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
44359 index 0a1467b..6a53245 100644
44360 --- a/fs/cachefiles/daemon.c
44361 +++ b/fs/cachefiles/daemon.c
44362 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
44363 if (n > buflen)
44364 return -EMSGSIZE;
44365
44366 - if (copy_to_user(_buffer, buffer, n) != 0)
44367 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44368 return -EFAULT;
44369
44370 return n;
44371 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
44372 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44373 return -EIO;
44374
44375 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44376 + if (datalen > PAGE_SIZE - 1)
44377 return -EOPNOTSUPP;
44378
44379 /* drag the command string into the kernel so we can parse it */
44380 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
44381 if (args[0] != '%' || args[1] != '\0')
44382 return -EINVAL;
44383
44384 - if (fstop < 0 || fstop >= cache->fcull_percent)
44385 + if (fstop >= cache->fcull_percent)
44386 return cachefiles_daemon_range_error(cache, args);
44387
44388 cache->fstop_percent = fstop;
44389 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44390 if (args[0] != '%' || args[1] != '\0')
44391 return -EINVAL;
44392
44393 - if (bstop < 0 || bstop >= cache->bcull_percent)
44394 + if (bstop >= cache->bcull_percent)
44395 return cachefiles_daemon_range_error(cache, args);
44396
44397 cache->bstop_percent = bstop;
44398 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44399 index bd6bc1b..b627b53 100644
44400 --- a/fs/cachefiles/internal.h
44401 +++ b/fs/cachefiles/internal.h
44402 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44403 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44404 struct rb_root active_nodes; /* active nodes (can't be culled) */
44405 rwlock_t active_lock; /* lock for active_nodes */
44406 - atomic_t gravecounter; /* graveyard uniquifier */
44407 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44408 unsigned frun_percent; /* when to stop culling (% files) */
44409 unsigned fcull_percent; /* when to start culling (% files) */
44410 unsigned fstop_percent; /* when to stop allocating (% files) */
44411 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44412 * proc.c
44413 */
44414 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44415 -extern atomic_t cachefiles_lookup_histogram[HZ];
44416 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44417 -extern atomic_t cachefiles_create_histogram[HZ];
44418 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44419 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44420 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44421
44422 extern int __init cachefiles_proc_init(void);
44423 extern void cachefiles_proc_cleanup(void);
44424 static inline
44425 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44426 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44427 {
44428 unsigned long jif = jiffies - start_jif;
44429 if (jif >= HZ)
44430 jif = HZ - 1;
44431 - atomic_inc(&histogram[jif]);
44432 + atomic_inc_unchecked(&histogram[jif]);
44433 }
44434
44435 #else
44436 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44437 index b0b5f7c..039bb26 100644
44438 --- a/fs/cachefiles/namei.c
44439 +++ b/fs/cachefiles/namei.c
44440 @@ -318,7 +318,7 @@ try_again:
44441 /* first step is to make up a grave dentry in the graveyard */
44442 sprintf(nbuffer, "%08x%08x",
44443 (uint32_t) get_seconds(),
44444 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44445 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44446
44447 /* do the multiway lock magic */
44448 trap = lock_rename(cache->graveyard, dir);
44449 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44450 index eccd339..4c1d995 100644
44451 --- a/fs/cachefiles/proc.c
44452 +++ b/fs/cachefiles/proc.c
44453 @@ -14,9 +14,9 @@
44454 #include <linux/seq_file.h>
44455 #include "internal.h"
44456
44457 -atomic_t cachefiles_lookup_histogram[HZ];
44458 -atomic_t cachefiles_mkdir_histogram[HZ];
44459 -atomic_t cachefiles_create_histogram[HZ];
44460 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44461 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44462 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44463
44464 /*
44465 * display the latency histogram
44466 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44467 return 0;
44468 default:
44469 index = (unsigned long) v - 3;
44470 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44471 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44472 - z = atomic_read(&cachefiles_create_histogram[index]);
44473 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44474 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44475 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44476 if (x == 0 && y == 0 && z == 0)
44477 return 0;
44478
44479 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44480 index c994691..2a1537f 100644
44481 --- a/fs/cachefiles/rdwr.c
44482 +++ b/fs/cachefiles/rdwr.c
44483 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44484 old_fs = get_fs();
44485 set_fs(KERNEL_DS);
44486 ret = file->f_op->write(
44487 - file, (const void __user *) data, len, &pos);
44488 + file, (const void __force_user *) data, len, &pos);
44489 set_fs(old_fs);
44490 kunmap(page);
44491 if (ret != len)
44492 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44493 index e5b7731..b9c59fb 100644
44494 --- a/fs/ceph/dir.c
44495 +++ b/fs/ceph/dir.c
44496 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44497 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44498 struct ceph_mds_client *mdsc = fsc->mdsc;
44499 unsigned frag = fpos_frag(filp->f_pos);
44500 - int off = fpos_off(filp->f_pos);
44501 + unsigned int off = fpos_off(filp->f_pos);
44502 int err;
44503 u32 ftype;
44504 struct ceph_mds_reply_info_parsed *rinfo;
44505 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44506 index d9ea6ed..1e6c8ac 100644
44507 --- a/fs/cifs/cifs_debug.c
44508 +++ b/fs/cifs/cifs_debug.c
44509 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44510
44511 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44512 #ifdef CONFIG_CIFS_STATS2
44513 - atomic_set(&totBufAllocCount, 0);
44514 - atomic_set(&totSmBufAllocCount, 0);
44515 + atomic_set_unchecked(&totBufAllocCount, 0);
44516 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44517 #endif /* CONFIG_CIFS_STATS2 */
44518 spin_lock(&cifs_tcp_ses_lock);
44519 list_for_each(tmp1, &cifs_tcp_ses_list) {
44520 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44521 tcon = list_entry(tmp3,
44522 struct cifs_tcon,
44523 tcon_list);
44524 - atomic_set(&tcon->num_smbs_sent, 0);
44525 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44526 if (server->ops->clear_stats)
44527 server->ops->clear_stats(tcon);
44528 }
44529 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44530 smBufAllocCount.counter, cifs_min_small);
44531 #ifdef CONFIG_CIFS_STATS2
44532 seq_printf(m, "Total Large %d Small %d Allocations\n",
44533 - atomic_read(&totBufAllocCount),
44534 - atomic_read(&totSmBufAllocCount));
44535 + atomic_read_unchecked(&totBufAllocCount),
44536 + atomic_read_unchecked(&totSmBufAllocCount));
44537 #endif /* CONFIG_CIFS_STATS2 */
44538
44539 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44540 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44541 if (tcon->need_reconnect)
44542 seq_puts(m, "\tDISCONNECTED ");
44543 seq_printf(m, "\nSMBs: %d",
44544 - atomic_read(&tcon->num_smbs_sent));
44545 + atomic_read_unchecked(&tcon->num_smbs_sent));
44546 if (server->ops->print_stats)
44547 server->ops->print_stats(m, tcon);
44548 }
44549 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44550 index db8a404..c712e2e 100644
44551 --- a/fs/cifs/cifsfs.c
44552 +++ b/fs/cifs/cifsfs.c
44553 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44554 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44555 cifs_req_cachep = kmem_cache_create("cifs_request",
44556 CIFSMaxBufSize + max_hdr_size, 0,
44557 - SLAB_HWCACHE_ALIGN, NULL);
44558 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44559 if (cifs_req_cachep == NULL)
44560 return -ENOMEM;
44561
44562 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44563 efficient to alloc 1 per page off the slab compared to 17K (5page)
44564 alloc of large cifs buffers even when page debugging is on */
44565 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44566 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44567 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44568 NULL);
44569 if (cifs_sm_req_cachep == NULL) {
44570 mempool_destroy(cifs_req_poolp);
44571 @@ -1115,8 +1115,8 @@ init_cifs(void)
44572 atomic_set(&bufAllocCount, 0);
44573 atomic_set(&smBufAllocCount, 0);
44574 #ifdef CONFIG_CIFS_STATS2
44575 - atomic_set(&totBufAllocCount, 0);
44576 - atomic_set(&totSmBufAllocCount, 0);
44577 + atomic_set_unchecked(&totBufAllocCount, 0);
44578 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44579 #endif /* CONFIG_CIFS_STATS2 */
44580
44581 atomic_set(&midCount, 0);
44582 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44583 index 977dc0e..ba48ab9 100644
44584 --- a/fs/cifs/cifsglob.h
44585 +++ b/fs/cifs/cifsglob.h
44586 @@ -590,35 +590,35 @@ struct cifs_tcon {
44587 __u16 Flags; /* optional support bits */
44588 enum statusEnum tidStatus;
44589 #ifdef CONFIG_CIFS_STATS
44590 - atomic_t num_smbs_sent;
44591 + atomic_unchecked_t num_smbs_sent;
44592 union {
44593 struct {
44594 - atomic_t num_writes;
44595 - atomic_t num_reads;
44596 - atomic_t num_flushes;
44597 - atomic_t num_oplock_brks;
44598 - atomic_t num_opens;
44599 - atomic_t num_closes;
44600 - atomic_t num_deletes;
44601 - atomic_t num_mkdirs;
44602 - atomic_t num_posixopens;
44603 - atomic_t num_posixmkdirs;
44604 - atomic_t num_rmdirs;
44605 - atomic_t num_renames;
44606 - atomic_t num_t2renames;
44607 - atomic_t num_ffirst;
44608 - atomic_t num_fnext;
44609 - atomic_t num_fclose;
44610 - atomic_t num_hardlinks;
44611 - atomic_t num_symlinks;
44612 - atomic_t num_locks;
44613 - atomic_t num_acl_get;
44614 - atomic_t num_acl_set;
44615 + atomic_unchecked_t num_writes;
44616 + atomic_unchecked_t num_reads;
44617 + atomic_unchecked_t num_flushes;
44618 + atomic_unchecked_t num_oplock_brks;
44619 + atomic_unchecked_t num_opens;
44620 + atomic_unchecked_t num_closes;
44621 + atomic_unchecked_t num_deletes;
44622 + atomic_unchecked_t num_mkdirs;
44623 + atomic_unchecked_t num_posixopens;
44624 + atomic_unchecked_t num_posixmkdirs;
44625 + atomic_unchecked_t num_rmdirs;
44626 + atomic_unchecked_t num_renames;
44627 + atomic_unchecked_t num_t2renames;
44628 + atomic_unchecked_t num_ffirst;
44629 + atomic_unchecked_t num_fnext;
44630 + atomic_unchecked_t num_fclose;
44631 + atomic_unchecked_t num_hardlinks;
44632 + atomic_unchecked_t num_symlinks;
44633 + atomic_unchecked_t num_locks;
44634 + atomic_unchecked_t num_acl_get;
44635 + atomic_unchecked_t num_acl_set;
44636 } cifs_stats;
44637 #ifdef CONFIG_CIFS_SMB2
44638 struct {
44639 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44640 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44641 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44642 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44643 } smb2_stats;
44644 #endif /* CONFIG_CIFS_SMB2 */
44645 } stats;
44646 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44647 }
44648
44649 #ifdef CONFIG_CIFS_STATS
44650 -#define cifs_stats_inc atomic_inc
44651 +#define cifs_stats_inc atomic_inc_unchecked
44652
44653 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44654 unsigned int bytes)
44655 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44656 /* Various Debug counters */
44657 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44658 #ifdef CONFIG_CIFS_STATS2
44659 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44660 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44661 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44662 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44663 #endif
44664 GLOBAL_EXTERN atomic_t smBufAllocCount;
44665 GLOBAL_EXTERN atomic_t midCount;
44666 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44667 index e6ce3b1..adc21fd 100644
44668 --- a/fs/cifs/link.c
44669 +++ b/fs/cifs/link.c
44670 @@ -602,7 +602,7 @@ symlink_exit:
44671
44672 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44673 {
44674 - char *p = nd_get_link(nd);
44675 + const char *p = nd_get_link(nd);
44676 if (!IS_ERR(p))
44677 kfree(p);
44678 }
44679 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44680 index ce41fee..ac0d27a 100644
44681 --- a/fs/cifs/misc.c
44682 +++ b/fs/cifs/misc.c
44683 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44684 memset(ret_buf, 0, buf_size + 3);
44685 atomic_inc(&bufAllocCount);
44686 #ifdef CONFIG_CIFS_STATS2
44687 - atomic_inc(&totBufAllocCount);
44688 + atomic_inc_unchecked(&totBufAllocCount);
44689 #endif /* CONFIG_CIFS_STATS2 */
44690 }
44691
44692 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44693 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44694 atomic_inc(&smBufAllocCount);
44695 #ifdef CONFIG_CIFS_STATS2
44696 - atomic_inc(&totSmBufAllocCount);
44697 + atomic_inc_unchecked(&totSmBufAllocCount);
44698 #endif /* CONFIG_CIFS_STATS2 */
44699
44700 }
44701 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44702 index 3129ac7..cc4a948 100644
44703 --- a/fs/cifs/smb1ops.c
44704 +++ b/fs/cifs/smb1ops.c
44705 @@ -524,27 +524,27 @@ static void
44706 cifs_clear_stats(struct cifs_tcon *tcon)
44707 {
44708 #ifdef CONFIG_CIFS_STATS
44709 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44710 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44711 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44712 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44713 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44714 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44715 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44716 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44717 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44718 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44719 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44720 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44721 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44722 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44723 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44724 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44725 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44726 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44727 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44728 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44729 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44730 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44731 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44732 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44733 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44734 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44735 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44736 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44737 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44738 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44739 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44740 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44741 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44742 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44743 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44744 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44745 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44746 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44747 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44748 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44749 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44750 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44751 #endif
44752 }
44753
44754 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44755 {
44756 #ifdef CONFIG_CIFS_STATS
44757 seq_printf(m, " Oplocks breaks: %d",
44758 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44759 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44760 seq_printf(m, "\nReads: %d Bytes: %llu",
44761 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44762 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44763 (long long)(tcon->bytes_read));
44764 seq_printf(m, "\nWrites: %d Bytes: %llu",
44765 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44766 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44767 (long long)(tcon->bytes_written));
44768 seq_printf(m, "\nFlushes: %d",
44769 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44770 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44771 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44772 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44773 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44774 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44775 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44776 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44777 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44778 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44779 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44780 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44781 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44782 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44783 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44784 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44785 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44786 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44787 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44788 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44789 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44790 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44791 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44792 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44793 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44794 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44795 seq_printf(m, "\nRenames: %d T2 Renames %d",
44796 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44797 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44798 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44799 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44800 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44801 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44802 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44803 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44804 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44805 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44806 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44807 #endif
44808 }
44809
44810 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44811 index 826209b..fa460f4 100644
44812 --- a/fs/cifs/smb2ops.c
44813 +++ b/fs/cifs/smb2ops.c
44814 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44815 #ifdef CONFIG_CIFS_STATS
44816 int i;
44817 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44818 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44819 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44820 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44821 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44822 }
44823 #endif
44824 }
44825 @@ -229,66 +229,66 @@ static void
44826 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44827 {
44828 #ifdef CONFIG_CIFS_STATS
44829 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44830 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44831 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44832 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44833 seq_printf(m, "\nNegotiates: %d sent %d failed",
44834 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44835 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44836 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44837 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44838 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44839 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44840 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44841 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44842 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44843 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44844 seq_printf(m, "\nLogoffs: %d sent %d failed",
44845 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44846 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44847 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44848 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44849 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44850 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44851 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44852 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44853 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44854 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44855 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44856 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44857 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44858 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44859 seq_printf(m, "\nCreates: %d sent %d failed",
44860 - atomic_read(&sent[SMB2_CREATE_HE]),
44861 - atomic_read(&failed[SMB2_CREATE_HE]));
44862 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44863 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44864 seq_printf(m, "\nCloses: %d sent %d failed",
44865 - atomic_read(&sent[SMB2_CLOSE_HE]),
44866 - atomic_read(&failed[SMB2_CLOSE_HE]));
44867 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44868 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44869 seq_printf(m, "\nFlushes: %d sent %d failed",
44870 - atomic_read(&sent[SMB2_FLUSH_HE]),
44871 - atomic_read(&failed[SMB2_FLUSH_HE]));
44872 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44873 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44874 seq_printf(m, "\nReads: %d sent %d failed",
44875 - atomic_read(&sent[SMB2_READ_HE]),
44876 - atomic_read(&failed[SMB2_READ_HE]));
44877 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44878 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44879 seq_printf(m, "\nWrites: %d sent %d failed",
44880 - atomic_read(&sent[SMB2_WRITE_HE]),
44881 - atomic_read(&failed[SMB2_WRITE_HE]));
44882 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44883 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44884 seq_printf(m, "\nLocks: %d sent %d failed",
44885 - atomic_read(&sent[SMB2_LOCK_HE]),
44886 - atomic_read(&failed[SMB2_LOCK_HE]));
44887 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44888 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44889 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44890 - atomic_read(&sent[SMB2_IOCTL_HE]),
44891 - atomic_read(&failed[SMB2_IOCTL_HE]));
44892 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44893 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44894 seq_printf(m, "\nCancels: %d sent %d failed",
44895 - atomic_read(&sent[SMB2_CANCEL_HE]),
44896 - atomic_read(&failed[SMB2_CANCEL_HE]));
44897 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44898 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44899 seq_printf(m, "\nEchos: %d sent %d failed",
44900 - atomic_read(&sent[SMB2_ECHO_HE]),
44901 - atomic_read(&failed[SMB2_ECHO_HE]));
44902 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44903 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44904 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44905 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44906 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44907 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44908 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44909 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44910 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44911 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44912 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44913 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44914 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44915 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44916 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44917 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44918 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44919 seq_printf(m, "\nSetInfos: %d sent %d failed",
44920 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44921 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44922 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44923 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44924 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44925 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44926 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44927 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44928 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44929 #endif
44930 }
44931
44932 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44933 index 958ae0e..505c9d0 100644
44934 --- a/fs/coda/cache.c
44935 +++ b/fs/coda/cache.c
44936 @@ -24,7 +24,7 @@
44937 #include "coda_linux.h"
44938 #include "coda_cache.h"
44939
44940 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44941 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44942
44943 /* replace or extend an acl cache hit */
44944 void coda_cache_enter(struct inode *inode, int mask)
44945 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44946 struct coda_inode_info *cii = ITOC(inode);
44947
44948 spin_lock(&cii->c_lock);
44949 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44950 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44951 if (cii->c_uid != current_fsuid()) {
44952 cii->c_uid = current_fsuid();
44953 cii->c_cached_perm = mask;
44954 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44955 {
44956 struct coda_inode_info *cii = ITOC(inode);
44957 spin_lock(&cii->c_lock);
44958 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44959 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44960 spin_unlock(&cii->c_lock);
44961 }
44962
44963 /* remove all acl caches */
44964 void coda_cache_clear_all(struct super_block *sb)
44965 {
44966 - atomic_inc(&permission_epoch);
44967 + atomic_inc_unchecked(&permission_epoch);
44968 }
44969
44970
44971 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44972 spin_lock(&cii->c_lock);
44973 hit = (mask & cii->c_cached_perm) == mask &&
44974 cii->c_uid == current_fsuid() &&
44975 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44976 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44977 spin_unlock(&cii->c_lock);
44978
44979 return hit;
44980 diff --git a/fs/compat.c b/fs/compat.c
44981 index 1bdb350..9f28287 100644
44982 --- a/fs/compat.c
44983 +++ b/fs/compat.c
44984 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44985
44986 set_fs(KERNEL_DS);
44987 /* The __user pointer cast is valid because of the set_fs() */
44988 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44989 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44990 set_fs(oldfs);
44991 /* truncating is ok because it's a user address */
44992 if (!ret)
44993 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44994 goto out;
44995
44996 ret = -EINVAL;
44997 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44998 + if (nr_segs > UIO_MAXIOV)
44999 goto out;
45000 if (nr_segs > fast_segs) {
45001 ret = -ENOMEM;
45002 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
45003
45004 struct compat_readdir_callback {
45005 struct compat_old_linux_dirent __user *dirent;
45006 + struct file * file;
45007 int result;
45008 };
45009
45010 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
45011 buf->result = -EOVERFLOW;
45012 return -EOVERFLOW;
45013 }
45014 +
45015 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45016 + return 0;
45017 +
45018 buf->result++;
45019 dirent = buf->dirent;
45020 if (!access_ok(VERIFY_WRITE, dirent,
45021 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
45022
45023 buf.result = 0;
45024 buf.dirent = dirent;
45025 + buf.file = file;
45026
45027 error = vfs_readdir(file, compat_fillonedir, &buf);
45028 if (buf.result)
45029 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
45030 struct compat_getdents_callback {
45031 struct compat_linux_dirent __user *current_dir;
45032 struct compat_linux_dirent __user *previous;
45033 + struct file * file;
45034 int count;
45035 int error;
45036 };
45037 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
45038 buf->error = -EOVERFLOW;
45039 return -EOVERFLOW;
45040 }
45041 +
45042 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45043 + return 0;
45044 +
45045 dirent = buf->previous;
45046 if (dirent) {
45047 if (__put_user(offset, &dirent->d_off))
45048 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
45049 buf.previous = NULL;
45050 buf.count = count;
45051 buf.error = 0;
45052 + buf.file = file;
45053
45054 error = vfs_readdir(file, compat_filldir, &buf);
45055 if (error >= 0)
45056 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
45057 struct compat_getdents_callback64 {
45058 struct linux_dirent64 __user *current_dir;
45059 struct linux_dirent64 __user *previous;
45060 + struct file * file;
45061 int count;
45062 int error;
45063 };
45064 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
45065 buf->error = -EINVAL; /* only used if we fail.. */
45066 if (reclen > buf->count)
45067 return -EINVAL;
45068 +
45069 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45070 + return 0;
45071 +
45072 dirent = buf->previous;
45073
45074 if (dirent) {
45075 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
45076 buf.previous = NULL;
45077 buf.count = count;
45078 buf.error = 0;
45079 + buf.file = file;
45080
45081 error = vfs_readdir(file, compat_filldir64, &buf);
45082 if (error >= 0)
45083 error = buf.error;
45084 lastdirent = buf.previous;
45085 if (lastdirent) {
45086 - typeof(lastdirent->d_off) d_off = file->f_pos;
45087 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
45088 if (__put_user_unaligned(d_off, &lastdirent->d_off))
45089 error = -EFAULT;
45090 else
45091 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
45092 index 112e45a..b59845b 100644
45093 --- a/fs/compat_binfmt_elf.c
45094 +++ b/fs/compat_binfmt_elf.c
45095 @@ -30,11 +30,13 @@
45096 #undef elf_phdr
45097 #undef elf_shdr
45098 #undef elf_note
45099 +#undef elf_dyn
45100 #undef elf_addr_t
45101 #define elfhdr elf32_hdr
45102 #define elf_phdr elf32_phdr
45103 #define elf_shdr elf32_shdr
45104 #define elf_note elf32_note
45105 +#define elf_dyn Elf32_Dyn
45106 #define elf_addr_t Elf32_Addr
45107
45108 /*
45109 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
45110 index 5d2069f..75d31d4 100644
45111 --- a/fs/compat_ioctl.c
45112 +++ b/fs/compat_ioctl.c
45113 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
45114 return -EFAULT;
45115 if (__get_user(udata, &ss32->iomem_base))
45116 return -EFAULT;
45117 - ss.iomem_base = compat_ptr(udata);
45118 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
45119 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
45120 __get_user(ss.port_high, &ss32->port_high))
45121 return -EFAULT;
45122 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
45123 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
45124 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
45125 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
45126 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
45127 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
45128 return -EFAULT;
45129
45130 return ioctl_preallocate(file, p);
45131 @@ -1612,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
45132 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
45133 {
45134 unsigned int a, b;
45135 - a = *(unsigned int *)p;
45136 - b = *(unsigned int *)q;
45137 + a = *(const unsigned int *)p;
45138 + b = *(const unsigned int *)q;
45139 if (a > b)
45140 return 1;
45141 if (a < b)
45142 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
45143 index 7414ae2..d98ad6d 100644
45144 --- a/fs/configfs/dir.c
45145 +++ b/fs/configfs/dir.c
45146 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
45147 }
45148 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
45149 struct configfs_dirent *next;
45150 - const char * name;
45151 + const unsigned char * name;
45152 + char d_name[sizeof(next->s_dentry->d_iname)];
45153 int len;
45154 struct inode *inode = NULL;
45155
45156 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
45157 continue;
45158
45159 name = configfs_get_name(next);
45160 - len = strlen(name);
45161 + if (next->s_dentry && name == next->s_dentry->d_iname) {
45162 + len = next->s_dentry->d_name.len;
45163 + memcpy(d_name, name, len);
45164 + name = d_name;
45165 + } else
45166 + len = strlen(name);
45167
45168 /*
45169 * We'll have a dentry and an inode for
45170 diff --git a/fs/dcache.c b/fs/dcache.c
45171 index 693f95b..95f1223 100644
45172 --- a/fs/dcache.c
45173 +++ b/fs/dcache.c
45174 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
45175 mempages -= reserve;
45176
45177 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
45178 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
45179 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
45180
45181 dcache_init();
45182 inode_init();
45183 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
45184 index 4733eab..71ef6fa 100644
45185 --- a/fs/debugfs/inode.c
45186 +++ b/fs/debugfs/inode.c
45187 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
45188 */
45189 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
45190 {
45191 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
45192 + return __create_file(name, S_IFDIR | S_IRWXU,
45193 +#else
45194 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
45195 +#endif
45196 parent, NULL, NULL);
45197 }
45198 EXPORT_SYMBOL_GPL(debugfs_create_dir);
45199 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
45200 index cc7709e..7e7211f 100644
45201 --- a/fs/ecryptfs/inode.c
45202 +++ b/fs/ecryptfs/inode.c
45203 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
45204 old_fs = get_fs();
45205 set_fs(get_ds());
45206 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
45207 - (char __user *)lower_buf,
45208 + (char __force_user *)lower_buf,
45209 PATH_MAX);
45210 set_fs(old_fs);
45211 if (rc < 0)
45212 @@ -706,7 +706,7 @@ out:
45213 static void
45214 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
45215 {
45216 - char *buf = nd_get_link(nd);
45217 + const char *buf = nd_get_link(nd);
45218 if (!IS_ERR(buf)) {
45219 /* Free the char* */
45220 kfree(buf);
45221 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
45222 index 412e6ed..4292d22 100644
45223 --- a/fs/ecryptfs/miscdev.c
45224 +++ b/fs/ecryptfs/miscdev.c
45225 @@ -315,7 +315,7 @@ check_list:
45226 goto out_unlock_msg_ctx;
45227 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
45228 if (msg_ctx->msg) {
45229 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
45230 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
45231 goto out_unlock_msg_ctx;
45232 i += packet_length_size;
45233 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
45234 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
45235 index b2a34a1..162fa69 100644
45236 --- a/fs/ecryptfs/read_write.c
45237 +++ b/fs/ecryptfs/read_write.c
45238 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
45239 return -EIO;
45240 fs_save = get_fs();
45241 set_fs(get_ds());
45242 - rc = vfs_write(lower_file, data, size, &offset);
45243 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
45244 set_fs(fs_save);
45245 mark_inode_dirty_sync(ecryptfs_inode);
45246 return rc;
45247 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
45248 return -EIO;
45249 fs_save = get_fs();
45250 set_fs(get_ds());
45251 - rc = vfs_read(lower_file, data, size, &offset);
45252 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
45253 set_fs(fs_save);
45254 return rc;
45255 }
45256 diff --git a/fs/exec.c b/fs/exec.c
45257 index fab2c6d..6a13dff 100644
45258 --- a/fs/exec.c
45259 +++ b/fs/exec.c
45260 @@ -55,6 +55,15 @@
45261 #include <linux/pipe_fs_i.h>
45262 #include <linux/oom.h>
45263 #include <linux/compat.h>
45264 +#include <linux/random.h>
45265 +#include <linux/seq_file.h>
45266 +
45267 +#ifdef CONFIG_PAX_REFCOUNT
45268 +#include <linux/kallsyms.h>
45269 +#include <linux/kdebug.h>
45270 +#endif
45271 +
45272 +#include <trace/events/fs.h>
45273
45274 #include <asm/uaccess.h>
45275 #include <asm/mmu_context.h>
45276 @@ -66,6 +75,18 @@
45277
45278 #include <trace/events/sched.h>
45279
45280 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45281 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
45282 +{
45283 + pr_warn_once("PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
45284 +}
45285 +#endif
45286 +
45287 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45288 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45289 +EXPORT_SYMBOL(pax_set_initial_flags_func);
45290 +#endif
45291 +
45292 int core_uses_pid;
45293 char core_pattern[CORENAME_MAX_SIZE] = "core";
45294 unsigned int core_pipe_limit;
45295 @@ -75,7 +96,7 @@ struct core_name {
45296 char *corename;
45297 int used, size;
45298 };
45299 -static atomic_t call_count = ATOMIC_INIT(1);
45300 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45301
45302 /* The maximal length of core_pattern is also specified in sysctl.c */
45303
45304 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45305 int write)
45306 {
45307 struct page *page;
45308 - int ret;
45309
45310 -#ifdef CONFIG_STACK_GROWSUP
45311 - if (write) {
45312 - ret = expand_downwards(bprm->vma, pos);
45313 - if (ret < 0)
45314 - return NULL;
45315 - }
45316 -#endif
45317 - ret = get_user_pages(current, bprm->mm, pos,
45318 - 1, write, 1, &page, NULL);
45319 - if (ret <= 0)
45320 + if (0 > expand_downwards(bprm->vma, pos))
45321 + return NULL;
45322 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45323 return NULL;
45324
45325 if (write) {
45326 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45327 if (size <= ARG_MAX)
45328 return page;
45329
45330 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45331 + // only allow 512KB for argv+env on suid/sgid binaries
45332 + // to prevent easy ASLR exhaustion
45333 + if (((bprm->cred->euid != current_euid()) ||
45334 + (bprm->cred->egid != current_egid())) &&
45335 + (size > (512 * 1024))) {
45336 + put_page(page);
45337 + return NULL;
45338 + }
45339 +#endif
45340 +
45341 /*
45342 * Limit to 1/4-th the stack size for the argv+env strings.
45343 * This ensures that:
45344 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45345 vma->vm_end = STACK_TOP_MAX;
45346 vma->vm_start = vma->vm_end - PAGE_SIZE;
45347 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45348 +
45349 +#ifdef CONFIG_PAX_SEGMEXEC
45350 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45351 +#endif
45352 +
45353 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45354 INIT_LIST_HEAD(&vma->anon_vma_chain);
45355
45356 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45357 mm->stack_vm = mm->total_vm = 1;
45358 up_write(&mm->mmap_sem);
45359 bprm->p = vma->vm_end - sizeof(void *);
45360 +
45361 +#ifdef CONFIG_PAX_RANDUSTACK
45362 + if (randomize_va_space)
45363 + bprm->p ^= random32() & ~PAGE_MASK;
45364 +#endif
45365 +
45366 return 0;
45367 err:
45368 up_write(&mm->mmap_sem);
45369 @@ -395,19 +430,7 @@ err:
45370 return err;
45371 }
45372
45373 -struct user_arg_ptr {
45374 -#ifdef CONFIG_COMPAT
45375 - bool is_compat;
45376 -#endif
45377 - union {
45378 - const char __user *const __user *native;
45379 -#ifdef CONFIG_COMPAT
45380 - compat_uptr_t __user *compat;
45381 -#endif
45382 - } ptr;
45383 -};
45384 -
45385 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45386 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45387 {
45388 const char __user *native;
45389
45390 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45391 compat_uptr_t compat;
45392
45393 if (get_user(compat, argv.ptr.compat + nr))
45394 - return ERR_PTR(-EFAULT);
45395 + return (const char __force_user *)ERR_PTR(-EFAULT);
45396
45397 return compat_ptr(compat);
45398 }
45399 #endif
45400
45401 if (get_user(native, argv.ptr.native + nr))
45402 - return ERR_PTR(-EFAULT);
45403 + return (const char __force_user *)ERR_PTR(-EFAULT);
45404
45405 return native;
45406 }
45407 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
45408 if (!p)
45409 break;
45410
45411 - if (IS_ERR(p))
45412 + if (IS_ERR((const char __force_kernel *)p))
45413 return -EFAULT;
45414
45415 if (i++ >= max)
45416 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45417
45418 ret = -EFAULT;
45419 str = get_user_arg_ptr(argv, argc);
45420 - if (IS_ERR(str))
45421 + if (IS_ERR((const char __force_kernel *)str))
45422 goto out;
45423
45424 len = strnlen_user(str, MAX_ARG_STRLEN);
45425 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45426 int r;
45427 mm_segment_t oldfs = get_fs();
45428 struct user_arg_ptr argv = {
45429 - .ptr.native = (const char __user *const __user *)__argv,
45430 + .ptr.native = (const char __force_user *const __force_user *)__argv,
45431 };
45432
45433 set_fs(KERNEL_DS);
45434 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45435 unsigned long new_end = old_end - shift;
45436 struct mmu_gather tlb;
45437
45438 - BUG_ON(new_start > new_end);
45439 + if (new_start >= new_end || new_start < mmap_min_addr)
45440 + return -ENOMEM;
45441
45442 /*
45443 * ensure there are no vmas between where we want to go
45444 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45445 if (vma != find_vma(mm, new_start))
45446 return -EFAULT;
45447
45448 +#ifdef CONFIG_PAX_SEGMEXEC
45449 + BUG_ON(pax_find_mirror_vma(vma));
45450 +#endif
45451 +
45452 /*
45453 * cover the whole range: [new_start, old_end)
45454 */
45455 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45456 stack_top = arch_align_stack(stack_top);
45457 stack_top = PAGE_ALIGN(stack_top);
45458
45459 - if (unlikely(stack_top < mmap_min_addr) ||
45460 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45461 - return -ENOMEM;
45462 -
45463 stack_shift = vma->vm_end - stack_top;
45464
45465 bprm->p -= stack_shift;
45466 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45467 bprm->exec -= stack_shift;
45468
45469 down_write(&mm->mmap_sem);
45470 +
45471 + /* Move stack pages down in memory. */
45472 + if (stack_shift) {
45473 + ret = shift_arg_pages(vma, stack_shift);
45474 + if (ret)
45475 + goto out_unlock;
45476 + }
45477 +
45478 vm_flags = VM_STACK_FLAGS;
45479
45480 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45481 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45482 + vm_flags &= ~VM_EXEC;
45483 +
45484 +#ifdef CONFIG_PAX_MPROTECT
45485 + if (mm->pax_flags & MF_PAX_MPROTECT)
45486 + vm_flags &= ~VM_MAYEXEC;
45487 +#endif
45488 +
45489 + }
45490 +#endif
45491 +
45492 /*
45493 * Adjust stack execute permissions; explicitly enable for
45494 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45495 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45496 goto out_unlock;
45497 BUG_ON(prev != vma);
45498
45499 - /* Move stack pages down in memory. */
45500 - if (stack_shift) {
45501 - ret = shift_arg_pages(vma, stack_shift);
45502 - if (ret)
45503 - goto out_unlock;
45504 - }
45505 -
45506 /* mprotect_fixup is overkill to remove the temporary stack flags */
45507 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45508
45509 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45510
45511 fsnotify_open(file);
45512
45513 + trace_open_exec(name);
45514 +
45515 err = deny_write_access(file);
45516 if (err)
45517 goto exit;
45518 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45519 old_fs = get_fs();
45520 set_fs(get_ds());
45521 /* The cast to a user pointer is valid due to the set_fs() */
45522 - result = vfs_read(file, (void __user *)addr, count, &pos);
45523 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45524 set_fs(old_fs);
45525 return result;
45526 }
45527 @@ -1258,7 +1297,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45528 }
45529 rcu_read_unlock();
45530
45531 - if (p->fs->users > n_fs) {
45532 + if (atomic_read(&p->fs->users) > n_fs) {
45533 bprm->unsafe |= LSM_UNSAFE_SHARE;
45534 } else {
45535 res = -EAGAIN;
45536 @@ -1461,6 +1500,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45537
45538 EXPORT_SYMBOL(search_binary_handler);
45539
45540 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45541 +static DEFINE_PER_CPU(u64, exec_counter);
45542 +static int __init init_exec_counters(void)
45543 +{
45544 + unsigned int cpu;
45545 +
45546 + for_each_possible_cpu(cpu) {
45547 + per_cpu(exec_counter, cpu) = (u64)cpu;
45548 + }
45549 +
45550 + return 0;
45551 +}
45552 +early_initcall(init_exec_counters);
45553 +static inline void increment_exec_counter(void)
45554 +{
45555 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45556 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45557 +}
45558 +#else
45559 +static inline void increment_exec_counter(void) {}
45560 +#endif
45561 +
45562 /*
45563 * sys_execve() executes a new program.
45564 */
45565 @@ -1469,6 +1530,11 @@ static int do_execve_common(const char *filename,
45566 struct user_arg_ptr envp,
45567 struct pt_regs *regs)
45568 {
45569 +#ifdef CONFIG_GRKERNSEC
45570 + struct file *old_exec_file;
45571 + struct acl_subject_label *old_acl;
45572 + struct rlimit old_rlim[RLIM_NLIMITS];
45573 +#endif
45574 struct linux_binprm *bprm;
45575 struct file *file;
45576 struct files_struct *displaced;
45577 @@ -1476,6 +1542,8 @@ static int do_execve_common(const char *filename,
45578 int retval;
45579 const struct cred *cred = current_cred();
45580
45581 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45582 +
45583 /*
45584 * We move the actual failure in case of RLIMIT_NPROC excess from
45585 * set*uid() to execve() because too many poorly written programs
45586 @@ -1516,12 +1584,27 @@ static int do_execve_common(const char *filename,
45587 if (IS_ERR(file))
45588 goto out_unmark;
45589
45590 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45591 + retval = -EPERM;
45592 + goto out_file;
45593 + }
45594 +
45595 sched_exec();
45596
45597 bprm->file = file;
45598 bprm->filename = filename;
45599 bprm->interp = filename;
45600
45601 + if (gr_process_user_ban()) {
45602 + retval = -EPERM;
45603 + goto out_file;
45604 + }
45605 +
45606 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45607 + retval = -EACCES;
45608 + goto out_file;
45609 + }
45610 +
45611 retval = bprm_mm_init(bprm);
45612 if (retval)
45613 goto out_file;
45614 @@ -1538,24 +1621,65 @@ static int do_execve_common(const char *filename,
45615 if (retval < 0)
45616 goto out;
45617
45618 +#ifdef CONFIG_GRKERNSEC
45619 + old_acl = current->acl;
45620 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45621 + old_exec_file = current->exec_file;
45622 + get_file(file);
45623 + current->exec_file = file;
45624 +#endif
45625 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45626 + /* limit suid stack to 8MB
45627 + we saved the old limits above and will restore them if this exec fails
45628 + */
45629 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45630 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45631 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45632 +#endif
45633 +
45634 + if (!gr_tpe_allow(file)) {
45635 + retval = -EACCES;
45636 + goto out_fail;
45637 + }
45638 +
45639 + if (gr_check_crash_exec(file)) {
45640 + retval = -EACCES;
45641 + goto out_fail;
45642 + }
45643 +
45644 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45645 + bprm->unsafe);
45646 + if (retval < 0)
45647 + goto out_fail;
45648 +
45649 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45650 if (retval < 0)
45651 - goto out;
45652 + goto out_fail;
45653
45654 bprm->exec = bprm->p;
45655 retval = copy_strings(bprm->envc, envp, bprm);
45656 if (retval < 0)
45657 - goto out;
45658 + goto out_fail;
45659
45660 retval = copy_strings(bprm->argc, argv, bprm);
45661 if (retval < 0)
45662 - goto out;
45663 + goto out_fail;
45664 +
45665 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45666 +
45667 + gr_handle_exec_args(bprm, argv);
45668
45669 retval = search_binary_handler(bprm,regs);
45670 if (retval < 0)
45671 - goto out;
45672 + goto out_fail;
45673 +#ifdef CONFIG_GRKERNSEC
45674 + if (old_exec_file)
45675 + fput(old_exec_file);
45676 +#endif
45677
45678 /* execve succeeded */
45679 +
45680 + increment_exec_counter();
45681 current->fs->in_exec = 0;
45682 current->in_execve = 0;
45683 acct_update_integrals(current);
45684 @@ -1564,6 +1688,14 @@ static int do_execve_common(const char *filename,
45685 put_files_struct(displaced);
45686 return retval;
45687
45688 +out_fail:
45689 +#ifdef CONFIG_GRKERNSEC
45690 + current->acl = old_acl;
45691 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45692 + fput(current->exec_file);
45693 + current->exec_file = old_exec_file;
45694 +#endif
45695 +
45696 out:
45697 if (bprm->mm) {
45698 acct_arg_size(bprm, 0);
45699 @@ -1637,7 +1769,7 @@ static int expand_corename(struct core_name *cn)
45700 {
45701 char *old_corename = cn->corename;
45702
45703 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45704 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45705 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45706
45707 if (!cn->corename) {
45708 @@ -1734,7 +1866,7 @@ static int format_corename(struct core_name *cn, long signr)
45709 int pid_in_pattern = 0;
45710 int err = 0;
45711
45712 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45713 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45714 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45715 cn->used = 0;
45716
45717 @@ -1831,6 +1963,250 @@ out:
45718 return ispipe;
45719 }
45720
45721 +int pax_check_flags(unsigned long *flags)
45722 +{
45723 + int retval = 0;
45724 +
45725 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45726 + if (*flags & MF_PAX_SEGMEXEC)
45727 + {
45728 + *flags &= ~MF_PAX_SEGMEXEC;
45729 + retval = -EINVAL;
45730 + }
45731 +#endif
45732 +
45733 + if ((*flags & MF_PAX_PAGEEXEC)
45734 +
45735 +#ifdef CONFIG_PAX_PAGEEXEC
45736 + && (*flags & MF_PAX_SEGMEXEC)
45737 +#endif
45738 +
45739 + )
45740 + {
45741 + *flags &= ~MF_PAX_PAGEEXEC;
45742 + retval = -EINVAL;
45743 + }
45744 +
45745 + if ((*flags & MF_PAX_MPROTECT)
45746 +
45747 +#ifdef CONFIG_PAX_MPROTECT
45748 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45749 +#endif
45750 +
45751 + )
45752 + {
45753 + *flags &= ~MF_PAX_MPROTECT;
45754 + retval = -EINVAL;
45755 + }
45756 +
45757 + if ((*flags & MF_PAX_EMUTRAMP)
45758 +
45759 +#ifdef CONFIG_PAX_EMUTRAMP
45760 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45761 +#endif
45762 +
45763 + )
45764 + {
45765 + *flags &= ~MF_PAX_EMUTRAMP;
45766 + retval = -EINVAL;
45767 + }
45768 +
45769 + return retval;
45770 +}
45771 +
45772 +EXPORT_SYMBOL(pax_check_flags);
45773 +
45774 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45775 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45776 +{
45777 + struct task_struct *tsk = current;
45778 + struct mm_struct *mm = current->mm;
45779 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45780 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45781 + char *path_exec = NULL;
45782 + char *path_fault = NULL;
45783 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45784 +
45785 + if (buffer_exec && buffer_fault) {
45786 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45787 +
45788 + down_read(&mm->mmap_sem);
45789 + vma = mm->mmap;
45790 + while (vma && (!vma_exec || !vma_fault)) {
45791 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45792 + vma_exec = vma;
45793 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45794 + vma_fault = vma;
45795 + vma = vma->vm_next;
45796 + }
45797 + if (vma_exec) {
45798 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45799 + if (IS_ERR(path_exec))
45800 + path_exec = "<path too long>";
45801 + else {
45802 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45803 + if (path_exec) {
45804 + *path_exec = 0;
45805 + path_exec = buffer_exec;
45806 + } else
45807 + path_exec = "<path too long>";
45808 + }
45809 + }
45810 + if (vma_fault) {
45811 + start = vma_fault->vm_start;
45812 + end = vma_fault->vm_end;
45813 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45814 + if (vma_fault->vm_file) {
45815 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45816 + if (IS_ERR(path_fault))
45817 + path_fault = "<path too long>";
45818 + else {
45819 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45820 + if (path_fault) {
45821 + *path_fault = 0;
45822 + path_fault = buffer_fault;
45823 + } else
45824 + path_fault = "<path too long>";
45825 + }
45826 + } else
45827 + path_fault = "<anonymous mapping>";
45828 + }
45829 + up_read(&mm->mmap_sem);
45830 + }
45831 + if (tsk->signal->curr_ip)
45832 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45833 + else
45834 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45835 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45836 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45837 + task_uid(tsk), task_euid(tsk), pc, sp);
45838 + free_page((unsigned long)buffer_exec);
45839 + free_page((unsigned long)buffer_fault);
45840 + pax_report_insns(regs, pc, sp);
45841 + do_coredump(SIGKILL, SIGKILL, regs);
45842 +}
45843 +#endif
45844 +
45845 +#ifdef CONFIG_PAX_REFCOUNT
45846 +void pax_report_refcount_overflow(struct pt_regs *regs)
45847 +{
45848 + if (current->signal->curr_ip)
45849 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45850 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45851 + else
45852 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45853 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45854 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45855 + show_regs(regs);
45856 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45857 +}
45858 +#endif
45859 +
45860 +#ifdef CONFIG_PAX_USERCOPY
45861 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45862 +static noinline int check_stack_object(const void *obj, unsigned long len)
45863 +{
45864 + const void * const stack = task_stack_page(current);
45865 + const void * const stackend = stack + THREAD_SIZE;
45866 +
45867 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45868 + const void *frame = NULL;
45869 + const void *oldframe;
45870 +#endif
45871 +
45872 + if (obj + len < obj)
45873 + return -1;
45874 +
45875 + if (obj + len <= stack || stackend <= obj)
45876 + return 0;
45877 +
45878 + if (obj < stack || stackend < obj + len)
45879 + return -1;
45880 +
45881 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45882 + oldframe = __builtin_frame_address(1);
45883 + if (oldframe)
45884 + frame = __builtin_frame_address(2);
45885 + /*
45886 + low ----------------------------------------------> high
45887 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45888 + ^----------------^
45889 + allow copies only within here
45890 + */
45891 + while (stack <= frame && frame < stackend) {
45892 + /* if obj + len extends past the last frame, this
45893 + check won't pass and the next frame will be 0,
45894 + causing us to bail out and correctly report
45895 + the copy as invalid
45896 + */
45897 + if (obj + len <= frame)
45898 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45899 + oldframe = frame;
45900 + frame = *(const void * const *)frame;
45901 + }
45902 + return -1;
45903 +#else
45904 + return 1;
45905 +#endif
45906 +}
45907 +
45908 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45909 +{
45910 + if (current->signal->curr_ip)
45911 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45912 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45913 + else
45914 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45915 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45916 + dump_stack();
45917 + gr_handle_kernel_exploit();
45918 + do_group_exit(SIGKILL);
45919 +}
45920 +#endif
45921 +
45922 +void check_object_size(const void *ptr, unsigned long n, bool to)
45923 +{
45924 +
45925 +#ifdef CONFIG_PAX_USERCOPY
45926 + const char *type;
45927 +
45928 + if (!n)
45929 + return;
45930 +
45931 + type = check_heap_object(ptr, n, to);
45932 + if (!type) {
45933 + if (check_stack_object(ptr, n) != -1)
45934 + return;
45935 + type = "<process stack>";
45936 + }
45937 +
45938 + pax_report_usercopy(ptr, n, to, type);
45939 +#endif
45940 +
45941 +}
45942 +EXPORT_SYMBOL(check_object_size);
45943 +
45944 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45945 +void pax_track_stack(void)
45946 +{
45947 + unsigned long sp = (unsigned long)&sp;
45948 + if (sp < current_thread_info()->lowest_stack &&
45949 + sp > (unsigned long)task_stack_page(current))
45950 + current_thread_info()->lowest_stack = sp;
45951 +}
45952 +EXPORT_SYMBOL(pax_track_stack);
45953 +#endif
45954 +
45955 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45956 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45957 +{
45958 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45959 + dump_stack();
45960 + do_group_exit(SIGKILL);
45961 +}
45962 +EXPORT_SYMBOL(report_size_overflow);
45963 +#endif
45964 +
45965 static int zap_process(struct task_struct *start, int exit_code)
45966 {
45967 struct task_struct *t;
45968 @@ -2041,17 +2417,17 @@ static void wait_for_dump_helpers(struct file *file)
45969 pipe = file->f_path.dentry->d_inode->i_pipe;
45970
45971 pipe_lock(pipe);
45972 - pipe->readers++;
45973 - pipe->writers--;
45974 + atomic_inc(&pipe->readers);
45975 + atomic_dec(&pipe->writers);
45976
45977 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45978 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45979 wake_up_interruptible_sync(&pipe->wait);
45980 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45981 pipe_wait(pipe);
45982 }
45983
45984 - pipe->readers--;
45985 - pipe->writers++;
45986 + atomic_dec(&pipe->readers);
45987 + atomic_inc(&pipe->writers);
45988 pipe_unlock(pipe);
45989
45990 }
45991 @@ -2106,7 +2482,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45992 int flag = 0;
45993 int ispipe;
45994 bool need_nonrelative = false;
45995 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45996 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45997 struct coredump_params cprm = {
45998 .signr = signr,
45999 .regs = regs,
46000 @@ -2121,6 +2497,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
46001
46002 audit_core_dumps(signr);
46003
46004 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46005 + gr_handle_brute_attach(current, cprm.mm_flags);
46006 +
46007 binfmt = mm->binfmt;
46008 if (!binfmt || !binfmt->core_dump)
46009 goto fail;
46010 @@ -2191,7 +2570,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
46011 }
46012 cprm.limit = RLIM_INFINITY;
46013
46014 - dump_count = atomic_inc_return(&core_dump_count);
46015 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
46016 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46017 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46018 task_tgid_vnr(current), current->comm);
46019 @@ -2218,6 +2597,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
46020 } else {
46021 struct inode *inode;
46022
46023 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46024 +
46025 if (cprm.limit < binfmt->min_coredump)
46026 goto fail_unlock;
46027
46028 @@ -2269,7 +2650,7 @@ close_fail:
46029 filp_close(cprm.file, NULL);
46030 fail_dropcount:
46031 if (ispipe)
46032 - atomic_dec(&core_dump_count);
46033 + atomic_dec_unchecked(&core_dump_count);
46034 fail_unlock:
46035 kfree(cn.corename);
46036 fail_corename:
46037 @@ -2288,7 +2669,7 @@ fail:
46038 */
46039 int dump_write(struct file *file, const void *addr, int nr)
46040 {
46041 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46042 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46043 }
46044 EXPORT_SYMBOL(dump_write);
46045
46046 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
46047 index 376aa77..59a129c 100644
46048 --- a/fs/ext2/balloc.c
46049 +++ b/fs/ext2/balloc.c
46050 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
46051
46052 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
46053 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
46054 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
46055 + if (free_blocks < root_blocks + 1 &&
46056 !uid_eq(sbi->s_resuid, current_fsuid()) &&
46057 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
46058 - !in_group_p (sbi->s_resgid))) {
46059 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
46060 return 0;
46061 }
46062 return 1;
46063 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
46064 index 90d901f..159975f 100644
46065 --- a/fs/ext3/balloc.c
46066 +++ b/fs/ext3/balloc.c
46067 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
46068
46069 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
46070 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
46071 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
46072 + if (free_blocks < root_blocks + 1 &&
46073 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
46074 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
46075 - !in_group_p (sbi->s_resgid))) {
46076 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
46077 return 0;
46078 }
46079 return 1;
46080 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
46081 index cf18217..8f6b9c3 100644
46082 --- a/fs/ext4/balloc.c
46083 +++ b/fs/ext4/balloc.c
46084 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
46085 /* Hm, nope. Are (enough) root reserved clusters available? */
46086 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
46087 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
46088 - capable(CAP_SYS_RESOURCE) ||
46089 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
46090 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
46091 + capable_nolog(CAP_SYS_RESOURCE)) {
46092
46093 if (free_clusters >= (nclusters + dirty_clusters))
46094 return 1;
46095 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
46096 index 5c69f2b..05dec7f 100644
46097 --- a/fs/ext4/ext4.h
46098 +++ b/fs/ext4/ext4.h
46099 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
46100 unsigned long s_mb_last_start;
46101
46102 /* stats for buddy allocator */
46103 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
46104 - atomic_t s_bal_success; /* we found long enough chunks */
46105 - atomic_t s_bal_allocated; /* in blocks */
46106 - atomic_t s_bal_ex_scanned; /* total extents scanned */
46107 - atomic_t s_bal_goals; /* goal hits */
46108 - atomic_t s_bal_breaks; /* too long searches */
46109 - atomic_t s_bal_2orders; /* 2^order hits */
46110 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
46111 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
46112 + atomic_unchecked_t s_bal_allocated; /* in blocks */
46113 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
46114 + atomic_unchecked_t s_bal_goals; /* goal hits */
46115 + atomic_unchecked_t s_bal_breaks; /* too long searches */
46116 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
46117 spinlock_t s_bal_lock;
46118 unsigned long s_mb_buddies_generated;
46119 unsigned long long s_mb_generation_time;
46120 - atomic_t s_mb_lost_chunks;
46121 - atomic_t s_mb_preallocated;
46122 - atomic_t s_mb_discarded;
46123 + atomic_unchecked_t s_mb_lost_chunks;
46124 + atomic_unchecked_t s_mb_preallocated;
46125 + atomic_unchecked_t s_mb_discarded;
46126 atomic_t s_lock_busy;
46127
46128 /* locality groups */
46129 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
46130 index b26410c..7383d90 100644
46131 --- a/fs/ext4/mballoc.c
46132 +++ b/fs/ext4/mballoc.c
46133 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
46134 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
46135
46136 if (EXT4_SB(sb)->s_mb_stats)
46137 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
46138 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
46139
46140 break;
46141 }
46142 @@ -2040,7 +2040,7 @@ repeat:
46143 ac->ac_status = AC_STATUS_CONTINUE;
46144 ac->ac_flags |= EXT4_MB_HINT_FIRST;
46145 cr = 3;
46146 - atomic_inc(&sbi->s_mb_lost_chunks);
46147 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
46148 goto repeat;
46149 }
46150 }
46151 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
46152 if (sbi->s_mb_stats) {
46153 ext4_msg(sb, KERN_INFO,
46154 "mballoc: %u blocks %u reqs (%u success)",
46155 - atomic_read(&sbi->s_bal_allocated),
46156 - atomic_read(&sbi->s_bal_reqs),
46157 - atomic_read(&sbi->s_bal_success));
46158 + atomic_read_unchecked(&sbi->s_bal_allocated),
46159 + atomic_read_unchecked(&sbi->s_bal_reqs),
46160 + atomic_read_unchecked(&sbi->s_bal_success));
46161 ext4_msg(sb, KERN_INFO,
46162 "mballoc: %u extents scanned, %u goal hits, "
46163 "%u 2^N hits, %u breaks, %u lost",
46164 - atomic_read(&sbi->s_bal_ex_scanned),
46165 - atomic_read(&sbi->s_bal_goals),
46166 - atomic_read(&sbi->s_bal_2orders),
46167 - atomic_read(&sbi->s_bal_breaks),
46168 - atomic_read(&sbi->s_mb_lost_chunks));
46169 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
46170 + atomic_read_unchecked(&sbi->s_bal_goals),
46171 + atomic_read_unchecked(&sbi->s_bal_2orders),
46172 + atomic_read_unchecked(&sbi->s_bal_breaks),
46173 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
46174 ext4_msg(sb, KERN_INFO,
46175 "mballoc: %lu generated and it took %Lu",
46176 sbi->s_mb_buddies_generated,
46177 sbi->s_mb_generation_time);
46178 ext4_msg(sb, KERN_INFO,
46179 "mballoc: %u preallocated, %u discarded",
46180 - atomic_read(&sbi->s_mb_preallocated),
46181 - atomic_read(&sbi->s_mb_discarded));
46182 + atomic_read_unchecked(&sbi->s_mb_preallocated),
46183 + atomic_read_unchecked(&sbi->s_mb_discarded));
46184 }
46185
46186 free_percpu(sbi->s_locality_groups);
46187 @@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
46188 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
46189
46190 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
46191 - atomic_inc(&sbi->s_bal_reqs);
46192 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46193 + atomic_inc_unchecked(&sbi->s_bal_reqs);
46194 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46195 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
46196 - atomic_inc(&sbi->s_bal_success);
46197 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
46198 + atomic_inc_unchecked(&sbi->s_bal_success);
46199 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
46200 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
46201 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
46202 - atomic_inc(&sbi->s_bal_goals);
46203 + atomic_inc_unchecked(&sbi->s_bal_goals);
46204 if (ac->ac_found > sbi->s_mb_max_to_scan)
46205 - atomic_inc(&sbi->s_bal_breaks);
46206 + atomic_inc_unchecked(&sbi->s_bal_breaks);
46207 }
46208
46209 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
46210 @@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
46211 trace_ext4_mb_new_inode_pa(ac, pa);
46212
46213 ext4_mb_use_inode_pa(ac, pa);
46214 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
46215 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
46216
46217 ei = EXT4_I(ac->ac_inode);
46218 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46219 @@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
46220 trace_ext4_mb_new_group_pa(ac, pa);
46221
46222 ext4_mb_use_group_pa(ac, pa);
46223 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46224 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46225
46226 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46227 lg = ac->ac_lg;
46228 @@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
46229 * from the bitmap and continue.
46230 */
46231 }
46232 - atomic_add(free, &sbi->s_mb_discarded);
46233 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
46234
46235 return err;
46236 }
46237 @@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
46238 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
46239 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
46240 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
46241 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46242 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46243 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
46244
46245 return 0;
46246 diff --git a/fs/fcntl.c b/fs/fcntl.c
46247 index 887b5ba..0e3f2c3 100644
46248 --- a/fs/fcntl.c
46249 +++ b/fs/fcntl.c
46250 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
46251 if (err)
46252 return err;
46253
46254 + if (gr_handle_chroot_fowner(pid, type))
46255 + return -ENOENT;
46256 + if (gr_check_protected_task_fowner(pid, type))
46257 + return -EACCES;
46258 +
46259 f_modown(filp, pid, type, force);
46260 return 0;
46261 }
46262 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
46263
46264 static int f_setown_ex(struct file *filp, unsigned long arg)
46265 {
46266 - struct f_owner_ex * __user owner_p = (void * __user)arg;
46267 + struct f_owner_ex __user *owner_p = (void __user *)arg;
46268 struct f_owner_ex owner;
46269 struct pid *pid;
46270 int type;
46271 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
46272
46273 static int f_getown_ex(struct file *filp, unsigned long arg)
46274 {
46275 - struct f_owner_ex * __user owner_p = (void * __user)arg;
46276 + struct f_owner_ex __user *owner_p = (void __user *)arg;
46277 struct f_owner_ex owner;
46278 int ret = 0;
46279
46280 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
46281 switch (cmd) {
46282 case F_DUPFD:
46283 case F_DUPFD_CLOEXEC:
46284 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
46285 if (arg >= rlimit(RLIMIT_NOFILE))
46286 break;
46287 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
46288 diff --git a/fs/fifo.c b/fs/fifo.c
46289 index cf6f434..3d7942c 100644
46290 --- a/fs/fifo.c
46291 +++ b/fs/fifo.c
46292 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
46293 */
46294 filp->f_op = &read_pipefifo_fops;
46295 pipe->r_counter++;
46296 - if (pipe->readers++ == 0)
46297 + if (atomic_inc_return(&pipe->readers) == 1)
46298 wake_up_partner(inode);
46299
46300 - if (!pipe->writers) {
46301 + if (!atomic_read(&pipe->writers)) {
46302 if ((filp->f_flags & O_NONBLOCK)) {
46303 /* suppress POLLHUP until we have
46304 * seen a writer */
46305 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
46306 * errno=ENXIO when there is no process reading the FIFO.
46307 */
46308 ret = -ENXIO;
46309 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46310 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46311 goto err;
46312
46313 filp->f_op = &write_pipefifo_fops;
46314 pipe->w_counter++;
46315 - if (!pipe->writers++)
46316 + if (atomic_inc_return(&pipe->writers) == 1)
46317 wake_up_partner(inode);
46318
46319 - if (!pipe->readers) {
46320 + if (!atomic_read(&pipe->readers)) {
46321 if (wait_for_partner(inode, &pipe->r_counter))
46322 goto err_wr;
46323 }
46324 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
46325 */
46326 filp->f_op = &rdwr_pipefifo_fops;
46327
46328 - pipe->readers++;
46329 - pipe->writers++;
46330 + atomic_inc(&pipe->readers);
46331 + atomic_inc(&pipe->writers);
46332 pipe->r_counter++;
46333 pipe->w_counter++;
46334 - if (pipe->readers == 1 || pipe->writers == 1)
46335 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46336 wake_up_partner(inode);
46337 break;
46338
46339 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
46340 return 0;
46341
46342 err_rd:
46343 - if (!--pipe->readers)
46344 + if (atomic_dec_and_test(&pipe->readers))
46345 wake_up_interruptible(&pipe->wait);
46346 ret = -ERESTARTSYS;
46347 goto err;
46348
46349 err_wr:
46350 - if (!--pipe->writers)
46351 + if (atomic_dec_and_test(&pipe->writers))
46352 wake_up_interruptible(&pipe->wait);
46353 ret = -ERESTARTSYS;
46354 goto err;
46355
46356 err:
46357 - if (!pipe->readers && !pipe->writers)
46358 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46359 free_pipe_info(inode);
46360
46361 err_nocleanup:
46362 diff --git a/fs/file.c b/fs/file.c
46363 index ba3f605..fade102 100644
46364 --- a/fs/file.c
46365 +++ b/fs/file.c
46366 @@ -15,6 +15,7 @@
46367 #include <linux/slab.h>
46368 #include <linux/vmalloc.h>
46369 #include <linux/file.h>
46370 +#include <linux/security.h>
46371 #include <linux/fdtable.h>
46372 #include <linux/bitops.h>
46373 #include <linux/interrupt.h>
46374 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
46375 * N.B. For clone tasks sharing a files structure, this test
46376 * will limit the total number of files that can be opened.
46377 */
46378 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46379 if (nr >= rlimit(RLIMIT_NOFILE))
46380 return -EMFILE;
46381
46382 diff --git a/fs/filesystems.c b/fs/filesystems.c
46383 index 96f2428..f5eeb8e 100644
46384 --- a/fs/filesystems.c
46385 +++ b/fs/filesystems.c
46386 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
46387 int len = dot ? dot - name : strlen(name);
46388
46389 fs = __get_fs_type(name, len);
46390 +
46391 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
46392 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46393 +#else
46394 if (!fs && (request_module("%.*s", len, name) == 0))
46395 +#endif
46396 fs = __get_fs_type(name, len);
46397
46398 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46399 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
46400 index 5df4775..f656176 100644
46401 --- a/fs/fs_struct.c
46402 +++ b/fs/fs_struct.c
46403 @@ -4,6 +4,7 @@
46404 #include <linux/path.h>
46405 #include <linux/slab.h>
46406 #include <linux/fs_struct.h>
46407 +#include <linux/grsecurity.h>
46408 #include "internal.h"
46409
46410 /*
46411 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
46412 write_seqcount_begin(&fs->seq);
46413 old_root = fs->root;
46414 fs->root = *path;
46415 + gr_set_chroot_entries(current, path);
46416 write_seqcount_end(&fs->seq);
46417 spin_unlock(&fs->lock);
46418 if (old_root.dentry)
46419 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
46420 return 1;
46421 }
46422
46423 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
46424 +{
46425 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
46426 + return 0;
46427 + *p = *new;
46428 +
46429 + /* This function is only called from pivot_root(). Leave our
46430 + gr_chroot_dentry and is_chrooted flags as-is, so that a
46431 + pivoted root isn't treated as a chroot
46432 + */
46433 + //gr_set_chroot_entries(task, new);
46434 +
46435 + return 1;
46436 +}
46437 +
46438 void chroot_fs_refs(struct path *old_root, struct path *new_root)
46439 {
46440 struct task_struct *g, *p;
46441 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
46442 int hits = 0;
46443 spin_lock(&fs->lock);
46444 write_seqcount_begin(&fs->seq);
46445 - hits += replace_path(&fs->root, old_root, new_root);
46446 + hits += replace_root_path(p, &fs->root, old_root, new_root);
46447 hits += replace_path(&fs->pwd, old_root, new_root);
46448 write_seqcount_end(&fs->seq);
46449 while (hits--) {
46450 @@ -94,12 +111,15 @@ void exit_fs(struct task_struct *tsk)
46451 {
46452 struct fs_struct *fs = tsk->fs;
46453
46454 + gr_put_exec_file(tsk);
46455 +
46456 if (fs) {
46457 int kill;
46458 task_lock(tsk);
46459 spin_lock(&fs->lock);
46460 tsk->fs = NULL;
46461 - kill = !--fs->users;
46462 + gr_clear_chroot_entries(tsk);
46463 + kill = !atomic_dec_return(&fs->users);
46464 spin_unlock(&fs->lock);
46465 task_unlock(tsk);
46466 if (kill)
46467 @@ -112,7 +132,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46468 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46469 /* We don't need to lock fs - think why ;-) */
46470 if (fs) {
46471 - fs->users = 1;
46472 + atomic_set(&fs->users, 1);
46473 fs->in_exec = 0;
46474 spin_lock_init(&fs->lock);
46475 seqcount_init(&fs->seq);
46476 @@ -121,6 +141,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46477 spin_lock(&old->lock);
46478 fs->root = old->root;
46479 path_get(&fs->root);
46480 + /* instead of calling gr_set_chroot_entries here,
46481 + we call it from every caller of this function
46482 + */
46483 fs->pwd = old->pwd;
46484 path_get(&fs->pwd);
46485 spin_unlock(&old->lock);
46486 @@ -139,8 +162,9 @@ int unshare_fs_struct(void)
46487
46488 task_lock(current);
46489 spin_lock(&fs->lock);
46490 - kill = !--fs->users;
46491 + kill = !atomic_dec_return(&fs->users);
46492 current->fs = new_fs;
46493 + gr_set_chroot_entries(current, &new_fs->root);
46494 spin_unlock(&fs->lock);
46495 task_unlock(current);
46496
46497 @@ -153,13 +177,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46498
46499 int current_umask(void)
46500 {
46501 - return current->fs->umask;
46502 + return current->fs->umask | gr_acl_umask();
46503 }
46504 EXPORT_SYMBOL(current_umask);
46505
46506 /* to be mentioned only in INIT_TASK */
46507 struct fs_struct init_fs = {
46508 - .users = 1,
46509 + .users = ATOMIC_INIT(1),
46510 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46511 .seq = SEQCNT_ZERO,
46512 .umask = 0022,
46513 @@ -169,18 +193,21 @@ void daemonize_fs_struct(void)
46514 {
46515 struct fs_struct *fs = current->fs;
46516
46517 + gr_put_exec_file(current);
46518 +
46519 if (fs) {
46520 int kill;
46521
46522 task_lock(current);
46523
46524 spin_lock(&init_fs.lock);
46525 - init_fs.users++;
46526 + atomic_inc(&init_fs.users);
46527 spin_unlock(&init_fs.lock);
46528
46529 spin_lock(&fs->lock);
46530 current->fs = &init_fs;
46531 - kill = !--fs->users;
46532 + gr_set_chroot_entries(current, &current->fs->root);
46533 + kill = !atomic_dec_return(&fs->users);
46534 spin_unlock(&fs->lock);
46535
46536 task_unlock(current);
46537 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46538 index 9905350..02eaec4 100644
46539 --- a/fs/fscache/cookie.c
46540 +++ b/fs/fscache/cookie.c
46541 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46542 parent ? (char *) parent->def->name : "<no-parent>",
46543 def->name, netfs_data);
46544
46545 - fscache_stat(&fscache_n_acquires);
46546 + fscache_stat_unchecked(&fscache_n_acquires);
46547
46548 /* if there's no parent cookie, then we don't create one here either */
46549 if (!parent) {
46550 - fscache_stat(&fscache_n_acquires_null);
46551 + fscache_stat_unchecked(&fscache_n_acquires_null);
46552 _leave(" [no parent]");
46553 return NULL;
46554 }
46555 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46556 /* allocate and initialise a cookie */
46557 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46558 if (!cookie) {
46559 - fscache_stat(&fscache_n_acquires_oom);
46560 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46561 _leave(" [ENOMEM]");
46562 return NULL;
46563 }
46564 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46565
46566 switch (cookie->def->type) {
46567 case FSCACHE_COOKIE_TYPE_INDEX:
46568 - fscache_stat(&fscache_n_cookie_index);
46569 + fscache_stat_unchecked(&fscache_n_cookie_index);
46570 break;
46571 case FSCACHE_COOKIE_TYPE_DATAFILE:
46572 - fscache_stat(&fscache_n_cookie_data);
46573 + fscache_stat_unchecked(&fscache_n_cookie_data);
46574 break;
46575 default:
46576 - fscache_stat(&fscache_n_cookie_special);
46577 + fscache_stat_unchecked(&fscache_n_cookie_special);
46578 break;
46579 }
46580
46581 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46582 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46583 atomic_dec(&parent->n_children);
46584 __fscache_cookie_put(cookie);
46585 - fscache_stat(&fscache_n_acquires_nobufs);
46586 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46587 _leave(" = NULL");
46588 return NULL;
46589 }
46590 }
46591
46592 - fscache_stat(&fscache_n_acquires_ok);
46593 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46594 _leave(" = %p", cookie);
46595 return cookie;
46596 }
46597 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46598 cache = fscache_select_cache_for_object(cookie->parent);
46599 if (!cache) {
46600 up_read(&fscache_addremove_sem);
46601 - fscache_stat(&fscache_n_acquires_no_cache);
46602 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46603 _leave(" = -ENOMEDIUM [no cache]");
46604 return -ENOMEDIUM;
46605 }
46606 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46607 object = cache->ops->alloc_object(cache, cookie);
46608 fscache_stat_d(&fscache_n_cop_alloc_object);
46609 if (IS_ERR(object)) {
46610 - fscache_stat(&fscache_n_object_no_alloc);
46611 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46612 ret = PTR_ERR(object);
46613 goto error;
46614 }
46615
46616 - fscache_stat(&fscache_n_object_alloc);
46617 + fscache_stat_unchecked(&fscache_n_object_alloc);
46618
46619 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46620
46621 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46622 struct fscache_object *object;
46623 struct hlist_node *_p;
46624
46625 - fscache_stat(&fscache_n_updates);
46626 + fscache_stat_unchecked(&fscache_n_updates);
46627
46628 if (!cookie) {
46629 - fscache_stat(&fscache_n_updates_null);
46630 + fscache_stat_unchecked(&fscache_n_updates_null);
46631 _leave(" [no cookie]");
46632 return;
46633 }
46634 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46635 struct fscache_object *object;
46636 unsigned long event;
46637
46638 - fscache_stat(&fscache_n_relinquishes);
46639 + fscache_stat_unchecked(&fscache_n_relinquishes);
46640 if (retire)
46641 - fscache_stat(&fscache_n_relinquishes_retire);
46642 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46643
46644 if (!cookie) {
46645 - fscache_stat(&fscache_n_relinquishes_null);
46646 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46647 _leave(" [no cookie]");
46648 return;
46649 }
46650 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46651
46652 /* wait for the cookie to finish being instantiated (or to fail) */
46653 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46654 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46655 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46656 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46657 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46658 }
46659 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46660 index f6aad48..88dcf26 100644
46661 --- a/fs/fscache/internal.h
46662 +++ b/fs/fscache/internal.h
46663 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46664 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46665 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46666
46667 -extern atomic_t fscache_n_op_pend;
46668 -extern atomic_t fscache_n_op_run;
46669 -extern atomic_t fscache_n_op_enqueue;
46670 -extern atomic_t fscache_n_op_deferred_release;
46671 -extern atomic_t fscache_n_op_release;
46672 -extern atomic_t fscache_n_op_gc;
46673 -extern atomic_t fscache_n_op_cancelled;
46674 -extern atomic_t fscache_n_op_rejected;
46675 +extern atomic_unchecked_t fscache_n_op_pend;
46676 +extern atomic_unchecked_t fscache_n_op_run;
46677 +extern atomic_unchecked_t fscache_n_op_enqueue;
46678 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46679 +extern atomic_unchecked_t fscache_n_op_release;
46680 +extern atomic_unchecked_t fscache_n_op_gc;
46681 +extern atomic_unchecked_t fscache_n_op_cancelled;
46682 +extern atomic_unchecked_t fscache_n_op_rejected;
46683
46684 -extern atomic_t fscache_n_attr_changed;
46685 -extern atomic_t fscache_n_attr_changed_ok;
46686 -extern atomic_t fscache_n_attr_changed_nobufs;
46687 -extern atomic_t fscache_n_attr_changed_nomem;
46688 -extern atomic_t fscache_n_attr_changed_calls;
46689 +extern atomic_unchecked_t fscache_n_attr_changed;
46690 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46691 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46692 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46693 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46694
46695 -extern atomic_t fscache_n_allocs;
46696 -extern atomic_t fscache_n_allocs_ok;
46697 -extern atomic_t fscache_n_allocs_wait;
46698 -extern atomic_t fscache_n_allocs_nobufs;
46699 -extern atomic_t fscache_n_allocs_intr;
46700 -extern atomic_t fscache_n_allocs_object_dead;
46701 -extern atomic_t fscache_n_alloc_ops;
46702 -extern atomic_t fscache_n_alloc_op_waits;
46703 +extern atomic_unchecked_t fscache_n_allocs;
46704 +extern atomic_unchecked_t fscache_n_allocs_ok;
46705 +extern atomic_unchecked_t fscache_n_allocs_wait;
46706 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46707 +extern atomic_unchecked_t fscache_n_allocs_intr;
46708 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46709 +extern atomic_unchecked_t fscache_n_alloc_ops;
46710 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46711
46712 -extern atomic_t fscache_n_retrievals;
46713 -extern atomic_t fscache_n_retrievals_ok;
46714 -extern atomic_t fscache_n_retrievals_wait;
46715 -extern atomic_t fscache_n_retrievals_nodata;
46716 -extern atomic_t fscache_n_retrievals_nobufs;
46717 -extern atomic_t fscache_n_retrievals_intr;
46718 -extern atomic_t fscache_n_retrievals_nomem;
46719 -extern atomic_t fscache_n_retrievals_object_dead;
46720 -extern atomic_t fscache_n_retrieval_ops;
46721 -extern atomic_t fscache_n_retrieval_op_waits;
46722 +extern atomic_unchecked_t fscache_n_retrievals;
46723 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46724 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46725 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46726 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46727 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46728 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46729 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46730 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46731 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46732
46733 -extern atomic_t fscache_n_stores;
46734 -extern atomic_t fscache_n_stores_ok;
46735 -extern atomic_t fscache_n_stores_again;
46736 -extern atomic_t fscache_n_stores_nobufs;
46737 -extern atomic_t fscache_n_stores_oom;
46738 -extern atomic_t fscache_n_store_ops;
46739 -extern atomic_t fscache_n_store_calls;
46740 -extern atomic_t fscache_n_store_pages;
46741 -extern atomic_t fscache_n_store_radix_deletes;
46742 -extern atomic_t fscache_n_store_pages_over_limit;
46743 +extern atomic_unchecked_t fscache_n_stores;
46744 +extern atomic_unchecked_t fscache_n_stores_ok;
46745 +extern atomic_unchecked_t fscache_n_stores_again;
46746 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46747 +extern atomic_unchecked_t fscache_n_stores_oom;
46748 +extern atomic_unchecked_t fscache_n_store_ops;
46749 +extern atomic_unchecked_t fscache_n_store_calls;
46750 +extern atomic_unchecked_t fscache_n_store_pages;
46751 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46752 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46753
46754 -extern atomic_t fscache_n_store_vmscan_not_storing;
46755 -extern atomic_t fscache_n_store_vmscan_gone;
46756 -extern atomic_t fscache_n_store_vmscan_busy;
46757 -extern atomic_t fscache_n_store_vmscan_cancelled;
46758 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46759 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46760 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46761 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46762
46763 -extern atomic_t fscache_n_marks;
46764 -extern atomic_t fscache_n_uncaches;
46765 +extern atomic_unchecked_t fscache_n_marks;
46766 +extern atomic_unchecked_t fscache_n_uncaches;
46767
46768 -extern atomic_t fscache_n_acquires;
46769 -extern atomic_t fscache_n_acquires_null;
46770 -extern atomic_t fscache_n_acquires_no_cache;
46771 -extern atomic_t fscache_n_acquires_ok;
46772 -extern atomic_t fscache_n_acquires_nobufs;
46773 -extern atomic_t fscache_n_acquires_oom;
46774 +extern atomic_unchecked_t fscache_n_acquires;
46775 +extern atomic_unchecked_t fscache_n_acquires_null;
46776 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46777 +extern atomic_unchecked_t fscache_n_acquires_ok;
46778 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46779 +extern atomic_unchecked_t fscache_n_acquires_oom;
46780
46781 -extern atomic_t fscache_n_updates;
46782 -extern atomic_t fscache_n_updates_null;
46783 -extern atomic_t fscache_n_updates_run;
46784 +extern atomic_unchecked_t fscache_n_updates;
46785 +extern atomic_unchecked_t fscache_n_updates_null;
46786 +extern atomic_unchecked_t fscache_n_updates_run;
46787
46788 -extern atomic_t fscache_n_relinquishes;
46789 -extern atomic_t fscache_n_relinquishes_null;
46790 -extern atomic_t fscache_n_relinquishes_waitcrt;
46791 -extern atomic_t fscache_n_relinquishes_retire;
46792 +extern atomic_unchecked_t fscache_n_relinquishes;
46793 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46794 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46795 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46796
46797 -extern atomic_t fscache_n_cookie_index;
46798 -extern atomic_t fscache_n_cookie_data;
46799 -extern atomic_t fscache_n_cookie_special;
46800 +extern atomic_unchecked_t fscache_n_cookie_index;
46801 +extern atomic_unchecked_t fscache_n_cookie_data;
46802 +extern atomic_unchecked_t fscache_n_cookie_special;
46803
46804 -extern atomic_t fscache_n_object_alloc;
46805 -extern atomic_t fscache_n_object_no_alloc;
46806 -extern atomic_t fscache_n_object_lookups;
46807 -extern atomic_t fscache_n_object_lookups_negative;
46808 -extern atomic_t fscache_n_object_lookups_positive;
46809 -extern atomic_t fscache_n_object_lookups_timed_out;
46810 -extern atomic_t fscache_n_object_created;
46811 -extern atomic_t fscache_n_object_avail;
46812 -extern atomic_t fscache_n_object_dead;
46813 +extern atomic_unchecked_t fscache_n_object_alloc;
46814 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46815 +extern atomic_unchecked_t fscache_n_object_lookups;
46816 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46817 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46818 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46819 +extern atomic_unchecked_t fscache_n_object_created;
46820 +extern atomic_unchecked_t fscache_n_object_avail;
46821 +extern atomic_unchecked_t fscache_n_object_dead;
46822
46823 -extern atomic_t fscache_n_checkaux_none;
46824 -extern atomic_t fscache_n_checkaux_okay;
46825 -extern atomic_t fscache_n_checkaux_update;
46826 -extern atomic_t fscache_n_checkaux_obsolete;
46827 +extern atomic_unchecked_t fscache_n_checkaux_none;
46828 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46829 +extern atomic_unchecked_t fscache_n_checkaux_update;
46830 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46831
46832 extern atomic_t fscache_n_cop_alloc_object;
46833 extern atomic_t fscache_n_cop_lookup_object;
46834 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46835 atomic_inc(stat);
46836 }
46837
46838 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46839 +{
46840 + atomic_inc_unchecked(stat);
46841 +}
46842 +
46843 static inline void fscache_stat_d(atomic_t *stat)
46844 {
46845 atomic_dec(stat);
46846 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46847
46848 #define __fscache_stat(stat) (NULL)
46849 #define fscache_stat(stat) do {} while (0)
46850 +#define fscache_stat_unchecked(stat) do {} while (0)
46851 #define fscache_stat_d(stat) do {} while (0)
46852 #endif
46853
46854 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46855 index b6b897c..0ffff9c 100644
46856 --- a/fs/fscache/object.c
46857 +++ b/fs/fscache/object.c
46858 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46859 /* update the object metadata on disk */
46860 case FSCACHE_OBJECT_UPDATING:
46861 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46862 - fscache_stat(&fscache_n_updates_run);
46863 + fscache_stat_unchecked(&fscache_n_updates_run);
46864 fscache_stat(&fscache_n_cop_update_object);
46865 object->cache->ops->update_object(object);
46866 fscache_stat_d(&fscache_n_cop_update_object);
46867 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46868 spin_lock(&object->lock);
46869 object->state = FSCACHE_OBJECT_DEAD;
46870 spin_unlock(&object->lock);
46871 - fscache_stat(&fscache_n_object_dead);
46872 + fscache_stat_unchecked(&fscache_n_object_dead);
46873 goto terminal_transit;
46874
46875 /* handle the parent cache of this object being withdrawn from
46876 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46877 spin_lock(&object->lock);
46878 object->state = FSCACHE_OBJECT_DEAD;
46879 spin_unlock(&object->lock);
46880 - fscache_stat(&fscache_n_object_dead);
46881 + fscache_stat_unchecked(&fscache_n_object_dead);
46882 goto terminal_transit;
46883
46884 /* complain about the object being woken up once it is
46885 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46886 parent->cookie->def->name, cookie->def->name,
46887 object->cache->tag->name);
46888
46889 - fscache_stat(&fscache_n_object_lookups);
46890 + fscache_stat_unchecked(&fscache_n_object_lookups);
46891 fscache_stat(&fscache_n_cop_lookup_object);
46892 ret = object->cache->ops->lookup_object(object);
46893 fscache_stat_d(&fscache_n_cop_lookup_object);
46894 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46895 if (ret == -ETIMEDOUT) {
46896 /* probably stuck behind another object, so move this one to
46897 * the back of the queue */
46898 - fscache_stat(&fscache_n_object_lookups_timed_out);
46899 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46900 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46901 }
46902
46903 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46904
46905 spin_lock(&object->lock);
46906 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46907 - fscache_stat(&fscache_n_object_lookups_negative);
46908 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46909
46910 /* transit here to allow write requests to begin stacking up
46911 * and read requests to begin returning ENODATA */
46912 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46913 * result, in which case there may be data available */
46914 spin_lock(&object->lock);
46915 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46916 - fscache_stat(&fscache_n_object_lookups_positive);
46917 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46918
46919 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46920
46921 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46922 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46923 } else {
46924 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46925 - fscache_stat(&fscache_n_object_created);
46926 + fscache_stat_unchecked(&fscache_n_object_created);
46927
46928 object->state = FSCACHE_OBJECT_AVAILABLE;
46929 spin_unlock(&object->lock);
46930 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46931 fscache_enqueue_dependents(object);
46932
46933 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46934 - fscache_stat(&fscache_n_object_avail);
46935 + fscache_stat_unchecked(&fscache_n_object_avail);
46936
46937 _leave("");
46938 }
46939 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46940 enum fscache_checkaux result;
46941
46942 if (!object->cookie->def->check_aux) {
46943 - fscache_stat(&fscache_n_checkaux_none);
46944 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46945 return FSCACHE_CHECKAUX_OKAY;
46946 }
46947
46948 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46949 switch (result) {
46950 /* entry okay as is */
46951 case FSCACHE_CHECKAUX_OKAY:
46952 - fscache_stat(&fscache_n_checkaux_okay);
46953 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46954 break;
46955
46956 /* entry requires update */
46957 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46958 - fscache_stat(&fscache_n_checkaux_update);
46959 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46960 break;
46961
46962 /* entry requires deletion */
46963 case FSCACHE_CHECKAUX_OBSOLETE:
46964 - fscache_stat(&fscache_n_checkaux_obsolete);
46965 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46966 break;
46967
46968 default:
46969 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46970 index 30afdfa..2256596 100644
46971 --- a/fs/fscache/operation.c
46972 +++ b/fs/fscache/operation.c
46973 @@ -17,7 +17,7 @@
46974 #include <linux/slab.h>
46975 #include "internal.h"
46976
46977 -atomic_t fscache_op_debug_id;
46978 +atomic_unchecked_t fscache_op_debug_id;
46979 EXPORT_SYMBOL(fscache_op_debug_id);
46980
46981 /**
46982 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46983 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46984 ASSERTCMP(atomic_read(&op->usage), >, 0);
46985
46986 - fscache_stat(&fscache_n_op_enqueue);
46987 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46988 switch (op->flags & FSCACHE_OP_TYPE) {
46989 case FSCACHE_OP_ASYNC:
46990 _debug("queue async");
46991 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46992 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46993 if (op->processor)
46994 fscache_enqueue_operation(op);
46995 - fscache_stat(&fscache_n_op_run);
46996 + fscache_stat_unchecked(&fscache_n_op_run);
46997 }
46998
46999 /*
47000 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
47001 if (object->n_ops > 1) {
47002 atomic_inc(&op->usage);
47003 list_add_tail(&op->pend_link, &object->pending_ops);
47004 - fscache_stat(&fscache_n_op_pend);
47005 + fscache_stat_unchecked(&fscache_n_op_pend);
47006 } else if (!list_empty(&object->pending_ops)) {
47007 atomic_inc(&op->usage);
47008 list_add_tail(&op->pend_link, &object->pending_ops);
47009 - fscache_stat(&fscache_n_op_pend);
47010 + fscache_stat_unchecked(&fscache_n_op_pend);
47011 fscache_start_operations(object);
47012 } else {
47013 ASSERTCMP(object->n_in_progress, ==, 0);
47014 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
47015 object->n_exclusive++; /* reads and writes must wait */
47016 atomic_inc(&op->usage);
47017 list_add_tail(&op->pend_link, &object->pending_ops);
47018 - fscache_stat(&fscache_n_op_pend);
47019 + fscache_stat_unchecked(&fscache_n_op_pend);
47020 ret = 0;
47021 } else {
47022 /* not allowed to submit ops in any other state */
47023 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
47024 if (object->n_exclusive > 0) {
47025 atomic_inc(&op->usage);
47026 list_add_tail(&op->pend_link, &object->pending_ops);
47027 - fscache_stat(&fscache_n_op_pend);
47028 + fscache_stat_unchecked(&fscache_n_op_pend);
47029 } else if (!list_empty(&object->pending_ops)) {
47030 atomic_inc(&op->usage);
47031 list_add_tail(&op->pend_link, &object->pending_ops);
47032 - fscache_stat(&fscache_n_op_pend);
47033 + fscache_stat_unchecked(&fscache_n_op_pend);
47034 fscache_start_operations(object);
47035 } else {
47036 ASSERTCMP(object->n_exclusive, ==, 0);
47037 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
47038 object->n_ops++;
47039 atomic_inc(&op->usage);
47040 list_add_tail(&op->pend_link, &object->pending_ops);
47041 - fscache_stat(&fscache_n_op_pend);
47042 + fscache_stat_unchecked(&fscache_n_op_pend);
47043 ret = 0;
47044 } else if (object->state == FSCACHE_OBJECT_DYING ||
47045 object->state == FSCACHE_OBJECT_LC_DYING ||
47046 object->state == FSCACHE_OBJECT_WITHDRAWING) {
47047 - fscache_stat(&fscache_n_op_rejected);
47048 + fscache_stat_unchecked(&fscache_n_op_rejected);
47049 ret = -ENOBUFS;
47050 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
47051 fscache_report_unexpected_submission(object, op, ostate);
47052 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
47053
47054 ret = -EBUSY;
47055 if (!list_empty(&op->pend_link)) {
47056 - fscache_stat(&fscache_n_op_cancelled);
47057 + fscache_stat_unchecked(&fscache_n_op_cancelled);
47058 list_del_init(&op->pend_link);
47059 object->n_ops--;
47060 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
47061 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
47062 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
47063 BUG();
47064
47065 - fscache_stat(&fscache_n_op_release);
47066 + fscache_stat_unchecked(&fscache_n_op_release);
47067
47068 if (op->release) {
47069 op->release(op);
47070 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
47071 * lock, and defer it otherwise */
47072 if (!spin_trylock(&object->lock)) {
47073 _debug("defer put");
47074 - fscache_stat(&fscache_n_op_deferred_release);
47075 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
47076
47077 cache = object->cache;
47078 spin_lock(&cache->op_gc_list_lock);
47079 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
47080
47081 _debug("GC DEFERRED REL OBJ%x OP%x",
47082 object->debug_id, op->debug_id);
47083 - fscache_stat(&fscache_n_op_gc);
47084 + fscache_stat_unchecked(&fscache_n_op_gc);
47085
47086 ASSERTCMP(atomic_read(&op->usage), ==, 0);
47087
47088 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
47089 index 3f7a59b..cf196cc 100644
47090 --- a/fs/fscache/page.c
47091 +++ b/fs/fscache/page.c
47092 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
47093 val = radix_tree_lookup(&cookie->stores, page->index);
47094 if (!val) {
47095 rcu_read_unlock();
47096 - fscache_stat(&fscache_n_store_vmscan_not_storing);
47097 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
47098 __fscache_uncache_page(cookie, page);
47099 return true;
47100 }
47101 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
47102 spin_unlock(&cookie->stores_lock);
47103
47104 if (xpage) {
47105 - fscache_stat(&fscache_n_store_vmscan_cancelled);
47106 - fscache_stat(&fscache_n_store_radix_deletes);
47107 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
47108 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
47109 ASSERTCMP(xpage, ==, page);
47110 } else {
47111 - fscache_stat(&fscache_n_store_vmscan_gone);
47112 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
47113 }
47114
47115 wake_up_bit(&cookie->flags, 0);
47116 @@ -107,7 +107,7 @@ page_busy:
47117 /* we might want to wait here, but that could deadlock the allocator as
47118 * the work threads writing to the cache may all end up sleeping
47119 * on memory allocation */
47120 - fscache_stat(&fscache_n_store_vmscan_busy);
47121 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
47122 return false;
47123 }
47124 EXPORT_SYMBOL(__fscache_maybe_release_page);
47125 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
47126 FSCACHE_COOKIE_STORING_TAG);
47127 if (!radix_tree_tag_get(&cookie->stores, page->index,
47128 FSCACHE_COOKIE_PENDING_TAG)) {
47129 - fscache_stat(&fscache_n_store_radix_deletes);
47130 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
47131 xpage = radix_tree_delete(&cookie->stores, page->index);
47132 }
47133 spin_unlock(&cookie->stores_lock);
47134 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
47135
47136 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
47137
47138 - fscache_stat(&fscache_n_attr_changed_calls);
47139 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
47140
47141 if (fscache_object_is_active(object)) {
47142 fscache_stat(&fscache_n_cop_attr_changed);
47143 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47144
47145 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47146
47147 - fscache_stat(&fscache_n_attr_changed);
47148 + fscache_stat_unchecked(&fscache_n_attr_changed);
47149
47150 op = kzalloc(sizeof(*op), GFP_KERNEL);
47151 if (!op) {
47152 - fscache_stat(&fscache_n_attr_changed_nomem);
47153 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
47154 _leave(" = -ENOMEM");
47155 return -ENOMEM;
47156 }
47157 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47158 if (fscache_submit_exclusive_op(object, op) < 0)
47159 goto nobufs;
47160 spin_unlock(&cookie->lock);
47161 - fscache_stat(&fscache_n_attr_changed_ok);
47162 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
47163 fscache_put_operation(op);
47164 _leave(" = 0");
47165 return 0;
47166 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47167 nobufs:
47168 spin_unlock(&cookie->lock);
47169 kfree(op);
47170 - fscache_stat(&fscache_n_attr_changed_nobufs);
47171 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
47172 _leave(" = %d", -ENOBUFS);
47173 return -ENOBUFS;
47174 }
47175 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
47176 /* allocate a retrieval operation and attempt to submit it */
47177 op = kzalloc(sizeof(*op), GFP_NOIO);
47178 if (!op) {
47179 - fscache_stat(&fscache_n_retrievals_nomem);
47180 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47181 return NULL;
47182 }
47183
47184 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
47185 return 0;
47186 }
47187
47188 - fscache_stat(&fscache_n_retrievals_wait);
47189 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
47190
47191 jif = jiffies;
47192 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
47193 fscache_wait_bit_interruptible,
47194 TASK_INTERRUPTIBLE) != 0) {
47195 - fscache_stat(&fscache_n_retrievals_intr);
47196 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47197 _leave(" = -ERESTARTSYS");
47198 return -ERESTARTSYS;
47199 }
47200 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
47201 */
47202 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47203 struct fscache_retrieval *op,
47204 - atomic_t *stat_op_waits,
47205 - atomic_t *stat_object_dead)
47206 + atomic_unchecked_t *stat_op_waits,
47207 + atomic_unchecked_t *stat_object_dead)
47208 {
47209 int ret;
47210
47211 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47212 goto check_if_dead;
47213
47214 _debug(">>> WT");
47215 - fscache_stat(stat_op_waits);
47216 + fscache_stat_unchecked(stat_op_waits);
47217 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
47218 fscache_wait_bit_interruptible,
47219 TASK_INTERRUPTIBLE) < 0) {
47220 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47221
47222 check_if_dead:
47223 if (unlikely(fscache_object_is_dead(object))) {
47224 - fscache_stat(stat_object_dead);
47225 + fscache_stat_unchecked(stat_object_dead);
47226 return -ENOBUFS;
47227 }
47228 return 0;
47229 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47230
47231 _enter("%p,%p,,,", cookie, page);
47232
47233 - fscache_stat(&fscache_n_retrievals);
47234 + fscache_stat_unchecked(&fscache_n_retrievals);
47235
47236 if (hlist_empty(&cookie->backing_objects))
47237 goto nobufs;
47238 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47239 goto nobufs_unlock;
47240 spin_unlock(&cookie->lock);
47241
47242 - fscache_stat(&fscache_n_retrieval_ops);
47243 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
47244
47245 /* pin the netfs read context in case we need to do the actual netfs
47246 * read because we've encountered a cache read failure */
47247 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47248
47249 error:
47250 if (ret == -ENOMEM)
47251 - fscache_stat(&fscache_n_retrievals_nomem);
47252 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47253 else if (ret == -ERESTARTSYS)
47254 - fscache_stat(&fscache_n_retrievals_intr);
47255 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47256 else if (ret == -ENODATA)
47257 - fscache_stat(&fscache_n_retrievals_nodata);
47258 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47259 else if (ret < 0)
47260 - fscache_stat(&fscache_n_retrievals_nobufs);
47261 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47262 else
47263 - fscache_stat(&fscache_n_retrievals_ok);
47264 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47265
47266 fscache_put_retrieval(op);
47267 _leave(" = %d", ret);
47268 @@ -429,7 +429,7 @@ nobufs_unlock:
47269 spin_unlock(&cookie->lock);
47270 kfree(op);
47271 nobufs:
47272 - fscache_stat(&fscache_n_retrievals_nobufs);
47273 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47274 _leave(" = -ENOBUFS");
47275 return -ENOBUFS;
47276 }
47277 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47278
47279 _enter("%p,,%d,,,", cookie, *nr_pages);
47280
47281 - fscache_stat(&fscache_n_retrievals);
47282 + fscache_stat_unchecked(&fscache_n_retrievals);
47283
47284 if (hlist_empty(&cookie->backing_objects))
47285 goto nobufs;
47286 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47287 goto nobufs_unlock;
47288 spin_unlock(&cookie->lock);
47289
47290 - fscache_stat(&fscache_n_retrieval_ops);
47291 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
47292
47293 /* pin the netfs read context in case we need to do the actual netfs
47294 * read because we've encountered a cache read failure */
47295 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47296
47297 error:
47298 if (ret == -ENOMEM)
47299 - fscache_stat(&fscache_n_retrievals_nomem);
47300 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47301 else if (ret == -ERESTARTSYS)
47302 - fscache_stat(&fscache_n_retrievals_intr);
47303 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47304 else if (ret == -ENODATA)
47305 - fscache_stat(&fscache_n_retrievals_nodata);
47306 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47307 else if (ret < 0)
47308 - fscache_stat(&fscache_n_retrievals_nobufs);
47309 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47310 else
47311 - fscache_stat(&fscache_n_retrievals_ok);
47312 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47313
47314 fscache_put_retrieval(op);
47315 _leave(" = %d", ret);
47316 @@ -545,7 +545,7 @@ nobufs_unlock:
47317 spin_unlock(&cookie->lock);
47318 kfree(op);
47319 nobufs:
47320 - fscache_stat(&fscache_n_retrievals_nobufs);
47321 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47322 _leave(" = -ENOBUFS");
47323 return -ENOBUFS;
47324 }
47325 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47326
47327 _enter("%p,%p,,,", cookie, page);
47328
47329 - fscache_stat(&fscache_n_allocs);
47330 + fscache_stat_unchecked(&fscache_n_allocs);
47331
47332 if (hlist_empty(&cookie->backing_objects))
47333 goto nobufs;
47334 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47335 goto nobufs_unlock;
47336 spin_unlock(&cookie->lock);
47337
47338 - fscache_stat(&fscache_n_alloc_ops);
47339 + fscache_stat_unchecked(&fscache_n_alloc_ops);
47340
47341 ret = fscache_wait_for_retrieval_activation(
47342 object, op,
47343 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47344
47345 error:
47346 if (ret == -ERESTARTSYS)
47347 - fscache_stat(&fscache_n_allocs_intr);
47348 + fscache_stat_unchecked(&fscache_n_allocs_intr);
47349 else if (ret < 0)
47350 - fscache_stat(&fscache_n_allocs_nobufs);
47351 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47352 else
47353 - fscache_stat(&fscache_n_allocs_ok);
47354 + fscache_stat_unchecked(&fscache_n_allocs_ok);
47355
47356 fscache_put_retrieval(op);
47357 _leave(" = %d", ret);
47358 @@ -625,7 +625,7 @@ nobufs_unlock:
47359 spin_unlock(&cookie->lock);
47360 kfree(op);
47361 nobufs:
47362 - fscache_stat(&fscache_n_allocs_nobufs);
47363 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47364 _leave(" = -ENOBUFS");
47365 return -ENOBUFS;
47366 }
47367 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47368
47369 spin_lock(&cookie->stores_lock);
47370
47371 - fscache_stat(&fscache_n_store_calls);
47372 + fscache_stat_unchecked(&fscache_n_store_calls);
47373
47374 /* find a page to store */
47375 page = NULL;
47376 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47377 page = results[0];
47378 _debug("gang %d [%lx]", n, page->index);
47379 if (page->index > op->store_limit) {
47380 - fscache_stat(&fscache_n_store_pages_over_limit);
47381 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47382 goto superseded;
47383 }
47384
47385 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47386 spin_unlock(&cookie->stores_lock);
47387 spin_unlock(&object->lock);
47388
47389 - fscache_stat(&fscache_n_store_pages);
47390 + fscache_stat_unchecked(&fscache_n_store_pages);
47391 fscache_stat(&fscache_n_cop_write_page);
47392 ret = object->cache->ops->write_page(op, page);
47393 fscache_stat_d(&fscache_n_cop_write_page);
47394 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47395 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47396 ASSERT(PageFsCache(page));
47397
47398 - fscache_stat(&fscache_n_stores);
47399 + fscache_stat_unchecked(&fscache_n_stores);
47400
47401 op = kzalloc(sizeof(*op), GFP_NOIO);
47402 if (!op)
47403 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47404 spin_unlock(&cookie->stores_lock);
47405 spin_unlock(&object->lock);
47406
47407 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47408 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47409 op->store_limit = object->store_limit;
47410
47411 if (fscache_submit_op(object, &op->op) < 0)
47412 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47413
47414 spin_unlock(&cookie->lock);
47415 radix_tree_preload_end();
47416 - fscache_stat(&fscache_n_store_ops);
47417 - fscache_stat(&fscache_n_stores_ok);
47418 + fscache_stat_unchecked(&fscache_n_store_ops);
47419 + fscache_stat_unchecked(&fscache_n_stores_ok);
47420
47421 /* the work queue now carries its own ref on the object */
47422 fscache_put_operation(&op->op);
47423 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47424 return 0;
47425
47426 already_queued:
47427 - fscache_stat(&fscache_n_stores_again);
47428 + fscache_stat_unchecked(&fscache_n_stores_again);
47429 already_pending:
47430 spin_unlock(&cookie->stores_lock);
47431 spin_unlock(&object->lock);
47432 spin_unlock(&cookie->lock);
47433 radix_tree_preload_end();
47434 kfree(op);
47435 - fscache_stat(&fscache_n_stores_ok);
47436 + fscache_stat_unchecked(&fscache_n_stores_ok);
47437 _leave(" = 0");
47438 return 0;
47439
47440 @@ -851,14 +851,14 @@ nobufs:
47441 spin_unlock(&cookie->lock);
47442 radix_tree_preload_end();
47443 kfree(op);
47444 - fscache_stat(&fscache_n_stores_nobufs);
47445 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47446 _leave(" = -ENOBUFS");
47447 return -ENOBUFS;
47448
47449 nomem_free:
47450 kfree(op);
47451 nomem:
47452 - fscache_stat(&fscache_n_stores_oom);
47453 + fscache_stat_unchecked(&fscache_n_stores_oom);
47454 _leave(" = -ENOMEM");
47455 return -ENOMEM;
47456 }
47457 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
47458 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47459 ASSERTCMP(page, !=, NULL);
47460
47461 - fscache_stat(&fscache_n_uncaches);
47462 + fscache_stat_unchecked(&fscache_n_uncaches);
47463
47464 /* cache withdrawal may beat us to it */
47465 if (!PageFsCache(page))
47466 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47467 unsigned long loop;
47468
47469 #ifdef CONFIG_FSCACHE_STATS
47470 - atomic_add(pagevec->nr, &fscache_n_marks);
47471 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47472 #endif
47473
47474 for (loop = 0; loop < pagevec->nr; loop++) {
47475 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47476 index 4765190..2a067f2 100644
47477 --- a/fs/fscache/stats.c
47478 +++ b/fs/fscache/stats.c
47479 @@ -18,95 +18,95 @@
47480 /*
47481 * operation counters
47482 */
47483 -atomic_t fscache_n_op_pend;
47484 -atomic_t fscache_n_op_run;
47485 -atomic_t fscache_n_op_enqueue;
47486 -atomic_t fscache_n_op_requeue;
47487 -atomic_t fscache_n_op_deferred_release;
47488 -atomic_t fscache_n_op_release;
47489 -atomic_t fscache_n_op_gc;
47490 -atomic_t fscache_n_op_cancelled;
47491 -atomic_t fscache_n_op_rejected;
47492 +atomic_unchecked_t fscache_n_op_pend;
47493 +atomic_unchecked_t fscache_n_op_run;
47494 +atomic_unchecked_t fscache_n_op_enqueue;
47495 +atomic_unchecked_t fscache_n_op_requeue;
47496 +atomic_unchecked_t fscache_n_op_deferred_release;
47497 +atomic_unchecked_t fscache_n_op_release;
47498 +atomic_unchecked_t fscache_n_op_gc;
47499 +atomic_unchecked_t fscache_n_op_cancelled;
47500 +atomic_unchecked_t fscache_n_op_rejected;
47501
47502 -atomic_t fscache_n_attr_changed;
47503 -atomic_t fscache_n_attr_changed_ok;
47504 -atomic_t fscache_n_attr_changed_nobufs;
47505 -atomic_t fscache_n_attr_changed_nomem;
47506 -atomic_t fscache_n_attr_changed_calls;
47507 +atomic_unchecked_t fscache_n_attr_changed;
47508 +atomic_unchecked_t fscache_n_attr_changed_ok;
47509 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47510 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47511 +atomic_unchecked_t fscache_n_attr_changed_calls;
47512
47513 -atomic_t fscache_n_allocs;
47514 -atomic_t fscache_n_allocs_ok;
47515 -atomic_t fscache_n_allocs_wait;
47516 -atomic_t fscache_n_allocs_nobufs;
47517 -atomic_t fscache_n_allocs_intr;
47518 -atomic_t fscache_n_allocs_object_dead;
47519 -atomic_t fscache_n_alloc_ops;
47520 -atomic_t fscache_n_alloc_op_waits;
47521 +atomic_unchecked_t fscache_n_allocs;
47522 +atomic_unchecked_t fscache_n_allocs_ok;
47523 +atomic_unchecked_t fscache_n_allocs_wait;
47524 +atomic_unchecked_t fscache_n_allocs_nobufs;
47525 +atomic_unchecked_t fscache_n_allocs_intr;
47526 +atomic_unchecked_t fscache_n_allocs_object_dead;
47527 +atomic_unchecked_t fscache_n_alloc_ops;
47528 +atomic_unchecked_t fscache_n_alloc_op_waits;
47529
47530 -atomic_t fscache_n_retrievals;
47531 -atomic_t fscache_n_retrievals_ok;
47532 -atomic_t fscache_n_retrievals_wait;
47533 -atomic_t fscache_n_retrievals_nodata;
47534 -atomic_t fscache_n_retrievals_nobufs;
47535 -atomic_t fscache_n_retrievals_intr;
47536 -atomic_t fscache_n_retrievals_nomem;
47537 -atomic_t fscache_n_retrievals_object_dead;
47538 -atomic_t fscache_n_retrieval_ops;
47539 -atomic_t fscache_n_retrieval_op_waits;
47540 +atomic_unchecked_t fscache_n_retrievals;
47541 +atomic_unchecked_t fscache_n_retrievals_ok;
47542 +atomic_unchecked_t fscache_n_retrievals_wait;
47543 +atomic_unchecked_t fscache_n_retrievals_nodata;
47544 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47545 +atomic_unchecked_t fscache_n_retrievals_intr;
47546 +atomic_unchecked_t fscache_n_retrievals_nomem;
47547 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47548 +atomic_unchecked_t fscache_n_retrieval_ops;
47549 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47550
47551 -atomic_t fscache_n_stores;
47552 -atomic_t fscache_n_stores_ok;
47553 -atomic_t fscache_n_stores_again;
47554 -atomic_t fscache_n_stores_nobufs;
47555 -atomic_t fscache_n_stores_oom;
47556 -atomic_t fscache_n_store_ops;
47557 -atomic_t fscache_n_store_calls;
47558 -atomic_t fscache_n_store_pages;
47559 -atomic_t fscache_n_store_radix_deletes;
47560 -atomic_t fscache_n_store_pages_over_limit;
47561 +atomic_unchecked_t fscache_n_stores;
47562 +atomic_unchecked_t fscache_n_stores_ok;
47563 +atomic_unchecked_t fscache_n_stores_again;
47564 +atomic_unchecked_t fscache_n_stores_nobufs;
47565 +atomic_unchecked_t fscache_n_stores_oom;
47566 +atomic_unchecked_t fscache_n_store_ops;
47567 +atomic_unchecked_t fscache_n_store_calls;
47568 +atomic_unchecked_t fscache_n_store_pages;
47569 +atomic_unchecked_t fscache_n_store_radix_deletes;
47570 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47571
47572 -atomic_t fscache_n_store_vmscan_not_storing;
47573 -atomic_t fscache_n_store_vmscan_gone;
47574 -atomic_t fscache_n_store_vmscan_busy;
47575 -atomic_t fscache_n_store_vmscan_cancelled;
47576 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47577 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47578 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47579 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47580
47581 -atomic_t fscache_n_marks;
47582 -atomic_t fscache_n_uncaches;
47583 +atomic_unchecked_t fscache_n_marks;
47584 +atomic_unchecked_t fscache_n_uncaches;
47585
47586 -atomic_t fscache_n_acquires;
47587 -atomic_t fscache_n_acquires_null;
47588 -atomic_t fscache_n_acquires_no_cache;
47589 -atomic_t fscache_n_acquires_ok;
47590 -atomic_t fscache_n_acquires_nobufs;
47591 -atomic_t fscache_n_acquires_oom;
47592 +atomic_unchecked_t fscache_n_acquires;
47593 +atomic_unchecked_t fscache_n_acquires_null;
47594 +atomic_unchecked_t fscache_n_acquires_no_cache;
47595 +atomic_unchecked_t fscache_n_acquires_ok;
47596 +atomic_unchecked_t fscache_n_acquires_nobufs;
47597 +atomic_unchecked_t fscache_n_acquires_oom;
47598
47599 -atomic_t fscache_n_updates;
47600 -atomic_t fscache_n_updates_null;
47601 -atomic_t fscache_n_updates_run;
47602 +atomic_unchecked_t fscache_n_updates;
47603 +atomic_unchecked_t fscache_n_updates_null;
47604 +atomic_unchecked_t fscache_n_updates_run;
47605
47606 -atomic_t fscache_n_relinquishes;
47607 -atomic_t fscache_n_relinquishes_null;
47608 -atomic_t fscache_n_relinquishes_waitcrt;
47609 -atomic_t fscache_n_relinquishes_retire;
47610 +atomic_unchecked_t fscache_n_relinquishes;
47611 +atomic_unchecked_t fscache_n_relinquishes_null;
47612 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47613 +atomic_unchecked_t fscache_n_relinquishes_retire;
47614
47615 -atomic_t fscache_n_cookie_index;
47616 -atomic_t fscache_n_cookie_data;
47617 -atomic_t fscache_n_cookie_special;
47618 +atomic_unchecked_t fscache_n_cookie_index;
47619 +atomic_unchecked_t fscache_n_cookie_data;
47620 +atomic_unchecked_t fscache_n_cookie_special;
47621
47622 -atomic_t fscache_n_object_alloc;
47623 -atomic_t fscache_n_object_no_alloc;
47624 -atomic_t fscache_n_object_lookups;
47625 -atomic_t fscache_n_object_lookups_negative;
47626 -atomic_t fscache_n_object_lookups_positive;
47627 -atomic_t fscache_n_object_lookups_timed_out;
47628 -atomic_t fscache_n_object_created;
47629 -atomic_t fscache_n_object_avail;
47630 -atomic_t fscache_n_object_dead;
47631 +atomic_unchecked_t fscache_n_object_alloc;
47632 +atomic_unchecked_t fscache_n_object_no_alloc;
47633 +atomic_unchecked_t fscache_n_object_lookups;
47634 +atomic_unchecked_t fscache_n_object_lookups_negative;
47635 +atomic_unchecked_t fscache_n_object_lookups_positive;
47636 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47637 +atomic_unchecked_t fscache_n_object_created;
47638 +atomic_unchecked_t fscache_n_object_avail;
47639 +atomic_unchecked_t fscache_n_object_dead;
47640
47641 -atomic_t fscache_n_checkaux_none;
47642 -atomic_t fscache_n_checkaux_okay;
47643 -atomic_t fscache_n_checkaux_update;
47644 -atomic_t fscache_n_checkaux_obsolete;
47645 +atomic_unchecked_t fscache_n_checkaux_none;
47646 +atomic_unchecked_t fscache_n_checkaux_okay;
47647 +atomic_unchecked_t fscache_n_checkaux_update;
47648 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47649
47650 atomic_t fscache_n_cop_alloc_object;
47651 atomic_t fscache_n_cop_lookup_object;
47652 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47653 seq_puts(m, "FS-Cache statistics\n");
47654
47655 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47656 - atomic_read(&fscache_n_cookie_index),
47657 - atomic_read(&fscache_n_cookie_data),
47658 - atomic_read(&fscache_n_cookie_special));
47659 + atomic_read_unchecked(&fscache_n_cookie_index),
47660 + atomic_read_unchecked(&fscache_n_cookie_data),
47661 + atomic_read_unchecked(&fscache_n_cookie_special));
47662
47663 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47664 - atomic_read(&fscache_n_object_alloc),
47665 - atomic_read(&fscache_n_object_no_alloc),
47666 - atomic_read(&fscache_n_object_avail),
47667 - atomic_read(&fscache_n_object_dead));
47668 + atomic_read_unchecked(&fscache_n_object_alloc),
47669 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47670 + atomic_read_unchecked(&fscache_n_object_avail),
47671 + atomic_read_unchecked(&fscache_n_object_dead));
47672 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47673 - atomic_read(&fscache_n_checkaux_none),
47674 - atomic_read(&fscache_n_checkaux_okay),
47675 - atomic_read(&fscache_n_checkaux_update),
47676 - atomic_read(&fscache_n_checkaux_obsolete));
47677 + atomic_read_unchecked(&fscache_n_checkaux_none),
47678 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47679 + atomic_read_unchecked(&fscache_n_checkaux_update),
47680 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47681
47682 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47683 - atomic_read(&fscache_n_marks),
47684 - atomic_read(&fscache_n_uncaches));
47685 + atomic_read_unchecked(&fscache_n_marks),
47686 + atomic_read_unchecked(&fscache_n_uncaches));
47687
47688 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47689 " oom=%u\n",
47690 - atomic_read(&fscache_n_acquires),
47691 - atomic_read(&fscache_n_acquires_null),
47692 - atomic_read(&fscache_n_acquires_no_cache),
47693 - atomic_read(&fscache_n_acquires_ok),
47694 - atomic_read(&fscache_n_acquires_nobufs),
47695 - atomic_read(&fscache_n_acquires_oom));
47696 + atomic_read_unchecked(&fscache_n_acquires),
47697 + atomic_read_unchecked(&fscache_n_acquires_null),
47698 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47699 + atomic_read_unchecked(&fscache_n_acquires_ok),
47700 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47701 + atomic_read_unchecked(&fscache_n_acquires_oom));
47702
47703 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47704 - atomic_read(&fscache_n_object_lookups),
47705 - atomic_read(&fscache_n_object_lookups_negative),
47706 - atomic_read(&fscache_n_object_lookups_positive),
47707 - atomic_read(&fscache_n_object_created),
47708 - atomic_read(&fscache_n_object_lookups_timed_out));
47709 + atomic_read_unchecked(&fscache_n_object_lookups),
47710 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47711 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47712 + atomic_read_unchecked(&fscache_n_object_created),
47713 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47714
47715 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47716 - atomic_read(&fscache_n_updates),
47717 - atomic_read(&fscache_n_updates_null),
47718 - atomic_read(&fscache_n_updates_run));
47719 + atomic_read_unchecked(&fscache_n_updates),
47720 + atomic_read_unchecked(&fscache_n_updates_null),
47721 + atomic_read_unchecked(&fscache_n_updates_run));
47722
47723 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47724 - atomic_read(&fscache_n_relinquishes),
47725 - atomic_read(&fscache_n_relinquishes_null),
47726 - atomic_read(&fscache_n_relinquishes_waitcrt),
47727 - atomic_read(&fscache_n_relinquishes_retire));
47728 + atomic_read_unchecked(&fscache_n_relinquishes),
47729 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47730 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47731 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47732
47733 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47734 - atomic_read(&fscache_n_attr_changed),
47735 - atomic_read(&fscache_n_attr_changed_ok),
47736 - atomic_read(&fscache_n_attr_changed_nobufs),
47737 - atomic_read(&fscache_n_attr_changed_nomem),
47738 - atomic_read(&fscache_n_attr_changed_calls));
47739 + atomic_read_unchecked(&fscache_n_attr_changed),
47740 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47741 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47742 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47743 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47744
47745 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47746 - atomic_read(&fscache_n_allocs),
47747 - atomic_read(&fscache_n_allocs_ok),
47748 - atomic_read(&fscache_n_allocs_wait),
47749 - atomic_read(&fscache_n_allocs_nobufs),
47750 - atomic_read(&fscache_n_allocs_intr));
47751 + atomic_read_unchecked(&fscache_n_allocs),
47752 + atomic_read_unchecked(&fscache_n_allocs_ok),
47753 + atomic_read_unchecked(&fscache_n_allocs_wait),
47754 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47755 + atomic_read_unchecked(&fscache_n_allocs_intr));
47756 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47757 - atomic_read(&fscache_n_alloc_ops),
47758 - atomic_read(&fscache_n_alloc_op_waits),
47759 - atomic_read(&fscache_n_allocs_object_dead));
47760 + atomic_read_unchecked(&fscache_n_alloc_ops),
47761 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47762 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47763
47764 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47765 " int=%u oom=%u\n",
47766 - atomic_read(&fscache_n_retrievals),
47767 - atomic_read(&fscache_n_retrievals_ok),
47768 - atomic_read(&fscache_n_retrievals_wait),
47769 - atomic_read(&fscache_n_retrievals_nodata),
47770 - atomic_read(&fscache_n_retrievals_nobufs),
47771 - atomic_read(&fscache_n_retrievals_intr),
47772 - atomic_read(&fscache_n_retrievals_nomem));
47773 + atomic_read_unchecked(&fscache_n_retrievals),
47774 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47775 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47776 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47777 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47778 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47779 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47780 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47781 - atomic_read(&fscache_n_retrieval_ops),
47782 - atomic_read(&fscache_n_retrieval_op_waits),
47783 - atomic_read(&fscache_n_retrievals_object_dead));
47784 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47785 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47786 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47787
47788 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47789 - atomic_read(&fscache_n_stores),
47790 - atomic_read(&fscache_n_stores_ok),
47791 - atomic_read(&fscache_n_stores_again),
47792 - atomic_read(&fscache_n_stores_nobufs),
47793 - atomic_read(&fscache_n_stores_oom));
47794 + atomic_read_unchecked(&fscache_n_stores),
47795 + atomic_read_unchecked(&fscache_n_stores_ok),
47796 + atomic_read_unchecked(&fscache_n_stores_again),
47797 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47798 + atomic_read_unchecked(&fscache_n_stores_oom));
47799 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47800 - atomic_read(&fscache_n_store_ops),
47801 - atomic_read(&fscache_n_store_calls),
47802 - atomic_read(&fscache_n_store_pages),
47803 - atomic_read(&fscache_n_store_radix_deletes),
47804 - atomic_read(&fscache_n_store_pages_over_limit));
47805 + atomic_read_unchecked(&fscache_n_store_ops),
47806 + atomic_read_unchecked(&fscache_n_store_calls),
47807 + atomic_read_unchecked(&fscache_n_store_pages),
47808 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47809 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47810
47811 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47812 - atomic_read(&fscache_n_store_vmscan_not_storing),
47813 - atomic_read(&fscache_n_store_vmscan_gone),
47814 - atomic_read(&fscache_n_store_vmscan_busy),
47815 - atomic_read(&fscache_n_store_vmscan_cancelled));
47816 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47817 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47818 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47819 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47820
47821 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47822 - atomic_read(&fscache_n_op_pend),
47823 - atomic_read(&fscache_n_op_run),
47824 - atomic_read(&fscache_n_op_enqueue),
47825 - atomic_read(&fscache_n_op_cancelled),
47826 - atomic_read(&fscache_n_op_rejected));
47827 + atomic_read_unchecked(&fscache_n_op_pend),
47828 + atomic_read_unchecked(&fscache_n_op_run),
47829 + atomic_read_unchecked(&fscache_n_op_enqueue),
47830 + atomic_read_unchecked(&fscache_n_op_cancelled),
47831 + atomic_read_unchecked(&fscache_n_op_rejected));
47832 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47833 - atomic_read(&fscache_n_op_deferred_release),
47834 - atomic_read(&fscache_n_op_release),
47835 - atomic_read(&fscache_n_op_gc));
47836 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47837 + atomic_read_unchecked(&fscache_n_op_release),
47838 + atomic_read_unchecked(&fscache_n_op_gc));
47839
47840 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47841 atomic_read(&fscache_n_cop_alloc_object),
47842 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47843 index ee8d550..7189d8c 100644
47844 --- a/fs/fuse/cuse.c
47845 +++ b/fs/fuse/cuse.c
47846 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47847 INIT_LIST_HEAD(&cuse_conntbl[i]);
47848
47849 /* inherit and extend fuse_dev_operations */
47850 - cuse_channel_fops = fuse_dev_operations;
47851 - cuse_channel_fops.owner = THIS_MODULE;
47852 - cuse_channel_fops.open = cuse_channel_open;
47853 - cuse_channel_fops.release = cuse_channel_release;
47854 + pax_open_kernel();
47855 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47856 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47857 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47858 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47859 + pax_close_kernel();
47860
47861 cuse_class = class_create(THIS_MODULE, "cuse");
47862 if (IS_ERR(cuse_class))
47863 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47864 index f4246cf..b4aed1d 100644
47865 --- a/fs/fuse/dev.c
47866 +++ b/fs/fuse/dev.c
47867 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47868 ret = 0;
47869 pipe_lock(pipe);
47870
47871 - if (!pipe->readers) {
47872 + if (!atomic_read(&pipe->readers)) {
47873 send_sig(SIGPIPE, current, 0);
47874 if (!ret)
47875 ret = -EPIPE;
47876 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47877 index 324bc08..4fdd56e 100644
47878 --- a/fs/fuse/dir.c
47879 +++ b/fs/fuse/dir.c
47880 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47881 return link;
47882 }
47883
47884 -static void free_link(char *link)
47885 +static void free_link(const char *link)
47886 {
47887 if (!IS_ERR(link))
47888 free_page((unsigned long) link);
47889 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47890 index 753af3d..f7b021a 100644
47891 --- a/fs/gfs2/inode.c
47892 +++ b/fs/gfs2/inode.c
47893 @@ -1498,7 +1498,7 @@ out:
47894
47895 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47896 {
47897 - char *s = nd_get_link(nd);
47898 + const char *s = nd_get_link(nd);
47899 if (!IS_ERR(s))
47900 kfree(s);
47901 }
47902 diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
47903 index a3bde91..2524579 100644
47904 --- a/fs/gfs2/quota.c
47905 +++ b/fs/gfs2/quota.c
47906 @@ -497,8 +497,11 @@ int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
47907 struct gfs2_quota_data **qd;
47908 int error;
47909
47910 - if (ip->i_res == NULL)
47911 - gfs2_rs_alloc(ip);
47912 + if (ip->i_res == NULL) {
47913 + error = gfs2_rs_alloc(ip);
47914 + if (error)
47915 + return error;
47916 + }
47917
47918 qd = ip->i_res->rs_qa_qd;
47919
47920 diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
47921 index c9ed814..4a45d5f 100644
47922 --- a/fs/gfs2/rgrp.c
47923 +++ b/fs/gfs2/rgrp.c
47924 @@ -477,7 +477,6 @@ void gfs2_free_clones(struct gfs2_rgrpd *rgd)
47925 */
47926 int gfs2_rs_alloc(struct gfs2_inode *ip)
47927 {
47928 - int error = 0;
47929 struct gfs2_blkreserv *res;
47930
47931 if (ip->i_res)
47932 @@ -485,7 +484,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47933
47934 res = kmem_cache_zalloc(gfs2_rsrv_cachep, GFP_NOFS);
47935 if (!res)
47936 - error = -ENOMEM;
47937 + return -ENOMEM;
47938
47939 down_write(&ip->i_rw_mutex);
47940 if (ip->i_res)
47941 @@ -493,7 +492,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47942 else
47943 ip->i_res = res;
47944 up_write(&ip->i_rw_mutex);
47945 - return error;
47946 + return 0;
47947 }
47948
47949 static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs)
47950 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47951 index 8349a89..51a0254 100644
47952 --- a/fs/hugetlbfs/inode.c
47953 +++ b/fs/hugetlbfs/inode.c
47954 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47955 .kill_sb = kill_litter_super,
47956 };
47957
47958 -static struct vfsmount *hugetlbfs_vfsmount;
47959 +struct vfsmount *hugetlbfs_vfsmount;
47960
47961 static int can_do_hugetlb_shm(void)
47962 {
47963 diff --git a/fs/inode.c b/fs/inode.c
47964 index ac8d904..9f45d40 100644
47965 --- a/fs/inode.c
47966 +++ b/fs/inode.c
47967 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47968
47969 #ifdef CONFIG_SMP
47970 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47971 - static atomic_t shared_last_ino;
47972 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47973 + static atomic_unchecked_t shared_last_ino;
47974 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47975
47976 res = next - LAST_INO_BATCH;
47977 }
47978 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47979 index 4a6cf28..d3a29d3 100644
47980 --- a/fs/jffs2/erase.c
47981 +++ b/fs/jffs2/erase.c
47982 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47983 struct jffs2_unknown_node marker = {
47984 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47985 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47986 - .totlen = cpu_to_je32(c->cleanmarker_size)
47987 + .totlen = cpu_to_je32(c->cleanmarker_size),
47988 + .hdr_crc = cpu_to_je32(0)
47989 };
47990
47991 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47992 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47993 index a6597d6..41b30ec 100644
47994 --- a/fs/jffs2/wbuf.c
47995 +++ b/fs/jffs2/wbuf.c
47996 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47997 {
47998 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47999 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
48000 - .totlen = constant_cpu_to_je32(8)
48001 + .totlen = constant_cpu_to_je32(8),
48002 + .hdr_crc = constant_cpu_to_je32(0)
48003 };
48004
48005 /*
48006 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
48007 index c55c745..f67ee56 100644
48008 --- a/fs/jfs/super.c
48009 +++ b/fs/jfs/super.c
48010 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
48011
48012 jfs_inode_cachep =
48013 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
48014 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
48015 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
48016 init_once);
48017 if (jfs_inode_cachep == NULL)
48018 return -ENOMEM;
48019 diff --git a/fs/libfs.c b/fs/libfs.c
48020 index a74cb17..37fcbe4 100644
48021 --- a/fs/libfs.c
48022 +++ b/fs/libfs.c
48023 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
48024
48025 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
48026 struct dentry *next;
48027 + char d_name[sizeof(next->d_iname)];
48028 + const unsigned char *name;
48029 +
48030 next = list_entry(p, struct dentry, d_u.d_child);
48031 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
48032 if (!simple_positive(next)) {
48033 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
48034
48035 spin_unlock(&next->d_lock);
48036 spin_unlock(&dentry->d_lock);
48037 - if (filldir(dirent, next->d_name.name,
48038 + name = next->d_name.name;
48039 + if (name == next->d_iname) {
48040 + memcpy(d_name, name, next->d_name.len);
48041 + name = d_name;
48042 + }
48043 + if (filldir(dirent, name,
48044 next->d_name.len, filp->f_pos,
48045 next->d_inode->i_ino,
48046 dt_type(next->d_inode)) < 0)
48047 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
48048 index 05d2912..760abfa 100644
48049 --- a/fs/lockd/clntproc.c
48050 +++ b/fs/lockd/clntproc.c
48051 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
48052 /*
48053 * Cookie counter for NLM requests
48054 */
48055 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
48056 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
48057
48058 void nlmclnt_next_cookie(struct nlm_cookie *c)
48059 {
48060 - u32 cookie = atomic_inc_return(&nlm_cookie);
48061 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
48062
48063 memcpy(c->data, &cookie, 4);
48064 c->len=4;
48065 diff --git a/fs/locks.c b/fs/locks.c
48066 index 7e81bfc..c3649aa 100644
48067 --- a/fs/locks.c
48068 +++ b/fs/locks.c
48069 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
48070 return;
48071
48072 if (filp->f_op && filp->f_op->flock) {
48073 - struct file_lock fl = {
48074 + struct file_lock flock = {
48075 .fl_pid = current->tgid,
48076 .fl_file = filp,
48077 .fl_flags = FL_FLOCK,
48078 .fl_type = F_UNLCK,
48079 .fl_end = OFFSET_MAX,
48080 };
48081 - filp->f_op->flock(filp, F_SETLKW, &fl);
48082 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
48083 - fl.fl_ops->fl_release_private(&fl);
48084 + filp->f_op->flock(filp, F_SETLKW, &flock);
48085 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
48086 + flock.fl_ops->fl_release_private(&flock);
48087 }
48088
48089 lock_flocks();
48090 diff --git a/fs/namei.c b/fs/namei.c
48091 index 091c4b7..fbcb268 100644
48092 --- a/fs/namei.c
48093 +++ b/fs/namei.c
48094 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
48095 if (ret != -EACCES)
48096 return ret;
48097
48098 +#ifdef CONFIG_GRKERNSEC
48099 + /* we'll block if we have to log due to a denied capability use */
48100 + if (mask & MAY_NOT_BLOCK)
48101 + return -ECHILD;
48102 +#endif
48103 +
48104 if (S_ISDIR(inode->i_mode)) {
48105 /* DACs are overridable for directories */
48106 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
48107 - return 0;
48108 if (!(mask & MAY_WRITE))
48109 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
48110 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
48111 + inode_capable(inode, CAP_DAC_READ_SEARCH))
48112 return 0;
48113 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
48114 + return 0;
48115 return -EACCES;
48116 }
48117 /*
48118 + * Searching includes executable on directories, else just read.
48119 + */
48120 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48121 + if (mask == MAY_READ)
48122 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
48123 + inode_capable(inode, CAP_DAC_READ_SEARCH))
48124 + return 0;
48125 +
48126 + /*
48127 * Read/write DACs are always overridable.
48128 * Executable DACs are overridable when there is
48129 * at least one exec bit set.
48130 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
48131 if (inode_capable(inode, CAP_DAC_OVERRIDE))
48132 return 0;
48133
48134 - /*
48135 - * Searching includes executable on directories, else just read.
48136 - */
48137 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48138 - if (mask == MAY_READ)
48139 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
48140 - return 0;
48141 -
48142 return -EACCES;
48143 }
48144
48145 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
48146 {
48147 struct dentry *dentry = link->dentry;
48148 int error;
48149 - char *s;
48150 + const char *s;
48151
48152 BUG_ON(nd->flags & LOOKUP_RCU);
48153
48154 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
48155 if (error)
48156 goto out_put_nd_path;
48157
48158 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
48159 + dentry->d_inode, dentry, nd->path.mnt)) {
48160 + error = -EACCES;
48161 + goto out_put_nd_path;
48162 + }
48163 +
48164 nd->last_type = LAST_BIND;
48165 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
48166 error = PTR_ERR(*p);
48167 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
48168 break;
48169 res = walk_component(nd, path, &nd->last,
48170 nd->last_type, LOOKUP_FOLLOW);
48171 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
48172 + res = -EACCES;
48173 put_link(nd, &link, cookie);
48174 } while (res > 0);
48175
48176 @@ -1648,7 +1664,7 @@ EXPORT_SYMBOL(full_name_hash);
48177 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
48178 {
48179 unsigned long a, b, adata, bdata, mask, hash, len;
48180 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
48181 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
48182
48183 hash = a = 0;
48184 len = -sizeof(unsigned long);
48185 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
48186 if (err)
48187 break;
48188 err = lookup_last(nd, &path);
48189 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
48190 + err = -EACCES;
48191 put_link(nd, &link, cookie);
48192 }
48193 }
48194 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
48195 if (!err)
48196 err = complete_walk(nd);
48197
48198 + if (!(nd->flags & LOOKUP_PARENT)) {
48199 +#ifdef CONFIG_GRKERNSEC
48200 + if (flags & LOOKUP_RCU) {
48201 + if (!err)
48202 + path_put(&nd->path);
48203 + err = -ECHILD;
48204 + } else
48205 +#endif
48206 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48207 + if (!err)
48208 + path_put(&nd->path);
48209 + err = -ENOENT;
48210 + }
48211 + }
48212 +
48213 if (!err && nd->flags & LOOKUP_DIRECTORY) {
48214 if (!nd->inode->i_op->lookup) {
48215 path_put(&nd->path);
48216 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
48217 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
48218
48219 if (likely(!retval)) {
48220 + if (*name != '/' && nd->path.dentry && nd->inode) {
48221 +#ifdef CONFIG_GRKERNSEC
48222 + if (flags & LOOKUP_RCU)
48223 + return -ECHILD;
48224 +#endif
48225 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
48226 + return -ENOENT;
48227 + }
48228 +
48229 if (unlikely(!audit_dummy_context())) {
48230 if (nd->path.dentry && nd->inode)
48231 audit_inode(name, nd->path.dentry);
48232 @@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
48233 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
48234 return -EPERM;
48235
48236 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
48237 + return -EPERM;
48238 + if (gr_handle_rawio(inode))
48239 + return -EPERM;
48240 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
48241 + return -EACCES;
48242 +
48243 return 0;
48244 }
48245
48246 @@ -2557,7 +2606,7 @@ looked_up:
48247 * cleared otherwise prior to returning.
48248 */
48249 static int lookup_open(struct nameidata *nd, struct path *path,
48250 - struct file *file,
48251 + struct path *link, struct file *file,
48252 const struct open_flags *op,
48253 bool got_write, int *opened)
48254 {
48255 @@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
48256 /* Negative dentry, just create the file */
48257 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
48258 umode_t mode = op->mode;
48259 +
48260 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
48261 + error = -EACCES;
48262 + goto out_dput;
48263 + }
48264 +
48265 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
48266 + error = -EACCES;
48267 + goto out_dput;
48268 + }
48269 +
48270 if (!IS_POSIXACL(dir->d_inode))
48271 mode &= ~current_umask();
48272 /*
48273 @@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
48274 nd->flags & LOOKUP_EXCL);
48275 if (error)
48276 goto out_dput;
48277 + else
48278 + gr_handle_create(dentry, nd->path.mnt);
48279 }
48280 out_no_open:
48281 path->dentry = dentry;
48282 @@ -2627,7 +2689,7 @@ out_dput:
48283 /*
48284 * Handle the last step of open()
48285 */
48286 -static int do_last(struct nameidata *nd, struct path *path,
48287 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
48288 struct file *file, const struct open_flags *op,
48289 int *opened, const char *pathname)
48290 {
48291 @@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
48292 error = complete_walk(nd);
48293 if (error)
48294 return error;
48295 +#ifdef CONFIG_GRKERNSEC
48296 + if (nd->flags & LOOKUP_RCU) {
48297 + error = -ECHILD;
48298 + goto out;
48299 + }
48300 +#endif
48301 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48302 + error = -ENOENT;
48303 + goto out;
48304 + }
48305 audit_inode(pathname, nd->path.dentry);
48306 if (open_flag & O_CREAT) {
48307 error = -EISDIR;
48308 goto out;
48309 }
48310 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48311 + error = -EACCES;
48312 + goto out;
48313 + }
48314 goto finish_open;
48315 case LAST_BIND:
48316 error = complete_walk(nd);
48317 if (error)
48318 return error;
48319 +#ifdef CONFIG_GRKERNSEC
48320 + if (nd->flags & LOOKUP_RCU) {
48321 + error = -ECHILD;
48322 + goto out;
48323 + }
48324 +#endif
48325 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
48326 + error = -ENOENT;
48327 + goto out;
48328 + }
48329 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48330 + error = -EACCES;
48331 + goto out;
48332 + }
48333 audit_inode(pathname, dir);
48334 goto finish_open;
48335 }
48336 @@ -2714,7 +2804,7 @@ retry_lookup:
48337 */
48338 }
48339 mutex_lock(&dir->d_inode->i_mutex);
48340 - error = lookup_open(nd, path, file, op, got_write, opened);
48341 + error = lookup_open(nd, path, link, file, op, got_write, opened);
48342 mutex_unlock(&dir->d_inode->i_mutex);
48343
48344 if (error <= 0) {
48345 @@ -2738,11 +2828,28 @@ retry_lookup:
48346 goto finish_open_created;
48347 }
48348
48349 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
48350 + error = -ENOENT;
48351 + goto exit_dput;
48352 + }
48353 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
48354 + error = -EACCES;
48355 + goto exit_dput;
48356 + }
48357 +
48358 /*
48359 * create/update audit record if it already exists.
48360 */
48361 - if (path->dentry->d_inode)
48362 + if (path->dentry->d_inode) {
48363 + /* only check if O_CREAT is specified, all other checks need to go
48364 + into may_open */
48365 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
48366 + error = -EACCES;
48367 + goto exit_dput;
48368 + }
48369 +
48370 audit_inode(pathname, path->dentry);
48371 + }
48372
48373 /*
48374 * If atomic_open() acquired write access it is dropped now due to
48375 @@ -2783,6 +2890,11 @@ finish_lookup:
48376 }
48377 }
48378 BUG_ON(inode != path->dentry->d_inode);
48379 + /* if we're resolving a symlink to another symlink */
48380 + if (link && gr_handle_symlink_owner(link, inode)) {
48381 + error = -EACCES;
48382 + goto out;
48383 + }
48384 return 1;
48385 }
48386
48387 @@ -2792,7 +2904,6 @@ finish_lookup:
48388 save_parent.dentry = nd->path.dentry;
48389 save_parent.mnt = mntget(path->mnt);
48390 nd->path.dentry = path->dentry;
48391 -
48392 }
48393 nd->inode = inode;
48394 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
48395 @@ -2801,6 +2912,22 @@ finish_lookup:
48396 path_put(&save_parent);
48397 return error;
48398 }
48399 +
48400 +#ifdef CONFIG_GRKERNSEC
48401 + if (nd->flags & LOOKUP_RCU) {
48402 + error = -ECHILD;
48403 + goto out;
48404 + }
48405 +#endif
48406 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48407 + error = -ENOENT;
48408 + goto out;
48409 + }
48410 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48411 + error = -EACCES;
48412 + goto out;
48413 + }
48414 +
48415 error = -EISDIR;
48416 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
48417 goto out;
48418 @@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48419 if (unlikely(error))
48420 goto out;
48421
48422 - error = do_last(nd, &path, file, op, &opened, pathname);
48423 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
48424 while (unlikely(error > 0)) { /* trailing symlink */
48425 struct path link = path;
48426 void *cookie;
48427 @@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48428 error = follow_link(&link, nd, &cookie);
48429 if (unlikely(error))
48430 break;
48431 - error = do_last(nd, &path, file, op, &opened, pathname);
48432 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
48433 put_link(nd, &link, cookie);
48434 }
48435 out:
48436 @@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
48437 goto unlock;
48438
48439 error = -EEXIST;
48440 - if (dentry->d_inode)
48441 + if (dentry->d_inode) {
48442 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
48443 + error = -ENOENT;
48444 + }
48445 goto fail;
48446 + }
48447 /*
48448 * Special case - lookup gave negative, but... we had foo/bar/
48449 * From the vfs_mknod() POV we just have a negative dentry -
48450 @@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
48451 }
48452 EXPORT_SYMBOL(user_path_create);
48453
48454 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
48455 +{
48456 + char *tmp = getname(pathname);
48457 + struct dentry *res;
48458 + if (IS_ERR(tmp))
48459 + return ERR_CAST(tmp);
48460 + res = kern_path_create(dfd, tmp, path, is_dir);
48461 + if (IS_ERR(res))
48462 + putname(tmp);
48463 + else
48464 + *to = tmp;
48465 + return res;
48466 +}
48467 +
48468 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
48469 {
48470 int error = may_create(dir, dentry);
48471 @@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48472
48473 if (!IS_POSIXACL(path.dentry->d_inode))
48474 mode &= ~current_umask();
48475 +
48476 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
48477 + error = -EPERM;
48478 + goto out;
48479 + }
48480 +
48481 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
48482 + error = -EACCES;
48483 + goto out;
48484 + }
48485 +
48486 error = security_path_mknod(&path, dentry, mode, dev);
48487 if (error)
48488 goto out;
48489 @@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48490 break;
48491 }
48492 out:
48493 + if (!error)
48494 + gr_handle_create(dentry, path.mnt);
48495 done_path_create(&path, dentry);
48496 return error;
48497 }
48498 @@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
48499
48500 if (!IS_POSIXACL(path.dentry->d_inode))
48501 mode &= ~current_umask();
48502 +
48503 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
48504 + error = -EACCES;
48505 + goto out;
48506 + }
48507 +
48508 error = security_path_mkdir(&path, dentry, mode);
48509 if (!error)
48510 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48511 + if (!error)
48512 + gr_handle_create(dentry, path.mnt);
48513 +out:
48514 done_path_create(&path, dentry);
48515 return error;
48516 }
48517 @@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48518 char * name;
48519 struct dentry *dentry;
48520 struct nameidata nd;
48521 + ino_t saved_ino = 0;
48522 + dev_t saved_dev = 0;
48523
48524 error = user_path_parent(dfd, pathname, &nd, &name);
48525 if (error)
48526 @@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
48527 error = -ENOENT;
48528 goto exit3;
48529 }
48530 +
48531 + saved_ino = dentry->d_inode->i_ino;
48532 + saved_dev = gr_get_dev_from_dentry(dentry);
48533 +
48534 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48535 + error = -EACCES;
48536 + goto exit3;
48537 + }
48538 +
48539 error = security_path_rmdir(&nd.path, dentry);
48540 if (error)
48541 goto exit3;
48542 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48543 + if (!error && (saved_dev || saved_ino))
48544 + gr_handle_delete(saved_ino, saved_dev);
48545 exit3:
48546 dput(dentry);
48547 exit2:
48548 @@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48549 struct dentry *dentry;
48550 struct nameidata nd;
48551 struct inode *inode = NULL;
48552 + ino_t saved_ino = 0;
48553 + dev_t saved_dev = 0;
48554
48555 error = user_path_parent(dfd, pathname, &nd, &name);
48556 if (error)
48557 @@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48558 if (!inode)
48559 goto slashes;
48560 ihold(inode);
48561 +
48562 + if (inode->i_nlink <= 1) {
48563 + saved_ino = inode->i_ino;
48564 + saved_dev = gr_get_dev_from_dentry(dentry);
48565 + }
48566 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48567 + error = -EACCES;
48568 + goto exit2;
48569 + }
48570 +
48571 error = security_path_unlink(&nd.path, dentry);
48572 if (error)
48573 goto exit2;
48574 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48575 + if (!error && (saved_ino || saved_dev))
48576 + gr_handle_delete(saved_ino, saved_dev);
48577 exit2:
48578 dput(dentry);
48579 }
48580 @@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48581 if (IS_ERR(dentry))
48582 goto out_putname;
48583
48584 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48585 + error = -EACCES;
48586 + goto out;
48587 + }
48588 +
48589 error = security_path_symlink(&path, dentry, from);
48590 if (!error)
48591 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48592 + if (!error)
48593 + gr_handle_create(dentry, path.mnt);
48594 +out:
48595 done_path_create(&path, dentry);
48596 out_putname:
48597 putname(from);
48598 @@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48599 {
48600 struct dentry *new_dentry;
48601 struct path old_path, new_path;
48602 + char *to = NULL;
48603 int how = 0;
48604 int error;
48605
48606 @@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48607 if (error)
48608 return error;
48609
48610 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48611 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48612 error = PTR_ERR(new_dentry);
48613 if (IS_ERR(new_dentry))
48614 goto out;
48615 @@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48616 error = may_linkat(&old_path);
48617 if (unlikely(error))
48618 goto out_dput;
48619 +
48620 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48621 + old_path.dentry->d_inode,
48622 + old_path.dentry->d_inode->i_mode, to)) {
48623 + error = -EACCES;
48624 + goto out_dput;
48625 + }
48626 +
48627 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48628 + old_path.dentry, old_path.mnt, to)) {
48629 + error = -EACCES;
48630 + goto out_dput;
48631 + }
48632 +
48633 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48634 if (error)
48635 goto out_dput;
48636 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48637 + if (!error)
48638 + gr_handle_create(new_dentry, new_path.mnt);
48639 out_dput:
48640 + putname(to);
48641 done_path_create(&new_path, new_dentry);
48642 out:
48643 path_put(&old_path);
48644 @@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48645 if (new_dentry == trap)
48646 goto exit5;
48647
48648 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48649 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48650 + to);
48651 + if (error)
48652 + goto exit5;
48653 +
48654 error = security_path_rename(&oldnd.path, old_dentry,
48655 &newnd.path, new_dentry);
48656 if (error)
48657 goto exit5;
48658 error = vfs_rename(old_dir->d_inode, old_dentry,
48659 new_dir->d_inode, new_dentry);
48660 + if (!error)
48661 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48662 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48663 exit5:
48664 dput(new_dentry);
48665 exit4:
48666 @@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48667
48668 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48669 {
48670 + char tmpbuf[64];
48671 + const char *newlink;
48672 int len;
48673
48674 len = PTR_ERR(link);
48675 @@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48676 len = strlen(link);
48677 if (len > (unsigned) buflen)
48678 len = buflen;
48679 - if (copy_to_user(buffer, link, len))
48680 +
48681 + if (len < sizeof(tmpbuf)) {
48682 + memcpy(tmpbuf, link, len);
48683 + newlink = tmpbuf;
48684 + } else
48685 + newlink = link;
48686 +
48687 + if (copy_to_user(buffer, newlink, len))
48688 len = -EFAULT;
48689 out:
48690 return len;
48691 diff --git a/fs/namespace.c b/fs/namespace.c
48692 index 7bdf790..eb79c4b 100644
48693 --- a/fs/namespace.c
48694 +++ b/fs/namespace.c
48695 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48696 if (!(sb->s_flags & MS_RDONLY))
48697 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48698 up_write(&sb->s_umount);
48699 +
48700 + gr_log_remount(mnt->mnt_devname, retval);
48701 +
48702 return retval;
48703 }
48704
48705 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48706 br_write_unlock(&vfsmount_lock);
48707 up_write(&namespace_sem);
48708 release_mounts(&umount_list);
48709 +
48710 + gr_log_unmount(mnt->mnt_devname, retval);
48711 +
48712 return retval;
48713 }
48714
48715 @@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48716 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48717 MS_STRICTATIME);
48718
48719 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48720 + retval = -EPERM;
48721 + goto dput_out;
48722 + }
48723 +
48724 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48725 + retval = -EPERM;
48726 + goto dput_out;
48727 + }
48728 +
48729 if (flags & MS_REMOUNT)
48730 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48731 data_page);
48732 @@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48733 dev_name, data_page);
48734 dput_out:
48735 path_put(&path);
48736 +
48737 + gr_log_mount(dev_name, dir_name, retval);
48738 +
48739 return retval;
48740 }
48741
48742 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48743 if (error)
48744 goto out2;
48745
48746 + if (gr_handle_chroot_pivot()) {
48747 + error = -EPERM;
48748 + goto out2;
48749 + }
48750 +
48751 get_fs_root(current->fs, &root);
48752 error = lock_mount(&old);
48753 if (error)
48754 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48755 index 9b47610..066975e 100644
48756 --- a/fs/nfs/inode.c
48757 +++ b/fs/nfs/inode.c
48758 @@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48759 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48760 }
48761
48762 -static atomic_long_t nfs_attr_generation_counter;
48763 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48764
48765 static unsigned long nfs_read_attr_generation_counter(void)
48766 {
48767 - return atomic_long_read(&nfs_attr_generation_counter);
48768 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48769 }
48770
48771 unsigned long nfs_inc_attr_generation_counter(void)
48772 {
48773 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48774 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48775 }
48776
48777 void nfs_fattr_init(struct nfs_fattr *fattr)
48778 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48779 index a9269f1..5490437 100644
48780 --- a/fs/nfsd/vfs.c
48781 +++ b/fs/nfsd/vfs.c
48782 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48783 } else {
48784 oldfs = get_fs();
48785 set_fs(KERNEL_DS);
48786 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48787 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48788 set_fs(oldfs);
48789 }
48790
48791 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48792
48793 /* Write the data. */
48794 oldfs = get_fs(); set_fs(KERNEL_DS);
48795 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48796 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48797 set_fs(oldfs);
48798 if (host_err < 0)
48799 goto out_nfserr;
48800 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48801 */
48802
48803 oldfs = get_fs(); set_fs(KERNEL_DS);
48804 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48805 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48806 set_fs(oldfs);
48807
48808 if (host_err < 0)
48809 diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
48810 index f35794b..a506360 100644
48811 --- a/fs/notify/fanotify/fanotify.c
48812 +++ b/fs/notify/fanotify/fanotify.c
48813 @@ -21,6 +21,7 @@ static bool should_merge(struct fsnotify_event *old, struct fsnotify_event *new)
48814 if ((old->path.mnt == new->path.mnt) &&
48815 (old->path.dentry == new->path.dentry))
48816 return true;
48817 + break;
48818 case (FSNOTIFY_EVENT_NONE):
48819 return true;
48820 default:
48821 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48822 index d438036..0ecadde 100644
48823 --- a/fs/notify/fanotify/fanotify_user.c
48824 +++ b/fs/notify/fanotify/fanotify_user.c
48825 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48826 goto out_close_fd;
48827
48828 ret = -EFAULT;
48829 - if (copy_to_user(buf, &fanotify_event_metadata,
48830 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48831 + copy_to_user(buf, &fanotify_event_metadata,
48832 fanotify_event_metadata.event_len))
48833 goto out_kill_access_response;
48834
48835 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48836 index c887b13..0fdf472 100644
48837 --- a/fs/notify/notification.c
48838 +++ b/fs/notify/notification.c
48839 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48840 * get set to 0 so it will never get 'freed'
48841 */
48842 static struct fsnotify_event *q_overflow_event;
48843 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48844 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48845
48846 /**
48847 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48848 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48849 */
48850 u32 fsnotify_get_cookie(void)
48851 {
48852 - return atomic_inc_return(&fsnotify_sync_cookie);
48853 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48854 }
48855 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48856
48857 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48858 index 99e3610..02c1068 100644
48859 --- a/fs/ntfs/dir.c
48860 +++ b/fs/ntfs/dir.c
48861 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48862 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48863 ~(s64)(ndir->itype.index.block_size - 1)));
48864 /* Bounds checks. */
48865 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48866 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48867 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48868 "inode 0x%lx or driver bug.", vdir->i_ino);
48869 goto err_out;
48870 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48871 index 1ecf464..e1ff8bf 100644
48872 --- a/fs/ntfs/file.c
48873 +++ b/fs/ntfs/file.c
48874 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48875 #endif /* NTFS_RW */
48876 };
48877
48878 -const struct file_operations ntfs_empty_file_ops = {};
48879 +const struct file_operations ntfs_empty_file_ops __read_only;
48880
48881 -const struct inode_operations ntfs_empty_inode_ops = {};
48882 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48883 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48884 index a9f78c7..ed8a381 100644
48885 --- a/fs/ocfs2/localalloc.c
48886 +++ b/fs/ocfs2/localalloc.c
48887 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48888 goto bail;
48889 }
48890
48891 - atomic_inc(&osb->alloc_stats.moves);
48892 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48893
48894 bail:
48895 if (handle)
48896 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48897 index d355e6e..578d905 100644
48898 --- a/fs/ocfs2/ocfs2.h
48899 +++ b/fs/ocfs2/ocfs2.h
48900 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48901
48902 struct ocfs2_alloc_stats
48903 {
48904 - atomic_t moves;
48905 - atomic_t local_data;
48906 - atomic_t bitmap_data;
48907 - atomic_t bg_allocs;
48908 - atomic_t bg_extends;
48909 + atomic_unchecked_t moves;
48910 + atomic_unchecked_t local_data;
48911 + atomic_unchecked_t bitmap_data;
48912 + atomic_unchecked_t bg_allocs;
48913 + atomic_unchecked_t bg_extends;
48914 };
48915
48916 enum ocfs2_local_alloc_state
48917 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48918 index f169da4..9112253 100644
48919 --- a/fs/ocfs2/suballoc.c
48920 +++ b/fs/ocfs2/suballoc.c
48921 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48922 mlog_errno(status);
48923 goto bail;
48924 }
48925 - atomic_inc(&osb->alloc_stats.bg_extends);
48926 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48927
48928 /* You should never ask for this much metadata */
48929 BUG_ON(bits_wanted >
48930 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48931 mlog_errno(status);
48932 goto bail;
48933 }
48934 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48935 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48936
48937 *suballoc_loc = res.sr_bg_blkno;
48938 *suballoc_bit_start = res.sr_bit_offset;
48939 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48940 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48941 res->sr_bits);
48942
48943 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48944 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48945
48946 BUG_ON(res->sr_bits != 1);
48947
48948 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48949 mlog_errno(status);
48950 goto bail;
48951 }
48952 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48953 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48954
48955 BUG_ON(res.sr_bits != 1);
48956
48957 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48958 cluster_start,
48959 num_clusters);
48960 if (!status)
48961 - atomic_inc(&osb->alloc_stats.local_data);
48962 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48963 } else {
48964 if (min_clusters > (osb->bitmap_cpg - 1)) {
48965 /* The only paths asking for contiguousness
48966 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48967 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48968 res.sr_bg_blkno,
48969 res.sr_bit_offset);
48970 - atomic_inc(&osb->alloc_stats.bitmap_data);
48971 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48972 *num_clusters = res.sr_bits;
48973 }
48974 }
48975 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48976 index 68f4541..89cfe6a 100644
48977 --- a/fs/ocfs2/super.c
48978 +++ b/fs/ocfs2/super.c
48979 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48980 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48981 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48982 "Stats",
48983 - atomic_read(&osb->alloc_stats.bitmap_data),
48984 - atomic_read(&osb->alloc_stats.local_data),
48985 - atomic_read(&osb->alloc_stats.bg_allocs),
48986 - atomic_read(&osb->alloc_stats.moves),
48987 - atomic_read(&osb->alloc_stats.bg_extends));
48988 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48989 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48990 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48991 + atomic_read_unchecked(&osb->alloc_stats.moves),
48992 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48993
48994 out += snprintf(buf + out, len - out,
48995 "%10s => State: %u Descriptor: %llu Size: %u bits "
48996 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48997 spin_lock_init(&osb->osb_xattr_lock);
48998 ocfs2_init_steal_slots(osb);
48999
49000 - atomic_set(&osb->alloc_stats.moves, 0);
49001 - atomic_set(&osb->alloc_stats.local_data, 0);
49002 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
49003 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
49004 - atomic_set(&osb->alloc_stats.bg_extends, 0);
49005 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
49006 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
49007 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
49008 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
49009 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
49010
49011 /* Copy the blockcheck stats from the superblock probe */
49012 osb->osb_ecc_stats = *stats;
49013 diff --git a/fs/open.c b/fs/open.c
49014 index e1f2cdb..3bd5f39 100644
49015 --- a/fs/open.c
49016 +++ b/fs/open.c
49017 @@ -31,6 +31,8 @@
49018 #include <linux/ima.h>
49019 #include <linux/dnotify.h>
49020
49021 +#define CREATE_TRACE_POINTS
49022 +#include <trace/events/fs.h>
49023 #include "internal.h"
49024
49025 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
49026 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
49027 error = locks_verify_truncate(inode, NULL, length);
49028 if (!error)
49029 error = security_path_truncate(&path);
49030 +
49031 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
49032 + error = -EACCES;
49033 +
49034 if (!error)
49035 error = do_truncate(path.dentry, length, 0, NULL);
49036
49037 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
49038 if (__mnt_is_readonly(path.mnt))
49039 res = -EROFS;
49040
49041 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
49042 + res = -EACCES;
49043 +
49044 out_path_release:
49045 path_put(&path);
49046 out:
49047 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
49048 if (error)
49049 goto dput_and_out;
49050
49051 + gr_log_chdir(path.dentry, path.mnt);
49052 +
49053 set_fs_pwd(current->fs, &path);
49054
49055 dput_and_out:
49056 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
49057 goto out_putf;
49058
49059 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
49060 +
49061 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
49062 + error = -EPERM;
49063 +
49064 + if (!error)
49065 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
49066 +
49067 if (!error)
49068 set_fs_pwd(current->fs, &file->f_path);
49069 out_putf:
49070 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
49071 if (error)
49072 goto dput_and_out;
49073
49074 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
49075 + goto dput_and_out;
49076 +
49077 set_fs_root(current->fs, &path);
49078 +
49079 + gr_handle_chroot_chdir(&path);
49080 +
49081 error = 0;
49082 dput_and_out:
49083 path_put(&path);
49084 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
49085 if (error)
49086 return error;
49087 mutex_lock(&inode->i_mutex);
49088 +
49089 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
49090 + error = -EACCES;
49091 + goto out_unlock;
49092 + }
49093 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
49094 + error = -EACCES;
49095 + goto out_unlock;
49096 + }
49097 +
49098 error = security_path_chmod(path, mode);
49099 if (error)
49100 goto out_unlock;
49101 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
49102 uid = make_kuid(current_user_ns(), user);
49103 gid = make_kgid(current_user_ns(), group);
49104
49105 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
49106 + return -EACCES;
49107 +
49108 newattrs.ia_valid = ATTR_CTIME;
49109 if (user != (uid_t) -1) {
49110 if (!uid_valid(uid))
49111 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
49112 } else {
49113 fsnotify_open(f);
49114 fd_install(fd, f);
49115 + trace_do_sys_open(tmp, flags, mode);
49116 }
49117 }
49118 putname(tmp);
49119 diff --git a/fs/pipe.c b/fs/pipe.c
49120 index 8d85d70..581036b 100644
49121 --- a/fs/pipe.c
49122 +++ b/fs/pipe.c
49123 @@ -438,9 +438,9 @@ redo:
49124 }
49125 if (bufs) /* More to do? */
49126 continue;
49127 - if (!pipe->writers)
49128 + if (!atomic_read(&pipe->writers))
49129 break;
49130 - if (!pipe->waiting_writers) {
49131 + if (!atomic_read(&pipe->waiting_writers)) {
49132 /* syscall merging: Usually we must not sleep
49133 * if O_NONBLOCK is set, or if we got some data.
49134 * But if a writer sleeps in kernel space, then
49135 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
49136 mutex_lock(&inode->i_mutex);
49137 pipe = inode->i_pipe;
49138
49139 - if (!pipe->readers) {
49140 + if (!atomic_read(&pipe->readers)) {
49141 send_sig(SIGPIPE, current, 0);
49142 ret = -EPIPE;
49143 goto out;
49144 @@ -553,7 +553,7 @@ redo1:
49145 for (;;) {
49146 int bufs;
49147
49148 - if (!pipe->readers) {
49149 + if (!atomic_read(&pipe->readers)) {
49150 send_sig(SIGPIPE, current, 0);
49151 if (!ret)
49152 ret = -EPIPE;
49153 @@ -644,9 +644,9 @@ redo2:
49154 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49155 do_wakeup = 0;
49156 }
49157 - pipe->waiting_writers++;
49158 + atomic_inc(&pipe->waiting_writers);
49159 pipe_wait(pipe);
49160 - pipe->waiting_writers--;
49161 + atomic_dec(&pipe->waiting_writers);
49162 }
49163 out:
49164 mutex_unlock(&inode->i_mutex);
49165 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
49166 mask = 0;
49167 if (filp->f_mode & FMODE_READ) {
49168 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
49169 - if (!pipe->writers && filp->f_version != pipe->w_counter)
49170 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
49171 mask |= POLLHUP;
49172 }
49173
49174 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
49175 * Most Unices do not set POLLERR for FIFOs but on Linux they
49176 * behave exactly like pipes for poll().
49177 */
49178 - if (!pipe->readers)
49179 + if (!atomic_read(&pipe->readers))
49180 mask |= POLLERR;
49181 }
49182
49183 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
49184
49185 mutex_lock(&inode->i_mutex);
49186 pipe = inode->i_pipe;
49187 - pipe->readers -= decr;
49188 - pipe->writers -= decw;
49189 + atomic_sub(decr, &pipe->readers);
49190 + atomic_sub(decw, &pipe->writers);
49191
49192 - if (!pipe->readers && !pipe->writers) {
49193 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
49194 free_pipe_info(inode);
49195 } else {
49196 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
49197 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
49198
49199 if (inode->i_pipe) {
49200 ret = 0;
49201 - inode->i_pipe->readers++;
49202 + atomic_inc(&inode->i_pipe->readers);
49203 }
49204
49205 mutex_unlock(&inode->i_mutex);
49206 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
49207
49208 if (inode->i_pipe) {
49209 ret = 0;
49210 - inode->i_pipe->writers++;
49211 + atomic_inc(&inode->i_pipe->writers);
49212 }
49213
49214 mutex_unlock(&inode->i_mutex);
49215 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
49216 if (inode->i_pipe) {
49217 ret = 0;
49218 if (filp->f_mode & FMODE_READ)
49219 - inode->i_pipe->readers++;
49220 + atomic_inc(&inode->i_pipe->readers);
49221 if (filp->f_mode & FMODE_WRITE)
49222 - inode->i_pipe->writers++;
49223 + atomic_inc(&inode->i_pipe->writers);
49224 }
49225
49226 mutex_unlock(&inode->i_mutex);
49227 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
49228 inode->i_pipe = NULL;
49229 }
49230
49231 -static struct vfsmount *pipe_mnt __read_mostly;
49232 +struct vfsmount *pipe_mnt __read_mostly;
49233
49234 /*
49235 * pipefs_dname() is called from d_path().
49236 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
49237 goto fail_iput;
49238 inode->i_pipe = pipe;
49239
49240 - pipe->readers = pipe->writers = 1;
49241 + atomic_set(&pipe->readers, 1);
49242 + atomic_set(&pipe->writers, 1);
49243 inode->i_fop = &rdwr_pipefifo_fops;
49244
49245 /*
49246 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
49247 index 15af622..0e9f4467 100644
49248 --- a/fs/proc/Kconfig
49249 +++ b/fs/proc/Kconfig
49250 @@ -30,12 +30,12 @@ config PROC_FS
49251
49252 config PROC_KCORE
49253 bool "/proc/kcore support" if !ARM
49254 - depends on PROC_FS && MMU
49255 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
49256
49257 config PROC_VMCORE
49258 bool "/proc/vmcore support"
49259 - depends on PROC_FS && CRASH_DUMP
49260 - default y
49261 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
49262 + default n
49263 help
49264 Exports the dump image of crashed kernel in ELF format.
49265
49266 @@ -59,8 +59,8 @@ config PROC_SYSCTL
49267 limited in memory.
49268
49269 config PROC_PAGE_MONITOR
49270 - default y
49271 - depends on PROC_FS && MMU
49272 + default n
49273 + depends on PROC_FS && MMU && !GRKERNSEC
49274 bool "Enable /proc page monitoring" if EXPERT
49275 help
49276 Various /proc files exist to monitor process memory utilization:
49277 diff --git a/fs/proc/array.c b/fs/proc/array.c
49278 index c1c207c..01ce725 100644
49279 --- a/fs/proc/array.c
49280 +++ b/fs/proc/array.c
49281 @@ -60,6 +60,7 @@
49282 #include <linux/tty.h>
49283 #include <linux/string.h>
49284 #include <linux/mman.h>
49285 +#include <linux/grsecurity.h>
49286 #include <linux/proc_fs.h>
49287 #include <linux/ioport.h>
49288 #include <linux/uaccess.h>
49289 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
49290 seq_putc(m, '\n');
49291 }
49292
49293 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49294 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
49295 +{
49296 + if (p->mm)
49297 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
49298 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
49299 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
49300 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
49301 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
49302 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
49303 + else
49304 + seq_printf(m, "PaX:\t-----\n");
49305 +}
49306 +#endif
49307 +
49308 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49309 struct pid *pid, struct task_struct *task)
49310 {
49311 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49312 task_cpus_allowed(m, task);
49313 cpuset_task_status_allowed(m, task);
49314 task_context_switch_counts(m, task);
49315 +
49316 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49317 + task_pax(m, task);
49318 +#endif
49319 +
49320 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
49321 + task_grsec_rbac(m, task);
49322 +#endif
49323 +
49324 return 0;
49325 }
49326
49327 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49328 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49329 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49330 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49331 +#endif
49332 +
49333 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49334 struct pid *pid, struct task_struct *task, int whole)
49335 {
49336 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49337 char tcomm[sizeof(task->comm)];
49338 unsigned long flags;
49339
49340 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49341 + if (current->exec_id != m->exec_id) {
49342 + gr_log_badprocpid("stat");
49343 + return 0;
49344 + }
49345 +#endif
49346 +
49347 state = *get_task_state(task);
49348 vsize = eip = esp = 0;
49349 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49350 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49351 gtime = task->gtime;
49352 }
49353
49354 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49355 + if (PAX_RAND_FLAGS(mm)) {
49356 + eip = 0;
49357 + esp = 0;
49358 + wchan = 0;
49359 + }
49360 +#endif
49361 +#ifdef CONFIG_GRKERNSEC_HIDESYM
49362 + wchan = 0;
49363 + eip =0;
49364 + esp =0;
49365 +#endif
49366 +
49367 /* scale priority and nice values from timeslices to -20..20 */
49368 /* to make it look like a "normal" Unix priority/nice value */
49369 priority = task_prio(task);
49370 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49371 seq_put_decimal_ull(m, ' ', vsize);
49372 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
49373 seq_put_decimal_ull(m, ' ', rsslim);
49374 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49375 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
49376 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
49377 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
49378 +#else
49379 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
49380 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
49381 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
49382 +#endif
49383 seq_put_decimal_ull(m, ' ', esp);
49384 seq_put_decimal_ull(m, ' ', eip);
49385 /* The signal information here is obsolete.
49386 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49387 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
49388 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
49389
49390 - if (mm && permitted) {
49391 + if (mm && permitted
49392 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49393 + && !PAX_RAND_FLAGS(mm)
49394 +#endif
49395 + ) {
49396 seq_put_decimal_ull(m, ' ', mm->start_data);
49397 seq_put_decimal_ull(m, ' ', mm->end_data);
49398 seq_put_decimal_ull(m, ' ', mm->start_brk);
49399 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49400 struct pid *pid, struct task_struct *task)
49401 {
49402 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
49403 - struct mm_struct *mm = get_task_mm(task);
49404 + struct mm_struct *mm;
49405
49406 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49407 + if (current->exec_id != m->exec_id) {
49408 + gr_log_badprocpid("statm");
49409 + return 0;
49410 + }
49411 +#endif
49412 + mm = get_task_mm(task);
49413 if (mm) {
49414 size = task_statm(mm, &shared, &text, &data, &resident);
49415 mmput(mm);
49416 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49417 return 0;
49418 }
49419
49420 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49421 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49422 +{
49423 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
49424 +}
49425 +#endif
49426 +
49427 #ifdef CONFIG_CHECKPOINT_RESTORE
49428 static struct pid *
49429 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
49430 diff --git a/fs/proc/base.c b/fs/proc/base.c
49431 index 1b6c84c..66b738b 100644
49432 --- a/fs/proc/base.c
49433 +++ b/fs/proc/base.c
49434 @@ -110,6 +110,14 @@ struct pid_entry {
49435 union proc_op op;
49436 };
49437
49438 +struct getdents_callback {
49439 + struct linux_dirent __user * current_dir;
49440 + struct linux_dirent __user * previous;
49441 + struct file * file;
49442 + int count;
49443 + int error;
49444 +};
49445 +
49446 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49447 .name = (NAME), \
49448 .len = sizeof(NAME) - 1, \
49449 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
49450 if (!mm->arg_end)
49451 goto out_mm; /* Shh! No looking before we're done */
49452
49453 + if (gr_acl_handle_procpidmem(task))
49454 + goto out_mm;
49455 +
49456 len = mm->arg_end - mm->arg_start;
49457
49458 if (len > PAGE_SIZE)
49459 @@ -236,12 +247,28 @@ out:
49460 return res;
49461 }
49462
49463 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49464 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49465 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49466 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49467 +#endif
49468 +
49469 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49470 {
49471 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
49472 int res = PTR_ERR(mm);
49473 if (mm && !IS_ERR(mm)) {
49474 unsigned int nwords = 0;
49475 +
49476 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49477 + /* allow if we're currently ptracing this task */
49478 + if (PAX_RAND_FLAGS(mm) &&
49479 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49480 + mmput(mm);
49481 + return 0;
49482 + }
49483 +#endif
49484 +
49485 do {
49486 nwords += 2;
49487 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49488 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
49489 }
49490
49491
49492 -#ifdef CONFIG_KALLSYMS
49493 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49494 /*
49495 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49496 * Returns the resolved symbol. If that fails, simply return the address.
49497 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
49498 mutex_unlock(&task->signal->cred_guard_mutex);
49499 }
49500
49501 -#ifdef CONFIG_STACKTRACE
49502 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49503
49504 #define MAX_STACK_TRACE_DEPTH 64
49505
49506 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
49507 return count;
49508 }
49509
49510 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49511 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49512 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49513 {
49514 long nr;
49515 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49516 /************************************************************************/
49517
49518 /* permission checks */
49519 -static int proc_fd_access_allowed(struct inode *inode)
49520 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49521 {
49522 struct task_struct *task;
49523 int allowed = 0;
49524 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49525 */
49526 task = get_proc_task(inode);
49527 if (task) {
49528 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49529 + if (log)
49530 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49531 + else
49532 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49533 put_task_struct(task);
49534 }
49535 return allowed;
49536 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49537 struct task_struct *task,
49538 int hide_pid_min)
49539 {
49540 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49541 + return false;
49542 +
49543 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49544 + rcu_read_lock();
49545 + {
49546 + const struct cred *tmpcred = current_cred();
49547 + const struct cred *cred = __task_cred(task);
49548 +
49549 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49550 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49551 + || in_group_p(grsec_proc_gid)
49552 +#endif
49553 + ) {
49554 + rcu_read_unlock();
49555 + return true;
49556 + }
49557 + }
49558 + rcu_read_unlock();
49559 +
49560 + if (!pid->hide_pid)
49561 + return false;
49562 +#endif
49563 +
49564 if (pid->hide_pid < hide_pid_min)
49565 return true;
49566 if (in_group_p(pid->pid_gid))
49567 return true;
49568 +
49569 return ptrace_may_access(task, PTRACE_MODE_READ);
49570 }
49571
49572 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49573 put_task_struct(task);
49574
49575 if (!has_perms) {
49576 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49577 + {
49578 +#else
49579 if (pid->hide_pid == 2) {
49580 +#endif
49581 /*
49582 * Let's make getdents(), stat(), and open()
49583 * consistent with each other. If a process
49584 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49585 if (!task)
49586 return -ESRCH;
49587
49588 + if (gr_acl_handle_procpidmem(task)) {
49589 + put_task_struct(task);
49590 + return -EPERM;
49591 + }
49592 +
49593 mm = mm_access(task, mode);
49594 put_task_struct(task);
49595
49596 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49597
49598 file->private_data = mm;
49599
49600 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49601 + file->f_version = current->exec_id;
49602 +#endif
49603 +
49604 return 0;
49605 }
49606
49607 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49608 ssize_t copied;
49609 char *page;
49610
49611 +#ifdef CONFIG_GRKERNSEC
49612 + if (write)
49613 + return -EPERM;
49614 +#endif
49615 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49616 + if (file->f_version != current->exec_id) {
49617 + gr_log_badprocpid("mem");
49618 + return 0;
49619 + }
49620 +#endif
49621 +
49622 if (!mm)
49623 return 0;
49624
49625 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49626 if (!mm)
49627 return 0;
49628
49629 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49630 + if (file->f_version != current->exec_id) {
49631 + gr_log_badprocpid("environ");
49632 + return 0;
49633 + }
49634 +#endif
49635 +
49636 page = (char *)__get_free_page(GFP_TEMPORARY);
49637 if (!page)
49638 return -ENOMEM;
49639 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49640 int error = -EACCES;
49641
49642 /* Are we allowed to snoop on the tasks file descriptors? */
49643 - if (!proc_fd_access_allowed(inode))
49644 + if (!proc_fd_access_allowed(inode, 0))
49645 goto out;
49646
49647 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49648 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49649 struct path path;
49650
49651 /* Are we allowed to snoop on the tasks file descriptors? */
49652 - if (!proc_fd_access_allowed(inode))
49653 - goto out;
49654 + /* logging this is needed for learning on chromium to work properly,
49655 + but we don't want to flood the logs from 'ps' which does a readlink
49656 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49657 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49658 + */
49659 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49660 + if (!proc_fd_access_allowed(inode,0))
49661 + goto out;
49662 + } else {
49663 + if (!proc_fd_access_allowed(inode,1))
49664 + goto out;
49665 + }
49666
49667 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49668 if (error)
49669 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49670 rcu_read_lock();
49671 cred = __task_cred(task);
49672 inode->i_uid = cred->euid;
49673 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49674 + inode->i_gid = grsec_proc_gid;
49675 +#else
49676 inode->i_gid = cred->egid;
49677 +#endif
49678 rcu_read_unlock();
49679 }
49680 security_task_to_inode(task, inode);
49681 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49682 return -ENOENT;
49683 }
49684 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49685 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49686 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49687 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49688 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49689 +#endif
49690 task_dumpable(task)) {
49691 cred = __task_cred(task);
49692 stat->uid = cred->euid;
49693 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49694 + stat->gid = grsec_proc_gid;
49695 +#else
49696 stat->gid = cred->egid;
49697 +#endif
49698 }
49699 }
49700 rcu_read_unlock();
49701 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49702
49703 if (task) {
49704 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49705 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49706 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49707 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49708 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49709 +#endif
49710 task_dumpable(task)) {
49711 rcu_read_lock();
49712 cred = __task_cred(task);
49713 inode->i_uid = cred->euid;
49714 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49715 + inode->i_gid = grsec_proc_gid;
49716 +#else
49717 inode->i_gid = cred->egid;
49718 +#endif
49719 rcu_read_unlock();
49720 } else {
49721 inode->i_uid = GLOBAL_ROOT_UID;
49722 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49723 int fd = proc_fd(inode);
49724
49725 if (task) {
49726 - files = get_files_struct(task);
49727 + if (!gr_acl_handle_procpidmem(task))
49728 + files = get_files_struct(task);
49729 put_task_struct(task);
49730 }
49731 if (files) {
49732 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49733 */
49734 static int proc_fd_permission(struct inode *inode, int mask)
49735 {
49736 + struct task_struct *task;
49737 int rv = generic_permission(inode, mask);
49738 - if (rv == 0)
49739 - return 0;
49740 +
49741 if (task_pid(current) == proc_pid(inode))
49742 rv = 0;
49743 +
49744 + task = get_proc_task(inode);
49745 + if (task == NULL)
49746 + return rv;
49747 +
49748 + if (gr_acl_handle_procpidmem(task))
49749 + rv = -EACCES;
49750 +
49751 + put_task_struct(task);
49752 +
49753 return rv;
49754 }
49755
49756 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49757 if (!task)
49758 goto out_no_task;
49759
49760 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49761 + goto out;
49762 +
49763 /*
49764 * Yes, it does not scale. And it should not. Don't add
49765 * new entries into /proc/<tgid>/ without very good reasons.
49766 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49767 if (!task)
49768 goto out_no_task;
49769
49770 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49771 + goto out;
49772 +
49773 ret = 0;
49774 i = filp->f_pos;
49775 switch (i) {
49776 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49777 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49778 void *cookie)
49779 {
49780 - char *s = nd_get_link(nd);
49781 + const char *s = nd_get_link(nd);
49782 if (!IS_ERR(s))
49783 __putname(s);
49784 }
49785 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49786 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49787 #endif
49788 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49789 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49790 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49791 INF("syscall", S_IRUGO, proc_pid_syscall),
49792 #endif
49793 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49794 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49795 #ifdef CONFIG_SECURITY
49796 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49797 #endif
49798 -#ifdef CONFIG_KALLSYMS
49799 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49800 INF("wchan", S_IRUGO, proc_pid_wchan),
49801 #endif
49802 -#ifdef CONFIG_STACKTRACE
49803 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49804 ONE("stack", S_IRUGO, proc_pid_stack),
49805 #endif
49806 #ifdef CONFIG_SCHEDSTATS
49807 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49808 #ifdef CONFIG_HARDWALL
49809 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49810 #endif
49811 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49812 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49813 +#endif
49814 #ifdef CONFIG_USER_NS
49815 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49816 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49817 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49818 if (!inode)
49819 goto out;
49820
49821 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49822 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49823 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49824 + inode->i_gid = grsec_proc_gid;
49825 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49826 +#else
49827 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49828 +#endif
49829 inode->i_op = &proc_tgid_base_inode_operations;
49830 inode->i_fop = &proc_tgid_base_operations;
49831 inode->i_flags|=S_IMMUTABLE;
49832 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49833 if (!task)
49834 goto out;
49835
49836 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49837 + goto out_put_task;
49838 +
49839 result = proc_pid_instantiate(dir, dentry, task, NULL);
49840 +out_put_task:
49841 put_task_struct(task);
49842 out:
49843 return result;
49844 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49845 static int fake_filldir(void *buf, const char *name, int namelen,
49846 loff_t offset, u64 ino, unsigned d_type)
49847 {
49848 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49849 + __buf->error = -EINVAL;
49850 return 0;
49851 }
49852
49853 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49854 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49855 #endif
49856 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49857 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49858 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49859 INF("syscall", S_IRUGO, proc_pid_syscall),
49860 #endif
49861 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49862 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49863 #ifdef CONFIG_SECURITY
49864 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49865 #endif
49866 -#ifdef CONFIG_KALLSYMS
49867 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49868 INF("wchan", S_IRUGO, proc_pid_wchan),
49869 #endif
49870 -#ifdef CONFIG_STACKTRACE
49871 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49872 ONE("stack", S_IRUGO, proc_pid_stack),
49873 #endif
49874 #ifdef CONFIG_SCHEDSTATS
49875 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49876 index 82676e3..5f8518a 100644
49877 --- a/fs/proc/cmdline.c
49878 +++ b/fs/proc/cmdline.c
49879 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49880
49881 static int __init proc_cmdline_init(void)
49882 {
49883 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49884 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49885 +#else
49886 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49887 +#endif
49888 return 0;
49889 }
49890 module_init(proc_cmdline_init);
49891 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49892 index b143471..bb105e5 100644
49893 --- a/fs/proc/devices.c
49894 +++ b/fs/proc/devices.c
49895 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49896
49897 static int __init proc_devices_init(void)
49898 {
49899 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49900 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49901 +#else
49902 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49903 +#endif
49904 return 0;
49905 }
49906 module_init(proc_devices_init);
49907 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49908 index 7ac817b..c5c9eb0 100644
49909 --- a/fs/proc/inode.c
49910 +++ b/fs/proc/inode.c
49911 @@ -21,11 +21,17 @@
49912 #include <linux/seq_file.h>
49913 #include <linux/slab.h>
49914 #include <linux/mount.h>
49915 +#include <linux/grsecurity.h>
49916
49917 #include <asm/uaccess.h>
49918
49919 #include "internal.h"
49920
49921 +#ifdef CONFIG_PROC_SYSCTL
49922 +extern const struct inode_operations proc_sys_inode_operations;
49923 +extern const struct inode_operations proc_sys_dir_operations;
49924 +#endif
49925 +
49926 static void proc_evict_inode(struct inode *inode)
49927 {
49928 struct proc_dir_entry *de;
49929 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49930 ns_ops = PROC_I(inode)->ns_ops;
49931 if (ns_ops && ns_ops->put)
49932 ns_ops->put(PROC_I(inode)->ns);
49933 +
49934 +#ifdef CONFIG_PROC_SYSCTL
49935 + if (inode->i_op == &proc_sys_inode_operations ||
49936 + inode->i_op == &proc_sys_dir_operations)
49937 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49938 +#endif
49939 +
49940 }
49941
49942 static struct kmem_cache * proc_inode_cachep;
49943 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49944 if (de->mode) {
49945 inode->i_mode = de->mode;
49946 inode->i_uid = de->uid;
49947 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49948 + inode->i_gid = grsec_proc_gid;
49949 +#else
49950 inode->i_gid = de->gid;
49951 +#endif
49952 }
49953 if (de->size)
49954 inode->i_size = de->size;
49955 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49956 index e1167a1..bd24f20 100644
49957 --- a/fs/proc/internal.h
49958 +++ b/fs/proc/internal.h
49959 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49960 struct pid *pid, struct task_struct *task);
49961 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49962 struct pid *pid, struct task_struct *task);
49963 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49964 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49965 +#endif
49966 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49967
49968 extern const struct file_operations proc_tid_children_operations;
49969 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49970 index 86c67ee..cdca321 100644
49971 --- a/fs/proc/kcore.c
49972 +++ b/fs/proc/kcore.c
49973 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49974 * the addresses in the elf_phdr on our list.
49975 */
49976 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49977 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49978 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49979 + if (tsz > buflen)
49980 tsz = buflen;
49981 -
49982 +
49983 while (buflen) {
49984 struct kcore_list *m;
49985
49986 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49987 kfree(elf_buf);
49988 } else {
49989 if (kern_addr_valid(start)) {
49990 - unsigned long n;
49991 + char *elf_buf;
49992 + mm_segment_t oldfs;
49993
49994 - n = copy_to_user(buffer, (char *)start, tsz);
49995 - /*
49996 - * We cannot distinguish between fault on source
49997 - * and fault on destination. When this happens
49998 - * we clear too and hope it will trigger the
49999 - * EFAULT again.
50000 - */
50001 - if (n) {
50002 - if (clear_user(buffer + tsz - n,
50003 - n))
50004 + elf_buf = kmalloc(tsz, GFP_KERNEL);
50005 + if (!elf_buf)
50006 + return -ENOMEM;
50007 + oldfs = get_fs();
50008 + set_fs(KERNEL_DS);
50009 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
50010 + set_fs(oldfs);
50011 + if (copy_to_user(buffer, elf_buf, tsz)) {
50012 + kfree(elf_buf);
50013 return -EFAULT;
50014 + }
50015 }
50016 + set_fs(oldfs);
50017 + kfree(elf_buf);
50018 } else {
50019 if (clear_user(buffer, tsz))
50020 return -EFAULT;
50021 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50022
50023 static int open_kcore(struct inode *inode, struct file *filp)
50024 {
50025 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
50026 + return -EPERM;
50027 +#endif
50028 if (!capable(CAP_SYS_RAWIO))
50029 return -EPERM;
50030 if (kcore_need_update)
50031 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
50032 index 80e4645..53e5fcf 100644
50033 --- a/fs/proc/meminfo.c
50034 +++ b/fs/proc/meminfo.c
50035 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
50036 vmi.used >> 10,
50037 vmi.largest_chunk >> 10
50038 #ifdef CONFIG_MEMORY_FAILURE
50039 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
50040 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
50041 #endif
50042 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
50043 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
50044 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
50045 index b1822dd..df622cb 100644
50046 --- a/fs/proc/nommu.c
50047 +++ b/fs/proc/nommu.c
50048 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
50049 if (len < 1)
50050 len = 1;
50051 seq_printf(m, "%*c", len, ' ');
50052 - seq_path(m, &file->f_path, "");
50053 + seq_path(m, &file->f_path, "\n\\");
50054 }
50055
50056 seq_putc(m, '\n');
50057 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
50058 index fe72cd0..cb9b67d 100644
50059 --- a/fs/proc/proc_net.c
50060 +++ b/fs/proc/proc_net.c
50061 @@ -23,6 +23,7 @@
50062 #include <linux/nsproxy.h>
50063 #include <net/net_namespace.h>
50064 #include <linux/seq_file.h>
50065 +#include <linux/grsecurity.h>
50066
50067 #include "internal.h"
50068
50069 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
50070 struct task_struct *task;
50071 struct nsproxy *ns;
50072 struct net *net = NULL;
50073 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50074 + const struct cred *cred = current_cred();
50075 +#endif
50076 +
50077 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50078 + if (cred->fsuid)
50079 + return net;
50080 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50081 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
50082 + return net;
50083 +#endif
50084
50085 rcu_read_lock();
50086 task = pid_task(proc_pid(dir), PIDTYPE_PID);
50087 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
50088 index eb7cc91..7327a46 100644
50089 --- a/fs/proc/proc_sysctl.c
50090 +++ b/fs/proc/proc_sysctl.c
50091 @@ -12,11 +12,15 @@
50092 #include <linux/module.h>
50093 #include "internal.h"
50094
50095 +extern int gr_handle_chroot_sysctl(const int op);
50096 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
50097 + const int op);
50098 +
50099 static const struct dentry_operations proc_sys_dentry_operations;
50100 static const struct file_operations proc_sys_file_operations;
50101 -static const struct inode_operations proc_sys_inode_operations;
50102 +const struct inode_operations proc_sys_inode_operations;
50103 static const struct file_operations proc_sys_dir_file_operations;
50104 -static const struct inode_operations proc_sys_dir_operations;
50105 +const struct inode_operations proc_sys_dir_operations;
50106
50107 void proc_sys_poll_notify(struct ctl_table_poll *poll)
50108 {
50109 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
50110
50111 err = NULL;
50112 d_set_d_op(dentry, &proc_sys_dentry_operations);
50113 +
50114 + gr_handle_proc_create(dentry, inode);
50115 +
50116 d_add(dentry, inode);
50117
50118 out:
50119 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
50120 struct inode *inode = filp->f_path.dentry->d_inode;
50121 struct ctl_table_header *head = grab_header(inode);
50122 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
50123 + int op = write ? MAY_WRITE : MAY_READ;
50124 ssize_t error;
50125 size_t res;
50126
50127 if (IS_ERR(head))
50128 return PTR_ERR(head);
50129
50130 +
50131 /*
50132 * At this point we know that the sysctl was not unregistered
50133 * and won't be until we finish.
50134 */
50135 error = -EPERM;
50136 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
50137 + if (sysctl_perm(head->root, table, op))
50138 goto out;
50139
50140 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
50141 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
50142 if (!table->proc_handler)
50143 goto out;
50144
50145 +#ifdef CONFIG_GRKERNSEC
50146 + error = -EPERM;
50147 + if (gr_handle_chroot_sysctl(op))
50148 + goto out;
50149 + dget(filp->f_path.dentry);
50150 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
50151 + dput(filp->f_path.dentry);
50152 + goto out;
50153 + }
50154 + dput(filp->f_path.dentry);
50155 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
50156 + goto out;
50157 + if (write && !capable(CAP_SYS_ADMIN))
50158 + goto out;
50159 +#endif
50160 +
50161 /* careful: calling conventions are nasty here */
50162 res = count;
50163 error = table->proc_handler(table, write, buf, &res, ppos);
50164 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
50165 return -ENOMEM;
50166 } else {
50167 d_set_d_op(child, &proc_sys_dentry_operations);
50168 +
50169 + gr_handle_proc_create(child, inode);
50170 +
50171 d_add(child, inode);
50172 }
50173 } else {
50174 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
50175 if ((*pos)++ < file->f_pos)
50176 return 0;
50177
50178 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
50179 + return 0;
50180 +
50181 if (unlikely(S_ISLNK(table->mode)))
50182 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
50183 else
50184 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
50185 if (IS_ERR(head))
50186 return PTR_ERR(head);
50187
50188 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
50189 + return -ENOENT;
50190 +
50191 generic_fillattr(inode, stat);
50192 if (table)
50193 stat->mode = (stat->mode & S_IFMT) | table->mode;
50194 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
50195 .llseek = generic_file_llseek,
50196 };
50197
50198 -static const struct inode_operations proc_sys_inode_operations = {
50199 +const struct inode_operations proc_sys_inode_operations = {
50200 .permission = proc_sys_permission,
50201 .setattr = proc_sys_setattr,
50202 .getattr = proc_sys_getattr,
50203 };
50204
50205 -static const struct inode_operations proc_sys_dir_operations = {
50206 +const struct inode_operations proc_sys_dir_operations = {
50207 .lookup = proc_sys_lookup,
50208 .permission = proc_sys_permission,
50209 .setattr = proc_sys_setattr,
50210 diff --git a/fs/proc/root.c b/fs/proc/root.c
50211 index 9a2d9fd..ddfc92a 100644
50212 --- a/fs/proc/root.c
50213 +++ b/fs/proc/root.c
50214 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
50215 #ifdef CONFIG_PROC_DEVICETREE
50216 proc_device_tree_init();
50217 #endif
50218 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50219 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50220 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
50221 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50222 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50223 +#endif
50224 +#else
50225 proc_mkdir("bus", NULL);
50226 +#endif
50227 proc_sys_init();
50228 }
50229
50230 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
50231 index 4540b8f..1b9772f 100644
50232 --- a/fs/proc/task_mmu.c
50233 +++ b/fs/proc/task_mmu.c
50234 @@ -11,12 +11,19 @@
50235 #include <linux/rmap.h>
50236 #include <linux/swap.h>
50237 #include <linux/swapops.h>
50238 +#include <linux/grsecurity.h>
50239
50240 #include <asm/elf.h>
50241 #include <asm/uaccess.h>
50242 #include <asm/tlbflush.h>
50243 #include "internal.h"
50244
50245 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50246 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50247 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50248 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50249 +#endif
50250 +
50251 void task_mem(struct seq_file *m, struct mm_struct *mm)
50252 {
50253 unsigned long data, text, lib, swap;
50254 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50255 "VmExe:\t%8lu kB\n"
50256 "VmLib:\t%8lu kB\n"
50257 "VmPTE:\t%8lu kB\n"
50258 - "VmSwap:\t%8lu kB\n",
50259 - hiwater_vm << (PAGE_SHIFT-10),
50260 + "VmSwap:\t%8lu kB\n"
50261 +
50262 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50263 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
50264 +#endif
50265 +
50266 + ,hiwater_vm << (PAGE_SHIFT-10),
50267 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
50268 mm->locked_vm << (PAGE_SHIFT-10),
50269 mm->pinned_vm << (PAGE_SHIFT-10),
50270 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50271 data << (PAGE_SHIFT-10),
50272 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
50273 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
50274 - swap << (PAGE_SHIFT-10));
50275 + swap << (PAGE_SHIFT-10)
50276 +
50277 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50278 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50279 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
50280 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
50281 +#else
50282 + , mm->context.user_cs_base
50283 + , mm->context.user_cs_limit
50284 +#endif
50285 +#endif
50286 +
50287 + );
50288 }
50289
50290 unsigned long task_vsize(struct mm_struct *mm)
50291 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50292 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
50293 }
50294
50295 - /* We don't show the stack guard page in /proc/maps */
50296 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50297 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
50298 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
50299 +#else
50300 start = vma->vm_start;
50301 - if (stack_guard_page_start(vma, start))
50302 - start += PAGE_SIZE;
50303 end = vma->vm_end;
50304 - if (stack_guard_page_end(vma, end))
50305 - end -= PAGE_SIZE;
50306 +#endif
50307
50308 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
50309 start,
50310 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50311 flags & VM_WRITE ? 'w' : '-',
50312 flags & VM_EXEC ? 'x' : '-',
50313 flags & VM_MAYSHARE ? 's' : 'p',
50314 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50315 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
50316 +#else
50317 pgoff,
50318 +#endif
50319 MAJOR(dev), MINOR(dev), ino, &len);
50320
50321 /*
50322 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50323 */
50324 if (file) {
50325 pad_len_spaces(m, len);
50326 - seq_path(m, &file->f_path, "\n");
50327 + seq_path(m, &file->f_path, "\n\\");
50328 goto done;
50329 }
50330
50331 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50332 * Thread stack in /proc/PID/task/TID/maps or
50333 * the main process stack.
50334 */
50335 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
50336 - vma->vm_end >= mm->start_stack)) {
50337 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
50338 + (vma->vm_start <= mm->start_stack &&
50339 + vma->vm_end >= mm->start_stack)) {
50340 name = "[stack]";
50341 } else {
50342 /* Thread stack in /proc/PID/maps */
50343 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
50344 struct proc_maps_private *priv = m->private;
50345 struct task_struct *task = priv->task;
50346
50347 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50348 + if (current->exec_id != m->exec_id) {
50349 + gr_log_badprocpid("maps");
50350 + return 0;
50351 + }
50352 +#endif
50353 +
50354 show_map_vma(m, vma, is_pid);
50355
50356 if (m->count < m->size) /* vma is copied successfully */
50357 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50358 .private = &mss,
50359 };
50360
50361 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50362 + if (current->exec_id != m->exec_id) {
50363 + gr_log_badprocpid("smaps");
50364 + return 0;
50365 + }
50366 +#endif
50367 memset(&mss, 0, sizeof mss);
50368 - mss.vma = vma;
50369 - /* mmap_sem is held in m_start */
50370 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50371 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50372 -
50373 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50374 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50375 +#endif
50376 + mss.vma = vma;
50377 + /* mmap_sem is held in m_start */
50378 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50379 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50380 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50381 + }
50382 +#endif
50383 show_map_vma(m, vma, is_pid);
50384
50385 seq_printf(m,
50386 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50387 "KernelPageSize: %8lu kB\n"
50388 "MMUPageSize: %8lu kB\n"
50389 "Locked: %8lu kB\n",
50390 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50391 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50392 +#else
50393 (vma->vm_end - vma->vm_start) >> 10,
50394 +#endif
50395 mss.resident >> 10,
50396 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50397 mss.shared_clean >> 10,
50398 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50399 int n;
50400 char buffer[50];
50401
50402 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50403 + if (current->exec_id != m->exec_id) {
50404 + gr_log_badprocpid("numa_maps");
50405 + return 0;
50406 + }
50407 +#endif
50408 +
50409 if (!mm)
50410 return 0;
50411
50412 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50413 mpol_to_str(buffer, sizeof(buffer), pol, 0);
50414 mpol_cond_put(pol);
50415
50416 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50417 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
50418 +#else
50419 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
50420 +#endif
50421
50422 if (file) {
50423 seq_printf(m, " file=");
50424 - seq_path(m, &file->f_path, "\n\t= ");
50425 + seq_path(m, &file->f_path, "\n\t\\= ");
50426 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
50427 seq_printf(m, " heap");
50428 } else {
50429 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
50430 index 1ccfa53..0848f95 100644
50431 --- a/fs/proc/task_nommu.c
50432 +++ b/fs/proc/task_nommu.c
50433 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50434 else
50435 bytes += kobjsize(mm);
50436
50437 - if (current->fs && current->fs->users > 1)
50438 + if (current->fs && atomic_read(&current->fs->users) > 1)
50439 sbytes += kobjsize(current->fs);
50440 else
50441 bytes += kobjsize(current->fs);
50442 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
50443
50444 if (file) {
50445 pad_len_spaces(m, len);
50446 - seq_path(m, &file->f_path, "");
50447 + seq_path(m, &file->f_path, "\n\\");
50448 } else if (mm) {
50449 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
50450
50451 diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
50452 index 29996e8..2d1e0f3 100644
50453 --- a/fs/pstore/platform.c
50454 +++ b/fs/pstore/platform.c
50455 @@ -161,12 +161,13 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c)
50456
50457 while (s < e) {
50458 unsigned long flags;
50459 + u64 id;
50460
50461 if (c > psinfo->bufsize)
50462 c = psinfo->bufsize;
50463 spin_lock_irqsave(&psinfo->buf_lock, flags);
50464 memcpy(psinfo->buf, s, c);
50465 - psinfo->write(PSTORE_TYPE_CONSOLE, 0, NULL, 0, c, psinfo);
50466 + psinfo->write(PSTORE_TYPE_CONSOLE, 0, &id, 0, c, psinfo);
50467 spin_unlock_irqrestore(&psinfo->buf_lock, flags);
50468 s += c;
50469 c = e - s;
50470 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
50471 index d67908b..d13f6a6 100644
50472 --- a/fs/quota/netlink.c
50473 +++ b/fs/quota/netlink.c
50474 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
50475 void quota_send_warning(short type, unsigned int id, dev_t dev,
50476 const char warntype)
50477 {
50478 - static atomic_t seq;
50479 + static atomic_unchecked_t seq;
50480 struct sk_buff *skb;
50481 void *msg_head;
50482 int ret;
50483 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
50484 "VFS: Not enough memory to send quota warning.\n");
50485 return;
50486 }
50487 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50488 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50489 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50490 if (!msg_head) {
50491 printk(KERN_ERR
50492 diff --git a/fs/readdir.c b/fs/readdir.c
50493 index 39e3370..20d446d 100644
50494 --- a/fs/readdir.c
50495 +++ b/fs/readdir.c
50496 @@ -17,6 +17,7 @@
50497 #include <linux/security.h>
50498 #include <linux/syscalls.h>
50499 #include <linux/unistd.h>
50500 +#include <linux/namei.h>
50501
50502 #include <asm/uaccess.h>
50503
50504 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50505
50506 struct readdir_callback {
50507 struct old_linux_dirent __user * dirent;
50508 + struct file * file;
50509 int result;
50510 };
50511
50512 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
50513 buf->result = -EOVERFLOW;
50514 return -EOVERFLOW;
50515 }
50516 +
50517 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50518 + return 0;
50519 +
50520 buf->result++;
50521 dirent = buf->dirent;
50522 if (!access_ok(VERIFY_WRITE, dirent,
50523 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50524
50525 buf.result = 0;
50526 buf.dirent = dirent;
50527 + buf.file = file;
50528
50529 error = vfs_readdir(file, fillonedir, &buf);
50530 if (buf.result)
50531 @@ -141,6 +148,7 @@ struct linux_dirent {
50532 struct getdents_callback {
50533 struct linux_dirent __user * current_dir;
50534 struct linux_dirent __user * previous;
50535 + struct file * file;
50536 int count;
50537 int error;
50538 };
50539 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50540 buf->error = -EOVERFLOW;
50541 return -EOVERFLOW;
50542 }
50543 +
50544 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50545 + return 0;
50546 +
50547 dirent = buf->previous;
50548 if (dirent) {
50549 if (__put_user(offset, &dirent->d_off))
50550 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50551 buf.previous = NULL;
50552 buf.count = count;
50553 buf.error = 0;
50554 + buf.file = file;
50555
50556 error = vfs_readdir(file, filldir, &buf);
50557 if (error >= 0)
50558 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50559 struct getdents_callback64 {
50560 struct linux_dirent64 __user * current_dir;
50561 struct linux_dirent64 __user * previous;
50562 + struct file *file;
50563 int count;
50564 int error;
50565 };
50566 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50567 buf->error = -EINVAL; /* only used if we fail.. */
50568 if (reclen > buf->count)
50569 return -EINVAL;
50570 +
50571 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50572 + return 0;
50573 +
50574 dirent = buf->previous;
50575 if (dirent) {
50576 if (__put_user(offset, &dirent->d_off))
50577 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50578
50579 buf.current_dir = dirent;
50580 buf.previous = NULL;
50581 + buf.file = file;
50582 buf.count = count;
50583 buf.error = 0;
50584
50585 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50586 error = buf.error;
50587 lastdirent = buf.previous;
50588 if (lastdirent) {
50589 - typeof(lastdirent->d_off) d_off = file->f_pos;
50590 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50591 if (__put_user(d_off, &lastdirent->d_off))
50592 error = -EFAULT;
50593 else
50594 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50595 index 2b7882b..1c5ef48 100644
50596 --- a/fs/reiserfs/do_balan.c
50597 +++ b/fs/reiserfs/do_balan.c
50598 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50599 return;
50600 }
50601
50602 - atomic_inc(&(fs_generation(tb->tb_sb)));
50603 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50604 do_balance_starts(tb);
50605
50606 /* balance leaf returns 0 except if combining L R and S into
50607 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50608 index e60e870..f40ac16 100644
50609 --- a/fs/reiserfs/procfs.c
50610 +++ b/fs/reiserfs/procfs.c
50611 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50612 "SMALL_TAILS " : "NO_TAILS ",
50613 replay_only(sb) ? "REPLAY_ONLY " : "",
50614 convert_reiserfs(sb) ? "CONV " : "",
50615 - atomic_read(&r->s_generation_counter),
50616 + atomic_read_unchecked(&r->s_generation_counter),
50617 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50618 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50619 SF(s_good_search_by_key_reada), SF(s_bmaps),
50620 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50621 index 33215f5..c5d427a 100644
50622 --- a/fs/reiserfs/reiserfs.h
50623 +++ b/fs/reiserfs/reiserfs.h
50624 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50625 /* Comment? -Hans */
50626 wait_queue_head_t s_wait;
50627 /* To be obsoleted soon by per buffer seals.. -Hans */
50628 - atomic_t s_generation_counter; // increased by one every time the
50629 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50630 // tree gets re-balanced
50631 unsigned long s_properties; /* File system properties. Currently holds
50632 on-disk FS format */
50633 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50634 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50635
50636 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50637 -#define get_generation(s) atomic_read (&fs_generation(s))
50638 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50639 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50640 #define __fs_changed(gen,s) (gen != get_generation (s))
50641 #define fs_changed(gen,s) \
50642 diff --git a/fs/select.c b/fs/select.c
50643 index db14c78..3aae1bd 100644
50644 --- a/fs/select.c
50645 +++ b/fs/select.c
50646 @@ -20,6 +20,7 @@
50647 #include <linux/export.h>
50648 #include <linux/slab.h>
50649 #include <linux/poll.h>
50650 +#include <linux/security.h>
50651 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50652 #include <linux/file.h>
50653 #include <linux/fdtable.h>
50654 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50655 struct poll_list *walk = head;
50656 unsigned long todo = nfds;
50657
50658 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50659 if (nfds > rlimit(RLIMIT_NOFILE))
50660 return -EINVAL;
50661
50662 diff --git a/fs/seq_file.c b/fs/seq_file.c
50663 index 14cf9de..adc4d5b 100644
50664 --- a/fs/seq_file.c
50665 +++ b/fs/seq_file.c
50666 @@ -9,6 +9,7 @@
50667 #include <linux/export.h>
50668 #include <linux/seq_file.h>
50669 #include <linux/slab.h>
50670 +#include <linux/sched.h>
50671
50672 #include <asm/uaccess.h>
50673 #include <asm/page.h>
50674 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50675 memset(p, 0, sizeof(*p));
50676 mutex_init(&p->lock);
50677 p->op = op;
50678 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50679 + p->exec_id = current->exec_id;
50680 +#endif
50681
50682 /*
50683 * Wrappers around seq_open(e.g. swaps_open) need to be
50684 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50685 return 0;
50686 }
50687 if (!m->buf) {
50688 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50689 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50690 if (!m->buf)
50691 return -ENOMEM;
50692 }
50693 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50694 Eoverflow:
50695 m->op->stop(m, p);
50696 kfree(m->buf);
50697 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50698 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50699 return !m->buf ? -ENOMEM : -EAGAIN;
50700 }
50701
50702 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50703
50704 /* grab buffer if we didn't have one */
50705 if (!m->buf) {
50706 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50707 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50708 if (!m->buf)
50709 goto Enomem;
50710 }
50711 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50712 goto Fill;
50713 m->op->stop(m, p);
50714 kfree(m->buf);
50715 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50716 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50717 if (!m->buf)
50718 goto Enomem;
50719 m->count = 0;
50720 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50721 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50722 void *data)
50723 {
50724 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50725 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50726 int res = -ENOMEM;
50727
50728 if (op) {
50729 diff --git a/fs/splice.c b/fs/splice.c
50730 index 41514dd..6564a93 100644
50731 --- a/fs/splice.c
50732 +++ b/fs/splice.c
50733 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50734 pipe_lock(pipe);
50735
50736 for (;;) {
50737 - if (!pipe->readers) {
50738 + if (!atomic_read(&pipe->readers)) {
50739 send_sig(SIGPIPE, current, 0);
50740 if (!ret)
50741 ret = -EPIPE;
50742 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50743 do_wakeup = 0;
50744 }
50745
50746 - pipe->waiting_writers++;
50747 + atomic_inc(&pipe->waiting_writers);
50748 pipe_wait(pipe);
50749 - pipe->waiting_writers--;
50750 + atomic_dec(&pipe->waiting_writers);
50751 }
50752
50753 pipe_unlock(pipe);
50754 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50755 old_fs = get_fs();
50756 set_fs(get_ds());
50757 /* The cast to a user pointer is valid due to the set_fs() */
50758 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50759 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50760 set_fs(old_fs);
50761
50762 return res;
50763 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50764 old_fs = get_fs();
50765 set_fs(get_ds());
50766 /* The cast to a user pointer is valid due to the set_fs() */
50767 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50768 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50769 set_fs(old_fs);
50770
50771 return res;
50772 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50773 goto err;
50774
50775 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50776 - vec[i].iov_base = (void __user *) page_address(page);
50777 + vec[i].iov_base = (void __force_user *) page_address(page);
50778 vec[i].iov_len = this_len;
50779 spd.pages[i] = page;
50780 spd.nr_pages++;
50781 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50782 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50783 {
50784 while (!pipe->nrbufs) {
50785 - if (!pipe->writers)
50786 + if (!atomic_read(&pipe->writers))
50787 return 0;
50788
50789 - if (!pipe->waiting_writers && sd->num_spliced)
50790 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50791 return 0;
50792
50793 if (sd->flags & SPLICE_F_NONBLOCK)
50794 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50795 * out of the pipe right after the splice_to_pipe(). So set
50796 * PIPE_READERS appropriately.
50797 */
50798 - pipe->readers = 1;
50799 + atomic_set(&pipe->readers, 1);
50800
50801 current->splice_pipe = pipe;
50802 }
50803 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50804 ret = -ERESTARTSYS;
50805 break;
50806 }
50807 - if (!pipe->writers)
50808 + if (!atomic_read(&pipe->writers))
50809 break;
50810 - if (!pipe->waiting_writers) {
50811 + if (!atomic_read(&pipe->waiting_writers)) {
50812 if (flags & SPLICE_F_NONBLOCK) {
50813 ret = -EAGAIN;
50814 break;
50815 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50816 pipe_lock(pipe);
50817
50818 while (pipe->nrbufs >= pipe->buffers) {
50819 - if (!pipe->readers) {
50820 + if (!atomic_read(&pipe->readers)) {
50821 send_sig(SIGPIPE, current, 0);
50822 ret = -EPIPE;
50823 break;
50824 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50825 ret = -ERESTARTSYS;
50826 break;
50827 }
50828 - pipe->waiting_writers++;
50829 + atomic_inc(&pipe->waiting_writers);
50830 pipe_wait(pipe);
50831 - pipe->waiting_writers--;
50832 + atomic_dec(&pipe->waiting_writers);
50833 }
50834
50835 pipe_unlock(pipe);
50836 @@ -1828,14 +1828,14 @@ retry:
50837 pipe_double_lock(ipipe, opipe);
50838
50839 do {
50840 - if (!opipe->readers) {
50841 + if (!atomic_read(&opipe->readers)) {
50842 send_sig(SIGPIPE, current, 0);
50843 if (!ret)
50844 ret = -EPIPE;
50845 break;
50846 }
50847
50848 - if (!ipipe->nrbufs && !ipipe->writers)
50849 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50850 break;
50851
50852 /*
50853 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50854 pipe_double_lock(ipipe, opipe);
50855
50856 do {
50857 - if (!opipe->readers) {
50858 + if (!atomic_read(&opipe->readers)) {
50859 send_sig(SIGPIPE, current, 0);
50860 if (!ret)
50861 ret = -EPIPE;
50862 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50863 * return EAGAIN if we have the potential of some data in the
50864 * future, otherwise just return 0
50865 */
50866 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50867 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50868 ret = -EAGAIN;
50869
50870 pipe_unlock(ipipe);
50871 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50872 index 2fbdff6..5530a61 100644
50873 --- a/fs/sysfs/dir.c
50874 +++ b/fs/sysfs/dir.c
50875 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50876 struct sysfs_dirent *sd;
50877 int rc;
50878
50879 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50880 + const char *parent_name = parent_sd->s_name;
50881 +
50882 + mode = S_IFDIR | S_IRWXU;
50883 +
50884 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50885 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50886 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50887 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50888 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50889 +#endif
50890 +
50891 /* allocate */
50892 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50893 if (!sd)
50894 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50895 index 00012e3..8392349 100644
50896 --- a/fs/sysfs/file.c
50897 +++ b/fs/sysfs/file.c
50898 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50899
50900 struct sysfs_open_dirent {
50901 atomic_t refcnt;
50902 - atomic_t event;
50903 + atomic_unchecked_t event;
50904 wait_queue_head_t poll;
50905 struct list_head buffers; /* goes through sysfs_buffer.list */
50906 };
50907 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50908 if (!sysfs_get_active(attr_sd))
50909 return -ENODEV;
50910
50911 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50912 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50913 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50914
50915 sysfs_put_active(attr_sd);
50916 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50917 return -ENOMEM;
50918
50919 atomic_set(&new_od->refcnt, 0);
50920 - atomic_set(&new_od->event, 1);
50921 + atomic_set_unchecked(&new_od->event, 1);
50922 init_waitqueue_head(&new_od->poll);
50923 INIT_LIST_HEAD(&new_od->buffers);
50924 goto retry;
50925 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50926
50927 sysfs_put_active(attr_sd);
50928
50929 - if (buffer->event != atomic_read(&od->event))
50930 + if (buffer->event != atomic_read_unchecked(&od->event))
50931 goto trigger;
50932
50933 return DEFAULT_POLLMASK;
50934 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50935
50936 od = sd->s_attr.open;
50937 if (od) {
50938 - atomic_inc(&od->event);
50939 + atomic_inc_unchecked(&od->event);
50940 wake_up_interruptible(&od->poll);
50941 }
50942
50943 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50944 index a7ac78f..02158e1 100644
50945 --- a/fs/sysfs/symlink.c
50946 +++ b/fs/sysfs/symlink.c
50947 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50948
50949 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50950 {
50951 - char *page = nd_get_link(nd);
50952 + const char *page = nd_get_link(nd);
50953 if (!IS_ERR(page))
50954 free_page((unsigned long)page);
50955 }
50956 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50957 index c175b4d..8f36a16 100644
50958 --- a/fs/udf/misc.c
50959 +++ b/fs/udf/misc.c
50960 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50961
50962 u8 udf_tag_checksum(const struct tag *t)
50963 {
50964 - u8 *data = (u8 *)t;
50965 + const u8 *data = (const u8 *)t;
50966 u8 checksum = 0;
50967 int i;
50968 for (i = 0; i < sizeof(struct tag); ++i)
50969 diff --git a/fs/utimes.c b/fs/utimes.c
50970 index fa4dbe4..e12d1b9 100644
50971 --- a/fs/utimes.c
50972 +++ b/fs/utimes.c
50973 @@ -1,6 +1,7 @@
50974 #include <linux/compiler.h>
50975 #include <linux/file.h>
50976 #include <linux/fs.h>
50977 +#include <linux/security.h>
50978 #include <linux/linkage.h>
50979 #include <linux/mount.h>
50980 #include <linux/namei.h>
50981 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50982 goto mnt_drop_write_and_out;
50983 }
50984 }
50985 +
50986 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50987 + error = -EACCES;
50988 + goto mnt_drop_write_and_out;
50989 + }
50990 +
50991 mutex_lock(&inode->i_mutex);
50992 error = notify_change(path->dentry, &newattrs);
50993 mutex_unlock(&inode->i_mutex);
50994 diff --git a/fs/xattr.c b/fs/xattr.c
50995 index 4d45b71..2ec08e10 100644
50996 --- a/fs/xattr.c
50997 +++ b/fs/xattr.c
50998 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50999 * Extended attribute SET operations
51000 */
51001 static long
51002 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
51003 +setxattr(struct path *path, const char __user *name, const void __user *value,
51004 size_t size, int flags)
51005 {
51006 int error;
51007 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
51008 }
51009 }
51010
51011 - error = vfs_setxattr(d, kname, kvalue, size, flags);
51012 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
51013 + error = -EACCES;
51014 + goto out;
51015 + }
51016 +
51017 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
51018 out:
51019 if (vvalue)
51020 vfree(vvalue);
51021 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
51022 return error;
51023 error = mnt_want_write(path.mnt);
51024 if (!error) {
51025 - error = setxattr(path.dentry, name, value, size, flags);
51026 + error = setxattr(&path, name, value, size, flags);
51027 mnt_drop_write(path.mnt);
51028 }
51029 path_put(&path);
51030 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
51031 return error;
51032 error = mnt_want_write(path.mnt);
51033 if (!error) {
51034 - error = setxattr(path.dentry, name, value, size, flags);
51035 + error = setxattr(&path, name, value, size, flags);
51036 mnt_drop_write(path.mnt);
51037 }
51038 path_put(&path);
51039 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
51040 {
51041 int fput_needed;
51042 struct file *f;
51043 - struct dentry *dentry;
51044 int error = -EBADF;
51045
51046 f = fget_light(fd, &fput_needed);
51047 if (!f)
51048 return error;
51049 - dentry = f->f_path.dentry;
51050 - audit_inode(NULL, dentry);
51051 + audit_inode(NULL, f->f_path.dentry);
51052 error = mnt_want_write_file(f);
51053 if (!error) {
51054 - error = setxattr(dentry, name, value, size, flags);
51055 + error = setxattr(&f->f_path, name, value, size, flags);
51056 mnt_drop_write_file(f);
51057 }
51058 fput_light(f, fput_needed);
51059 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
51060 index 69d06b0..c0996e5 100644
51061 --- a/fs/xattr_acl.c
51062 +++ b/fs/xattr_acl.c
51063 @@ -17,8 +17,8 @@
51064 struct posix_acl *
51065 posix_acl_from_xattr(const void *value, size_t size)
51066 {
51067 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
51068 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
51069 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
51070 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
51071 int count;
51072 struct posix_acl *acl;
51073 struct posix_acl_entry *acl_e;
51074 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
51075 index 848ffa7..1f249bf 100644
51076 --- a/fs/xfs/xfs_bmap.c
51077 +++ b/fs/xfs/xfs_bmap.c
51078 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
51079 int nmap,
51080 int ret_nmap);
51081 #else
51082 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
51083 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
51084 #endif /* DEBUG */
51085
51086 STATIC int
51087 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
51088 index 1b9fc3e..e1bdde0 100644
51089 --- a/fs/xfs/xfs_dir2_sf.c
51090 +++ b/fs/xfs/xfs_dir2_sf.c
51091 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
51092 }
51093
51094 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
51095 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51096 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
51097 + char name[sfep->namelen];
51098 + memcpy(name, sfep->name, sfep->namelen);
51099 + if (filldir(dirent, name, sfep->namelen,
51100 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
51101 + *offset = off & 0x7fffffff;
51102 + return 0;
51103 + }
51104 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51105 off & 0x7fffffff, ino, DT_UNKNOWN)) {
51106 *offset = off & 0x7fffffff;
51107 return 0;
51108 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
51109 index 0e0232c..fa5c3fe 100644
51110 --- a/fs/xfs/xfs_ioctl.c
51111 +++ b/fs/xfs/xfs_ioctl.c
51112 @@ -126,7 +126,7 @@ xfs_find_handle(
51113 }
51114
51115 error = -EFAULT;
51116 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
51117 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
51118 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
51119 goto out_put;
51120
51121 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
51122 index 4e00cf0..3374374 100644
51123 --- a/fs/xfs/xfs_iops.c
51124 +++ b/fs/xfs/xfs_iops.c
51125 @@ -394,7 +394,7 @@ xfs_vn_put_link(
51126 struct nameidata *nd,
51127 void *p)
51128 {
51129 - char *s = nd_get_link(nd);
51130 + const char *s = nd_get_link(nd);
51131
51132 if (!IS_ERR(s))
51133 kfree(s);
51134 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
51135 new file mode 100644
51136 index 0000000..10c36fb
51137 --- /dev/null
51138 +++ b/grsecurity/Kconfig
51139 @@ -0,0 +1,964 @@
51140 +#
51141 +# grecurity configuration
51142 +#
51143 +menu "Memory Protections"
51144 +depends on GRKERNSEC
51145 +
51146 +config GRKERNSEC_KMEM
51147 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
51148 + default y if GRKERNSEC_CONFIG_AUTO
51149 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
51150 + help
51151 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
51152 + be written to or read from to modify or leak the contents of the running
51153 + kernel. /dev/port will also not be allowed to be opened. If you have module
51154 + support disabled, enabling this will close up four ways that are
51155 + currently used to insert malicious code into the running kernel.
51156 + Even with all these features enabled, we still highly recommend that
51157 + you use the RBAC system, as it is still possible for an attacker to
51158 + modify the running kernel through privileged I/O granted by ioperm/iopl.
51159 + If you are not using XFree86, you may be able to stop this additional
51160 + case by enabling the 'Disable privileged I/O' option. Though nothing
51161 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
51162 + but only to video memory, which is the only writing we allow in this
51163 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
51164 + not be allowed to mprotect it with PROT_WRITE later.
51165 + It is highly recommended that you say Y here if you meet all the
51166 + conditions above.
51167 +
51168 +config GRKERNSEC_VM86
51169 + bool "Restrict VM86 mode"
51170 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51171 + depends on X86_32
51172 +
51173 + help
51174 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
51175 + make use of a special execution mode on 32bit x86 processors called
51176 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
51177 + video cards and will still work with this option enabled. The purpose
51178 + of the option is to prevent exploitation of emulation errors in
51179 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
51180 + Nearly all users should be able to enable this option.
51181 +
51182 +config GRKERNSEC_IO
51183 + bool "Disable privileged I/O"
51184 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51185 + depends on X86
51186 + select RTC_CLASS
51187 + select RTC_INTF_DEV
51188 + select RTC_DRV_CMOS
51189 +
51190 + help
51191 + If you say Y here, all ioperm and iopl calls will return an error.
51192 + Ioperm and iopl can be used to modify the running kernel.
51193 + Unfortunately, some programs need this access to operate properly,
51194 + the most notable of which are XFree86 and hwclock. hwclock can be
51195 + remedied by having RTC support in the kernel, so real-time
51196 + clock support is enabled if this option is enabled, to ensure
51197 + that hwclock operates correctly. XFree86 still will not
51198 + operate correctly with this option enabled, so DO NOT CHOOSE Y
51199 + IF YOU USE XFree86. If you use XFree86 and you still want to
51200 + protect your kernel against modification, use the RBAC system.
51201 +
51202 +config GRKERNSEC_JIT_HARDEN
51203 + bool "Harden BPF JIT against spray attacks"
51204 + default y if GRKERNSEC_CONFIG_AUTO
51205 + depends on BPF_JIT
51206 + help
51207 + If you say Y here, the native code generated by the kernel's Berkeley
51208 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
51209 + attacks that attempt to fit attacker-beneficial instructions in
51210 + 32bit immediate fields of JIT-generated native instructions. The
51211 + attacker will generally aim to cause an unintended instruction sequence
51212 + of JIT-generated native code to execute by jumping into the middle of
51213 + a generated instruction. This feature effectively randomizes the 32bit
51214 + immediate constants present in the generated code to thwart such attacks.
51215 +
51216 + If you're using KERNEXEC, it's recommended that you enable this option
51217 + to supplement the hardening of the kernel.
51218 +
51219 +config GRKERNSEC_PROC_MEMMAP
51220 + bool "Harden ASLR against information leaks and entropy reduction"
51221 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
51222 + depends on PAX_NOEXEC || PAX_ASLR
51223 + help
51224 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
51225 + give no information about the addresses of its mappings if
51226 + PaX features that rely on random addresses are enabled on the task.
51227 + In addition to sanitizing this information and disabling other
51228 + dangerous sources of information, this option causes reads of sensitive
51229 + /proc/<pid> entries where the file descriptor was opened in a different
51230 + task than the one performing the read. Such attempts are logged.
51231 + This option also limits argv/env strings for suid/sgid binaries
51232 + to 512KB to prevent a complete exhaustion of the stack entropy provided
51233 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
51234 + binaries to prevent alternative mmap layouts from being abused.
51235 +
51236 + If you use PaX it is essential that you say Y here as it closes up
51237 + several holes that make full ASLR useless locally.
51238 +
51239 +config GRKERNSEC_BRUTE
51240 + bool "Deter exploit bruteforcing"
51241 + default y if GRKERNSEC_CONFIG_AUTO
51242 + help
51243 + If you say Y here, attempts to bruteforce exploits against forking
51244 + daemons such as apache or sshd, as well as against suid/sgid binaries
51245 + will be deterred. When a child of a forking daemon is killed by PaX
51246 + or crashes due to an illegal instruction or other suspicious signal,
51247 + the parent process will be delayed 30 seconds upon every subsequent
51248 + fork until the administrator is able to assess the situation and
51249 + restart the daemon.
51250 + In the suid/sgid case, the attempt is logged, the user has all their
51251 + processes terminated, and they are prevented from executing any further
51252 + processes for 15 minutes.
51253 + It is recommended that you also enable signal logging in the auditing
51254 + section so that logs are generated when a process triggers a suspicious
51255 + signal.
51256 + If the sysctl option is enabled, a sysctl option with name
51257 + "deter_bruteforce" is created.
51258 +
51259 +
51260 +config GRKERNSEC_MODHARDEN
51261 + bool "Harden module auto-loading"
51262 + default y if GRKERNSEC_CONFIG_AUTO
51263 + depends on MODULES
51264 + help
51265 + If you say Y here, module auto-loading in response to use of some
51266 + feature implemented by an unloaded module will be restricted to
51267 + root users. Enabling this option helps defend against attacks
51268 + by unprivileged users who abuse the auto-loading behavior to
51269 + cause a vulnerable module to load that is then exploited.
51270 +
51271 + If this option prevents a legitimate use of auto-loading for a
51272 + non-root user, the administrator can execute modprobe manually
51273 + with the exact name of the module mentioned in the alert log.
51274 + Alternatively, the administrator can add the module to the list
51275 + of modules loaded at boot by modifying init scripts.
51276 +
51277 + Modification of init scripts will most likely be needed on
51278 + Ubuntu servers with encrypted home directory support enabled,
51279 + as the first non-root user logging in will cause the ecb(aes),
51280 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
51281 +
51282 +config GRKERNSEC_HIDESYM
51283 + bool "Hide kernel symbols"
51284 + default y if GRKERNSEC_CONFIG_AUTO
51285 + select PAX_USERCOPY_SLABS
51286 + help
51287 + If you say Y here, getting information on loaded modules, and
51288 + displaying all kernel symbols through a syscall will be restricted
51289 + to users with CAP_SYS_MODULE. For software compatibility reasons,
51290 + /proc/kallsyms will be restricted to the root user. The RBAC
51291 + system can hide that entry even from root.
51292 +
51293 + This option also prevents leaking of kernel addresses through
51294 + several /proc entries.
51295 +
51296 + Note that this option is only effective provided the following
51297 + conditions are met:
51298 + 1) The kernel using grsecurity is not precompiled by some distribution
51299 + 2) You have also enabled GRKERNSEC_DMESG
51300 + 3) You are using the RBAC system and hiding other files such as your
51301 + kernel image and System.map. Alternatively, enabling this option
51302 + causes the permissions on /boot, /lib/modules, and the kernel
51303 + source directory to change at compile time to prevent
51304 + reading by non-root users.
51305 + If the above conditions are met, this option will aid in providing a
51306 + useful protection against local kernel exploitation of overflows
51307 + and arbitrary read/write vulnerabilities.
51308 +
51309 +config GRKERNSEC_KERN_LOCKOUT
51310 + bool "Active kernel exploit response"
51311 + default y if GRKERNSEC_CONFIG_AUTO
51312 + depends on X86 || ARM || PPC || SPARC
51313 + help
51314 + If you say Y here, when a PaX alert is triggered due to suspicious
51315 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
51316 + or an OOPS occurs due to bad memory accesses, instead of just
51317 + terminating the offending process (and potentially allowing
51318 + a subsequent exploit from the same user), we will take one of two
51319 + actions:
51320 + If the user was root, we will panic the system
51321 + If the user was non-root, we will log the attempt, terminate
51322 + all processes owned by the user, then prevent them from creating
51323 + any new processes until the system is restarted
51324 + This deters repeated kernel exploitation/bruteforcing attempts
51325 + and is useful for later forensics.
51326 +
51327 +endmenu
51328 +menu "Role Based Access Control Options"
51329 +depends on GRKERNSEC
51330 +
51331 +config GRKERNSEC_RBAC_DEBUG
51332 + bool
51333 +
51334 +config GRKERNSEC_NO_RBAC
51335 + bool "Disable RBAC system"
51336 + help
51337 + If you say Y here, the /dev/grsec device will be removed from the kernel,
51338 + preventing the RBAC system from being enabled. You should only say Y
51339 + here if you have no intention of using the RBAC system, so as to prevent
51340 + an attacker with root access from misusing the RBAC system to hide files
51341 + and processes when loadable module support and /dev/[k]mem have been
51342 + locked down.
51343 +
51344 +config GRKERNSEC_ACL_HIDEKERN
51345 + bool "Hide kernel processes"
51346 + help
51347 + If you say Y here, all kernel threads will be hidden to all
51348 + processes but those whose subject has the "view hidden processes"
51349 + flag.
51350 +
51351 +config GRKERNSEC_ACL_MAXTRIES
51352 + int "Maximum tries before password lockout"
51353 + default 3
51354 + help
51355 + This option enforces the maximum number of times a user can attempt
51356 + to authorize themselves with the grsecurity RBAC system before being
51357 + denied the ability to attempt authorization again for a specified time.
51358 + The lower the number, the harder it will be to brute-force a password.
51359 +
51360 +config GRKERNSEC_ACL_TIMEOUT
51361 + int "Time to wait after max password tries, in seconds"
51362 + default 30
51363 + help
51364 + This option specifies the time the user must wait after attempting to
51365 + authorize to the RBAC system with the maximum number of invalid
51366 + passwords. The higher the number, the harder it will be to brute-force
51367 + a password.
51368 +
51369 +endmenu
51370 +menu "Filesystem Protections"
51371 +depends on GRKERNSEC
51372 +
51373 +config GRKERNSEC_PROC
51374 + bool "Proc restrictions"
51375 + default y if GRKERNSEC_CONFIG_AUTO
51376 + help
51377 + If you say Y here, the permissions of the /proc filesystem
51378 + will be altered to enhance system security and privacy. You MUST
51379 + choose either a user only restriction or a user and group restriction.
51380 + Depending upon the option you choose, you can either restrict users to
51381 + see only the processes they themselves run, or choose a group that can
51382 + view all processes and files normally restricted to root if you choose
51383 + the "restrict to user only" option. NOTE: If you're running identd or
51384 + ntpd as a non-root user, you will have to run it as the group you
51385 + specify here.
51386 +
51387 +config GRKERNSEC_PROC_USER
51388 + bool "Restrict /proc to user only"
51389 + depends on GRKERNSEC_PROC
51390 + help
51391 + If you say Y here, non-root users will only be able to view their own
51392 + processes, and restricts them from viewing network-related information,
51393 + and viewing kernel symbol and module information.
51394 +
51395 +config GRKERNSEC_PROC_USERGROUP
51396 + bool "Allow special group"
51397 + default y if GRKERNSEC_CONFIG_AUTO
51398 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
51399 + help
51400 + If you say Y here, you will be able to select a group that will be
51401 + able to view all processes and network-related information. If you've
51402 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
51403 + remain hidden. This option is useful if you want to run identd as
51404 + a non-root user. The group you select may also be chosen at boot time
51405 + via "grsec_proc_gid=" on the kernel commandline.
51406 +
51407 +config GRKERNSEC_PROC_GID
51408 + int "GID for special group"
51409 + depends on GRKERNSEC_PROC_USERGROUP
51410 + default 1001
51411 +
51412 +config GRKERNSEC_PROC_ADD
51413 + bool "Additional restrictions"
51414 + default y if GRKERNSEC_CONFIG_AUTO
51415 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
51416 + help
51417 + If you say Y here, additional restrictions will be placed on
51418 + /proc that keep normal users from viewing device information and
51419 + slabinfo information that could be useful for exploits.
51420 +
51421 +config GRKERNSEC_LINK
51422 + bool "Linking restrictions"
51423 + default y if GRKERNSEC_CONFIG_AUTO
51424 + help
51425 + If you say Y here, /tmp race exploits will be prevented, since users
51426 + will no longer be able to follow symlinks owned by other users in
51427 + world-writable +t directories (e.g. /tmp), unless the owner of the
51428 + symlink is the owner of the directory. users will also not be
51429 + able to hardlink to files they do not own. If the sysctl option is
51430 + enabled, a sysctl option with name "linking_restrictions" is created.
51431 +
51432 +config GRKERNSEC_SYMLINKOWN
51433 + bool "Kernel-enforced SymlinksIfOwnerMatch"
51434 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51435 + help
51436 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
51437 + that prevents it from being used as a security feature. As Apache
51438 + verifies the symlink by performing a stat() against the target of
51439 + the symlink before it is followed, an attacker can setup a symlink
51440 + to point to a same-owned file, then replace the symlink with one
51441 + that targets another user's file just after Apache "validates" the
51442 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
51443 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
51444 + will be in place for the group you specify. If the sysctl option
51445 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
51446 + created.
51447 +
51448 +config GRKERNSEC_SYMLINKOWN_GID
51449 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
51450 + depends on GRKERNSEC_SYMLINKOWN
51451 + default 1006
51452 + help
51453 + Setting this GID determines what group kernel-enforced
51454 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
51455 + is enabled, a sysctl option with name "symlinkown_gid" is created.
51456 +
51457 +config GRKERNSEC_FIFO
51458 + bool "FIFO restrictions"
51459 + default y if GRKERNSEC_CONFIG_AUTO
51460 + help
51461 + If you say Y here, users will not be able to write to FIFOs they don't
51462 + own in world-writable +t directories (e.g. /tmp), unless the owner of
51463 + the FIFO is the same owner of the directory it's held in. If the sysctl
51464 + option is enabled, a sysctl option with name "fifo_restrictions" is
51465 + created.
51466 +
51467 +config GRKERNSEC_SYSFS_RESTRICT
51468 + bool "Sysfs/debugfs restriction"
51469 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51470 + depends on SYSFS
51471 + help
51472 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51473 + any filesystem normally mounted under it (e.g. debugfs) will be
51474 + mostly accessible only by root. These filesystems generally provide access
51475 + to hardware and debug information that isn't appropriate for unprivileged
51476 + users of the system. Sysfs and debugfs have also become a large source
51477 + of new vulnerabilities, ranging from infoleaks to local compromise.
51478 + There has been very little oversight with an eye toward security involved
51479 + in adding new exporters of information to these filesystems, so their
51480 + use is discouraged.
51481 + For reasons of compatibility, a few directories have been whitelisted
51482 + for access by non-root users:
51483 + /sys/fs/selinux
51484 + /sys/fs/fuse
51485 + /sys/devices/system/cpu
51486 +
51487 +config GRKERNSEC_ROFS
51488 + bool "Runtime read-only mount protection"
51489 + help
51490 + If you say Y here, a sysctl option with name "romount_protect" will
51491 + be created. By setting this option to 1 at runtime, filesystems
51492 + will be protected in the following ways:
51493 + * No new writable mounts will be allowed
51494 + * Existing read-only mounts won't be able to be remounted read/write
51495 + * Write operations will be denied on all block devices
51496 + This option acts independently of grsec_lock: once it is set to 1,
51497 + it cannot be turned off. Therefore, please be mindful of the resulting
51498 + behavior if this option is enabled in an init script on a read-only
51499 + filesystem. This feature is mainly intended for secure embedded systems.
51500 +
51501 +config GRKERNSEC_CHROOT
51502 + bool "Chroot jail restrictions"
51503 + default y if GRKERNSEC_CONFIG_AUTO
51504 + help
51505 + If you say Y here, you will be able to choose several options that will
51506 + make breaking out of a chrooted jail much more difficult. If you
51507 + encounter no software incompatibilities with the following options, it
51508 + is recommended that you enable each one.
51509 +
51510 +config GRKERNSEC_CHROOT_MOUNT
51511 + bool "Deny mounts"
51512 + default y if GRKERNSEC_CONFIG_AUTO
51513 + depends on GRKERNSEC_CHROOT
51514 + help
51515 + If you say Y here, processes inside a chroot will not be able to
51516 + mount or remount filesystems. If the sysctl option is enabled, a
51517 + sysctl option with name "chroot_deny_mount" is created.
51518 +
51519 +config GRKERNSEC_CHROOT_DOUBLE
51520 + bool "Deny double-chroots"
51521 + default y if GRKERNSEC_CONFIG_AUTO
51522 + depends on GRKERNSEC_CHROOT
51523 + help
51524 + If you say Y here, processes inside a chroot will not be able to chroot
51525 + again outside the chroot. This is a widely used method of breaking
51526 + out of a chroot jail and should not be allowed. If the sysctl
51527 + option is enabled, a sysctl option with name
51528 + "chroot_deny_chroot" is created.
51529 +
51530 +config GRKERNSEC_CHROOT_PIVOT
51531 + bool "Deny pivot_root in chroot"
51532 + default y if GRKERNSEC_CONFIG_AUTO
51533 + depends on GRKERNSEC_CHROOT
51534 + help
51535 + If you say Y here, processes inside a chroot will not be able to use
51536 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51537 + works similar to chroot in that it changes the root filesystem. This
51538 + function could be misused in a chrooted process to attempt to break out
51539 + of the chroot, and therefore should not be allowed. If the sysctl
51540 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51541 + created.
51542 +
51543 +config GRKERNSEC_CHROOT_CHDIR
51544 + bool "Enforce chdir(\"/\") on all chroots"
51545 + default y if GRKERNSEC_CONFIG_AUTO
51546 + depends on GRKERNSEC_CHROOT
51547 + help
51548 + If you say Y here, the current working directory of all newly-chrooted
51549 + applications will be set to the the root directory of the chroot.
51550 + The man page on chroot(2) states:
51551 + Note that this call does not change the current working
51552 + directory, so that `.' can be outside the tree rooted at
51553 + `/'. In particular, the super-user can escape from a
51554 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51555 +
51556 + It is recommended that you say Y here, since it's not known to break
51557 + any software. If the sysctl option is enabled, a sysctl option with
51558 + name "chroot_enforce_chdir" is created.
51559 +
51560 +config GRKERNSEC_CHROOT_CHMOD
51561 + bool "Deny (f)chmod +s"
51562 + default y if GRKERNSEC_CONFIG_AUTO
51563 + depends on GRKERNSEC_CHROOT
51564 + help
51565 + If you say Y here, processes inside a chroot will not be able to chmod
51566 + or fchmod files to make them have suid or sgid bits. This protects
51567 + against another published method of breaking a chroot. If the sysctl
51568 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51569 + created.
51570 +
51571 +config GRKERNSEC_CHROOT_FCHDIR
51572 + bool "Deny fchdir out of chroot"
51573 + default y if GRKERNSEC_CONFIG_AUTO
51574 + depends on GRKERNSEC_CHROOT
51575 + help
51576 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51577 + to a file descriptor of the chrooting process that points to a directory
51578 + outside the filesystem will be stopped. If the sysctl option
51579 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51580 +
51581 +config GRKERNSEC_CHROOT_MKNOD
51582 + bool "Deny mknod"
51583 + default y if GRKERNSEC_CONFIG_AUTO
51584 + depends on GRKERNSEC_CHROOT
51585 + help
51586 + If you say Y here, processes inside a chroot will not be allowed to
51587 + mknod. The problem with using mknod inside a chroot is that it
51588 + would allow an attacker to create a device entry that is the same
51589 + as one on the physical root of your system, which could range from
51590 + anything from the console device to a device for your harddrive (which
51591 + they could then use to wipe the drive or steal data). It is recommended
51592 + that you say Y here, unless you run into software incompatibilities.
51593 + If the sysctl option is enabled, a sysctl option with name
51594 + "chroot_deny_mknod" is created.
51595 +
51596 +config GRKERNSEC_CHROOT_SHMAT
51597 + bool "Deny shmat() out of chroot"
51598 + default y if GRKERNSEC_CONFIG_AUTO
51599 + depends on GRKERNSEC_CHROOT
51600 + help
51601 + If you say Y here, processes inside a chroot will not be able to attach
51602 + to shared memory segments that were created outside of the chroot jail.
51603 + It is recommended that you say Y here. If the sysctl option is enabled,
51604 + a sysctl option with name "chroot_deny_shmat" is created.
51605 +
51606 +config GRKERNSEC_CHROOT_UNIX
51607 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51608 + default y if GRKERNSEC_CONFIG_AUTO
51609 + depends on GRKERNSEC_CHROOT
51610 + help
51611 + If you say Y here, processes inside a chroot will not be able to
51612 + connect to abstract (meaning not belonging to a filesystem) Unix
51613 + domain sockets that were bound outside of a chroot. It is recommended
51614 + that you say Y here. If the sysctl option is enabled, a sysctl option
51615 + with name "chroot_deny_unix" is created.
51616 +
51617 +config GRKERNSEC_CHROOT_FINDTASK
51618 + bool "Protect outside processes"
51619 + default y if GRKERNSEC_CONFIG_AUTO
51620 + depends on GRKERNSEC_CHROOT
51621 + help
51622 + If you say Y here, processes inside a chroot will not be able to
51623 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51624 + getsid, or view any process outside of the chroot. If the sysctl
51625 + option is enabled, a sysctl option with name "chroot_findtask" is
51626 + created.
51627 +
51628 +config GRKERNSEC_CHROOT_NICE
51629 + bool "Restrict priority changes"
51630 + default y if GRKERNSEC_CONFIG_AUTO
51631 + depends on GRKERNSEC_CHROOT
51632 + help
51633 + If you say Y here, processes inside a chroot will not be able to raise
51634 + the priority of processes in the chroot, or alter the priority of
51635 + processes outside the chroot. This provides more security than simply
51636 + removing CAP_SYS_NICE from the process' capability set. If the
51637 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51638 + is created.
51639 +
51640 +config GRKERNSEC_CHROOT_SYSCTL
51641 + bool "Deny sysctl writes"
51642 + default y if GRKERNSEC_CONFIG_AUTO
51643 + depends on GRKERNSEC_CHROOT
51644 + help
51645 + If you say Y here, an attacker in a chroot will not be able to
51646 + write to sysctl entries, either by sysctl(2) or through a /proc
51647 + interface. It is strongly recommended that you say Y here. If the
51648 + sysctl option is enabled, a sysctl option with name
51649 + "chroot_deny_sysctl" is created.
51650 +
51651 +config GRKERNSEC_CHROOT_CAPS
51652 + bool "Capability restrictions"
51653 + default y if GRKERNSEC_CONFIG_AUTO
51654 + depends on GRKERNSEC_CHROOT
51655 + help
51656 + If you say Y here, the capabilities on all processes within a
51657 + chroot jail will be lowered to stop module insertion, raw i/o,
51658 + system and net admin tasks, rebooting the system, modifying immutable
51659 + files, modifying IPC owned by another, and changing the system time.
51660 + This is left an option because it can break some apps. Disable this
51661 + if your chrooted apps are having problems performing those kinds of
51662 + tasks. If the sysctl option is enabled, a sysctl option with
51663 + name "chroot_caps" is created.
51664 +
51665 +endmenu
51666 +menu "Kernel Auditing"
51667 +depends on GRKERNSEC
51668 +
51669 +config GRKERNSEC_AUDIT_GROUP
51670 + bool "Single group for auditing"
51671 + help
51672 + If you say Y here, the exec, chdir, and (un)mount logging features
51673 + will only operate on a group you specify. This option is recommended
51674 + if you only want to watch certain users instead of having a large
51675 + amount of logs from the entire system. If the sysctl option is enabled,
51676 + a sysctl option with name "audit_group" is created.
51677 +
51678 +config GRKERNSEC_AUDIT_GID
51679 + int "GID for auditing"
51680 + depends on GRKERNSEC_AUDIT_GROUP
51681 + default 1007
51682 +
51683 +config GRKERNSEC_EXECLOG
51684 + bool "Exec logging"
51685 + help
51686 + If you say Y here, all execve() calls will be logged (since the
51687 + other exec*() calls are frontends to execve(), all execution
51688 + will be logged). Useful for shell-servers that like to keep track
51689 + of their users. If the sysctl option is enabled, a sysctl option with
51690 + name "exec_logging" is created.
51691 + WARNING: This option when enabled will produce a LOT of logs, especially
51692 + on an active system.
51693 +
51694 +config GRKERNSEC_RESLOG
51695 + bool "Resource logging"
51696 + default y if GRKERNSEC_CONFIG_AUTO
51697 + help
51698 + If you say Y here, all attempts to overstep resource limits will
51699 + be logged with the resource name, the requested size, and the current
51700 + limit. It is highly recommended that you say Y here. If the sysctl
51701 + option is enabled, a sysctl option with name "resource_logging" is
51702 + created. If the RBAC system is enabled, the sysctl value is ignored.
51703 +
51704 +config GRKERNSEC_CHROOT_EXECLOG
51705 + bool "Log execs within chroot"
51706 + help
51707 + If you say Y here, all executions inside a chroot jail will be logged
51708 + to syslog. This can cause a large amount of logs if certain
51709 + applications (eg. djb's daemontools) are installed on the system, and
51710 + is therefore left as an option. If the sysctl option is enabled, a
51711 + sysctl option with name "chroot_execlog" is created.
51712 +
51713 +config GRKERNSEC_AUDIT_PTRACE
51714 + bool "Ptrace logging"
51715 + help
51716 + If you say Y here, all attempts to attach to a process via ptrace
51717 + will be logged. If the sysctl option is enabled, a sysctl option
51718 + with name "audit_ptrace" is created.
51719 +
51720 +config GRKERNSEC_AUDIT_CHDIR
51721 + bool "Chdir logging"
51722 + help
51723 + If you say Y here, all chdir() calls will be logged. If the sysctl
51724 + option is enabled, a sysctl option with name "audit_chdir" is created.
51725 +
51726 +config GRKERNSEC_AUDIT_MOUNT
51727 + bool "(Un)Mount logging"
51728 + help
51729 + If you say Y here, all mounts and unmounts will be logged. If the
51730 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51731 + created.
51732 +
51733 +config GRKERNSEC_SIGNAL
51734 + bool "Signal logging"
51735 + default y if GRKERNSEC_CONFIG_AUTO
51736 + help
51737 + If you say Y here, certain important signals will be logged, such as
51738 + SIGSEGV, which will as a result inform you of when a error in a program
51739 + occurred, which in some cases could mean a possible exploit attempt.
51740 + If the sysctl option is enabled, a sysctl option with name
51741 + "signal_logging" is created.
51742 +
51743 +config GRKERNSEC_FORKFAIL
51744 + bool "Fork failure logging"
51745 + help
51746 + If you say Y here, all failed fork() attempts will be logged.
51747 + This could suggest a fork bomb, or someone attempting to overstep
51748 + their process limit. If the sysctl option is enabled, a sysctl option
51749 + with name "forkfail_logging" is created.
51750 +
51751 +config GRKERNSEC_TIME
51752 + bool "Time change logging"
51753 + default y if GRKERNSEC_CONFIG_AUTO
51754 + help
51755 + If you say Y here, any changes of the system clock will be logged.
51756 + If the sysctl option is enabled, a sysctl option with name
51757 + "timechange_logging" is created.
51758 +
51759 +config GRKERNSEC_PROC_IPADDR
51760 + bool "/proc/<pid>/ipaddr support"
51761 + default y if GRKERNSEC_CONFIG_AUTO
51762 + help
51763 + If you say Y here, a new entry will be added to each /proc/<pid>
51764 + directory that contains the IP address of the person using the task.
51765 + The IP is carried across local TCP and AF_UNIX stream sockets.
51766 + This information can be useful for IDS/IPSes to perform remote response
51767 + to a local attack. The entry is readable by only the owner of the
51768 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51769 + the RBAC system), and thus does not create privacy concerns.
51770 +
51771 +config GRKERNSEC_RWXMAP_LOG
51772 + bool 'Denied RWX mmap/mprotect logging'
51773 + default y if GRKERNSEC_CONFIG_AUTO
51774 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51775 + help
51776 + If you say Y here, calls to mmap() and mprotect() with explicit
51777 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51778 + denied by the PAX_MPROTECT feature. If the sysctl option is
51779 + enabled, a sysctl option with name "rwxmap_logging" is created.
51780 +
51781 +config GRKERNSEC_AUDIT_TEXTREL
51782 + bool 'ELF text relocations logging (READ HELP)'
51783 + depends on PAX_MPROTECT
51784 + help
51785 + If you say Y here, text relocations will be logged with the filename
51786 + of the offending library or binary. The purpose of the feature is
51787 + to help Linux distribution developers get rid of libraries and
51788 + binaries that need text relocations which hinder the future progress
51789 + of PaX. Only Linux distribution developers should say Y here, and
51790 + never on a production machine, as this option creates an information
51791 + leak that could aid an attacker in defeating the randomization of
51792 + a single memory region. If the sysctl option is enabled, a sysctl
51793 + option with name "audit_textrel" is created.
51794 +
51795 +endmenu
51796 +
51797 +menu "Executable Protections"
51798 +depends on GRKERNSEC
51799 +
51800 +config GRKERNSEC_DMESG
51801 + bool "Dmesg(8) restriction"
51802 + default y if GRKERNSEC_CONFIG_AUTO
51803 + help
51804 + If you say Y here, non-root users will not be able to use dmesg(8)
51805 + to view up to the last 4kb of messages in the kernel's log buffer.
51806 + The kernel's log buffer often contains kernel addresses and other
51807 + identifying information useful to an attacker in fingerprinting a
51808 + system for a targeted exploit.
51809 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51810 + created.
51811 +
51812 +config GRKERNSEC_HARDEN_PTRACE
51813 + bool "Deter ptrace-based process snooping"
51814 + default y if GRKERNSEC_CONFIG_AUTO
51815 + help
51816 + If you say Y here, TTY sniffers and other malicious monitoring
51817 + programs implemented through ptrace will be defeated. If you
51818 + have been using the RBAC system, this option has already been
51819 + enabled for several years for all users, with the ability to make
51820 + fine-grained exceptions.
51821 +
51822 + This option only affects the ability of non-root users to ptrace
51823 + processes that are not a descendent of the ptracing process.
51824 + This means that strace ./binary and gdb ./binary will still work,
51825 + but attaching to arbitrary processes will not. If the sysctl
51826 + option is enabled, a sysctl option with name "harden_ptrace" is
51827 + created.
51828 +
51829 +config GRKERNSEC_PTRACE_READEXEC
51830 + bool "Require read access to ptrace sensitive binaries"
51831 + default y if GRKERNSEC_CONFIG_AUTO
51832 + help
51833 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51834 + binaries. This option is useful in environments that
51835 + remove the read bits (e.g. file mode 4711) from suid binaries to
51836 + prevent infoleaking of their contents. This option adds
51837 + consistency to the use of that file mode, as the binary could normally
51838 + be read out when run without privileges while ptracing.
51839 +
51840 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51841 + is created.
51842 +
51843 +config GRKERNSEC_SETXID
51844 + bool "Enforce consistent multithreaded privileges"
51845 + default y if GRKERNSEC_CONFIG_AUTO
51846 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51847 + help
51848 + If you say Y here, a change from a root uid to a non-root uid
51849 + in a multithreaded application will cause the resulting uids,
51850 + gids, supplementary groups, and capabilities in that thread
51851 + to be propagated to the other threads of the process. In most
51852 + cases this is unnecessary, as glibc will emulate this behavior
51853 + on behalf of the application. Other libcs do not act in the
51854 + same way, allowing the other threads of the process to continue
51855 + running with root privileges. If the sysctl option is enabled,
51856 + a sysctl option with name "consistent_setxid" is created.
51857 +
51858 +config GRKERNSEC_TPE
51859 + bool "Trusted Path Execution (TPE)"
51860 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51861 + help
51862 + If you say Y here, you will be able to choose a gid to add to the
51863 + supplementary groups of users you want to mark as "untrusted."
51864 + These users will not be able to execute any files that are not in
51865 + root-owned directories writable only by root. If the sysctl option
51866 + is enabled, a sysctl option with name "tpe" is created.
51867 +
51868 +config GRKERNSEC_TPE_ALL
51869 + bool "Partially restrict all non-root users"
51870 + depends on GRKERNSEC_TPE
51871 + help
51872 + If you say Y here, all non-root users will be covered under
51873 + a weaker TPE restriction. This is separate from, and in addition to,
51874 + the main TPE options that you have selected elsewhere. Thus, if a
51875 + "trusted" GID is chosen, this restriction applies to even that GID.
51876 + Under this restriction, all non-root users will only be allowed to
51877 + execute files in directories they own that are not group or
51878 + world-writable, or in directories owned by root and writable only by
51879 + root. If the sysctl option is enabled, a sysctl option with name
51880 + "tpe_restrict_all" is created.
51881 +
51882 +config GRKERNSEC_TPE_INVERT
51883 + bool "Invert GID option"
51884 + depends on GRKERNSEC_TPE
51885 + help
51886 + If you say Y here, the group you specify in the TPE configuration will
51887 + decide what group TPE restrictions will be *disabled* for. This
51888 + option is useful if you want TPE restrictions to be applied to most
51889 + users on the system. If the sysctl option is enabled, a sysctl option
51890 + with name "tpe_invert" is created. Unlike other sysctl options, this
51891 + entry will default to on for backward-compatibility.
51892 +
51893 +config GRKERNSEC_TPE_GID
51894 + int
51895 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51896 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51897 +
51898 +config GRKERNSEC_TPE_UNTRUSTED_GID
51899 + int "GID for TPE-untrusted users"
51900 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51901 + default 1005
51902 + help
51903 + Setting this GID determines what group TPE restrictions will be
51904 + *enabled* for. If the sysctl option is enabled, a sysctl option
51905 + with name "tpe_gid" is created.
51906 +
51907 +config GRKERNSEC_TPE_TRUSTED_GID
51908 + int "GID for TPE-trusted users"
51909 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51910 + default 1005
51911 + help
51912 + Setting this GID determines what group TPE restrictions will be
51913 + *disabled* for. If the sysctl option is enabled, a sysctl option
51914 + with name "tpe_gid" is created.
51915 +
51916 +endmenu
51917 +menu "Network Protections"
51918 +depends on GRKERNSEC
51919 +
51920 +config GRKERNSEC_RANDNET
51921 + bool "Larger entropy pools"
51922 + default y if GRKERNSEC_CONFIG_AUTO
51923 + help
51924 + If you say Y here, the entropy pools used for many features of Linux
51925 + and grsecurity will be doubled in size. Since several grsecurity
51926 + features use additional randomness, it is recommended that you say Y
51927 + here. Saying Y here has a similar effect as modifying
51928 + /proc/sys/kernel/random/poolsize.
51929 +
51930 +config GRKERNSEC_BLACKHOLE
51931 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51932 + default y if GRKERNSEC_CONFIG_AUTO
51933 + depends on NET
51934 + help
51935 + If you say Y here, neither TCP resets nor ICMP
51936 + destination-unreachable packets will be sent in response to packets
51937 + sent to ports for which no associated listening process exists.
51938 + This feature supports both IPV4 and IPV6 and exempts the
51939 + loopback interface from blackholing. Enabling this feature
51940 + makes a host more resilient to DoS attacks and reduces network
51941 + visibility against scanners.
51942 +
51943 + The blackhole feature as-implemented is equivalent to the FreeBSD
51944 + blackhole feature, as it prevents RST responses to all packets, not
51945 + just SYNs. Under most application behavior this causes no
51946 + problems, but applications (like haproxy) may not close certain
51947 + connections in a way that cleanly terminates them on the remote
51948 + end, leaving the remote host in LAST_ACK state. Because of this
51949 + side-effect and to prevent intentional LAST_ACK DoSes, this
51950 + feature also adds automatic mitigation against such attacks.
51951 + The mitigation drastically reduces the amount of time a socket
51952 + can spend in LAST_ACK state. If you're using haproxy and not
51953 + all servers it connects to have this option enabled, consider
51954 + disabling this feature on the haproxy host.
51955 +
51956 + If the sysctl option is enabled, two sysctl options with names
51957 + "ip_blackhole" and "lastack_retries" will be created.
51958 + While "ip_blackhole" takes the standard zero/non-zero on/off
51959 + toggle, "lastack_retries" uses the same kinds of values as
51960 + "tcp_retries1" and "tcp_retries2". The default value of 4
51961 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51962 + state.
51963 +
51964 +config GRKERNSEC_SOCKET
51965 + bool "Socket restrictions"
51966 + depends on NET
51967 + help
51968 + If you say Y here, you will be able to choose from several options.
51969 + If you assign a GID on your system and add it to the supplementary
51970 + groups of users you want to restrict socket access to, this patch
51971 + will perform up to three things, based on the option(s) you choose.
51972 +
51973 +config GRKERNSEC_SOCKET_ALL
51974 + bool "Deny any sockets to group"
51975 + depends on GRKERNSEC_SOCKET
51976 + help
51977 + If you say Y here, you will be able to choose a GID of whose users will
51978 + be unable to connect to other hosts from your machine or run server
51979 + applications from your machine. If the sysctl option is enabled, a
51980 + sysctl option with name "socket_all" is created.
51981 +
51982 +config GRKERNSEC_SOCKET_ALL_GID
51983 + int "GID to deny all sockets for"
51984 + depends on GRKERNSEC_SOCKET_ALL
51985 + default 1004
51986 + help
51987 + Here you can choose the GID to disable socket access for. Remember to
51988 + add the users you want socket access disabled for to the GID
51989 + specified here. If the sysctl option is enabled, a sysctl option
51990 + with name "socket_all_gid" is created.
51991 +
51992 +config GRKERNSEC_SOCKET_CLIENT
51993 + bool "Deny client sockets to group"
51994 + depends on GRKERNSEC_SOCKET
51995 + help
51996 + If you say Y here, you will be able to choose a GID of whose users will
51997 + be unable to connect to other hosts from your machine, but will be
51998 + able to run servers. If this option is enabled, all users in the group
51999 + you specify will have to use passive mode when initiating ftp transfers
52000 + from the shell on your machine. If the sysctl option is enabled, a
52001 + sysctl option with name "socket_client" is created.
52002 +
52003 +config GRKERNSEC_SOCKET_CLIENT_GID
52004 + int "GID to deny client sockets for"
52005 + depends on GRKERNSEC_SOCKET_CLIENT
52006 + default 1003
52007 + help
52008 + Here you can choose the GID to disable client socket access for.
52009 + Remember to add the users you want client socket access disabled for to
52010 + the GID specified here. If the sysctl option is enabled, a sysctl
52011 + option with name "socket_client_gid" is created.
52012 +
52013 +config GRKERNSEC_SOCKET_SERVER
52014 + bool "Deny server sockets to group"
52015 + depends on GRKERNSEC_SOCKET
52016 + help
52017 + If you say Y here, you will be able to choose a GID of whose users will
52018 + be unable to run server applications from your machine. If the sysctl
52019 + option is enabled, a sysctl option with name "socket_server" is created.
52020 +
52021 +config GRKERNSEC_SOCKET_SERVER_GID
52022 + int "GID to deny server sockets for"
52023 + depends on GRKERNSEC_SOCKET_SERVER
52024 + default 1002
52025 + help
52026 + Here you can choose the GID to disable server socket access for.
52027 + Remember to add the users you want server socket access disabled for to
52028 + the GID specified here. If the sysctl option is enabled, a sysctl
52029 + option with name "socket_server_gid" is created.
52030 +
52031 +endmenu
52032 +menu "Sysctl Support"
52033 +depends on GRKERNSEC && SYSCTL
52034 +
52035 +config GRKERNSEC_SYSCTL
52036 + bool "Sysctl support"
52037 + default y if GRKERNSEC_CONFIG_AUTO
52038 + help
52039 + If you say Y here, you will be able to change the options that
52040 + grsecurity runs with at bootup, without having to recompile your
52041 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
52042 + to enable (1) or disable (0) various features. All the sysctl entries
52043 + are mutable until the "grsec_lock" entry is set to a non-zero value.
52044 + All features enabled in the kernel configuration are disabled at boot
52045 + if you do not say Y to the "Turn on features by default" option.
52046 + All options should be set at startup, and the grsec_lock entry should
52047 + be set to a non-zero value after all the options are set.
52048 + *THIS IS EXTREMELY IMPORTANT*
52049 +
52050 +config GRKERNSEC_SYSCTL_DISTRO
52051 + bool "Extra sysctl support for distro makers (READ HELP)"
52052 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
52053 + help
52054 + If you say Y here, additional sysctl options will be created
52055 + for features that affect processes running as root. Therefore,
52056 + it is critical when using this option that the grsec_lock entry be
52057 + enabled after boot. Only distros with prebuilt kernel packages
52058 + with this option enabled that can ensure grsec_lock is enabled
52059 + after boot should use this option.
52060 + *Failure to set grsec_lock after boot makes all grsec features
52061 + this option covers useless*
52062 +
52063 + Currently this option creates the following sysctl entries:
52064 + "Disable Privileged I/O": "disable_priv_io"
52065 +
52066 +config GRKERNSEC_SYSCTL_ON
52067 + bool "Turn on features by default"
52068 + default y if GRKERNSEC_CONFIG_AUTO
52069 + depends on GRKERNSEC_SYSCTL
52070 + help
52071 + If you say Y here, instead of having all features enabled in the
52072 + kernel configuration disabled at boot time, the features will be
52073 + enabled at boot time. It is recommended you say Y here unless
52074 + there is some reason you would want all sysctl-tunable features to
52075 + be disabled by default. As mentioned elsewhere, it is important
52076 + to enable the grsec_lock entry once you have finished modifying
52077 + the sysctl entries.
52078 +
52079 +endmenu
52080 +menu "Logging Options"
52081 +depends on GRKERNSEC
52082 +
52083 +config GRKERNSEC_FLOODTIME
52084 + int "Seconds in between log messages (minimum)"
52085 + default 10
52086 + help
52087 + This option allows you to enforce the number of seconds between
52088 + grsecurity log messages. The default should be suitable for most
52089 + people, however, if you choose to change it, choose a value small enough
52090 + to allow informative logs to be produced, but large enough to
52091 + prevent flooding.
52092 +
52093 +config GRKERNSEC_FLOODBURST
52094 + int "Number of messages in a burst (maximum)"
52095 + default 6
52096 + help
52097 + This option allows you to choose the maximum number of messages allowed
52098 + within the flood time interval you chose in a separate option. The
52099 + default should be suitable for most people, however if you find that
52100 + many of your logs are being interpreted as flooding, you may want to
52101 + raise this value.
52102 +
52103 +endmenu
52104 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
52105 new file mode 100644
52106 index 0000000..1b9afa9
52107 --- /dev/null
52108 +++ b/grsecurity/Makefile
52109 @@ -0,0 +1,38 @@
52110 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
52111 +# during 2001-2009 it has been completely redesigned by Brad Spengler
52112 +# into an RBAC system
52113 +#
52114 +# All code in this directory and various hooks inserted throughout the kernel
52115 +# are copyright Brad Spengler - Open Source Security, Inc., and released
52116 +# under the GPL v2 or higher
52117 +
52118 +KBUILD_CFLAGS += -Werror
52119 +
52120 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
52121 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
52122 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
52123 +
52124 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
52125 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
52126 + gracl_learn.o grsec_log.o
52127 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
52128 +
52129 +ifdef CONFIG_NET
52130 +obj-y += grsec_sock.o
52131 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
52132 +endif
52133 +
52134 +ifndef CONFIG_GRKERNSEC
52135 +obj-y += grsec_disabled.o
52136 +endif
52137 +
52138 +ifdef CONFIG_GRKERNSEC_HIDESYM
52139 +extra-y := grsec_hidesym.o
52140 +$(obj)/grsec_hidesym.o:
52141 + @-chmod -f 500 /boot
52142 + @-chmod -f 500 /lib/modules
52143 + @-chmod -f 500 /lib64/modules
52144 + @-chmod -f 500 /lib32/modules
52145 + @-chmod -f 700 .
52146 + @echo ' grsec: protected kernel image paths'
52147 +endif
52148 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
52149 new file mode 100644
52150 index 0000000..4428c82
52151 --- /dev/null
52152 +++ b/grsecurity/gracl.c
52153 @@ -0,0 +1,4056 @@
52154 +#include <linux/kernel.h>
52155 +#include <linux/module.h>
52156 +#include <linux/sched.h>
52157 +#include <linux/mm.h>
52158 +#include <linux/file.h>
52159 +#include <linux/fs.h>
52160 +#include <linux/namei.h>
52161 +#include <linux/mount.h>
52162 +#include <linux/tty.h>
52163 +#include <linux/proc_fs.h>
52164 +#include <linux/lglock.h>
52165 +#include <linux/slab.h>
52166 +#include <linux/vmalloc.h>
52167 +#include <linux/types.h>
52168 +#include <linux/sysctl.h>
52169 +#include <linux/netdevice.h>
52170 +#include <linux/ptrace.h>
52171 +#include <linux/gracl.h>
52172 +#include <linux/gralloc.h>
52173 +#include <linux/security.h>
52174 +#include <linux/grinternal.h>
52175 +#include <linux/pid_namespace.h>
52176 +#include <linux/stop_machine.h>
52177 +#include <linux/fdtable.h>
52178 +#include <linux/percpu.h>
52179 +#include <linux/lglock.h>
52180 +#include "../fs/mount.h"
52181 +
52182 +#include <asm/uaccess.h>
52183 +#include <asm/errno.h>
52184 +#include <asm/mman.h>
52185 +
52186 +extern struct lglock vfsmount_lock;
52187 +
52188 +static struct acl_role_db acl_role_set;
52189 +static struct name_db name_set;
52190 +static struct inodev_db inodev_set;
52191 +
52192 +/* for keeping track of userspace pointers used for subjects, so we
52193 + can share references in the kernel as well
52194 +*/
52195 +
52196 +static struct path real_root;
52197 +
52198 +static struct acl_subj_map_db subj_map_set;
52199 +
52200 +static struct acl_role_label *default_role;
52201 +
52202 +static struct acl_role_label *role_list;
52203 +
52204 +static u16 acl_sp_role_value;
52205 +
52206 +extern char *gr_shared_page[4];
52207 +static DEFINE_MUTEX(gr_dev_mutex);
52208 +DEFINE_RWLOCK(gr_inode_lock);
52209 +
52210 +struct gr_arg *gr_usermode;
52211 +
52212 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
52213 +
52214 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
52215 +extern void gr_clear_learn_entries(void);
52216 +
52217 +#ifdef CONFIG_GRKERNSEC_RESLOG
52218 +extern void gr_log_resource(const struct task_struct *task,
52219 + const int res, const unsigned long wanted, const int gt);
52220 +#endif
52221 +
52222 +unsigned char *gr_system_salt;
52223 +unsigned char *gr_system_sum;
52224 +
52225 +static struct sprole_pw **acl_special_roles = NULL;
52226 +static __u16 num_sprole_pws = 0;
52227 +
52228 +static struct acl_role_label *kernel_role = NULL;
52229 +
52230 +static unsigned int gr_auth_attempts = 0;
52231 +static unsigned long gr_auth_expires = 0UL;
52232 +
52233 +#ifdef CONFIG_NET
52234 +extern struct vfsmount *sock_mnt;
52235 +#endif
52236 +
52237 +extern struct vfsmount *pipe_mnt;
52238 +extern struct vfsmount *shm_mnt;
52239 +#ifdef CONFIG_HUGETLBFS
52240 +extern struct vfsmount *hugetlbfs_vfsmount;
52241 +#endif
52242 +
52243 +static struct acl_object_label *fakefs_obj_rw;
52244 +static struct acl_object_label *fakefs_obj_rwx;
52245 +
52246 +extern int gr_init_uidset(void);
52247 +extern void gr_free_uidset(void);
52248 +extern void gr_remove_uid(uid_t uid);
52249 +extern int gr_find_uid(uid_t uid);
52250 +
52251 +__inline__ int
52252 +gr_acl_is_enabled(void)
52253 +{
52254 + return (gr_status & GR_READY);
52255 +}
52256 +
52257 +#ifdef CONFIG_BTRFS_FS
52258 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
52259 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
52260 +#endif
52261 +
52262 +static inline dev_t __get_dev(const struct dentry *dentry)
52263 +{
52264 +#ifdef CONFIG_BTRFS_FS
52265 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
52266 + return get_btrfs_dev_from_inode(dentry->d_inode);
52267 + else
52268 +#endif
52269 + return dentry->d_inode->i_sb->s_dev;
52270 +}
52271 +
52272 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
52273 +{
52274 + return __get_dev(dentry);
52275 +}
52276 +
52277 +static char gr_task_roletype_to_char(struct task_struct *task)
52278 +{
52279 + switch (task->role->roletype &
52280 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
52281 + GR_ROLE_SPECIAL)) {
52282 + case GR_ROLE_DEFAULT:
52283 + return 'D';
52284 + case GR_ROLE_USER:
52285 + return 'U';
52286 + case GR_ROLE_GROUP:
52287 + return 'G';
52288 + case GR_ROLE_SPECIAL:
52289 + return 'S';
52290 + }
52291 +
52292 + return 'X';
52293 +}
52294 +
52295 +char gr_roletype_to_char(void)
52296 +{
52297 + return gr_task_roletype_to_char(current);
52298 +}
52299 +
52300 +__inline__ int
52301 +gr_acl_tpe_check(void)
52302 +{
52303 + if (unlikely(!(gr_status & GR_READY)))
52304 + return 0;
52305 + if (current->role->roletype & GR_ROLE_TPE)
52306 + return 1;
52307 + else
52308 + return 0;
52309 +}
52310 +
52311 +int
52312 +gr_handle_rawio(const struct inode *inode)
52313 +{
52314 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
52315 + if (inode && S_ISBLK(inode->i_mode) &&
52316 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
52317 + !capable(CAP_SYS_RAWIO))
52318 + return 1;
52319 +#endif
52320 + return 0;
52321 +}
52322 +
52323 +static int
52324 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
52325 +{
52326 + if (likely(lena != lenb))
52327 + return 0;
52328 +
52329 + return !memcmp(a, b, lena);
52330 +}
52331 +
52332 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
52333 +{
52334 + *buflen -= namelen;
52335 + if (*buflen < 0)
52336 + return -ENAMETOOLONG;
52337 + *buffer -= namelen;
52338 + memcpy(*buffer, str, namelen);
52339 + return 0;
52340 +}
52341 +
52342 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
52343 +{
52344 + return prepend(buffer, buflen, name->name, name->len);
52345 +}
52346 +
52347 +static int prepend_path(const struct path *path, struct path *root,
52348 + char **buffer, int *buflen)
52349 +{
52350 + struct dentry *dentry = path->dentry;
52351 + struct vfsmount *vfsmnt = path->mnt;
52352 + struct mount *mnt = real_mount(vfsmnt);
52353 + bool slash = false;
52354 + int error = 0;
52355 +
52356 + while (dentry != root->dentry || vfsmnt != root->mnt) {
52357 + struct dentry * parent;
52358 +
52359 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
52360 + /* Global root? */
52361 + if (!mnt_has_parent(mnt)) {
52362 + goto out;
52363 + }
52364 + dentry = mnt->mnt_mountpoint;
52365 + mnt = mnt->mnt_parent;
52366 + vfsmnt = &mnt->mnt;
52367 + continue;
52368 + }
52369 + parent = dentry->d_parent;
52370 + prefetch(parent);
52371 + spin_lock(&dentry->d_lock);
52372 + error = prepend_name(buffer, buflen, &dentry->d_name);
52373 + spin_unlock(&dentry->d_lock);
52374 + if (!error)
52375 + error = prepend(buffer, buflen, "/", 1);
52376 + if (error)
52377 + break;
52378 +
52379 + slash = true;
52380 + dentry = parent;
52381 + }
52382 +
52383 +out:
52384 + if (!error && !slash)
52385 + error = prepend(buffer, buflen, "/", 1);
52386 +
52387 + return error;
52388 +}
52389 +
52390 +/* this must be called with vfsmount_lock and rename_lock held */
52391 +
52392 +static char *__our_d_path(const struct path *path, struct path *root,
52393 + char *buf, int buflen)
52394 +{
52395 + char *res = buf + buflen;
52396 + int error;
52397 +
52398 + prepend(&res, &buflen, "\0", 1);
52399 + error = prepend_path(path, root, &res, &buflen);
52400 + if (error)
52401 + return ERR_PTR(error);
52402 +
52403 + return res;
52404 +}
52405 +
52406 +static char *
52407 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
52408 +{
52409 + char *retval;
52410 +
52411 + retval = __our_d_path(path, root, buf, buflen);
52412 + if (unlikely(IS_ERR(retval)))
52413 + retval = strcpy(buf, "<path too long>");
52414 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
52415 + retval[1] = '\0';
52416 +
52417 + return retval;
52418 +}
52419 +
52420 +static char *
52421 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52422 + char *buf, int buflen)
52423 +{
52424 + struct path path;
52425 + char *res;
52426 +
52427 + path.dentry = (struct dentry *)dentry;
52428 + path.mnt = (struct vfsmount *)vfsmnt;
52429 +
52430 + /* we can use real_root.dentry, real_root.mnt, because this is only called
52431 + by the RBAC system */
52432 + res = gen_full_path(&path, &real_root, buf, buflen);
52433 +
52434 + return res;
52435 +}
52436 +
52437 +static char *
52438 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52439 + char *buf, int buflen)
52440 +{
52441 + char *res;
52442 + struct path path;
52443 + struct path root;
52444 + struct task_struct *reaper = init_pid_ns.child_reaper;
52445 +
52446 + path.dentry = (struct dentry *)dentry;
52447 + path.mnt = (struct vfsmount *)vfsmnt;
52448 +
52449 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
52450 + get_fs_root(reaper->fs, &root);
52451 +
52452 + write_seqlock(&rename_lock);
52453 + br_read_lock(&vfsmount_lock);
52454 + res = gen_full_path(&path, &root, buf, buflen);
52455 + br_read_unlock(&vfsmount_lock);
52456 + write_sequnlock(&rename_lock);
52457 +
52458 + path_put(&root);
52459 + return res;
52460 +}
52461 +
52462 +static char *
52463 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52464 +{
52465 + char *ret;
52466 + write_seqlock(&rename_lock);
52467 + br_read_lock(&vfsmount_lock);
52468 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52469 + PAGE_SIZE);
52470 + br_read_unlock(&vfsmount_lock);
52471 + write_sequnlock(&rename_lock);
52472 + return ret;
52473 +}
52474 +
52475 +static char *
52476 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52477 +{
52478 + char *ret;
52479 + char *buf;
52480 + int buflen;
52481 +
52482 + write_seqlock(&rename_lock);
52483 + br_read_lock(&vfsmount_lock);
52484 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52485 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52486 + buflen = (int)(ret - buf);
52487 + if (buflen >= 5)
52488 + prepend(&ret, &buflen, "/proc", 5);
52489 + else
52490 + ret = strcpy(buf, "<path too long>");
52491 + br_read_unlock(&vfsmount_lock);
52492 + write_sequnlock(&rename_lock);
52493 + return ret;
52494 +}
52495 +
52496 +char *
52497 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52498 +{
52499 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52500 + PAGE_SIZE);
52501 +}
52502 +
52503 +char *
52504 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52505 +{
52506 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52507 + PAGE_SIZE);
52508 +}
52509 +
52510 +char *
52511 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52512 +{
52513 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52514 + PAGE_SIZE);
52515 +}
52516 +
52517 +char *
52518 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52519 +{
52520 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52521 + PAGE_SIZE);
52522 +}
52523 +
52524 +char *
52525 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52526 +{
52527 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52528 + PAGE_SIZE);
52529 +}
52530 +
52531 +__inline__ __u32
52532 +to_gr_audit(const __u32 reqmode)
52533 +{
52534 + /* masks off auditable permission flags, then shifts them to create
52535 + auditing flags, and adds the special case of append auditing if
52536 + we're requesting write */
52537 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52538 +}
52539 +
52540 +struct acl_subject_label *
52541 +lookup_subject_map(const struct acl_subject_label *userp)
52542 +{
52543 + unsigned int index = shash(userp, subj_map_set.s_size);
52544 + struct subject_map *match;
52545 +
52546 + match = subj_map_set.s_hash[index];
52547 +
52548 + while (match && match->user != userp)
52549 + match = match->next;
52550 +
52551 + if (match != NULL)
52552 + return match->kernel;
52553 + else
52554 + return NULL;
52555 +}
52556 +
52557 +static void
52558 +insert_subj_map_entry(struct subject_map *subjmap)
52559 +{
52560 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52561 + struct subject_map **curr;
52562 +
52563 + subjmap->prev = NULL;
52564 +
52565 + curr = &subj_map_set.s_hash[index];
52566 + if (*curr != NULL)
52567 + (*curr)->prev = subjmap;
52568 +
52569 + subjmap->next = *curr;
52570 + *curr = subjmap;
52571 +
52572 + return;
52573 +}
52574 +
52575 +static struct acl_role_label *
52576 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52577 + const gid_t gid)
52578 +{
52579 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52580 + struct acl_role_label *match;
52581 + struct role_allowed_ip *ipp;
52582 + unsigned int x;
52583 + u32 curr_ip = task->signal->curr_ip;
52584 +
52585 + task->signal->saved_ip = curr_ip;
52586 +
52587 + match = acl_role_set.r_hash[index];
52588 +
52589 + while (match) {
52590 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52591 + for (x = 0; x < match->domain_child_num; x++) {
52592 + if (match->domain_children[x] == uid)
52593 + goto found;
52594 + }
52595 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52596 + break;
52597 + match = match->next;
52598 + }
52599 +found:
52600 + if (match == NULL) {
52601 + try_group:
52602 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52603 + match = acl_role_set.r_hash[index];
52604 +
52605 + while (match) {
52606 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52607 + for (x = 0; x < match->domain_child_num; x++) {
52608 + if (match->domain_children[x] == gid)
52609 + goto found2;
52610 + }
52611 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52612 + break;
52613 + match = match->next;
52614 + }
52615 +found2:
52616 + if (match == NULL)
52617 + match = default_role;
52618 + if (match->allowed_ips == NULL)
52619 + return match;
52620 + else {
52621 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52622 + if (likely
52623 + ((ntohl(curr_ip) & ipp->netmask) ==
52624 + (ntohl(ipp->addr) & ipp->netmask)))
52625 + return match;
52626 + }
52627 + match = default_role;
52628 + }
52629 + } else if (match->allowed_ips == NULL) {
52630 + return match;
52631 + } else {
52632 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52633 + if (likely
52634 + ((ntohl(curr_ip) & ipp->netmask) ==
52635 + (ntohl(ipp->addr) & ipp->netmask)))
52636 + return match;
52637 + }
52638 + goto try_group;
52639 + }
52640 +
52641 + return match;
52642 +}
52643 +
52644 +struct acl_subject_label *
52645 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52646 + const struct acl_role_label *role)
52647 +{
52648 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52649 + struct acl_subject_label *match;
52650 +
52651 + match = role->subj_hash[index];
52652 +
52653 + while (match && (match->inode != ino || match->device != dev ||
52654 + (match->mode & GR_DELETED))) {
52655 + match = match->next;
52656 + }
52657 +
52658 + if (match && !(match->mode & GR_DELETED))
52659 + return match;
52660 + else
52661 + return NULL;
52662 +}
52663 +
52664 +struct acl_subject_label *
52665 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52666 + const struct acl_role_label *role)
52667 +{
52668 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52669 + struct acl_subject_label *match;
52670 +
52671 + match = role->subj_hash[index];
52672 +
52673 + while (match && (match->inode != ino || match->device != dev ||
52674 + !(match->mode & GR_DELETED))) {
52675 + match = match->next;
52676 + }
52677 +
52678 + if (match && (match->mode & GR_DELETED))
52679 + return match;
52680 + else
52681 + return NULL;
52682 +}
52683 +
52684 +static struct acl_object_label *
52685 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52686 + const struct acl_subject_label *subj)
52687 +{
52688 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52689 + struct acl_object_label *match;
52690 +
52691 + match = subj->obj_hash[index];
52692 +
52693 + while (match && (match->inode != ino || match->device != dev ||
52694 + (match->mode & GR_DELETED))) {
52695 + match = match->next;
52696 + }
52697 +
52698 + if (match && !(match->mode & GR_DELETED))
52699 + return match;
52700 + else
52701 + return NULL;
52702 +}
52703 +
52704 +static struct acl_object_label *
52705 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52706 + const struct acl_subject_label *subj)
52707 +{
52708 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52709 + struct acl_object_label *match;
52710 +
52711 + match = subj->obj_hash[index];
52712 +
52713 + while (match && (match->inode != ino || match->device != dev ||
52714 + !(match->mode & GR_DELETED))) {
52715 + match = match->next;
52716 + }
52717 +
52718 + if (match && (match->mode & GR_DELETED))
52719 + return match;
52720 +
52721 + match = subj->obj_hash[index];
52722 +
52723 + while (match && (match->inode != ino || match->device != dev ||
52724 + (match->mode & GR_DELETED))) {
52725 + match = match->next;
52726 + }
52727 +
52728 + if (match && !(match->mode & GR_DELETED))
52729 + return match;
52730 + else
52731 + return NULL;
52732 +}
52733 +
52734 +static struct name_entry *
52735 +lookup_name_entry(const char *name)
52736 +{
52737 + unsigned int len = strlen(name);
52738 + unsigned int key = full_name_hash(name, len);
52739 + unsigned int index = key % name_set.n_size;
52740 + struct name_entry *match;
52741 +
52742 + match = name_set.n_hash[index];
52743 +
52744 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52745 + match = match->next;
52746 +
52747 + return match;
52748 +}
52749 +
52750 +static struct name_entry *
52751 +lookup_name_entry_create(const char *name)
52752 +{
52753 + unsigned int len = strlen(name);
52754 + unsigned int key = full_name_hash(name, len);
52755 + unsigned int index = key % name_set.n_size;
52756 + struct name_entry *match;
52757 +
52758 + match = name_set.n_hash[index];
52759 +
52760 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52761 + !match->deleted))
52762 + match = match->next;
52763 +
52764 + if (match && match->deleted)
52765 + return match;
52766 +
52767 + match = name_set.n_hash[index];
52768 +
52769 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52770 + match->deleted))
52771 + match = match->next;
52772 +
52773 + if (match && !match->deleted)
52774 + return match;
52775 + else
52776 + return NULL;
52777 +}
52778 +
52779 +static struct inodev_entry *
52780 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52781 +{
52782 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52783 + struct inodev_entry *match;
52784 +
52785 + match = inodev_set.i_hash[index];
52786 +
52787 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52788 + match = match->next;
52789 +
52790 + return match;
52791 +}
52792 +
52793 +static void
52794 +insert_inodev_entry(struct inodev_entry *entry)
52795 +{
52796 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52797 + inodev_set.i_size);
52798 + struct inodev_entry **curr;
52799 +
52800 + entry->prev = NULL;
52801 +
52802 + curr = &inodev_set.i_hash[index];
52803 + if (*curr != NULL)
52804 + (*curr)->prev = entry;
52805 +
52806 + entry->next = *curr;
52807 + *curr = entry;
52808 +
52809 + return;
52810 +}
52811 +
52812 +static void
52813 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52814 +{
52815 + unsigned int index =
52816 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52817 + struct acl_role_label **curr;
52818 + struct acl_role_label *tmp, *tmp2;
52819 +
52820 + curr = &acl_role_set.r_hash[index];
52821 +
52822 + /* simple case, slot is empty, just set it to our role */
52823 + if (*curr == NULL) {
52824 + *curr = role;
52825 + } else {
52826 + /* example:
52827 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52828 + 2 -> 3
52829 + */
52830 + /* first check to see if we can already be reached via this slot */
52831 + tmp = *curr;
52832 + while (tmp && tmp != role)
52833 + tmp = tmp->next;
52834 + if (tmp == role) {
52835 + /* we don't need to add ourselves to this slot's chain */
52836 + return;
52837 + }
52838 + /* we need to add ourselves to this chain, two cases */
52839 + if (role->next == NULL) {
52840 + /* simple case, append the current chain to our role */
52841 + role->next = *curr;
52842 + *curr = role;
52843 + } else {
52844 + /* 1 -> 2 -> 3 -> 4
52845 + 2 -> 3 -> 4
52846 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52847 + */
52848 + /* trickier case: walk our role's chain until we find
52849 + the role for the start of the current slot's chain */
52850 + tmp = role;
52851 + tmp2 = *curr;
52852 + while (tmp->next && tmp->next != tmp2)
52853 + tmp = tmp->next;
52854 + if (tmp->next == tmp2) {
52855 + /* from example above, we found 3, so just
52856 + replace this slot's chain with ours */
52857 + *curr = role;
52858 + } else {
52859 + /* we didn't find a subset of our role's chain
52860 + in the current slot's chain, so append their
52861 + chain to ours, and set us as the first role in
52862 + the slot's chain
52863 +
52864 + we could fold this case with the case above,
52865 + but making it explicit for clarity
52866 + */
52867 + tmp->next = tmp2;
52868 + *curr = role;
52869 + }
52870 + }
52871 + }
52872 +
52873 + return;
52874 +}
52875 +
52876 +static void
52877 +insert_acl_role_label(struct acl_role_label *role)
52878 +{
52879 + int i;
52880 +
52881 + if (role_list == NULL) {
52882 + role_list = role;
52883 + role->prev = NULL;
52884 + } else {
52885 + role->prev = role_list;
52886 + role_list = role;
52887 + }
52888 +
52889 + /* used for hash chains */
52890 + role->next = NULL;
52891 +
52892 + if (role->roletype & GR_ROLE_DOMAIN) {
52893 + for (i = 0; i < role->domain_child_num; i++)
52894 + __insert_acl_role_label(role, role->domain_children[i]);
52895 + } else
52896 + __insert_acl_role_label(role, role->uidgid);
52897 +}
52898 +
52899 +static int
52900 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52901 +{
52902 + struct name_entry **curr, *nentry;
52903 + struct inodev_entry *ientry;
52904 + unsigned int len = strlen(name);
52905 + unsigned int key = full_name_hash(name, len);
52906 + unsigned int index = key % name_set.n_size;
52907 +
52908 + curr = &name_set.n_hash[index];
52909 +
52910 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52911 + curr = &((*curr)->next);
52912 +
52913 + if (*curr != NULL)
52914 + return 1;
52915 +
52916 + nentry = acl_alloc(sizeof (struct name_entry));
52917 + if (nentry == NULL)
52918 + return 0;
52919 + ientry = acl_alloc(sizeof (struct inodev_entry));
52920 + if (ientry == NULL)
52921 + return 0;
52922 + ientry->nentry = nentry;
52923 +
52924 + nentry->key = key;
52925 + nentry->name = name;
52926 + nentry->inode = inode;
52927 + nentry->device = device;
52928 + nentry->len = len;
52929 + nentry->deleted = deleted;
52930 +
52931 + nentry->prev = NULL;
52932 + curr = &name_set.n_hash[index];
52933 + if (*curr != NULL)
52934 + (*curr)->prev = nentry;
52935 + nentry->next = *curr;
52936 + *curr = nentry;
52937 +
52938 + /* insert us into the table searchable by inode/dev */
52939 + insert_inodev_entry(ientry);
52940 +
52941 + return 1;
52942 +}
52943 +
52944 +static void
52945 +insert_acl_obj_label(struct acl_object_label *obj,
52946 + struct acl_subject_label *subj)
52947 +{
52948 + unsigned int index =
52949 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52950 + struct acl_object_label **curr;
52951 +
52952 +
52953 + obj->prev = NULL;
52954 +
52955 + curr = &subj->obj_hash[index];
52956 + if (*curr != NULL)
52957 + (*curr)->prev = obj;
52958 +
52959 + obj->next = *curr;
52960 + *curr = obj;
52961 +
52962 + return;
52963 +}
52964 +
52965 +static void
52966 +insert_acl_subj_label(struct acl_subject_label *obj,
52967 + struct acl_role_label *role)
52968 +{
52969 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52970 + struct acl_subject_label **curr;
52971 +
52972 + obj->prev = NULL;
52973 +
52974 + curr = &role->subj_hash[index];
52975 + if (*curr != NULL)
52976 + (*curr)->prev = obj;
52977 +
52978 + obj->next = *curr;
52979 + *curr = obj;
52980 +
52981 + return;
52982 +}
52983 +
52984 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52985 +
52986 +static void *
52987 +create_table(__u32 * len, int elementsize)
52988 +{
52989 + unsigned int table_sizes[] = {
52990 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52991 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52992 + 4194301, 8388593, 16777213, 33554393, 67108859
52993 + };
52994 + void *newtable = NULL;
52995 + unsigned int pwr = 0;
52996 +
52997 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52998 + table_sizes[pwr] <= *len)
52999 + pwr++;
53000 +
53001 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
53002 + return newtable;
53003 +
53004 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
53005 + newtable =
53006 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
53007 + else
53008 + newtable = vmalloc(table_sizes[pwr] * elementsize);
53009 +
53010 + *len = table_sizes[pwr];
53011 +
53012 + return newtable;
53013 +}
53014 +
53015 +static int
53016 +init_variables(const struct gr_arg *arg)
53017 +{
53018 + struct task_struct *reaper = init_pid_ns.child_reaper;
53019 + unsigned int stacksize;
53020 +
53021 + subj_map_set.s_size = arg->role_db.num_subjects;
53022 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
53023 + name_set.n_size = arg->role_db.num_objects;
53024 + inodev_set.i_size = arg->role_db.num_objects;
53025 +
53026 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
53027 + !name_set.n_size || !inodev_set.i_size)
53028 + return 1;
53029 +
53030 + if (!gr_init_uidset())
53031 + return 1;
53032 +
53033 + /* set up the stack that holds allocation info */
53034 +
53035 + stacksize = arg->role_db.num_pointers + 5;
53036 +
53037 + if (!acl_alloc_stack_init(stacksize))
53038 + return 1;
53039 +
53040 + /* grab reference for the real root dentry and vfsmount */
53041 + get_fs_root(reaper->fs, &real_root);
53042 +
53043 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53044 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
53045 +#endif
53046 +
53047 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
53048 + if (fakefs_obj_rw == NULL)
53049 + return 1;
53050 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
53051 +
53052 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
53053 + if (fakefs_obj_rwx == NULL)
53054 + return 1;
53055 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
53056 +
53057 + subj_map_set.s_hash =
53058 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
53059 + acl_role_set.r_hash =
53060 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
53061 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
53062 + inodev_set.i_hash =
53063 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
53064 +
53065 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
53066 + !name_set.n_hash || !inodev_set.i_hash)
53067 + return 1;
53068 +
53069 + memset(subj_map_set.s_hash, 0,
53070 + sizeof(struct subject_map *) * subj_map_set.s_size);
53071 + memset(acl_role_set.r_hash, 0,
53072 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
53073 + memset(name_set.n_hash, 0,
53074 + sizeof (struct name_entry *) * name_set.n_size);
53075 + memset(inodev_set.i_hash, 0,
53076 + sizeof (struct inodev_entry *) * inodev_set.i_size);
53077 +
53078 + return 0;
53079 +}
53080 +
53081 +/* free information not needed after startup
53082 + currently contains user->kernel pointer mappings for subjects
53083 +*/
53084 +
53085 +static void
53086 +free_init_variables(void)
53087 +{
53088 + __u32 i;
53089 +
53090 + if (subj_map_set.s_hash) {
53091 + for (i = 0; i < subj_map_set.s_size; i++) {
53092 + if (subj_map_set.s_hash[i]) {
53093 + kfree(subj_map_set.s_hash[i]);
53094 + subj_map_set.s_hash[i] = NULL;
53095 + }
53096 + }
53097 +
53098 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
53099 + PAGE_SIZE)
53100 + kfree(subj_map_set.s_hash);
53101 + else
53102 + vfree(subj_map_set.s_hash);
53103 + }
53104 +
53105 + return;
53106 +}
53107 +
53108 +static void
53109 +free_variables(void)
53110 +{
53111 + struct acl_subject_label *s;
53112 + struct acl_role_label *r;
53113 + struct task_struct *task, *task2;
53114 + unsigned int x;
53115 +
53116 + gr_clear_learn_entries();
53117 +
53118 + read_lock(&tasklist_lock);
53119 + do_each_thread(task2, task) {
53120 + task->acl_sp_role = 0;
53121 + task->acl_role_id = 0;
53122 + task->acl = NULL;
53123 + task->role = NULL;
53124 + } while_each_thread(task2, task);
53125 + read_unlock(&tasklist_lock);
53126 +
53127 + /* release the reference to the real root dentry and vfsmount */
53128 + path_put(&real_root);
53129 + memset(&real_root, 0, sizeof(real_root));
53130 +
53131 + /* free all object hash tables */
53132 +
53133 + FOR_EACH_ROLE_START(r)
53134 + if (r->subj_hash == NULL)
53135 + goto next_role;
53136 + FOR_EACH_SUBJECT_START(r, s, x)
53137 + if (s->obj_hash == NULL)
53138 + break;
53139 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
53140 + kfree(s->obj_hash);
53141 + else
53142 + vfree(s->obj_hash);
53143 + FOR_EACH_SUBJECT_END(s, x)
53144 + FOR_EACH_NESTED_SUBJECT_START(r, s)
53145 + if (s->obj_hash == NULL)
53146 + break;
53147 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
53148 + kfree(s->obj_hash);
53149 + else
53150 + vfree(s->obj_hash);
53151 + FOR_EACH_NESTED_SUBJECT_END(s)
53152 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
53153 + kfree(r->subj_hash);
53154 + else
53155 + vfree(r->subj_hash);
53156 + r->subj_hash = NULL;
53157 +next_role:
53158 + FOR_EACH_ROLE_END(r)
53159 +
53160 + acl_free_all();
53161 +
53162 + if (acl_role_set.r_hash) {
53163 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
53164 + PAGE_SIZE)
53165 + kfree(acl_role_set.r_hash);
53166 + else
53167 + vfree(acl_role_set.r_hash);
53168 + }
53169 + if (name_set.n_hash) {
53170 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
53171 + PAGE_SIZE)
53172 + kfree(name_set.n_hash);
53173 + else
53174 + vfree(name_set.n_hash);
53175 + }
53176 +
53177 + if (inodev_set.i_hash) {
53178 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
53179 + PAGE_SIZE)
53180 + kfree(inodev_set.i_hash);
53181 + else
53182 + vfree(inodev_set.i_hash);
53183 + }
53184 +
53185 + gr_free_uidset();
53186 +
53187 + memset(&name_set, 0, sizeof (struct name_db));
53188 + memset(&inodev_set, 0, sizeof (struct inodev_db));
53189 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
53190 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
53191 +
53192 + default_role = NULL;
53193 + kernel_role = NULL;
53194 + role_list = NULL;
53195 +
53196 + return;
53197 +}
53198 +
53199 +static __u32
53200 +count_user_objs(struct acl_object_label *userp)
53201 +{
53202 + struct acl_object_label o_tmp;
53203 + __u32 num = 0;
53204 +
53205 + while (userp) {
53206 + if (copy_from_user(&o_tmp, userp,
53207 + sizeof (struct acl_object_label)))
53208 + break;
53209 +
53210 + userp = o_tmp.prev;
53211 + num++;
53212 + }
53213 +
53214 + return num;
53215 +}
53216 +
53217 +static struct acl_subject_label *
53218 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
53219 +
53220 +static int
53221 +copy_user_glob(struct acl_object_label *obj)
53222 +{
53223 + struct acl_object_label *g_tmp, **guser;
53224 + unsigned int len;
53225 + char *tmp;
53226 +
53227 + if (obj->globbed == NULL)
53228 + return 0;
53229 +
53230 + guser = &obj->globbed;
53231 + while (*guser) {
53232 + g_tmp = (struct acl_object_label *)
53233 + acl_alloc(sizeof (struct acl_object_label));
53234 + if (g_tmp == NULL)
53235 + return -ENOMEM;
53236 +
53237 + if (copy_from_user(g_tmp, *guser,
53238 + sizeof (struct acl_object_label)))
53239 + return -EFAULT;
53240 +
53241 + len = strnlen_user(g_tmp->filename, PATH_MAX);
53242 +
53243 + if (!len || len >= PATH_MAX)
53244 + return -EINVAL;
53245 +
53246 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53247 + return -ENOMEM;
53248 +
53249 + if (copy_from_user(tmp, g_tmp->filename, len))
53250 + return -EFAULT;
53251 + tmp[len-1] = '\0';
53252 + g_tmp->filename = tmp;
53253 +
53254 + *guser = g_tmp;
53255 + guser = &(g_tmp->next);
53256 + }
53257 +
53258 + return 0;
53259 +}
53260 +
53261 +static int
53262 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
53263 + struct acl_role_label *role)
53264 +{
53265 + struct acl_object_label *o_tmp;
53266 + unsigned int len;
53267 + int ret;
53268 + char *tmp;
53269 +
53270 + while (userp) {
53271 + if ((o_tmp = (struct acl_object_label *)
53272 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
53273 + return -ENOMEM;
53274 +
53275 + if (copy_from_user(o_tmp, userp,
53276 + sizeof (struct acl_object_label)))
53277 + return -EFAULT;
53278 +
53279 + userp = o_tmp->prev;
53280 +
53281 + len = strnlen_user(o_tmp->filename, PATH_MAX);
53282 +
53283 + if (!len || len >= PATH_MAX)
53284 + return -EINVAL;
53285 +
53286 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53287 + return -ENOMEM;
53288 +
53289 + if (copy_from_user(tmp, o_tmp->filename, len))
53290 + return -EFAULT;
53291 + tmp[len-1] = '\0';
53292 + o_tmp->filename = tmp;
53293 +
53294 + insert_acl_obj_label(o_tmp, subj);
53295 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
53296 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
53297 + return -ENOMEM;
53298 +
53299 + ret = copy_user_glob(o_tmp);
53300 + if (ret)
53301 + return ret;
53302 +
53303 + if (o_tmp->nested) {
53304 + int already_copied;
53305 +
53306 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
53307 + if (IS_ERR(o_tmp->nested))
53308 + return PTR_ERR(o_tmp->nested);
53309 +
53310 + /* insert into nested subject list if we haven't copied this one yet
53311 + to prevent duplicate entries */
53312 + if (!already_copied) {
53313 + o_tmp->nested->next = role->hash->first;
53314 + role->hash->first = o_tmp->nested;
53315 + }
53316 + }
53317 + }
53318 +
53319 + return 0;
53320 +}
53321 +
53322 +static __u32
53323 +count_user_subjs(struct acl_subject_label *userp)
53324 +{
53325 + struct acl_subject_label s_tmp;
53326 + __u32 num = 0;
53327 +
53328 + while (userp) {
53329 + if (copy_from_user(&s_tmp, userp,
53330 + sizeof (struct acl_subject_label)))
53331 + break;
53332 +
53333 + userp = s_tmp.prev;
53334 + /* do not count nested subjects against this count, since
53335 + they are not included in the hash table, but are
53336 + attached to objects. We have already counted
53337 + the subjects in userspace for the allocation
53338 + stack
53339 + */
53340 + if (!(s_tmp.mode & GR_NESTED))
53341 + num++;
53342 + }
53343 +
53344 + return num;
53345 +}
53346 +
53347 +static int
53348 +copy_user_allowedips(struct acl_role_label *rolep)
53349 +{
53350 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
53351 +
53352 + ruserip = rolep->allowed_ips;
53353 +
53354 + while (ruserip) {
53355 + rlast = rtmp;
53356 +
53357 + if ((rtmp = (struct role_allowed_ip *)
53358 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
53359 + return -ENOMEM;
53360 +
53361 + if (copy_from_user(rtmp, ruserip,
53362 + sizeof (struct role_allowed_ip)))
53363 + return -EFAULT;
53364 +
53365 + ruserip = rtmp->prev;
53366 +
53367 + if (!rlast) {
53368 + rtmp->prev = NULL;
53369 + rolep->allowed_ips = rtmp;
53370 + } else {
53371 + rlast->next = rtmp;
53372 + rtmp->prev = rlast;
53373 + }
53374 +
53375 + if (!ruserip)
53376 + rtmp->next = NULL;
53377 + }
53378 +
53379 + return 0;
53380 +}
53381 +
53382 +static int
53383 +copy_user_transitions(struct acl_role_label *rolep)
53384 +{
53385 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
53386 +
53387 + unsigned int len;
53388 + char *tmp;
53389 +
53390 + rusertp = rolep->transitions;
53391 +
53392 + while (rusertp) {
53393 + rlast = rtmp;
53394 +
53395 + if ((rtmp = (struct role_transition *)
53396 + acl_alloc(sizeof (struct role_transition))) == NULL)
53397 + return -ENOMEM;
53398 +
53399 + if (copy_from_user(rtmp, rusertp,
53400 + sizeof (struct role_transition)))
53401 + return -EFAULT;
53402 +
53403 + rusertp = rtmp->prev;
53404 +
53405 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
53406 +
53407 + if (!len || len >= GR_SPROLE_LEN)
53408 + return -EINVAL;
53409 +
53410 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53411 + return -ENOMEM;
53412 +
53413 + if (copy_from_user(tmp, rtmp->rolename, len))
53414 + return -EFAULT;
53415 + tmp[len-1] = '\0';
53416 + rtmp->rolename = tmp;
53417 +
53418 + if (!rlast) {
53419 + rtmp->prev = NULL;
53420 + rolep->transitions = rtmp;
53421 + } else {
53422 + rlast->next = rtmp;
53423 + rtmp->prev = rlast;
53424 + }
53425 +
53426 + if (!rusertp)
53427 + rtmp->next = NULL;
53428 + }
53429 +
53430 + return 0;
53431 +}
53432 +
53433 +static struct acl_subject_label *
53434 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
53435 +{
53436 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
53437 + unsigned int len;
53438 + char *tmp;
53439 + __u32 num_objs;
53440 + struct acl_ip_label **i_tmp, *i_utmp2;
53441 + struct gr_hash_struct ghash;
53442 + struct subject_map *subjmap;
53443 + unsigned int i_num;
53444 + int err;
53445 +
53446 + if (already_copied != NULL)
53447 + *already_copied = 0;
53448 +
53449 + s_tmp = lookup_subject_map(userp);
53450 +
53451 + /* we've already copied this subject into the kernel, just return
53452 + the reference to it, and don't copy it over again
53453 + */
53454 + if (s_tmp) {
53455 + if (already_copied != NULL)
53456 + *already_copied = 1;
53457 + return(s_tmp);
53458 + }
53459 +
53460 + if ((s_tmp = (struct acl_subject_label *)
53461 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53462 + return ERR_PTR(-ENOMEM);
53463 +
53464 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53465 + if (subjmap == NULL)
53466 + return ERR_PTR(-ENOMEM);
53467 +
53468 + subjmap->user = userp;
53469 + subjmap->kernel = s_tmp;
53470 + insert_subj_map_entry(subjmap);
53471 +
53472 + if (copy_from_user(s_tmp, userp,
53473 + sizeof (struct acl_subject_label)))
53474 + return ERR_PTR(-EFAULT);
53475 +
53476 + len = strnlen_user(s_tmp->filename, PATH_MAX);
53477 +
53478 + if (!len || len >= PATH_MAX)
53479 + return ERR_PTR(-EINVAL);
53480 +
53481 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53482 + return ERR_PTR(-ENOMEM);
53483 +
53484 + if (copy_from_user(tmp, s_tmp->filename, len))
53485 + return ERR_PTR(-EFAULT);
53486 + tmp[len-1] = '\0';
53487 + s_tmp->filename = tmp;
53488 +
53489 + if (!strcmp(s_tmp->filename, "/"))
53490 + role->root_label = s_tmp;
53491 +
53492 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53493 + return ERR_PTR(-EFAULT);
53494 +
53495 + /* copy user and group transition tables */
53496 +
53497 + if (s_tmp->user_trans_num) {
53498 + uid_t *uidlist;
53499 +
53500 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53501 + if (uidlist == NULL)
53502 + return ERR_PTR(-ENOMEM);
53503 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53504 + return ERR_PTR(-EFAULT);
53505 +
53506 + s_tmp->user_transitions = uidlist;
53507 + }
53508 +
53509 + if (s_tmp->group_trans_num) {
53510 + gid_t *gidlist;
53511 +
53512 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53513 + if (gidlist == NULL)
53514 + return ERR_PTR(-ENOMEM);
53515 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53516 + return ERR_PTR(-EFAULT);
53517 +
53518 + s_tmp->group_transitions = gidlist;
53519 + }
53520 +
53521 + /* set up object hash table */
53522 + num_objs = count_user_objs(ghash.first);
53523 +
53524 + s_tmp->obj_hash_size = num_objs;
53525 + s_tmp->obj_hash =
53526 + (struct acl_object_label **)
53527 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53528 +
53529 + if (!s_tmp->obj_hash)
53530 + return ERR_PTR(-ENOMEM);
53531 +
53532 + memset(s_tmp->obj_hash, 0,
53533 + s_tmp->obj_hash_size *
53534 + sizeof (struct acl_object_label *));
53535 +
53536 + /* add in objects */
53537 + err = copy_user_objs(ghash.first, s_tmp, role);
53538 +
53539 + if (err)
53540 + return ERR_PTR(err);
53541 +
53542 + /* set pointer for parent subject */
53543 + if (s_tmp->parent_subject) {
53544 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
53545 +
53546 + if (IS_ERR(s_tmp2))
53547 + return s_tmp2;
53548 +
53549 + s_tmp->parent_subject = s_tmp2;
53550 + }
53551 +
53552 + /* add in ip acls */
53553 +
53554 + if (!s_tmp->ip_num) {
53555 + s_tmp->ips = NULL;
53556 + goto insert;
53557 + }
53558 +
53559 + i_tmp =
53560 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53561 + sizeof (struct acl_ip_label *));
53562 +
53563 + if (!i_tmp)
53564 + return ERR_PTR(-ENOMEM);
53565 +
53566 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53567 + *(i_tmp + i_num) =
53568 + (struct acl_ip_label *)
53569 + acl_alloc(sizeof (struct acl_ip_label));
53570 + if (!*(i_tmp + i_num))
53571 + return ERR_PTR(-ENOMEM);
53572 +
53573 + if (copy_from_user
53574 + (&i_utmp2, s_tmp->ips + i_num,
53575 + sizeof (struct acl_ip_label *)))
53576 + return ERR_PTR(-EFAULT);
53577 +
53578 + if (copy_from_user
53579 + (*(i_tmp + i_num), i_utmp2,
53580 + sizeof (struct acl_ip_label)))
53581 + return ERR_PTR(-EFAULT);
53582 +
53583 + if ((*(i_tmp + i_num))->iface == NULL)
53584 + continue;
53585 +
53586 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53587 + if (!len || len >= IFNAMSIZ)
53588 + return ERR_PTR(-EINVAL);
53589 + tmp = acl_alloc(len);
53590 + if (tmp == NULL)
53591 + return ERR_PTR(-ENOMEM);
53592 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53593 + return ERR_PTR(-EFAULT);
53594 + (*(i_tmp + i_num))->iface = tmp;
53595 + }
53596 +
53597 + s_tmp->ips = i_tmp;
53598 +
53599 +insert:
53600 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53601 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53602 + return ERR_PTR(-ENOMEM);
53603 +
53604 + return s_tmp;
53605 +}
53606 +
53607 +static int
53608 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53609 +{
53610 + struct acl_subject_label s_pre;
53611 + struct acl_subject_label * ret;
53612 + int err;
53613 +
53614 + while (userp) {
53615 + if (copy_from_user(&s_pre, userp,
53616 + sizeof (struct acl_subject_label)))
53617 + return -EFAULT;
53618 +
53619 + /* do not add nested subjects here, add
53620 + while parsing objects
53621 + */
53622 +
53623 + if (s_pre.mode & GR_NESTED) {
53624 + userp = s_pre.prev;
53625 + continue;
53626 + }
53627 +
53628 + ret = do_copy_user_subj(userp, role, NULL);
53629 +
53630 + err = PTR_ERR(ret);
53631 + if (IS_ERR(ret))
53632 + return err;
53633 +
53634 + insert_acl_subj_label(ret, role);
53635 +
53636 + userp = s_pre.prev;
53637 + }
53638 +
53639 + return 0;
53640 +}
53641 +
53642 +static int
53643 +copy_user_acl(struct gr_arg *arg)
53644 +{
53645 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53646 + struct acl_subject_label *subj_list;
53647 + struct sprole_pw *sptmp;
53648 + struct gr_hash_struct *ghash;
53649 + uid_t *domainlist;
53650 + unsigned int r_num;
53651 + unsigned int len;
53652 + char *tmp;
53653 + int err = 0;
53654 + __u16 i;
53655 + __u32 num_subjs;
53656 +
53657 + /* we need a default and kernel role */
53658 + if (arg->role_db.num_roles < 2)
53659 + return -EINVAL;
53660 +
53661 + /* copy special role authentication info from userspace */
53662 +
53663 + num_sprole_pws = arg->num_sprole_pws;
53664 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53665 +
53666 + if (!acl_special_roles && num_sprole_pws)
53667 + return -ENOMEM;
53668 +
53669 + for (i = 0; i < num_sprole_pws; i++) {
53670 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53671 + if (!sptmp)
53672 + return -ENOMEM;
53673 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53674 + sizeof (struct sprole_pw)))
53675 + return -EFAULT;
53676 +
53677 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53678 +
53679 + if (!len || len >= GR_SPROLE_LEN)
53680 + return -EINVAL;
53681 +
53682 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53683 + return -ENOMEM;
53684 +
53685 + if (copy_from_user(tmp, sptmp->rolename, len))
53686 + return -EFAULT;
53687 +
53688 + tmp[len-1] = '\0';
53689 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53690 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53691 +#endif
53692 + sptmp->rolename = tmp;
53693 + acl_special_roles[i] = sptmp;
53694 + }
53695 +
53696 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53697 +
53698 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53699 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53700 +
53701 + if (!r_tmp)
53702 + return -ENOMEM;
53703 +
53704 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53705 + sizeof (struct acl_role_label *)))
53706 + return -EFAULT;
53707 +
53708 + if (copy_from_user(r_tmp, r_utmp2,
53709 + sizeof (struct acl_role_label)))
53710 + return -EFAULT;
53711 +
53712 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53713 +
53714 + if (!len || len >= PATH_MAX)
53715 + return -EINVAL;
53716 +
53717 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53718 + return -ENOMEM;
53719 +
53720 + if (copy_from_user(tmp, r_tmp->rolename, len))
53721 + return -EFAULT;
53722 +
53723 + tmp[len-1] = '\0';
53724 + r_tmp->rolename = tmp;
53725 +
53726 + if (!strcmp(r_tmp->rolename, "default")
53727 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53728 + default_role = r_tmp;
53729 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53730 + kernel_role = r_tmp;
53731 + }
53732 +
53733 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53734 + return -ENOMEM;
53735 +
53736 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53737 + return -EFAULT;
53738 +
53739 + r_tmp->hash = ghash;
53740 +
53741 + num_subjs = count_user_subjs(r_tmp->hash->first);
53742 +
53743 + r_tmp->subj_hash_size = num_subjs;
53744 + r_tmp->subj_hash =
53745 + (struct acl_subject_label **)
53746 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53747 +
53748 + if (!r_tmp->subj_hash)
53749 + return -ENOMEM;
53750 +
53751 + err = copy_user_allowedips(r_tmp);
53752 + if (err)
53753 + return err;
53754 +
53755 + /* copy domain info */
53756 + if (r_tmp->domain_children != NULL) {
53757 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53758 + if (domainlist == NULL)
53759 + return -ENOMEM;
53760 +
53761 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53762 + return -EFAULT;
53763 +
53764 + r_tmp->domain_children = domainlist;
53765 + }
53766 +
53767 + err = copy_user_transitions(r_tmp);
53768 + if (err)
53769 + return err;
53770 +
53771 + memset(r_tmp->subj_hash, 0,
53772 + r_tmp->subj_hash_size *
53773 + sizeof (struct acl_subject_label *));
53774 +
53775 + /* acquire the list of subjects, then NULL out
53776 + the list prior to parsing the subjects for this role,
53777 + as during this parsing the list is replaced with a list
53778 + of *nested* subjects for the role
53779 + */
53780 + subj_list = r_tmp->hash->first;
53781 +
53782 + /* set nested subject list to null */
53783 + r_tmp->hash->first = NULL;
53784 +
53785 + err = copy_user_subjs(subj_list, r_tmp);
53786 +
53787 + if (err)
53788 + return err;
53789 +
53790 + insert_acl_role_label(r_tmp);
53791 + }
53792 +
53793 + if (default_role == NULL || kernel_role == NULL)
53794 + return -EINVAL;
53795 +
53796 + return err;
53797 +}
53798 +
53799 +static int
53800 +gracl_init(struct gr_arg *args)
53801 +{
53802 + int error = 0;
53803 +
53804 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53805 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53806 +
53807 + if (init_variables(args)) {
53808 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53809 + error = -ENOMEM;
53810 + free_variables();
53811 + goto out;
53812 + }
53813 +
53814 + error = copy_user_acl(args);
53815 + free_init_variables();
53816 + if (error) {
53817 + free_variables();
53818 + goto out;
53819 + }
53820 +
53821 + if ((error = gr_set_acls(0))) {
53822 + free_variables();
53823 + goto out;
53824 + }
53825 +
53826 + pax_open_kernel();
53827 + gr_status |= GR_READY;
53828 + pax_close_kernel();
53829 +
53830 + out:
53831 + return error;
53832 +}
53833 +
53834 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53835 +
53836 +static int
53837 +glob_match(const char *p, const char *n)
53838 +{
53839 + char c;
53840 +
53841 + while ((c = *p++) != '\0') {
53842 + switch (c) {
53843 + case '?':
53844 + if (*n == '\0')
53845 + return 1;
53846 + else if (*n == '/')
53847 + return 1;
53848 + break;
53849 + case '\\':
53850 + if (*n != c)
53851 + return 1;
53852 + break;
53853 + case '*':
53854 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53855 + if (*n == '/')
53856 + return 1;
53857 + else if (c == '?') {
53858 + if (*n == '\0')
53859 + return 1;
53860 + else
53861 + ++n;
53862 + }
53863 + }
53864 + if (c == '\0') {
53865 + return 0;
53866 + } else {
53867 + const char *endp;
53868 +
53869 + if ((endp = strchr(n, '/')) == NULL)
53870 + endp = n + strlen(n);
53871 +
53872 + if (c == '[') {
53873 + for (--p; n < endp; ++n)
53874 + if (!glob_match(p, n))
53875 + return 0;
53876 + } else if (c == '/') {
53877 + while (*n != '\0' && *n != '/')
53878 + ++n;
53879 + if (*n == '/' && !glob_match(p, n + 1))
53880 + return 0;
53881 + } else {
53882 + for (--p; n < endp; ++n)
53883 + if (*n == c && !glob_match(p, n))
53884 + return 0;
53885 + }
53886 +
53887 + return 1;
53888 + }
53889 + case '[':
53890 + {
53891 + int not;
53892 + char cold;
53893 +
53894 + if (*n == '\0' || *n == '/')
53895 + return 1;
53896 +
53897 + not = (*p == '!' || *p == '^');
53898 + if (not)
53899 + ++p;
53900 +
53901 + c = *p++;
53902 + for (;;) {
53903 + unsigned char fn = (unsigned char)*n;
53904 +
53905 + if (c == '\0')
53906 + return 1;
53907 + else {
53908 + if (c == fn)
53909 + goto matched;
53910 + cold = c;
53911 + c = *p++;
53912 +
53913 + if (c == '-' && *p != ']') {
53914 + unsigned char cend = *p++;
53915 +
53916 + if (cend == '\0')
53917 + return 1;
53918 +
53919 + if (cold <= fn && fn <= cend)
53920 + goto matched;
53921 +
53922 + c = *p++;
53923 + }
53924 + }
53925 +
53926 + if (c == ']')
53927 + break;
53928 + }
53929 + if (!not)
53930 + return 1;
53931 + break;
53932 + matched:
53933 + while (c != ']') {
53934 + if (c == '\0')
53935 + return 1;
53936 +
53937 + c = *p++;
53938 + }
53939 + if (not)
53940 + return 1;
53941 + }
53942 + break;
53943 + default:
53944 + if (c != *n)
53945 + return 1;
53946 + }
53947 +
53948 + ++n;
53949 + }
53950 +
53951 + if (*n == '\0')
53952 + return 0;
53953 +
53954 + if (*n == '/')
53955 + return 0;
53956 +
53957 + return 1;
53958 +}
53959 +
53960 +static struct acl_object_label *
53961 +chk_glob_label(struct acl_object_label *globbed,
53962 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53963 +{
53964 + struct acl_object_label *tmp;
53965 +
53966 + if (*path == NULL)
53967 + *path = gr_to_filename_nolock(dentry, mnt);
53968 +
53969 + tmp = globbed;
53970 +
53971 + while (tmp) {
53972 + if (!glob_match(tmp->filename, *path))
53973 + return tmp;
53974 + tmp = tmp->next;
53975 + }
53976 +
53977 + return NULL;
53978 +}
53979 +
53980 +static struct acl_object_label *
53981 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53982 + const ino_t curr_ino, const dev_t curr_dev,
53983 + const struct acl_subject_label *subj, char **path, const int checkglob)
53984 +{
53985 + struct acl_subject_label *tmpsubj;
53986 + struct acl_object_label *retval;
53987 + struct acl_object_label *retval2;
53988 +
53989 + tmpsubj = (struct acl_subject_label *) subj;
53990 + read_lock(&gr_inode_lock);
53991 + do {
53992 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53993 + if (retval) {
53994 + if (checkglob && retval->globbed) {
53995 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53996 + if (retval2)
53997 + retval = retval2;
53998 + }
53999 + break;
54000 + }
54001 + } while ((tmpsubj = tmpsubj->parent_subject));
54002 + read_unlock(&gr_inode_lock);
54003 +
54004 + return retval;
54005 +}
54006 +
54007 +static __inline__ struct acl_object_label *
54008 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
54009 + struct dentry *curr_dentry,
54010 + const struct acl_subject_label *subj, char **path, const int checkglob)
54011 +{
54012 + int newglob = checkglob;
54013 + ino_t inode;
54014 + dev_t device;
54015 +
54016 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
54017 + as we don't want a / * rule to match instead of the / object
54018 + don't do this for create lookups that call this function though, since they're looking up
54019 + on the parent and thus need globbing checks on all paths
54020 + */
54021 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
54022 + newglob = GR_NO_GLOB;
54023 +
54024 + spin_lock(&curr_dentry->d_lock);
54025 + inode = curr_dentry->d_inode->i_ino;
54026 + device = __get_dev(curr_dentry);
54027 + spin_unlock(&curr_dentry->d_lock);
54028 +
54029 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
54030 +}
54031 +
54032 +static struct acl_object_label *
54033 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54034 + const struct acl_subject_label *subj, char *path, const int checkglob)
54035 +{
54036 + struct dentry *dentry = (struct dentry *) l_dentry;
54037 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
54038 + struct mount *real_mnt = real_mount(mnt);
54039 + struct acl_object_label *retval;
54040 + struct dentry *parent;
54041 +
54042 + write_seqlock(&rename_lock);
54043 + br_read_lock(&vfsmount_lock);
54044 +
54045 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
54046 +#ifdef CONFIG_NET
54047 + mnt == sock_mnt ||
54048 +#endif
54049 +#ifdef CONFIG_HUGETLBFS
54050 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
54051 +#endif
54052 + /* ignore Eric Biederman */
54053 + IS_PRIVATE(l_dentry->d_inode))) {
54054 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
54055 + goto out;
54056 + }
54057 +
54058 + for (;;) {
54059 + if (dentry == real_root.dentry && mnt == real_root.mnt)
54060 + break;
54061 +
54062 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
54063 + if (!mnt_has_parent(real_mnt))
54064 + break;
54065 +
54066 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54067 + if (retval != NULL)
54068 + goto out;
54069 +
54070 + dentry = real_mnt->mnt_mountpoint;
54071 + real_mnt = real_mnt->mnt_parent;
54072 + mnt = &real_mnt->mnt;
54073 + continue;
54074 + }
54075 +
54076 + parent = dentry->d_parent;
54077 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54078 + if (retval != NULL)
54079 + goto out;
54080 +
54081 + dentry = parent;
54082 + }
54083 +
54084 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54085 +
54086 + /* real_root is pinned so we don't have to hold a reference */
54087 + if (retval == NULL)
54088 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
54089 +out:
54090 + br_read_unlock(&vfsmount_lock);
54091 + write_sequnlock(&rename_lock);
54092 +
54093 + BUG_ON(retval == NULL);
54094 +
54095 + return retval;
54096 +}
54097 +
54098 +static __inline__ struct acl_object_label *
54099 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54100 + const struct acl_subject_label *subj)
54101 +{
54102 + char *path = NULL;
54103 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
54104 +}
54105 +
54106 +static __inline__ struct acl_object_label *
54107 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54108 + const struct acl_subject_label *subj)
54109 +{
54110 + char *path = NULL;
54111 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
54112 +}
54113 +
54114 +static __inline__ struct acl_object_label *
54115 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54116 + const struct acl_subject_label *subj, char *path)
54117 +{
54118 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
54119 +}
54120 +
54121 +static struct acl_subject_label *
54122 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54123 + const struct acl_role_label *role)
54124 +{
54125 + struct dentry *dentry = (struct dentry *) l_dentry;
54126 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
54127 + struct mount *real_mnt = real_mount(mnt);
54128 + struct acl_subject_label *retval;
54129 + struct dentry *parent;
54130 +
54131 + write_seqlock(&rename_lock);
54132 + br_read_lock(&vfsmount_lock);
54133 +
54134 + for (;;) {
54135 + if (dentry == real_root.dentry && mnt == real_root.mnt)
54136 + break;
54137 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
54138 + if (!mnt_has_parent(real_mnt))
54139 + break;
54140 +
54141 + spin_lock(&dentry->d_lock);
54142 + read_lock(&gr_inode_lock);
54143 + retval =
54144 + lookup_acl_subj_label(dentry->d_inode->i_ino,
54145 + __get_dev(dentry), role);
54146 + read_unlock(&gr_inode_lock);
54147 + spin_unlock(&dentry->d_lock);
54148 + if (retval != NULL)
54149 + goto out;
54150 +
54151 + dentry = real_mnt->mnt_mountpoint;
54152 + real_mnt = real_mnt->mnt_parent;
54153 + mnt = &real_mnt->mnt;
54154 + continue;
54155 + }
54156 +
54157 + spin_lock(&dentry->d_lock);
54158 + read_lock(&gr_inode_lock);
54159 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
54160 + __get_dev(dentry), role);
54161 + read_unlock(&gr_inode_lock);
54162 + parent = dentry->d_parent;
54163 + spin_unlock(&dentry->d_lock);
54164 +
54165 + if (retval != NULL)
54166 + goto out;
54167 +
54168 + dentry = parent;
54169 + }
54170 +
54171 + spin_lock(&dentry->d_lock);
54172 + read_lock(&gr_inode_lock);
54173 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
54174 + __get_dev(dentry), role);
54175 + read_unlock(&gr_inode_lock);
54176 + spin_unlock(&dentry->d_lock);
54177 +
54178 + if (unlikely(retval == NULL)) {
54179 + /* real_root is pinned, we don't need to hold a reference */
54180 + read_lock(&gr_inode_lock);
54181 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
54182 + __get_dev(real_root.dentry), role);
54183 + read_unlock(&gr_inode_lock);
54184 + }
54185 +out:
54186 + br_read_unlock(&vfsmount_lock);
54187 + write_sequnlock(&rename_lock);
54188 +
54189 + BUG_ON(retval == NULL);
54190 +
54191 + return retval;
54192 +}
54193 +
54194 +static void
54195 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
54196 +{
54197 + struct task_struct *task = current;
54198 + const struct cred *cred = current_cred();
54199 +
54200 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
54201 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
54202 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
54203 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
54204 +
54205 + return;
54206 +}
54207 +
54208 +static void
54209 +gr_log_learn_id_change(const char type, const unsigned int real,
54210 + const unsigned int effective, const unsigned int fs)
54211 +{
54212 + struct task_struct *task = current;
54213 + const struct cred *cred = current_cred();
54214 +
54215 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
54216 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
54217 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
54218 + type, real, effective, fs, &task->signal->saved_ip);
54219 +
54220 + return;
54221 +}
54222 +
54223 +__u32
54224 +gr_search_file(const struct dentry * dentry, const __u32 mode,
54225 + const struct vfsmount * mnt)
54226 +{
54227 + __u32 retval = mode;
54228 + struct acl_subject_label *curracl;
54229 + struct acl_object_label *currobj;
54230 +
54231 + if (unlikely(!(gr_status & GR_READY)))
54232 + return (mode & ~GR_AUDITS);
54233 +
54234 + curracl = current->acl;
54235 +
54236 + currobj = chk_obj_label(dentry, mnt, curracl);
54237 + retval = currobj->mode & mode;
54238 +
54239 + /* if we're opening a specified transfer file for writing
54240 + (e.g. /dev/initctl), then transfer our role to init
54241 + */
54242 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
54243 + current->role->roletype & GR_ROLE_PERSIST)) {
54244 + struct task_struct *task = init_pid_ns.child_reaper;
54245 +
54246 + if (task->role != current->role) {
54247 + task->acl_sp_role = 0;
54248 + task->acl_role_id = current->acl_role_id;
54249 + task->role = current->role;
54250 + rcu_read_lock();
54251 + read_lock(&grsec_exec_file_lock);
54252 + gr_apply_subject_to_task(task);
54253 + read_unlock(&grsec_exec_file_lock);
54254 + rcu_read_unlock();
54255 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
54256 + }
54257 + }
54258 +
54259 + if (unlikely
54260 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
54261 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
54262 + __u32 new_mode = mode;
54263 +
54264 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54265 +
54266 + retval = new_mode;
54267 +
54268 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
54269 + new_mode |= GR_INHERIT;
54270 +
54271 + if (!(mode & GR_NOLEARN))
54272 + gr_log_learn(dentry, mnt, new_mode);
54273 + }
54274 +
54275 + return retval;
54276 +}
54277 +
54278 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
54279 + const struct dentry *parent,
54280 + const struct vfsmount *mnt)
54281 +{
54282 + struct name_entry *match;
54283 + struct acl_object_label *matchpo;
54284 + struct acl_subject_label *curracl;
54285 + char *path;
54286 +
54287 + if (unlikely(!(gr_status & GR_READY)))
54288 + return NULL;
54289 +
54290 + preempt_disable();
54291 + path = gr_to_filename_rbac(new_dentry, mnt);
54292 + match = lookup_name_entry_create(path);
54293 +
54294 + curracl = current->acl;
54295 +
54296 + if (match) {
54297 + read_lock(&gr_inode_lock);
54298 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
54299 + read_unlock(&gr_inode_lock);
54300 +
54301 + if (matchpo) {
54302 + preempt_enable();
54303 + return matchpo;
54304 + }
54305 + }
54306 +
54307 + // lookup parent
54308 +
54309 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
54310 +
54311 + preempt_enable();
54312 + return matchpo;
54313 +}
54314 +
54315 +__u32
54316 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
54317 + const struct vfsmount * mnt, const __u32 mode)
54318 +{
54319 + struct acl_object_label *matchpo;
54320 + __u32 retval;
54321 +
54322 + if (unlikely(!(gr_status & GR_READY)))
54323 + return (mode & ~GR_AUDITS);
54324 +
54325 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
54326 +
54327 + retval = matchpo->mode & mode;
54328 +
54329 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
54330 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54331 + __u32 new_mode = mode;
54332 +
54333 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54334 +
54335 + gr_log_learn(new_dentry, mnt, new_mode);
54336 + return new_mode;
54337 + }
54338 +
54339 + return retval;
54340 +}
54341 +
54342 +__u32
54343 +gr_check_link(const struct dentry * new_dentry,
54344 + const struct dentry * parent_dentry,
54345 + const struct vfsmount * parent_mnt,
54346 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
54347 +{
54348 + struct acl_object_label *obj;
54349 + __u32 oldmode, newmode;
54350 + __u32 needmode;
54351 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
54352 + GR_DELETE | GR_INHERIT;
54353 +
54354 + if (unlikely(!(gr_status & GR_READY)))
54355 + return (GR_CREATE | GR_LINK);
54356 +
54357 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
54358 + oldmode = obj->mode;
54359 +
54360 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
54361 + newmode = obj->mode;
54362 +
54363 + needmode = newmode & checkmodes;
54364 +
54365 + // old name for hardlink must have at least the permissions of the new name
54366 + if ((oldmode & needmode) != needmode)
54367 + goto bad;
54368 +
54369 + // if old name had restrictions/auditing, make sure the new name does as well
54370 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
54371 +
54372 + // don't allow hardlinking of suid/sgid/fcapped files without permission
54373 + if (is_privileged_binary(old_dentry))
54374 + needmode |= GR_SETID;
54375 +
54376 + if ((newmode & needmode) != needmode)
54377 + goto bad;
54378 +
54379 + // enforce minimum permissions
54380 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
54381 + return newmode;
54382 +bad:
54383 + needmode = oldmode;
54384 + if (is_privileged_binary(old_dentry))
54385 + needmode |= GR_SETID;
54386 +
54387 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
54388 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
54389 + return (GR_CREATE | GR_LINK);
54390 + } else if (newmode & GR_SUPPRESS)
54391 + return GR_SUPPRESS;
54392 + else
54393 + return 0;
54394 +}
54395 +
54396 +int
54397 +gr_check_hidden_task(const struct task_struct *task)
54398 +{
54399 + if (unlikely(!(gr_status & GR_READY)))
54400 + return 0;
54401 +
54402 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
54403 + return 1;
54404 +
54405 + return 0;
54406 +}
54407 +
54408 +int
54409 +gr_check_protected_task(const struct task_struct *task)
54410 +{
54411 + if (unlikely(!(gr_status & GR_READY) || !task))
54412 + return 0;
54413 +
54414 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54415 + task->acl != current->acl)
54416 + return 1;
54417 +
54418 + return 0;
54419 +}
54420 +
54421 +int
54422 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54423 +{
54424 + struct task_struct *p;
54425 + int ret = 0;
54426 +
54427 + if (unlikely(!(gr_status & GR_READY) || !pid))
54428 + return ret;
54429 +
54430 + read_lock(&tasklist_lock);
54431 + do_each_pid_task(pid, type, p) {
54432 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54433 + p->acl != current->acl) {
54434 + ret = 1;
54435 + goto out;
54436 + }
54437 + } while_each_pid_task(pid, type, p);
54438 +out:
54439 + read_unlock(&tasklist_lock);
54440 +
54441 + return ret;
54442 +}
54443 +
54444 +void
54445 +gr_copy_label(struct task_struct *tsk)
54446 +{
54447 + tsk->signal->used_accept = 0;
54448 + tsk->acl_sp_role = 0;
54449 + tsk->acl_role_id = current->acl_role_id;
54450 + tsk->acl = current->acl;
54451 + tsk->role = current->role;
54452 + tsk->signal->curr_ip = current->signal->curr_ip;
54453 + tsk->signal->saved_ip = current->signal->saved_ip;
54454 + if (current->exec_file)
54455 + get_file(current->exec_file);
54456 + tsk->exec_file = current->exec_file;
54457 + tsk->is_writable = current->is_writable;
54458 + if (unlikely(current->signal->used_accept)) {
54459 + current->signal->curr_ip = 0;
54460 + current->signal->saved_ip = 0;
54461 + }
54462 +
54463 + return;
54464 +}
54465 +
54466 +static void
54467 +gr_set_proc_res(struct task_struct *task)
54468 +{
54469 + struct acl_subject_label *proc;
54470 + unsigned short i;
54471 +
54472 + proc = task->acl;
54473 +
54474 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54475 + return;
54476 +
54477 + for (i = 0; i < RLIM_NLIMITS; i++) {
54478 + if (!(proc->resmask & (1 << i)))
54479 + continue;
54480 +
54481 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54482 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54483 + }
54484 +
54485 + return;
54486 +}
54487 +
54488 +extern int __gr_process_user_ban(struct user_struct *user);
54489 +
54490 +int
54491 +gr_check_user_change(int real, int effective, int fs)
54492 +{
54493 + unsigned int i;
54494 + __u16 num;
54495 + uid_t *uidlist;
54496 + int curuid;
54497 + int realok = 0;
54498 + int effectiveok = 0;
54499 + int fsok = 0;
54500 +
54501 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54502 + struct user_struct *user;
54503 +
54504 + if (real == -1)
54505 + goto skipit;
54506 +
54507 + user = find_user(real);
54508 + if (user == NULL)
54509 + goto skipit;
54510 +
54511 + if (__gr_process_user_ban(user)) {
54512 + /* for find_user */
54513 + free_uid(user);
54514 + return 1;
54515 + }
54516 +
54517 + /* for find_user */
54518 + free_uid(user);
54519 +
54520 +skipit:
54521 +#endif
54522 +
54523 + if (unlikely(!(gr_status & GR_READY)))
54524 + return 0;
54525 +
54526 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54527 + gr_log_learn_id_change('u', real, effective, fs);
54528 +
54529 + num = current->acl->user_trans_num;
54530 + uidlist = current->acl->user_transitions;
54531 +
54532 + if (uidlist == NULL)
54533 + return 0;
54534 +
54535 + if (real == -1)
54536 + realok = 1;
54537 + if (effective == -1)
54538 + effectiveok = 1;
54539 + if (fs == -1)
54540 + fsok = 1;
54541 +
54542 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54543 + for (i = 0; i < num; i++) {
54544 + curuid = (int)uidlist[i];
54545 + if (real == curuid)
54546 + realok = 1;
54547 + if (effective == curuid)
54548 + effectiveok = 1;
54549 + if (fs == curuid)
54550 + fsok = 1;
54551 + }
54552 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54553 + for (i = 0; i < num; i++) {
54554 + curuid = (int)uidlist[i];
54555 + if (real == curuid)
54556 + break;
54557 + if (effective == curuid)
54558 + break;
54559 + if (fs == curuid)
54560 + break;
54561 + }
54562 + /* not in deny list */
54563 + if (i == num) {
54564 + realok = 1;
54565 + effectiveok = 1;
54566 + fsok = 1;
54567 + }
54568 + }
54569 +
54570 + if (realok && effectiveok && fsok)
54571 + return 0;
54572 + else {
54573 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54574 + return 1;
54575 + }
54576 +}
54577 +
54578 +int
54579 +gr_check_group_change(int real, int effective, int fs)
54580 +{
54581 + unsigned int i;
54582 + __u16 num;
54583 + gid_t *gidlist;
54584 + int curgid;
54585 + int realok = 0;
54586 + int effectiveok = 0;
54587 + int fsok = 0;
54588 +
54589 + if (unlikely(!(gr_status & GR_READY)))
54590 + return 0;
54591 +
54592 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54593 + gr_log_learn_id_change('g', real, effective, fs);
54594 +
54595 + num = current->acl->group_trans_num;
54596 + gidlist = current->acl->group_transitions;
54597 +
54598 + if (gidlist == NULL)
54599 + return 0;
54600 +
54601 + if (real == -1)
54602 + realok = 1;
54603 + if (effective == -1)
54604 + effectiveok = 1;
54605 + if (fs == -1)
54606 + fsok = 1;
54607 +
54608 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54609 + for (i = 0; i < num; i++) {
54610 + curgid = (int)gidlist[i];
54611 + if (real == curgid)
54612 + realok = 1;
54613 + if (effective == curgid)
54614 + effectiveok = 1;
54615 + if (fs == curgid)
54616 + fsok = 1;
54617 + }
54618 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54619 + for (i = 0; i < num; i++) {
54620 + curgid = (int)gidlist[i];
54621 + if (real == curgid)
54622 + break;
54623 + if (effective == curgid)
54624 + break;
54625 + if (fs == curgid)
54626 + break;
54627 + }
54628 + /* not in deny list */
54629 + if (i == num) {
54630 + realok = 1;
54631 + effectiveok = 1;
54632 + fsok = 1;
54633 + }
54634 + }
54635 +
54636 + if (realok && effectiveok && fsok)
54637 + return 0;
54638 + else {
54639 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54640 + return 1;
54641 + }
54642 +}
54643 +
54644 +extern int gr_acl_is_capable(const int cap);
54645 +
54646 +void
54647 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54648 +{
54649 + struct acl_role_label *role = task->role;
54650 + struct acl_subject_label *subj = NULL;
54651 + struct acl_object_label *obj;
54652 + struct file *filp;
54653 +
54654 + if (unlikely(!(gr_status & GR_READY)))
54655 + return;
54656 +
54657 + filp = task->exec_file;
54658 +
54659 + /* kernel process, we'll give them the kernel role */
54660 + if (unlikely(!filp)) {
54661 + task->role = kernel_role;
54662 + task->acl = kernel_role->root_label;
54663 + return;
54664 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54665 + role = lookup_acl_role_label(task, uid, gid);
54666 +
54667 + /* don't change the role if we're not a privileged process */
54668 + if (role && task->role != role &&
54669 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54670 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54671 + return;
54672 +
54673 + /* perform subject lookup in possibly new role
54674 + we can use this result below in the case where role == task->role
54675 + */
54676 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54677 +
54678 + /* if we changed uid/gid, but result in the same role
54679 + and are using inheritance, don't lose the inherited subject
54680 + if current subject is other than what normal lookup
54681 + would result in, we arrived via inheritance, don't
54682 + lose subject
54683 + */
54684 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54685 + (subj == task->acl)))
54686 + task->acl = subj;
54687 +
54688 + task->role = role;
54689 +
54690 + task->is_writable = 0;
54691 +
54692 + /* ignore additional mmap checks for processes that are writable
54693 + by the default ACL */
54694 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54695 + if (unlikely(obj->mode & GR_WRITE))
54696 + task->is_writable = 1;
54697 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54698 + if (unlikely(obj->mode & GR_WRITE))
54699 + task->is_writable = 1;
54700 +
54701 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54702 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54703 +#endif
54704 +
54705 + gr_set_proc_res(task);
54706 +
54707 + return;
54708 +}
54709 +
54710 +int
54711 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54712 + const int unsafe_flags)
54713 +{
54714 + struct task_struct *task = current;
54715 + struct acl_subject_label *newacl;
54716 + struct acl_object_label *obj;
54717 + __u32 retmode;
54718 +
54719 + if (unlikely(!(gr_status & GR_READY)))
54720 + return 0;
54721 +
54722 + newacl = chk_subj_label(dentry, mnt, task->role);
54723 +
54724 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54725 + did an exec
54726 + */
54727 + rcu_read_lock();
54728 + read_lock(&tasklist_lock);
54729 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54730 + (task->parent->acl->mode & GR_POVERRIDE))) {
54731 + read_unlock(&tasklist_lock);
54732 + rcu_read_unlock();
54733 + goto skip_check;
54734 + }
54735 + read_unlock(&tasklist_lock);
54736 + rcu_read_unlock();
54737 +
54738 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54739 + !(task->role->roletype & GR_ROLE_GOD) &&
54740 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54741 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54742 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54743 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54744 + else
54745 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54746 + return -EACCES;
54747 + }
54748 +
54749 +skip_check:
54750 +
54751 + obj = chk_obj_label(dentry, mnt, task->acl);
54752 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54753 +
54754 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54755 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54756 + if (obj->nested)
54757 + task->acl = obj->nested;
54758 + else
54759 + task->acl = newacl;
54760 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54761 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54762 +
54763 + task->is_writable = 0;
54764 +
54765 + /* ignore additional mmap checks for processes that are writable
54766 + by the default ACL */
54767 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54768 + if (unlikely(obj->mode & GR_WRITE))
54769 + task->is_writable = 1;
54770 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54771 + if (unlikely(obj->mode & GR_WRITE))
54772 + task->is_writable = 1;
54773 +
54774 + gr_set_proc_res(task);
54775 +
54776 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54777 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54778 +#endif
54779 + return 0;
54780 +}
54781 +
54782 +/* always called with valid inodev ptr */
54783 +static void
54784 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54785 +{
54786 + struct acl_object_label *matchpo;
54787 + struct acl_subject_label *matchps;
54788 + struct acl_subject_label *subj;
54789 + struct acl_role_label *role;
54790 + unsigned int x;
54791 +
54792 + FOR_EACH_ROLE_START(role)
54793 + FOR_EACH_SUBJECT_START(role, subj, x)
54794 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54795 + matchpo->mode |= GR_DELETED;
54796 + FOR_EACH_SUBJECT_END(subj,x)
54797 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54798 + /* nested subjects aren't in the role's subj_hash table */
54799 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54800 + matchpo->mode |= GR_DELETED;
54801 + FOR_EACH_NESTED_SUBJECT_END(subj)
54802 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54803 + matchps->mode |= GR_DELETED;
54804 + FOR_EACH_ROLE_END(role)
54805 +
54806 + inodev->nentry->deleted = 1;
54807 +
54808 + return;
54809 +}
54810 +
54811 +void
54812 +gr_handle_delete(const ino_t ino, const dev_t dev)
54813 +{
54814 + struct inodev_entry *inodev;
54815 +
54816 + if (unlikely(!(gr_status & GR_READY)))
54817 + return;
54818 +
54819 + write_lock(&gr_inode_lock);
54820 + inodev = lookup_inodev_entry(ino, dev);
54821 + if (inodev != NULL)
54822 + do_handle_delete(inodev, ino, dev);
54823 + write_unlock(&gr_inode_lock);
54824 +
54825 + return;
54826 +}
54827 +
54828 +static void
54829 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54830 + const ino_t newinode, const dev_t newdevice,
54831 + struct acl_subject_label *subj)
54832 +{
54833 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54834 + struct acl_object_label *match;
54835 +
54836 + match = subj->obj_hash[index];
54837 +
54838 + while (match && (match->inode != oldinode ||
54839 + match->device != olddevice ||
54840 + !(match->mode & GR_DELETED)))
54841 + match = match->next;
54842 +
54843 + if (match && (match->inode == oldinode)
54844 + && (match->device == olddevice)
54845 + && (match->mode & GR_DELETED)) {
54846 + if (match->prev == NULL) {
54847 + subj->obj_hash[index] = match->next;
54848 + if (match->next != NULL)
54849 + match->next->prev = NULL;
54850 + } else {
54851 + match->prev->next = match->next;
54852 + if (match->next != NULL)
54853 + match->next->prev = match->prev;
54854 + }
54855 + match->prev = NULL;
54856 + match->next = NULL;
54857 + match->inode = newinode;
54858 + match->device = newdevice;
54859 + match->mode &= ~GR_DELETED;
54860 +
54861 + insert_acl_obj_label(match, subj);
54862 + }
54863 +
54864 + return;
54865 +}
54866 +
54867 +static void
54868 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54869 + const ino_t newinode, const dev_t newdevice,
54870 + struct acl_role_label *role)
54871 +{
54872 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54873 + struct acl_subject_label *match;
54874 +
54875 + match = role->subj_hash[index];
54876 +
54877 + while (match && (match->inode != oldinode ||
54878 + match->device != olddevice ||
54879 + !(match->mode & GR_DELETED)))
54880 + match = match->next;
54881 +
54882 + if (match && (match->inode == oldinode)
54883 + && (match->device == olddevice)
54884 + && (match->mode & GR_DELETED)) {
54885 + if (match->prev == NULL) {
54886 + role->subj_hash[index] = match->next;
54887 + if (match->next != NULL)
54888 + match->next->prev = NULL;
54889 + } else {
54890 + match->prev->next = match->next;
54891 + if (match->next != NULL)
54892 + match->next->prev = match->prev;
54893 + }
54894 + match->prev = NULL;
54895 + match->next = NULL;
54896 + match->inode = newinode;
54897 + match->device = newdevice;
54898 + match->mode &= ~GR_DELETED;
54899 +
54900 + insert_acl_subj_label(match, role);
54901 + }
54902 +
54903 + return;
54904 +}
54905 +
54906 +static void
54907 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54908 + const ino_t newinode, const dev_t newdevice)
54909 +{
54910 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54911 + struct inodev_entry *match;
54912 +
54913 + match = inodev_set.i_hash[index];
54914 +
54915 + while (match && (match->nentry->inode != oldinode ||
54916 + match->nentry->device != olddevice || !match->nentry->deleted))
54917 + match = match->next;
54918 +
54919 + if (match && (match->nentry->inode == oldinode)
54920 + && (match->nentry->device == olddevice) &&
54921 + match->nentry->deleted) {
54922 + if (match->prev == NULL) {
54923 + inodev_set.i_hash[index] = match->next;
54924 + if (match->next != NULL)
54925 + match->next->prev = NULL;
54926 + } else {
54927 + match->prev->next = match->next;
54928 + if (match->next != NULL)
54929 + match->next->prev = match->prev;
54930 + }
54931 + match->prev = NULL;
54932 + match->next = NULL;
54933 + match->nentry->inode = newinode;
54934 + match->nentry->device = newdevice;
54935 + match->nentry->deleted = 0;
54936 +
54937 + insert_inodev_entry(match);
54938 + }
54939 +
54940 + return;
54941 +}
54942 +
54943 +static void
54944 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54945 +{
54946 + struct acl_subject_label *subj;
54947 + struct acl_role_label *role;
54948 + unsigned int x;
54949 +
54950 + FOR_EACH_ROLE_START(role)
54951 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54952 +
54953 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54954 + if ((subj->inode == ino) && (subj->device == dev)) {
54955 + subj->inode = ino;
54956 + subj->device = dev;
54957 + }
54958 + /* nested subjects aren't in the role's subj_hash table */
54959 + update_acl_obj_label(matchn->inode, matchn->device,
54960 + ino, dev, subj);
54961 + FOR_EACH_NESTED_SUBJECT_END(subj)
54962 + FOR_EACH_SUBJECT_START(role, subj, x)
54963 + update_acl_obj_label(matchn->inode, matchn->device,
54964 + ino, dev, subj);
54965 + FOR_EACH_SUBJECT_END(subj,x)
54966 + FOR_EACH_ROLE_END(role)
54967 +
54968 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54969 +
54970 + return;
54971 +}
54972 +
54973 +static void
54974 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54975 + const struct vfsmount *mnt)
54976 +{
54977 + ino_t ino = dentry->d_inode->i_ino;
54978 + dev_t dev = __get_dev(dentry);
54979 +
54980 + __do_handle_create(matchn, ino, dev);
54981 +
54982 + return;
54983 +}
54984 +
54985 +void
54986 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54987 +{
54988 + struct name_entry *matchn;
54989 +
54990 + if (unlikely(!(gr_status & GR_READY)))
54991 + return;
54992 +
54993 + preempt_disable();
54994 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54995 +
54996 + if (unlikely((unsigned long)matchn)) {
54997 + write_lock(&gr_inode_lock);
54998 + do_handle_create(matchn, dentry, mnt);
54999 + write_unlock(&gr_inode_lock);
55000 + }
55001 + preempt_enable();
55002 +
55003 + return;
55004 +}
55005 +
55006 +void
55007 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
55008 +{
55009 + struct name_entry *matchn;
55010 +
55011 + if (unlikely(!(gr_status & GR_READY)))
55012 + return;
55013 +
55014 + preempt_disable();
55015 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
55016 +
55017 + if (unlikely((unsigned long)matchn)) {
55018 + write_lock(&gr_inode_lock);
55019 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
55020 + write_unlock(&gr_inode_lock);
55021 + }
55022 + preempt_enable();
55023 +
55024 + return;
55025 +}
55026 +
55027 +void
55028 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
55029 + struct dentry *old_dentry,
55030 + struct dentry *new_dentry,
55031 + struct vfsmount *mnt, const __u8 replace)
55032 +{
55033 + struct name_entry *matchn;
55034 + struct inodev_entry *inodev;
55035 + struct inode *inode = new_dentry->d_inode;
55036 + ino_t old_ino = old_dentry->d_inode->i_ino;
55037 + dev_t old_dev = __get_dev(old_dentry);
55038 +
55039 + /* vfs_rename swaps the name and parent link for old_dentry and
55040 + new_dentry
55041 + at this point, old_dentry has the new name, parent link, and inode
55042 + for the renamed file
55043 + if a file is being replaced by a rename, new_dentry has the inode
55044 + and name for the replaced file
55045 + */
55046 +
55047 + if (unlikely(!(gr_status & GR_READY)))
55048 + return;
55049 +
55050 + preempt_disable();
55051 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
55052 +
55053 + /* we wouldn't have to check d_inode if it weren't for
55054 + NFS silly-renaming
55055 + */
55056 +
55057 + write_lock(&gr_inode_lock);
55058 + if (unlikely(replace && inode)) {
55059 + ino_t new_ino = inode->i_ino;
55060 + dev_t new_dev = __get_dev(new_dentry);
55061 +
55062 + inodev = lookup_inodev_entry(new_ino, new_dev);
55063 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
55064 + do_handle_delete(inodev, new_ino, new_dev);
55065 + }
55066 +
55067 + inodev = lookup_inodev_entry(old_ino, old_dev);
55068 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
55069 + do_handle_delete(inodev, old_ino, old_dev);
55070 +
55071 + if (unlikely((unsigned long)matchn))
55072 + do_handle_create(matchn, old_dentry, mnt);
55073 +
55074 + write_unlock(&gr_inode_lock);
55075 + preempt_enable();
55076 +
55077 + return;
55078 +}
55079 +
55080 +static int
55081 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
55082 + unsigned char **sum)
55083 +{
55084 + struct acl_role_label *r;
55085 + struct role_allowed_ip *ipp;
55086 + struct role_transition *trans;
55087 + unsigned int i;
55088 + int found = 0;
55089 + u32 curr_ip = current->signal->curr_ip;
55090 +
55091 + current->signal->saved_ip = curr_ip;
55092 +
55093 + /* check transition table */
55094 +
55095 + for (trans = current->role->transitions; trans; trans = trans->next) {
55096 + if (!strcmp(rolename, trans->rolename)) {
55097 + found = 1;
55098 + break;
55099 + }
55100 + }
55101 +
55102 + if (!found)
55103 + return 0;
55104 +
55105 + /* handle special roles that do not require authentication
55106 + and check ip */
55107 +
55108 + FOR_EACH_ROLE_START(r)
55109 + if (!strcmp(rolename, r->rolename) &&
55110 + (r->roletype & GR_ROLE_SPECIAL)) {
55111 + found = 0;
55112 + if (r->allowed_ips != NULL) {
55113 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
55114 + if ((ntohl(curr_ip) & ipp->netmask) ==
55115 + (ntohl(ipp->addr) & ipp->netmask))
55116 + found = 1;
55117 + }
55118 + } else
55119 + found = 2;
55120 + if (!found)
55121 + return 0;
55122 +
55123 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
55124 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
55125 + *salt = NULL;
55126 + *sum = NULL;
55127 + return 1;
55128 + }
55129 + }
55130 + FOR_EACH_ROLE_END(r)
55131 +
55132 + for (i = 0; i < num_sprole_pws; i++) {
55133 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
55134 + *salt = acl_special_roles[i]->salt;
55135 + *sum = acl_special_roles[i]->sum;
55136 + return 1;
55137 + }
55138 + }
55139 +
55140 + return 0;
55141 +}
55142 +
55143 +static void
55144 +assign_special_role(char *rolename)
55145 +{
55146 + struct acl_object_label *obj;
55147 + struct acl_role_label *r;
55148 + struct acl_role_label *assigned = NULL;
55149 + struct task_struct *tsk;
55150 + struct file *filp;
55151 +
55152 + FOR_EACH_ROLE_START(r)
55153 + if (!strcmp(rolename, r->rolename) &&
55154 + (r->roletype & GR_ROLE_SPECIAL)) {
55155 + assigned = r;
55156 + break;
55157 + }
55158 + FOR_EACH_ROLE_END(r)
55159 +
55160 + if (!assigned)
55161 + return;
55162 +
55163 + read_lock(&tasklist_lock);
55164 + read_lock(&grsec_exec_file_lock);
55165 +
55166 + tsk = current->real_parent;
55167 + if (tsk == NULL)
55168 + goto out_unlock;
55169 +
55170 + filp = tsk->exec_file;
55171 + if (filp == NULL)
55172 + goto out_unlock;
55173 +
55174 + tsk->is_writable = 0;
55175 +
55176 + tsk->acl_sp_role = 1;
55177 + tsk->acl_role_id = ++acl_sp_role_value;
55178 + tsk->role = assigned;
55179 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
55180 +
55181 + /* ignore additional mmap checks for processes that are writable
55182 + by the default ACL */
55183 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55184 + if (unlikely(obj->mode & GR_WRITE))
55185 + tsk->is_writable = 1;
55186 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
55187 + if (unlikely(obj->mode & GR_WRITE))
55188 + tsk->is_writable = 1;
55189 +
55190 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55191 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
55192 +#endif
55193 +
55194 +out_unlock:
55195 + read_unlock(&grsec_exec_file_lock);
55196 + read_unlock(&tasklist_lock);
55197 + return;
55198 +}
55199 +
55200 +int gr_check_secure_terminal(struct task_struct *task)
55201 +{
55202 + struct task_struct *p, *p2, *p3;
55203 + struct files_struct *files;
55204 + struct fdtable *fdt;
55205 + struct file *our_file = NULL, *file;
55206 + int i;
55207 +
55208 + if (task->signal->tty == NULL)
55209 + return 1;
55210 +
55211 + files = get_files_struct(task);
55212 + if (files != NULL) {
55213 + rcu_read_lock();
55214 + fdt = files_fdtable(files);
55215 + for (i=0; i < fdt->max_fds; i++) {
55216 + file = fcheck_files(files, i);
55217 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
55218 + get_file(file);
55219 + our_file = file;
55220 + }
55221 + }
55222 + rcu_read_unlock();
55223 + put_files_struct(files);
55224 + }
55225 +
55226 + if (our_file == NULL)
55227 + return 1;
55228 +
55229 + read_lock(&tasklist_lock);
55230 + do_each_thread(p2, p) {
55231 + files = get_files_struct(p);
55232 + if (files == NULL ||
55233 + (p->signal && p->signal->tty == task->signal->tty)) {
55234 + if (files != NULL)
55235 + put_files_struct(files);
55236 + continue;
55237 + }
55238 + rcu_read_lock();
55239 + fdt = files_fdtable(files);
55240 + for (i=0; i < fdt->max_fds; i++) {
55241 + file = fcheck_files(files, i);
55242 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
55243 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
55244 + p3 = task;
55245 + while (p3->pid > 0) {
55246 + if (p3 == p)
55247 + break;
55248 + p3 = p3->real_parent;
55249 + }
55250 + if (p3 == p)
55251 + break;
55252 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
55253 + gr_handle_alertkill(p);
55254 + rcu_read_unlock();
55255 + put_files_struct(files);
55256 + read_unlock(&tasklist_lock);
55257 + fput(our_file);
55258 + return 0;
55259 + }
55260 + }
55261 + rcu_read_unlock();
55262 + put_files_struct(files);
55263 + } while_each_thread(p2, p);
55264 + read_unlock(&tasklist_lock);
55265 +
55266 + fput(our_file);
55267 + return 1;
55268 +}
55269 +
55270 +static int gr_rbac_disable(void *unused)
55271 +{
55272 + pax_open_kernel();
55273 + gr_status &= ~GR_READY;
55274 + pax_close_kernel();
55275 +
55276 + return 0;
55277 +}
55278 +
55279 +ssize_t
55280 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
55281 +{
55282 + struct gr_arg_wrapper uwrap;
55283 + unsigned char *sprole_salt = NULL;
55284 + unsigned char *sprole_sum = NULL;
55285 + int error = sizeof (struct gr_arg_wrapper);
55286 + int error2 = 0;
55287 +
55288 + mutex_lock(&gr_dev_mutex);
55289 +
55290 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
55291 + error = -EPERM;
55292 + goto out;
55293 + }
55294 +
55295 + if (count != sizeof (struct gr_arg_wrapper)) {
55296 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
55297 + error = -EINVAL;
55298 + goto out;
55299 + }
55300 +
55301 +
55302 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
55303 + gr_auth_expires = 0;
55304 + gr_auth_attempts = 0;
55305 + }
55306 +
55307 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
55308 + error = -EFAULT;
55309 + goto out;
55310 + }
55311 +
55312 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
55313 + error = -EINVAL;
55314 + goto out;
55315 + }
55316 +
55317 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
55318 + error = -EFAULT;
55319 + goto out;
55320 + }
55321 +
55322 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55323 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55324 + time_after(gr_auth_expires, get_seconds())) {
55325 + error = -EBUSY;
55326 + goto out;
55327 + }
55328 +
55329 + /* if non-root trying to do anything other than use a special role,
55330 + do not attempt authentication, do not count towards authentication
55331 + locking
55332 + */
55333 +
55334 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
55335 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55336 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
55337 + error = -EPERM;
55338 + goto out;
55339 + }
55340 +
55341 + /* ensure pw and special role name are null terminated */
55342 +
55343 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
55344 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
55345 +
55346 + /* Okay.
55347 + * We have our enough of the argument structure..(we have yet
55348 + * to copy_from_user the tables themselves) . Copy the tables
55349 + * only if we need them, i.e. for loading operations. */
55350 +
55351 + switch (gr_usermode->mode) {
55352 + case GR_STATUS:
55353 + if (gr_status & GR_READY) {
55354 + error = 1;
55355 + if (!gr_check_secure_terminal(current))
55356 + error = 3;
55357 + } else
55358 + error = 2;
55359 + goto out;
55360 + case GR_SHUTDOWN:
55361 + if ((gr_status & GR_READY)
55362 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55363 + stop_machine(gr_rbac_disable, NULL, NULL);
55364 + free_variables();
55365 + memset(gr_usermode, 0, sizeof (struct gr_arg));
55366 + memset(gr_system_salt, 0, GR_SALT_LEN);
55367 + memset(gr_system_sum, 0, GR_SHA_LEN);
55368 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
55369 + } else if (gr_status & GR_READY) {
55370 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
55371 + error = -EPERM;
55372 + } else {
55373 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
55374 + error = -EAGAIN;
55375 + }
55376 + break;
55377 + case GR_ENABLE:
55378 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
55379 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
55380 + else {
55381 + if (gr_status & GR_READY)
55382 + error = -EAGAIN;
55383 + else
55384 + error = error2;
55385 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
55386 + }
55387 + break;
55388 + case GR_RELOAD:
55389 + if (!(gr_status & GR_READY)) {
55390 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
55391 + error = -EAGAIN;
55392 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55393 + stop_machine(gr_rbac_disable, NULL, NULL);
55394 + free_variables();
55395 + error2 = gracl_init(gr_usermode);
55396 + if (!error2)
55397 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
55398 + else {
55399 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55400 + error = error2;
55401 + }
55402 + } else {
55403 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55404 + error = -EPERM;
55405 + }
55406 + break;
55407 + case GR_SEGVMOD:
55408 + if (unlikely(!(gr_status & GR_READY))) {
55409 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
55410 + error = -EAGAIN;
55411 + break;
55412 + }
55413 +
55414 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55415 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
55416 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
55417 + struct acl_subject_label *segvacl;
55418 + segvacl =
55419 + lookup_acl_subj_label(gr_usermode->segv_inode,
55420 + gr_usermode->segv_device,
55421 + current->role);
55422 + if (segvacl) {
55423 + segvacl->crashes = 0;
55424 + segvacl->expires = 0;
55425 + }
55426 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
55427 + gr_remove_uid(gr_usermode->segv_uid);
55428 + }
55429 + } else {
55430 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
55431 + error = -EPERM;
55432 + }
55433 + break;
55434 + case GR_SPROLE:
55435 + case GR_SPROLEPAM:
55436 + if (unlikely(!(gr_status & GR_READY))) {
55437 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
55438 + error = -EAGAIN;
55439 + break;
55440 + }
55441 +
55442 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
55443 + current->role->expires = 0;
55444 + current->role->auth_attempts = 0;
55445 + }
55446 +
55447 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55448 + time_after(current->role->expires, get_seconds())) {
55449 + error = -EBUSY;
55450 + goto out;
55451 + }
55452 +
55453 + if (lookup_special_role_auth
55454 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
55455 + && ((!sprole_salt && !sprole_sum)
55456 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
55457 + char *p = "";
55458 + assign_special_role(gr_usermode->sp_role);
55459 + read_lock(&tasklist_lock);
55460 + if (current->real_parent)
55461 + p = current->real_parent->role->rolename;
55462 + read_unlock(&tasklist_lock);
55463 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
55464 + p, acl_sp_role_value);
55465 + } else {
55466 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
55467 + error = -EPERM;
55468 + if(!(current->role->auth_attempts++))
55469 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55470 +
55471 + goto out;
55472 + }
55473 + break;
55474 + case GR_UNSPROLE:
55475 + if (unlikely(!(gr_status & GR_READY))) {
55476 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55477 + error = -EAGAIN;
55478 + break;
55479 + }
55480 +
55481 + if (current->role->roletype & GR_ROLE_SPECIAL) {
55482 + char *p = "";
55483 + int i = 0;
55484 +
55485 + read_lock(&tasklist_lock);
55486 + if (current->real_parent) {
55487 + p = current->real_parent->role->rolename;
55488 + i = current->real_parent->acl_role_id;
55489 + }
55490 + read_unlock(&tasklist_lock);
55491 +
55492 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55493 + gr_set_acls(1);
55494 + } else {
55495 + error = -EPERM;
55496 + goto out;
55497 + }
55498 + break;
55499 + default:
55500 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55501 + error = -EINVAL;
55502 + break;
55503 + }
55504 +
55505 + if (error != -EPERM)
55506 + goto out;
55507 +
55508 + if(!(gr_auth_attempts++))
55509 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55510 +
55511 + out:
55512 + mutex_unlock(&gr_dev_mutex);
55513 + return error;
55514 +}
55515 +
55516 +/* must be called with
55517 + rcu_read_lock();
55518 + read_lock(&tasklist_lock);
55519 + read_lock(&grsec_exec_file_lock);
55520 +*/
55521 +int gr_apply_subject_to_task(struct task_struct *task)
55522 +{
55523 + struct acl_object_label *obj;
55524 + char *tmpname;
55525 + struct acl_subject_label *tmpsubj;
55526 + struct file *filp;
55527 + struct name_entry *nmatch;
55528 +
55529 + filp = task->exec_file;
55530 + if (filp == NULL)
55531 + return 0;
55532 +
55533 + /* the following is to apply the correct subject
55534 + on binaries running when the RBAC system
55535 + is enabled, when the binaries have been
55536 + replaced or deleted since their execution
55537 + -----
55538 + when the RBAC system starts, the inode/dev
55539 + from exec_file will be one the RBAC system
55540 + is unaware of. It only knows the inode/dev
55541 + of the present file on disk, or the absence
55542 + of it.
55543 + */
55544 + preempt_disable();
55545 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55546 +
55547 + nmatch = lookup_name_entry(tmpname);
55548 + preempt_enable();
55549 + tmpsubj = NULL;
55550 + if (nmatch) {
55551 + if (nmatch->deleted)
55552 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55553 + else
55554 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55555 + if (tmpsubj != NULL)
55556 + task->acl = tmpsubj;
55557 + }
55558 + if (tmpsubj == NULL)
55559 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55560 + task->role);
55561 + if (task->acl) {
55562 + task->is_writable = 0;
55563 + /* ignore additional mmap checks for processes that are writable
55564 + by the default ACL */
55565 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55566 + if (unlikely(obj->mode & GR_WRITE))
55567 + task->is_writable = 1;
55568 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55569 + if (unlikely(obj->mode & GR_WRITE))
55570 + task->is_writable = 1;
55571 +
55572 + gr_set_proc_res(task);
55573 +
55574 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55575 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55576 +#endif
55577 + } else {
55578 + return 1;
55579 + }
55580 +
55581 + return 0;
55582 +}
55583 +
55584 +int
55585 +gr_set_acls(const int type)
55586 +{
55587 + struct task_struct *task, *task2;
55588 + struct acl_role_label *role = current->role;
55589 + __u16 acl_role_id = current->acl_role_id;
55590 + const struct cred *cred;
55591 + int ret;
55592 +
55593 + rcu_read_lock();
55594 + read_lock(&tasklist_lock);
55595 + read_lock(&grsec_exec_file_lock);
55596 + do_each_thread(task2, task) {
55597 + /* check to see if we're called from the exit handler,
55598 + if so, only replace ACLs that have inherited the admin
55599 + ACL */
55600 +
55601 + if (type && (task->role != role ||
55602 + task->acl_role_id != acl_role_id))
55603 + continue;
55604 +
55605 + task->acl_role_id = 0;
55606 + task->acl_sp_role = 0;
55607 +
55608 + if (task->exec_file) {
55609 + cred = __task_cred(task);
55610 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55611 + ret = gr_apply_subject_to_task(task);
55612 + if (ret) {
55613 + read_unlock(&grsec_exec_file_lock);
55614 + read_unlock(&tasklist_lock);
55615 + rcu_read_unlock();
55616 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55617 + return ret;
55618 + }
55619 + } else {
55620 + // it's a kernel process
55621 + task->role = kernel_role;
55622 + task->acl = kernel_role->root_label;
55623 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55624 + task->acl->mode &= ~GR_PROCFIND;
55625 +#endif
55626 + }
55627 + } while_each_thread(task2, task);
55628 + read_unlock(&grsec_exec_file_lock);
55629 + read_unlock(&tasklist_lock);
55630 + rcu_read_unlock();
55631 +
55632 + return 0;
55633 +}
55634 +
55635 +void
55636 +gr_learn_resource(const struct task_struct *task,
55637 + const int res, const unsigned long wanted, const int gt)
55638 +{
55639 + struct acl_subject_label *acl;
55640 + const struct cred *cred;
55641 +
55642 + if (unlikely((gr_status & GR_READY) &&
55643 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55644 + goto skip_reslog;
55645 +
55646 +#ifdef CONFIG_GRKERNSEC_RESLOG
55647 + gr_log_resource(task, res, wanted, gt);
55648 +#endif
55649 + skip_reslog:
55650 +
55651 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55652 + return;
55653 +
55654 + acl = task->acl;
55655 +
55656 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55657 + !(acl->resmask & (1 << (unsigned short) res))))
55658 + return;
55659 +
55660 + if (wanted >= acl->res[res].rlim_cur) {
55661 + unsigned long res_add;
55662 +
55663 + res_add = wanted;
55664 + switch (res) {
55665 + case RLIMIT_CPU:
55666 + res_add += GR_RLIM_CPU_BUMP;
55667 + break;
55668 + case RLIMIT_FSIZE:
55669 + res_add += GR_RLIM_FSIZE_BUMP;
55670 + break;
55671 + case RLIMIT_DATA:
55672 + res_add += GR_RLIM_DATA_BUMP;
55673 + break;
55674 + case RLIMIT_STACK:
55675 + res_add += GR_RLIM_STACK_BUMP;
55676 + break;
55677 + case RLIMIT_CORE:
55678 + res_add += GR_RLIM_CORE_BUMP;
55679 + break;
55680 + case RLIMIT_RSS:
55681 + res_add += GR_RLIM_RSS_BUMP;
55682 + break;
55683 + case RLIMIT_NPROC:
55684 + res_add += GR_RLIM_NPROC_BUMP;
55685 + break;
55686 + case RLIMIT_NOFILE:
55687 + res_add += GR_RLIM_NOFILE_BUMP;
55688 + break;
55689 + case RLIMIT_MEMLOCK:
55690 + res_add += GR_RLIM_MEMLOCK_BUMP;
55691 + break;
55692 + case RLIMIT_AS:
55693 + res_add += GR_RLIM_AS_BUMP;
55694 + break;
55695 + case RLIMIT_LOCKS:
55696 + res_add += GR_RLIM_LOCKS_BUMP;
55697 + break;
55698 + case RLIMIT_SIGPENDING:
55699 + res_add += GR_RLIM_SIGPENDING_BUMP;
55700 + break;
55701 + case RLIMIT_MSGQUEUE:
55702 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55703 + break;
55704 + case RLIMIT_NICE:
55705 + res_add += GR_RLIM_NICE_BUMP;
55706 + break;
55707 + case RLIMIT_RTPRIO:
55708 + res_add += GR_RLIM_RTPRIO_BUMP;
55709 + break;
55710 + case RLIMIT_RTTIME:
55711 + res_add += GR_RLIM_RTTIME_BUMP;
55712 + break;
55713 + }
55714 +
55715 + acl->res[res].rlim_cur = res_add;
55716 +
55717 + if (wanted > acl->res[res].rlim_max)
55718 + acl->res[res].rlim_max = res_add;
55719 +
55720 + /* only log the subject filename, since resource logging is supported for
55721 + single-subject learning only */
55722 + rcu_read_lock();
55723 + cred = __task_cred(task);
55724 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55725 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55726 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55727 + "", (unsigned long) res, &task->signal->saved_ip);
55728 + rcu_read_unlock();
55729 + }
55730 +
55731 + return;
55732 +}
55733 +
55734 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55735 +void
55736 +pax_set_initial_flags(struct linux_binprm *bprm)
55737 +{
55738 + struct task_struct *task = current;
55739 + struct acl_subject_label *proc;
55740 + unsigned long flags;
55741 +
55742 + if (unlikely(!(gr_status & GR_READY)))
55743 + return;
55744 +
55745 + flags = pax_get_flags(task);
55746 +
55747 + proc = task->acl;
55748 +
55749 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55750 + flags &= ~MF_PAX_PAGEEXEC;
55751 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55752 + flags &= ~MF_PAX_SEGMEXEC;
55753 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55754 + flags &= ~MF_PAX_RANDMMAP;
55755 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55756 + flags &= ~MF_PAX_EMUTRAMP;
55757 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55758 + flags &= ~MF_PAX_MPROTECT;
55759 +
55760 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55761 + flags |= MF_PAX_PAGEEXEC;
55762 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55763 + flags |= MF_PAX_SEGMEXEC;
55764 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55765 + flags |= MF_PAX_RANDMMAP;
55766 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55767 + flags |= MF_PAX_EMUTRAMP;
55768 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55769 + flags |= MF_PAX_MPROTECT;
55770 +
55771 + pax_set_flags(task, flags);
55772 +
55773 + return;
55774 +}
55775 +#endif
55776 +
55777 +int
55778 +gr_handle_proc_ptrace(struct task_struct *task)
55779 +{
55780 + struct file *filp;
55781 + struct task_struct *tmp = task;
55782 + struct task_struct *curtemp = current;
55783 + __u32 retmode;
55784 +
55785 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55786 + if (unlikely(!(gr_status & GR_READY)))
55787 + return 0;
55788 +#endif
55789 +
55790 + read_lock(&tasklist_lock);
55791 + read_lock(&grsec_exec_file_lock);
55792 + filp = task->exec_file;
55793 +
55794 + while (tmp->pid > 0) {
55795 + if (tmp == curtemp)
55796 + break;
55797 + tmp = tmp->real_parent;
55798 + }
55799 +
55800 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55801 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55802 + read_unlock(&grsec_exec_file_lock);
55803 + read_unlock(&tasklist_lock);
55804 + return 1;
55805 + }
55806 +
55807 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55808 + if (!(gr_status & GR_READY)) {
55809 + read_unlock(&grsec_exec_file_lock);
55810 + read_unlock(&tasklist_lock);
55811 + return 0;
55812 + }
55813 +#endif
55814 +
55815 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55816 + read_unlock(&grsec_exec_file_lock);
55817 + read_unlock(&tasklist_lock);
55818 +
55819 + if (retmode & GR_NOPTRACE)
55820 + return 1;
55821 +
55822 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55823 + && (current->acl != task->acl || (current->acl != current->role->root_label
55824 + && current->pid != task->pid)))
55825 + return 1;
55826 +
55827 + return 0;
55828 +}
55829 +
55830 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55831 +{
55832 + if (unlikely(!(gr_status & GR_READY)))
55833 + return;
55834 +
55835 + if (!(current->role->roletype & GR_ROLE_GOD))
55836 + return;
55837 +
55838 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55839 + p->role->rolename, gr_task_roletype_to_char(p),
55840 + p->acl->filename);
55841 +}
55842 +
55843 +int
55844 +gr_handle_ptrace(struct task_struct *task, const long request)
55845 +{
55846 + struct task_struct *tmp = task;
55847 + struct task_struct *curtemp = current;
55848 + __u32 retmode;
55849 +
55850 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55851 + if (unlikely(!(gr_status & GR_READY)))
55852 + return 0;
55853 +#endif
55854 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55855 + read_lock(&tasklist_lock);
55856 + while (tmp->pid > 0) {
55857 + if (tmp == curtemp)
55858 + break;
55859 + tmp = tmp->real_parent;
55860 + }
55861 +
55862 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55863 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55864 + read_unlock(&tasklist_lock);
55865 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55866 + return 1;
55867 + }
55868 + read_unlock(&tasklist_lock);
55869 + }
55870 +
55871 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55872 + if (!(gr_status & GR_READY))
55873 + return 0;
55874 +#endif
55875 +
55876 + read_lock(&grsec_exec_file_lock);
55877 + if (unlikely(!task->exec_file)) {
55878 + read_unlock(&grsec_exec_file_lock);
55879 + return 0;
55880 + }
55881 +
55882 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55883 + read_unlock(&grsec_exec_file_lock);
55884 +
55885 + if (retmode & GR_NOPTRACE) {
55886 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55887 + return 1;
55888 + }
55889 +
55890 + if (retmode & GR_PTRACERD) {
55891 + switch (request) {
55892 + case PTRACE_SEIZE:
55893 + case PTRACE_POKETEXT:
55894 + case PTRACE_POKEDATA:
55895 + case PTRACE_POKEUSR:
55896 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55897 + case PTRACE_SETREGS:
55898 + case PTRACE_SETFPREGS:
55899 +#endif
55900 +#ifdef CONFIG_X86
55901 + case PTRACE_SETFPXREGS:
55902 +#endif
55903 +#ifdef CONFIG_ALTIVEC
55904 + case PTRACE_SETVRREGS:
55905 +#endif
55906 + return 1;
55907 + default:
55908 + return 0;
55909 + }
55910 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55911 + !(current->role->roletype & GR_ROLE_GOD) &&
55912 + (current->acl != task->acl)) {
55913 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55914 + return 1;
55915 + }
55916 +
55917 + return 0;
55918 +}
55919 +
55920 +static int is_writable_mmap(const struct file *filp)
55921 +{
55922 + struct task_struct *task = current;
55923 + struct acl_object_label *obj, *obj2;
55924 +
55925 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55926 + !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))) {
55927 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55928 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55929 + task->role->root_label);
55930 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55931 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55932 + return 1;
55933 + }
55934 + }
55935 + return 0;
55936 +}
55937 +
55938 +int
55939 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55940 +{
55941 + __u32 mode;
55942 +
55943 + if (unlikely(!file || !(prot & PROT_EXEC)))
55944 + return 1;
55945 +
55946 + if (is_writable_mmap(file))
55947 + return 0;
55948 +
55949 + mode =
55950 + gr_search_file(file->f_path.dentry,
55951 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55952 + file->f_path.mnt);
55953 +
55954 + if (!gr_tpe_allow(file))
55955 + return 0;
55956 +
55957 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55958 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55959 + return 0;
55960 + } else if (unlikely(!(mode & GR_EXEC))) {
55961 + return 0;
55962 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55963 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55964 + return 1;
55965 + }
55966 +
55967 + return 1;
55968 +}
55969 +
55970 +int
55971 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55972 +{
55973 + __u32 mode;
55974 +
55975 + if (unlikely(!file || !(prot & PROT_EXEC)))
55976 + return 1;
55977 +
55978 + if (is_writable_mmap(file))
55979 + return 0;
55980 +
55981 + mode =
55982 + gr_search_file(file->f_path.dentry,
55983 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55984 + file->f_path.mnt);
55985 +
55986 + if (!gr_tpe_allow(file))
55987 + return 0;
55988 +
55989 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55990 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55991 + return 0;
55992 + } else if (unlikely(!(mode & GR_EXEC))) {
55993 + return 0;
55994 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55995 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55996 + return 1;
55997 + }
55998 +
55999 + return 1;
56000 +}
56001 +
56002 +void
56003 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56004 +{
56005 + unsigned long runtime;
56006 + unsigned long cputime;
56007 + unsigned int wday, cday;
56008 + __u8 whr, chr;
56009 + __u8 wmin, cmin;
56010 + __u8 wsec, csec;
56011 + struct timespec timeval;
56012 +
56013 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
56014 + !(task->acl->mode & GR_PROCACCT)))
56015 + return;
56016 +
56017 + do_posix_clock_monotonic_gettime(&timeval);
56018 + runtime = timeval.tv_sec - task->start_time.tv_sec;
56019 + wday = runtime / (3600 * 24);
56020 + runtime -= wday * (3600 * 24);
56021 + whr = runtime / 3600;
56022 + runtime -= whr * 3600;
56023 + wmin = runtime / 60;
56024 + runtime -= wmin * 60;
56025 + wsec = runtime;
56026 +
56027 + cputime = (task->utime + task->stime) / HZ;
56028 + cday = cputime / (3600 * 24);
56029 + cputime -= cday * (3600 * 24);
56030 + chr = cputime / 3600;
56031 + cputime -= chr * 3600;
56032 + cmin = cputime / 60;
56033 + cputime -= cmin * 60;
56034 + csec = cputime;
56035 +
56036 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
56037 +
56038 + return;
56039 +}
56040 +
56041 +void gr_set_kernel_label(struct task_struct *task)
56042 +{
56043 + if (gr_status & GR_READY) {
56044 + task->role = kernel_role;
56045 + task->acl = kernel_role->root_label;
56046 + }
56047 + return;
56048 +}
56049 +
56050 +#ifdef CONFIG_TASKSTATS
56051 +int gr_is_taskstats_denied(int pid)
56052 +{
56053 + struct task_struct *task;
56054 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56055 + const struct cred *cred;
56056 +#endif
56057 + int ret = 0;
56058 +
56059 + /* restrict taskstats viewing to un-chrooted root users
56060 + who have the 'view' subject flag if the RBAC system is enabled
56061 + */
56062 +
56063 + rcu_read_lock();
56064 + read_lock(&tasklist_lock);
56065 + task = find_task_by_vpid(pid);
56066 + if (task) {
56067 +#ifdef CONFIG_GRKERNSEC_CHROOT
56068 + if (proc_is_chrooted(task))
56069 + ret = -EACCES;
56070 +#endif
56071 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56072 + cred = __task_cred(task);
56073 +#ifdef CONFIG_GRKERNSEC_PROC_USER
56074 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
56075 + ret = -EACCES;
56076 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56077 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
56078 + ret = -EACCES;
56079 +#endif
56080 +#endif
56081 + if (gr_status & GR_READY) {
56082 + if (!(task->acl->mode & GR_VIEW))
56083 + ret = -EACCES;
56084 + }
56085 + } else
56086 + ret = -ENOENT;
56087 +
56088 + read_unlock(&tasklist_lock);
56089 + rcu_read_unlock();
56090 +
56091 + return ret;
56092 +}
56093 +#endif
56094 +
56095 +/* AUXV entries are filled via a descendant of search_binary_handler
56096 + after we've already applied the subject for the target
56097 +*/
56098 +int gr_acl_enable_at_secure(void)
56099 +{
56100 + if (unlikely(!(gr_status & GR_READY)))
56101 + return 0;
56102 +
56103 + if (current->acl->mode & GR_ATSECURE)
56104 + return 1;
56105 +
56106 + return 0;
56107 +}
56108 +
56109 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
56110 +{
56111 + struct task_struct *task = current;
56112 + struct dentry *dentry = file->f_path.dentry;
56113 + struct vfsmount *mnt = file->f_path.mnt;
56114 + struct acl_object_label *obj, *tmp;
56115 + struct acl_subject_label *subj;
56116 + unsigned int bufsize;
56117 + int is_not_root;
56118 + char *path;
56119 + dev_t dev = __get_dev(dentry);
56120 +
56121 + if (unlikely(!(gr_status & GR_READY)))
56122 + return 1;
56123 +
56124 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56125 + return 1;
56126 +
56127 + /* ignore Eric Biederman */
56128 + if (IS_PRIVATE(dentry->d_inode))
56129 + return 1;
56130 +
56131 + subj = task->acl;
56132 + read_lock(&gr_inode_lock);
56133 + do {
56134 + obj = lookup_acl_obj_label(ino, dev, subj);
56135 + if (obj != NULL) {
56136 + read_unlock(&gr_inode_lock);
56137 + return (obj->mode & GR_FIND) ? 1 : 0;
56138 + }
56139 + } while ((subj = subj->parent_subject));
56140 + read_unlock(&gr_inode_lock);
56141 +
56142 + /* this is purely an optimization since we're looking for an object
56143 + for the directory we're doing a readdir on
56144 + if it's possible for any globbed object to match the entry we're
56145 + filling into the directory, then the object we find here will be
56146 + an anchor point with attached globbed objects
56147 + */
56148 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
56149 + if (obj->globbed == NULL)
56150 + return (obj->mode & GR_FIND) ? 1 : 0;
56151 +
56152 + is_not_root = ((obj->filename[0] == '/') &&
56153 + (obj->filename[1] == '\0')) ? 0 : 1;
56154 + bufsize = PAGE_SIZE - namelen - is_not_root;
56155 +
56156 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
56157 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
56158 + return 1;
56159 +
56160 + preempt_disable();
56161 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
56162 + bufsize);
56163 +
56164 + bufsize = strlen(path);
56165 +
56166 + /* if base is "/", don't append an additional slash */
56167 + if (is_not_root)
56168 + *(path + bufsize) = '/';
56169 + memcpy(path + bufsize + is_not_root, name, namelen);
56170 + *(path + bufsize + namelen + is_not_root) = '\0';
56171 +
56172 + tmp = obj->globbed;
56173 + while (tmp) {
56174 + if (!glob_match(tmp->filename, path)) {
56175 + preempt_enable();
56176 + return (tmp->mode & GR_FIND) ? 1 : 0;
56177 + }
56178 + tmp = tmp->next;
56179 + }
56180 + preempt_enable();
56181 + return (obj->mode & GR_FIND) ? 1 : 0;
56182 +}
56183 +
56184 +void gr_put_exec_file(struct task_struct *task)
56185 +{
56186 + struct file *filp;
56187 +
56188 + write_lock(&grsec_exec_file_lock);
56189 + filp = task->exec_file;
56190 + task->exec_file = NULL;
56191 + write_unlock(&grsec_exec_file_lock);
56192 +
56193 + if (filp)
56194 + fput(filp);
56195 +
56196 + return;
56197 +}
56198 +
56199 +
56200 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
56201 +EXPORT_SYMBOL(gr_acl_is_enabled);
56202 +#endif
56203 +EXPORT_SYMBOL(gr_learn_resource);
56204 +EXPORT_SYMBOL(gr_set_kernel_label);
56205 +#ifdef CONFIG_SECURITY
56206 +EXPORT_SYMBOL(gr_check_user_change);
56207 +EXPORT_SYMBOL(gr_check_group_change);
56208 +#endif
56209 +
56210 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
56211 new file mode 100644
56212 index 0000000..34fefda
56213 --- /dev/null
56214 +++ b/grsecurity/gracl_alloc.c
56215 @@ -0,0 +1,105 @@
56216 +#include <linux/kernel.h>
56217 +#include <linux/mm.h>
56218 +#include <linux/slab.h>
56219 +#include <linux/vmalloc.h>
56220 +#include <linux/gracl.h>
56221 +#include <linux/grsecurity.h>
56222 +
56223 +static unsigned long alloc_stack_next = 1;
56224 +static unsigned long alloc_stack_size = 1;
56225 +static void **alloc_stack;
56226 +
56227 +static __inline__ int
56228 +alloc_pop(void)
56229 +{
56230 + if (alloc_stack_next == 1)
56231 + return 0;
56232 +
56233 + kfree(alloc_stack[alloc_stack_next - 2]);
56234 +
56235 + alloc_stack_next--;
56236 +
56237 + return 1;
56238 +}
56239 +
56240 +static __inline__ int
56241 +alloc_push(void *buf)
56242 +{
56243 + if (alloc_stack_next >= alloc_stack_size)
56244 + return 1;
56245 +
56246 + alloc_stack[alloc_stack_next - 1] = buf;
56247 +
56248 + alloc_stack_next++;
56249 +
56250 + return 0;
56251 +}
56252 +
56253 +void *
56254 +acl_alloc(unsigned long len)
56255 +{
56256 + void *ret = NULL;
56257 +
56258 + if (!len || len > PAGE_SIZE)
56259 + goto out;
56260 +
56261 + ret = kmalloc(len, GFP_KERNEL);
56262 +
56263 + if (ret) {
56264 + if (alloc_push(ret)) {
56265 + kfree(ret);
56266 + ret = NULL;
56267 + }
56268 + }
56269 +
56270 +out:
56271 + return ret;
56272 +}
56273 +
56274 +void *
56275 +acl_alloc_num(unsigned long num, unsigned long len)
56276 +{
56277 + if (!len || (num > (PAGE_SIZE / len)))
56278 + return NULL;
56279 +
56280 + return acl_alloc(num * len);
56281 +}
56282 +
56283 +void
56284 +acl_free_all(void)
56285 +{
56286 + if (gr_acl_is_enabled() || !alloc_stack)
56287 + return;
56288 +
56289 + while (alloc_pop()) ;
56290 +
56291 + if (alloc_stack) {
56292 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
56293 + kfree(alloc_stack);
56294 + else
56295 + vfree(alloc_stack);
56296 + }
56297 +
56298 + alloc_stack = NULL;
56299 + alloc_stack_size = 1;
56300 + alloc_stack_next = 1;
56301 +
56302 + return;
56303 +}
56304 +
56305 +int
56306 +acl_alloc_stack_init(unsigned long size)
56307 +{
56308 + if ((size * sizeof (void *)) <= PAGE_SIZE)
56309 + alloc_stack =
56310 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
56311 + else
56312 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
56313 +
56314 + alloc_stack_size = size;
56315 +
56316 + if (!alloc_stack)
56317 + return 0;
56318 + else
56319 + return 1;
56320 +}
56321 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
56322 new file mode 100644
56323 index 0000000..6d21049
56324 --- /dev/null
56325 +++ b/grsecurity/gracl_cap.c
56326 @@ -0,0 +1,110 @@
56327 +#include <linux/kernel.h>
56328 +#include <linux/module.h>
56329 +#include <linux/sched.h>
56330 +#include <linux/gracl.h>
56331 +#include <linux/grsecurity.h>
56332 +#include <linux/grinternal.h>
56333 +
56334 +extern const char *captab_log[];
56335 +extern int captab_log_entries;
56336 +
56337 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56338 +{
56339 + struct acl_subject_label *curracl;
56340 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56341 + kernel_cap_t cap_audit = __cap_empty_set;
56342 +
56343 + if (!gr_acl_is_enabled())
56344 + return 1;
56345 +
56346 + curracl = task->acl;
56347 +
56348 + cap_drop = curracl->cap_lower;
56349 + cap_mask = curracl->cap_mask;
56350 + cap_audit = curracl->cap_invert_audit;
56351 +
56352 + while ((curracl = curracl->parent_subject)) {
56353 + /* if the cap isn't specified in the current computed mask but is specified in the
56354 + current level subject, and is lowered in the current level subject, then add
56355 + it to the set of dropped capabilities
56356 + otherwise, add the current level subject's mask to the current computed mask
56357 + */
56358 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56359 + cap_raise(cap_mask, cap);
56360 + if (cap_raised(curracl->cap_lower, cap))
56361 + cap_raise(cap_drop, cap);
56362 + if (cap_raised(curracl->cap_invert_audit, cap))
56363 + cap_raise(cap_audit, cap);
56364 + }
56365 + }
56366 +
56367 + if (!cap_raised(cap_drop, cap)) {
56368 + if (cap_raised(cap_audit, cap))
56369 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
56370 + return 1;
56371 + }
56372 +
56373 + curracl = task->acl;
56374 +
56375 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
56376 + && cap_raised(cred->cap_effective, cap)) {
56377 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56378 + task->role->roletype, cred->uid,
56379 + cred->gid, task->exec_file ?
56380 + gr_to_filename(task->exec_file->f_path.dentry,
56381 + task->exec_file->f_path.mnt) : curracl->filename,
56382 + curracl->filename, 0UL,
56383 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
56384 + return 1;
56385 + }
56386 +
56387 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
56388 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
56389 +
56390 + return 0;
56391 +}
56392 +
56393 +int
56394 +gr_acl_is_capable(const int cap)
56395 +{
56396 + return gr_task_acl_is_capable(current, current_cred(), cap);
56397 +}
56398 +
56399 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
56400 +{
56401 + struct acl_subject_label *curracl;
56402 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56403 +
56404 + if (!gr_acl_is_enabled())
56405 + return 1;
56406 +
56407 + curracl = task->acl;
56408 +
56409 + cap_drop = curracl->cap_lower;
56410 + cap_mask = curracl->cap_mask;
56411 +
56412 + while ((curracl = curracl->parent_subject)) {
56413 + /* if the cap isn't specified in the current computed mask but is specified in the
56414 + current level subject, and is lowered in the current level subject, then add
56415 + it to the set of dropped capabilities
56416 + otherwise, add the current level subject's mask to the current computed mask
56417 + */
56418 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56419 + cap_raise(cap_mask, cap);
56420 + if (cap_raised(curracl->cap_lower, cap))
56421 + cap_raise(cap_drop, cap);
56422 + }
56423 + }
56424 +
56425 + if (!cap_raised(cap_drop, cap))
56426 + return 1;
56427 +
56428 + return 0;
56429 +}
56430 +
56431 +int
56432 +gr_acl_is_capable_nolog(const int cap)
56433 +{
56434 + return gr_task_acl_is_capable_nolog(current, cap);
56435 +}
56436 +
56437 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
56438 new file mode 100644
56439 index 0000000..d28e241
56440 --- /dev/null
56441 +++ b/grsecurity/gracl_fs.c
56442 @@ -0,0 +1,437 @@
56443 +#include <linux/kernel.h>
56444 +#include <linux/sched.h>
56445 +#include <linux/types.h>
56446 +#include <linux/fs.h>
56447 +#include <linux/file.h>
56448 +#include <linux/stat.h>
56449 +#include <linux/grsecurity.h>
56450 +#include <linux/grinternal.h>
56451 +#include <linux/gracl.h>
56452 +
56453 +umode_t
56454 +gr_acl_umask(void)
56455 +{
56456 + if (unlikely(!gr_acl_is_enabled()))
56457 + return 0;
56458 +
56459 + return current->role->umask;
56460 +}
56461 +
56462 +__u32
56463 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56464 + const struct vfsmount * mnt)
56465 +{
56466 + __u32 mode;
56467 +
56468 + if (unlikely(!dentry->d_inode))
56469 + return GR_FIND;
56470 +
56471 + mode =
56472 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56473 +
56474 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56475 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56476 + return mode;
56477 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56478 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56479 + return 0;
56480 + } else if (unlikely(!(mode & GR_FIND)))
56481 + return 0;
56482 +
56483 + return GR_FIND;
56484 +}
56485 +
56486 +__u32
56487 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56488 + int acc_mode)
56489 +{
56490 + __u32 reqmode = GR_FIND;
56491 + __u32 mode;
56492 +
56493 + if (unlikely(!dentry->d_inode))
56494 + return reqmode;
56495 +
56496 + if (acc_mode & MAY_APPEND)
56497 + reqmode |= GR_APPEND;
56498 + else if (acc_mode & MAY_WRITE)
56499 + reqmode |= GR_WRITE;
56500 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56501 + reqmode |= GR_READ;
56502 +
56503 + mode =
56504 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56505 + mnt);
56506 +
56507 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56508 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56509 + reqmode & GR_READ ? " reading" : "",
56510 + reqmode & GR_WRITE ? " writing" : reqmode &
56511 + GR_APPEND ? " appending" : "");
56512 + return reqmode;
56513 + } else
56514 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56515 + {
56516 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56517 + reqmode & GR_READ ? " reading" : "",
56518 + reqmode & GR_WRITE ? " writing" : reqmode &
56519 + GR_APPEND ? " appending" : "");
56520 + return 0;
56521 + } else if (unlikely((mode & reqmode) != reqmode))
56522 + return 0;
56523 +
56524 + return reqmode;
56525 +}
56526 +
56527 +__u32
56528 +gr_acl_handle_creat(const struct dentry * dentry,
56529 + const struct dentry * p_dentry,
56530 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56531 + const int imode)
56532 +{
56533 + __u32 reqmode = GR_WRITE | GR_CREATE;
56534 + __u32 mode;
56535 +
56536 + if (acc_mode & MAY_APPEND)
56537 + reqmode |= GR_APPEND;
56538 + // if a directory was required or the directory already exists, then
56539 + // don't count this open as a read
56540 + if ((acc_mode & MAY_READ) &&
56541 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56542 + reqmode |= GR_READ;
56543 + if ((open_flags & O_CREAT) &&
56544 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56545 + reqmode |= GR_SETID;
56546 +
56547 + mode =
56548 + gr_check_create(dentry, p_dentry, p_mnt,
56549 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56550 +
56551 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56552 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56553 + reqmode & GR_READ ? " reading" : "",
56554 + reqmode & GR_WRITE ? " writing" : reqmode &
56555 + GR_APPEND ? " appending" : "");
56556 + return reqmode;
56557 + } else
56558 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56559 + {
56560 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56561 + reqmode & GR_READ ? " reading" : "",
56562 + reqmode & GR_WRITE ? " writing" : reqmode &
56563 + GR_APPEND ? " appending" : "");
56564 + return 0;
56565 + } else if (unlikely((mode & reqmode) != reqmode))
56566 + return 0;
56567 +
56568 + return reqmode;
56569 +}
56570 +
56571 +__u32
56572 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56573 + const int fmode)
56574 +{
56575 + __u32 mode, reqmode = GR_FIND;
56576 +
56577 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56578 + reqmode |= GR_EXEC;
56579 + if (fmode & S_IWOTH)
56580 + reqmode |= GR_WRITE;
56581 + if (fmode & S_IROTH)
56582 + reqmode |= GR_READ;
56583 +
56584 + mode =
56585 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56586 + mnt);
56587 +
56588 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56589 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56590 + reqmode & GR_READ ? " reading" : "",
56591 + reqmode & GR_WRITE ? " writing" : "",
56592 + reqmode & GR_EXEC ? " executing" : "");
56593 + return reqmode;
56594 + } else
56595 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56596 + {
56597 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56598 + reqmode & GR_READ ? " reading" : "",
56599 + reqmode & GR_WRITE ? " writing" : "",
56600 + reqmode & GR_EXEC ? " executing" : "");
56601 + return 0;
56602 + } else if (unlikely((mode & reqmode) != reqmode))
56603 + return 0;
56604 +
56605 + return reqmode;
56606 +}
56607 +
56608 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56609 +{
56610 + __u32 mode;
56611 +
56612 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56613 +
56614 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56615 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56616 + return mode;
56617 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56618 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56619 + return 0;
56620 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56621 + return 0;
56622 +
56623 + return (reqmode);
56624 +}
56625 +
56626 +__u32
56627 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56628 +{
56629 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56630 +}
56631 +
56632 +__u32
56633 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56634 +{
56635 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56636 +}
56637 +
56638 +__u32
56639 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56640 +{
56641 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56642 +}
56643 +
56644 +__u32
56645 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56646 +{
56647 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56648 +}
56649 +
56650 +__u32
56651 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56652 + umode_t *modeptr)
56653 +{
56654 + umode_t mode;
56655 +
56656 + *modeptr &= ~gr_acl_umask();
56657 + mode = *modeptr;
56658 +
56659 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56660 + return 1;
56661 +
56662 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56663 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56664 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56665 + GR_CHMOD_ACL_MSG);
56666 + } else {
56667 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56668 + }
56669 +}
56670 +
56671 +__u32
56672 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56673 +{
56674 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56675 +}
56676 +
56677 +__u32
56678 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56679 +{
56680 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56681 +}
56682 +
56683 +__u32
56684 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56685 +{
56686 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56687 +}
56688 +
56689 +__u32
56690 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56691 +{
56692 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56693 + GR_UNIXCONNECT_ACL_MSG);
56694 +}
56695 +
56696 +/* hardlinks require at minimum create and link permission,
56697 + any additional privilege required is based on the
56698 + privilege of the file being linked to
56699 +*/
56700 +__u32
56701 +gr_acl_handle_link(const struct dentry * new_dentry,
56702 + const struct dentry * parent_dentry,
56703 + const struct vfsmount * parent_mnt,
56704 + const struct dentry * old_dentry,
56705 + const struct vfsmount * old_mnt, const char *to)
56706 +{
56707 + __u32 mode;
56708 + __u32 needmode = GR_CREATE | GR_LINK;
56709 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56710 +
56711 + mode =
56712 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56713 + old_mnt);
56714 +
56715 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56716 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56717 + return mode;
56718 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56719 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56720 + return 0;
56721 + } else if (unlikely((mode & needmode) != needmode))
56722 + return 0;
56723 +
56724 + return 1;
56725 +}
56726 +
56727 +__u32
56728 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56729 + const struct dentry * parent_dentry,
56730 + const struct vfsmount * parent_mnt, const char *from)
56731 +{
56732 + __u32 needmode = GR_WRITE | GR_CREATE;
56733 + __u32 mode;
56734 +
56735 + mode =
56736 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56737 + GR_CREATE | GR_AUDIT_CREATE |
56738 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56739 +
56740 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56741 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56742 + return mode;
56743 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56744 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56745 + return 0;
56746 + } else if (unlikely((mode & needmode) != needmode))
56747 + return 0;
56748 +
56749 + return (GR_WRITE | GR_CREATE);
56750 +}
56751 +
56752 +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)
56753 +{
56754 + __u32 mode;
56755 +
56756 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56757 +
56758 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56759 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56760 + return mode;
56761 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56762 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56763 + return 0;
56764 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56765 + return 0;
56766 +
56767 + return (reqmode);
56768 +}
56769 +
56770 +__u32
56771 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56772 + const struct dentry * parent_dentry,
56773 + const struct vfsmount * parent_mnt,
56774 + const int mode)
56775 +{
56776 + __u32 reqmode = GR_WRITE | GR_CREATE;
56777 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56778 + reqmode |= GR_SETID;
56779 +
56780 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56781 + reqmode, GR_MKNOD_ACL_MSG);
56782 +}
56783 +
56784 +__u32
56785 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56786 + const struct dentry *parent_dentry,
56787 + const struct vfsmount *parent_mnt)
56788 +{
56789 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56790 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56791 +}
56792 +
56793 +#define RENAME_CHECK_SUCCESS(old, new) \
56794 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56795 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56796 +
56797 +int
56798 +gr_acl_handle_rename(struct dentry *new_dentry,
56799 + struct dentry *parent_dentry,
56800 + const struct vfsmount *parent_mnt,
56801 + struct dentry *old_dentry,
56802 + struct inode *old_parent_inode,
56803 + struct vfsmount *old_mnt, const char *newname)
56804 +{
56805 + __u32 comp1, comp2;
56806 + int error = 0;
56807 +
56808 + if (unlikely(!gr_acl_is_enabled()))
56809 + return 0;
56810 +
56811 + if (!new_dentry->d_inode) {
56812 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56813 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56814 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56815 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56816 + GR_DELETE | GR_AUDIT_DELETE |
56817 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56818 + GR_SUPPRESS, old_mnt);
56819 + } else {
56820 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56821 + GR_CREATE | GR_DELETE |
56822 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56823 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56824 + GR_SUPPRESS, parent_mnt);
56825 + comp2 =
56826 + gr_search_file(old_dentry,
56827 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56828 + GR_DELETE | GR_AUDIT_DELETE |
56829 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56830 + }
56831 +
56832 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56833 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56834 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56835 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56836 + && !(comp2 & GR_SUPPRESS)) {
56837 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56838 + error = -EACCES;
56839 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56840 + error = -EACCES;
56841 +
56842 + return error;
56843 +}
56844 +
56845 +void
56846 +gr_acl_handle_exit(void)
56847 +{
56848 + u16 id;
56849 + char *rolename;
56850 + struct file *exec_file;
56851 +
56852 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56853 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56854 + id = current->acl_role_id;
56855 + rolename = current->role->rolename;
56856 + gr_set_acls(1);
56857 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56858 + }
56859 +
56860 + write_lock(&grsec_exec_file_lock);
56861 + exec_file = current->exec_file;
56862 + current->exec_file = NULL;
56863 + write_unlock(&grsec_exec_file_lock);
56864 +
56865 + if (exec_file)
56866 + fput(exec_file);
56867 +}
56868 +
56869 +int
56870 +gr_acl_handle_procpidmem(const struct task_struct *task)
56871 +{
56872 + if (unlikely(!gr_acl_is_enabled()))
56873 + return 0;
56874 +
56875 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56876 + return -EACCES;
56877 +
56878 + return 0;
56879 +}
56880 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56881 new file mode 100644
56882 index 0000000..58800a7
56883 --- /dev/null
56884 +++ b/grsecurity/gracl_ip.c
56885 @@ -0,0 +1,384 @@
56886 +#include <linux/kernel.h>
56887 +#include <asm/uaccess.h>
56888 +#include <asm/errno.h>
56889 +#include <net/sock.h>
56890 +#include <linux/file.h>
56891 +#include <linux/fs.h>
56892 +#include <linux/net.h>
56893 +#include <linux/in.h>
56894 +#include <linux/skbuff.h>
56895 +#include <linux/ip.h>
56896 +#include <linux/udp.h>
56897 +#include <linux/types.h>
56898 +#include <linux/sched.h>
56899 +#include <linux/netdevice.h>
56900 +#include <linux/inetdevice.h>
56901 +#include <linux/gracl.h>
56902 +#include <linux/grsecurity.h>
56903 +#include <linux/grinternal.h>
56904 +
56905 +#define GR_BIND 0x01
56906 +#define GR_CONNECT 0x02
56907 +#define GR_INVERT 0x04
56908 +#define GR_BINDOVERRIDE 0x08
56909 +#define GR_CONNECTOVERRIDE 0x10
56910 +#define GR_SOCK_FAMILY 0x20
56911 +
56912 +static const char * gr_protocols[IPPROTO_MAX] = {
56913 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56914 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56915 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56916 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56917 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56918 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56919 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56920 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56921 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56922 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56923 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56924 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56925 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56926 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56927 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56928 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56929 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56930 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56931 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56932 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56933 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56934 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56935 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56936 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56937 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56938 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56939 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56940 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56941 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56942 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56943 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56944 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56945 + };
56946 +
56947 +static const char * gr_socktypes[SOCK_MAX] = {
56948 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56949 + "unknown:7", "unknown:8", "unknown:9", "packet"
56950 + };
56951 +
56952 +static const char * gr_sockfamilies[AF_MAX+1] = {
56953 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56954 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56955 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56956 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56957 + };
56958 +
56959 +const char *
56960 +gr_proto_to_name(unsigned char proto)
56961 +{
56962 + return gr_protocols[proto];
56963 +}
56964 +
56965 +const char *
56966 +gr_socktype_to_name(unsigned char type)
56967 +{
56968 + return gr_socktypes[type];
56969 +}
56970 +
56971 +const char *
56972 +gr_sockfamily_to_name(unsigned char family)
56973 +{
56974 + return gr_sockfamilies[family];
56975 +}
56976 +
56977 +int
56978 +gr_search_socket(const int domain, const int type, const int protocol)
56979 +{
56980 + struct acl_subject_label *curr;
56981 + const struct cred *cred = current_cred();
56982 +
56983 + if (unlikely(!gr_acl_is_enabled()))
56984 + goto exit;
56985 +
56986 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56987 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56988 + goto exit; // let the kernel handle it
56989 +
56990 + curr = current->acl;
56991 +
56992 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56993 + /* the family is allowed, if this is PF_INET allow it only if
56994 + the extra sock type/protocol checks pass */
56995 + if (domain == PF_INET)
56996 + goto inet_check;
56997 + goto exit;
56998 + } else {
56999 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57000 + __u32 fakeip = 0;
57001 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57002 + current->role->roletype, cred->uid,
57003 + cred->gid, current->exec_file ?
57004 + gr_to_filename(current->exec_file->f_path.dentry,
57005 + current->exec_file->f_path.mnt) :
57006 + curr->filename, curr->filename,
57007 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
57008 + &current->signal->saved_ip);
57009 + goto exit;
57010 + }
57011 + goto exit_fail;
57012 + }
57013 +
57014 +inet_check:
57015 + /* the rest of this checking is for IPv4 only */
57016 + if (!curr->ips)
57017 + goto exit;
57018 +
57019 + if ((curr->ip_type & (1 << type)) &&
57020 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
57021 + goto exit;
57022 +
57023 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57024 + /* we don't place acls on raw sockets , and sometimes
57025 + dgram/ip sockets are opened for ioctl and not
57026 + bind/connect, so we'll fake a bind learn log */
57027 + if (type == SOCK_RAW || type == SOCK_PACKET) {
57028 + __u32 fakeip = 0;
57029 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57030 + current->role->roletype, cred->uid,
57031 + cred->gid, current->exec_file ?
57032 + gr_to_filename(current->exec_file->f_path.dentry,
57033 + current->exec_file->f_path.mnt) :
57034 + curr->filename, curr->filename,
57035 + &fakeip, 0, type,
57036 + protocol, GR_CONNECT, &current->signal->saved_ip);
57037 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
57038 + __u32 fakeip = 0;
57039 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57040 + current->role->roletype, cred->uid,
57041 + cred->gid, current->exec_file ?
57042 + gr_to_filename(current->exec_file->f_path.dentry,
57043 + current->exec_file->f_path.mnt) :
57044 + curr->filename, curr->filename,
57045 + &fakeip, 0, type,
57046 + protocol, GR_BIND, &current->signal->saved_ip);
57047 + }
57048 + /* we'll log when they use connect or bind */
57049 + goto exit;
57050 + }
57051 +
57052 +exit_fail:
57053 + if (domain == PF_INET)
57054 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
57055 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
57056 + else
57057 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
57058 + gr_socktype_to_name(type), protocol);
57059 +
57060 + return 0;
57061 +exit:
57062 + return 1;
57063 +}
57064 +
57065 +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)
57066 +{
57067 + if ((ip->mode & mode) &&
57068 + (ip_port >= ip->low) &&
57069 + (ip_port <= ip->high) &&
57070 + ((ntohl(ip_addr) & our_netmask) ==
57071 + (ntohl(our_addr) & our_netmask))
57072 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
57073 + && (ip->type & (1 << type))) {
57074 + if (ip->mode & GR_INVERT)
57075 + return 2; // specifically denied
57076 + else
57077 + return 1; // allowed
57078 + }
57079 +
57080 + return 0; // not specifically allowed, may continue parsing
57081 +}
57082 +
57083 +static int
57084 +gr_search_connectbind(const int full_mode, struct sock *sk,
57085 + struct sockaddr_in *addr, const int type)
57086 +{
57087 + char iface[IFNAMSIZ] = {0};
57088 + struct acl_subject_label *curr;
57089 + struct acl_ip_label *ip;
57090 + struct inet_sock *isk;
57091 + struct net_device *dev;
57092 + struct in_device *idev;
57093 + unsigned long i;
57094 + int ret;
57095 + int mode = full_mode & (GR_BIND | GR_CONNECT);
57096 + __u32 ip_addr = 0;
57097 + __u32 our_addr;
57098 + __u32 our_netmask;
57099 + char *p;
57100 + __u16 ip_port = 0;
57101 + const struct cred *cred = current_cred();
57102 +
57103 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
57104 + return 0;
57105 +
57106 + curr = current->acl;
57107 + isk = inet_sk(sk);
57108 +
57109 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
57110 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
57111 + addr->sin_addr.s_addr = curr->inaddr_any_override;
57112 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
57113 + struct sockaddr_in saddr;
57114 + int err;
57115 +
57116 + saddr.sin_family = AF_INET;
57117 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
57118 + saddr.sin_port = isk->inet_sport;
57119 +
57120 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
57121 + if (err)
57122 + return err;
57123 +
57124 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
57125 + if (err)
57126 + return err;
57127 + }
57128 +
57129 + if (!curr->ips)
57130 + return 0;
57131 +
57132 + ip_addr = addr->sin_addr.s_addr;
57133 + ip_port = ntohs(addr->sin_port);
57134 +
57135 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57136 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57137 + current->role->roletype, cred->uid,
57138 + cred->gid, current->exec_file ?
57139 + gr_to_filename(current->exec_file->f_path.dentry,
57140 + current->exec_file->f_path.mnt) :
57141 + curr->filename, curr->filename,
57142 + &ip_addr, ip_port, type,
57143 + sk->sk_protocol, mode, &current->signal->saved_ip);
57144 + return 0;
57145 + }
57146 +
57147 + for (i = 0; i < curr->ip_num; i++) {
57148 + ip = *(curr->ips + i);
57149 + if (ip->iface != NULL) {
57150 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
57151 + p = strchr(iface, ':');
57152 + if (p != NULL)
57153 + *p = '\0';
57154 + dev = dev_get_by_name(sock_net(sk), iface);
57155 + if (dev == NULL)
57156 + continue;
57157 + idev = in_dev_get(dev);
57158 + if (idev == NULL) {
57159 + dev_put(dev);
57160 + continue;
57161 + }
57162 + rcu_read_lock();
57163 + for_ifa(idev) {
57164 + if (!strcmp(ip->iface, ifa->ifa_label)) {
57165 + our_addr = ifa->ifa_address;
57166 + our_netmask = 0xffffffff;
57167 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
57168 + if (ret == 1) {
57169 + rcu_read_unlock();
57170 + in_dev_put(idev);
57171 + dev_put(dev);
57172 + return 0;
57173 + } else if (ret == 2) {
57174 + rcu_read_unlock();
57175 + in_dev_put(idev);
57176 + dev_put(dev);
57177 + goto denied;
57178 + }
57179 + }
57180 + } endfor_ifa(idev);
57181 + rcu_read_unlock();
57182 + in_dev_put(idev);
57183 + dev_put(dev);
57184 + } else {
57185 + our_addr = ip->addr;
57186 + our_netmask = ip->netmask;
57187 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
57188 + if (ret == 1)
57189 + return 0;
57190 + else if (ret == 2)
57191 + goto denied;
57192 + }
57193 + }
57194 +
57195 +denied:
57196 + if (mode == GR_BIND)
57197 + 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));
57198 + else if (mode == GR_CONNECT)
57199 + 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));
57200 +
57201 + return -EACCES;
57202 +}
57203 +
57204 +int
57205 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
57206 +{
57207 + /* always allow disconnection of dgram sockets with connect */
57208 + if (addr->sin_family == AF_UNSPEC)
57209 + return 0;
57210 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
57211 +}
57212 +
57213 +int
57214 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
57215 +{
57216 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
57217 +}
57218 +
57219 +int gr_search_listen(struct socket *sock)
57220 +{
57221 + struct sock *sk = sock->sk;
57222 + struct sockaddr_in addr;
57223 +
57224 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
57225 + addr.sin_port = inet_sk(sk)->inet_sport;
57226 +
57227 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57228 +}
57229 +
57230 +int gr_search_accept(struct socket *sock)
57231 +{
57232 + struct sock *sk = sock->sk;
57233 + struct sockaddr_in addr;
57234 +
57235 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
57236 + addr.sin_port = inet_sk(sk)->inet_sport;
57237 +
57238 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57239 +}
57240 +
57241 +int
57242 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
57243 +{
57244 + if (addr)
57245 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
57246 + else {
57247 + struct sockaddr_in sin;
57248 + const struct inet_sock *inet = inet_sk(sk);
57249 +
57250 + sin.sin_addr.s_addr = inet->inet_daddr;
57251 + sin.sin_port = inet->inet_dport;
57252 +
57253 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57254 + }
57255 +}
57256 +
57257 +int
57258 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
57259 +{
57260 + struct sockaddr_in sin;
57261 +
57262 + if (unlikely(skb->len < sizeof (struct udphdr)))
57263 + return 0; // skip this packet
57264 +
57265 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
57266 + sin.sin_port = udp_hdr(skb)->source;
57267 +
57268 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57269 +}
57270 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
57271 new file mode 100644
57272 index 0000000..25f54ef
57273 --- /dev/null
57274 +++ b/grsecurity/gracl_learn.c
57275 @@ -0,0 +1,207 @@
57276 +#include <linux/kernel.h>
57277 +#include <linux/mm.h>
57278 +#include <linux/sched.h>
57279 +#include <linux/poll.h>
57280 +#include <linux/string.h>
57281 +#include <linux/file.h>
57282 +#include <linux/types.h>
57283 +#include <linux/vmalloc.h>
57284 +#include <linux/grinternal.h>
57285 +
57286 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
57287 + size_t count, loff_t *ppos);
57288 +extern int gr_acl_is_enabled(void);
57289 +
57290 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
57291 +static int gr_learn_attached;
57292 +
57293 +/* use a 512k buffer */
57294 +#define LEARN_BUFFER_SIZE (512 * 1024)
57295 +
57296 +static DEFINE_SPINLOCK(gr_learn_lock);
57297 +static DEFINE_MUTEX(gr_learn_user_mutex);
57298 +
57299 +/* we need to maintain two buffers, so that the kernel context of grlearn
57300 + uses a semaphore around the userspace copying, and the other kernel contexts
57301 + use a spinlock when copying into the buffer, since they cannot sleep
57302 +*/
57303 +static char *learn_buffer;
57304 +static char *learn_buffer_user;
57305 +static int learn_buffer_len;
57306 +static int learn_buffer_user_len;
57307 +
57308 +static ssize_t
57309 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
57310 +{
57311 + DECLARE_WAITQUEUE(wait, current);
57312 + ssize_t retval = 0;
57313 +
57314 + add_wait_queue(&learn_wait, &wait);
57315 + set_current_state(TASK_INTERRUPTIBLE);
57316 + do {
57317 + mutex_lock(&gr_learn_user_mutex);
57318 + spin_lock(&gr_learn_lock);
57319 + if (learn_buffer_len)
57320 + break;
57321 + spin_unlock(&gr_learn_lock);
57322 + mutex_unlock(&gr_learn_user_mutex);
57323 + if (file->f_flags & O_NONBLOCK) {
57324 + retval = -EAGAIN;
57325 + goto out;
57326 + }
57327 + if (signal_pending(current)) {
57328 + retval = -ERESTARTSYS;
57329 + goto out;
57330 + }
57331 +
57332 + schedule();
57333 + } while (1);
57334 +
57335 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
57336 + learn_buffer_user_len = learn_buffer_len;
57337 + retval = learn_buffer_len;
57338 + learn_buffer_len = 0;
57339 +
57340 + spin_unlock(&gr_learn_lock);
57341 +
57342 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
57343 + retval = -EFAULT;
57344 +
57345 + mutex_unlock(&gr_learn_user_mutex);
57346 +out:
57347 + set_current_state(TASK_RUNNING);
57348 + remove_wait_queue(&learn_wait, &wait);
57349 + return retval;
57350 +}
57351 +
57352 +static unsigned int
57353 +poll_learn(struct file * file, poll_table * wait)
57354 +{
57355 + poll_wait(file, &learn_wait, wait);
57356 +
57357 + if (learn_buffer_len)
57358 + return (POLLIN | POLLRDNORM);
57359 +
57360 + return 0;
57361 +}
57362 +
57363 +void
57364 +gr_clear_learn_entries(void)
57365 +{
57366 + char *tmp;
57367 +
57368 + mutex_lock(&gr_learn_user_mutex);
57369 + spin_lock(&gr_learn_lock);
57370 + tmp = learn_buffer;
57371 + learn_buffer = NULL;
57372 + spin_unlock(&gr_learn_lock);
57373 + if (tmp)
57374 + vfree(tmp);
57375 + if (learn_buffer_user != NULL) {
57376 + vfree(learn_buffer_user);
57377 + learn_buffer_user = NULL;
57378 + }
57379 + learn_buffer_len = 0;
57380 + mutex_unlock(&gr_learn_user_mutex);
57381 +
57382 + return;
57383 +}
57384 +
57385 +void
57386 +gr_add_learn_entry(const char *fmt, ...)
57387 +{
57388 + va_list args;
57389 + unsigned int len;
57390 +
57391 + if (!gr_learn_attached)
57392 + return;
57393 +
57394 + spin_lock(&gr_learn_lock);
57395 +
57396 + /* leave a gap at the end so we know when it's "full" but don't have to
57397 + compute the exact length of the string we're trying to append
57398 + */
57399 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
57400 + spin_unlock(&gr_learn_lock);
57401 + wake_up_interruptible(&learn_wait);
57402 + return;
57403 + }
57404 + if (learn_buffer == NULL) {
57405 + spin_unlock(&gr_learn_lock);
57406 + return;
57407 + }
57408 +
57409 + va_start(args, fmt);
57410 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
57411 + va_end(args);
57412 +
57413 + learn_buffer_len += len + 1;
57414 +
57415 + spin_unlock(&gr_learn_lock);
57416 + wake_up_interruptible(&learn_wait);
57417 +
57418 + return;
57419 +}
57420 +
57421 +static int
57422 +open_learn(struct inode *inode, struct file *file)
57423 +{
57424 + if (file->f_mode & FMODE_READ && gr_learn_attached)
57425 + return -EBUSY;
57426 + if (file->f_mode & FMODE_READ) {
57427 + int retval = 0;
57428 + mutex_lock(&gr_learn_user_mutex);
57429 + if (learn_buffer == NULL)
57430 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
57431 + if (learn_buffer_user == NULL)
57432 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
57433 + if (learn_buffer == NULL) {
57434 + retval = -ENOMEM;
57435 + goto out_error;
57436 + }
57437 + if (learn_buffer_user == NULL) {
57438 + retval = -ENOMEM;
57439 + goto out_error;
57440 + }
57441 + learn_buffer_len = 0;
57442 + learn_buffer_user_len = 0;
57443 + gr_learn_attached = 1;
57444 +out_error:
57445 + mutex_unlock(&gr_learn_user_mutex);
57446 + return retval;
57447 + }
57448 + return 0;
57449 +}
57450 +
57451 +static int
57452 +close_learn(struct inode *inode, struct file *file)
57453 +{
57454 + if (file->f_mode & FMODE_READ) {
57455 + char *tmp = NULL;
57456 + mutex_lock(&gr_learn_user_mutex);
57457 + spin_lock(&gr_learn_lock);
57458 + tmp = learn_buffer;
57459 + learn_buffer = NULL;
57460 + spin_unlock(&gr_learn_lock);
57461 + if (tmp)
57462 + vfree(tmp);
57463 + if (learn_buffer_user != NULL) {
57464 + vfree(learn_buffer_user);
57465 + learn_buffer_user = NULL;
57466 + }
57467 + learn_buffer_len = 0;
57468 + learn_buffer_user_len = 0;
57469 + gr_learn_attached = 0;
57470 + mutex_unlock(&gr_learn_user_mutex);
57471 + }
57472 +
57473 + return 0;
57474 +}
57475 +
57476 +const struct file_operations grsec_fops = {
57477 + .read = read_learn,
57478 + .write = write_grsec_handler,
57479 + .open = open_learn,
57480 + .release = close_learn,
57481 + .poll = poll_learn,
57482 +};
57483 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
57484 new file mode 100644
57485 index 0000000..39645c9
57486 --- /dev/null
57487 +++ b/grsecurity/gracl_res.c
57488 @@ -0,0 +1,68 @@
57489 +#include <linux/kernel.h>
57490 +#include <linux/sched.h>
57491 +#include <linux/gracl.h>
57492 +#include <linux/grinternal.h>
57493 +
57494 +static const char *restab_log[] = {
57495 + [RLIMIT_CPU] = "RLIMIT_CPU",
57496 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57497 + [RLIMIT_DATA] = "RLIMIT_DATA",
57498 + [RLIMIT_STACK] = "RLIMIT_STACK",
57499 + [RLIMIT_CORE] = "RLIMIT_CORE",
57500 + [RLIMIT_RSS] = "RLIMIT_RSS",
57501 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
57502 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57503 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57504 + [RLIMIT_AS] = "RLIMIT_AS",
57505 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57506 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57507 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57508 + [RLIMIT_NICE] = "RLIMIT_NICE",
57509 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57510 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57511 + [GR_CRASH_RES] = "RLIMIT_CRASH"
57512 +};
57513 +
57514 +void
57515 +gr_log_resource(const struct task_struct *task,
57516 + const int res, const unsigned long wanted, const int gt)
57517 +{
57518 + const struct cred *cred;
57519 + unsigned long rlim;
57520 +
57521 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
57522 + return;
57523 +
57524 + // not yet supported resource
57525 + if (unlikely(!restab_log[res]))
57526 + return;
57527 +
57528 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57529 + rlim = task_rlimit_max(task, res);
57530 + else
57531 + rlim = task_rlimit(task, res);
57532 +
57533 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57534 + return;
57535 +
57536 + rcu_read_lock();
57537 + cred = __task_cred(task);
57538 +
57539 + if (res == RLIMIT_NPROC &&
57540 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57541 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57542 + goto out_rcu_unlock;
57543 + else if (res == RLIMIT_MEMLOCK &&
57544 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57545 + goto out_rcu_unlock;
57546 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57547 + goto out_rcu_unlock;
57548 + rcu_read_unlock();
57549 +
57550 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57551 +
57552 + return;
57553 +out_rcu_unlock:
57554 + rcu_read_unlock();
57555 + return;
57556 +}
57557 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57558 new file mode 100644
57559 index 0000000..25197e9
57560 --- /dev/null
57561 +++ b/grsecurity/gracl_segv.c
57562 @@ -0,0 +1,299 @@
57563 +#include <linux/kernel.h>
57564 +#include <linux/mm.h>
57565 +#include <asm/uaccess.h>
57566 +#include <asm/errno.h>
57567 +#include <asm/mman.h>
57568 +#include <net/sock.h>
57569 +#include <linux/file.h>
57570 +#include <linux/fs.h>
57571 +#include <linux/net.h>
57572 +#include <linux/in.h>
57573 +#include <linux/slab.h>
57574 +#include <linux/types.h>
57575 +#include <linux/sched.h>
57576 +#include <linux/timer.h>
57577 +#include <linux/gracl.h>
57578 +#include <linux/grsecurity.h>
57579 +#include <linux/grinternal.h>
57580 +
57581 +static struct crash_uid *uid_set;
57582 +static unsigned short uid_used;
57583 +static DEFINE_SPINLOCK(gr_uid_lock);
57584 +extern rwlock_t gr_inode_lock;
57585 +extern struct acl_subject_label *
57586 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57587 + struct acl_role_label *role);
57588 +
57589 +#ifdef CONFIG_BTRFS_FS
57590 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57591 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57592 +#endif
57593 +
57594 +static inline dev_t __get_dev(const struct dentry *dentry)
57595 +{
57596 +#ifdef CONFIG_BTRFS_FS
57597 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57598 + return get_btrfs_dev_from_inode(dentry->d_inode);
57599 + else
57600 +#endif
57601 + return dentry->d_inode->i_sb->s_dev;
57602 +}
57603 +
57604 +int
57605 +gr_init_uidset(void)
57606 +{
57607 + uid_set =
57608 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57609 + uid_used = 0;
57610 +
57611 + return uid_set ? 1 : 0;
57612 +}
57613 +
57614 +void
57615 +gr_free_uidset(void)
57616 +{
57617 + if (uid_set)
57618 + kfree(uid_set);
57619 +
57620 + return;
57621 +}
57622 +
57623 +int
57624 +gr_find_uid(const uid_t uid)
57625 +{
57626 + struct crash_uid *tmp = uid_set;
57627 + uid_t buid;
57628 + int low = 0, high = uid_used - 1, mid;
57629 +
57630 + while (high >= low) {
57631 + mid = (low + high) >> 1;
57632 + buid = tmp[mid].uid;
57633 + if (buid == uid)
57634 + return mid;
57635 + if (buid > uid)
57636 + high = mid - 1;
57637 + if (buid < uid)
57638 + low = mid + 1;
57639 + }
57640 +
57641 + return -1;
57642 +}
57643 +
57644 +static __inline__ void
57645 +gr_insertsort(void)
57646 +{
57647 + unsigned short i, j;
57648 + struct crash_uid index;
57649 +
57650 + for (i = 1; i < uid_used; i++) {
57651 + index = uid_set[i];
57652 + j = i;
57653 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57654 + uid_set[j] = uid_set[j - 1];
57655 + j--;
57656 + }
57657 + uid_set[j] = index;
57658 + }
57659 +
57660 + return;
57661 +}
57662 +
57663 +static __inline__ void
57664 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57665 +{
57666 + int loc;
57667 +
57668 + if (uid_used == GR_UIDTABLE_MAX)
57669 + return;
57670 +
57671 + loc = gr_find_uid(uid);
57672 +
57673 + if (loc >= 0) {
57674 + uid_set[loc].expires = expires;
57675 + return;
57676 + }
57677 +
57678 + uid_set[uid_used].uid = uid;
57679 + uid_set[uid_used].expires = expires;
57680 + uid_used++;
57681 +
57682 + gr_insertsort();
57683 +
57684 + return;
57685 +}
57686 +
57687 +void
57688 +gr_remove_uid(const unsigned short loc)
57689 +{
57690 + unsigned short i;
57691 +
57692 + for (i = loc + 1; i < uid_used; i++)
57693 + uid_set[i - 1] = uid_set[i];
57694 +
57695 + uid_used--;
57696 +
57697 + return;
57698 +}
57699 +
57700 +int
57701 +gr_check_crash_uid(const uid_t uid)
57702 +{
57703 + int loc;
57704 + int ret = 0;
57705 +
57706 + if (unlikely(!gr_acl_is_enabled()))
57707 + return 0;
57708 +
57709 + spin_lock(&gr_uid_lock);
57710 + loc = gr_find_uid(uid);
57711 +
57712 + if (loc < 0)
57713 + goto out_unlock;
57714 +
57715 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57716 + gr_remove_uid(loc);
57717 + else
57718 + ret = 1;
57719 +
57720 +out_unlock:
57721 + spin_unlock(&gr_uid_lock);
57722 + return ret;
57723 +}
57724 +
57725 +static __inline__ int
57726 +proc_is_setxid(const struct cred *cred)
57727 +{
57728 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57729 + !uid_eq(cred->uid, cred->fsuid))
57730 + return 1;
57731 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57732 + !uid_eq(cred->gid, cred->fsgid))
57733 + return 1;
57734 +
57735 + return 0;
57736 +}
57737 +
57738 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57739 +
57740 +void
57741 +gr_handle_crash(struct task_struct *task, const int sig)
57742 +{
57743 + struct acl_subject_label *curr;
57744 + struct task_struct *tsk, *tsk2;
57745 + const struct cred *cred;
57746 + const struct cred *cred2;
57747 +
57748 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57749 + return;
57750 +
57751 + if (unlikely(!gr_acl_is_enabled()))
57752 + return;
57753 +
57754 + curr = task->acl;
57755 +
57756 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57757 + return;
57758 +
57759 + if (time_before_eq(curr->expires, get_seconds())) {
57760 + curr->expires = 0;
57761 + curr->crashes = 0;
57762 + }
57763 +
57764 + curr->crashes++;
57765 +
57766 + if (!curr->expires)
57767 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57768 +
57769 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57770 + time_after(curr->expires, get_seconds())) {
57771 + rcu_read_lock();
57772 + cred = __task_cred(task);
57773 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57774 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57775 + spin_lock(&gr_uid_lock);
57776 + gr_insert_uid(cred->uid, curr->expires);
57777 + spin_unlock(&gr_uid_lock);
57778 + curr->expires = 0;
57779 + curr->crashes = 0;
57780 + read_lock(&tasklist_lock);
57781 + do_each_thread(tsk2, tsk) {
57782 + cred2 = __task_cred(tsk);
57783 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57784 + gr_fake_force_sig(SIGKILL, tsk);
57785 + } while_each_thread(tsk2, tsk);
57786 + read_unlock(&tasklist_lock);
57787 + } else {
57788 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57789 + read_lock(&tasklist_lock);
57790 + read_lock(&grsec_exec_file_lock);
57791 + do_each_thread(tsk2, tsk) {
57792 + if (likely(tsk != task)) {
57793 + // if this thread has the same subject as the one that triggered
57794 + // RES_CRASH and it's the same binary, kill it
57795 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57796 + gr_fake_force_sig(SIGKILL, tsk);
57797 + }
57798 + } while_each_thread(tsk2, tsk);
57799 + read_unlock(&grsec_exec_file_lock);
57800 + read_unlock(&tasklist_lock);
57801 + }
57802 + rcu_read_unlock();
57803 + }
57804 +
57805 + return;
57806 +}
57807 +
57808 +int
57809 +gr_check_crash_exec(const struct file *filp)
57810 +{
57811 + struct acl_subject_label *curr;
57812 +
57813 + if (unlikely(!gr_acl_is_enabled()))
57814 + return 0;
57815 +
57816 + read_lock(&gr_inode_lock);
57817 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57818 + __get_dev(filp->f_path.dentry),
57819 + current->role);
57820 + read_unlock(&gr_inode_lock);
57821 +
57822 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57823 + (!curr->crashes && !curr->expires))
57824 + return 0;
57825 +
57826 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57827 + time_after(curr->expires, get_seconds()))
57828 + return 1;
57829 + else if (time_before_eq(curr->expires, get_seconds())) {
57830 + curr->crashes = 0;
57831 + curr->expires = 0;
57832 + }
57833 +
57834 + return 0;
57835 +}
57836 +
57837 +void
57838 +gr_handle_alertkill(struct task_struct *task)
57839 +{
57840 + struct acl_subject_label *curracl;
57841 + __u32 curr_ip;
57842 + struct task_struct *p, *p2;
57843 +
57844 + if (unlikely(!gr_acl_is_enabled()))
57845 + return;
57846 +
57847 + curracl = task->acl;
57848 + curr_ip = task->signal->curr_ip;
57849 +
57850 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57851 + read_lock(&tasklist_lock);
57852 + do_each_thread(p2, p) {
57853 + if (p->signal->curr_ip == curr_ip)
57854 + gr_fake_force_sig(SIGKILL, p);
57855 + } while_each_thread(p2, p);
57856 + read_unlock(&tasklist_lock);
57857 + } else if (curracl->mode & GR_KILLPROC)
57858 + gr_fake_force_sig(SIGKILL, task);
57859 +
57860 + return;
57861 +}
57862 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57863 new file mode 100644
57864 index 0000000..9d83a69
57865 --- /dev/null
57866 +++ b/grsecurity/gracl_shm.c
57867 @@ -0,0 +1,40 @@
57868 +#include <linux/kernel.h>
57869 +#include <linux/mm.h>
57870 +#include <linux/sched.h>
57871 +#include <linux/file.h>
57872 +#include <linux/ipc.h>
57873 +#include <linux/gracl.h>
57874 +#include <linux/grsecurity.h>
57875 +#include <linux/grinternal.h>
57876 +
57877 +int
57878 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57879 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57880 +{
57881 + struct task_struct *task;
57882 +
57883 + if (!gr_acl_is_enabled())
57884 + return 1;
57885 +
57886 + rcu_read_lock();
57887 + read_lock(&tasklist_lock);
57888 +
57889 + task = find_task_by_vpid(shm_cprid);
57890 +
57891 + if (unlikely(!task))
57892 + task = find_task_by_vpid(shm_lapid);
57893 +
57894 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57895 + (task->pid == shm_lapid)) &&
57896 + (task->acl->mode & GR_PROTSHM) &&
57897 + (task->acl != current->acl))) {
57898 + read_unlock(&tasklist_lock);
57899 + rcu_read_unlock();
57900 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57901 + return 0;
57902 + }
57903 + read_unlock(&tasklist_lock);
57904 + rcu_read_unlock();
57905 +
57906 + return 1;
57907 +}
57908 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57909 new file mode 100644
57910 index 0000000..bc0be01
57911 --- /dev/null
57912 +++ b/grsecurity/grsec_chdir.c
57913 @@ -0,0 +1,19 @@
57914 +#include <linux/kernel.h>
57915 +#include <linux/sched.h>
57916 +#include <linux/fs.h>
57917 +#include <linux/file.h>
57918 +#include <linux/grsecurity.h>
57919 +#include <linux/grinternal.h>
57920 +
57921 +void
57922 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57923 +{
57924 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57925 + if ((grsec_enable_chdir && grsec_enable_group &&
57926 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57927 + !grsec_enable_group)) {
57928 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57929 + }
57930 +#endif
57931 + return;
57932 +}
57933 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57934 new file mode 100644
57935 index 0000000..9807ee2
57936 --- /dev/null
57937 +++ b/grsecurity/grsec_chroot.c
57938 @@ -0,0 +1,368 @@
57939 +#include <linux/kernel.h>
57940 +#include <linux/module.h>
57941 +#include <linux/sched.h>
57942 +#include <linux/file.h>
57943 +#include <linux/fs.h>
57944 +#include <linux/mount.h>
57945 +#include <linux/types.h>
57946 +#include "../fs/mount.h"
57947 +#include <linux/grsecurity.h>
57948 +#include <linux/grinternal.h>
57949 +
57950 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57951 +{
57952 +#ifdef CONFIG_GRKERNSEC
57953 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57954 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57955 + task->gr_is_chrooted = 1;
57956 + else
57957 + task->gr_is_chrooted = 0;
57958 +
57959 + task->gr_chroot_dentry = path->dentry;
57960 +#endif
57961 + return;
57962 +}
57963 +
57964 +void gr_clear_chroot_entries(struct task_struct *task)
57965 +{
57966 +#ifdef CONFIG_GRKERNSEC
57967 + task->gr_is_chrooted = 0;
57968 + task->gr_chroot_dentry = NULL;
57969 +#endif
57970 + return;
57971 +}
57972 +
57973 +int
57974 +gr_handle_chroot_unix(const pid_t pid)
57975 +{
57976 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57977 + struct task_struct *p;
57978 +
57979 + if (unlikely(!grsec_enable_chroot_unix))
57980 + return 1;
57981 +
57982 + if (likely(!proc_is_chrooted(current)))
57983 + return 1;
57984 +
57985 + rcu_read_lock();
57986 + read_lock(&tasklist_lock);
57987 + p = find_task_by_vpid_unrestricted(pid);
57988 + if (unlikely(p && !have_same_root(current, p))) {
57989 + read_unlock(&tasklist_lock);
57990 + rcu_read_unlock();
57991 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57992 + return 0;
57993 + }
57994 + read_unlock(&tasklist_lock);
57995 + rcu_read_unlock();
57996 +#endif
57997 + return 1;
57998 +}
57999 +
58000 +int
58001 +gr_handle_chroot_nice(void)
58002 +{
58003 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58004 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
58005 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
58006 + return -EPERM;
58007 + }
58008 +#endif
58009 + return 0;
58010 +}
58011 +
58012 +int
58013 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
58014 +{
58015 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58016 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
58017 + && proc_is_chrooted(current)) {
58018 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
58019 + return -EACCES;
58020 + }
58021 +#endif
58022 + return 0;
58023 +}
58024 +
58025 +int
58026 +gr_handle_chroot_rawio(const struct inode *inode)
58027 +{
58028 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58029 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58030 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
58031 + return 1;
58032 +#endif
58033 + return 0;
58034 +}
58035 +
58036 +int
58037 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
58038 +{
58039 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58040 + struct task_struct *p;
58041 + int ret = 0;
58042 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
58043 + return ret;
58044 +
58045 + read_lock(&tasklist_lock);
58046 + do_each_pid_task(pid, type, p) {
58047 + if (!have_same_root(current, p)) {
58048 + ret = 1;
58049 + goto out;
58050 + }
58051 + } while_each_pid_task(pid, type, p);
58052 +out:
58053 + read_unlock(&tasklist_lock);
58054 + return ret;
58055 +#endif
58056 + return 0;
58057 +}
58058 +
58059 +int
58060 +gr_pid_is_chrooted(struct task_struct *p)
58061 +{
58062 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58063 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
58064 + return 0;
58065 +
58066 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
58067 + !have_same_root(current, p)) {
58068 + return 1;
58069 + }
58070 +#endif
58071 + return 0;
58072 +}
58073 +
58074 +EXPORT_SYMBOL(gr_pid_is_chrooted);
58075 +
58076 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
58077 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
58078 +{
58079 + struct path path, currentroot;
58080 + int ret = 0;
58081 +
58082 + path.dentry = (struct dentry *)u_dentry;
58083 + path.mnt = (struct vfsmount *)u_mnt;
58084 + get_fs_root(current->fs, &currentroot);
58085 + if (path_is_under(&path, &currentroot))
58086 + ret = 1;
58087 + path_put(&currentroot);
58088 +
58089 + return ret;
58090 +}
58091 +#endif
58092 +
58093 +int
58094 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
58095 +{
58096 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58097 + if (!grsec_enable_chroot_fchdir)
58098 + return 1;
58099 +
58100 + if (!proc_is_chrooted(current))
58101 + return 1;
58102 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
58103 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
58104 + return 0;
58105 + }
58106 +#endif
58107 + return 1;
58108 +}
58109 +
58110 +int
58111 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58112 + const time_t shm_createtime)
58113 +{
58114 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58115 + struct task_struct *p;
58116 + time_t starttime;
58117 +
58118 + if (unlikely(!grsec_enable_chroot_shmat))
58119 + return 1;
58120 +
58121 + if (likely(!proc_is_chrooted(current)))
58122 + return 1;
58123 +
58124 + rcu_read_lock();
58125 + read_lock(&tasklist_lock);
58126 +
58127 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
58128 + starttime = p->start_time.tv_sec;
58129 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
58130 + if (have_same_root(current, p)) {
58131 + goto allow;
58132 + } else {
58133 + read_unlock(&tasklist_lock);
58134 + rcu_read_unlock();
58135 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
58136 + return 0;
58137 + }
58138 + }
58139 + /* creator exited, pid reuse, fall through to next check */
58140 + }
58141 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
58142 + if (unlikely(!have_same_root(current, p))) {
58143 + read_unlock(&tasklist_lock);
58144 + rcu_read_unlock();
58145 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
58146 + return 0;
58147 + }
58148 + }
58149 +
58150 +allow:
58151 + read_unlock(&tasklist_lock);
58152 + rcu_read_unlock();
58153 +#endif
58154 + return 1;
58155 +}
58156 +
58157 +void
58158 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
58159 +{
58160 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58161 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
58162 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
58163 +#endif
58164 + return;
58165 +}
58166 +
58167 +int
58168 +gr_handle_chroot_mknod(const struct dentry *dentry,
58169 + const struct vfsmount *mnt, const int mode)
58170 +{
58171 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58172 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
58173 + proc_is_chrooted(current)) {
58174 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
58175 + return -EPERM;
58176 + }
58177 +#endif
58178 + return 0;
58179 +}
58180 +
58181 +int
58182 +gr_handle_chroot_mount(const struct dentry *dentry,
58183 + const struct vfsmount *mnt, const char *dev_name)
58184 +{
58185 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58186 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
58187 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
58188 + return -EPERM;
58189 + }
58190 +#endif
58191 + return 0;
58192 +}
58193 +
58194 +int
58195 +gr_handle_chroot_pivot(void)
58196 +{
58197 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58198 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
58199 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
58200 + return -EPERM;
58201 + }
58202 +#endif
58203 + return 0;
58204 +}
58205 +
58206 +int
58207 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
58208 +{
58209 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58210 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
58211 + !gr_is_outside_chroot(dentry, mnt)) {
58212 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
58213 + return -EPERM;
58214 + }
58215 +#endif
58216 + return 0;
58217 +}
58218 +
58219 +extern const char *captab_log[];
58220 +extern int captab_log_entries;
58221 +
58222 +int
58223 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58224 +{
58225 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58226 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
58227 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58228 + if (cap_raised(chroot_caps, cap)) {
58229 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
58230 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
58231 + }
58232 + return 0;
58233 + }
58234 + }
58235 +#endif
58236 + return 1;
58237 +}
58238 +
58239 +int
58240 +gr_chroot_is_capable(const int cap)
58241 +{
58242 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58243 + return gr_task_chroot_is_capable(current, current_cred(), cap);
58244 +#endif
58245 + return 1;
58246 +}
58247 +
58248 +int
58249 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
58250 +{
58251 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58252 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
58253 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58254 + if (cap_raised(chroot_caps, cap)) {
58255 + return 0;
58256 + }
58257 + }
58258 +#endif
58259 + return 1;
58260 +}
58261 +
58262 +int
58263 +gr_chroot_is_capable_nolog(const int cap)
58264 +{
58265 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58266 + return gr_task_chroot_is_capable_nolog(current, cap);
58267 +#endif
58268 + return 1;
58269 +}
58270 +
58271 +int
58272 +gr_handle_chroot_sysctl(const int op)
58273 +{
58274 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58275 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
58276 + proc_is_chrooted(current))
58277 + return -EACCES;
58278 +#endif
58279 + return 0;
58280 +}
58281 +
58282 +void
58283 +gr_handle_chroot_chdir(struct path *path)
58284 +{
58285 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58286 + if (grsec_enable_chroot_chdir)
58287 + set_fs_pwd(current->fs, path);
58288 +#endif
58289 + return;
58290 +}
58291 +
58292 +int
58293 +gr_handle_chroot_chmod(const struct dentry *dentry,
58294 + const struct vfsmount *mnt, const int mode)
58295 +{
58296 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58297 + /* allow chmod +s on directories, but not files */
58298 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
58299 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
58300 + proc_is_chrooted(current)) {
58301 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
58302 + return -EPERM;
58303 + }
58304 +#endif
58305 + return 0;
58306 +}
58307 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
58308 new file mode 100644
58309 index 0000000..b79fe50
58310 --- /dev/null
58311 +++ b/grsecurity/grsec_disabled.c
58312 @@ -0,0 +1,442 @@
58313 +#include <linux/kernel.h>
58314 +#include <linux/module.h>
58315 +#include <linux/sched.h>
58316 +#include <linux/file.h>
58317 +#include <linux/fs.h>
58318 +#include <linux/kdev_t.h>
58319 +#include <linux/net.h>
58320 +#include <linux/in.h>
58321 +#include <linux/ip.h>
58322 +#include <linux/skbuff.h>
58323 +#include <linux/sysctl.h>
58324 +
58325 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58326 +void
58327 +pax_set_initial_flags(struct linux_binprm *bprm)
58328 +{
58329 + return;
58330 +}
58331 +#endif
58332 +
58333 +#ifdef CONFIG_SYSCTL
58334 +__u32
58335 +gr_handle_sysctl(const struct ctl_table * table, const int op)
58336 +{
58337 + return 0;
58338 +}
58339 +#endif
58340 +
58341 +#ifdef CONFIG_TASKSTATS
58342 +int gr_is_taskstats_denied(int pid)
58343 +{
58344 + return 0;
58345 +}
58346 +#endif
58347 +
58348 +int
58349 +gr_acl_is_enabled(void)
58350 +{
58351 + return 0;
58352 +}
58353 +
58354 +void
58355 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
58356 +{
58357 + return;
58358 +}
58359 +
58360 +int
58361 +gr_handle_rawio(const struct inode *inode)
58362 +{
58363 + return 0;
58364 +}
58365 +
58366 +void
58367 +gr_acl_handle_psacct(struct task_struct *task, const long code)
58368 +{
58369 + return;
58370 +}
58371 +
58372 +int
58373 +gr_handle_ptrace(struct task_struct *task, const long request)
58374 +{
58375 + return 0;
58376 +}
58377 +
58378 +int
58379 +gr_handle_proc_ptrace(struct task_struct *task)
58380 +{
58381 + return 0;
58382 +}
58383 +
58384 +void
58385 +gr_learn_resource(const struct task_struct *task,
58386 + const int res, const unsigned long wanted, const int gt)
58387 +{
58388 + return;
58389 +}
58390 +
58391 +int
58392 +gr_set_acls(const int type)
58393 +{
58394 + return 0;
58395 +}
58396 +
58397 +int
58398 +gr_check_hidden_task(const struct task_struct *tsk)
58399 +{
58400 + return 0;
58401 +}
58402 +
58403 +int
58404 +gr_check_protected_task(const struct task_struct *task)
58405 +{
58406 + return 0;
58407 +}
58408 +
58409 +int
58410 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58411 +{
58412 + return 0;
58413 +}
58414 +
58415 +void
58416 +gr_copy_label(struct task_struct *tsk)
58417 +{
58418 + return;
58419 +}
58420 +
58421 +void
58422 +gr_set_pax_flags(struct task_struct *task)
58423 +{
58424 + return;
58425 +}
58426 +
58427 +int
58428 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
58429 + const int unsafe_share)
58430 +{
58431 + return 0;
58432 +}
58433 +
58434 +void
58435 +gr_handle_delete(const ino_t ino, const dev_t dev)
58436 +{
58437 + return;
58438 +}
58439 +
58440 +void
58441 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58442 +{
58443 + return;
58444 +}
58445 +
58446 +void
58447 +gr_handle_crash(struct task_struct *task, const int sig)
58448 +{
58449 + return;
58450 +}
58451 +
58452 +int
58453 +gr_check_crash_exec(const struct file *filp)
58454 +{
58455 + return 0;
58456 +}
58457 +
58458 +int
58459 +gr_check_crash_uid(const uid_t uid)
58460 +{
58461 + return 0;
58462 +}
58463 +
58464 +void
58465 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58466 + struct dentry *old_dentry,
58467 + struct dentry *new_dentry,
58468 + struct vfsmount *mnt, const __u8 replace)
58469 +{
58470 + return;
58471 +}
58472 +
58473 +int
58474 +gr_search_socket(const int family, const int type, const int protocol)
58475 +{
58476 + return 1;
58477 +}
58478 +
58479 +int
58480 +gr_search_connectbind(const int mode, const struct socket *sock,
58481 + const struct sockaddr_in *addr)
58482 +{
58483 + return 0;
58484 +}
58485 +
58486 +void
58487 +gr_handle_alertkill(struct task_struct *task)
58488 +{
58489 + return;
58490 +}
58491 +
58492 +__u32
58493 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58494 +{
58495 + return 1;
58496 +}
58497 +
58498 +__u32
58499 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58500 + const struct vfsmount * mnt)
58501 +{
58502 + return 1;
58503 +}
58504 +
58505 +__u32
58506 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58507 + int acc_mode)
58508 +{
58509 + return 1;
58510 +}
58511 +
58512 +__u32
58513 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58514 +{
58515 + return 1;
58516 +}
58517 +
58518 +__u32
58519 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58520 +{
58521 + return 1;
58522 +}
58523 +
58524 +int
58525 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58526 + unsigned int *vm_flags)
58527 +{
58528 + return 1;
58529 +}
58530 +
58531 +__u32
58532 +gr_acl_handle_truncate(const struct dentry * dentry,
58533 + const struct vfsmount * mnt)
58534 +{
58535 + return 1;
58536 +}
58537 +
58538 +__u32
58539 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58540 +{
58541 + return 1;
58542 +}
58543 +
58544 +__u32
58545 +gr_acl_handle_access(const struct dentry * dentry,
58546 + const struct vfsmount * mnt, const int fmode)
58547 +{
58548 + return 1;
58549 +}
58550 +
58551 +__u32
58552 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58553 + umode_t *mode)
58554 +{
58555 + return 1;
58556 +}
58557 +
58558 +__u32
58559 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58560 +{
58561 + return 1;
58562 +}
58563 +
58564 +__u32
58565 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58566 +{
58567 + return 1;
58568 +}
58569 +
58570 +void
58571 +grsecurity_init(void)
58572 +{
58573 + return;
58574 +}
58575 +
58576 +umode_t gr_acl_umask(void)
58577 +{
58578 + return 0;
58579 +}
58580 +
58581 +__u32
58582 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58583 + const struct dentry * parent_dentry,
58584 + const struct vfsmount * parent_mnt,
58585 + const int mode)
58586 +{
58587 + return 1;
58588 +}
58589 +
58590 +__u32
58591 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58592 + const struct dentry * parent_dentry,
58593 + const struct vfsmount * parent_mnt)
58594 +{
58595 + return 1;
58596 +}
58597 +
58598 +__u32
58599 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58600 + const struct dentry * parent_dentry,
58601 + const struct vfsmount * parent_mnt, const char *from)
58602 +{
58603 + return 1;
58604 +}
58605 +
58606 +__u32
58607 +gr_acl_handle_link(const struct dentry * new_dentry,
58608 + const struct dentry * parent_dentry,
58609 + const struct vfsmount * parent_mnt,
58610 + const struct dentry * old_dentry,
58611 + const struct vfsmount * old_mnt, const char *to)
58612 +{
58613 + return 1;
58614 +}
58615 +
58616 +int
58617 +gr_acl_handle_rename(const struct dentry *new_dentry,
58618 + const struct dentry *parent_dentry,
58619 + const struct vfsmount *parent_mnt,
58620 + const struct dentry *old_dentry,
58621 + const struct inode *old_parent_inode,
58622 + const struct vfsmount *old_mnt, const char *newname)
58623 +{
58624 + return 0;
58625 +}
58626 +
58627 +int
58628 +gr_acl_handle_filldir(const struct file *file, const char *name,
58629 + const int namelen, const ino_t ino)
58630 +{
58631 + return 1;
58632 +}
58633 +
58634 +int
58635 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58636 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58637 +{
58638 + return 1;
58639 +}
58640 +
58641 +int
58642 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58643 +{
58644 + return 0;
58645 +}
58646 +
58647 +int
58648 +gr_search_accept(const struct socket *sock)
58649 +{
58650 + return 0;
58651 +}
58652 +
58653 +int
58654 +gr_search_listen(const struct socket *sock)
58655 +{
58656 + return 0;
58657 +}
58658 +
58659 +int
58660 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58661 +{
58662 + return 0;
58663 +}
58664 +
58665 +__u32
58666 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58667 +{
58668 + return 1;
58669 +}
58670 +
58671 +__u32
58672 +gr_acl_handle_creat(const struct dentry * dentry,
58673 + const struct dentry * p_dentry,
58674 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58675 + const int imode)
58676 +{
58677 + return 1;
58678 +}
58679 +
58680 +void
58681 +gr_acl_handle_exit(void)
58682 +{
58683 + return;
58684 +}
58685 +
58686 +int
58687 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58688 +{
58689 + return 1;
58690 +}
58691 +
58692 +void
58693 +gr_set_role_label(const uid_t uid, const gid_t gid)
58694 +{
58695 + return;
58696 +}
58697 +
58698 +int
58699 +gr_acl_handle_procpidmem(const struct task_struct *task)
58700 +{
58701 + return 0;
58702 +}
58703 +
58704 +int
58705 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58706 +{
58707 + return 0;
58708 +}
58709 +
58710 +int
58711 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58712 +{
58713 + return 0;
58714 +}
58715 +
58716 +void
58717 +gr_set_kernel_label(struct task_struct *task)
58718 +{
58719 + return;
58720 +}
58721 +
58722 +int
58723 +gr_check_user_change(int real, int effective, int fs)
58724 +{
58725 + return 0;
58726 +}
58727 +
58728 +int
58729 +gr_check_group_change(int real, int effective, int fs)
58730 +{
58731 + return 0;
58732 +}
58733 +
58734 +int gr_acl_enable_at_secure(void)
58735 +{
58736 + return 0;
58737 +}
58738 +
58739 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58740 +{
58741 + return dentry->d_inode->i_sb->s_dev;
58742 +}
58743 +
58744 +void gr_put_exec_file(struct task_struct *task)
58745 +{
58746 + return;
58747 +}
58748 +
58749 +EXPORT_SYMBOL(gr_learn_resource);
58750 +EXPORT_SYMBOL(gr_set_kernel_label);
58751 +#ifdef CONFIG_SECURITY
58752 +EXPORT_SYMBOL(gr_check_user_change);
58753 +EXPORT_SYMBOL(gr_check_group_change);
58754 +#endif
58755 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58756 new file mode 100644
58757 index 0000000..abfa971
58758 --- /dev/null
58759 +++ b/grsecurity/grsec_exec.c
58760 @@ -0,0 +1,174 @@
58761 +#include <linux/kernel.h>
58762 +#include <linux/sched.h>
58763 +#include <linux/file.h>
58764 +#include <linux/binfmts.h>
58765 +#include <linux/fs.h>
58766 +#include <linux/types.h>
58767 +#include <linux/grdefs.h>
58768 +#include <linux/grsecurity.h>
58769 +#include <linux/grinternal.h>
58770 +#include <linux/capability.h>
58771 +#include <linux/module.h>
58772 +
58773 +#include <asm/uaccess.h>
58774 +
58775 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58776 +static char gr_exec_arg_buf[132];
58777 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58778 +#endif
58779 +
58780 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58781 +
58782 +void
58783 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58784 +{
58785 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58786 + char *grarg = gr_exec_arg_buf;
58787 + unsigned int i, x, execlen = 0;
58788 + char c;
58789 +
58790 + if (!((grsec_enable_execlog && grsec_enable_group &&
58791 + in_group_p(grsec_audit_gid))
58792 + || (grsec_enable_execlog && !grsec_enable_group)))
58793 + return;
58794 +
58795 + mutex_lock(&gr_exec_arg_mutex);
58796 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58797 +
58798 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58799 + const char __user *p;
58800 + unsigned int len;
58801 +
58802 + p = get_user_arg_ptr(argv, i);
58803 + if (IS_ERR(p))
58804 + goto log;
58805 +
58806 + len = strnlen_user(p, 128 - execlen);
58807 + if (len > 128 - execlen)
58808 + len = 128 - execlen;
58809 + else if (len > 0)
58810 + len--;
58811 + if (copy_from_user(grarg + execlen, p, len))
58812 + goto log;
58813 +
58814 + /* rewrite unprintable characters */
58815 + for (x = 0; x < len; x++) {
58816 + c = *(grarg + execlen + x);
58817 + if (c < 32 || c > 126)
58818 + *(grarg + execlen + x) = ' ';
58819 + }
58820 +
58821 + execlen += len;
58822 + *(grarg + execlen) = ' ';
58823 + *(grarg + execlen + 1) = '\0';
58824 + execlen++;
58825 + }
58826 +
58827 + log:
58828 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58829 + bprm->file->f_path.mnt, grarg);
58830 + mutex_unlock(&gr_exec_arg_mutex);
58831 +#endif
58832 + return;
58833 +}
58834 +
58835 +#ifdef CONFIG_GRKERNSEC
58836 +extern int gr_acl_is_capable(const int cap);
58837 +extern int gr_acl_is_capable_nolog(const int cap);
58838 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58839 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58840 +extern int gr_chroot_is_capable(const int cap);
58841 +extern int gr_chroot_is_capable_nolog(const int cap);
58842 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58843 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58844 +#endif
58845 +
58846 +const char *captab_log[] = {
58847 + "CAP_CHOWN",
58848 + "CAP_DAC_OVERRIDE",
58849 + "CAP_DAC_READ_SEARCH",
58850 + "CAP_FOWNER",
58851 + "CAP_FSETID",
58852 + "CAP_KILL",
58853 + "CAP_SETGID",
58854 + "CAP_SETUID",
58855 + "CAP_SETPCAP",
58856 + "CAP_LINUX_IMMUTABLE",
58857 + "CAP_NET_BIND_SERVICE",
58858 + "CAP_NET_BROADCAST",
58859 + "CAP_NET_ADMIN",
58860 + "CAP_NET_RAW",
58861 + "CAP_IPC_LOCK",
58862 + "CAP_IPC_OWNER",
58863 + "CAP_SYS_MODULE",
58864 + "CAP_SYS_RAWIO",
58865 + "CAP_SYS_CHROOT",
58866 + "CAP_SYS_PTRACE",
58867 + "CAP_SYS_PACCT",
58868 + "CAP_SYS_ADMIN",
58869 + "CAP_SYS_BOOT",
58870 + "CAP_SYS_NICE",
58871 + "CAP_SYS_RESOURCE",
58872 + "CAP_SYS_TIME",
58873 + "CAP_SYS_TTY_CONFIG",
58874 + "CAP_MKNOD",
58875 + "CAP_LEASE",
58876 + "CAP_AUDIT_WRITE",
58877 + "CAP_AUDIT_CONTROL",
58878 + "CAP_SETFCAP",
58879 + "CAP_MAC_OVERRIDE",
58880 + "CAP_MAC_ADMIN",
58881 + "CAP_SYSLOG",
58882 + "CAP_WAKE_ALARM"
58883 +};
58884 +
58885 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58886 +
58887 +int gr_is_capable(const int cap)
58888 +{
58889 +#ifdef CONFIG_GRKERNSEC
58890 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58891 + return 1;
58892 + return 0;
58893 +#else
58894 + return 1;
58895 +#endif
58896 +}
58897 +
58898 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58899 +{
58900 +#ifdef CONFIG_GRKERNSEC
58901 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58902 + return 1;
58903 + return 0;
58904 +#else
58905 + return 1;
58906 +#endif
58907 +}
58908 +
58909 +int gr_is_capable_nolog(const int cap)
58910 +{
58911 +#ifdef CONFIG_GRKERNSEC
58912 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58913 + return 1;
58914 + return 0;
58915 +#else
58916 + return 1;
58917 +#endif
58918 +}
58919 +
58920 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58921 +{
58922 +#ifdef CONFIG_GRKERNSEC
58923 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58924 + return 1;
58925 + return 0;
58926 +#else
58927 + return 1;
58928 +#endif
58929 +}
58930 +
58931 +EXPORT_SYMBOL(gr_is_capable);
58932 +EXPORT_SYMBOL(gr_is_capable_nolog);
58933 +EXPORT_SYMBOL(gr_task_is_capable);
58934 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58935 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58936 new file mode 100644
58937 index 0000000..d3ee748
58938 --- /dev/null
58939 +++ b/grsecurity/grsec_fifo.c
58940 @@ -0,0 +1,24 @@
58941 +#include <linux/kernel.h>
58942 +#include <linux/sched.h>
58943 +#include <linux/fs.h>
58944 +#include <linux/file.h>
58945 +#include <linux/grinternal.h>
58946 +
58947 +int
58948 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58949 + const struct dentry *dir, const int flag, const int acc_mode)
58950 +{
58951 +#ifdef CONFIG_GRKERNSEC_FIFO
58952 + const struct cred *cred = current_cred();
58953 +
58954 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58955 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58956 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58957 + (cred->fsuid != dentry->d_inode->i_uid)) {
58958 + if (!inode_permission(dentry->d_inode, acc_mode))
58959 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58960 + return -EACCES;
58961 + }
58962 +#endif
58963 + return 0;
58964 +}
58965 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58966 new file mode 100644
58967 index 0000000..8ca18bf
58968 --- /dev/null
58969 +++ b/grsecurity/grsec_fork.c
58970 @@ -0,0 +1,23 @@
58971 +#include <linux/kernel.h>
58972 +#include <linux/sched.h>
58973 +#include <linux/grsecurity.h>
58974 +#include <linux/grinternal.h>
58975 +#include <linux/errno.h>
58976 +
58977 +void
58978 +gr_log_forkfail(const int retval)
58979 +{
58980 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58981 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58982 + switch (retval) {
58983 + case -EAGAIN:
58984 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58985 + break;
58986 + case -ENOMEM:
58987 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58988 + break;
58989 + }
58990 + }
58991 +#endif
58992 + return;
58993 +}
58994 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58995 new file mode 100644
58996 index 0000000..05a6015
58997 --- /dev/null
58998 +++ b/grsecurity/grsec_init.c
58999 @@ -0,0 +1,283 @@
59000 +#include <linux/kernel.h>
59001 +#include <linux/sched.h>
59002 +#include <linux/mm.h>
59003 +#include <linux/gracl.h>
59004 +#include <linux/slab.h>
59005 +#include <linux/vmalloc.h>
59006 +#include <linux/percpu.h>
59007 +#include <linux/module.h>
59008 +
59009 +int grsec_enable_ptrace_readexec;
59010 +int grsec_enable_setxid;
59011 +int grsec_enable_symlinkown;
59012 +int grsec_symlinkown_gid;
59013 +int grsec_enable_brute;
59014 +int grsec_enable_link;
59015 +int grsec_enable_dmesg;
59016 +int grsec_enable_harden_ptrace;
59017 +int grsec_enable_fifo;
59018 +int grsec_enable_execlog;
59019 +int grsec_enable_signal;
59020 +int grsec_enable_forkfail;
59021 +int grsec_enable_audit_ptrace;
59022 +int grsec_enable_time;
59023 +int grsec_enable_audit_textrel;
59024 +int grsec_enable_group;
59025 +int grsec_audit_gid;
59026 +int grsec_enable_chdir;
59027 +int grsec_enable_mount;
59028 +int grsec_enable_rofs;
59029 +int grsec_enable_chroot_findtask;
59030 +int grsec_enable_chroot_mount;
59031 +int grsec_enable_chroot_shmat;
59032 +int grsec_enable_chroot_fchdir;
59033 +int grsec_enable_chroot_double;
59034 +int grsec_enable_chroot_pivot;
59035 +int grsec_enable_chroot_chdir;
59036 +int grsec_enable_chroot_chmod;
59037 +int grsec_enable_chroot_mknod;
59038 +int grsec_enable_chroot_nice;
59039 +int grsec_enable_chroot_execlog;
59040 +int grsec_enable_chroot_caps;
59041 +int grsec_enable_chroot_sysctl;
59042 +int grsec_enable_chroot_unix;
59043 +int grsec_enable_tpe;
59044 +int grsec_tpe_gid;
59045 +int grsec_enable_blackhole;
59046 +#ifdef CONFIG_IPV6_MODULE
59047 +EXPORT_SYMBOL(grsec_enable_blackhole);
59048 +#endif
59049 +int grsec_lastack_retries;
59050 +int grsec_enable_tpe_all;
59051 +int grsec_enable_tpe_invert;
59052 +int grsec_enable_socket_all;
59053 +int grsec_socket_all_gid;
59054 +int grsec_enable_socket_client;
59055 +int grsec_socket_client_gid;
59056 +int grsec_enable_socket_server;
59057 +int grsec_socket_server_gid;
59058 +int grsec_resource_logging;
59059 +int grsec_disable_privio;
59060 +int grsec_enable_log_rwxmaps;
59061 +int grsec_lock;
59062 +
59063 +DEFINE_SPINLOCK(grsec_alert_lock);
59064 +unsigned long grsec_alert_wtime = 0;
59065 +unsigned long grsec_alert_fyet = 0;
59066 +
59067 +DEFINE_SPINLOCK(grsec_audit_lock);
59068 +
59069 +DEFINE_RWLOCK(grsec_exec_file_lock);
59070 +
59071 +char *gr_shared_page[4];
59072 +
59073 +char *gr_alert_log_fmt;
59074 +char *gr_audit_log_fmt;
59075 +char *gr_alert_log_buf;
59076 +char *gr_audit_log_buf;
59077 +
59078 +extern struct gr_arg *gr_usermode;
59079 +extern unsigned char *gr_system_salt;
59080 +extern unsigned char *gr_system_sum;
59081 +
59082 +void __init
59083 +grsecurity_init(void)
59084 +{
59085 + int j;
59086 + /* create the per-cpu shared pages */
59087 +
59088 +#ifdef CONFIG_X86
59089 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
59090 +#endif
59091 +
59092 + for (j = 0; j < 4; j++) {
59093 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
59094 + if (gr_shared_page[j] == NULL) {
59095 + panic("Unable to allocate grsecurity shared page");
59096 + return;
59097 + }
59098 + }
59099 +
59100 + /* allocate log buffers */
59101 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
59102 + if (!gr_alert_log_fmt) {
59103 + panic("Unable to allocate grsecurity alert log format buffer");
59104 + return;
59105 + }
59106 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
59107 + if (!gr_audit_log_fmt) {
59108 + panic("Unable to allocate grsecurity audit log format buffer");
59109 + return;
59110 + }
59111 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
59112 + if (!gr_alert_log_buf) {
59113 + panic("Unable to allocate grsecurity alert log buffer");
59114 + return;
59115 + }
59116 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
59117 + if (!gr_audit_log_buf) {
59118 + panic("Unable to allocate grsecurity audit log buffer");
59119 + return;
59120 + }
59121 +
59122 + /* allocate memory for authentication structure */
59123 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
59124 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
59125 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
59126 +
59127 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
59128 + panic("Unable to allocate grsecurity authentication structure");
59129 + return;
59130 + }
59131 +
59132 +
59133 +#ifdef CONFIG_GRKERNSEC_IO
59134 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
59135 + grsec_disable_privio = 1;
59136 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
59137 + grsec_disable_privio = 1;
59138 +#else
59139 + grsec_disable_privio = 0;
59140 +#endif
59141 +#endif
59142 +
59143 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59144 + /* for backward compatibility, tpe_invert always defaults to on if
59145 + enabled in the kernel
59146 + */
59147 + grsec_enable_tpe_invert = 1;
59148 +#endif
59149 +
59150 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
59151 +#ifndef CONFIG_GRKERNSEC_SYSCTL
59152 + grsec_lock = 1;
59153 +#endif
59154 +
59155 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59156 + grsec_enable_audit_textrel = 1;
59157 +#endif
59158 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59159 + grsec_enable_log_rwxmaps = 1;
59160 +#endif
59161 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59162 + grsec_enable_group = 1;
59163 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
59164 +#endif
59165 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59166 + grsec_enable_ptrace_readexec = 1;
59167 +#endif
59168 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59169 + grsec_enable_chdir = 1;
59170 +#endif
59171 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59172 + grsec_enable_harden_ptrace = 1;
59173 +#endif
59174 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59175 + grsec_enable_mount = 1;
59176 +#endif
59177 +#ifdef CONFIG_GRKERNSEC_LINK
59178 + grsec_enable_link = 1;
59179 +#endif
59180 +#ifdef CONFIG_GRKERNSEC_BRUTE
59181 + grsec_enable_brute = 1;
59182 +#endif
59183 +#ifdef CONFIG_GRKERNSEC_DMESG
59184 + grsec_enable_dmesg = 1;
59185 +#endif
59186 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59187 + grsec_enable_blackhole = 1;
59188 + grsec_lastack_retries = 4;
59189 +#endif
59190 +#ifdef CONFIG_GRKERNSEC_FIFO
59191 + grsec_enable_fifo = 1;
59192 +#endif
59193 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59194 + grsec_enable_execlog = 1;
59195 +#endif
59196 +#ifdef CONFIG_GRKERNSEC_SETXID
59197 + grsec_enable_setxid = 1;
59198 +#endif
59199 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59200 + grsec_enable_signal = 1;
59201 +#endif
59202 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59203 + grsec_enable_forkfail = 1;
59204 +#endif
59205 +#ifdef CONFIG_GRKERNSEC_TIME
59206 + grsec_enable_time = 1;
59207 +#endif
59208 +#ifdef CONFIG_GRKERNSEC_RESLOG
59209 + grsec_resource_logging = 1;
59210 +#endif
59211 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59212 + grsec_enable_chroot_findtask = 1;
59213 +#endif
59214 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59215 + grsec_enable_chroot_unix = 1;
59216 +#endif
59217 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59218 + grsec_enable_chroot_mount = 1;
59219 +#endif
59220 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59221 + grsec_enable_chroot_fchdir = 1;
59222 +#endif
59223 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59224 + grsec_enable_chroot_shmat = 1;
59225 +#endif
59226 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59227 + grsec_enable_audit_ptrace = 1;
59228 +#endif
59229 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59230 + grsec_enable_chroot_double = 1;
59231 +#endif
59232 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59233 + grsec_enable_chroot_pivot = 1;
59234 +#endif
59235 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59236 + grsec_enable_chroot_chdir = 1;
59237 +#endif
59238 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59239 + grsec_enable_chroot_chmod = 1;
59240 +#endif
59241 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59242 + grsec_enable_chroot_mknod = 1;
59243 +#endif
59244 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59245 + grsec_enable_chroot_nice = 1;
59246 +#endif
59247 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59248 + grsec_enable_chroot_execlog = 1;
59249 +#endif
59250 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59251 + grsec_enable_chroot_caps = 1;
59252 +#endif
59253 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59254 + grsec_enable_chroot_sysctl = 1;
59255 +#endif
59256 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59257 + grsec_enable_symlinkown = 1;
59258 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
59259 +#endif
59260 +#ifdef CONFIG_GRKERNSEC_TPE
59261 + grsec_enable_tpe = 1;
59262 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
59263 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59264 + grsec_enable_tpe_all = 1;
59265 +#endif
59266 +#endif
59267 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59268 + grsec_enable_socket_all = 1;
59269 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
59270 +#endif
59271 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59272 + grsec_enable_socket_client = 1;
59273 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
59274 +#endif
59275 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59276 + grsec_enable_socket_server = 1;
59277 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
59278 +#endif
59279 +#endif
59280 +
59281 + return;
59282 +}
59283 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
59284 new file mode 100644
59285 index 0000000..589481f
59286 --- /dev/null
59287 +++ b/grsecurity/grsec_link.c
59288 @@ -0,0 +1,58 @@
59289 +#include <linux/kernel.h>
59290 +#include <linux/sched.h>
59291 +#include <linux/fs.h>
59292 +#include <linux/file.h>
59293 +#include <linux/grinternal.h>
59294 +
59295 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
59296 +{
59297 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59298 + const struct inode *link_inode = link->dentry->d_inode;
59299 +
59300 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
59301 + /* ignore root-owned links, e.g. /proc/self */
59302 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
59303 + !uid_eq(link_inode->i_uid, target->i_uid)) {
59304 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
59305 + return 1;
59306 + }
59307 +#endif
59308 + return 0;
59309 +}
59310 +
59311 +int
59312 +gr_handle_follow_link(const struct inode *parent,
59313 + const struct inode *inode,
59314 + const struct dentry *dentry, const struct vfsmount *mnt)
59315 +{
59316 +#ifdef CONFIG_GRKERNSEC_LINK
59317 + const struct cred *cred = current_cred();
59318 +
59319 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
59320 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
59321 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
59322 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
59323 + return -EACCES;
59324 + }
59325 +#endif
59326 + return 0;
59327 +}
59328 +
59329 +int
59330 +gr_handle_hardlink(const struct dentry *dentry,
59331 + const struct vfsmount *mnt,
59332 + struct inode *inode, const int mode, const char *to)
59333 +{
59334 +#ifdef CONFIG_GRKERNSEC_LINK
59335 + const struct cred *cred = current_cred();
59336 +
59337 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
59338 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
59339 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
59340 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59341 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
59342 + return -EPERM;
59343 + }
59344 +#endif
59345 + return 0;
59346 +}
59347 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
59348 new file mode 100644
59349 index 0000000..a45d2e9
59350 --- /dev/null
59351 +++ b/grsecurity/grsec_log.c
59352 @@ -0,0 +1,322 @@
59353 +#include <linux/kernel.h>
59354 +#include <linux/sched.h>
59355 +#include <linux/file.h>
59356 +#include <linux/tty.h>
59357 +#include <linux/fs.h>
59358 +#include <linux/grinternal.h>
59359 +
59360 +#ifdef CONFIG_TREE_PREEMPT_RCU
59361 +#define DISABLE_PREEMPT() preempt_disable()
59362 +#define ENABLE_PREEMPT() preempt_enable()
59363 +#else
59364 +#define DISABLE_PREEMPT()
59365 +#define ENABLE_PREEMPT()
59366 +#endif
59367 +
59368 +#define BEGIN_LOCKS(x) \
59369 + DISABLE_PREEMPT(); \
59370 + rcu_read_lock(); \
59371 + read_lock(&tasklist_lock); \
59372 + read_lock(&grsec_exec_file_lock); \
59373 + if (x != GR_DO_AUDIT) \
59374 + spin_lock(&grsec_alert_lock); \
59375 + else \
59376 + spin_lock(&grsec_audit_lock)
59377 +
59378 +#define END_LOCKS(x) \
59379 + if (x != GR_DO_AUDIT) \
59380 + spin_unlock(&grsec_alert_lock); \
59381 + else \
59382 + spin_unlock(&grsec_audit_lock); \
59383 + read_unlock(&grsec_exec_file_lock); \
59384 + read_unlock(&tasklist_lock); \
59385 + rcu_read_unlock(); \
59386 + ENABLE_PREEMPT(); \
59387 + if (x == GR_DONT_AUDIT) \
59388 + gr_handle_alertkill(current)
59389 +
59390 +enum {
59391 + FLOODING,
59392 + NO_FLOODING
59393 +};
59394 +
59395 +extern char *gr_alert_log_fmt;
59396 +extern char *gr_audit_log_fmt;
59397 +extern char *gr_alert_log_buf;
59398 +extern char *gr_audit_log_buf;
59399 +
59400 +static int gr_log_start(int audit)
59401 +{
59402 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
59403 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
59404 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59405 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
59406 + unsigned long curr_secs = get_seconds();
59407 +
59408 + if (audit == GR_DO_AUDIT)
59409 + goto set_fmt;
59410 +
59411 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
59412 + grsec_alert_wtime = curr_secs;
59413 + grsec_alert_fyet = 0;
59414 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
59415 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
59416 + grsec_alert_fyet++;
59417 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
59418 + grsec_alert_wtime = curr_secs;
59419 + grsec_alert_fyet++;
59420 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
59421 + return FLOODING;
59422 + }
59423 + else return FLOODING;
59424 +
59425 +set_fmt:
59426 +#endif
59427 + memset(buf, 0, PAGE_SIZE);
59428 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
59429 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
59430 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59431 + } else if (current->signal->curr_ip) {
59432 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
59433 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
59434 + } else if (gr_acl_is_enabled()) {
59435 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
59436 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59437 + } else {
59438 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
59439 + strcpy(buf, fmt);
59440 + }
59441 +
59442 + return NO_FLOODING;
59443 +}
59444 +
59445 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59446 + __attribute__ ((format (printf, 2, 0)));
59447 +
59448 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59449 +{
59450 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59451 + unsigned int len = strlen(buf);
59452 +
59453 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59454 +
59455 + return;
59456 +}
59457 +
59458 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59459 + __attribute__ ((format (printf, 2, 3)));
59460 +
59461 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59462 +{
59463 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59464 + unsigned int len = strlen(buf);
59465 + va_list ap;
59466 +
59467 + va_start(ap, msg);
59468 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59469 + va_end(ap);
59470 +
59471 + return;
59472 +}
59473 +
59474 +static void gr_log_end(int audit, int append_default)
59475 +{
59476 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59477 +
59478 + if (append_default) {
59479 + unsigned int len = strlen(buf);
59480 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59481 + }
59482 +
59483 + printk("%s\n", buf);
59484 +
59485 + return;
59486 +}
59487 +
59488 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59489 +{
59490 + int logtype;
59491 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59492 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59493 + void *voidptr = NULL;
59494 + int num1 = 0, num2 = 0;
59495 + unsigned long ulong1 = 0, ulong2 = 0;
59496 + struct dentry *dentry = NULL;
59497 + struct vfsmount *mnt = NULL;
59498 + struct file *file = NULL;
59499 + struct task_struct *task = NULL;
59500 + const struct cred *cred, *pcred;
59501 + va_list ap;
59502 +
59503 + BEGIN_LOCKS(audit);
59504 + logtype = gr_log_start(audit);
59505 + if (logtype == FLOODING) {
59506 + END_LOCKS(audit);
59507 + return;
59508 + }
59509 + va_start(ap, argtypes);
59510 + switch (argtypes) {
59511 + case GR_TTYSNIFF:
59512 + task = va_arg(ap, struct task_struct *);
59513 + 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);
59514 + break;
59515 + case GR_SYSCTL_HIDDEN:
59516 + str1 = va_arg(ap, char *);
59517 + gr_log_middle_varargs(audit, msg, result, str1);
59518 + break;
59519 + case GR_RBAC:
59520 + dentry = va_arg(ap, struct dentry *);
59521 + mnt = va_arg(ap, struct vfsmount *);
59522 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59523 + break;
59524 + case GR_RBAC_STR:
59525 + dentry = va_arg(ap, struct dentry *);
59526 + mnt = va_arg(ap, struct vfsmount *);
59527 + str1 = va_arg(ap, char *);
59528 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59529 + break;
59530 + case GR_STR_RBAC:
59531 + str1 = va_arg(ap, char *);
59532 + dentry = va_arg(ap, struct dentry *);
59533 + mnt = va_arg(ap, struct vfsmount *);
59534 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59535 + break;
59536 + case GR_RBAC_MODE2:
59537 + dentry = va_arg(ap, struct dentry *);
59538 + mnt = va_arg(ap, struct vfsmount *);
59539 + str1 = va_arg(ap, char *);
59540 + str2 = va_arg(ap, char *);
59541 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59542 + break;
59543 + case GR_RBAC_MODE3:
59544 + dentry = va_arg(ap, struct dentry *);
59545 + mnt = va_arg(ap, struct vfsmount *);
59546 + str1 = va_arg(ap, char *);
59547 + str2 = va_arg(ap, char *);
59548 + str3 = va_arg(ap, char *);
59549 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59550 + break;
59551 + case GR_FILENAME:
59552 + dentry = va_arg(ap, struct dentry *);
59553 + mnt = va_arg(ap, struct vfsmount *);
59554 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59555 + break;
59556 + case GR_STR_FILENAME:
59557 + str1 = va_arg(ap, char *);
59558 + dentry = va_arg(ap, struct dentry *);
59559 + mnt = va_arg(ap, struct vfsmount *);
59560 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59561 + break;
59562 + case GR_FILENAME_STR:
59563 + dentry = va_arg(ap, struct dentry *);
59564 + mnt = va_arg(ap, struct vfsmount *);
59565 + str1 = va_arg(ap, char *);
59566 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59567 + break;
59568 + case GR_FILENAME_TWO_INT:
59569 + dentry = va_arg(ap, struct dentry *);
59570 + mnt = va_arg(ap, struct vfsmount *);
59571 + num1 = va_arg(ap, int);
59572 + num2 = va_arg(ap, int);
59573 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59574 + break;
59575 + case GR_FILENAME_TWO_INT_STR:
59576 + dentry = va_arg(ap, struct dentry *);
59577 + mnt = va_arg(ap, struct vfsmount *);
59578 + num1 = va_arg(ap, int);
59579 + num2 = va_arg(ap, int);
59580 + str1 = va_arg(ap, char *);
59581 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59582 + break;
59583 + case GR_TEXTREL:
59584 + file = va_arg(ap, struct file *);
59585 + ulong1 = va_arg(ap, unsigned long);
59586 + ulong2 = va_arg(ap, unsigned long);
59587 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59588 + break;
59589 + case GR_PTRACE:
59590 + task = va_arg(ap, struct task_struct *);
59591 + 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);
59592 + break;
59593 + case GR_RESOURCE:
59594 + task = va_arg(ap, struct task_struct *);
59595 + cred = __task_cred(task);
59596 + pcred = __task_cred(task->real_parent);
59597 + ulong1 = va_arg(ap, unsigned long);
59598 + str1 = va_arg(ap, char *);
59599 + ulong2 = va_arg(ap, unsigned long);
59600 + 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);
59601 + break;
59602 + case GR_CAP:
59603 + task = va_arg(ap, struct task_struct *);
59604 + cred = __task_cred(task);
59605 + pcred = __task_cred(task->real_parent);
59606 + str1 = va_arg(ap, char *);
59607 + 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);
59608 + break;
59609 + case GR_SIG:
59610 + str1 = va_arg(ap, char *);
59611 + voidptr = va_arg(ap, void *);
59612 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59613 + break;
59614 + case GR_SIG2:
59615 + task = va_arg(ap, struct task_struct *);
59616 + cred = __task_cred(task);
59617 + pcred = __task_cred(task->real_parent);
59618 + num1 = va_arg(ap, int);
59619 + 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);
59620 + break;
59621 + case GR_CRASH1:
59622 + task = va_arg(ap, struct task_struct *);
59623 + cred = __task_cred(task);
59624 + pcred = __task_cred(task->real_parent);
59625 + ulong1 = va_arg(ap, unsigned long);
59626 + 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);
59627 + break;
59628 + case GR_CRASH2:
59629 + task = va_arg(ap, struct task_struct *);
59630 + cred = __task_cred(task);
59631 + pcred = __task_cred(task->real_parent);
59632 + ulong1 = va_arg(ap, unsigned long);
59633 + 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);
59634 + break;
59635 + case GR_RWXMAP:
59636 + file = va_arg(ap, struct file *);
59637 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59638 + break;
59639 + case GR_PSACCT:
59640 + {
59641 + unsigned int wday, cday;
59642 + __u8 whr, chr;
59643 + __u8 wmin, cmin;
59644 + __u8 wsec, csec;
59645 + char cur_tty[64] = { 0 };
59646 + char parent_tty[64] = { 0 };
59647 +
59648 + task = va_arg(ap, struct task_struct *);
59649 + wday = va_arg(ap, unsigned int);
59650 + cday = va_arg(ap, unsigned int);
59651 + whr = va_arg(ap, int);
59652 + chr = va_arg(ap, int);
59653 + wmin = va_arg(ap, int);
59654 + cmin = va_arg(ap, int);
59655 + wsec = va_arg(ap, int);
59656 + csec = va_arg(ap, int);
59657 + ulong1 = va_arg(ap, unsigned long);
59658 + cred = __task_cred(task);
59659 + pcred = __task_cred(task->real_parent);
59660 +
59661 + 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);
59662 + }
59663 + break;
59664 + default:
59665 + gr_log_middle(audit, msg, ap);
59666 + }
59667 + va_end(ap);
59668 + // these don't need DEFAULTSECARGS printed on the end
59669 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59670 + gr_log_end(audit, 0);
59671 + else
59672 + gr_log_end(audit, 1);
59673 + END_LOCKS(audit);
59674 +}
59675 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59676 new file mode 100644
59677 index 0000000..f536303
59678 --- /dev/null
59679 +++ b/grsecurity/grsec_mem.c
59680 @@ -0,0 +1,40 @@
59681 +#include <linux/kernel.h>
59682 +#include <linux/sched.h>
59683 +#include <linux/mm.h>
59684 +#include <linux/mman.h>
59685 +#include <linux/grinternal.h>
59686 +
59687 +void
59688 +gr_handle_ioperm(void)
59689 +{
59690 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59691 + return;
59692 +}
59693 +
59694 +void
59695 +gr_handle_iopl(void)
59696 +{
59697 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59698 + return;
59699 +}
59700 +
59701 +void
59702 +gr_handle_mem_readwrite(u64 from, u64 to)
59703 +{
59704 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59705 + return;
59706 +}
59707 +
59708 +void
59709 +gr_handle_vm86(void)
59710 +{
59711 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59712 + return;
59713 +}
59714 +
59715 +void
59716 +gr_log_badprocpid(const char *entry)
59717 +{
59718 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59719 + return;
59720 +}
59721 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59722 new file mode 100644
59723 index 0000000..2131422
59724 --- /dev/null
59725 +++ b/grsecurity/grsec_mount.c
59726 @@ -0,0 +1,62 @@
59727 +#include <linux/kernel.h>
59728 +#include <linux/sched.h>
59729 +#include <linux/mount.h>
59730 +#include <linux/grsecurity.h>
59731 +#include <linux/grinternal.h>
59732 +
59733 +void
59734 +gr_log_remount(const char *devname, const int retval)
59735 +{
59736 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59737 + if (grsec_enable_mount && (retval >= 0))
59738 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59739 +#endif
59740 + return;
59741 +}
59742 +
59743 +void
59744 +gr_log_unmount(const char *devname, const int retval)
59745 +{
59746 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59747 + if (grsec_enable_mount && (retval >= 0))
59748 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59749 +#endif
59750 + return;
59751 +}
59752 +
59753 +void
59754 +gr_log_mount(const char *from, const char *to, const int retval)
59755 +{
59756 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59757 + if (grsec_enable_mount && (retval >= 0))
59758 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59759 +#endif
59760 + return;
59761 +}
59762 +
59763 +int
59764 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59765 +{
59766 +#ifdef CONFIG_GRKERNSEC_ROFS
59767 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59768 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59769 + return -EPERM;
59770 + } else
59771 + return 0;
59772 +#endif
59773 + return 0;
59774 +}
59775 +
59776 +int
59777 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59778 +{
59779 +#ifdef CONFIG_GRKERNSEC_ROFS
59780 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59781 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59782 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59783 + return -EPERM;
59784 + } else
59785 + return 0;
59786 +#endif
59787 + return 0;
59788 +}
59789 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59790 new file mode 100644
59791 index 0000000..a3b12a0
59792 --- /dev/null
59793 +++ b/grsecurity/grsec_pax.c
59794 @@ -0,0 +1,36 @@
59795 +#include <linux/kernel.h>
59796 +#include <linux/sched.h>
59797 +#include <linux/mm.h>
59798 +#include <linux/file.h>
59799 +#include <linux/grinternal.h>
59800 +#include <linux/grsecurity.h>
59801 +
59802 +void
59803 +gr_log_textrel(struct vm_area_struct * vma)
59804 +{
59805 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59806 + if (grsec_enable_audit_textrel)
59807 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59808 +#endif
59809 + return;
59810 +}
59811 +
59812 +void
59813 +gr_log_rwxmmap(struct file *file)
59814 +{
59815 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59816 + if (grsec_enable_log_rwxmaps)
59817 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59818 +#endif
59819 + return;
59820 +}
59821 +
59822 +void
59823 +gr_log_rwxmprotect(struct file *file)
59824 +{
59825 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59826 + if (grsec_enable_log_rwxmaps)
59827 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59828 +#endif
59829 + return;
59830 +}
59831 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59832 new file mode 100644
59833 index 0000000..f7f29aa
59834 --- /dev/null
59835 +++ b/grsecurity/grsec_ptrace.c
59836 @@ -0,0 +1,30 @@
59837 +#include <linux/kernel.h>
59838 +#include <linux/sched.h>
59839 +#include <linux/grinternal.h>
59840 +#include <linux/security.h>
59841 +
59842 +void
59843 +gr_audit_ptrace(struct task_struct *task)
59844 +{
59845 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59846 + if (grsec_enable_audit_ptrace)
59847 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59848 +#endif
59849 + return;
59850 +}
59851 +
59852 +int
59853 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59854 +{
59855 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59856 + const struct dentry *dentry = file->f_path.dentry;
59857 + const struct vfsmount *mnt = file->f_path.mnt;
59858 +
59859 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59860 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59861 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59862 + return -EACCES;
59863 + }
59864 +#endif
59865 + return 0;
59866 +}
59867 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59868 new file mode 100644
59869 index 0000000..b4ac94c
59870 --- /dev/null
59871 +++ b/grsecurity/grsec_sig.c
59872 @@ -0,0 +1,209 @@
59873 +#include <linux/kernel.h>
59874 +#include <linux/sched.h>
59875 +#include <linux/delay.h>
59876 +#include <linux/grsecurity.h>
59877 +#include <linux/grinternal.h>
59878 +#include <linux/hardirq.h>
59879 +
59880 +char *signames[] = {
59881 + [SIGSEGV] = "Segmentation fault",
59882 + [SIGILL] = "Illegal instruction",
59883 + [SIGABRT] = "Abort",
59884 + [SIGBUS] = "Invalid alignment/Bus error"
59885 +};
59886 +
59887 +void
59888 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59889 +{
59890 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59891 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59892 + (sig == SIGABRT) || (sig == SIGBUS))) {
59893 + if (t->pid == current->pid) {
59894 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59895 + } else {
59896 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59897 + }
59898 + }
59899 +#endif
59900 + return;
59901 +}
59902 +
59903 +int
59904 +gr_handle_signal(const struct task_struct *p, const int sig)
59905 +{
59906 +#ifdef CONFIG_GRKERNSEC
59907 + /* ignore the 0 signal for protected task checks */
59908 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59909 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59910 + return -EPERM;
59911 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59912 + return -EPERM;
59913 + }
59914 +#endif
59915 + return 0;
59916 +}
59917 +
59918 +#ifdef CONFIG_GRKERNSEC
59919 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59920 +
59921 +int gr_fake_force_sig(int sig, struct task_struct *t)
59922 +{
59923 + unsigned long int flags;
59924 + int ret, blocked, ignored;
59925 + struct k_sigaction *action;
59926 +
59927 + spin_lock_irqsave(&t->sighand->siglock, flags);
59928 + action = &t->sighand->action[sig-1];
59929 + ignored = action->sa.sa_handler == SIG_IGN;
59930 + blocked = sigismember(&t->blocked, sig);
59931 + if (blocked || ignored) {
59932 + action->sa.sa_handler = SIG_DFL;
59933 + if (blocked) {
59934 + sigdelset(&t->blocked, sig);
59935 + recalc_sigpending_and_wake(t);
59936 + }
59937 + }
59938 + if (action->sa.sa_handler == SIG_DFL)
59939 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59940 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59941 +
59942 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59943 +
59944 + return ret;
59945 +}
59946 +#endif
59947 +
59948 +#ifdef CONFIG_GRKERNSEC_BRUTE
59949 +#define GR_USER_BAN_TIME (15 * 60)
59950 +
59951 +static int __get_dumpable(unsigned long mm_flags)
59952 +{
59953 + int ret;
59954 +
59955 + ret = mm_flags & MMF_DUMPABLE_MASK;
59956 + return (ret >= 2) ? 2 : ret;
59957 +}
59958 +#endif
59959 +
59960 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59961 +{
59962 +#ifdef CONFIG_GRKERNSEC_BRUTE
59963 + kuid_t uid = GLOBAL_ROOT_UID;
59964 +
59965 + if (!grsec_enable_brute)
59966 + return;
59967 +
59968 + rcu_read_lock();
59969 + read_lock(&tasklist_lock);
59970 + read_lock(&grsec_exec_file_lock);
59971 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59972 + p->real_parent->brute = 1;
59973 + else {
59974 + const struct cred *cred = __task_cred(p), *cred2;
59975 + struct task_struct *tsk, *tsk2;
59976 +
59977 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59978 + struct user_struct *user;
59979 +
59980 + uid = cred->uid;
59981 +
59982 + /* this is put upon execution past expiration */
59983 + user = find_user(uid);
59984 + if (user == NULL)
59985 + goto unlock;
59986 + user->banned = 1;
59987 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59988 + if (user->ban_expires == ~0UL)
59989 + user->ban_expires--;
59990 +
59991 + do_each_thread(tsk2, tsk) {
59992 + cred2 = __task_cred(tsk);
59993 + if (tsk != p && uid_eq(cred2->uid, uid))
59994 + gr_fake_force_sig(SIGKILL, tsk);
59995 + } while_each_thread(tsk2, tsk);
59996 + }
59997 + }
59998 +unlock:
59999 + read_unlock(&grsec_exec_file_lock);
60000 + read_unlock(&tasklist_lock);
60001 + rcu_read_unlock();
60002 +
60003 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
60004 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
60005 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
60006 +
60007 +#endif
60008 + return;
60009 +}
60010 +
60011 +void gr_handle_brute_check(void)
60012 +{
60013 +#ifdef CONFIG_GRKERNSEC_BRUTE
60014 + if (current->brute)
60015 + msleep(30 * 1000);
60016 +#endif
60017 + return;
60018 +}
60019 +
60020 +void gr_handle_kernel_exploit(void)
60021 +{
60022 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
60023 + const struct cred *cred;
60024 + struct task_struct *tsk, *tsk2;
60025 + struct user_struct *user;
60026 + kuid_t uid;
60027 +
60028 + if (in_irq() || in_serving_softirq() || in_nmi())
60029 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
60030 +
60031 + uid = current_uid();
60032 +
60033 + if (uid_eq(uid, GLOBAL_ROOT_UID))
60034 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
60035 + else {
60036 + /* kill all the processes of this user, hold a reference
60037 + to their creds struct, and prevent them from creating
60038 + another process until system reset
60039 + */
60040 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
60041 + from_kuid_munged(&init_user_ns, uid));
60042 + /* we intentionally leak this ref */
60043 + user = get_uid(current->cred->user);
60044 + if (user) {
60045 + user->banned = 1;
60046 + user->ban_expires = ~0UL;
60047 + }
60048 +
60049 + read_lock(&tasklist_lock);
60050 + do_each_thread(tsk2, tsk) {
60051 + cred = __task_cred(tsk);
60052 + if (uid_eq(cred->uid, uid))
60053 + gr_fake_force_sig(SIGKILL, tsk);
60054 + } while_each_thread(tsk2, tsk);
60055 + read_unlock(&tasklist_lock);
60056 + }
60057 +#endif
60058 +}
60059 +
60060 +int __gr_process_user_ban(struct user_struct *user)
60061 +{
60062 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60063 + if (unlikely(user->banned)) {
60064 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
60065 + user->banned = 0;
60066 + user->ban_expires = 0;
60067 + free_uid(user);
60068 + } else
60069 + return -EPERM;
60070 + }
60071 +#endif
60072 + return 0;
60073 +}
60074 +
60075 +int gr_process_user_ban(void)
60076 +{
60077 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60078 + return __gr_process_user_ban(current->cred->user);
60079 +#endif
60080 + return 0;
60081 +}
60082 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
60083 new file mode 100644
60084 index 0000000..4030d57
60085 --- /dev/null
60086 +++ b/grsecurity/grsec_sock.c
60087 @@ -0,0 +1,244 @@
60088 +#include <linux/kernel.h>
60089 +#include <linux/module.h>
60090 +#include <linux/sched.h>
60091 +#include <linux/file.h>
60092 +#include <linux/net.h>
60093 +#include <linux/in.h>
60094 +#include <linux/ip.h>
60095 +#include <net/sock.h>
60096 +#include <net/inet_sock.h>
60097 +#include <linux/grsecurity.h>
60098 +#include <linux/grinternal.h>
60099 +#include <linux/gracl.h>
60100 +
60101 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
60102 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
60103 +
60104 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
60105 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
60106 +
60107 +#ifdef CONFIG_UNIX_MODULE
60108 +EXPORT_SYMBOL(gr_acl_handle_unix);
60109 +EXPORT_SYMBOL(gr_acl_handle_mknod);
60110 +EXPORT_SYMBOL(gr_handle_chroot_unix);
60111 +EXPORT_SYMBOL(gr_handle_create);
60112 +#endif
60113 +
60114 +#ifdef CONFIG_GRKERNSEC
60115 +#define gr_conn_table_size 32749
60116 +struct conn_table_entry {
60117 + struct conn_table_entry *next;
60118 + struct signal_struct *sig;
60119 +};
60120 +
60121 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
60122 +DEFINE_SPINLOCK(gr_conn_table_lock);
60123 +
60124 +extern const char * gr_socktype_to_name(unsigned char type);
60125 +extern const char * gr_proto_to_name(unsigned char proto);
60126 +extern const char * gr_sockfamily_to_name(unsigned char family);
60127 +
60128 +static __inline__ int
60129 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
60130 +{
60131 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
60132 +}
60133 +
60134 +static __inline__ int
60135 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
60136 + __u16 sport, __u16 dport)
60137 +{
60138 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
60139 + sig->gr_sport == sport && sig->gr_dport == dport))
60140 + return 1;
60141 + else
60142 + return 0;
60143 +}
60144 +
60145 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
60146 +{
60147 + struct conn_table_entry **match;
60148 + unsigned int index;
60149 +
60150 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
60151 + sig->gr_sport, sig->gr_dport,
60152 + gr_conn_table_size);
60153 +
60154 + newent->sig = sig;
60155 +
60156 + match = &gr_conn_table[index];
60157 + newent->next = *match;
60158 + *match = newent;
60159 +
60160 + return;
60161 +}
60162 +
60163 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
60164 +{
60165 + struct conn_table_entry *match, *last = NULL;
60166 + unsigned int index;
60167 +
60168 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
60169 + sig->gr_sport, sig->gr_dport,
60170 + gr_conn_table_size);
60171 +
60172 + match = gr_conn_table[index];
60173 + while (match && !conn_match(match->sig,
60174 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
60175 + sig->gr_dport)) {
60176 + last = match;
60177 + match = match->next;
60178 + }
60179 +
60180 + if (match) {
60181 + if (last)
60182 + last->next = match->next;
60183 + else
60184 + gr_conn_table[index] = NULL;
60185 + kfree(match);
60186 + }
60187 +
60188 + return;
60189 +}
60190 +
60191 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
60192 + __u16 sport, __u16 dport)
60193 +{
60194 + struct conn_table_entry *match;
60195 + unsigned int index;
60196 +
60197 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
60198 +
60199 + match = gr_conn_table[index];
60200 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
60201 + match = match->next;
60202 +
60203 + if (match)
60204 + return match->sig;
60205 + else
60206 + return NULL;
60207 +}
60208 +
60209 +#endif
60210 +
60211 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
60212 +{
60213 +#ifdef CONFIG_GRKERNSEC
60214 + struct signal_struct *sig = task->signal;
60215 + struct conn_table_entry *newent;
60216 +
60217 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
60218 + if (newent == NULL)
60219 + return;
60220 + /* no bh lock needed since we are called with bh disabled */
60221 + spin_lock(&gr_conn_table_lock);
60222 + gr_del_task_from_ip_table_nolock(sig);
60223 + sig->gr_saddr = inet->inet_rcv_saddr;
60224 + sig->gr_daddr = inet->inet_daddr;
60225 + sig->gr_sport = inet->inet_sport;
60226 + sig->gr_dport = inet->inet_dport;
60227 + gr_add_to_task_ip_table_nolock(sig, newent);
60228 + spin_unlock(&gr_conn_table_lock);
60229 +#endif
60230 + return;
60231 +}
60232 +
60233 +void gr_del_task_from_ip_table(struct task_struct *task)
60234 +{
60235 +#ifdef CONFIG_GRKERNSEC
60236 + spin_lock_bh(&gr_conn_table_lock);
60237 + gr_del_task_from_ip_table_nolock(task->signal);
60238 + spin_unlock_bh(&gr_conn_table_lock);
60239 +#endif
60240 + return;
60241 +}
60242 +
60243 +void
60244 +gr_attach_curr_ip(const struct sock *sk)
60245 +{
60246 +#ifdef CONFIG_GRKERNSEC
60247 + struct signal_struct *p, *set;
60248 + const struct inet_sock *inet = inet_sk(sk);
60249 +
60250 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
60251 + return;
60252 +
60253 + set = current->signal;
60254 +
60255 + spin_lock_bh(&gr_conn_table_lock);
60256 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
60257 + inet->inet_dport, inet->inet_sport);
60258 + if (unlikely(p != NULL)) {
60259 + set->curr_ip = p->curr_ip;
60260 + set->used_accept = 1;
60261 + gr_del_task_from_ip_table_nolock(p);
60262 + spin_unlock_bh(&gr_conn_table_lock);
60263 + return;
60264 + }
60265 + spin_unlock_bh(&gr_conn_table_lock);
60266 +
60267 + set->curr_ip = inet->inet_daddr;
60268 + set->used_accept = 1;
60269 +#endif
60270 + return;
60271 +}
60272 +
60273 +int
60274 +gr_handle_sock_all(const int family, const int type, const int protocol)
60275 +{
60276 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60277 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
60278 + (family != AF_UNIX)) {
60279 + if (family == AF_INET)
60280 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
60281 + else
60282 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
60283 + return -EACCES;
60284 + }
60285 +#endif
60286 + return 0;
60287 +}
60288 +
60289 +int
60290 +gr_handle_sock_server(const struct sockaddr *sck)
60291 +{
60292 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60293 + if (grsec_enable_socket_server &&
60294 + in_group_p(grsec_socket_server_gid) &&
60295 + sck && (sck->sa_family != AF_UNIX) &&
60296 + (sck->sa_family != AF_LOCAL)) {
60297 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60298 + return -EACCES;
60299 + }
60300 +#endif
60301 + return 0;
60302 +}
60303 +
60304 +int
60305 +gr_handle_sock_server_other(const struct sock *sck)
60306 +{
60307 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60308 + if (grsec_enable_socket_server &&
60309 + in_group_p(grsec_socket_server_gid) &&
60310 + sck && (sck->sk_family != AF_UNIX) &&
60311 + (sck->sk_family != AF_LOCAL)) {
60312 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60313 + return -EACCES;
60314 + }
60315 +#endif
60316 + return 0;
60317 +}
60318 +
60319 +int
60320 +gr_handle_sock_client(const struct sockaddr *sck)
60321 +{
60322 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60323 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
60324 + sck && (sck->sa_family != AF_UNIX) &&
60325 + (sck->sa_family != AF_LOCAL)) {
60326 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
60327 + return -EACCES;
60328 + }
60329 +#endif
60330 + return 0;
60331 +}
60332 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
60333 new file mode 100644
60334 index 0000000..f55ef0f
60335 --- /dev/null
60336 +++ b/grsecurity/grsec_sysctl.c
60337 @@ -0,0 +1,469 @@
60338 +#include <linux/kernel.h>
60339 +#include <linux/sched.h>
60340 +#include <linux/sysctl.h>
60341 +#include <linux/grsecurity.h>
60342 +#include <linux/grinternal.h>
60343 +
60344 +int
60345 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
60346 +{
60347 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60348 + if (dirname == NULL || name == NULL)
60349 + return 0;
60350 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
60351 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
60352 + return -EACCES;
60353 + }
60354 +#endif
60355 + return 0;
60356 +}
60357 +
60358 +#ifdef CONFIG_GRKERNSEC_ROFS
60359 +static int __maybe_unused one = 1;
60360 +#endif
60361 +
60362 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
60363 +struct ctl_table grsecurity_table[] = {
60364 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60365 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
60366 +#ifdef CONFIG_GRKERNSEC_IO
60367 + {
60368 + .procname = "disable_priv_io",
60369 + .data = &grsec_disable_privio,
60370 + .maxlen = sizeof(int),
60371 + .mode = 0600,
60372 + .proc_handler = &proc_dointvec,
60373 + },
60374 +#endif
60375 +#endif
60376 +#ifdef CONFIG_GRKERNSEC_LINK
60377 + {
60378 + .procname = "linking_restrictions",
60379 + .data = &grsec_enable_link,
60380 + .maxlen = sizeof(int),
60381 + .mode = 0600,
60382 + .proc_handler = &proc_dointvec,
60383 + },
60384 +#endif
60385 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60386 + {
60387 + .procname = "enforce_symlinksifowner",
60388 + .data = &grsec_enable_symlinkown,
60389 + .maxlen = sizeof(int),
60390 + .mode = 0600,
60391 + .proc_handler = &proc_dointvec,
60392 + },
60393 + {
60394 + .procname = "symlinkown_gid",
60395 + .data = &grsec_symlinkown_gid,
60396 + .maxlen = sizeof(int),
60397 + .mode = 0600,
60398 + .proc_handler = &proc_dointvec,
60399 + },
60400 +#endif
60401 +#ifdef CONFIG_GRKERNSEC_BRUTE
60402 + {
60403 + .procname = "deter_bruteforce",
60404 + .data = &grsec_enable_brute,
60405 + .maxlen = sizeof(int),
60406 + .mode = 0600,
60407 + .proc_handler = &proc_dointvec,
60408 + },
60409 +#endif
60410 +#ifdef CONFIG_GRKERNSEC_FIFO
60411 + {
60412 + .procname = "fifo_restrictions",
60413 + .data = &grsec_enable_fifo,
60414 + .maxlen = sizeof(int),
60415 + .mode = 0600,
60416 + .proc_handler = &proc_dointvec,
60417 + },
60418 +#endif
60419 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60420 + {
60421 + .procname = "ptrace_readexec",
60422 + .data = &grsec_enable_ptrace_readexec,
60423 + .maxlen = sizeof(int),
60424 + .mode = 0600,
60425 + .proc_handler = &proc_dointvec,
60426 + },
60427 +#endif
60428 +#ifdef CONFIG_GRKERNSEC_SETXID
60429 + {
60430 + .procname = "consistent_setxid",
60431 + .data = &grsec_enable_setxid,
60432 + .maxlen = sizeof(int),
60433 + .mode = 0600,
60434 + .proc_handler = &proc_dointvec,
60435 + },
60436 +#endif
60437 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60438 + {
60439 + .procname = "ip_blackhole",
60440 + .data = &grsec_enable_blackhole,
60441 + .maxlen = sizeof(int),
60442 + .mode = 0600,
60443 + .proc_handler = &proc_dointvec,
60444 + },
60445 + {
60446 + .procname = "lastack_retries",
60447 + .data = &grsec_lastack_retries,
60448 + .maxlen = sizeof(int),
60449 + .mode = 0600,
60450 + .proc_handler = &proc_dointvec,
60451 + },
60452 +#endif
60453 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60454 + {
60455 + .procname = "exec_logging",
60456 + .data = &grsec_enable_execlog,
60457 + .maxlen = sizeof(int),
60458 + .mode = 0600,
60459 + .proc_handler = &proc_dointvec,
60460 + },
60461 +#endif
60462 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60463 + {
60464 + .procname = "rwxmap_logging",
60465 + .data = &grsec_enable_log_rwxmaps,
60466 + .maxlen = sizeof(int),
60467 + .mode = 0600,
60468 + .proc_handler = &proc_dointvec,
60469 + },
60470 +#endif
60471 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60472 + {
60473 + .procname = "signal_logging",
60474 + .data = &grsec_enable_signal,
60475 + .maxlen = sizeof(int),
60476 + .mode = 0600,
60477 + .proc_handler = &proc_dointvec,
60478 + },
60479 +#endif
60480 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60481 + {
60482 + .procname = "forkfail_logging",
60483 + .data = &grsec_enable_forkfail,
60484 + .maxlen = sizeof(int),
60485 + .mode = 0600,
60486 + .proc_handler = &proc_dointvec,
60487 + },
60488 +#endif
60489 +#ifdef CONFIG_GRKERNSEC_TIME
60490 + {
60491 + .procname = "timechange_logging",
60492 + .data = &grsec_enable_time,
60493 + .maxlen = sizeof(int),
60494 + .mode = 0600,
60495 + .proc_handler = &proc_dointvec,
60496 + },
60497 +#endif
60498 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60499 + {
60500 + .procname = "chroot_deny_shmat",
60501 + .data = &grsec_enable_chroot_shmat,
60502 + .maxlen = sizeof(int),
60503 + .mode = 0600,
60504 + .proc_handler = &proc_dointvec,
60505 + },
60506 +#endif
60507 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60508 + {
60509 + .procname = "chroot_deny_unix",
60510 + .data = &grsec_enable_chroot_unix,
60511 + .maxlen = sizeof(int),
60512 + .mode = 0600,
60513 + .proc_handler = &proc_dointvec,
60514 + },
60515 +#endif
60516 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60517 + {
60518 + .procname = "chroot_deny_mount",
60519 + .data = &grsec_enable_chroot_mount,
60520 + .maxlen = sizeof(int),
60521 + .mode = 0600,
60522 + .proc_handler = &proc_dointvec,
60523 + },
60524 +#endif
60525 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60526 + {
60527 + .procname = "chroot_deny_fchdir",
60528 + .data = &grsec_enable_chroot_fchdir,
60529 + .maxlen = sizeof(int),
60530 + .mode = 0600,
60531 + .proc_handler = &proc_dointvec,
60532 + },
60533 +#endif
60534 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60535 + {
60536 + .procname = "chroot_deny_chroot",
60537 + .data = &grsec_enable_chroot_double,
60538 + .maxlen = sizeof(int),
60539 + .mode = 0600,
60540 + .proc_handler = &proc_dointvec,
60541 + },
60542 +#endif
60543 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60544 + {
60545 + .procname = "chroot_deny_pivot",
60546 + .data = &grsec_enable_chroot_pivot,
60547 + .maxlen = sizeof(int),
60548 + .mode = 0600,
60549 + .proc_handler = &proc_dointvec,
60550 + },
60551 +#endif
60552 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60553 + {
60554 + .procname = "chroot_enforce_chdir",
60555 + .data = &grsec_enable_chroot_chdir,
60556 + .maxlen = sizeof(int),
60557 + .mode = 0600,
60558 + .proc_handler = &proc_dointvec,
60559 + },
60560 +#endif
60561 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60562 + {
60563 + .procname = "chroot_deny_chmod",
60564 + .data = &grsec_enable_chroot_chmod,
60565 + .maxlen = sizeof(int),
60566 + .mode = 0600,
60567 + .proc_handler = &proc_dointvec,
60568 + },
60569 +#endif
60570 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60571 + {
60572 + .procname = "chroot_deny_mknod",
60573 + .data = &grsec_enable_chroot_mknod,
60574 + .maxlen = sizeof(int),
60575 + .mode = 0600,
60576 + .proc_handler = &proc_dointvec,
60577 + },
60578 +#endif
60579 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60580 + {
60581 + .procname = "chroot_restrict_nice",
60582 + .data = &grsec_enable_chroot_nice,
60583 + .maxlen = sizeof(int),
60584 + .mode = 0600,
60585 + .proc_handler = &proc_dointvec,
60586 + },
60587 +#endif
60588 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60589 + {
60590 + .procname = "chroot_execlog",
60591 + .data = &grsec_enable_chroot_execlog,
60592 + .maxlen = sizeof(int),
60593 + .mode = 0600,
60594 + .proc_handler = &proc_dointvec,
60595 + },
60596 +#endif
60597 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60598 + {
60599 + .procname = "chroot_caps",
60600 + .data = &grsec_enable_chroot_caps,
60601 + .maxlen = sizeof(int),
60602 + .mode = 0600,
60603 + .proc_handler = &proc_dointvec,
60604 + },
60605 +#endif
60606 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60607 + {
60608 + .procname = "chroot_deny_sysctl",
60609 + .data = &grsec_enable_chroot_sysctl,
60610 + .maxlen = sizeof(int),
60611 + .mode = 0600,
60612 + .proc_handler = &proc_dointvec,
60613 + },
60614 +#endif
60615 +#ifdef CONFIG_GRKERNSEC_TPE
60616 + {
60617 + .procname = "tpe",
60618 + .data = &grsec_enable_tpe,
60619 + .maxlen = sizeof(int),
60620 + .mode = 0600,
60621 + .proc_handler = &proc_dointvec,
60622 + },
60623 + {
60624 + .procname = "tpe_gid",
60625 + .data = &grsec_tpe_gid,
60626 + .maxlen = sizeof(int),
60627 + .mode = 0600,
60628 + .proc_handler = &proc_dointvec,
60629 + },
60630 +#endif
60631 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60632 + {
60633 + .procname = "tpe_invert",
60634 + .data = &grsec_enable_tpe_invert,
60635 + .maxlen = sizeof(int),
60636 + .mode = 0600,
60637 + .proc_handler = &proc_dointvec,
60638 + },
60639 +#endif
60640 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60641 + {
60642 + .procname = "tpe_restrict_all",
60643 + .data = &grsec_enable_tpe_all,
60644 + .maxlen = sizeof(int),
60645 + .mode = 0600,
60646 + .proc_handler = &proc_dointvec,
60647 + },
60648 +#endif
60649 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60650 + {
60651 + .procname = "socket_all",
60652 + .data = &grsec_enable_socket_all,
60653 + .maxlen = sizeof(int),
60654 + .mode = 0600,
60655 + .proc_handler = &proc_dointvec,
60656 + },
60657 + {
60658 + .procname = "socket_all_gid",
60659 + .data = &grsec_socket_all_gid,
60660 + .maxlen = sizeof(int),
60661 + .mode = 0600,
60662 + .proc_handler = &proc_dointvec,
60663 + },
60664 +#endif
60665 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60666 + {
60667 + .procname = "socket_client",
60668 + .data = &grsec_enable_socket_client,
60669 + .maxlen = sizeof(int),
60670 + .mode = 0600,
60671 + .proc_handler = &proc_dointvec,
60672 + },
60673 + {
60674 + .procname = "socket_client_gid",
60675 + .data = &grsec_socket_client_gid,
60676 + .maxlen = sizeof(int),
60677 + .mode = 0600,
60678 + .proc_handler = &proc_dointvec,
60679 + },
60680 +#endif
60681 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60682 + {
60683 + .procname = "socket_server",
60684 + .data = &grsec_enable_socket_server,
60685 + .maxlen = sizeof(int),
60686 + .mode = 0600,
60687 + .proc_handler = &proc_dointvec,
60688 + },
60689 + {
60690 + .procname = "socket_server_gid",
60691 + .data = &grsec_socket_server_gid,
60692 + .maxlen = sizeof(int),
60693 + .mode = 0600,
60694 + .proc_handler = &proc_dointvec,
60695 + },
60696 +#endif
60697 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60698 + {
60699 + .procname = "audit_group",
60700 + .data = &grsec_enable_group,
60701 + .maxlen = sizeof(int),
60702 + .mode = 0600,
60703 + .proc_handler = &proc_dointvec,
60704 + },
60705 + {
60706 + .procname = "audit_gid",
60707 + .data = &grsec_audit_gid,
60708 + .maxlen = sizeof(int),
60709 + .mode = 0600,
60710 + .proc_handler = &proc_dointvec,
60711 + },
60712 +#endif
60713 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60714 + {
60715 + .procname = "audit_chdir",
60716 + .data = &grsec_enable_chdir,
60717 + .maxlen = sizeof(int),
60718 + .mode = 0600,
60719 + .proc_handler = &proc_dointvec,
60720 + },
60721 +#endif
60722 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60723 + {
60724 + .procname = "audit_mount",
60725 + .data = &grsec_enable_mount,
60726 + .maxlen = sizeof(int),
60727 + .mode = 0600,
60728 + .proc_handler = &proc_dointvec,
60729 + },
60730 +#endif
60731 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60732 + {
60733 + .procname = "audit_textrel",
60734 + .data = &grsec_enable_audit_textrel,
60735 + .maxlen = sizeof(int),
60736 + .mode = 0600,
60737 + .proc_handler = &proc_dointvec,
60738 + },
60739 +#endif
60740 +#ifdef CONFIG_GRKERNSEC_DMESG
60741 + {
60742 + .procname = "dmesg",
60743 + .data = &grsec_enable_dmesg,
60744 + .maxlen = sizeof(int),
60745 + .mode = 0600,
60746 + .proc_handler = &proc_dointvec,
60747 + },
60748 +#endif
60749 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60750 + {
60751 + .procname = "chroot_findtask",
60752 + .data = &grsec_enable_chroot_findtask,
60753 + .maxlen = sizeof(int),
60754 + .mode = 0600,
60755 + .proc_handler = &proc_dointvec,
60756 + },
60757 +#endif
60758 +#ifdef CONFIG_GRKERNSEC_RESLOG
60759 + {
60760 + .procname = "resource_logging",
60761 + .data = &grsec_resource_logging,
60762 + .maxlen = sizeof(int),
60763 + .mode = 0600,
60764 + .proc_handler = &proc_dointvec,
60765 + },
60766 +#endif
60767 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60768 + {
60769 + .procname = "audit_ptrace",
60770 + .data = &grsec_enable_audit_ptrace,
60771 + .maxlen = sizeof(int),
60772 + .mode = 0600,
60773 + .proc_handler = &proc_dointvec,
60774 + },
60775 +#endif
60776 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60777 + {
60778 + .procname = "harden_ptrace",
60779 + .data = &grsec_enable_harden_ptrace,
60780 + .maxlen = sizeof(int),
60781 + .mode = 0600,
60782 + .proc_handler = &proc_dointvec,
60783 + },
60784 +#endif
60785 + {
60786 + .procname = "grsec_lock",
60787 + .data = &grsec_lock,
60788 + .maxlen = sizeof(int),
60789 + .mode = 0600,
60790 + .proc_handler = &proc_dointvec,
60791 + },
60792 +#endif
60793 +#ifdef CONFIG_GRKERNSEC_ROFS
60794 + {
60795 + .procname = "romount_protect",
60796 + .data = &grsec_enable_rofs,
60797 + .maxlen = sizeof(int),
60798 + .mode = 0600,
60799 + .proc_handler = &proc_dointvec_minmax,
60800 + .extra1 = &one,
60801 + .extra2 = &one,
60802 + },
60803 +#endif
60804 + { }
60805 +};
60806 +#endif
60807 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60808 new file mode 100644
60809 index 0000000..0dc13c3
60810 --- /dev/null
60811 +++ b/grsecurity/grsec_time.c
60812 @@ -0,0 +1,16 @@
60813 +#include <linux/kernel.h>
60814 +#include <linux/sched.h>
60815 +#include <linux/grinternal.h>
60816 +#include <linux/module.h>
60817 +
60818 +void
60819 +gr_log_timechange(void)
60820 +{
60821 +#ifdef CONFIG_GRKERNSEC_TIME
60822 + if (grsec_enable_time)
60823 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60824 +#endif
60825 + return;
60826 +}
60827 +
60828 +EXPORT_SYMBOL(gr_log_timechange);
60829 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60830 new file mode 100644
60831 index 0000000..07e0dc0
60832 --- /dev/null
60833 +++ b/grsecurity/grsec_tpe.c
60834 @@ -0,0 +1,73 @@
60835 +#include <linux/kernel.h>
60836 +#include <linux/sched.h>
60837 +#include <linux/file.h>
60838 +#include <linux/fs.h>
60839 +#include <linux/grinternal.h>
60840 +
60841 +extern int gr_acl_tpe_check(void);
60842 +
60843 +int
60844 +gr_tpe_allow(const struct file *file)
60845 +{
60846 +#ifdef CONFIG_GRKERNSEC
60847 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60848 + const struct cred *cred = current_cred();
60849 + char *msg = NULL;
60850 + char *msg2 = NULL;
60851 +
60852 + // never restrict root
60853 + if (!cred->uid)
60854 + return 1;
60855 +
60856 + if (grsec_enable_tpe) {
60857 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60858 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60859 + msg = "not being in trusted group";
60860 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60861 + msg = "being in untrusted group";
60862 +#else
60863 + if (in_group_p(grsec_tpe_gid))
60864 + msg = "being in untrusted group";
60865 +#endif
60866 + }
60867 + if (!msg && gr_acl_tpe_check())
60868 + msg = "being in untrusted role";
60869 +
60870 + // not in any affected group/role
60871 + if (!msg)
60872 + goto next_check;
60873 +
60874 + if (inode->i_uid)
60875 + msg2 = "file in non-root-owned directory";
60876 + else if (inode->i_mode & S_IWOTH)
60877 + msg2 = "file in world-writable directory";
60878 + else if (inode->i_mode & S_IWGRP)
60879 + msg2 = "file in group-writable directory";
60880 +
60881 + if (msg && msg2) {
60882 + char fullmsg[70] = {0};
60883 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60884 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60885 + return 0;
60886 + }
60887 + msg = NULL;
60888 +next_check:
60889 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60890 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60891 + return 1;
60892 +
60893 + if (inode->i_uid && (inode->i_uid != cred->uid))
60894 + msg = "directory not owned by user";
60895 + else if (inode->i_mode & S_IWOTH)
60896 + msg = "file in world-writable directory";
60897 + else if (inode->i_mode & S_IWGRP)
60898 + msg = "file in group-writable directory";
60899 +
60900 + if (msg) {
60901 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60902 + return 0;
60903 + }
60904 +#endif
60905 +#endif
60906 + return 1;
60907 +}
60908 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60909 new file mode 100644
60910 index 0000000..9f7b1ac
60911 --- /dev/null
60912 +++ b/grsecurity/grsum.c
60913 @@ -0,0 +1,61 @@
60914 +#include <linux/err.h>
60915 +#include <linux/kernel.h>
60916 +#include <linux/sched.h>
60917 +#include <linux/mm.h>
60918 +#include <linux/scatterlist.h>
60919 +#include <linux/crypto.h>
60920 +#include <linux/gracl.h>
60921 +
60922 +
60923 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60924 +#error "crypto and sha256 must be built into the kernel"
60925 +#endif
60926 +
60927 +int
60928 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60929 +{
60930 + char *p;
60931 + struct crypto_hash *tfm;
60932 + struct hash_desc desc;
60933 + struct scatterlist sg;
60934 + unsigned char temp_sum[GR_SHA_LEN];
60935 + volatile int retval = 0;
60936 + volatile int dummy = 0;
60937 + unsigned int i;
60938 +
60939 + sg_init_table(&sg, 1);
60940 +
60941 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60942 + if (IS_ERR(tfm)) {
60943 + /* should never happen, since sha256 should be built in */
60944 + return 1;
60945 + }
60946 +
60947 + desc.tfm = tfm;
60948 + desc.flags = 0;
60949 +
60950 + crypto_hash_init(&desc);
60951 +
60952 + p = salt;
60953 + sg_set_buf(&sg, p, GR_SALT_LEN);
60954 + crypto_hash_update(&desc, &sg, sg.length);
60955 +
60956 + p = entry->pw;
60957 + sg_set_buf(&sg, p, strlen(p));
60958 +
60959 + crypto_hash_update(&desc, &sg, sg.length);
60960 +
60961 + crypto_hash_final(&desc, temp_sum);
60962 +
60963 + memset(entry->pw, 0, GR_PW_LEN);
60964 +
60965 + for (i = 0; i < GR_SHA_LEN; i++)
60966 + if (sum[i] != temp_sum[i])
60967 + retval = 1;
60968 + else
60969 + dummy = 1; // waste a cycle
60970 +
60971 + crypto_free_hash(tfm);
60972 +
60973 + return retval;
60974 +}
60975 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60976 index bde976e..a1cc32a 100644
60977 --- a/include/acpi/acpi_bus.h
60978 +++ b/include/acpi/acpi_bus.h
60979 @@ -136,7 +136,7 @@ struct acpi_device_ops {
60980 acpi_op_bind bind;
60981 acpi_op_unbind unbind;
60982 acpi_op_notify notify;
60983 -};
60984 +} __no_const;
60985
60986 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60987
60988 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60989 index 77ff547..181834f 100644
60990 --- a/include/asm-generic/4level-fixup.h
60991 +++ b/include/asm-generic/4level-fixup.h
60992 @@ -13,8 +13,10 @@
60993 #define pmd_alloc(mm, pud, address) \
60994 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60995 NULL: pmd_offset(pud, address))
60996 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60997
60998 #define pud_alloc(mm, pgd, address) (pgd)
60999 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
61000 #define pud_offset(pgd, start) (pgd)
61001 #define pud_none(pud) 0
61002 #define pud_bad(pud) 0
61003 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
61004 index b7babf0..3ba8aee 100644
61005 --- a/include/asm-generic/atomic-long.h
61006 +++ b/include/asm-generic/atomic-long.h
61007 @@ -22,6 +22,12 @@
61008
61009 typedef atomic64_t atomic_long_t;
61010
61011 +#ifdef CONFIG_PAX_REFCOUNT
61012 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
61013 +#else
61014 +typedef atomic64_t atomic_long_unchecked_t;
61015 +#endif
61016 +
61017 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
61018
61019 static inline long atomic_long_read(atomic_long_t *l)
61020 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
61021 return (long)atomic64_read(v);
61022 }
61023
61024 +#ifdef CONFIG_PAX_REFCOUNT
61025 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61026 +{
61027 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61028 +
61029 + return (long)atomic64_read_unchecked(v);
61030 +}
61031 +#endif
61032 +
61033 static inline void atomic_long_set(atomic_long_t *l, long i)
61034 {
61035 atomic64_t *v = (atomic64_t *)l;
61036 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
61037 atomic64_set(v, i);
61038 }
61039
61040 +#ifdef CONFIG_PAX_REFCOUNT
61041 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61042 +{
61043 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61044 +
61045 + atomic64_set_unchecked(v, i);
61046 +}
61047 +#endif
61048 +
61049 static inline void atomic_long_inc(atomic_long_t *l)
61050 {
61051 atomic64_t *v = (atomic64_t *)l;
61052 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
61053 atomic64_inc(v);
61054 }
61055
61056 +#ifdef CONFIG_PAX_REFCOUNT
61057 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61058 +{
61059 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61060 +
61061 + atomic64_inc_unchecked(v);
61062 +}
61063 +#endif
61064 +
61065 static inline void atomic_long_dec(atomic_long_t *l)
61066 {
61067 atomic64_t *v = (atomic64_t *)l;
61068 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
61069 atomic64_dec(v);
61070 }
61071
61072 +#ifdef CONFIG_PAX_REFCOUNT
61073 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61074 +{
61075 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61076 +
61077 + atomic64_dec_unchecked(v);
61078 +}
61079 +#endif
61080 +
61081 static inline void atomic_long_add(long i, atomic_long_t *l)
61082 {
61083 atomic64_t *v = (atomic64_t *)l;
61084 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
61085 atomic64_add(i, v);
61086 }
61087
61088 +#ifdef CONFIG_PAX_REFCOUNT
61089 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61090 +{
61091 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61092 +
61093 + atomic64_add_unchecked(i, v);
61094 +}
61095 +#endif
61096 +
61097 static inline void atomic_long_sub(long i, atomic_long_t *l)
61098 {
61099 atomic64_t *v = (atomic64_t *)l;
61100 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
61101 atomic64_sub(i, v);
61102 }
61103
61104 +#ifdef CONFIG_PAX_REFCOUNT
61105 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61106 +{
61107 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61108 +
61109 + atomic64_sub_unchecked(i, v);
61110 +}
61111 +#endif
61112 +
61113 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61114 {
61115 atomic64_t *v = (atomic64_t *)l;
61116 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
61117 return (long)atomic64_inc_return(v);
61118 }
61119
61120 +#ifdef CONFIG_PAX_REFCOUNT
61121 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61122 +{
61123 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61124 +
61125 + return (long)atomic64_inc_return_unchecked(v);
61126 +}
61127 +#endif
61128 +
61129 static inline long atomic_long_dec_return(atomic_long_t *l)
61130 {
61131 atomic64_t *v = (atomic64_t *)l;
61132 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
61133
61134 typedef atomic_t atomic_long_t;
61135
61136 +#ifdef CONFIG_PAX_REFCOUNT
61137 +typedef atomic_unchecked_t atomic_long_unchecked_t;
61138 +#else
61139 +typedef atomic_t atomic_long_unchecked_t;
61140 +#endif
61141 +
61142 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
61143 static inline long atomic_long_read(atomic_long_t *l)
61144 {
61145 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
61146 return (long)atomic_read(v);
61147 }
61148
61149 +#ifdef CONFIG_PAX_REFCOUNT
61150 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61151 +{
61152 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61153 +
61154 + return (long)atomic_read_unchecked(v);
61155 +}
61156 +#endif
61157 +
61158 static inline void atomic_long_set(atomic_long_t *l, long i)
61159 {
61160 atomic_t *v = (atomic_t *)l;
61161 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
61162 atomic_set(v, i);
61163 }
61164
61165 +#ifdef CONFIG_PAX_REFCOUNT
61166 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61167 +{
61168 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61169 +
61170 + atomic_set_unchecked(v, i);
61171 +}
61172 +#endif
61173 +
61174 static inline void atomic_long_inc(atomic_long_t *l)
61175 {
61176 atomic_t *v = (atomic_t *)l;
61177 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
61178 atomic_inc(v);
61179 }
61180
61181 +#ifdef CONFIG_PAX_REFCOUNT
61182 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61183 +{
61184 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61185 +
61186 + atomic_inc_unchecked(v);
61187 +}
61188 +#endif
61189 +
61190 static inline void atomic_long_dec(atomic_long_t *l)
61191 {
61192 atomic_t *v = (atomic_t *)l;
61193 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
61194 atomic_dec(v);
61195 }
61196
61197 +#ifdef CONFIG_PAX_REFCOUNT
61198 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61199 +{
61200 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61201 +
61202 + atomic_dec_unchecked(v);
61203 +}
61204 +#endif
61205 +
61206 static inline void atomic_long_add(long i, atomic_long_t *l)
61207 {
61208 atomic_t *v = (atomic_t *)l;
61209 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
61210 atomic_add(i, v);
61211 }
61212
61213 +#ifdef CONFIG_PAX_REFCOUNT
61214 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61215 +{
61216 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61217 +
61218 + atomic_add_unchecked(i, v);
61219 +}
61220 +#endif
61221 +
61222 static inline void atomic_long_sub(long i, atomic_long_t *l)
61223 {
61224 atomic_t *v = (atomic_t *)l;
61225 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
61226 atomic_sub(i, v);
61227 }
61228
61229 +#ifdef CONFIG_PAX_REFCOUNT
61230 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61231 +{
61232 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61233 +
61234 + atomic_sub_unchecked(i, v);
61235 +}
61236 +#endif
61237 +
61238 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61239 {
61240 atomic_t *v = (atomic_t *)l;
61241 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
61242 return (long)atomic_inc_return(v);
61243 }
61244
61245 +#ifdef CONFIG_PAX_REFCOUNT
61246 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61247 +{
61248 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61249 +
61250 + return (long)atomic_inc_return_unchecked(v);
61251 +}
61252 +#endif
61253 +
61254 static inline long atomic_long_dec_return(atomic_long_t *l)
61255 {
61256 atomic_t *v = (atomic_t *)l;
61257 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
61258
61259 #endif /* BITS_PER_LONG == 64 */
61260
61261 +#ifdef CONFIG_PAX_REFCOUNT
61262 +static inline void pax_refcount_needs_these_functions(void)
61263 +{
61264 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
61265 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
61266 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
61267 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
61268 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
61269 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
61270 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
61271 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
61272 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
61273 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
61274 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
61275 +#ifdef CONFIG_X86
61276 + atomic_clear_mask_unchecked(0, NULL);
61277 + atomic_set_mask_unchecked(0, NULL);
61278 +#endif
61279 +
61280 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
61281 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
61282 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
61283 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
61284 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
61285 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
61286 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
61287 +}
61288 +#else
61289 +#define atomic_read_unchecked(v) atomic_read(v)
61290 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
61291 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
61292 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
61293 +#define atomic_inc_unchecked(v) atomic_inc(v)
61294 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
61295 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
61296 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
61297 +#define atomic_dec_unchecked(v) atomic_dec(v)
61298 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
61299 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
61300 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
61301 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
61302 +
61303 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
61304 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
61305 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
61306 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
61307 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
61308 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
61309 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
61310 +#endif
61311 +
61312 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
61313 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
61314 index 1ced641..c896ee8 100644
61315 --- a/include/asm-generic/atomic.h
61316 +++ b/include/asm-generic/atomic.h
61317 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
61318 * Atomically clears the bits set in @mask from @v
61319 */
61320 #ifndef atomic_clear_mask
61321 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
61322 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
61323 {
61324 unsigned long flags;
61325
61326 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
61327 index b18ce4f..2ee2843 100644
61328 --- a/include/asm-generic/atomic64.h
61329 +++ b/include/asm-generic/atomic64.h
61330 @@ -16,6 +16,8 @@ typedef struct {
61331 long long counter;
61332 } atomic64_t;
61333
61334 +typedef atomic64_t atomic64_unchecked_t;
61335 +
61336 #define ATOMIC64_INIT(i) { (i) }
61337
61338 extern long long atomic64_read(const atomic64_t *v);
61339 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
61340 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
61341 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
61342
61343 +#define atomic64_read_unchecked(v) atomic64_read(v)
61344 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
61345 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
61346 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
61347 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
61348 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
61349 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
61350 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
61351 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
61352 +
61353 #endif /* _ASM_GENERIC_ATOMIC64_H */
61354 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
61355 index 1bfcfe5..e04c5c9 100644
61356 --- a/include/asm-generic/cache.h
61357 +++ b/include/asm-generic/cache.h
61358 @@ -6,7 +6,7 @@
61359 * cache lines need to provide their own cache.h.
61360 */
61361
61362 -#define L1_CACHE_SHIFT 5
61363 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61364 +#define L1_CACHE_SHIFT 5UL
61365 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
61366
61367 #endif /* __ASM_GENERIC_CACHE_H */
61368 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
61369 index 0d68a1e..b74a761 100644
61370 --- a/include/asm-generic/emergency-restart.h
61371 +++ b/include/asm-generic/emergency-restart.h
61372 @@ -1,7 +1,7 @@
61373 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
61374 #define _ASM_GENERIC_EMERGENCY_RESTART_H
61375
61376 -static inline void machine_emergency_restart(void)
61377 +static inline __noreturn void machine_emergency_restart(void)
61378 {
61379 machine_restart(NULL);
61380 }
61381 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
61382 index 90f99c7..00ce236 100644
61383 --- a/include/asm-generic/kmap_types.h
61384 +++ b/include/asm-generic/kmap_types.h
61385 @@ -2,9 +2,9 @@
61386 #define _ASM_GENERIC_KMAP_TYPES_H
61387
61388 #ifdef __WITH_KM_FENCE
61389 -# define KM_TYPE_NR 41
61390 +# define KM_TYPE_NR 42
61391 #else
61392 -# define KM_TYPE_NR 20
61393 +# define KM_TYPE_NR 21
61394 #endif
61395
61396 #endif
61397 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
61398 index 9ceb03b..2efbcbd 100644
61399 --- a/include/asm-generic/local.h
61400 +++ b/include/asm-generic/local.h
61401 @@ -39,6 +39,7 @@ typedef struct
61402 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
61403 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
61404 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
61405 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
61406
61407 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
61408 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
61409 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
61410 index 725612b..9cc513a 100644
61411 --- a/include/asm-generic/pgtable-nopmd.h
61412 +++ b/include/asm-generic/pgtable-nopmd.h
61413 @@ -1,14 +1,19 @@
61414 #ifndef _PGTABLE_NOPMD_H
61415 #define _PGTABLE_NOPMD_H
61416
61417 -#ifndef __ASSEMBLY__
61418 -
61419 #include <asm-generic/pgtable-nopud.h>
61420
61421 -struct mm_struct;
61422 -
61423 #define __PAGETABLE_PMD_FOLDED
61424
61425 +#define PMD_SHIFT PUD_SHIFT
61426 +#define PTRS_PER_PMD 1
61427 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61428 +#define PMD_MASK (~(PMD_SIZE-1))
61429 +
61430 +#ifndef __ASSEMBLY__
61431 +
61432 +struct mm_struct;
61433 +
61434 /*
61435 * Having the pmd type consist of a pud gets the size right, and allows
61436 * us to conceptually access the pud entry that this pmd is folded into
61437 @@ -16,11 +21,6 @@ struct mm_struct;
61438 */
61439 typedef struct { pud_t pud; } pmd_t;
61440
61441 -#define PMD_SHIFT PUD_SHIFT
61442 -#define PTRS_PER_PMD 1
61443 -#define PMD_SIZE (1UL << PMD_SHIFT)
61444 -#define PMD_MASK (~(PMD_SIZE-1))
61445 -
61446 /*
61447 * The "pud_xxx()" functions here are trivial for a folded two-level
61448 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61449 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
61450 index 810431d..0ec4804f 100644
61451 --- a/include/asm-generic/pgtable-nopud.h
61452 +++ b/include/asm-generic/pgtable-nopud.h
61453 @@ -1,10 +1,15 @@
61454 #ifndef _PGTABLE_NOPUD_H
61455 #define _PGTABLE_NOPUD_H
61456
61457 -#ifndef __ASSEMBLY__
61458 -
61459 #define __PAGETABLE_PUD_FOLDED
61460
61461 +#define PUD_SHIFT PGDIR_SHIFT
61462 +#define PTRS_PER_PUD 1
61463 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61464 +#define PUD_MASK (~(PUD_SIZE-1))
61465 +
61466 +#ifndef __ASSEMBLY__
61467 +
61468 /*
61469 * Having the pud type consist of a pgd gets the size right, and allows
61470 * us to conceptually access the pgd entry that this pud is folded into
61471 @@ -12,11 +17,6 @@
61472 */
61473 typedef struct { pgd_t pgd; } pud_t;
61474
61475 -#define PUD_SHIFT PGDIR_SHIFT
61476 -#define PTRS_PER_PUD 1
61477 -#define PUD_SIZE (1UL << PUD_SHIFT)
61478 -#define PUD_MASK (~(PUD_SIZE-1))
61479 -
61480 /*
61481 * The "pgd_xxx()" functions here are trivial for a folded two-level
61482 * setup: the pud is never bad, and a pud always exists (as it's folded
61483 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61484 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61485
61486 #define pgd_populate(mm, pgd, pud) do { } while (0)
61487 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61488 /*
61489 * (puds are folded into pgds so this doesn't get actually called,
61490 * but the define is needed for a generic inline function.)
61491 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61492 index ff4947b..f48183f 100644
61493 --- a/include/asm-generic/pgtable.h
61494 +++ b/include/asm-generic/pgtable.h
61495 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61496 #endif
61497 }
61498
61499 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61500 +static inline unsigned long pax_open_kernel(void) { return 0; }
61501 +#endif
61502 +
61503 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61504 +static inline unsigned long pax_close_kernel(void) { return 0; }
61505 +#endif
61506 +
61507 #endif /* CONFIG_MMU */
61508
61509 #endif /* !__ASSEMBLY__ */
61510 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61511 index 4e2e1cc..12c266b 100644
61512 --- a/include/asm-generic/vmlinux.lds.h
61513 +++ b/include/asm-generic/vmlinux.lds.h
61514 @@ -218,6 +218,7 @@
61515 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61516 VMLINUX_SYMBOL(__start_rodata) = .; \
61517 *(.rodata) *(.rodata.*) \
61518 + *(.data..read_only) \
61519 *(__vermagic) /* Kernel version magic */ \
61520 . = ALIGN(8); \
61521 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61522 @@ -716,17 +717,18 @@
61523 * section in the linker script will go there too. @phdr should have
61524 * a leading colon.
61525 *
61526 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61527 + * Note that this macros defines per_cpu_load as an absolute symbol.
61528 * If there is no need to put the percpu section at a predetermined
61529 * address, use PERCPU_SECTION.
61530 */
61531 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61532 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61533 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61534 + per_cpu_load = .; \
61535 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61536 - LOAD_OFFSET) { \
61537 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61538 PERCPU_INPUT(cacheline) \
61539 } phdr \
61540 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61541 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61542
61543 /**
61544 * PERCPU_SECTION - define output section for percpu area, simple version
61545 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61546 index d6b67bb..a272c29 100644
61547 --- a/include/drm/drmP.h
61548 +++ b/include/drm/drmP.h
61549 @@ -72,6 +72,7 @@
61550 #include <linux/workqueue.h>
61551 #include <linux/poll.h>
61552 #include <asm/pgalloc.h>
61553 +#include <asm/local.h>
61554 #include "drm.h"
61555
61556 #include <linux/idr.h>
61557 @@ -1067,7 +1068,7 @@ struct drm_device {
61558
61559 /** \name Usage Counters */
61560 /*@{ */
61561 - int open_count; /**< Outstanding files open */
61562 + local_t open_count; /**< Outstanding files open */
61563 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61564 atomic_t vma_count; /**< Outstanding vma areas open */
61565 int buf_use; /**< Buffers in use -- cannot alloc */
61566 @@ -1078,7 +1079,7 @@ struct drm_device {
61567 /*@{ */
61568 unsigned long counters;
61569 enum drm_stat_type types[15];
61570 - atomic_t counts[15];
61571 + atomic_unchecked_t counts[15];
61572 /*@} */
61573
61574 struct list_head filelist;
61575 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61576 index e01cc80..319855d 100644
61577 --- a/include/drm/drm_crtc_helper.h
61578 +++ b/include/drm/drm_crtc_helper.h
61579 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61580
61581 /* disable crtc when not in use - more explicit than dpms off */
61582 void (*disable)(struct drm_crtc *crtc);
61583 -};
61584 +} __no_const;
61585
61586 /**
61587 * drm_encoder_helper_funcs - helper operations for encoders
61588 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61589 struct drm_connector *connector);
61590 /* disable encoder when not in use - more explicit than dpms off */
61591 void (*disable)(struct drm_encoder *encoder);
61592 -};
61593 +} __no_const;
61594
61595 /**
61596 * drm_connector_helper_funcs - helper operations for connectors
61597 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61598 index d6d1da4..fdd1ac5 100644
61599 --- a/include/drm/ttm/ttm_memory.h
61600 +++ b/include/drm/ttm/ttm_memory.h
61601 @@ -48,7 +48,7 @@
61602
61603 struct ttm_mem_shrink {
61604 int (*do_shrink) (struct ttm_mem_shrink *);
61605 -};
61606 +} __no_const;
61607
61608 /**
61609 * struct ttm_mem_global - Global memory accounting structure.
61610 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61611 index e86dfca..40cc55f 100644
61612 --- a/include/linux/a.out.h
61613 +++ b/include/linux/a.out.h
61614 @@ -39,6 +39,14 @@ enum machine_type {
61615 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61616 };
61617
61618 +/* Constants for the N_FLAGS field */
61619 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61620 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61621 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61622 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61623 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61624 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61625 +
61626 #if !defined (N_MAGIC)
61627 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61628 #endif
61629 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61630 index 06fd4bb..1caec0d 100644
61631 --- a/include/linux/atmdev.h
61632 +++ b/include/linux/atmdev.h
61633 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61634 #endif
61635
61636 struct k_atm_aal_stats {
61637 -#define __HANDLE_ITEM(i) atomic_t i
61638 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61639 __AAL_STAT_ITEMS
61640 #undef __HANDLE_ITEM
61641 };
61642 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61643 index 366422b..1fa7f84 100644
61644 --- a/include/linux/binfmts.h
61645 +++ b/include/linux/binfmts.h
61646 @@ -89,6 +89,7 @@ struct linux_binfmt {
61647 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61648 int (*load_shlib)(struct file *);
61649 int (*core_dump)(struct coredump_params *cprm);
61650 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61651 unsigned long min_coredump; /* minimal dump size */
61652 };
61653
61654 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61655 index 4a2ab7c..a2de7a8 100644
61656 --- a/include/linux/blkdev.h
61657 +++ b/include/linux/blkdev.h
61658 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61659 /* this callback is with swap_lock and sometimes page table lock held */
61660 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61661 struct module *owner;
61662 -};
61663 +} __do_const;
61664
61665 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61666 unsigned long);
61667 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61668 index 4d1a074..88f929a 100644
61669 --- a/include/linux/blktrace_api.h
61670 +++ b/include/linux/blktrace_api.h
61671 @@ -162,7 +162,7 @@ struct blk_trace {
61672 struct dentry *dir;
61673 struct dentry *dropped_file;
61674 struct dentry *msg_file;
61675 - atomic_t dropped;
61676 + atomic_unchecked_t dropped;
61677 };
61678
61679 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61680 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61681 index 83195fb..0b0f77d 100644
61682 --- a/include/linux/byteorder/little_endian.h
61683 +++ b/include/linux/byteorder/little_endian.h
61684 @@ -42,51 +42,51 @@
61685
61686 static inline __le64 __cpu_to_le64p(const __u64 *p)
61687 {
61688 - return (__force __le64)*p;
61689 + return (__force const __le64)*p;
61690 }
61691 static inline __u64 __le64_to_cpup(const __le64 *p)
61692 {
61693 - return (__force __u64)*p;
61694 + return (__force const __u64)*p;
61695 }
61696 static inline __le32 __cpu_to_le32p(const __u32 *p)
61697 {
61698 - return (__force __le32)*p;
61699 + return (__force const __le32)*p;
61700 }
61701 static inline __u32 __le32_to_cpup(const __le32 *p)
61702 {
61703 - return (__force __u32)*p;
61704 + return (__force const __u32)*p;
61705 }
61706 static inline __le16 __cpu_to_le16p(const __u16 *p)
61707 {
61708 - return (__force __le16)*p;
61709 + return (__force const __le16)*p;
61710 }
61711 static inline __u16 __le16_to_cpup(const __le16 *p)
61712 {
61713 - return (__force __u16)*p;
61714 + return (__force const __u16)*p;
61715 }
61716 static inline __be64 __cpu_to_be64p(const __u64 *p)
61717 {
61718 - return (__force __be64)__swab64p(p);
61719 + return (__force const __be64)__swab64p(p);
61720 }
61721 static inline __u64 __be64_to_cpup(const __be64 *p)
61722 {
61723 - return __swab64p((__u64 *)p);
61724 + return __swab64p((const __u64 *)p);
61725 }
61726 static inline __be32 __cpu_to_be32p(const __u32 *p)
61727 {
61728 - return (__force __be32)__swab32p(p);
61729 + return (__force const __be32)__swab32p(p);
61730 }
61731 static inline __u32 __be32_to_cpup(const __be32 *p)
61732 {
61733 - return __swab32p((__u32 *)p);
61734 + return __swab32p((const __u32 *)p);
61735 }
61736 static inline __be16 __cpu_to_be16p(const __u16 *p)
61737 {
61738 - return (__force __be16)__swab16p(p);
61739 + return (__force const __be16)__swab16p(p);
61740 }
61741 static inline __u16 __be16_to_cpup(const __be16 *p)
61742 {
61743 - return __swab16p((__u16 *)p);
61744 + return __swab16p((const __u16 *)p);
61745 }
61746 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61747 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61748 diff --git a/include/linux/cache.h b/include/linux/cache.h
61749 index 4c57065..4307975 100644
61750 --- a/include/linux/cache.h
61751 +++ b/include/linux/cache.h
61752 @@ -16,6 +16,10 @@
61753 #define __read_mostly
61754 #endif
61755
61756 +#ifndef __read_only
61757 +#define __read_only __read_mostly
61758 +#endif
61759 +
61760 #ifndef ____cacheline_aligned
61761 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61762 #endif
61763 diff --git a/include/linux/capability.h b/include/linux/capability.h
61764 index d10b7ed..0288b79 100644
61765 --- a/include/linux/capability.h
61766 +++ b/include/linux/capability.h
61767 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61768 extern bool ns_capable(struct user_namespace *ns, int cap);
61769 extern bool nsown_capable(int cap);
61770 extern bool inode_capable(const struct inode *inode, int cap);
61771 +extern bool capable_nolog(int cap);
61772 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61773 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61774
61775 /* audit system wants to get cap info from files as well */
61776 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61777
61778 +extern int is_privileged_binary(const struct dentry *dentry);
61779 +
61780 #endif /* __KERNEL__ */
61781
61782 #endif /* !_LINUX_CAPABILITY_H */
61783 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61784 index 42e55de..1cd0e66 100644
61785 --- a/include/linux/cleancache.h
61786 +++ b/include/linux/cleancache.h
61787 @@ -31,7 +31,7 @@ struct cleancache_ops {
61788 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61789 void (*invalidate_inode)(int, struct cleancache_filekey);
61790 void (*invalidate_fs)(int);
61791 -};
61792 +} __no_const;
61793
61794 extern struct cleancache_ops
61795 cleancache_register_ops(struct cleancache_ops *ops);
61796 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61797 index 77335fa..6cbe7dd 100644
61798 --- a/include/linux/clk-provider.h
61799 +++ b/include/linux/clk-provider.h
61800 @@ -111,6 +111,7 @@ struct clk_ops {
61801 unsigned long);
61802 void (*init)(struct clk_hw *hw);
61803 };
61804 +typedef struct clk_ops __no_const clk_ops_no_const;
61805
61806 /**
61807 * struct clk_init_data - holds init data that's common to all clocks and is
61808 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61809 index 934bc34..1b47129 100644
61810 --- a/include/linux/compiler-gcc4.h
61811 +++ b/include/linux/compiler-gcc4.h
61812 @@ -32,6 +32,21 @@
61813 #define __linktime_error(message) __attribute__((__error__(message)))
61814
61815 #if __GNUC_MINOR__ >= 5
61816 +
61817 +#ifdef CONSTIFY_PLUGIN
61818 +#define __no_const __attribute__((no_const))
61819 +#define __do_const __attribute__((do_const))
61820 +#endif
61821 +
61822 +#ifdef SIZE_OVERFLOW_PLUGIN
61823 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61824 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61825 +#endif
61826 +
61827 +#ifdef LATENT_ENTROPY_PLUGIN
61828 +#define __latent_entropy __attribute__((latent_entropy))
61829 +#endif
61830 +
61831 /*
61832 * Mark a position in code as unreachable. This can be used to
61833 * suppress control flow warnings after asm blocks that transfer
61834 @@ -47,6 +62,11 @@
61835 #define __noclone __attribute__((__noclone__))
61836
61837 #endif
61838 +
61839 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61840 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61841 +#define __bos0(ptr) __bos((ptr), 0)
61842 +#define __bos1(ptr) __bos((ptr), 1)
61843 #endif
61844
61845 #if __GNUC_MINOR__ >= 6
61846 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61847 index f430e41..38be90f 100644
61848 --- a/include/linux/compiler.h
61849 +++ b/include/linux/compiler.h
61850 @@ -5,31 +5,62 @@
61851
61852 #ifdef __CHECKER__
61853 # define __user __attribute__((noderef, address_space(1)))
61854 +# define __force_user __force __user
61855 # define __kernel __attribute__((address_space(0)))
61856 +# define __force_kernel __force __kernel
61857 # define __safe __attribute__((safe))
61858 # define __force __attribute__((force))
61859 # define __nocast __attribute__((nocast))
61860 # define __iomem __attribute__((noderef, address_space(2)))
61861 +# define __force_iomem __force __iomem
61862 # define __acquires(x) __attribute__((context(x,0,1)))
61863 # define __releases(x) __attribute__((context(x,1,0)))
61864 # define __acquire(x) __context__(x,1)
61865 # define __release(x) __context__(x,-1)
61866 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61867 # define __percpu __attribute__((noderef, address_space(3)))
61868 +# define __force_percpu __force __percpu
61869 #ifdef CONFIG_SPARSE_RCU_POINTER
61870 # define __rcu __attribute__((noderef, address_space(4)))
61871 +# define __force_rcu __force __rcu
61872 #else
61873 # define __rcu
61874 +# define __force_rcu
61875 #endif
61876 extern void __chk_user_ptr(const volatile void __user *);
61877 extern void __chk_io_ptr(const volatile void __iomem *);
61878 +#elif defined(CHECKER_PLUGIN)
61879 +//# define __user
61880 +//# define __force_user
61881 +//# define __kernel
61882 +//# define __force_kernel
61883 +# define __safe
61884 +# define __force
61885 +# define __nocast
61886 +# define __iomem
61887 +# define __force_iomem
61888 +# define __chk_user_ptr(x) (void)0
61889 +# define __chk_io_ptr(x) (void)0
61890 +# define __builtin_warning(x, y...) (1)
61891 +# define __acquires(x)
61892 +# define __releases(x)
61893 +# define __acquire(x) (void)0
61894 +# define __release(x) (void)0
61895 +# define __cond_lock(x,c) (c)
61896 +# define __percpu
61897 +# define __force_percpu
61898 +# define __rcu
61899 +# define __force_rcu
61900 #else
61901 # define __user
61902 +# define __force_user
61903 # define __kernel
61904 +# define __force_kernel
61905 # define __safe
61906 # define __force
61907 # define __nocast
61908 # define __iomem
61909 +# define __force_iomem
61910 # define __chk_user_ptr(x) (void)0
61911 # define __chk_io_ptr(x) (void)0
61912 # define __builtin_warning(x, y...) (1)
61913 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61914 # define __release(x) (void)0
61915 # define __cond_lock(x,c) (c)
61916 # define __percpu
61917 +# define __force_percpu
61918 # define __rcu
61919 +# define __force_rcu
61920 #endif
61921
61922 #ifdef __KERNEL__
61923 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61924 # define __attribute_const__ /* unimplemented */
61925 #endif
61926
61927 +#ifndef __no_const
61928 +# define __no_const
61929 +#endif
61930 +
61931 +#ifndef __do_const
61932 +# define __do_const
61933 +#endif
61934 +
61935 +#ifndef __size_overflow
61936 +# define __size_overflow(...)
61937 +#endif
61938 +
61939 +#ifndef __intentional_overflow
61940 +# define __intentional_overflow(...)
61941 +#endif
61942 +
61943 +#ifndef __latent_entropy
61944 +# define __latent_entropy
61945 +#endif
61946 +
61947 /*
61948 * Tell gcc if a function is cold. The compiler will assume any path
61949 * directly leading to the call is unlikely.
61950 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61951 #define __cold
61952 #endif
61953
61954 +#ifndef __alloc_size
61955 +#define __alloc_size(...)
61956 +#endif
61957 +
61958 +#ifndef __bos
61959 +#define __bos(ptr, arg)
61960 +#endif
61961 +
61962 +#ifndef __bos0
61963 +#define __bos0(ptr)
61964 +#endif
61965 +
61966 +#ifndef __bos1
61967 +#define __bos1(ptr)
61968 +#endif
61969 +
61970 /* Simple shorthand for a section definition */
61971 #ifndef __section
61972 # define __section(S) __attribute__ ((__section__(#S)))
61973 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61974 * use is to mediate communication between process-level code and irq/NMI
61975 * handlers, all running on the same CPU.
61976 */
61977 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61978 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61979 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61980
61981 #endif /* __LINUX_COMPILER_H */
61982 diff --git a/include/linux/cred.h b/include/linux/cred.h
61983 index ebbed2c..908cc2c 100644
61984 --- a/include/linux/cred.h
61985 +++ b/include/linux/cred.h
61986 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61987 static inline void validate_process_creds(void)
61988 {
61989 }
61990 +static inline void validate_task_creds(struct task_struct *task)
61991 +{
61992 +}
61993 #endif
61994
61995 /**
61996 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61997 index b92eadf..b4ecdc1 100644
61998 --- a/include/linux/crypto.h
61999 +++ b/include/linux/crypto.h
62000 @@ -373,7 +373,7 @@ struct cipher_tfm {
62001 const u8 *key, unsigned int keylen);
62002 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
62003 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
62004 -};
62005 +} __no_const;
62006
62007 struct hash_tfm {
62008 int (*init)(struct hash_desc *desc);
62009 @@ -394,13 +394,13 @@ struct compress_tfm {
62010 int (*cot_decompress)(struct crypto_tfm *tfm,
62011 const u8 *src, unsigned int slen,
62012 u8 *dst, unsigned int *dlen);
62013 -};
62014 +} __no_const;
62015
62016 struct rng_tfm {
62017 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
62018 unsigned int dlen);
62019 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
62020 -};
62021 +} __no_const;
62022
62023 #define crt_ablkcipher crt_u.ablkcipher
62024 #define crt_aead crt_u.aead
62025 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
62026 index 7925bf0..d5143d2 100644
62027 --- a/include/linux/decompress/mm.h
62028 +++ b/include/linux/decompress/mm.h
62029 @@ -77,7 +77,7 @@ static void free(void *where)
62030 * warnings when not needed (indeed large_malloc / large_free are not
62031 * needed by inflate */
62032
62033 -#define malloc(a) kmalloc(a, GFP_KERNEL)
62034 +#define malloc(a) kmalloc((a), GFP_KERNEL)
62035 #define free(a) kfree(a)
62036
62037 #define large_malloc(a) vmalloc(a)
62038 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
62039 index 94af418..b1ca7a2 100644
62040 --- a/include/linux/dma-mapping.h
62041 +++ b/include/linux/dma-mapping.h
62042 @@ -54,7 +54,7 @@ struct dma_map_ops {
62043 u64 (*get_required_mask)(struct device *dev);
62044 #endif
62045 int is_phys;
62046 -};
62047 +} __do_const;
62048
62049 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
62050
62051 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
62052 index 9c02a45..89fdd73 100644
62053 --- a/include/linux/dmaengine.h
62054 +++ b/include/linux/dmaengine.h
62055 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
62056 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
62057 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
62058
62059 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
62060 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
62061 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
62062 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
62063 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
62064 struct dma_pinned_list *pinned_list, struct page *page,
62065 unsigned int offset, size_t len);
62066
62067 diff --git a/include/linux/efi.h b/include/linux/efi.h
62068 index 5782114..e9b1ba1 100644
62069 --- a/include/linux/efi.h
62070 +++ b/include/linux/efi.h
62071 @@ -640,7 +640,7 @@ struct efivar_operations {
62072 efi_get_variable_t *get_variable;
62073 efi_get_next_variable_t *get_next_variable;
62074 efi_set_variable_t *set_variable;
62075 -};
62076 +} __no_const;
62077
62078 struct efivars {
62079 /*
62080 diff --git a/include/linux/elf.h b/include/linux/elf.h
62081 index 999b4f5..57753b4 100644
62082 --- a/include/linux/elf.h
62083 +++ b/include/linux/elf.h
62084 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
62085 #define PT_GNU_EH_FRAME 0x6474e550
62086
62087 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
62088 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
62089 +
62090 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
62091 +
62092 +/* Constants for the e_flags field */
62093 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
62094 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
62095 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
62096 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
62097 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
62098 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
62099
62100 /*
62101 * Extended Numbering
62102 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
62103 #define DT_DEBUG 21
62104 #define DT_TEXTREL 22
62105 #define DT_JMPREL 23
62106 +#define DT_FLAGS 30
62107 + #define DF_TEXTREL 0x00000004
62108 #define DT_ENCODING 32
62109 #define OLD_DT_LOOS 0x60000000
62110 #define DT_LOOS 0x6000000d
62111 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
62112 #define PF_W 0x2
62113 #define PF_X 0x1
62114
62115 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
62116 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
62117 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
62118 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
62119 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
62120 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
62121 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
62122 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
62123 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
62124 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
62125 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
62126 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
62127 +
62128 typedef struct elf32_phdr{
62129 Elf32_Word p_type;
62130 Elf32_Off p_offset;
62131 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
62132 #define EI_OSABI 7
62133 #define EI_PAD 8
62134
62135 +#define EI_PAX 14
62136 +
62137 #define ELFMAG0 0x7f /* EI_MAG */
62138 #define ELFMAG1 'E'
62139 #define ELFMAG2 'L'
62140 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
62141 #define elf_note elf32_note
62142 #define elf_addr_t Elf32_Off
62143 #define Elf_Half Elf32_Half
62144 +#define elf_dyn Elf32_Dyn
62145
62146 #else
62147
62148 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
62149 #define elf_note elf64_note
62150 #define elf_addr_t Elf64_Off
62151 #define Elf_Half Elf64_Half
62152 +#define elf_dyn Elf64_Dyn
62153
62154 #endif
62155
62156 diff --git a/include/linux/filter.h b/include/linux/filter.h
62157 index 82b0135..917914d 100644
62158 --- a/include/linux/filter.h
62159 +++ b/include/linux/filter.h
62160 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
62161
62162 struct sk_buff;
62163 struct sock;
62164 +struct bpf_jit_work;
62165
62166 struct sk_filter
62167 {
62168 @@ -153,6 +154,9 @@ struct sk_filter
62169 unsigned int len; /* Number of filter blocks */
62170 unsigned int (*bpf_func)(const struct sk_buff *skb,
62171 const struct sock_filter *filter);
62172 +#ifdef CONFIG_BPF_JIT
62173 + struct bpf_jit_work *work;
62174 +#endif
62175 struct rcu_head rcu;
62176 struct sock_filter insns[0];
62177 };
62178 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
62179 index db04ec5..f6ed627 100644
62180 --- a/include/linux/firewire.h
62181 +++ b/include/linux/firewire.h
62182 @@ -430,7 +430,7 @@ struct fw_iso_context {
62183 union {
62184 fw_iso_callback_t sc;
62185 fw_iso_mc_callback_t mc;
62186 - } callback;
62187 + } __no_const callback;
62188 void *callback_data;
62189 };
62190
62191 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
62192 index 0e4e2ee..4ff4312 100644
62193 --- a/include/linux/frontswap.h
62194 +++ b/include/linux/frontswap.h
62195 @@ -11,7 +11,7 @@ struct frontswap_ops {
62196 int (*load)(unsigned, pgoff_t, struct page *);
62197 void (*invalidate_page)(unsigned, pgoff_t);
62198 void (*invalidate_area)(unsigned);
62199 -};
62200 +} __no_const;
62201
62202 extern bool frontswap_enabled;
62203 extern struct frontswap_ops
62204 diff --git a/include/linux/fs.h b/include/linux/fs.h
62205 index aa11047..7d046d0 100644
62206 --- a/include/linux/fs.h
62207 +++ b/include/linux/fs.h
62208 @@ -1802,7 +1802,8 @@ struct file_operations {
62209 int (*setlease)(struct file *, long, struct file_lock **);
62210 long (*fallocate)(struct file *file, int mode, loff_t offset,
62211 loff_t len);
62212 -};
62213 +} __do_const;
62214 +typedef struct file_operations __no_const file_operations_no_const;
62215
62216 struct inode_operations {
62217 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
62218 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
62219 index 003dc0f..3c4ea97 100644
62220 --- a/include/linux/fs_struct.h
62221 +++ b/include/linux/fs_struct.h
62222 @@ -6,7 +6,7 @@
62223 #include <linux/seqlock.h>
62224
62225 struct fs_struct {
62226 - int users;
62227 + atomic_t users;
62228 spinlock_t lock;
62229 seqcount_t seq;
62230 int umask;
62231 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
62232 index ce31408..b1ad003 100644
62233 --- a/include/linux/fscache-cache.h
62234 +++ b/include/linux/fscache-cache.h
62235 @@ -102,7 +102,7 @@ struct fscache_operation {
62236 fscache_operation_release_t release;
62237 };
62238
62239 -extern atomic_t fscache_op_debug_id;
62240 +extern atomic_unchecked_t fscache_op_debug_id;
62241 extern void fscache_op_work_func(struct work_struct *work);
62242
62243 extern void fscache_enqueue_operation(struct fscache_operation *);
62244 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
62245 {
62246 INIT_WORK(&op->work, fscache_op_work_func);
62247 atomic_set(&op->usage, 1);
62248 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62249 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62250 op->processor = processor;
62251 op->release = release;
62252 INIT_LIST_HEAD(&op->pend_link);
62253 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
62254 index a6dfe69..569586df 100644
62255 --- a/include/linux/fsnotify.h
62256 +++ b/include/linux/fsnotify.h
62257 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
62258 */
62259 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
62260 {
62261 - return kstrdup(name, GFP_KERNEL);
62262 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
62263 }
62264
62265 /*
62266 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
62267 index 63d966d..cdcb717 100644
62268 --- a/include/linux/fsnotify_backend.h
62269 +++ b/include/linux/fsnotify_backend.h
62270 @@ -105,6 +105,7 @@ struct fsnotify_ops {
62271 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
62272 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
62273 };
62274 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
62275
62276 /*
62277 * A group is a "thing" that wants to receive notification about filesystem
62278 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
62279 index 642928c..e6c83a7 100644
62280 --- a/include/linux/ftrace_event.h
62281 +++ b/include/linux/ftrace_event.h
62282 @@ -97,7 +97,7 @@ struct trace_event_functions {
62283 trace_print_func raw;
62284 trace_print_func hex;
62285 trace_print_func binary;
62286 -};
62287 +} __no_const;
62288
62289 struct trace_event {
62290 struct hlist_node node;
62291 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
62292 extern int trace_add_event_call(struct ftrace_event_call *call);
62293 extern void trace_remove_event_call(struct ftrace_event_call *call);
62294
62295 -#define is_signed_type(type) (((type)(-1)) < 0)
62296 +#define is_signed_type(type) (((type)(-1)) < (type)1)
62297
62298 int trace_set_clr_event(const char *system, const char *event, int set);
62299
62300 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
62301 index 4f440b3..342233a 100644
62302 --- a/include/linux/genhd.h
62303 +++ b/include/linux/genhd.h
62304 @@ -190,7 +190,7 @@ struct gendisk {
62305 struct kobject *slave_dir;
62306
62307 struct timer_rand_state *random;
62308 - atomic_t sync_io; /* RAID */
62309 + atomic_unchecked_t sync_io; /* RAID */
62310 struct disk_events *ev;
62311 #ifdef CONFIG_BLK_DEV_INTEGRITY
62312 struct blk_integrity *integrity;
62313 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
62314 index 4883f39..26688a8 100644
62315 --- a/include/linux/gfp.h
62316 +++ b/include/linux/gfp.h
62317 @@ -39,6 +39,12 @@ struct vm_area_struct;
62318 #define ___GFP_OTHER_NODE 0x800000u
62319 #define ___GFP_WRITE 0x1000000u
62320
62321 +#ifdef CONFIG_PAX_USERCOPY_SLABS
62322 +#define ___GFP_USERCOPY 0x2000000u
62323 +#else
62324 +#define ___GFP_USERCOPY 0
62325 +#endif
62326 +
62327 /*
62328 * GFP bitmasks..
62329 *
62330 @@ -93,6 +99,7 @@ struct vm_area_struct;
62331 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
62332 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
62333 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
62334 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
62335
62336 /*
62337 * This may seem redundant, but it's a way of annotating false positives vs.
62338 @@ -100,7 +107,7 @@ struct vm_area_struct;
62339 */
62340 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
62341
62342 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
62343 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
62344 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
62345
62346 /* This equals 0, but use constants in case they ever change */
62347 @@ -154,6 +161,8 @@ struct vm_area_struct;
62348 /* 4GB DMA on some platforms */
62349 #define GFP_DMA32 __GFP_DMA32
62350
62351 +#define GFP_USERCOPY __GFP_USERCOPY
62352 +
62353 /* Convert GFP flags to their corresponding migrate type */
62354 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
62355 {
62356 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
62357 new file mode 100644
62358 index 0000000..c938b1f
62359 --- /dev/null
62360 +++ b/include/linux/gracl.h
62361 @@ -0,0 +1,319 @@
62362 +#ifndef GR_ACL_H
62363 +#define GR_ACL_H
62364 +
62365 +#include <linux/grdefs.h>
62366 +#include <linux/resource.h>
62367 +#include <linux/capability.h>
62368 +#include <linux/dcache.h>
62369 +#include <asm/resource.h>
62370 +
62371 +/* Major status information */
62372 +
62373 +#define GR_VERSION "grsecurity 2.9.1"
62374 +#define GRSECURITY_VERSION 0x2901
62375 +
62376 +enum {
62377 + GR_SHUTDOWN = 0,
62378 + GR_ENABLE = 1,
62379 + GR_SPROLE = 2,
62380 + GR_RELOAD = 3,
62381 + GR_SEGVMOD = 4,
62382 + GR_STATUS = 5,
62383 + GR_UNSPROLE = 6,
62384 + GR_PASSSET = 7,
62385 + GR_SPROLEPAM = 8,
62386 +};
62387 +
62388 +/* Password setup definitions
62389 + * kernel/grhash.c */
62390 +enum {
62391 + GR_PW_LEN = 128,
62392 + GR_SALT_LEN = 16,
62393 + GR_SHA_LEN = 32,
62394 +};
62395 +
62396 +enum {
62397 + GR_SPROLE_LEN = 64,
62398 +};
62399 +
62400 +enum {
62401 + GR_NO_GLOB = 0,
62402 + GR_REG_GLOB,
62403 + GR_CREATE_GLOB
62404 +};
62405 +
62406 +#define GR_NLIMITS 32
62407 +
62408 +/* Begin Data Structures */
62409 +
62410 +struct sprole_pw {
62411 + unsigned char *rolename;
62412 + unsigned char salt[GR_SALT_LEN];
62413 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62414 +};
62415 +
62416 +struct name_entry {
62417 + __u32 key;
62418 + ino_t inode;
62419 + dev_t device;
62420 + char *name;
62421 + __u16 len;
62422 + __u8 deleted;
62423 + struct name_entry *prev;
62424 + struct name_entry *next;
62425 +};
62426 +
62427 +struct inodev_entry {
62428 + struct name_entry *nentry;
62429 + struct inodev_entry *prev;
62430 + struct inodev_entry *next;
62431 +};
62432 +
62433 +struct acl_role_db {
62434 + struct acl_role_label **r_hash;
62435 + __u32 r_size;
62436 +};
62437 +
62438 +struct inodev_db {
62439 + struct inodev_entry **i_hash;
62440 + __u32 i_size;
62441 +};
62442 +
62443 +struct name_db {
62444 + struct name_entry **n_hash;
62445 + __u32 n_size;
62446 +};
62447 +
62448 +struct crash_uid {
62449 + uid_t uid;
62450 + unsigned long expires;
62451 +};
62452 +
62453 +struct gr_hash_struct {
62454 + void **table;
62455 + void **nametable;
62456 + void *first;
62457 + __u32 table_size;
62458 + __u32 used_size;
62459 + int type;
62460 +};
62461 +
62462 +/* Userspace Grsecurity ACL data structures */
62463 +
62464 +struct acl_subject_label {
62465 + char *filename;
62466 + ino_t inode;
62467 + dev_t device;
62468 + __u32 mode;
62469 + kernel_cap_t cap_mask;
62470 + kernel_cap_t cap_lower;
62471 + kernel_cap_t cap_invert_audit;
62472 +
62473 + struct rlimit res[GR_NLIMITS];
62474 + __u32 resmask;
62475 +
62476 + __u8 user_trans_type;
62477 + __u8 group_trans_type;
62478 + uid_t *user_transitions;
62479 + gid_t *group_transitions;
62480 + __u16 user_trans_num;
62481 + __u16 group_trans_num;
62482 +
62483 + __u32 sock_families[2];
62484 + __u32 ip_proto[8];
62485 + __u32 ip_type;
62486 + struct acl_ip_label **ips;
62487 + __u32 ip_num;
62488 + __u32 inaddr_any_override;
62489 +
62490 + __u32 crashes;
62491 + unsigned long expires;
62492 +
62493 + struct acl_subject_label *parent_subject;
62494 + struct gr_hash_struct *hash;
62495 + struct acl_subject_label *prev;
62496 + struct acl_subject_label *next;
62497 +
62498 + struct acl_object_label **obj_hash;
62499 + __u32 obj_hash_size;
62500 + __u16 pax_flags;
62501 +};
62502 +
62503 +struct role_allowed_ip {
62504 + __u32 addr;
62505 + __u32 netmask;
62506 +
62507 + struct role_allowed_ip *prev;
62508 + struct role_allowed_ip *next;
62509 +};
62510 +
62511 +struct role_transition {
62512 + char *rolename;
62513 +
62514 + struct role_transition *prev;
62515 + struct role_transition *next;
62516 +};
62517 +
62518 +struct acl_role_label {
62519 + char *rolename;
62520 + uid_t uidgid;
62521 + __u16 roletype;
62522 +
62523 + __u16 auth_attempts;
62524 + unsigned long expires;
62525 +
62526 + struct acl_subject_label *root_label;
62527 + struct gr_hash_struct *hash;
62528 +
62529 + struct acl_role_label *prev;
62530 + struct acl_role_label *next;
62531 +
62532 + struct role_transition *transitions;
62533 + struct role_allowed_ip *allowed_ips;
62534 + uid_t *domain_children;
62535 + __u16 domain_child_num;
62536 +
62537 + umode_t umask;
62538 +
62539 + struct acl_subject_label **subj_hash;
62540 + __u32 subj_hash_size;
62541 +};
62542 +
62543 +struct user_acl_role_db {
62544 + struct acl_role_label **r_table;
62545 + __u32 num_pointers; /* Number of allocations to track */
62546 + __u32 num_roles; /* Number of roles */
62547 + __u32 num_domain_children; /* Number of domain children */
62548 + __u32 num_subjects; /* Number of subjects */
62549 + __u32 num_objects; /* Number of objects */
62550 +};
62551 +
62552 +struct acl_object_label {
62553 + char *filename;
62554 + ino_t inode;
62555 + dev_t device;
62556 + __u32 mode;
62557 +
62558 + struct acl_subject_label *nested;
62559 + struct acl_object_label *globbed;
62560 +
62561 + /* next two structures not used */
62562 +
62563 + struct acl_object_label *prev;
62564 + struct acl_object_label *next;
62565 +};
62566 +
62567 +struct acl_ip_label {
62568 + char *iface;
62569 + __u32 addr;
62570 + __u32 netmask;
62571 + __u16 low, high;
62572 + __u8 mode;
62573 + __u32 type;
62574 + __u32 proto[8];
62575 +
62576 + /* next two structures not used */
62577 +
62578 + struct acl_ip_label *prev;
62579 + struct acl_ip_label *next;
62580 +};
62581 +
62582 +struct gr_arg {
62583 + struct user_acl_role_db role_db;
62584 + unsigned char pw[GR_PW_LEN];
62585 + unsigned char salt[GR_SALT_LEN];
62586 + unsigned char sum[GR_SHA_LEN];
62587 + unsigned char sp_role[GR_SPROLE_LEN];
62588 + struct sprole_pw *sprole_pws;
62589 + dev_t segv_device;
62590 + ino_t segv_inode;
62591 + uid_t segv_uid;
62592 + __u16 num_sprole_pws;
62593 + __u16 mode;
62594 +};
62595 +
62596 +struct gr_arg_wrapper {
62597 + struct gr_arg *arg;
62598 + __u32 version;
62599 + __u32 size;
62600 +};
62601 +
62602 +struct subject_map {
62603 + struct acl_subject_label *user;
62604 + struct acl_subject_label *kernel;
62605 + struct subject_map *prev;
62606 + struct subject_map *next;
62607 +};
62608 +
62609 +struct acl_subj_map_db {
62610 + struct subject_map **s_hash;
62611 + __u32 s_size;
62612 +};
62613 +
62614 +/* End Data Structures Section */
62615 +
62616 +/* Hash functions generated by empirical testing by Brad Spengler
62617 + Makes good use of the low bits of the inode. Generally 0-1 times
62618 + in loop for successful match. 0-3 for unsuccessful match.
62619 + Shift/add algorithm with modulus of table size and an XOR*/
62620 +
62621 +static __inline__ unsigned int
62622 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62623 +{
62624 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62625 +}
62626 +
62627 + static __inline__ unsigned int
62628 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62629 +{
62630 + return ((const unsigned long)userp % sz);
62631 +}
62632 +
62633 +static __inline__ unsigned int
62634 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62635 +{
62636 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62637 +}
62638 +
62639 +static __inline__ unsigned int
62640 +nhash(const char *name, const __u16 len, const unsigned int sz)
62641 +{
62642 + return full_name_hash((const unsigned char *)name, len) % sz;
62643 +}
62644 +
62645 +#define FOR_EACH_ROLE_START(role) \
62646 + role = role_list; \
62647 + while (role) {
62648 +
62649 +#define FOR_EACH_ROLE_END(role) \
62650 + role = role->prev; \
62651 + }
62652 +
62653 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62654 + subj = NULL; \
62655 + iter = 0; \
62656 + while (iter < role->subj_hash_size) { \
62657 + if (subj == NULL) \
62658 + subj = role->subj_hash[iter]; \
62659 + if (subj == NULL) { \
62660 + iter++; \
62661 + continue; \
62662 + }
62663 +
62664 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62665 + subj = subj->next; \
62666 + if (subj == NULL) \
62667 + iter++; \
62668 + }
62669 +
62670 +
62671 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62672 + subj = role->hash->first; \
62673 + while (subj != NULL) {
62674 +
62675 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62676 + subj = subj->next; \
62677 + }
62678 +
62679 +#endif
62680 +
62681 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62682 new file mode 100644
62683 index 0000000..323ecf2
62684 --- /dev/null
62685 +++ b/include/linux/gralloc.h
62686 @@ -0,0 +1,9 @@
62687 +#ifndef __GRALLOC_H
62688 +#define __GRALLOC_H
62689 +
62690 +void acl_free_all(void);
62691 +int acl_alloc_stack_init(unsigned long size);
62692 +void *acl_alloc(unsigned long len);
62693 +void *acl_alloc_num(unsigned long num, unsigned long len);
62694 +
62695 +#endif
62696 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62697 new file mode 100644
62698 index 0000000..b30e9bc
62699 --- /dev/null
62700 +++ b/include/linux/grdefs.h
62701 @@ -0,0 +1,140 @@
62702 +#ifndef GRDEFS_H
62703 +#define GRDEFS_H
62704 +
62705 +/* Begin grsecurity status declarations */
62706 +
62707 +enum {
62708 + GR_READY = 0x01,
62709 + GR_STATUS_INIT = 0x00 // disabled state
62710 +};
62711 +
62712 +/* Begin ACL declarations */
62713 +
62714 +/* Role flags */
62715 +
62716 +enum {
62717 + GR_ROLE_USER = 0x0001,
62718 + GR_ROLE_GROUP = 0x0002,
62719 + GR_ROLE_DEFAULT = 0x0004,
62720 + GR_ROLE_SPECIAL = 0x0008,
62721 + GR_ROLE_AUTH = 0x0010,
62722 + GR_ROLE_NOPW = 0x0020,
62723 + GR_ROLE_GOD = 0x0040,
62724 + GR_ROLE_LEARN = 0x0080,
62725 + GR_ROLE_TPE = 0x0100,
62726 + GR_ROLE_DOMAIN = 0x0200,
62727 + GR_ROLE_PAM = 0x0400,
62728 + GR_ROLE_PERSIST = 0x0800
62729 +};
62730 +
62731 +/* ACL Subject and Object mode flags */
62732 +enum {
62733 + GR_DELETED = 0x80000000
62734 +};
62735 +
62736 +/* ACL Object-only mode flags */
62737 +enum {
62738 + GR_READ = 0x00000001,
62739 + GR_APPEND = 0x00000002,
62740 + GR_WRITE = 0x00000004,
62741 + GR_EXEC = 0x00000008,
62742 + GR_FIND = 0x00000010,
62743 + GR_INHERIT = 0x00000020,
62744 + GR_SETID = 0x00000040,
62745 + GR_CREATE = 0x00000080,
62746 + GR_DELETE = 0x00000100,
62747 + GR_LINK = 0x00000200,
62748 + GR_AUDIT_READ = 0x00000400,
62749 + GR_AUDIT_APPEND = 0x00000800,
62750 + GR_AUDIT_WRITE = 0x00001000,
62751 + GR_AUDIT_EXEC = 0x00002000,
62752 + GR_AUDIT_FIND = 0x00004000,
62753 + GR_AUDIT_INHERIT= 0x00008000,
62754 + GR_AUDIT_SETID = 0x00010000,
62755 + GR_AUDIT_CREATE = 0x00020000,
62756 + GR_AUDIT_DELETE = 0x00040000,
62757 + GR_AUDIT_LINK = 0x00080000,
62758 + GR_PTRACERD = 0x00100000,
62759 + GR_NOPTRACE = 0x00200000,
62760 + GR_SUPPRESS = 0x00400000,
62761 + GR_NOLEARN = 0x00800000,
62762 + GR_INIT_TRANSFER= 0x01000000
62763 +};
62764 +
62765 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62766 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62767 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62768 +
62769 +/* ACL subject-only mode flags */
62770 +enum {
62771 + GR_KILL = 0x00000001,
62772 + GR_VIEW = 0x00000002,
62773 + GR_PROTECTED = 0x00000004,
62774 + GR_LEARN = 0x00000008,
62775 + GR_OVERRIDE = 0x00000010,
62776 + /* just a placeholder, this mode is only used in userspace */
62777 + GR_DUMMY = 0x00000020,
62778 + GR_PROTSHM = 0x00000040,
62779 + GR_KILLPROC = 0x00000080,
62780 + GR_KILLIPPROC = 0x00000100,
62781 + /* just a placeholder, this mode is only used in userspace */
62782 + GR_NOTROJAN = 0x00000200,
62783 + GR_PROTPROCFD = 0x00000400,
62784 + GR_PROCACCT = 0x00000800,
62785 + GR_RELAXPTRACE = 0x00001000,
62786 + GR_NESTED = 0x00002000,
62787 + GR_INHERITLEARN = 0x00004000,
62788 + GR_PROCFIND = 0x00008000,
62789 + GR_POVERRIDE = 0x00010000,
62790 + GR_KERNELAUTH = 0x00020000,
62791 + GR_ATSECURE = 0x00040000,
62792 + GR_SHMEXEC = 0x00080000
62793 +};
62794 +
62795 +enum {
62796 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62797 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62798 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62799 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62800 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62801 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62802 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62803 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62804 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62805 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62806 +};
62807 +
62808 +enum {
62809 + GR_ID_USER = 0x01,
62810 + GR_ID_GROUP = 0x02,
62811 +};
62812 +
62813 +enum {
62814 + GR_ID_ALLOW = 0x01,
62815 + GR_ID_DENY = 0x02,
62816 +};
62817 +
62818 +#define GR_CRASH_RES 31
62819 +#define GR_UIDTABLE_MAX 500
62820 +
62821 +/* begin resource learning section */
62822 +enum {
62823 + GR_RLIM_CPU_BUMP = 60,
62824 + GR_RLIM_FSIZE_BUMP = 50000,
62825 + GR_RLIM_DATA_BUMP = 10000,
62826 + GR_RLIM_STACK_BUMP = 1000,
62827 + GR_RLIM_CORE_BUMP = 10000,
62828 + GR_RLIM_RSS_BUMP = 500000,
62829 + GR_RLIM_NPROC_BUMP = 1,
62830 + GR_RLIM_NOFILE_BUMP = 5,
62831 + GR_RLIM_MEMLOCK_BUMP = 50000,
62832 + GR_RLIM_AS_BUMP = 500000,
62833 + GR_RLIM_LOCKS_BUMP = 2,
62834 + GR_RLIM_SIGPENDING_BUMP = 5,
62835 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62836 + GR_RLIM_NICE_BUMP = 1,
62837 + GR_RLIM_RTPRIO_BUMP = 1,
62838 + GR_RLIM_RTTIME_BUMP = 1000000
62839 +};
62840 +
62841 +#endif
62842 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62843 new file mode 100644
62844 index 0000000..c9292f7
62845 --- /dev/null
62846 +++ b/include/linux/grinternal.h
62847 @@ -0,0 +1,223 @@
62848 +#ifndef __GRINTERNAL_H
62849 +#define __GRINTERNAL_H
62850 +
62851 +#ifdef CONFIG_GRKERNSEC
62852 +
62853 +#include <linux/fs.h>
62854 +#include <linux/mnt_namespace.h>
62855 +#include <linux/nsproxy.h>
62856 +#include <linux/gracl.h>
62857 +#include <linux/grdefs.h>
62858 +#include <linux/grmsg.h>
62859 +
62860 +void gr_add_learn_entry(const char *fmt, ...)
62861 + __attribute__ ((format (printf, 1, 2)));
62862 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62863 + const struct vfsmount *mnt);
62864 +__u32 gr_check_create(const struct dentry *new_dentry,
62865 + const struct dentry *parent,
62866 + const struct vfsmount *mnt, const __u32 mode);
62867 +int gr_check_protected_task(const struct task_struct *task);
62868 +__u32 to_gr_audit(const __u32 reqmode);
62869 +int gr_set_acls(const int type);
62870 +int gr_apply_subject_to_task(struct task_struct *task);
62871 +int gr_acl_is_enabled(void);
62872 +char gr_roletype_to_char(void);
62873 +
62874 +void gr_handle_alertkill(struct task_struct *task);
62875 +char *gr_to_filename(const struct dentry *dentry,
62876 + const struct vfsmount *mnt);
62877 +char *gr_to_filename1(const struct dentry *dentry,
62878 + const struct vfsmount *mnt);
62879 +char *gr_to_filename2(const struct dentry *dentry,
62880 + const struct vfsmount *mnt);
62881 +char *gr_to_filename3(const struct dentry *dentry,
62882 + const struct vfsmount *mnt);
62883 +
62884 +extern int grsec_enable_ptrace_readexec;
62885 +extern int grsec_enable_harden_ptrace;
62886 +extern int grsec_enable_link;
62887 +extern int grsec_enable_fifo;
62888 +extern int grsec_enable_execve;
62889 +extern int grsec_enable_shm;
62890 +extern int grsec_enable_execlog;
62891 +extern int grsec_enable_signal;
62892 +extern int grsec_enable_audit_ptrace;
62893 +extern int grsec_enable_forkfail;
62894 +extern int grsec_enable_time;
62895 +extern int grsec_enable_rofs;
62896 +extern int grsec_enable_chroot_shmat;
62897 +extern int grsec_enable_chroot_mount;
62898 +extern int grsec_enable_chroot_double;
62899 +extern int grsec_enable_chroot_pivot;
62900 +extern int grsec_enable_chroot_chdir;
62901 +extern int grsec_enable_chroot_chmod;
62902 +extern int grsec_enable_chroot_mknod;
62903 +extern int grsec_enable_chroot_fchdir;
62904 +extern int grsec_enable_chroot_nice;
62905 +extern int grsec_enable_chroot_execlog;
62906 +extern int grsec_enable_chroot_caps;
62907 +extern int grsec_enable_chroot_sysctl;
62908 +extern int grsec_enable_chroot_unix;
62909 +extern int grsec_enable_symlinkown;
62910 +extern int grsec_symlinkown_gid;
62911 +extern int grsec_enable_tpe;
62912 +extern int grsec_tpe_gid;
62913 +extern int grsec_enable_tpe_all;
62914 +extern int grsec_enable_tpe_invert;
62915 +extern int grsec_enable_socket_all;
62916 +extern int grsec_socket_all_gid;
62917 +extern int grsec_enable_socket_client;
62918 +extern int grsec_socket_client_gid;
62919 +extern int grsec_enable_socket_server;
62920 +extern int grsec_socket_server_gid;
62921 +extern int grsec_audit_gid;
62922 +extern int grsec_enable_group;
62923 +extern int grsec_enable_audit_textrel;
62924 +extern int grsec_enable_log_rwxmaps;
62925 +extern int grsec_enable_mount;
62926 +extern int grsec_enable_chdir;
62927 +extern int grsec_resource_logging;
62928 +extern int grsec_enable_blackhole;
62929 +extern int grsec_lastack_retries;
62930 +extern int grsec_enable_brute;
62931 +extern int grsec_lock;
62932 +
62933 +extern spinlock_t grsec_alert_lock;
62934 +extern unsigned long grsec_alert_wtime;
62935 +extern unsigned long grsec_alert_fyet;
62936 +
62937 +extern spinlock_t grsec_audit_lock;
62938 +
62939 +extern rwlock_t grsec_exec_file_lock;
62940 +
62941 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62942 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62943 + (tsk)->exec_file->f_vfsmnt) : "/")
62944 +
62945 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62946 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62947 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62948 +
62949 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62950 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62951 + (tsk)->exec_file->f_vfsmnt) : "/")
62952 +
62953 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62954 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62955 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62956 +
62957 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62958 +
62959 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62960 +
62961 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62962 + (task)->pid, (cred)->uid, \
62963 + (cred)->euid, (cred)->gid, (cred)->egid, \
62964 + gr_parent_task_fullpath(task), \
62965 + (task)->real_parent->comm, (task)->real_parent->pid, \
62966 + (pcred)->uid, (pcred)->euid, \
62967 + (pcred)->gid, (pcred)->egid
62968 +
62969 +#define GR_CHROOT_CAPS {{ \
62970 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62971 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62972 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62973 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62974 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62975 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62976 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62977 +
62978 +#define security_learn(normal_msg,args...) \
62979 +({ \
62980 + read_lock(&grsec_exec_file_lock); \
62981 + gr_add_learn_entry(normal_msg "\n", ## args); \
62982 + read_unlock(&grsec_exec_file_lock); \
62983 +})
62984 +
62985 +enum {
62986 + GR_DO_AUDIT,
62987 + GR_DONT_AUDIT,
62988 + /* used for non-audit messages that we shouldn't kill the task on */
62989 + GR_DONT_AUDIT_GOOD
62990 +};
62991 +
62992 +enum {
62993 + GR_TTYSNIFF,
62994 + GR_RBAC,
62995 + GR_RBAC_STR,
62996 + GR_STR_RBAC,
62997 + GR_RBAC_MODE2,
62998 + GR_RBAC_MODE3,
62999 + GR_FILENAME,
63000 + GR_SYSCTL_HIDDEN,
63001 + GR_NOARGS,
63002 + GR_ONE_INT,
63003 + GR_ONE_INT_TWO_STR,
63004 + GR_ONE_STR,
63005 + GR_STR_INT,
63006 + GR_TWO_STR_INT,
63007 + GR_TWO_INT,
63008 + GR_TWO_U64,
63009 + GR_THREE_INT,
63010 + GR_FIVE_INT_TWO_STR,
63011 + GR_TWO_STR,
63012 + GR_THREE_STR,
63013 + GR_FOUR_STR,
63014 + GR_STR_FILENAME,
63015 + GR_FILENAME_STR,
63016 + GR_FILENAME_TWO_INT,
63017 + GR_FILENAME_TWO_INT_STR,
63018 + GR_TEXTREL,
63019 + GR_PTRACE,
63020 + GR_RESOURCE,
63021 + GR_CAP,
63022 + GR_SIG,
63023 + GR_SIG2,
63024 + GR_CRASH1,
63025 + GR_CRASH2,
63026 + GR_PSACCT,
63027 + GR_RWXMAP
63028 +};
63029 +
63030 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
63031 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
63032 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
63033 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
63034 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
63035 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
63036 +#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)
63037 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
63038 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
63039 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
63040 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
63041 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
63042 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
63043 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
63044 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
63045 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
63046 +#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)
63047 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
63048 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
63049 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
63050 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
63051 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
63052 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
63053 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
63054 +#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)
63055 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
63056 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
63057 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
63058 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
63059 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
63060 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
63061 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
63062 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
63063 +#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)
63064 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
63065 +
63066 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
63067 +
63068 +#endif
63069 +
63070 +#endif
63071 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
63072 new file mode 100644
63073 index 0000000..54f4e85
63074 --- /dev/null
63075 +++ b/include/linux/grmsg.h
63076 @@ -0,0 +1,110 @@
63077 +#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"
63078 +#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"
63079 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
63080 +#define GR_STOPMOD_MSG "denied modification of module state by "
63081 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
63082 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
63083 +#define GR_IOPERM_MSG "denied use of ioperm() by "
63084 +#define GR_IOPL_MSG "denied use of iopl() by "
63085 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
63086 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
63087 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
63088 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
63089 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
63090 +#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"
63091 +#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"
63092 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
63093 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
63094 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
63095 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
63096 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
63097 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
63098 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
63099 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
63100 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
63101 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
63102 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
63103 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
63104 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
63105 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
63106 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
63107 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
63108 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
63109 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
63110 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
63111 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
63112 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
63113 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
63114 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
63115 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
63116 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
63117 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
63118 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
63119 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
63120 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
63121 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
63122 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
63123 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
63124 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
63125 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
63126 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
63127 +#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"
63128 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
63129 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
63130 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
63131 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
63132 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
63133 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
63134 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
63135 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
63136 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
63137 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
63138 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
63139 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
63140 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
63141 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
63142 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
63143 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
63144 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
63145 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
63146 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
63147 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
63148 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
63149 +#define GR_NICE_CHROOT_MSG "denied priority change by "
63150 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
63151 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
63152 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
63153 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
63154 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
63155 +#define GR_TIME_MSG "time set by "
63156 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
63157 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
63158 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
63159 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
63160 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
63161 +#define GR_BIND_MSG "denied bind() by "
63162 +#define GR_CONNECT_MSG "denied connect() by "
63163 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
63164 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
63165 +#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"
63166 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
63167 +#define GR_CAP_ACL_MSG "use of %s denied for "
63168 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
63169 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
63170 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
63171 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
63172 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
63173 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
63174 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
63175 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
63176 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
63177 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
63178 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
63179 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
63180 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
63181 +#define GR_VM86_MSG "denied use of vm86 by "
63182 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
63183 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
63184 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
63185 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
63186 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
63187 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
63188 new file mode 100644
63189 index 0000000..187b3ed
63190 --- /dev/null
63191 +++ b/include/linux/grsecurity.h
63192 @@ -0,0 +1,239 @@
63193 +#ifndef GR_SECURITY_H
63194 +#define GR_SECURITY_H
63195 +#include <linux/fs.h>
63196 +#include <linux/fs_struct.h>
63197 +#include <linux/binfmts.h>
63198 +#include <linux/gracl.h>
63199 +
63200 +/* notify of brain-dead configs */
63201 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63202 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
63203 +#endif
63204 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
63205 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
63206 +#endif
63207 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
63208 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
63209 +#endif
63210 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
63211 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
63212 +#endif
63213 +
63214 +#include <linux/compat.h>
63215 +
63216 +struct user_arg_ptr {
63217 +#ifdef CONFIG_COMPAT
63218 + bool is_compat;
63219 +#endif
63220 + union {
63221 + const char __user *const __user *native;
63222 +#ifdef CONFIG_COMPAT
63223 + compat_uptr_t __user *compat;
63224 +#endif
63225 + } ptr;
63226 +};
63227 +
63228 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
63229 +void gr_handle_brute_check(void);
63230 +void gr_handle_kernel_exploit(void);
63231 +int gr_process_user_ban(void);
63232 +
63233 +char gr_roletype_to_char(void);
63234 +
63235 +int gr_acl_enable_at_secure(void);
63236 +
63237 +int gr_check_user_change(int real, int effective, int fs);
63238 +int gr_check_group_change(int real, int effective, int fs);
63239 +
63240 +void gr_del_task_from_ip_table(struct task_struct *p);
63241 +
63242 +int gr_pid_is_chrooted(struct task_struct *p);
63243 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
63244 +int gr_handle_chroot_nice(void);
63245 +int gr_handle_chroot_sysctl(const int op);
63246 +int gr_handle_chroot_setpriority(struct task_struct *p,
63247 + const int niceval);
63248 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
63249 +int gr_handle_chroot_chroot(const struct dentry *dentry,
63250 + const struct vfsmount *mnt);
63251 +void gr_handle_chroot_chdir(struct path *path);
63252 +int gr_handle_chroot_chmod(const struct dentry *dentry,
63253 + const struct vfsmount *mnt, const int mode);
63254 +int gr_handle_chroot_mknod(const struct dentry *dentry,
63255 + const struct vfsmount *mnt, const int mode);
63256 +int gr_handle_chroot_mount(const struct dentry *dentry,
63257 + const struct vfsmount *mnt,
63258 + const char *dev_name);
63259 +int gr_handle_chroot_pivot(void);
63260 +int gr_handle_chroot_unix(const pid_t pid);
63261 +
63262 +int gr_handle_rawio(const struct inode *inode);
63263 +
63264 +void gr_handle_ioperm(void);
63265 +void gr_handle_iopl(void);
63266 +
63267 +umode_t gr_acl_umask(void);
63268 +
63269 +int gr_tpe_allow(const struct file *file);
63270 +
63271 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
63272 +void gr_clear_chroot_entries(struct task_struct *task);
63273 +
63274 +void gr_log_forkfail(const int retval);
63275 +void gr_log_timechange(void);
63276 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
63277 +void gr_log_chdir(const struct dentry *dentry,
63278 + const struct vfsmount *mnt);
63279 +void gr_log_chroot_exec(const struct dentry *dentry,
63280 + const struct vfsmount *mnt);
63281 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
63282 +void gr_log_remount(const char *devname, const int retval);
63283 +void gr_log_unmount(const char *devname, const int retval);
63284 +void gr_log_mount(const char *from, const char *to, const int retval);
63285 +void gr_log_textrel(struct vm_area_struct *vma);
63286 +void gr_log_rwxmmap(struct file *file);
63287 +void gr_log_rwxmprotect(struct file *file);
63288 +
63289 +int gr_handle_follow_link(const struct inode *parent,
63290 + const struct inode *inode,
63291 + const struct dentry *dentry,
63292 + const struct vfsmount *mnt);
63293 +int gr_handle_fifo(const struct dentry *dentry,
63294 + const struct vfsmount *mnt,
63295 + const struct dentry *dir, const int flag,
63296 + const int acc_mode);
63297 +int gr_handle_hardlink(const struct dentry *dentry,
63298 + const struct vfsmount *mnt,
63299 + struct inode *inode,
63300 + const int mode, const char *to);
63301 +
63302 +int gr_is_capable(const int cap);
63303 +int gr_is_capable_nolog(const int cap);
63304 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63305 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
63306 +
63307 +void gr_learn_resource(const struct task_struct *task, const int limit,
63308 + const unsigned long wanted, const int gt);
63309 +void gr_copy_label(struct task_struct *tsk);
63310 +void gr_handle_crash(struct task_struct *task, const int sig);
63311 +int gr_handle_signal(const struct task_struct *p, const int sig);
63312 +int gr_check_crash_uid(const uid_t uid);
63313 +int gr_check_protected_task(const struct task_struct *task);
63314 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63315 +int gr_acl_handle_mmap(const struct file *file,
63316 + const unsigned long prot);
63317 +int gr_acl_handle_mprotect(const struct file *file,
63318 + const unsigned long prot);
63319 +int gr_check_hidden_task(const struct task_struct *tsk);
63320 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63321 + const struct vfsmount *mnt);
63322 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
63323 + const struct vfsmount *mnt);
63324 +__u32 gr_acl_handle_access(const struct dentry *dentry,
63325 + const struct vfsmount *mnt, const int fmode);
63326 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63327 + const struct vfsmount *mnt, umode_t *mode);
63328 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
63329 + const struct vfsmount *mnt);
63330 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63331 + const struct vfsmount *mnt);
63332 +int gr_handle_ptrace(struct task_struct *task, const long request);
63333 +int gr_handle_proc_ptrace(struct task_struct *task);
63334 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
63335 + const struct vfsmount *mnt);
63336 +int gr_check_crash_exec(const struct file *filp);
63337 +int gr_acl_is_enabled(void);
63338 +void gr_set_kernel_label(struct task_struct *task);
63339 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
63340 + const gid_t gid);
63341 +int gr_set_proc_label(const struct dentry *dentry,
63342 + const struct vfsmount *mnt,
63343 + const int unsafe_flags);
63344 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63345 + const struct vfsmount *mnt);
63346 +__u32 gr_acl_handle_open(const struct dentry *dentry,
63347 + const struct vfsmount *mnt, int acc_mode);
63348 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
63349 + const struct dentry *p_dentry,
63350 + const struct vfsmount *p_mnt,
63351 + int open_flags, int acc_mode, const int imode);
63352 +void gr_handle_create(const struct dentry *dentry,
63353 + const struct vfsmount *mnt);
63354 +void gr_handle_proc_create(const struct dentry *dentry,
63355 + const struct inode *inode);
63356 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63357 + const struct dentry *parent_dentry,
63358 + const struct vfsmount *parent_mnt,
63359 + const int mode);
63360 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63361 + const struct dentry *parent_dentry,
63362 + const struct vfsmount *parent_mnt);
63363 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63364 + const struct vfsmount *mnt);
63365 +void gr_handle_delete(const ino_t ino, const dev_t dev);
63366 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63367 + const struct vfsmount *mnt);
63368 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63369 + const struct dentry *parent_dentry,
63370 + const struct vfsmount *parent_mnt,
63371 + const char *from);
63372 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63373 + const struct dentry *parent_dentry,
63374 + const struct vfsmount *parent_mnt,
63375 + const struct dentry *old_dentry,
63376 + const struct vfsmount *old_mnt, const char *to);
63377 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
63378 +int gr_acl_handle_rename(struct dentry *new_dentry,
63379 + struct dentry *parent_dentry,
63380 + const struct vfsmount *parent_mnt,
63381 + struct dentry *old_dentry,
63382 + struct inode *old_parent_inode,
63383 + struct vfsmount *old_mnt, const char *newname);
63384 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63385 + struct dentry *old_dentry,
63386 + struct dentry *new_dentry,
63387 + struct vfsmount *mnt, const __u8 replace);
63388 +__u32 gr_check_link(const struct dentry *new_dentry,
63389 + const struct dentry *parent_dentry,
63390 + const struct vfsmount *parent_mnt,
63391 + const struct dentry *old_dentry,
63392 + const struct vfsmount *old_mnt);
63393 +int gr_acl_handle_filldir(const struct file *file, const char *name,
63394 + const unsigned int namelen, const ino_t ino);
63395 +
63396 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
63397 + const struct vfsmount *mnt);
63398 +void gr_acl_handle_exit(void);
63399 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
63400 +int gr_acl_handle_procpidmem(const struct task_struct *task);
63401 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63402 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63403 +void gr_audit_ptrace(struct task_struct *task);
63404 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63405 +void gr_put_exec_file(struct task_struct *task);
63406 +
63407 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
63408 +
63409 +#ifdef CONFIG_GRKERNSEC
63410 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63411 +void gr_handle_vm86(void);
63412 +void gr_handle_mem_readwrite(u64 from, u64 to);
63413 +
63414 +void gr_log_badprocpid(const char *entry);
63415 +
63416 +extern int grsec_enable_dmesg;
63417 +extern int grsec_disable_privio;
63418 +
63419 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63420 +extern int grsec_proc_gid;
63421 +#endif
63422 +
63423 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63424 +extern int grsec_enable_chroot_findtask;
63425 +#endif
63426 +#ifdef CONFIG_GRKERNSEC_SETXID
63427 +extern int grsec_enable_setxid;
63428 +#endif
63429 +#endif
63430 +
63431 +#endif
63432 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
63433 new file mode 100644
63434 index 0000000..e7ffaaf
63435 --- /dev/null
63436 +++ b/include/linux/grsock.h
63437 @@ -0,0 +1,19 @@
63438 +#ifndef __GRSOCK_H
63439 +#define __GRSOCK_H
63440 +
63441 +extern void gr_attach_curr_ip(const struct sock *sk);
63442 +extern int gr_handle_sock_all(const int family, const int type,
63443 + const int protocol);
63444 +extern int gr_handle_sock_server(const struct sockaddr *sck);
63445 +extern int gr_handle_sock_server_other(const struct sock *sck);
63446 +extern int gr_handle_sock_client(const struct sockaddr *sck);
63447 +extern int gr_search_connect(struct socket * sock,
63448 + struct sockaddr_in * addr);
63449 +extern int gr_search_bind(struct socket * sock,
63450 + struct sockaddr_in * addr);
63451 +extern int gr_search_listen(struct socket * sock);
63452 +extern int gr_search_accept(struct socket * sock);
63453 +extern int gr_search_socket(const int domain, const int type,
63454 + const int protocol);
63455 +
63456 +#endif
63457 diff --git a/include/linux/hid.h b/include/linux/hid.h
63458 index 42970de..5db3c92 100644
63459 --- a/include/linux/hid.h
63460 +++ b/include/linux/hid.h
63461 @@ -705,7 +705,7 @@ struct hid_ll_driver {
63462 unsigned int code, int value);
63463
63464 int (*parse)(struct hid_device *hdev);
63465 -};
63466 +} __no_const;
63467
63468 #define PM_HINT_FULLON 1<<5
63469 #define PM_HINT_NORMAL 1<<1
63470 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
63471 index ef788b5..ac41b7b 100644
63472 --- a/include/linux/highmem.h
63473 +++ b/include/linux/highmem.h
63474 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
63475 kunmap_atomic(kaddr);
63476 }
63477
63478 +static inline void sanitize_highpage(struct page *page)
63479 +{
63480 + void *kaddr;
63481 + unsigned long flags;
63482 +
63483 + local_irq_save(flags);
63484 + kaddr = kmap_atomic(page);
63485 + clear_page(kaddr);
63486 + kunmap_atomic(kaddr);
63487 + local_irq_restore(flags);
63488 +}
63489 +
63490 static inline void zero_user_segments(struct page *page,
63491 unsigned start1, unsigned end1,
63492 unsigned start2, unsigned end2)
63493 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
63494 index 5970266..1c48c3b 100644
63495 --- a/include/linux/i2c.h
63496 +++ b/include/linux/i2c.h
63497 @@ -369,6 +369,7 @@ struct i2c_algorithm {
63498 /* To determine what the adapter supports */
63499 u32 (*functionality) (struct i2c_adapter *);
63500 };
63501 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63502
63503 /*
63504 * i2c_adapter is the structure used to identify a physical i2c bus along
63505 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63506 index d23c3c2..eb63c81 100644
63507 --- a/include/linux/i2o.h
63508 +++ b/include/linux/i2o.h
63509 @@ -565,7 +565,7 @@ struct i2o_controller {
63510 struct i2o_device *exec; /* Executive */
63511 #if BITS_PER_LONG == 64
63512 spinlock_t context_list_lock; /* lock for context_list */
63513 - atomic_t context_list_counter; /* needed for unique contexts */
63514 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63515 struct list_head context_list; /* list of context id's
63516 and pointers */
63517 #endif
63518 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63519 index aa2e167..84024ce 100644
63520 --- a/include/linux/if_team.h
63521 +++ b/include/linux/if_team.h
63522 @@ -109,6 +109,7 @@ struct team_mode_ops {
63523 void (*port_enabled)(struct team *team, struct team_port *port);
63524 void (*port_disabled)(struct team *team, struct team_port *port);
63525 };
63526 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63527
63528 enum team_option_type {
63529 TEAM_OPTION_TYPE_U32,
63530 @@ -181,7 +182,7 @@ struct team {
63531 struct list_head option_inst_list; /* list of option instances */
63532
63533 const struct team_mode *mode;
63534 - struct team_mode_ops ops;
63535 + team_mode_ops_no_const ops;
63536 long mode_priv[TEAM_MODE_PRIV_LONGS];
63537 };
63538
63539 diff --git a/include/linux/init.h b/include/linux/init.h
63540 index 5e664f6..15ae326 100644
63541 --- a/include/linux/init.h
63542 +++ b/include/linux/init.h
63543 @@ -39,9 +39,33 @@
63544 * Also note, that this data cannot be "const".
63545 */
63546
63547 +#ifdef MODULE
63548 +#define add_init_latent_entropy
63549 +#else
63550 +#define add_init_latent_entropy __latent_entropy
63551 +#endif
63552 +
63553 +#ifdef CONFIG_HOTPLUG
63554 +#define add_devinit_latent_entropy
63555 +#else
63556 +#define add_devinit_latent_entropy __latent_entropy
63557 +#endif
63558 +
63559 +#ifdef CONFIG_HOTPLUG_CPU
63560 +#define add_cpuinit_latent_entropy
63561 +#else
63562 +#define add_cpuinit_latent_entropy __latent_entropy
63563 +#endif
63564 +
63565 +#ifdef CONFIG_MEMORY_HOTPLUG
63566 +#define add_meminit_latent_entropy
63567 +#else
63568 +#define add_meminit_latent_entropy __latent_entropy
63569 +#endif
63570 +
63571 /* These are for everybody (although not all archs will actually
63572 discard it in modules) */
63573 -#define __init __section(.init.text) __cold notrace
63574 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
63575 #define __initdata __section(.init.data)
63576 #define __initconst __section(.init.rodata)
63577 #define __exitdata __section(.exit.data)
63578 @@ -83,7 +107,7 @@
63579 #define __exit __section(.exit.text) __exitused __cold notrace
63580
63581 /* Used for HOTPLUG */
63582 -#define __devinit __section(.devinit.text) __cold notrace
63583 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
63584 #define __devinitdata __section(.devinit.data)
63585 #define __devinitconst __section(.devinit.rodata)
63586 #define __devexit __section(.devexit.text) __exitused __cold notrace
63587 @@ -91,7 +115,7 @@
63588 #define __devexitconst __section(.devexit.rodata)
63589
63590 /* Used for HOTPLUG_CPU */
63591 -#define __cpuinit __section(.cpuinit.text) __cold notrace
63592 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
63593 #define __cpuinitdata __section(.cpuinit.data)
63594 #define __cpuinitconst __section(.cpuinit.rodata)
63595 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63596 @@ -99,7 +123,7 @@
63597 #define __cpuexitconst __section(.cpuexit.rodata)
63598
63599 /* Used for MEMORY_HOTPLUG */
63600 -#define __meminit __section(.meminit.text) __cold notrace
63601 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
63602 #define __meminitdata __section(.meminit.data)
63603 #define __meminitconst __section(.meminit.rodata)
63604 #define __memexit __section(.memexit.text) __exitused __cold notrace
63605 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63606 index 89f1cb1..7986c0f 100644
63607 --- a/include/linux/init_task.h
63608 +++ b/include/linux/init_task.h
63609 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63610
63611 #define INIT_TASK_COMM "swapper"
63612
63613 +#ifdef CONFIG_X86
63614 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63615 +#else
63616 +#define INIT_TASK_THREAD_INFO
63617 +#endif
63618 +
63619 /*
63620 * INIT_TASK is used to set up the first task table, touch at
63621 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63622 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63623 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63624 .comm = INIT_TASK_COMM, \
63625 .thread = INIT_THREAD, \
63626 + INIT_TASK_THREAD_INFO \
63627 .fs = &init_fs, \
63628 .files = &init_files, \
63629 .signal = &init_signals, \
63630 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63631 index 78e2ada..745564d 100644
63632 --- a/include/linux/intel-iommu.h
63633 +++ b/include/linux/intel-iommu.h
63634 @@ -296,7 +296,7 @@ struct iommu_flush {
63635 u8 fm, u64 type);
63636 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63637 unsigned int size_order, u64 type);
63638 -};
63639 +} __no_const;
63640
63641 enum {
63642 SR_DMAR_FECTL_REG,
63643 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63644 index c5f856a..d29c117 100644
63645 --- a/include/linux/interrupt.h
63646 +++ b/include/linux/interrupt.h
63647 @@ -433,7 +433,7 @@ enum
63648 /* map softirq index to softirq name. update 'softirq_to_name' in
63649 * kernel/softirq.c when adding a new softirq.
63650 */
63651 -extern char *softirq_to_name[NR_SOFTIRQS];
63652 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63653
63654 /* softirq mask and active fields moved to irq_cpustat_t in
63655 * asm/hardirq.h to get better cache usage. KAO
63656 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63657
63658 struct softirq_action
63659 {
63660 - void (*action)(struct softirq_action *);
63661 + void (*action)(void);
63662 };
63663
63664 asmlinkage void do_softirq(void);
63665 asmlinkage void __do_softirq(void);
63666 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63667 +extern void open_softirq(int nr, void (*action)(void));
63668 extern void softirq_init(void);
63669 extern void __raise_softirq_irqoff(unsigned int nr);
63670
63671 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63672 index 6883e19..06992b1 100644
63673 --- a/include/linux/kallsyms.h
63674 +++ b/include/linux/kallsyms.h
63675 @@ -15,7 +15,8 @@
63676
63677 struct module;
63678
63679 -#ifdef CONFIG_KALLSYMS
63680 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63681 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63682 /* Lookup the address for a symbol. Returns 0 if not found. */
63683 unsigned long kallsyms_lookup_name(const char *name);
63684
63685 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63686 /* Stupid that this does nothing, but I didn't create this mess. */
63687 #define __print_symbol(fmt, addr)
63688 #endif /*CONFIG_KALLSYMS*/
63689 +#else /* when included by kallsyms.c, vsnprintf.c, or
63690 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63691 +extern void __print_symbol(const char *fmt, unsigned long address);
63692 +extern int sprint_backtrace(char *buffer, unsigned long address);
63693 +extern int sprint_symbol(char *buffer, unsigned long address);
63694 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63695 +const char *kallsyms_lookup(unsigned long addr,
63696 + unsigned long *symbolsize,
63697 + unsigned long *offset,
63698 + char **modname, char *namebuf);
63699 +#endif
63700
63701 /* This macro allows us to keep printk typechecking */
63702 static __printf(1, 2)
63703 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63704 index c4d2fc1..5df9c19 100644
63705 --- a/include/linux/kgdb.h
63706 +++ b/include/linux/kgdb.h
63707 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63708 extern int kgdb_io_module_registered;
63709
63710 extern atomic_t kgdb_setting_breakpoint;
63711 -extern atomic_t kgdb_cpu_doing_single_step;
63712 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63713
63714 extern struct task_struct *kgdb_usethread;
63715 extern struct task_struct *kgdb_contthread;
63716 @@ -252,7 +252,7 @@ struct kgdb_arch {
63717 void (*disable_hw_break)(struct pt_regs *regs);
63718 void (*remove_all_hw_break)(void);
63719 void (*correct_hw_break)(void);
63720 -};
63721 +} __do_const;
63722
63723 /**
63724 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63725 @@ -277,7 +277,7 @@ struct kgdb_io {
63726 void (*pre_exception) (void);
63727 void (*post_exception) (void);
63728 int is_console;
63729 -};
63730 +} __do_const;
63731
63732 extern struct kgdb_arch arch_kgdb_ops;
63733
63734 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63735 index 5398d58..5883a34 100644
63736 --- a/include/linux/kmod.h
63737 +++ b/include/linux/kmod.h
63738 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63739 * usually useless though. */
63740 extern __printf(2, 3)
63741 int __request_module(bool wait, const char *name, ...);
63742 +extern __printf(3, 4)
63743 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63744 #define request_module(mod...) __request_module(true, mod)
63745 #define request_module_nowait(mod...) __request_module(false, mod)
63746 #define try_then_request_module(x, mod...) \
63747 diff --git a/include/linux/kref.h b/include/linux/kref.h
63748 index 65af688..0592677 100644
63749 --- a/include/linux/kref.h
63750 +++ b/include/linux/kref.h
63751 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63752 static inline int kref_sub(struct kref *kref, unsigned int count,
63753 void (*release)(struct kref *kref))
63754 {
63755 - WARN_ON(release == NULL);
63756 + BUG_ON(release == NULL);
63757
63758 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63759 release(kref);
63760 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63761 index b70b48b..0d7153b 100644
63762 --- a/include/linux/kvm_host.h
63763 +++ b/include/linux/kvm_host.h
63764 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63765 void vcpu_load(struct kvm_vcpu *vcpu);
63766 void vcpu_put(struct kvm_vcpu *vcpu);
63767
63768 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63769 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63770 struct module *module);
63771 void kvm_exit(void);
63772
63773 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63774 struct kvm_guest_debug *dbg);
63775 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63776
63777 -int kvm_arch_init(void *opaque);
63778 +int kvm_arch_init(const void *opaque);
63779 void kvm_arch_exit(void);
63780
63781 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63782 diff --git a/include/linux/libata.h b/include/linux/libata.h
63783 index 64f90e1..32b945b 100644
63784 --- a/include/linux/libata.h
63785 +++ b/include/linux/libata.h
63786 @@ -909,7 +909,7 @@ struct ata_port_operations {
63787 * fields must be pointers.
63788 */
63789 const struct ata_port_operations *inherits;
63790 -};
63791 +} __do_const;
63792
63793 struct ata_port_info {
63794 unsigned long flags;
63795 diff --git a/include/linux/memory.h b/include/linux/memory.h
63796 index ff9a9f8..c715deb 100644
63797 --- a/include/linux/memory.h
63798 +++ b/include/linux/memory.h
63799 @@ -143,7 +143,7 @@ struct memory_accessor {
63800 size_t count);
63801 ssize_t (*write)(struct memory_accessor *, const char *buf,
63802 off_t offset, size_t count);
63803 -};
63804 +} __no_const;
63805
63806 /*
63807 * Kernel text modification mutex, used for code patching. Users of this lock
63808 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63809 index 1318ca6..7521340 100644
63810 --- a/include/linux/mfd/abx500.h
63811 +++ b/include/linux/mfd/abx500.h
63812 @@ -452,6 +452,7 @@ struct abx500_ops {
63813 int (*event_registers_startup_state_get) (struct device *, u8 *);
63814 int (*startup_irq_enabled) (struct device *, unsigned int);
63815 };
63816 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63817
63818 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63819 void abx500_remove_ops(struct device *dev);
63820 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63821 index 9b07725..3d55001 100644
63822 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63823 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63824 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63825 int (*enable) (struct ux500_charger *, int, int, int);
63826 int (*kick_wd) (struct ux500_charger *);
63827 int (*update_curr) (struct ux500_charger *, int);
63828 -};
63829 +} __no_const;
63830
63831 /**
63832 * struct ux500_charger - power supply ux500 charger sub class
63833 diff --git a/include/linux/mm.h b/include/linux/mm.h
63834 index 311be90..5f1638c 100644
63835 --- a/include/linux/mm.h
63836 +++ b/include/linux/mm.h
63837 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63838
63839 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63840 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63841 +
63842 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63843 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63844 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63845 +#else
63846 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63847 +#endif
63848 +
63849 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63850 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63851
63852 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63853 int set_page_dirty_lock(struct page *page);
63854 int clear_page_dirty_for_io(struct page *page);
63855
63856 -/* Is the vma a continuation of the stack vma above it? */
63857 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63858 -{
63859 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63860 -}
63861 -
63862 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63863 - unsigned long addr)
63864 -{
63865 - return (vma->vm_flags & VM_GROWSDOWN) &&
63866 - (vma->vm_start == addr) &&
63867 - !vma_growsdown(vma->vm_prev, addr);
63868 -}
63869 -
63870 -/* Is the vma a continuation of the stack vma below it? */
63871 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63872 -{
63873 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63874 -}
63875 -
63876 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63877 - unsigned long addr)
63878 -{
63879 - return (vma->vm_flags & VM_GROWSUP) &&
63880 - (vma->vm_end == addr) &&
63881 - !vma_growsup(vma->vm_next, addr);
63882 -}
63883 -
63884 extern pid_t
63885 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63886
63887 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63888 }
63889 #endif
63890
63891 +#ifdef CONFIG_MMU
63892 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63893 +#else
63894 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63895 +{
63896 + return __pgprot(0);
63897 +}
63898 +#endif
63899 +
63900 int vma_wants_writenotify(struct vm_area_struct *vma);
63901
63902 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63903 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63904 {
63905 return 0;
63906 }
63907 +
63908 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63909 + unsigned long address)
63910 +{
63911 + return 0;
63912 +}
63913 #else
63914 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63915 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63916 #endif
63917
63918 #ifdef __PAGETABLE_PMD_FOLDED
63919 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63920 {
63921 return 0;
63922 }
63923 +
63924 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63925 + unsigned long address)
63926 +{
63927 + return 0;
63928 +}
63929 #else
63930 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63931 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63932 #endif
63933
63934 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63935 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63936 NULL: pud_offset(pgd, address);
63937 }
63938
63939 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63940 +{
63941 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63942 + NULL: pud_offset(pgd, address);
63943 +}
63944 +
63945 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63946 {
63947 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63948 NULL: pmd_offset(pud, address);
63949 }
63950 +
63951 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63952 +{
63953 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63954 + NULL: pmd_offset(pud, address);
63955 +}
63956 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63957
63958 #if USE_SPLIT_PTLOCKS
63959 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63960 unsigned long, unsigned long,
63961 unsigned long, unsigned long);
63962 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63963 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63964
63965 /* These take the mm semaphore themselves */
63966 extern unsigned long vm_brk(unsigned long, unsigned long);
63967 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63968 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63969 struct vm_area_struct **pprev);
63970
63971 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63972 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63973 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63974 +
63975 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63976 NULL if none. Assume start_addr < end_addr. */
63977 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63978 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63979 return vma;
63980 }
63981
63982 -#ifdef CONFIG_MMU
63983 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63984 -#else
63985 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63986 -{
63987 - return __pgprot(0);
63988 -}
63989 -#endif
63990 -
63991 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63992 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63993 unsigned long pfn, unsigned long size, pgprot_t);
63994 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63995 extern int sysctl_memory_failure_early_kill;
63996 extern int sysctl_memory_failure_recovery;
63997 extern void shake_page(struct page *p, int access);
63998 -extern atomic_long_t mce_bad_pages;
63999 +extern atomic_long_unchecked_t mce_bad_pages;
64000 extern int soft_offline_page(struct page *page, int flags);
64001
64002 extern void dump_page(struct page *page);
64003 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
64004 static inline bool page_is_guard(struct page *page) { return false; }
64005 #endif /* CONFIG_DEBUG_PAGEALLOC */
64006
64007 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64008 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
64009 +#else
64010 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
64011 +#endif
64012 +
64013 #endif /* __KERNEL__ */
64014 #endif /* _LINUX_MM_H */
64015 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
64016 index bf78672..debc693 100644
64017 --- a/include/linux/mm_types.h
64018 +++ b/include/linux/mm_types.h
64019 @@ -279,6 +279,8 @@ struct vm_area_struct {
64020 #ifdef CONFIG_NUMA
64021 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
64022 #endif
64023 +
64024 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
64025 };
64026
64027 struct core_thread {
64028 @@ -353,7 +355,7 @@ struct mm_struct {
64029 unsigned long def_flags;
64030 unsigned long nr_ptes; /* Page table pages */
64031 unsigned long start_code, end_code, start_data, end_data;
64032 - unsigned long start_brk, brk, start_stack;
64033 + unsigned long brk_gap, start_brk, brk, start_stack;
64034 unsigned long arg_start, arg_end, env_start, env_end;
64035
64036 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
64037 @@ -405,6 +407,24 @@ struct mm_struct {
64038 struct cpumask cpumask_allocation;
64039 #endif
64040 struct uprobes_state uprobes_state;
64041 +
64042 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64043 + unsigned long pax_flags;
64044 +#endif
64045 +
64046 +#ifdef CONFIG_PAX_DLRESOLVE
64047 + unsigned long call_dl_resolve;
64048 +#endif
64049 +
64050 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
64051 + unsigned long call_syscall;
64052 +#endif
64053 +
64054 +#ifdef CONFIG_PAX_ASLR
64055 + unsigned long delta_mmap; /* randomized offset */
64056 + unsigned long delta_stack; /* randomized offset */
64057 +#endif
64058 +
64059 };
64060
64061 static inline void mm_init_cpumask(struct mm_struct *mm)
64062 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
64063 index 1d1b1e1..2a13c78 100644
64064 --- a/include/linux/mmu_notifier.h
64065 +++ b/include/linux/mmu_notifier.h
64066 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
64067 */
64068 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
64069 ({ \
64070 - pte_t __pte; \
64071 + pte_t ___pte; \
64072 struct vm_area_struct *___vma = __vma; \
64073 unsigned long ___address = __address; \
64074 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
64075 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
64076 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
64077 - __pte; \
64078 + ___pte; \
64079 })
64080
64081 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
64082 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
64083 index 2daa54f..bfdf2f5 100644
64084 --- a/include/linux/mmzone.h
64085 +++ b/include/linux/mmzone.h
64086 @@ -414,7 +414,7 @@ struct zone {
64087 unsigned long flags; /* zone flags, see below */
64088
64089 /* Zone statistics */
64090 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64091 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64092
64093 /*
64094 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
64095 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
64096 index 6955045..ebdb7cd 100644
64097 --- a/include/linux/mod_devicetable.h
64098 +++ b/include/linux/mod_devicetable.h
64099 @@ -12,7 +12,7 @@
64100 typedef unsigned long kernel_ulong_t;
64101 #endif
64102
64103 -#define PCI_ANY_ID (~0)
64104 +#define PCI_ANY_ID ((__u16)~0)
64105
64106 struct pci_device_id {
64107 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
64108 @@ -139,7 +139,7 @@ struct usb_device_id {
64109 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
64110 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
64111
64112 -#define HID_ANY_ID (~0)
64113 +#define HID_ANY_ID (~0U)
64114 #define HID_BUS_ANY 0xffff
64115 #define HID_GROUP_ANY 0x0000
64116
64117 diff --git a/include/linux/module.h b/include/linux/module.h
64118 index fbcafe2..e5d9587 100644
64119 --- a/include/linux/module.h
64120 +++ b/include/linux/module.h
64121 @@ -17,6 +17,7 @@
64122 #include <linux/moduleparam.h>
64123 #include <linux/tracepoint.h>
64124 #include <linux/export.h>
64125 +#include <linux/fs.h>
64126
64127 #include <linux/percpu.h>
64128 #include <asm/module.h>
64129 @@ -273,19 +274,16 @@ struct module
64130 int (*init)(void);
64131
64132 /* If this is non-NULL, vfree after init() returns */
64133 - void *module_init;
64134 + void *module_init_rx, *module_init_rw;
64135
64136 /* Here is the actual code + data, vfree'd on unload. */
64137 - void *module_core;
64138 + void *module_core_rx, *module_core_rw;
64139
64140 /* Here are the sizes of the init and core sections */
64141 - unsigned int init_size, core_size;
64142 + unsigned int init_size_rw, core_size_rw;
64143
64144 /* The size of the executable code in each section. */
64145 - unsigned int init_text_size, core_text_size;
64146 -
64147 - /* Size of RO sections of the module (text+rodata) */
64148 - unsigned int init_ro_size, core_ro_size;
64149 + unsigned int init_size_rx, core_size_rx;
64150
64151 /* Arch-specific module values */
64152 struct mod_arch_specific arch;
64153 @@ -341,6 +339,10 @@ struct module
64154 #ifdef CONFIG_EVENT_TRACING
64155 struct ftrace_event_call **trace_events;
64156 unsigned int num_trace_events;
64157 + struct file_operations trace_id;
64158 + struct file_operations trace_enable;
64159 + struct file_operations trace_format;
64160 + struct file_operations trace_filter;
64161 #endif
64162 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
64163 unsigned int num_ftrace_callsites;
64164 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
64165 bool is_module_percpu_address(unsigned long addr);
64166 bool is_module_text_address(unsigned long addr);
64167
64168 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
64169 +{
64170 +
64171 +#ifdef CONFIG_PAX_KERNEXEC
64172 + if (ktla_ktva(addr) >= (unsigned long)start &&
64173 + ktla_ktva(addr) < (unsigned long)start + size)
64174 + return 1;
64175 +#endif
64176 +
64177 + return ((void *)addr >= start && (void *)addr < start + size);
64178 +}
64179 +
64180 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
64181 +{
64182 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
64183 +}
64184 +
64185 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
64186 +{
64187 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
64188 +}
64189 +
64190 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
64191 +{
64192 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
64193 +}
64194 +
64195 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
64196 +{
64197 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
64198 +}
64199 +
64200 static inline int within_module_core(unsigned long addr, struct module *mod)
64201 {
64202 - return (unsigned long)mod->module_core <= addr &&
64203 - addr < (unsigned long)mod->module_core + mod->core_size;
64204 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
64205 }
64206
64207 static inline int within_module_init(unsigned long addr, struct module *mod)
64208 {
64209 - return (unsigned long)mod->module_init <= addr &&
64210 - addr < (unsigned long)mod->module_init + mod->init_size;
64211 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
64212 }
64213
64214 /* Search for module by name: must hold module_mutex. */
64215 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
64216 index b2be02e..72d2f78 100644
64217 --- a/include/linux/moduleloader.h
64218 +++ b/include/linux/moduleloader.h
64219 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
64220
64221 /* Allocator used for allocating struct module, core sections and init
64222 sections. Returns NULL on failure. */
64223 -void *module_alloc(unsigned long size);
64224 +void *module_alloc(unsigned long size) __size_overflow(1);
64225 +
64226 +#ifdef CONFIG_PAX_KERNEXEC
64227 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
64228 +#else
64229 +#define module_alloc_exec(x) module_alloc(x)
64230 +#endif
64231
64232 /* Free memory returned from module_alloc. */
64233 void module_free(struct module *mod, void *module_region);
64234
64235 +#ifdef CONFIG_PAX_KERNEXEC
64236 +void module_free_exec(struct module *mod, void *module_region);
64237 +#else
64238 +#define module_free_exec(x, y) module_free((x), (y))
64239 +#endif
64240 +
64241 /* Apply the given relocation to the (simplified) ELF. Return -error
64242 or 0. */
64243 int apply_relocate(Elf_Shdr *sechdrs,
64244 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
64245 index d6a5806..7c13347 100644
64246 --- a/include/linux/moduleparam.h
64247 +++ b/include/linux/moduleparam.h
64248 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
64249 * @len is usually just sizeof(string).
64250 */
64251 #define module_param_string(name, string, len, perm) \
64252 - static const struct kparam_string __param_string_##name \
64253 + static const struct kparam_string __param_string_##name __used \
64254 = { len, string }; \
64255 __module_param_call(MODULE_PARAM_PREFIX, name, \
64256 &param_ops_string, \
64257 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
64258 */
64259 #define module_param_array_named(name, array, type, nump, perm) \
64260 param_check_##type(name, &(array)[0]); \
64261 - static const struct kparam_array __param_arr_##name \
64262 + static const struct kparam_array __param_arr_##name __used \
64263 = { .max = ARRAY_SIZE(array), .num = nump, \
64264 .ops = &param_ops_##type, \
64265 .elemsize = sizeof(array[0]), .elem = array }; \
64266 diff --git a/include/linux/namei.h b/include/linux/namei.h
64267 index 4bf19d8..5268cea 100644
64268 --- a/include/linux/namei.h
64269 +++ b/include/linux/namei.h
64270 @@ -18,7 +18,7 @@ struct nameidata {
64271 unsigned seq;
64272 int last_type;
64273 unsigned depth;
64274 - char *saved_names[MAX_NESTED_LINKS + 1];
64275 + const char *saved_names[MAX_NESTED_LINKS + 1];
64276 };
64277
64278 /*
64279 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
64280
64281 extern void nd_jump_link(struct nameidata *nd, struct path *path);
64282
64283 -static inline void nd_set_link(struct nameidata *nd, char *path)
64284 +static inline void nd_set_link(struct nameidata *nd, const char *path)
64285 {
64286 nd->saved_names[nd->depth] = path;
64287 }
64288
64289 -static inline char *nd_get_link(struct nameidata *nd)
64290 +static inline const char *nd_get_link(const struct nameidata *nd)
64291 {
64292 return nd->saved_names[nd->depth];
64293 }
64294 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
64295 index 59dc05f3..c905a34 100644
64296 --- a/include/linux/netdevice.h
64297 +++ b/include/linux/netdevice.h
64298 @@ -1027,6 +1027,7 @@ struct net_device_ops {
64299 struct net_device *dev,
64300 int idx);
64301 };
64302 +typedef struct net_device_ops __no_const net_device_ops_no_const;
64303
64304 /*
64305 * The DEVICE structure.
64306 @@ -1087,7 +1088,7 @@ struct net_device {
64307 int iflink;
64308
64309 struct net_device_stats stats;
64310 - atomic_long_t rx_dropped; /* dropped packets by core network
64311 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
64312 * Do not use this in drivers.
64313 */
64314
64315 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
64316 new file mode 100644
64317 index 0000000..33f4af8
64318 --- /dev/null
64319 +++ b/include/linux/netfilter/xt_gradm.h
64320 @@ -0,0 +1,9 @@
64321 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
64322 +#define _LINUX_NETFILTER_XT_GRADM_H 1
64323 +
64324 +struct xt_gradm_mtinfo {
64325 + __u16 flags;
64326 + __u16 invflags;
64327 +};
64328 +
64329 +#endif
64330 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
64331 index c65a18a..0c05f3a 100644
64332 --- a/include/linux/of_pdt.h
64333 +++ b/include/linux/of_pdt.h
64334 @@ -32,7 +32,7 @@ struct of_pdt_ops {
64335
64336 /* return 0 on success; fill in 'len' with number of bytes in path */
64337 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
64338 -};
64339 +} __no_const;
64340
64341 extern void *prom_early_alloc(unsigned long size);
64342
64343 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
64344 index a4c5624..79d6d88 100644
64345 --- a/include/linux/oprofile.h
64346 +++ b/include/linux/oprofile.h
64347 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
64348 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64349 char const * name, ulong * val);
64350
64351 -/** Create a file for read-only access to an atomic_t. */
64352 +/** Create a file for read-only access to an atomic_unchecked_t. */
64353 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64354 - char const * name, atomic_t * val);
64355 + char const * name, atomic_unchecked_t * val);
64356
64357 /** create a directory */
64358 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64359 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
64360 index bdb4161..f373d41 100644
64361 --- a/include/linux/perf_event.h
64362 +++ b/include/linux/perf_event.h
64363 @@ -882,8 +882,8 @@ struct perf_event {
64364
64365 enum perf_event_active_state state;
64366 unsigned int attach_state;
64367 - local64_t count;
64368 - atomic64_t child_count;
64369 + local64_t count; /* PaX: fix it one day */
64370 + atomic64_unchecked_t child_count;
64371
64372 /*
64373 * These are the total time in nanoseconds that the event
64374 @@ -934,8 +934,8 @@ struct perf_event {
64375 * These accumulate total time (in nanoseconds) that children
64376 * events have been enabled and running, respectively.
64377 */
64378 - atomic64_t child_total_time_enabled;
64379 - atomic64_t child_total_time_running;
64380 + atomic64_unchecked_t child_total_time_enabled;
64381 + atomic64_unchecked_t child_total_time_running;
64382
64383 /*
64384 * Protect attach/detach and child_list:
64385 diff --git a/include/linux/personality.h b/include/linux/personality.h
64386 index 8fc7dd1a..c19d89e 100644
64387 --- a/include/linux/personality.h
64388 +++ b/include/linux/personality.h
64389 @@ -44,6 +44,7 @@ enum {
64390 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
64391 ADDR_NO_RANDOMIZE | \
64392 ADDR_COMPAT_LAYOUT | \
64393 + ADDR_LIMIT_3GB | \
64394 MMAP_PAGE_ZERO)
64395
64396 /*
64397 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
64398 index ad1a427..6419649 100644
64399 --- a/include/linux/pipe_fs_i.h
64400 +++ b/include/linux/pipe_fs_i.h
64401 @@ -45,9 +45,9 @@ struct pipe_buffer {
64402 struct pipe_inode_info {
64403 wait_queue_head_t wait;
64404 unsigned int nrbufs, curbuf, buffers;
64405 - unsigned int readers;
64406 - unsigned int writers;
64407 - unsigned int waiting_writers;
64408 + atomic_t readers;
64409 + atomic_t writers;
64410 + atomic_t waiting_writers;
64411 unsigned int r_counter;
64412 unsigned int w_counter;
64413 struct page *tmp_page;
64414 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
64415 index f271860..6b3bec5 100644
64416 --- a/include/linux/pm_runtime.h
64417 +++ b/include/linux/pm_runtime.h
64418 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
64419
64420 static inline void pm_runtime_mark_last_busy(struct device *dev)
64421 {
64422 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
64423 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
64424 }
64425
64426 #else /* !CONFIG_PM_RUNTIME */
64427 diff --git a/include/linux/poison.h b/include/linux/poison.h
64428 index 2110a81..13a11bb 100644
64429 --- a/include/linux/poison.h
64430 +++ b/include/linux/poison.h
64431 @@ -19,8 +19,8 @@
64432 * under normal circumstances, used to verify that nobody uses
64433 * non-initialized list entries.
64434 */
64435 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64436 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64437 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64438 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64439
64440 /********** include/linux/timer.h **********/
64441 /*
64442 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
64443 index 5a710b9..0b0dab9 100644
64444 --- a/include/linux/preempt.h
64445 +++ b/include/linux/preempt.h
64446 @@ -126,7 +126,7 @@ struct preempt_ops {
64447 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
64448 void (*sched_out)(struct preempt_notifier *notifier,
64449 struct task_struct *next);
64450 -};
64451 +} __no_const;
64452
64453 /**
64454 * preempt_notifier - key for installing preemption notifiers
64455 diff --git a/include/linux/printk.h b/include/linux/printk.h
64456 index 9afc01e..92c32e8 100644
64457 --- a/include/linux/printk.h
64458 +++ b/include/linux/printk.h
64459 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
64460 extern int printk_needs_cpu(int cpu);
64461 extern void printk_tick(void);
64462
64463 +extern int kptr_restrict;
64464 +
64465 #ifdef CONFIG_PRINTK
64466 asmlinkage __printf(5, 0)
64467 int vprintk_emit(int facility, int level,
64468 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
64469
64470 extern int printk_delay_msec;
64471 extern int dmesg_restrict;
64472 -extern int kptr_restrict;
64473
64474 void log_buf_kexec_setup(void);
64475 void __init setup_log_buf(int early);
64476 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
64477 index 3fd2e87..d93a721 100644
64478 --- a/include/linux/proc_fs.h
64479 +++ b/include/linux/proc_fs.h
64480 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
64481 return proc_create_data(name, mode, parent, proc_fops, NULL);
64482 }
64483
64484 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
64485 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64486 +{
64487 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64488 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64489 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64490 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64491 +#else
64492 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64493 +#endif
64494 +}
64495 +
64496 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64497 umode_t mode, struct proc_dir_entry *base,
64498 read_proc_t *read_proc, void * data)
64499 @@ -258,7 +270,7 @@ union proc_op {
64500 int (*proc_show)(struct seq_file *m,
64501 struct pid_namespace *ns, struct pid *pid,
64502 struct task_struct *task);
64503 -};
64504 +} __no_const;
64505
64506 struct ctl_table_header;
64507 struct ctl_table;
64508 diff --git a/include/linux/random.h b/include/linux/random.h
64509 index ac621ce..c1215f3 100644
64510 --- a/include/linux/random.h
64511 +++ b/include/linux/random.h
64512 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
64513 unsigned int value);
64514 extern void add_interrupt_randomness(int irq, int irq_flags);
64515
64516 +#ifdef CONFIG_PAX_LATENT_ENTROPY
64517 +extern void transfer_latent_entropy(void);
64518 +#endif
64519 +
64520 extern void get_random_bytes(void *buf, int nbytes);
64521 extern void get_random_bytes_arch(void *buf, int nbytes);
64522 void generate_random_uuid(unsigned char uuid_out[16]);
64523 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
64524
64525 u32 prandom32(struct rnd_state *);
64526
64527 +static inline unsigned long pax_get_random_long(void)
64528 +{
64529 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64530 +}
64531 +
64532 /*
64533 * Handle minimum values for seeds
64534 */
64535 static inline u32 __seed(u32 x, u32 m)
64536 {
64537 - return (x < m) ? x + m : x;
64538 + return (x <= m) ? x + m + 1 : x;
64539 }
64540
64541 /**
64542 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64543 index e0879a7..a12f962 100644
64544 --- a/include/linux/reboot.h
64545 +++ b/include/linux/reboot.h
64546 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64547 * Architecture-specific implementations of sys_reboot commands.
64548 */
64549
64550 -extern void machine_restart(char *cmd);
64551 -extern void machine_halt(void);
64552 -extern void machine_power_off(void);
64553 +extern void machine_restart(char *cmd) __noreturn;
64554 +extern void machine_halt(void) __noreturn;
64555 +extern void machine_power_off(void) __noreturn;
64556
64557 extern void machine_shutdown(void);
64558 struct pt_regs;
64559 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64560 */
64561
64562 extern void kernel_restart_prepare(char *cmd);
64563 -extern void kernel_restart(char *cmd);
64564 -extern void kernel_halt(void);
64565 -extern void kernel_power_off(void);
64566 +extern void kernel_restart(char *cmd) __noreturn;
64567 +extern void kernel_halt(void) __noreturn;
64568 +extern void kernel_power_off(void) __noreturn;
64569
64570 extern int C_A_D; /* for sysctl */
64571 void ctrl_alt_del(void);
64572 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64573 * Emergency restart, callable from an interrupt handler.
64574 */
64575
64576 -extern void emergency_restart(void);
64577 +extern void emergency_restart(void) __noreturn;
64578 #include <asm/emergency-restart.h>
64579
64580 #endif
64581 diff --git a/include/linux/relay.h b/include/linux/relay.h
64582 index 91cacc3..b55ff74 100644
64583 --- a/include/linux/relay.h
64584 +++ b/include/linux/relay.h
64585 @@ -160,7 +160,7 @@ struct rchan_callbacks
64586 * The callback should return 0 if successful, negative if not.
64587 */
64588 int (*remove_buf_file)(struct dentry *dentry);
64589 -};
64590 +} __no_const;
64591
64592 /*
64593 * CONFIG_RELAY kernel API, kernel/relay.c
64594 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64595 index 6fdf027..ff72610 100644
64596 --- a/include/linux/rfkill.h
64597 +++ b/include/linux/rfkill.h
64598 @@ -147,6 +147,7 @@ struct rfkill_ops {
64599 void (*query)(struct rfkill *rfkill, void *data);
64600 int (*set_block)(void *data, bool blocked);
64601 };
64602 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64603
64604 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64605 /**
64606 diff --git a/include/linux/rio.h b/include/linux/rio.h
64607 index a90ebad..fd87b5d 100644
64608 --- a/include/linux/rio.h
64609 +++ b/include/linux/rio.h
64610 @@ -321,7 +321,7 @@ struct rio_ops {
64611 int mbox, void *buffer, size_t len);
64612 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64613 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64614 -};
64615 +} __no_const;
64616
64617 #define RIO_RESOURCE_MEM 0x00000100
64618 #define RIO_RESOURCE_DOORBELL 0x00000200
64619 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64620 index 3fce545..b4fed6e 100644
64621 --- a/include/linux/rmap.h
64622 +++ b/include/linux/rmap.h
64623 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64624 void anon_vma_init(void); /* create anon_vma_cachep */
64625 int anon_vma_prepare(struct vm_area_struct *);
64626 void unlink_anon_vmas(struct vm_area_struct *);
64627 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64628 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64629 void anon_vma_moveto_tail(struct vm_area_struct *);
64630 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64631 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64632
64633 static inline void anon_vma_merge(struct vm_area_struct *vma,
64634 struct vm_area_struct *next)
64635 diff --git a/include/linux/sched.h b/include/linux/sched.h
64636 index 23bddac..5976055 100644
64637 --- a/include/linux/sched.h
64638 +++ b/include/linux/sched.h
64639 @@ -101,6 +101,7 @@ struct bio_list;
64640 struct fs_struct;
64641 struct perf_event_context;
64642 struct blk_plug;
64643 +struct linux_binprm;
64644
64645 /*
64646 * List of flags we want to share for kernel threads,
64647 @@ -384,10 +385,13 @@ struct user_namespace;
64648 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64649
64650 extern int sysctl_max_map_count;
64651 +extern unsigned long sysctl_heap_stack_gap;
64652
64653 #include <linux/aio.h>
64654
64655 #ifdef CONFIG_MMU
64656 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64657 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64658 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64659 extern unsigned long
64660 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64661 @@ -651,6 +655,17 @@ struct signal_struct {
64662 #ifdef CONFIG_TASKSTATS
64663 struct taskstats *stats;
64664 #endif
64665 +
64666 +#ifdef CONFIG_GRKERNSEC
64667 + u32 curr_ip;
64668 + u32 saved_ip;
64669 + u32 gr_saddr;
64670 + u32 gr_daddr;
64671 + u16 gr_sport;
64672 + u16 gr_dport;
64673 + u8 used_accept:1;
64674 +#endif
64675 +
64676 #ifdef CONFIG_AUDIT
64677 unsigned audit_tty;
64678 struct tty_audit_buf *tty_audit_buf;
64679 @@ -734,6 +749,11 @@ struct user_struct {
64680 struct key *session_keyring; /* UID's default session keyring */
64681 #endif
64682
64683 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64684 + unsigned int banned;
64685 + unsigned long ban_expires;
64686 +#endif
64687 +
64688 /* Hash table maintenance information */
64689 struct hlist_node uidhash_node;
64690 kuid_t uid;
64691 @@ -1356,8 +1376,8 @@ struct task_struct {
64692 struct list_head thread_group;
64693
64694 struct completion *vfork_done; /* for vfork() */
64695 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64696 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64697 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64698 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64699
64700 cputime_t utime, stime, utimescaled, stimescaled;
64701 cputime_t gtime;
64702 @@ -1373,11 +1393,6 @@ struct task_struct {
64703 struct task_cputime cputime_expires;
64704 struct list_head cpu_timers[3];
64705
64706 -/* process credentials */
64707 - const struct cred __rcu *real_cred; /* objective and real subjective task
64708 - * credentials (COW) */
64709 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64710 - * credentials (COW) */
64711 char comm[TASK_COMM_LEN]; /* executable name excluding path
64712 - access with [gs]et_task_comm (which lock
64713 it with task_lock())
64714 @@ -1394,6 +1409,10 @@ struct task_struct {
64715 #endif
64716 /* CPU-specific state of this task */
64717 struct thread_struct thread;
64718 +/* thread_info moved to task_struct */
64719 +#ifdef CONFIG_X86
64720 + struct thread_info tinfo;
64721 +#endif
64722 /* filesystem information */
64723 struct fs_struct *fs;
64724 /* open file information */
64725 @@ -1467,6 +1486,10 @@ struct task_struct {
64726 gfp_t lockdep_reclaim_gfp;
64727 #endif
64728
64729 +/* process credentials */
64730 + const struct cred __rcu *real_cred; /* objective and real subjective task
64731 + * credentials (COW) */
64732 +
64733 /* journalling filesystem info */
64734 void *journal_info;
64735
64736 @@ -1505,6 +1528,10 @@ struct task_struct {
64737 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64738 struct list_head cg_list;
64739 #endif
64740 +
64741 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64742 + * credentials (COW) */
64743 +
64744 #ifdef CONFIG_FUTEX
64745 struct robust_list_head __user *robust_list;
64746 #ifdef CONFIG_COMPAT
64747 @@ -1589,8 +1616,74 @@ struct task_struct {
64748 #ifdef CONFIG_UPROBES
64749 struct uprobe_task *utask;
64750 #endif
64751 +
64752 +#ifdef CONFIG_GRKERNSEC
64753 + /* grsecurity */
64754 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64755 + u64 exec_id;
64756 +#endif
64757 +#ifdef CONFIG_GRKERNSEC_SETXID
64758 + const struct cred *delayed_cred;
64759 +#endif
64760 + struct dentry *gr_chroot_dentry;
64761 + struct acl_subject_label *acl;
64762 + struct acl_role_label *role;
64763 + struct file *exec_file;
64764 + u16 acl_role_id;
64765 + /* is this the task that authenticated to the special role */
64766 + u8 acl_sp_role;
64767 + u8 is_writable;
64768 + u8 brute;
64769 + u8 gr_is_chrooted;
64770 +#endif
64771 +
64772 };
64773
64774 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64775 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64776 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64777 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64778 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64779 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64780 +
64781 +#ifdef CONFIG_PAX_SOFTMODE
64782 +extern int pax_softmode;
64783 +#endif
64784 +
64785 +extern int pax_check_flags(unsigned long *);
64786 +
64787 +/* if tsk != current then task_lock must be held on it */
64788 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64789 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64790 +{
64791 + if (likely(tsk->mm))
64792 + return tsk->mm->pax_flags;
64793 + else
64794 + return 0UL;
64795 +}
64796 +
64797 +/* if tsk != current then task_lock must be held on it */
64798 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64799 +{
64800 + if (likely(tsk->mm)) {
64801 + tsk->mm->pax_flags = flags;
64802 + return 0;
64803 + }
64804 + return -EINVAL;
64805 +}
64806 +#endif
64807 +
64808 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64809 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64810 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64811 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64812 +#endif
64813 +
64814 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64815 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64816 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64817 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64818 +
64819 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64820 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64821
64822 @@ -2125,7 +2218,9 @@ void yield(void);
64823 extern struct exec_domain default_exec_domain;
64824
64825 union thread_union {
64826 +#ifndef CONFIG_X86
64827 struct thread_info thread_info;
64828 +#endif
64829 unsigned long stack[THREAD_SIZE/sizeof(long)];
64830 };
64831
64832 @@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64833 */
64834
64835 extern struct task_struct *find_task_by_vpid(pid_t nr);
64836 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64837 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64838 struct pid_namespace *ns);
64839
64840 @@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64841 extern void exit_itimers(struct signal_struct *);
64842 extern void flush_itimer_signals(void);
64843
64844 -extern void do_group_exit(int);
64845 +extern __noreturn void do_group_exit(int);
64846
64847 extern void daemonize(const char *, ...);
64848 extern int allow_signal(int);
64849 @@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64850
64851 #endif
64852
64853 -static inline int object_is_on_stack(void *obj)
64854 +static inline int object_starts_on_stack(void *obj)
64855 {
64856 - void *stack = task_stack_page(current);
64857 + const void *stack = task_stack_page(current);
64858
64859 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64860 }
64861 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64862 index 899fbb4..1cb4138 100644
64863 --- a/include/linux/screen_info.h
64864 +++ b/include/linux/screen_info.h
64865 @@ -43,7 +43,8 @@ struct screen_info {
64866 __u16 pages; /* 0x32 */
64867 __u16 vesa_attributes; /* 0x34 */
64868 __u32 capabilities; /* 0x36 */
64869 - __u8 _reserved[6]; /* 0x3a */
64870 + __u16 vesapm_size; /* 0x3a */
64871 + __u8 _reserved[4]; /* 0x3c */
64872 } __attribute__((packed));
64873
64874 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64875 diff --git a/include/linux/security.h b/include/linux/security.h
64876 index d143b8e..9f27b95 100644
64877 --- a/include/linux/security.h
64878 +++ b/include/linux/security.h
64879 @@ -26,6 +26,7 @@
64880 #include <linux/capability.h>
64881 #include <linux/slab.h>
64882 #include <linux/err.h>
64883 +#include <linux/grsecurity.h>
64884
64885 struct linux_binprm;
64886 struct cred;
64887 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64888 index 83c44ee..e8a9eba 100644
64889 --- a/include/linux/seq_file.h
64890 +++ b/include/linux/seq_file.h
64891 @@ -25,6 +25,9 @@ struct seq_file {
64892 struct mutex lock;
64893 const struct seq_operations *op;
64894 int poll_event;
64895 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64896 + u64 exec_id;
64897 +#endif
64898 void *private;
64899 };
64900
64901 @@ -34,6 +37,7 @@ struct seq_operations {
64902 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64903 int (*show) (struct seq_file *m, void *v);
64904 };
64905 +typedef struct seq_operations __no_const seq_operations_no_const;
64906
64907 #define SEQ_SKIP 1
64908
64909 diff --git a/include/linux/shm.h b/include/linux/shm.h
64910 index edd0868..f98feee 100644
64911 --- a/include/linux/shm.h
64912 +++ b/include/linux/shm.h
64913 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64914
64915 /* The task created the shm object. NULL if the task is dead. */
64916 struct task_struct *shm_creator;
64917 +#ifdef CONFIG_GRKERNSEC
64918 + time_t shm_createtime;
64919 + pid_t shm_lapid;
64920 +#endif
64921 };
64922
64923 /* shm_mode upper byte flags */
64924 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64925 index f3165d2..2cb3cb7 100644
64926 --- a/include/linux/skbuff.h
64927 +++ b/include/linux/skbuff.h
64928 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64929 extern struct sk_buff *__alloc_skb(unsigned int size,
64930 gfp_t priority, int flags, int node);
64931 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64932 -static inline struct sk_buff *alloc_skb(unsigned int size,
64933 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64934 gfp_t priority)
64935 {
64936 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64937 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64938 */
64939 static inline int skb_queue_empty(const struct sk_buff_head *list)
64940 {
64941 - return list->next == (struct sk_buff *)list;
64942 + return list->next == (const struct sk_buff *)list;
64943 }
64944
64945 /**
64946 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64947 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64948 const struct sk_buff *skb)
64949 {
64950 - return skb->next == (struct sk_buff *)list;
64951 + return skb->next == (const struct sk_buff *)list;
64952 }
64953
64954 /**
64955 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64956 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64957 const struct sk_buff *skb)
64958 {
64959 - return skb->prev == (struct sk_buff *)list;
64960 + return skb->prev == (const struct sk_buff *)list;
64961 }
64962
64963 /**
64964 @@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64965 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64966 */
64967 #ifndef NET_SKB_PAD
64968 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64969 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64970 #endif
64971
64972 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64973 @@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64974 int noblock, int *err);
64975 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64976 struct poll_table_struct *wait);
64977 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64978 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64979 int offset, struct iovec *to,
64980 int size);
64981 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64982 diff --git a/include/linux/slab.h b/include/linux/slab.h
64983 index 0dd2dfa..2b8677c 100644
64984 --- a/include/linux/slab.h
64985 +++ b/include/linux/slab.h
64986 @@ -11,12 +11,20 @@
64987
64988 #include <linux/gfp.h>
64989 #include <linux/types.h>
64990 +#include <linux/err.h>
64991
64992 /*
64993 * Flags to pass to kmem_cache_create().
64994 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64995 */
64996 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64997 +
64998 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64999 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
65000 +#else
65001 +#define SLAB_USERCOPY 0x00000000UL
65002 +#endif
65003 +
65004 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
65005 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
65006 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
65007 @@ -87,10 +95,13 @@
65008 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
65009 * Both make kfree a no-op.
65010 */
65011 -#define ZERO_SIZE_PTR ((void *)16)
65012 +#define ZERO_SIZE_PTR \
65013 +({ \
65014 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
65015 + (void *)(-MAX_ERRNO-1L); \
65016 +})
65017
65018 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
65019 - (unsigned long)ZERO_SIZE_PTR)
65020 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
65021
65022 /*
65023 * Common fields provided in kmem_cache by all slab allocators
65024 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
65025 void kfree(const void *);
65026 void kzfree(const void *);
65027 size_t ksize(const void *);
65028 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
65029 +bool is_usercopy_object(const void *ptr);
65030
65031 /*
65032 * Allocator specific definitions. These are mainly used to establish optimized
65033 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
65034 */
65035 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
65036 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
65037 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
65038 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
65039 #define kmalloc_track_caller(size, flags) \
65040 __kmalloc_track_caller(size, flags, _RET_IP_)
65041 #else
65042 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
65043 */
65044 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
65045 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
65046 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
65047 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
65048 #define kmalloc_node_track_caller(size, flags, node) \
65049 __kmalloc_node_track_caller(size, flags, node, \
65050 _RET_IP_)
65051 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
65052 index 0c634fa..8616300 100644
65053 --- a/include/linux/slab_def.h
65054 +++ b/include/linux/slab_def.h
65055 @@ -69,10 +69,10 @@ struct kmem_cache {
65056 unsigned long node_allocs;
65057 unsigned long node_frees;
65058 unsigned long node_overflow;
65059 - atomic_t allochit;
65060 - atomic_t allocmiss;
65061 - atomic_t freehit;
65062 - atomic_t freemiss;
65063 + atomic_unchecked_t allochit;
65064 + atomic_unchecked_t allocmiss;
65065 + atomic_unchecked_t freehit;
65066 + atomic_unchecked_t freemiss;
65067
65068 /*
65069 * If debugging is enabled, then the allocator can add additional
65070 @@ -105,11 +105,16 @@ struct cache_sizes {
65071 #ifdef CONFIG_ZONE_DMA
65072 struct kmem_cache *cs_dmacachep;
65073 #endif
65074 +
65075 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65076 + struct kmem_cache *cs_usercopycachep;
65077 +#endif
65078 +
65079 };
65080 extern struct cache_sizes malloc_sizes[];
65081
65082 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
65083 -void *__kmalloc(size_t size, gfp_t flags);
65084 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
65085
65086 #ifdef CONFIG_TRACING
65087 extern void *kmem_cache_alloc_trace(size_t size,
65088 @@ -152,6 +157,13 @@ found:
65089 cachep = malloc_sizes[i].cs_dmacachep;
65090 else
65091 #endif
65092 +
65093 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65094 + if (flags & GFP_USERCOPY)
65095 + cachep = malloc_sizes[i].cs_usercopycachep;
65096 + else
65097 +#endif
65098 +
65099 cachep = malloc_sizes[i].cs_cachep;
65100
65101 ret = kmem_cache_alloc_trace(size, cachep, flags);
65102 @@ -162,7 +174,7 @@ found:
65103 }
65104
65105 #ifdef CONFIG_NUMA
65106 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
65107 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65108 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
65109
65110 #ifdef CONFIG_TRACING
65111 @@ -205,6 +217,13 @@ found:
65112 cachep = malloc_sizes[i].cs_dmacachep;
65113 else
65114 #endif
65115 +
65116 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65117 + if (flags & GFP_USERCOPY)
65118 + cachep = malloc_sizes[i].cs_usercopycachep;
65119 + else
65120 +#endif
65121 +
65122 cachep = malloc_sizes[i].cs_cachep;
65123
65124 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
65125 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
65126 index 0ec00b3..22b4715 100644
65127 --- a/include/linux/slob_def.h
65128 +++ b/include/linux/slob_def.h
65129 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
65130 return kmem_cache_alloc_node(cachep, flags, -1);
65131 }
65132
65133 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
65134 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65135
65136 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
65137 {
65138 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
65139 return __kmalloc_node(size, flags, -1);
65140 }
65141
65142 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
65143 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
65144 {
65145 return kmalloc(size, flags);
65146 }
65147 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
65148 index df448ad..b99e7f6 100644
65149 --- a/include/linux/slub_def.h
65150 +++ b/include/linux/slub_def.h
65151 @@ -91,7 +91,7 @@ struct kmem_cache {
65152 struct kmem_cache_order_objects max;
65153 struct kmem_cache_order_objects min;
65154 gfp_t allocflags; /* gfp flags to use on each alloc */
65155 - int refcount; /* Refcount for slab cache destroy */
65156 + atomic_t refcount; /* Refcount for slab cache destroy */
65157 void (*ctor)(void *);
65158 int inuse; /* Offset to metadata */
65159 int align; /* Alignment */
65160 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
65161 * Sorry that the following has to be that ugly but some versions of GCC
65162 * have trouble with constant propagation and loops.
65163 */
65164 -static __always_inline int kmalloc_index(size_t size)
65165 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
65166 {
65167 if (!size)
65168 return 0;
65169 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
65170 }
65171
65172 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
65173 -void *__kmalloc(size_t size, gfp_t flags);
65174 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
65175
65176 static __always_inline void *
65177 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
65178 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
65179 }
65180 #endif
65181
65182 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
65183 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
65184 {
65185 unsigned int order = get_order(size);
65186 return kmalloc_order_trace(size, flags, order);
65187 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
65188 }
65189
65190 #ifdef CONFIG_NUMA
65191 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
65192 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65193 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
65194
65195 #ifdef CONFIG_TRACING
65196 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
65197 index de8832d..0147b46 100644
65198 --- a/include/linux/sonet.h
65199 +++ b/include/linux/sonet.h
65200 @@ -61,7 +61,7 @@ struct sonet_stats {
65201 #include <linux/atomic.h>
65202
65203 struct k_sonet_stats {
65204 -#define __HANDLE_ITEM(i) atomic_t i
65205 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
65206 __SONET_ITEMS
65207 #undef __HANDLE_ITEM
65208 };
65209 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
65210 index 523547e..2cb7140 100644
65211 --- a/include/linux/sunrpc/clnt.h
65212 +++ b/include/linux/sunrpc/clnt.h
65213 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
65214 {
65215 switch (sap->sa_family) {
65216 case AF_INET:
65217 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
65218 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
65219 case AF_INET6:
65220 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
65221 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
65222 }
65223 return 0;
65224 }
65225 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
65226 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
65227 const struct sockaddr *src)
65228 {
65229 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
65230 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
65231 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
65232
65233 dsin->sin_family = ssin->sin_family;
65234 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
65235 if (sa->sa_family != AF_INET6)
65236 return 0;
65237
65238 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
65239 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
65240 }
65241
65242 #endif /* __KERNEL__ */
65243 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
65244 index dc0c3cc..8503fb6 100644
65245 --- a/include/linux/sunrpc/sched.h
65246 +++ b/include/linux/sunrpc/sched.h
65247 @@ -106,6 +106,7 @@ struct rpc_call_ops {
65248 void (*rpc_count_stats)(struct rpc_task *, void *);
65249 void (*rpc_release)(void *);
65250 };
65251 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
65252
65253 struct rpc_task_setup {
65254 struct rpc_task *task;
65255 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
65256 index 0b8e3e6..33e0a01 100644
65257 --- a/include/linux/sunrpc/svc_rdma.h
65258 +++ b/include/linux/sunrpc/svc_rdma.h
65259 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
65260 extern unsigned int svcrdma_max_requests;
65261 extern unsigned int svcrdma_max_req_size;
65262
65263 -extern atomic_t rdma_stat_recv;
65264 -extern atomic_t rdma_stat_read;
65265 -extern atomic_t rdma_stat_write;
65266 -extern atomic_t rdma_stat_sq_starve;
65267 -extern atomic_t rdma_stat_rq_starve;
65268 -extern atomic_t rdma_stat_rq_poll;
65269 -extern atomic_t rdma_stat_rq_prod;
65270 -extern atomic_t rdma_stat_sq_poll;
65271 -extern atomic_t rdma_stat_sq_prod;
65272 +extern atomic_unchecked_t rdma_stat_recv;
65273 +extern atomic_unchecked_t rdma_stat_read;
65274 +extern atomic_unchecked_t rdma_stat_write;
65275 +extern atomic_unchecked_t rdma_stat_sq_starve;
65276 +extern atomic_unchecked_t rdma_stat_rq_starve;
65277 +extern atomic_unchecked_t rdma_stat_rq_poll;
65278 +extern atomic_unchecked_t rdma_stat_rq_prod;
65279 +extern atomic_unchecked_t rdma_stat_sq_poll;
65280 +extern atomic_unchecked_t rdma_stat_sq_prod;
65281
65282 #define RPCRDMA_VERSION 1
65283
65284 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
65285 index c34b4c8..a65b67d 100644
65286 --- a/include/linux/sysctl.h
65287 +++ b/include/linux/sysctl.h
65288 @@ -155,7 +155,11 @@ enum
65289 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
65290 };
65291
65292 -
65293 +#ifdef CONFIG_PAX_SOFTMODE
65294 +enum {
65295 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
65296 +};
65297 +#endif
65298
65299 /* CTL_VM names: */
65300 enum
65301 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
65302
65303 extern int proc_dostring(struct ctl_table *, int,
65304 void __user *, size_t *, loff_t *);
65305 +extern int proc_dostring_modpriv(struct ctl_table *, int,
65306 + void __user *, size_t *, loff_t *);
65307 extern int proc_dointvec(struct ctl_table *, int,
65308 void __user *, size_t *, loff_t *);
65309 extern int proc_dointvec_minmax(struct ctl_table *, int,
65310 diff --git a/include/linux/tty.h b/include/linux/tty.h
65311 index 9f47ab5..73da944 100644
65312 --- a/include/linux/tty.h
65313 +++ b/include/linux/tty.h
65314 @@ -225,7 +225,7 @@ struct tty_port {
65315 const struct tty_port_operations *ops; /* Port operations */
65316 spinlock_t lock; /* Lock protecting tty field */
65317 int blocked_open; /* Waiting to open */
65318 - int count; /* Usage count */
65319 + atomic_t count; /* Usage count */
65320 wait_queue_head_t open_wait; /* Open waiters */
65321 wait_queue_head_t close_wait; /* Close waiters */
65322 wait_queue_head_t delta_msr_wait; /* Modem status change */
65323 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
65324 struct tty_struct *tty, struct file *filp);
65325 static inline int tty_port_users(struct tty_port *port)
65326 {
65327 - return port->count + port->blocked_open;
65328 + return atomic_read(&port->count) + port->blocked_open;
65329 }
65330
65331 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
65332 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
65333 index fb79dd8d..07d4773 100644
65334 --- a/include/linux/tty_ldisc.h
65335 +++ b/include/linux/tty_ldisc.h
65336 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
65337
65338 struct module *owner;
65339
65340 - int refcount;
65341 + atomic_t refcount;
65342 };
65343
65344 struct tty_ldisc {
65345 diff --git a/include/linux/types.h b/include/linux/types.h
65346 index bf0dd75..a1f23aaa 100644
65347 --- a/include/linux/types.h
65348 +++ b/include/linux/types.h
65349 @@ -220,10 +220,26 @@ typedef struct {
65350 int counter;
65351 } atomic_t;
65352
65353 +#ifdef CONFIG_PAX_REFCOUNT
65354 +typedef struct {
65355 + int counter;
65356 +} atomic_unchecked_t;
65357 +#else
65358 +typedef atomic_t atomic_unchecked_t;
65359 +#endif
65360 +
65361 #ifdef CONFIG_64BIT
65362 typedef struct {
65363 long counter;
65364 } atomic64_t;
65365 +
65366 +#ifdef CONFIG_PAX_REFCOUNT
65367 +typedef struct {
65368 + long counter;
65369 +} atomic64_unchecked_t;
65370 +#else
65371 +typedef atomic64_t atomic64_unchecked_t;
65372 +#endif
65373 #endif
65374
65375 struct list_head {
65376 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
65377 index 5ca0951..ab496a5 100644
65378 --- a/include/linux/uaccess.h
65379 +++ b/include/linux/uaccess.h
65380 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
65381 long ret; \
65382 mm_segment_t old_fs = get_fs(); \
65383 \
65384 - set_fs(KERNEL_DS); \
65385 pagefault_disable(); \
65386 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65387 - pagefault_enable(); \
65388 + set_fs(KERNEL_DS); \
65389 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
65390 set_fs(old_fs); \
65391 + pagefault_enable(); \
65392 ret; \
65393 })
65394
65395 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
65396 index 99c1b4d..bb94261 100644
65397 --- a/include/linux/unaligned/access_ok.h
65398 +++ b/include/linux/unaligned/access_ok.h
65399 @@ -6,32 +6,32 @@
65400
65401 static inline u16 get_unaligned_le16(const void *p)
65402 {
65403 - return le16_to_cpup((__le16 *)p);
65404 + return le16_to_cpup((const __le16 *)p);
65405 }
65406
65407 static inline u32 get_unaligned_le32(const void *p)
65408 {
65409 - return le32_to_cpup((__le32 *)p);
65410 + return le32_to_cpup((const __le32 *)p);
65411 }
65412
65413 static inline u64 get_unaligned_le64(const void *p)
65414 {
65415 - return le64_to_cpup((__le64 *)p);
65416 + return le64_to_cpup((const __le64 *)p);
65417 }
65418
65419 static inline u16 get_unaligned_be16(const void *p)
65420 {
65421 - return be16_to_cpup((__be16 *)p);
65422 + return be16_to_cpup((const __be16 *)p);
65423 }
65424
65425 static inline u32 get_unaligned_be32(const void *p)
65426 {
65427 - return be32_to_cpup((__be32 *)p);
65428 + return be32_to_cpup((const __be32 *)p);
65429 }
65430
65431 static inline u64 get_unaligned_be64(const void *p)
65432 {
65433 - return be64_to_cpup((__be64 *)p);
65434 + return be64_to_cpup((const __be64 *)p);
65435 }
65436
65437 static inline void put_unaligned_le16(u16 val, void *p)
65438 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
65439 index c5d36c6..8478c90 100644
65440 --- a/include/linux/usb/renesas_usbhs.h
65441 +++ b/include/linux/usb/renesas_usbhs.h
65442 @@ -39,7 +39,7 @@ enum {
65443 */
65444 struct renesas_usbhs_driver_callback {
65445 int (*notify_hotplug)(struct platform_device *pdev);
65446 -};
65447 +} __no_const;
65448
65449 /*
65450 * callback functions for platform
65451 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
65452 * VBUS control is needed for Host
65453 */
65454 int (*set_vbus)(struct platform_device *pdev, int enable);
65455 -};
65456 +} __no_const;
65457
65458 /*
65459 * parameters for renesas usbhs
65460 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
65461 index 6f8fbcf..8259001 100644
65462 --- a/include/linux/vermagic.h
65463 +++ b/include/linux/vermagic.h
65464 @@ -25,9 +25,35 @@
65465 #define MODULE_ARCH_VERMAGIC ""
65466 #endif
65467
65468 +#ifdef CONFIG_PAX_REFCOUNT
65469 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
65470 +#else
65471 +#define MODULE_PAX_REFCOUNT ""
65472 +#endif
65473 +
65474 +#ifdef CONSTIFY_PLUGIN
65475 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
65476 +#else
65477 +#define MODULE_CONSTIFY_PLUGIN ""
65478 +#endif
65479 +
65480 +#ifdef STACKLEAK_PLUGIN
65481 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
65482 +#else
65483 +#define MODULE_STACKLEAK_PLUGIN ""
65484 +#endif
65485 +
65486 +#ifdef CONFIG_GRKERNSEC
65487 +#define MODULE_GRSEC "GRSEC "
65488 +#else
65489 +#define MODULE_GRSEC ""
65490 +#endif
65491 +
65492 #define VERMAGIC_STRING \
65493 UTS_RELEASE " " \
65494 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65495 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65496 - MODULE_ARCH_VERMAGIC
65497 + MODULE_ARCH_VERMAGIC \
65498 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
65499 + MODULE_GRSEC
65500
65501 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65502 index 6071e91..ca6a489 100644
65503 --- a/include/linux/vmalloc.h
65504 +++ b/include/linux/vmalloc.h
65505 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65506 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65507 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65508 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65509 +
65510 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65511 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65512 +#endif
65513 +
65514 /* bits [20..32] reserved for arch specific ioremap internals */
65515
65516 /*
65517 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
65518 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65519 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65520 unsigned long start, unsigned long end, gfp_t gfp_mask,
65521 - pgprot_t prot, int node, const void *caller);
65522 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
65523 extern void vfree(const void *addr);
65524
65525 extern void *vmap(struct page **pages, unsigned int count,
65526 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65527 extern void free_vm_area(struct vm_struct *area);
65528
65529 /* for /dev/kmem */
65530 -extern long vread(char *buf, char *addr, unsigned long count);
65531 -extern long vwrite(char *buf, char *addr, unsigned long count);
65532 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65533 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65534
65535 /*
65536 * Internals. Dont't use..
65537 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65538 index ad2cfd5..74c94ad 100644
65539 --- a/include/linux/vmstat.h
65540 +++ b/include/linux/vmstat.h
65541 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65542 /*
65543 * Zone based page accounting with per cpu differentials.
65544 */
65545 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65546 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65547
65548 static inline void zone_page_state_add(long x, struct zone *zone,
65549 enum zone_stat_item item)
65550 {
65551 - atomic_long_add(x, &zone->vm_stat[item]);
65552 - atomic_long_add(x, &vm_stat[item]);
65553 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65554 + atomic_long_add_unchecked(x, &vm_stat[item]);
65555 }
65556
65557 static inline unsigned long global_page_state(enum zone_stat_item item)
65558 {
65559 - long x = atomic_long_read(&vm_stat[item]);
65560 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65561 #ifdef CONFIG_SMP
65562 if (x < 0)
65563 x = 0;
65564 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65565 static inline unsigned long zone_page_state(struct zone *zone,
65566 enum zone_stat_item item)
65567 {
65568 - long x = atomic_long_read(&zone->vm_stat[item]);
65569 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65570 #ifdef CONFIG_SMP
65571 if (x < 0)
65572 x = 0;
65573 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65574 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65575 enum zone_stat_item item)
65576 {
65577 - long x = atomic_long_read(&zone->vm_stat[item]);
65578 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65579
65580 #ifdef CONFIG_SMP
65581 int cpu;
65582 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65583
65584 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65585 {
65586 - atomic_long_inc(&zone->vm_stat[item]);
65587 - atomic_long_inc(&vm_stat[item]);
65588 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65589 + atomic_long_inc_unchecked(&vm_stat[item]);
65590 }
65591
65592 static inline void __inc_zone_page_state(struct page *page,
65593 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
65594
65595 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65596 {
65597 - atomic_long_dec(&zone->vm_stat[item]);
65598 - atomic_long_dec(&vm_stat[item]);
65599 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65600 + atomic_long_dec_unchecked(&vm_stat[item]);
65601 }
65602
65603 static inline void __dec_zone_page_state(struct page *page,
65604 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65605 index e5d1220..ef6e406 100644
65606 --- a/include/linux/xattr.h
65607 +++ b/include/linux/xattr.h
65608 @@ -57,6 +57,11 @@
65609 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65610 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65611
65612 +/* User namespace */
65613 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65614 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
65615 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65616 +
65617 #ifdef __KERNEL__
65618
65619 #include <linux/types.h>
65620 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65621 index 944ecdf..a3994fc 100644
65622 --- a/include/media/saa7146_vv.h
65623 +++ b/include/media/saa7146_vv.h
65624 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
65625 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65626
65627 /* the extension can override this */
65628 - struct v4l2_ioctl_ops vid_ops;
65629 - struct v4l2_ioctl_ops vbi_ops;
65630 + v4l2_ioctl_ops_no_const vid_ops;
65631 + v4l2_ioctl_ops_no_const vbi_ops;
65632 /* pointer to the saa7146 core ops */
65633 const struct v4l2_ioctl_ops *core_ops;
65634
65635 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65636 index 5c416cd..20021aa 100644
65637 --- a/include/media/v4l2-dev.h
65638 +++ b/include/media/v4l2-dev.h
65639 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
65640 int (*mmap) (struct file *, struct vm_area_struct *);
65641 int (*open) (struct file *);
65642 int (*release) (struct file *);
65643 -};
65644 +} __do_const;
65645 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65646
65647 /*
65648 * Newer version of video_device, handled by videodev2.c
65649 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65650 index e614c9c..20602b7 100644
65651 --- a/include/media/v4l2-ioctl.h
65652 +++ b/include/media/v4l2-ioctl.h
65653 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
65654 long (*vidioc_default) (struct file *file, void *fh,
65655 bool valid_prio, int cmd, void *arg);
65656 };
65657 -
65658 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65659
65660 /* v4l debugging and diagnostics */
65661
65662 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65663 index bcb9cc3..f4ec722e 100644
65664 --- a/include/net/caif/caif_hsi.h
65665 +++ b/include/net/caif/caif_hsi.h
65666 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65667 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65668 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65669 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65670 -};
65671 +} __no_const;
65672
65673 /* Structure implemented by HSI device. */
65674 struct cfhsi_ops {
65675 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65676 index 9e5425b..8136ffc 100644
65677 --- a/include/net/caif/cfctrl.h
65678 +++ b/include/net/caif/cfctrl.h
65679 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65680 void (*radioset_rsp)(void);
65681 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65682 struct cflayer *client_layer);
65683 -};
65684 +} __no_const;
65685
65686 /* Link Setup Parameters for CAIF-Links. */
65687 struct cfctrl_link_param {
65688 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65689 struct cfctrl {
65690 struct cfsrvl serv;
65691 struct cfctrl_rsp res;
65692 - atomic_t req_seq_no;
65693 - atomic_t rsp_seq_no;
65694 + atomic_unchecked_t req_seq_no;
65695 + atomic_unchecked_t rsp_seq_no;
65696 struct list_head list;
65697 /* Protects from simultaneous access to first_req list */
65698 spinlock_t info_list_lock;
65699 diff --git a/include/net/flow.h b/include/net/flow.h
65700 index 628e11b..4c475df 100644
65701 --- a/include/net/flow.h
65702 +++ b/include/net/flow.h
65703 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65704
65705 extern void flow_cache_flush(void);
65706 extern void flow_cache_flush_deferred(void);
65707 -extern atomic_t flow_cache_genid;
65708 +extern atomic_unchecked_t flow_cache_genid;
65709
65710 #endif
65711 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65712 index 53f464d..ba76aaa 100644
65713 --- a/include/net/inetpeer.h
65714 +++ b/include/net/inetpeer.h
65715 @@ -47,8 +47,8 @@ struct inet_peer {
65716 */
65717 union {
65718 struct {
65719 - atomic_t rid; /* Frag reception counter */
65720 - atomic_t ip_id_count; /* IP ID for the next packet */
65721 + atomic_unchecked_t rid; /* Frag reception counter */
65722 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65723 };
65724 struct rcu_head rcu;
65725 struct inet_peer *gc_next;
65726 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65727 more++;
65728 inet_peer_refcheck(p);
65729 do {
65730 - old = atomic_read(&p->ip_id_count);
65731 + old = atomic_read_unchecked(&p->ip_id_count);
65732 new = old + more;
65733 if (!new)
65734 new = 1;
65735 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65736 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65737 return new;
65738 }
65739
65740 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65741 index 9497be1..5a4fafe 100644
65742 --- a/include/net/ip_fib.h
65743 +++ b/include/net/ip_fib.h
65744 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65745
65746 #define FIB_RES_SADDR(net, res) \
65747 ((FIB_RES_NH(res).nh_saddr_genid == \
65748 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65749 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65750 FIB_RES_NH(res).nh_saddr : \
65751 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65752 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65753 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65754 index 95374d1..2300e36 100644
65755 --- a/include/net/ip_vs.h
65756 +++ b/include/net/ip_vs.h
65757 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65758 struct ip_vs_conn *control; /* Master control connection */
65759 atomic_t n_control; /* Number of controlled ones */
65760 struct ip_vs_dest *dest; /* real server */
65761 - atomic_t in_pkts; /* incoming packet counter */
65762 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65763
65764 /* packet transmitter for different forwarding methods. If it
65765 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65766 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65767 __be16 port; /* port number of the server */
65768 union nf_inet_addr addr; /* IP address of the server */
65769 volatile unsigned int flags; /* dest status flags */
65770 - atomic_t conn_flags; /* flags to copy to conn */
65771 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65772 atomic_t weight; /* server weight */
65773
65774 atomic_t refcnt; /* reference counter */
65775 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65776 index 69b610a..fe3962c 100644
65777 --- a/include/net/irda/ircomm_core.h
65778 +++ b/include/net/irda/ircomm_core.h
65779 @@ -51,7 +51,7 @@ typedef struct {
65780 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65781 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65782 struct ircomm_info *);
65783 -} call_t;
65784 +} __no_const call_t;
65785
65786 struct ircomm_cb {
65787 irda_queue_t queue;
65788 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65789 index 59ba38bc..d515662 100644
65790 --- a/include/net/irda/ircomm_tty.h
65791 +++ b/include/net/irda/ircomm_tty.h
65792 @@ -35,6 +35,7 @@
65793 #include <linux/termios.h>
65794 #include <linux/timer.h>
65795 #include <linux/tty.h> /* struct tty_struct */
65796 +#include <asm/local.h>
65797
65798 #include <net/irda/irias_object.h>
65799 #include <net/irda/ircomm_core.h>
65800 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65801 unsigned short close_delay;
65802 unsigned short closing_wait; /* time to wait before closing */
65803
65804 - int open_count;
65805 - int blocked_open; /* # of blocked opens */
65806 + local_t open_count;
65807 + local_t blocked_open; /* # of blocked opens */
65808
65809 /* Protect concurent access to :
65810 * o self->open_count
65811 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65812 index cc7c197..9f2da2a 100644
65813 --- a/include/net/iucv/af_iucv.h
65814 +++ b/include/net/iucv/af_iucv.h
65815 @@ -141,7 +141,7 @@ struct iucv_sock {
65816 struct iucv_sock_list {
65817 struct hlist_head head;
65818 rwlock_t lock;
65819 - atomic_t autobind_name;
65820 + atomic_unchecked_t autobind_name;
65821 };
65822
65823 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65824 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65825 index 344d898..2ae1302 100644
65826 --- a/include/net/neighbour.h
65827 +++ b/include/net/neighbour.h
65828 @@ -123,7 +123,7 @@ struct neigh_ops {
65829 void (*error_report)(struct neighbour *, struct sk_buff *);
65830 int (*output)(struct neighbour *, struct sk_buff *);
65831 int (*connected_output)(struct neighbour *, struct sk_buff *);
65832 -};
65833 +} __do_const;
65834
65835 struct pneigh_entry {
65836 struct pneigh_entry *next;
65837 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65838 index fd87963..312a11f 100644
65839 --- a/include/net/net_namespace.h
65840 +++ b/include/net/net_namespace.h
65841 @@ -102,7 +102,7 @@ struct net {
65842 #endif
65843 struct netns_ipvs *ipvs;
65844 struct sock *diag_nlsk;
65845 - atomic_t rt_genid;
65846 + atomic_unchecked_t rt_genid;
65847 };
65848
65849
65850 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65851
65852 static inline int rt_genid(struct net *net)
65853 {
65854 - return atomic_read(&net->rt_genid);
65855 + return atomic_read_unchecked(&net->rt_genid);
65856 }
65857
65858 static inline void rt_genid_bump(struct net *net)
65859 {
65860 - atomic_inc(&net->rt_genid);
65861 + atomic_inc_unchecked(&net->rt_genid);
65862 }
65863
65864 #endif /* __NET_NET_NAMESPACE_H */
65865 diff --git a/include/net/netdma.h b/include/net/netdma.h
65866 index 8ba8ce2..99b7fff 100644
65867 --- a/include/net/netdma.h
65868 +++ b/include/net/netdma.h
65869 @@ -24,7 +24,7 @@
65870 #include <linux/dmaengine.h>
65871 #include <linux/skbuff.h>
65872
65873 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65874 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65875 struct sk_buff *skb, int offset, struct iovec *to,
65876 size_t len, struct dma_pinned_list *pinned_list);
65877
65878 diff --git a/include/net/netlink.h b/include/net/netlink.h
65879 index 785f37a..c81dc0c 100644
65880 --- a/include/net/netlink.h
65881 +++ b/include/net/netlink.h
65882 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65883 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65884 {
65885 if (mark)
65886 - skb_trim(skb, (unsigned char *) mark - skb->data);
65887 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65888 }
65889
65890 /**
65891 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65892 index eb24dbc..567d6ed 100644
65893 --- a/include/net/netns/ipv4.h
65894 +++ b/include/net/netns/ipv4.h
65895 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65896 unsigned int sysctl_ping_group_range[2];
65897 long sysctl_tcp_mem[3];
65898
65899 - atomic_t dev_addr_genid;
65900 + atomic_unchecked_t dev_addr_genid;
65901
65902 #ifdef CONFIG_IP_MROUTE
65903 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65904 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65905 index ff49964..1411fee 100644
65906 --- a/include/net/sctp/sctp.h
65907 +++ b/include/net/sctp/sctp.h
65908 @@ -320,9 +320,9 @@ do { \
65909
65910 #else /* SCTP_DEBUG */
65911
65912 -#define SCTP_DEBUG_PRINTK(whatever...)
65913 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65914 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65915 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65916 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65917 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65918 #define SCTP_ENABLE_DEBUG
65919 #define SCTP_DISABLE_DEBUG
65920 #define SCTP_ASSERT(expr, str, func)
65921 diff --git a/include/net/sock.h b/include/net/sock.h
65922 index adb7da2..1100002 100644
65923 --- a/include/net/sock.h
65924 +++ b/include/net/sock.h
65925 @@ -305,7 +305,7 @@ struct sock {
65926 #ifdef CONFIG_RPS
65927 __u32 sk_rxhash;
65928 #endif
65929 - atomic_t sk_drops;
65930 + atomic_unchecked_t sk_drops;
65931 int sk_rcvbuf;
65932
65933 struct sk_filter __rcu *sk_filter;
65934 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65935 }
65936
65937 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65938 - char __user *from, char *to,
65939 + char __user *from, unsigned char *to,
65940 int copy, int offset)
65941 {
65942 if (skb->ip_summed == CHECKSUM_NONE) {
65943 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65944 }
65945 }
65946
65947 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65948 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65949
65950 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65951 {
65952 diff --git a/include/net/tcp.h b/include/net/tcp.h
65953 index 1f000ff..e5a8dfb 100644
65954 --- a/include/net/tcp.h
65955 +++ b/include/net/tcp.h
65956 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65957 extern void tcp_xmit_retransmit_queue(struct sock *);
65958 extern void tcp_simple_retransmit(struct sock *);
65959 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65960 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65961 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65962
65963 extern void tcp_send_probe0(struct sock *);
65964 extern void tcp_send_partial(struct sock *);
65965 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
65966 struct inet6_skb_parm h6;
65967 #endif
65968 } header; /* For incoming frames */
65969 - __u32 seq; /* Starting sequence number */
65970 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65971 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65972 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65973 __u32 when; /* used to compute rtt's */
65974 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65975
65976 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
65977
65978 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65979 /* 1 byte hole */
65980 - __u32 ack_seq; /* Sequence number ACK'd */
65981 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65982 };
65983
65984 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65985 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65986 char *name;
65987 sa_family_t family;
65988 const struct file_operations *seq_fops;
65989 - struct seq_operations seq_ops;
65990 + seq_operations_no_const seq_ops;
65991 };
65992
65993 struct tcp_iter_state {
65994 diff --git a/include/net/udp.h b/include/net/udp.h
65995 index 065f379..b661b40 100644
65996 --- a/include/net/udp.h
65997 +++ b/include/net/udp.h
65998 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65999 sa_family_t family;
66000 struct udp_table *udp_table;
66001 const struct file_operations *seq_fops;
66002 - struct seq_operations seq_ops;
66003 + seq_operations_no_const seq_ops;
66004 };
66005
66006 struct udp_iter_state {
66007 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
66008 index 639dd13..15b206c 100644
66009 --- a/include/net/xfrm.h
66010 +++ b/include/net/xfrm.h
66011 @@ -514,7 +514,7 @@ struct xfrm_policy {
66012 struct timer_list timer;
66013
66014 struct flow_cache_object flo;
66015 - atomic_t genid;
66016 + atomic_unchecked_t genid;
66017 u32 priority;
66018 u32 index;
66019 struct xfrm_mark mark;
66020 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
66021 index 1a046b1..ee0bef0 100644
66022 --- a/include/rdma/iw_cm.h
66023 +++ b/include/rdma/iw_cm.h
66024 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
66025 int backlog);
66026
66027 int (*destroy_listen)(struct iw_cm_id *cm_id);
66028 -};
66029 +} __no_const;
66030
66031 /**
66032 * iw_create_cm_id - Create an IW CM identifier.
66033 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
66034 index 399162b..b337f1a 100644
66035 --- a/include/scsi/libfc.h
66036 +++ b/include/scsi/libfc.h
66037 @@ -762,6 +762,7 @@ struct libfc_function_template {
66038 */
66039 void (*disc_stop_final) (struct fc_lport *);
66040 };
66041 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
66042
66043 /**
66044 * struct fc_disc - Discovery context
66045 @@ -866,7 +867,7 @@ struct fc_lport {
66046 struct fc_vport *vport;
66047
66048 /* Operational Information */
66049 - struct libfc_function_template tt;
66050 + libfc_function_template_no_const tt;
66051 u8 link_up;
66052 u8 qfull;
66053 enum fc_lport_state state;
66054 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
66055 index 9895f69..f1418f0 100644
66056 --- a/include/scsi/scsi_device.h
66057 +++ b/include/scsi/scsi_device.h
66058 @@ -166,9 +166,9 @@ struct scsi_device {
66059 unsigned int max_device_blocked; /* what device_blocked counts down from */
66060 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
66061
66062 - atomic_t iorequest_cnt;
66063 - atomic_t iodone_cnt;
66064 - atomic_t ioerr_cnt;
66065 + atomic_unchecked_t iorequest_cnt;
66066 + atomic_unchecked_t iodone_cnt;
66067 + atomic_unchecked_t ioerr_cnt;
66068
66069 struct device sdev_gendev,
66070 sdev_dev;
66071 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
66072 index b797e8f..8e2c3aa 100644
66073 --- a/include/scsi/scsi_transport_fc.h
66074 +++ b/include/scsi/scsi_transport_fc.h
66075 @@ -751,7 +751,8 @@ struct fc_function_template {
66076 unsigned long show_host_system_hostname:1;
66077
66078 unsigned long disable_target_scan:1;
66079 -};
66080 +} __do_const;
66081 +typedef struct fc_function_template __no_const fc_function_template_no_const;
66082
66083
66084 /**
66085 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
66086 index 030b87c..98a6954 100644
66087 --- a/include/sound/ak4xxx-adda.h
66088 +++ b/include/sound/ak4xxx-adda.h
66089 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
66090 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
66091 unsigned char val);
66092 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
66093 -};
66094 +} __no_const;
66095
66096 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
66097
66098 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
66099 index 8c05e47..2b5df97 100644
66100 --- a/include/sound/hwdep.h
66101 +++ b/include/sound/hwdep.h
66102 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
66103 struct snd_hwdep_dsp_status *status);
66104 int (*dsp_load)(struct snd_hwdep *hw,
66105 struct snd_hwdep_dsp_image *image);
66106 -};
66107 +} __no_const;
66108
66109 struct snd_hwdep {
66110 struct snd_card *card;
66111 diff --git a/include/sound/info.h b/include/sound/info.h
66112 index 9ca1a49..aba1728 100644
66113 --- a/include/sound/info.h
66114 +++ b/include/sound/info.h
66115 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
66116 struct snd_info_buffer *buffer);
66117 void (*write)(struct snd_info_entry *entry,
66118 struct snd_info_buffer *buffer);
66119 -};
66120 +} __no_const;
66121
66122 struct snd_info_entry_ops {
66123 int (*open)(struct snd_info_entry *entry,
66124 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
66125 index cdca2ab..10bbe05 100644
66126 --- a/include/sound/pcm.h
66127 +++ b/include/sound/pcm.h
66128 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
66129 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
66130 int (*ack)(struct snd_pcm_substream *substream);
66131 };
66132 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
66133
66134 /*
66135 *
66136 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
66137 index af1b49e..a5d55a5 100644
66138 --- a/include/sound/sb16_csp.h
66139 +++ b/include/sound/sb16_csp.h
66140 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
66141 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
66142 int (*csp_stop) (struct snd_sb_csp * p);
66143 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
66144 -};
66145 +} __no_const;
66146
66147 /*
66148 * CSP private data
66149 diff --git a/include/sound/soc.h b/include/sound/soc.h
66150 index e063380..e8077d5 100644
66151 --- a/include/sound/soc.h
66152 +++ b/include/sound/soc.h
66153 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
66154 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
66155 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
66156 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
66157 -};
66158 +} __do_const;
66159
66160 struct snd_soc_platform {
66161 const char *name;
66162 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
66163 struct snd_soc_dai_link *dai_link;
66164 struct mutex pcm_mutex;
66165 enum snd_soc_pcm_subclass pcm_subclass;
66166 - struct snd_pcm_ops ops;
66167 + snd_pcm_ops_no_const ops;
66168
66169 unsigned int dev_registered:1;
66170
66171 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
66172 index fe8590c..aaed363 100644
66173 --- a/include/sound/tea575x-tuner.h
66174 +++ b/include/sound/tea575x-tuner.h
66175 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
66176
66177 struct snd_tea575x {
66178 struct v4l2_device *v4l2_dev;
66179 - struct v4l2_file_operations fops;
66180 + v4l2_file_operations_no_const fops;
66181 struct video_device vd; /* video device */
66182 int radio_nr; /* radio_nr */
66183 bool tea5759; /* 5759 chip is present */
66184 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
66185 index 5be8937..a8e46e9 100644
66186 --- a/include/target/target_core_base.h
66187 +++ b/include/target/target_core_base.h
66188 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
66189 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
66190 int (*t10_pr_register)(struct se_cmd *);
66191 int (*t10_pr_clear)(struct se_cmd *);
66192 -};
66193 +} __no_const;
66194
66195 struct t10_reservation {
66196 /* Reservation effects all target ports */
66197 @@ -758,7 +758,7 @@ struct se_device {
66198 spinlock_t stats_lock;
66199 /* Active commands on this virtual SE device */
66200 atomic_t simple_cmds;
66201 - atomic_t dev_ordered_id;
66202 + atomic_unchecked_t dev_ordered_id;
66203 atomic_t dev_ordered_sync;
66204 atomic_t dev_qf_count;
66205 struct se_obj dev_obj;
66206 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
66207 new file mode 100644
66208 index 0000000..2efe49d
66209 --- /dev/null
66210 +++ b/include/trace/events/fs.h
66211 @@ -0,0 +1,53 @@
66212 +#undef TRACE_SYSTEM
66213 +#define TRACE_SYSTEM fs
66214 +
66215 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
66216 +#define _TRACE_FS_H
66217 +
66218 +#include <linux/fs.h>
66219 +#include <linux/tracepoint.h>
66220 +
66221 +TRACE_EVENT(do_sys_open,
66222 +
66223 + TP_PROTO(char *filename, int flags, int mode),
66224 +
66225 + TP_ARGS(filename, flags, mode),
66226 +
66227 + TP_STRUCT__entry(
66228 + __string( filename, filename )
66229 + __field( int, flags )
66230 + __field( int, mode )
66231 + ),
66232 +
66233 + TP_fast_assign(
66234 + __assign_str(filename, filename);
66235 + __entry->flags = flags;
66236 + __entry->mode = mode;
66237 + ),
66238 +
66239 + TP_printk("\"%s\" %x %o",
66240 + __get_str(filename), __entry->flags, __entry->mode)
66241 +);
66242 +
66243 +TRACE_EVENT(open_exec,
66244 +
66245 + TP_PROTO(const char *filename),
66246 +
66247 + TP_ARGS(filename),
66248 +
66249 + TP_STRUCT__entry(
66250 + __string( filename, filename )
66251 + ),
66252 +
66253 + TP_fast_assign(
66254 + __assign_str(filename, filename);
66255 + ),
66256 +
66257 + TP_printk("\"%s\"",
66258 + __get_str(filename))
66259 +);
66260 +
66261 +#endif /* _TRACE_FS_H */
66262 +
66263 +/* This part must be outside protection */
66264 +#include <trace/define_trace.h>
66265 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
66266 index 1c09820..7f5ec79 100644
66267 --- a/include/trace/events/irq.h
66268 +++ b/include/trace/events/irq.h
66269 @@ -36,7 +36,7 @@ struct softirq_action;
66270 */
66271 TRACE_EVENT(irq_handler_entry,
66272
66273 - TP_PROTO(int irq, struct irqaction *action),
66274 + TP_PROTO(int irq, const struct irqaction *action),
66275
66276 TP_ARGS(irq, action),
66277
66278 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
66279 */
66280 TRACE_EVENT(irq_handler_exit,
66281
66282 - TP_PROTO(int irq, struct irqaction *action, int ret),
66283 + TP_PROTO(int irq, const struct irqaction *action, int ret),
66284
66285 TP_ARGS(irq, action, ret),
66286
66287 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
66288 index f9466fa..f4e2b81 100644
66289 --- a/include/video/udlfb.h
66290 +++ b/include/video/udlfb.h
66291 @@ -53,10 +53,10 @@ struct dlfb_data {
66292 u32 pseudo_palette[256];
66293 int blank_mode; /*one of FB_BLANK_ */
66294 /* blit-only rendering path metrics, exposed through sysfs */
66295 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66296 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
66297 - atomic_t bytes_sent; /* to usb, after compression including overhead */
66298 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
66299 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66300 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
66301 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
66302 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
66303 };
66304
66305 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
66306 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
66307 index 0993a22..32ba2fe 100644
66308 --- a/include/video/uvesafb.h
66309 +++ b/include/video/uvesafb.h
66310 @@ -177,6 +177,7 @@ struct uvesafb_par {
66311 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
66312 u8 pmi_setpal; /* PMI for palette changes */
66313 u16 *pmi_base; /* protected mode interface location */
66314 + u8 *pmi_code; /* protected mode code location */
66315 void *pmi_start;
66316 void *pmi_pal;
66317 u8 *vbe_state_orig; /*
66318 diff --git a/init/Kconfig b/init/Kconfig
66319 index af6c7f8..5c188f8 100644
66320 --- a/init/Kconfig
66321 +++ b/init/Kconfig
66322 @@ -850,6 +850,7 @@ endif # CGROUPS
66323
66324 config CHECKPOINT_RESTORE
66325 bool "Checkpoint/restore support" if EXPERT
66326 + depends on !GRKERNSEC
66327 default n
66328 help
66329 Enables additional kernel features in a sake of checkpoint/restore.
66330 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
66331 # Security modules
66332 depends on SECURITY_TOMOYO = n
66333 depends on SECURITY_APPARMOR = n
66334 + depends on GRKERNSEC = n
66335
66336 config UIDGID_STRICT_TYPE_CHECKS
66337 bool "Require conversions between uid/gids and their internal representation"
66338 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
66339
66340 config COMPAT_BRK
66341 bool "Disable heap randomization"
66342 - default y
66343 + default n
66344 help
66345 Randomizing heap placement makes heap exploits harder, but it
66346 also breaks ancient binaries (including anything libc5 based).
66347 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
66348 config STOP_MACHINE
66349 bool
66350 default y
66351 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
66352 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
66353 help
66354 Need stop_machine() primitive.
66355
66356 diff --git a/init/Makefile b/init/Makefile
66357 index 7bc47ee..6da2dc7 100644
66358 --- a/init/Makefile
66359 +++ b/init/Makefile
66360 @@ -2,6 +2,9 @@
66361 # Makefile for the linux kernel.
66362 #
66363
66364 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
66365 +asflags-y := $(GCC_PLUGINS_AFLAGS)
66366 +
66367 obj-y := main.o version.o mounts.o
66368 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
66369 obj-y += noinitramfs.o
66370 diff --git a/init/do_mounts.c b/init/do_mounts.c
66371 index d3f0aee..c9322f5 100644
66372 --- a/init/do_mounts.c
66373 +++ b/init/do_mounts.c
66374 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
66375 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66376 {
66377 struct super_block *s;
66378 - int err = sys_mount(name, "/root", fs, flags, data);
66379 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
66380 if (err)
66381 return err;
66382
66383 - sys_chdir("/root");
66384 + sys_chdir((const char __force_user *)"/root");
66385 s = current->fs->pwd.dentry->d_sb;
66386 ROOT_DEV = s->s_dev;
66387 printk(KERN_INFO
66388 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
66389 va_start(args, fmt);
66390 vsprintf(buf, fmt, args);
66391 va_end(args);
66392 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66393 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66394 if (fd >= 0) {
66395 sys_ioctl(fd, FDEJECT, 0);
66396 sys_close(fd);
66397 }
66398 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66399 - fd = sys_open("/dev/console", O_RDWR, 0);
66400 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66401 if (fd >= 0) {
66402 sys_ioctl(fd, TCGETS, (long)&termios);
66403 termios.c_lflag &= ~ICANON;
66404 sys_ioctl(fd, TCSETSF, (long)&termios);
66405 - sys_read(fd, &c, 1);
66406 + sys_read(fd, (char __user *)&c, 1);
66407 termios.c_lflag |= ICANON;
66408 sys_ioctl(fd, TCSETSF, (long)&termios);
66409 sys_close(fd);
66410 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
66411 mount_root();
66412 out:
66413 devtmpfs_mount("dev");
66414 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66415 - sys_chroot(".");
66416 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66417 + sys_chroot((const char __force_user *)".");
66418 }
66419 diff --git a/init/do_mounts.h b/init/do_mounts.h
66420 index f5b978a..69dbfe8 100644
66421 --- a/init/do_mounts.h
66422 +++ b/init/do_mounts.h
66423 @@ -15,15 +15,15 @@ extern int root_mountflags;
66424
66425 static inline int create_dev(char *name, dev_t dev)
66426 {
66427 - sys_unlink(name);
66428 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66429 + sys_unlink((char __force_user *)name);
66430 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
66431 }
66432
66433 #if BITS_PER_LONG == 32
66434 static inline u32 bstat(char *name)
66435 {
66436 struct stat64 stat;
66437 - if (sys_stat64(name, &stat) != 0)
66438 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
66439 return 0;
66440 if (!S_ISBLK(stat.st_mode))
66441 return 0;
66442 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
66443 static inline u32 bstat(char *name)
66444 {
66445 struct stat stat;
66446 - if (sys_newstat(name, &stat) != 0)
66447 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
66448 return 0;
66449 if (!S_ISBLK(stat.st_mode))
66450 return 0;
66451 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
66452 index 135959a2..28a3f43 100644
66453 --- a/init/do_mounts_initrd.c
66454 +++ b/init/do_mounts_initrd.c
66455 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
66456 create_dev("/dev/root.old", Root_RAM0);
66457 /* mount initrd on rootfs' /root */
66458 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66459 - sys_mkdir("/old", 0700);
66460 - root_fd = sys_open("/", 0, 0);
66461 - old_fd = sys_open("/old", 0, 0);
66462 + sys_mkdir((const char __force_user *)"/old", 0700);
66463 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
66464 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
66465 /* move initrd over / and chdir/chroot in initrd root */
66466 - sys_chdir("/root");
66467 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66468 - sys_chroot(".");
66469 + sys_chdir((const char __force_user *)"/root");
66470 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66471 + sys_chroot((const char __force_user *)".");
66472
66473 /*
66474 * In case that a resume from disk is carried out by linuxrc or one of
66475 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
66476
66477 /* move initrd to rootfs' /old */
66478 sys_fchdir(old_fd);
66479 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
66480 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
66481 /* switch root and cwd back to / of rootfs */
66482 sys_fchdir(root_fd);
66483 - sys_chroot(".");
66484 + sys_chroot((const char __force_user *)".");
66485 sys_close(old_fd);
66486 sys_close(root_fd);
66487
66488 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66489 - sys_chdir("/old");
66490 + sys_chdir((const char __force_user *)"/old");
66491 return;
66492 }
66493
66494 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
66495 mount_root();
66496
66497 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66498 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66499 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66500 if (!error)
66501 printk("okay\n");
66502 else {
66503 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66504 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66505 if (error == -ENOENT)
66506 printk("/initrd does not exist. Ignored.\n");
66507 else
66508 printk("failed\n");
66509 printk(KERN_NOTICE "Unmounting old root\n");
66510 - sys_umount("/old", MNT_DETACH);
66511 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66512 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66513 if (fd < 0) {
66514 error = fd;
66515 @@ -125,11 +125,11 @@ int __init initrd_load(void)
66516 * mounted in the normal path.
66517 */
66518 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66519 - sys_unlink("/initrd.image");
66520 + sys_unlink((const char __force_user *)"/initrd.image");
66521 handle_initrd();
66522 return 1;
66523 }
66524 }
66525 - sys_unlink("/initrd.image");
66526 + sys_unlink((const char __force_user *)"/initrd.image");
66527 return 0;
66528 }
66529 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66530 index 8cb6db5..d729f50 100644
66531 --- a/init/do_mounts_md.c
66532 +++ b/init/do_mounts_md.c
66533 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66534 partitioned ? "_d" : "", minor,
66535 md_setup_args[ent].device_names);
66536
66537 - fd = sys_open(name, 0, 0);
66538 + fd = sys_open((char __force_user *)name, 0, 0);
66539 if (fd < 0) {
66540 printk(KERN_ERR "md: open failed - cannot start "
66541 "array %s\n", name);
66542 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66543 * array without it
66544 */
66545 sys_close(fd);
66546 - fd = sys_open(name, 0, 0);
66547 + fd = sys_open((char __force_user *)name, 0, 0);
66548 sys_ioctl(fd, BLKRRPART, 0);
66549 }
66550 sys_close(fd);
66551 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66552
66553 wait_for_device_probe();
66554
66555 - fd = sys_open("/dev/md0", 0, 0);
66556 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66557 if (fd >= 0) {
66558 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66559 sys_close(fd);
66560 diff --git a/init/init_task.c b/init/init_task.c
66561 index 8b2f399..f0797c9 100644
66562 --- a/init/init_task.c
66563 +++ b/init/init_task.c
66564 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66565 * Initial thread structure. Alignment of this is handled by a special
66566 * linker map entry.
66567 */
66568 +#ifdef CONFIG_X86
66569 +union thread_union init_thread_union __init_task_data;
66570 +#else
66571 union thread_union init_thread_union __init_task_data =
66572 { INIT_THREAD_INFO(init_task) };
66573 +#endif
66574 diff --git a/init/initramfs.c b/init/initramfs.c
66575 index 84c6bf1..8899338 100644
66576 --- a/init/initramfs.c
66577 +++ b/init/initramfs.c
66578 @@ -84,7 +84,7 @@ static void __init free_hash(void)
66579 }
66580 }
66581
66582 -static long __init do_utime(char *filename, time_t mtime)
66583 +static long __init do_utime(char __force_user *filename, time_t mtime)
66584 {
66585 struct timespec t[2];
66586
66587 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
66588 struct dir_entry *de, *tmp;
66589 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66590 list_del(&de->list);
66591 - do_utime(de->name, de->mtime);
66592 + do_utime((char __force_user *)de->name, de->mtime);
66593 kfree(de->name);
66594 kfree(de);
66595 }
66596 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
66597 if (nlink >= 2) {
66598 char *old = find_link(major, minor, ino, mode, collected);
66599 if (old)
66600 - return (sys_link(old, collected) < 0) ? -1 : 1;
66601 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66602 }
66603 return 0;
66604 }
66605 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66606 {
66607 struct stat st;
66608
66609 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66610 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66611 if (S_ISDIR(st.st_mode))
66612 - sys_rmdir(path);
66613 + sys_rmdir((char __force_user *)path);
66614 else
66615 - sys_unlink(path);
66616 + sys_unlink((char __force_user *)path);
66617 }
66618 }
66619
66620 @@ -315,7 +315,7 @@ static int __init do_name(void)
66621 int openflags = O_WRONLY|O_CREAT;
66622 if (ml != 1)
66623 openflags |= O_TRUNC;
66624 - wfd = sys_open(collected, openflags, mode);
66625 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66626
66627 if (wfd >= 0) {
66628 sys_fchown(wfd, uid, gid);
66629 @@ -327,17 +327,17 @@ static int __init do_name(void)
66630 }
66631 }
66632 } else if (S_ISDIR(mode)) {
66633 - sys_mkdir(collected, mode);
66634 - sys_chown(collected, uid, gid);
66635 - sys_chmod(collected, mode);
66636 + sys_mkdir((char __force_user *)collected, mode);
66637 + sys_chown((char __force_user *)collected, uid, gid);
66638 + sys_chmod((char __force_user *)collected, mode);
66639 dir_add(collected, mtime);
66640 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66641 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66642 if (maybe_link() == 0) {
66643 - sys_mknod(collected, mode, rdev);
66644 - sys_chown(collected, uid, gid);
66645 - sys_chmod(collected, mode);
66646 - do_utime(collected, mtime);
66647 + sys_mknod((char __force_user *)collected, mode, rdev);
66648 + sys_chown((char __force_user *)collected, uid, gid);
66649 + sys_chmod((char __force_user *)collected, mode);
66650 + do_utime((char __force_user *)collected, mtime);
66651 }
66652 }
66653 return 0;
66654 @@ -346,15 +346,15 @@ static int __init do_name(void)
66655 static int __init do_copy(void)
66656 {
66657 if (count >= body_len) {
66658 - sys_write(wfd, victim, body_len);
66659 + sys_write(wfd, (char __force_user *)victim, body_len);
66660 sys_close(wfd);
66661 - do_utime(vcollected, mtime);
66662 + do_utime((char __force_user *)vcollected, mtime);
66663 kfree(vcollected);
66664 eat(body_len);
66665 state = SkipIt;
66666 return 0;
66667 } else {
66668 - sys_write(wfd, victim, count);
66669 + sys_write(wfd, (char __force_user *)victim, count);
66670 body_len -= count;
66671 eat(count);
66672 return 1;
66673 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66674 {
66675 collected[N_ALIGN(name_len) + body_len] = '\0';
66676 clean_path(collected, 0);
66677 - sys_symlink(collected + N_ALIGN(name_len), collected);
66678 - sys_lchown(collected, uid, gid);
66679 - do_utime(collected, mtime);
66680 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66681 + sys_lchown((char __force_user *)collected, uid, gid);
66682 + do_utime((char __force_user *)collected, mtime);
66683 state = SkipIt;
66684 next_state = Reset;
66685 return 0;
66686 diff --git a/init/main.c b/init/main.c
66687 index d61ec54..bd3144f 100644
66688 --- a/init/main.c
66689 +++ b/init/main.c
66690 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66691 extern void tc_init(void);
66692 #endif
66693
66694 +extern void grsecurity_init(void);
66695 +
66696 /*
66697 * Debug helper: via this flag we know that we are in 'early bootup code'
66698 * where only the boot processor is running with IRQ disabled. This means
66699 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66700
66701 __setup("reset_devices", set_reset_devices);
66702
66703 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66704 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66705 +static int __init setup_grsec_proc_gid(char *str)
66706 +{
66707 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66708 + return 1;
66709 +}
66710 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66711 +#endif
66712 +
66713 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66714 +extern char pax_enter_kernel_user[];
66715 +extern char pax_exit_kernel_user[];
66716 +extern pgdval_t clone_pgd_mask;
66717 +#endif
66718 +
66719 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66720 +static int __init setup_pax_nouderef(char *str)
66721 +{
66722 +#ifdef CONFIG_X86_32
66723 + unsigned int cpu;
66724 + struct desc_struct *gdt;
66725 +
66726 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66727 + gdt = get_cpu_gdt_table(cpu);
66728 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66729 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66730 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66731 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66732 + }
66733 + loadsegment(ds, __KERNEL_DS);
66734 + loadsegment(es, __KERNEL_DS);
66735 + loadsegment(ss, __KERNEL_DS);
66736 +#else
66737 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66738 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66739 + clone_pgd_mask = ~(pgdval_t)0UL;
66740 +#endif
66741 +
66742 + return 0;
66743 +}
66744 +early_param("pax_nouderef", setup_pax_nouderef);
66745 +#endif
66746 +
66747 +#ifdef CONFIG_PAX_SOFTMODE
66748 +int pax_softmode;
66749 +
66750 +static int __init setup_pax_softmode(char *str)
66751 +{
66752 + get_option(&str, &pax_softmode);
66753 + return 1;
66754 +}
66755 +__setup("pax_softmode=", setup_pax_softmode);
66756 +#endif
66757 +
66758 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66759 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66760 static const char *panic_later, *panic_param;
66761 @@ -678,6 +735,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66762 {
66763 int count = preempt_count();
66764 int ret;
66765 + const char *msg1 = "", *msg2 = "";
66766
66767 if (initcall_debug)
66768 ret = do_one_initcall_debug(fn);
66769 @@ -690,15 +748,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66770 sprintf(msgbuf, "error code %d ", ret);
66771
66772 if (preempt_count() != count) {
66773 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66774 + msg1 = " preemption imbalance";
66775 preempt_count() = count;
66776 }
66777 if (irqs_disabled()) {
66778 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66779 + msg2 = " disabled interrupts";
66780 local_irq_enable();
66781 }
66782 - if (msgbuf[0]) {
66783 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66784 + if (msgbuf[0] || *msg1 || *msg2) {
66785 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66786 }
66787
66788 return ret;
66789 @@ -752,8 +810,14 @@ static void __init do_initcall_level(int level)
66790 level, level,
66791 &repair_env_string);
66792
66793 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66794 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66795 do_one_initcall(*fn);
66796 +
66797 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66798 + transfer_latent_entropy();
66799 +#endif
66800 +
66801 + }
66802 }
66803
66804 static void __init do_initcalls(void)
66805 @@ -787,8 +851,14 @@ static void __init do_pre_smp_initcalls(void)
66806 {
66807 initcall_t *fn;
66808
66809 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66810 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66811 do_one_initcall(*fn);
66812 +
66813 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66814 + transfer_latent_entropy();
66815 +#endif
66816 +
66817 + }
66818 }
66819
66820 static void run_init_process(const char *init_filename)
66821 @@ -870,7 +940,7 @@ static int __init kernel_init(void * unused)
66822 do_basic_setup();
66823
66824 /* Open the /dev/console on the rootfs, this should never fail */
66825 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66826 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66827 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66828
66829 (void) sys_dup(0);
66830 @@ -883,11 +953,13 @@ static int __init kernel_init(void * unused)
66831 if (!ramdisk_execute_command)
66832 ramdisk_execute_command = "/init";
66833
66834 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66835 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66836 ramdisk_execute_command = NULL;
66837 prepare_namespace();
66838 }
66839
66840 + grsecurity_init();
66841 +
66842 /*
66843 * Ok, we have completed the initial bootup, and
66844 * we're essentially up and running. Get rid of the
66845 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66846 index 9a08acc..e65ebe7 100644
66847 --- a/ipc/mqueue.c
66848 +++ b/ipc/mqueue.c
66849 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66850 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66851 info->attr.mq_msgsize);
66852
66853 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66854 spin_lock(&mq_lock);
66855 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66856 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66857 diff --git a/ipc/msg.c b/ipc/msg.c
66858 index 7385de2..a8180e08 100644
66859 --- a/ipc/msg.c
66860 +++ b/ipc/msg.c
66861 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66862 return security_msg_queue_associate(msq, msgflg);
66863 }
66864
66865 +static struct ipc_ops msg_ops = {
66866 + .getnew = newque,
66867 + .associate = msg_security,
66868 + .more_checks = NULL
66869 +};
66870 +
66871 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66872 {
66873 struct ipc_namespace *ns;
66874 - struct ipc_ops msg_ops;
66875 struct ipc_params msg_params;
66876
66877 ns = current->nsproxy->ipc_ns;
66878
66879 - msg_ops.getnew = newque;
66880 - msg_ops.associate = msg_security;
66881 - msg_ops.more_checks = NULL;
66882 -
66883 msg_params.key = key;
66884 msg_params.flg = msgflg;
66885
66886 diff --git a/ipc/sem.c b/ipc/sem.c
66887 index 5215a81..cfc0cac 100644
66888 --- a/ipc/sem.c
66889 +++ b/ipc/sem.c
66890 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66891 return 0;
66892 }
66893
66894 +static struct ipc_ops sem_ops = {
66895 + .getnew = newary,
66896 + .associate = sem_security,
66897 + .more_checks = sem_more_checks
66898 +};
66899 +
66900 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66901 {
66902 struct ipc_namespace *ns;
66903 - struct ipc_ops sem_ops;
66904 struct ipc_params sem_params;
66905
66906 ns = current->nsproxy->ipc_ns;
66907 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66908 if (nsems < 0 || nsems > ns->sc_semmsl)
66909 return -EINVAL;
66910
66911 - sem_ops.getnew = newary;
66912 - sem_ops.associate = sem_security;
66913 - sem_ops.more_checks = sem_more_checks;
66914 -
66915 sem_params.key = key;
66916 sem_params.flg = semflg;
66917 sem_params.u.nsems = nsems;
66918 diff --git a/ipc/shm.c b/ipc/shm.c
66919 index 00faa05..7040960 100644
66920 --- a/ipc/shm.c
66921 +++ b/ipc/shm.c
66922 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66923 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66924 #endif
66925
66926 +#ifdef CONFIG_GRKERNSEC
66927 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66928 + const time_t shm_createtime, const uid_t cuid,
66929 + const int shmid);
66930 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66931 + const time_t shm_createtime);
66932 +#endif
66933 +
66934 void shm_init_ns(struct ipc_namespace *ns)
66935 {
66936 ns->shm_ctlmax = SHMMAX;
66937 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66938 shp->shm_lprid = 0;
66939 shp->shm_atim = shp->shm_dtim = 0;
66940 shp->shm_ctim = get_seconds();
66941 +#ifdef CONFIG_GRKERNSEC
66942 + {
66943 + struct timespec timeval;
66944 + do_posix_clock_monotonic_gettime(&timeval);
66945 +
66946 + shp->shm_createtime = timeval.tv_sec;
66947 + }
66948 +#endif
66949 shp->shm_segsz = size;
66950 shp->shm_nattch = 0;
66951 shp->shm_file = file;
66952 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66953 return 0;
66954 }
66955
66956 +static struct ipc_ops shm_ops = {
66957 + .getnew = newseg,
66958 + .associate = shm_security,
66959 + .more_checks = shm_more_checks
66960 +};
66961 +
66962 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66963 {
66964 struct ipc_namespace *ns;
66965 - struct ipc_ops shm_ops;
66966 struct ipc_params shm_params;
66967
66968 ns = current->nsproxy->ipc_ns;
66969
66970 - shm_ops.getnew = newseg;
66971 - shm_ops.associate = shm_security;
66972 - shm_ops.more_checks = shm_more_checks;
66973 -
66974 shm_params.key = key;
66975 shm_params.flg = shmflg;
66976 shm_params.u.size = size;
66977 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66978 f_mode = FMODE_READ | FMODE_WRITE;
66979 }
66980 if (shmflg & SHM_EXEC) {
66981 +
66982 +#ifdef CONFIG_PAX_MPROTECT
66983 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66984 + goto out;
66985 +#endif
66986 +
66987 prot |= PROT_EXEC;
66988 acc_mode |= S_IXUGO;
66989 }
66990 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66991 if (err)
66992 goto out_unlock;
66993
66994 +#ifdef CONFIG_GRKERNSEC
66995 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66996 + shp->shm_perm.cuid, shmid) ||
66997 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66998 + err = -EACCES;
66999 + goto out_unlock;
67000 + }
67001 +#endif
67002 +
67003 path = shp->shm_file->f_path;
67004 path_get(&path);
67005 shp->shm_nattch++;
67006 +#ifdef CONFIG_GRKERNSEC
67007 + shp->shm_lapid = current->pid;
67008 +#endif
67009 size = i_size_read(path.dentry->d_inode);
67010 shm_unlock(shp);
67011
67012 diff --git a/kernel/acct.c b/kernel/acct.c
67013 index 02e6167..54824f7 100644
67014 --- a/kernel/acct.c
67015 +++ b/kernel/acct.c
67016 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
67017 */
67018 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
67019 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
67020 - file->f_op->write(file, (char *)&ac,
67021 + file->f_op->write(file, (char __force_user *)&ac,
67022 sizeof(acct_t), &file->f_pos);
67023 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
67024 set_fs(fs);
67025 diff --git a/kernel/audit.c b/kernel/audit.c
67026 index a8c84be..8bd034c 100644
67027 --- a/kernel/audit.c
67028 +++ b/kernel/audit.c
67029 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
67030 3) suppressed due to audit_rate_limit
67031 4) suppressed due to audit_backlog_limit
67032 */
67033 -static atomic_t audit_lost = ATOMIC_INIT(0);
67034 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
67035
67036 /* The netlink socket. */
67037 static struct sock *audit_sock;
67038 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
67039 unsigned long now;
67040 int print;
67041
67042 - atomic_inc(&audit_lost);
67043 + atomic_inc_unchecked(&audit_lost);
67044
67045 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
67046
67047 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
67048 printk(KERN_WARNING
67049 "audit: audit_lost=%d audit_rate_limit=%d "
67050 "audit_backlog_limit=%d\n",
67051 - atomic_read(&audit_lost),
67052 + atomic_read_unchecked(&audit_lost),
67053 audit_rate_limit,
67054 audit_backlog_limit);
67055 audit_panic(message);
67056 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
67057 status_set.pid = audit_pid;
67058 status_set.rate_limit = audit_rate_limit;
67059 status_set.backlog_limit = audit_backlog_limit;
67060 - status_set.lost = atomic_read(&audit_lost);
67061 + status_set.lost = atomic_read_unchecked(&audit_lost);
67062 status_set.backlog = skb_queue_len(&audit_skb_queue);
67063 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
67064 &status_set, sizeof(status_set));
67065 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
67066 index 4b96415..d8c16ee 100644
67067 --- a/kernel/auditsc.c
67068 +++ b/kernel/auditsc.c
67069 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
67070 }
67071
67072 /* global counter which is incremented every time something logs in */
67073 -static atomic_t session_id = ATOMIC_INIT(0);
67074 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
67075
67076 /**
67077 * audit_set_loginuid - set current task's audit_context loginuid
67078 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
67079 return -EPERM;
67080 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
67081
67082 - sessionid = atomic_inc_return(&session_id);
67083 + sessionid = atomic_inc_return_unchecked(&session_id);
67084 if (context && context->in_syscall) {
67085 struct audit_buffer *ab;
67086
67087 diff --git a/kernel/capability.c b/kernel/capability.c
67088 index 493d972..ea17248 100644
67089 --- a/kernel/capability.c
67090 +++ b/kernel/capability.c
67091 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
67092 * before modification is attempted and the application
67093 * fails.
67094 */
67095 + if (tocopy > ARRAY_SIZE(kdata))
67096 + return -EFAULT;
67097 +
67098 if (copy_to_user(dataptr, kdata, tocopy
67099 * sizeof(struct __user_cap_data_struct))) {
67100 return -EFAULT;
67101 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
67102 int ret;
67103
67104 rcu_read_lock();
67105 - ret = security_capable(__task_cred(t), ns, cap);
67106 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
67107 + gr_task_is_capable(t, __task_cred(t), cap);
67108 rcu_read_unlock();
67109
67110 - return (ret == 0);
67111 + return ret;
67112 }
67113
67114 /**
67115 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
67116 int ret;
67117
67118 rcu_read_lock();
67119 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
67120 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
67121 rcu_read_unlock();
67122
67123 - return (ret == 0);
67124 + return ret;
67125 }
67126
67127 /**
67128 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
67129 BUG();
67130 }
67131
67132 - if (security_capable(current_cred(), ns, cap) == 0) {
67133 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
67134 current->flags |= PF_SUPERPRIV;
67135 return true;
67136 }
67137 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
67138 }
67139 EXPORT_SYMBOL(ns_capable);
67140
67141 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
67142 +{
67143 + if (unlikely(!cap_valid(cap))) {
67144 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
67145 + BUG();
67146 + }
67147 +
67148 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
67149 + current->flags |= PF_SUPERPRIV;
67150 + return true;
67151 + }
67152 + return false;
67153 +}
67154 +EXPORT_SYMBOL(ns_capable_nolog);
67155 +
67156 /**
67157 * capable - Determine if the current task has a superior capability in effect
67158 * @cap: The capability to be tested for
67159 @@ -408,6 +427,12 @@ bool capable(int cap)
67160 }
67161 EXPORT_SYMBOL(capable);
67162
67163 +bool capable_nolog(int cap)
67164 +{
67165 + return ns_capable_nolog(&init_user_ns, cap);
67166 +}
67167 +EXPORT_SYMBOL(capable_nolog);
67168 +
67169 /**
67170 * nsown_capable - Check superior capability to one's own user_ns
67171 * @cap: The capability in question
67172 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
67173
67174 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
67175 }
67176 +
67177 +bool inode_capable_nolog(const struct inode *inode, int cap)
67178 +{
67179 + struct user_namespace *ns = current_user_ns();
67180 +
67181 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
67182 +}
67183 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
67184 index ff2bce5..a41e8f9 100644
67185 --- a/kernel/cgroup.c
67186 +++ b/kernel/cgroup.c
67187 @@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
67188 struct css_set *cg = link->cg;
67189 struct task_struct *task;
67190 int count = 0;
67191 - seq_printf(seq, "css_set %p\n", cg);
67192 + seq_printf(seq, "css_set %pK\n", cg);
67193 list_for_each_entry(task, &cg->tasks, cg_list) {
67194 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
67195 seq_puts(seq, " ...\n");
67196 diff --git a/kernel/compat.c b/kernel/compat.c
67197 index c28a306..b4d0cf3 100644
67198 --- a/kernel/compat.c
67199 +++ b/kernel/compat.c
67200 @@ -13,6 +13,7 @@
67201
67202 #include <linux/linkage.h>
67203 #include <linux/compat.h>
67204 +#include <linux/module.h>
67205 #include <linux/errno.h>
67206 #include <linux/time.h>
67207 #include <linux/signal.h>
67208 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
67209 mm_segment_t oldfs;
67210 long ret;
67211
67212 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
67213 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
67214 oldfs = get_fs();
67215 set_fs(KERNEL_DS);
67216 ret = hrtimer_nanosleep_restart(restart);
67217 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
67218 oldfs = get_fs();
67219 set_fs(KERNEL_DS);
67220 ret = hrtimer_nanosleep(&tu,
67221 - rmtp ? (struct timespec __user *)&rmt : NULL,
67222 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
67223 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
67224 set_fs(oldfs);
67225
67226 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
67227 mm_segment_t old_fs = get_fs();
67228
67229 set_fs(KERNEL_DS);
67230 - ret = sys_sigpending((old_sigset_t __user *) &s);
67231 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
67232 set_fs(old_fs);
67233 if (ret == 0)
67234 ret = put_user(s, set);
67235 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
67236 mm_segment_t old_fs = get_fs();
67237
67238 set_fs(KERNEL_DS);
67239 - ret = sys_old_getrlimit(resource, &r);
67240 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
67241 set_fs(old_fs);
67242
67243 if (!ret) {
67244 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
67245 mm_segment_t old_fs = get_fs();
67246
67247 set_fs(KERNEL_DS);
67248 - ret = sys_getrusage(who, (struct rusage __user *) &r);
67249 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
67250 set_fs(old_fs);
67251
67252 if (ret)
67253 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
67254 set_fs (KERNEL_DS);
67255 ret = sys_wait4(pid,
67256 (stat_addr ?
67257 - (unsigned int __user *) &status : NULL),
67258 - options, (struct rusage __user *) &r);
67259 + (unsigned int __force_user *) &status : NULL),
67260 + options, (struct rusage __force_user *) &r);
67261 set_fs (old_fs);
67262
67263 if (ret > 0) {
67264 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
67265 memset(&info, 0, sizeof(info));
67266
67267 set_fs(KERNEL_DS);
67268 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
67269 - uru ? (struct rusage __user *)&ru : NULL);
67270 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
67271 + uru ? (struct rusage __force_user *)&ru : NULL);
67272 set_fs(old_fs);
67273
67274 if ((ret < 0) || (info.si_signo == 0))
67275 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
67276 oldfs = get_fs();
67277 set_fs(KERNEL_DS);
67278 err = sys_timer_settime(timer_id, flags,
67279 - (struct itimerspec __user *) &newts,
67280 - (struct itimerspec __user *) &oldts);
67281 + (struct itimerspec __force_user *) &newts,
67282 + (struct itimerspec __force_user *) &oldts);
67283 set_fs(oldfs);
67284 if (!err && old && put_compat_itimerspec(old, &oldts))
67285 return -EFAULT;
67286 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
67287 oldfs = get_fs();
67288 set_fs(KERNEL_DS);
67289 err = sys_timer_gettime(timer_id,
67290 - (struct itimerspec __user *) &ts);
67291 + (struct itimerspec __force_user *) &ts);
67292 set_fs(oldfs);
67293 if (!err && put_compat_itimerspec(setting, &ts))
67294 return -EFAULT;
67295 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
67296 oldfs = get_fs();
67297 set_fs(KERNEL_DS);
67298 err = sys_clock_settime(which_clock,
67299 - (struct timespec __user *) &ts);
67300 + (struct timespec __force_user *) &ts);
67301 set_fs(oldfs);
67302 return err;
67303 }
67304 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
67305 oldfs = get_fs();
67306 set_fs(KERNEL_DS);
67307 err = sys_clock_gettime(which_clock,
67308 - (struct timespec __user *) &ts);
67309 + (struct timespec __force_user *) &ts);
67310 set_fs(oldfs);
67311 if (!err && put_compat_timespec(&ts, tp))
67312 return -EFAULT;
67313 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
67314
67315 oldfs = get_fs();
67316 set_fs(KERNEL_DS);
67317 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
67318 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
67319 set_fs(oldfs);
67320
67321 err = compat_put_timex(utp, &txc);
67322 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
67323 oldfs = get_fs();
67324 set_fs(KERNEL_DS);
67325 err = sys_clock_getres(which_clock,
67326 - (struct timespec __user *) &ts);
67327 + (struct timespec __force_user *) &ts);
67328 set_fs(oldfs);
67329 if (!err && tp && put_compat_timespec(&ts, tp))
67330 return -EFAULT;
67331 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
67332 long err;
67333 mm_segment_t oldfs;
67334 struct timespec tu;
67335 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
67336 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
67337
67338 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
67339 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
67340 oldfs = get_fs();
67341 set_fs(KERNEL_DS);
67342 err = clock_nanosleep_restart(restart);
67343 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
67344 oldfs = get_fs();
67345 set_fs(KERNEL_DS);
67346 err = sys_clock_nanosleep(which_clock, flags,
67347 - (struct timespec __user *) &in,
67348 - (struct timespec __user *) &out);
67349 + (struct timespec __force_user *) &in,
67350 + (struct timespec __force_user *) &out);
67351 set_fs(oldfs);
67352
67353 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
67354 diff --git a/kernel/configs.c b/kernel/configs.c
67355 index 42e8fa0..9e7406b 100644
67356 --- a/kernel/configs.c
67357 +++ b/kernel/configs.c
67358 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
67359 struct proc_dir_entry *entry;
67360
67361 /* create the current config file */
67362 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67363 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
67364 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
67365 + &ikconfig_file_ops);
67366 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67367 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
67368 + &ikconfig_file_ops);
67369 +#endif
67370 +#else
67371 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
67372 &ikconfig_file_ops);
67373 +#endif
67374 +
67375 if (!entry)
67376 return -ENOMEM;
67377
67378 diff --git a/kernel/cred.c b/kernel/cred.c
67379 index de728ac..e3c267c 100644
67380 --- a/kernel/cred.c
67381 +++ b/kernel/cred.c
67382 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
67383 validate_creds(cred);
67384 alter_cred_subscribers(cred, -1);
67385 put_cred(cred);
67386 +
67387 +#ifdef CONFIG_GRKERNSEC_SETXID
67388 + cred = (struct cred *) tsk->delayed_cred;
67389 + if (cred != NULL) {
67390 + tsk->delayed_cred = NULL;
67391 + validate_creds(cred);
67392 + alter_cred_subscribers(cred, -1);
67393 + put_cred(cred);
67394 + }
67395 +#endif
67396 }
67397
67398 /**
67399 @@ -469,7 +479,7 @@ error_put:
67400 * Always returns 0 thus allowing this function to be tail-called at the end
67401 * of, say, sys_setgid().
67402 */
67403 -int commit_creds(struct cred *new)
67404 +static int __commit_creds(struct cred *new)
67405 {
67406 struct task_struct *task = current;
67407 const struct cred *old = task->real_cred;
67408 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
67409
67410 get_cred(new); /* we will require a ref for the subj creds too */
67411
67412 + gr_set_role_label(task, new->uid, new->gid);
67413 +
67414 /* dumpability changes */
67415 if (!uid_eq(old->euid, new->euid) ||
67416 !gid_eq(old->egid, new->egid) ||
67417 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
67418 put_cred(old);
67419 return 0;
67420 }
67421 +#ifdef CONFIG_GRKERNSEC_SETXID
67422 +extern int set_user(struct cred *new);
67423 +
67424 +void gr_delayed_cred_worker(void)
67425 +{
67426 + const struct cred *new = current->delayed_cred;
67427 + struct cred *ncred;
67428 +
67429 + current->delayed_cred = NULL;
67430 +
67431 + if (current_uid() && new != NULL) {
67432 + // from doing get_cred on it when queueing this
67433 + put_cred(new);
67434 + return;
67435 + } else if (new == NULL)
67436 + return;
67437 +
67438 + ncred = prepare_creds();
67439 + if (!ncred)
67440 + goto die;
67441 + // uids
67442 + ncred->uid = new->uid;
67443 + ncred->euid = new->euid;
67444 + ncred->suid = new->suid;
67445 + ncred->fsuid = new->fsuid;
67446 + // gids
67447 + ncred->gid = new->gid;
67448 + ncred->egid = new->egid;
67449 + ncred->sgid = new->sgid;
67450 + ncred->fsgid = new->fsgid;
67451 + // groups
67452 + if (set_groups(ncred, new->group_info) < 0) {
67453 + abort_creds(ncred);
67454 + goto die;
67455 + }
67456 + // caps
67457 + ncred->securebits = new->securebits;
67458 + ncred->cap_inheritable = new->cap_inheritable;
67459 + ncred->cap_permitted = new->cap_permitted;
67460 + ncred->cap_effective = new->cap_effective;
67461 + ncred->cap_bset = new->cap_bset;
67462 +
67463 + if (set_user(ncred)) {
67464 + abort_creds(ncred);
67465 + goto die;
67466 + }
67467 +
67468 + // from doing get_cred on it when queueing this
67469 + put_cred(new);
67470 +
67471 + __commit_creds(ncred);
67472 + return;
67473 +die:
67474 + // from doing get_cred on it when queueing this
67475 + put_cred(new);
67476 + do_group_exit(SIGKILL);
67477 +}
67478 +#endif
67479 +
67480 +int commit_creds(struct cred *new)
67481 +{
67482 +#ifdef CONFIG_GRKERNSEC_SETXID
67483 + int ret;
67484 + int schedule_it = 0;
67485 + struct task_struct *t;
67486 +
67487 + /* we won't get called with tasklist_lock held for writing
67488 + and interrupts disabled as the cred struct in that case is
67489 + init_cred
67490 + */
67491 + if (grsec_enable_setxid && !current_is_single_threaded() &&
67492 + !current_uid() && new->uid) {
67493 + schedule_it = 1;
67494 + }
67495 + ret = __commit_creds(new);
67496 + if (schedule_it) {
67497 + rcu_read_lock();
67498 + read_lock(&tasklist_lock);
67499 + for (t = next_thread(current); t != current;
67500 + t = next_thread(t)) {
67501 + if (t->delayed_cred == NULL) {
67502 + t->delayed_cred = get_cred(new);
67503 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67504 + set_tsk_need_resched(t);
67505 + }
67506 + }
67507 + read_unlock(&tasklist_lock);
67508 + rcu_read_unlock();
67509 + }
67510 + return ret;
67511 +#else
67512 + return __commit_creds(new);
67513 +#endif
67514 +}
67515 +
67516 EXPORT_SYMBOL(commit_creds);
67517
67518 /**
67519 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67520 index 0557f24..1a00d9a 100644
67521 --- a/kernel/debug/debug_core.c
67522 +++ b/kernel/debug/debug_core.c
67523 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67524 */
67525 static atomic_t masters_in_kgdb;
67526 static atomic_t slaves_in_kgdb;
67527 -static atomic_t kgdb_break_tasklet_var;
67528 +static atomic_unchecked_t kgdb_break_tasklet_var;
67529 atomic_t kgdb_setting_breakpoint;
67530
67531 struct task_struct *kgdb_usethread;
67532 @@ -132,7 +132,7 @@ int kgdb_single_step;
67533 static pid_t kgdb_sstep_pid;
67534
67535 /* to keep track of the CPU which is doing the single stepping*/
67536 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67537 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67538
67539 /*
67540 * If you are debugging a problem where roundup (the collection of
67541 @@ -540,7 +540,7 @@ return_normal:
67542 * kernel will only try for the value of sstep_tries before
67543 * giving up and continuing on.
67544 */
67545 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67546 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67547 (kgdb_info[cpu].task &&
67548 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67549 atomic_set(&kgdb_active, -1);
67550 @@ -634,8 +634,8 @@ cpu_master_loop:
67551 }
67552
67553 kgdb_restore:
67554 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67555 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67556 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67557 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67558 if (kgdb_info[sstep_cpu].task)
67559 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67560 else
67561 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
67562 static void kgdb_tasklet_bpt(unsigned long ing)
67563 {
67564 kgdb_breakpoint();
67565 - atomic_set(&kgdb_break_tasklet_var, 0);
67566 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67567 }
67568
67569 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67570
67571 void kgdb_schedule_breakpoint(void)
67572 {
67573 - if (atomic_read(&kgdb_break_tasklet_var) ||
67574 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67575 atomic_read(&kgdb_active) != -1 ||
67576 atomic_read(&kgdb_setting_breakpoint))
67577 return;
67578 - atomic_inc(&kgdb_break_tasklet_var);
67579 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67580 tasklet_schedule(&kgdb_tasklet_breakpoint);
67581 }
67582 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67583 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67584 index 31df170..bc98840 100644
67585 --- a/kernel/debug/kdb/kdb_main.c
67586 +++ b/kernel/debug/kdb/kdb_main.c
67587 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
67588 list_for_each_entry(mod, kdb_modules, list) {
67589
67590 kdb_printf("%-20s%8u 0x%p ", mod->name,
67591 - mod->core_size, (void *)mod);
67592 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67593 #ifdef CONFIG_MODULE_UNLOAD
67594 kdb_printf("%4ld ", module_refcount(mod));
67595 #endif
67596 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
67597 kdb_printf(" (Loading)");
67598 else
67599 kdb_printf(" (Live)");
67600 - kdb_printf(" 0x%p", mod->module_core);
67601 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67602
67603 #ifdef CONFIG_MODULE_UNLOAD
67604 {
67605 diff --git a/kernel/events/core.c b/kernel/events/core.c
67606 index 7fee567..8affa2c 100644
67607 --- a/kernel/events/core.c
67608 +++ b/kernel/events/core.c
67609 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67610 return 0;
67611 }
67612
67613 -static atomic64_t perf_event_id;
67614 +static atomic64_unchecked_t perf_event_id;
67615
67616 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67617 enum event_type_t event_type);
67618 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
67619
67620 static inline u64 perf_event_count(struct perf_event *event)
67621 {
67622 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67623 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67624 }
67625
67626 static u64 perf_event_read(struct perf_event *event)
67627 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67628 mutex_lock(&event->child_mutex);
67629 total += perf_event_read(event);
67630 *enabled += event->total_time_enabled +
67631 - atomic64_read(&event->child_total_time_enabled);
67632 + atomic64_read_unchecked(&event->child_total_time_enabled);
67633 *running += event->total_time_running +
67634 - atomic64_read(&event->child_total_time_running);
67635 + atomic64_read_unchecked(&event->child_total_time_running);
67636
67637 list_for_each_entry(child, &event->child_list, child_list) {
67638 total += perf_event_read(child);
67639 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
67640 userpg->offset -= local64_read(&event->hw.prev_count);
67641
67642 userpg->time_enabled = enabled +
67643 - atomic64_read(&event->child_total_time_enabled);
67644 + atomic64_read_unchecked(&event->child_total_time_enabled);
67645
67646 userpg->time_running = running +
67647 - atomic64_read(&event->child_total_time_running);
67648 + atomic64_read_unchecked(&event->child_total_time_running);
67649
67650 arch_perf_update_userpage(userpg, now);
67651
67652 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67653 values[n++] = perf_event_count(event);
67654 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67655 values[n++] = enabled +
67656 - atomic64_read(&event->child_total_time_enabled);
67657 + atomic64_read_unchecked(&event->child_total_time_enabled);
67658 }
67659 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67660 values[n++] = running +
67661 - atomic64_read(&event->child_total_time_running);
67662 + atomic64_read_unchecked(&event->child_total_time_running);
67663 }
67664 if (read_format & PERF_FORMAT_ID)
67665 values[n++] = primary_event_id(event);
67666 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67667 * need to add enough zero bytes after the string to handle
67668 * the 64bit alignment we do later.
67669 */
67670 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67671 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67672 if (!buf) {
67673 name = strncpy(tmp, "//enomem", sizeof(tmp));
67674 goto got_name;
67675 }
67676 - name = d_path(&file->f_path, buf, PATH_MAX);
67677 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67678 if (IS_ERR(name)) {
67679 name = strncpy(tmp, "//toolong", sizeof(tmp));
67680 goto got_name;
67681 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67682 event->parent = parent_event;
67683
67684 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67685 - event->id = atomic64_inc_return(&perf_event_id);
67686 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67687
67688 event->state = PERF_EVENT_STATE_INACTIVE;
67689
67690 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67691 /*
67692 * Add back the child's count to the parent's count:
67693 */
67694 - atomic64_add(child_val, &parent_event->child_count);
67695 - atomic64_add(child_event->total_time_enabled,
67696 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67697 + atomic64_add_unchecked(child_event->total_time_enabled,
67698 &parent_event->child_total_time_enabled);
67699 - atomic64_add(child_event->total_time_running,
67700 + atomic64_add_unchecked(child_event->total_time_running,
67701 &parent_event->child_total_time_running);
67702
67703 /*
67704 diff --git a/kernel/exit.c b/kernel/exit.c
67705 index f65345f9..1423231 100644
67706 --- a/kernel/exit.c
67707 +++ b/kernel/exit.c
67708 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
67709 struct task_struct *leader;
67710 int zap_leader;
67711 repeat:
67712 +#ifdef CONFIG_NET
67713 + gr_del_task_from_ip_table(p);
67714 +#endif
67715 +
67716 /* don't need to get the RCU readlock here - the process is dead and
67717 * can't be modifying its own credentials. But shut RCU-lockdep up */
67718 rcu_read_lock();
67719 @@ -394,7 +398,7 @@ int allow_signal(int sig)
67720 * know it'll be handled, so that they don't get converted to
67721 * SIGKILL or just silently dropped.
67722 */
67723 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67724 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67725 recalc_sigpending();
67726 spin_unlock_irq(&current->sighand->siglock);
67727 return 0;
67728 @@ -430,6 +434,8 @@ void daemonize(const char *name, ...)
67729 vsnprintf(current->comm, sizeof(current->comm), name, args);
67730 va_end(args);
67731
67732 + gr_set_kernel_label(current);
67733 +
67734 /*
67735 * If we were started as result of loading a module, close all of the
67736 * user space pages. We don't need them, and if we didn't close them
67737 @@ -907,6 +913,8 @@ void do_exit(long code)
67738 struct task_struct *tsk = current;
67739 int group_dead;
67740
67741 + set_fs(USER_DS);
67742 +
67743 profile_task_exit(tsk);
67744
67745 WARN_ON(blk_needs_flush_plug(tsk));
67746 @@ -923,7 +931,6 @@ void do_exit(long code)
67747 * mm_release()->clear_child_tid() from writing to a user-controlled
67748 * kernel address.
67749 */
67750 - set_fs(USER_DS);
67751
67752 ptrace_event(PTRACE_EVENT_EXIT, code);
67753
67754 @@ -982,6 +989,9 @@ void do_exit(long code)
67755 tsk->exit_code = code;
67756 taskstats_exit(tsk, group_dead);
67757
67758 + gr_acl_handle_psacct(tsk, code);
67759 + gr_acl_handle_exit();
67760 +
67761 exit_mm(tsk);
67762
67763 if (group_dead)
67764 @@ -1099,7 +1109,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67765 * Take down every thread in the group. This is called by fatal signals
67766 * as well as by sys_exit_group (below).
67767 */
67768 -void
67769 +__noreturn void
67770 do_group_exit(int exit_code)
67771 {
67772 struct signal_struct *sig = current->signal;
67773 diff --git a/kernel/fork.c b/kernel/fork.c
67774 index 2c8857e..288c9c7 100644
67775 --- a/kernel/fork.c
67776 +++ b/kernel/fork.c
67777 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67778 *stackend = STACK_END_MAGIC; /* for overflow detection */
67779
67780 #ifdef CONFIG_CC_STACKPROTECTOR
67781 - tsk->stack_canary = get_random_int();
67782 + tsk->stack_canary = pax_get_random_long();
67783 #endif
67784
67785 /*
67786 @@ -343,13 +343,78 @@ free_tsk:
67787 }
67788
67789 #ifdef CONFIG_MMU
67790 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67791 +{
67792 + struct vm_area_struct *tmp;
67793 + unsigned long charge;
67794 + struct mempolicy *pol;
67795 + struct file *file;
67796 +
67797 + charge = 0;
67798 + if (mpnt->vm_flags & VM_ACCOUNT) {
67799 + unsigned long len = vma_pages(mpnt);
67800 +
67801 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67802 + goto fail_nomem;
67803 + charge = len;
67804 + }
67805 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67806 + if (!tmp)
67807 + goto fail_nomem;
67808 + *tmp = *mpnt;
67809 + tmp->vm_mm = mm;
67810 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67811 + pol = mpol_dup(vma_policy(mpnt));
67812 + if (IS_ERR(pol))
67813 + goto fail_nomem_policy;
67814 + vma_set_policy(tmp, pol);
67815 + if (anon_vma_fork(tmp, mpnt))
67816 + goto fail_nomem_anon_vma_fork;
67817 + tmp->vm_flags &= ~VM_LOCKED;
67818 + tmp->vm_next = tmp->vm_prev = NULL;
67819 + tmp->vm_mirror = NULL;
67820 + file = tmp->vm_file;
67821 + if (file) {
67822 + struct inode *inode = file->f_path.dentry->d_inode;
67823 + struct address_space *mapping = file->f_mapping;
67824 +
67825 + get_file(file);
67826 + if (tmp->vm_flags & VM_DENYWRITE)
67827 + atomic_dec(&inode->i_writecount);
67828 + mutex_lock(&mapping->i_mmap_mutex);
67829 + if (tmp->vm_flags & VM_SHARED)
67830 + mapping->i_mmap_writable++;
67831 + flush_dcache_mmap_lock(mapping);
67832 + /* insert tmp into the share list, just after mpnt */
67833 + vma_prio_tree_add(tmp, mpnt);
67834 + flush_dcache_mmap_unlock(mapping);
67835 + mutex_unlock(&mapping->i_mmap_mutex);
67836 + }
67837 +
67838 + /*
67839 + * Clear hugetlb-related page reserves for children. This only
67840 + * affects MAP_PRIVATE mappings. Faults generated by the child
67841 + * are not guaranteed to succeed, even if read-only
67842 + */
67843 + if (is_vm_hugetlb_page(tmp))
67844 + reset_vma_resv_huge_pages(tmp);
67845 +
67846 + return tmp;
67847 +
67848 +fail_nomem_anon_vma_fork:
67849 + mpol_put(pol);
67850 +fail_nomem_policy:
67851 + kmem_cache_free(vm_area_cachep, tmp);
67852 +fail_nomem:
67853 + vm_unacct_memory(charge);
67854 + return NULL;
67855 +}
67856 +
67857 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67858 {
67859 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67860 struct rb_node **rb_link, *rb_parent;
67861 int retval;
67862 - unsigned long charge;
67863 - struct mempolicy *pol;
67864
67865 down_write(&oldmm->mmap_sem);
67866 flush_cache_dup_mm(oldmm);
67867 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67868 mm->locked_vm = 0;
67869 mm->mmap = NULL;
67870 mm->mmap_cache = NULL;
67871 - mm->free_area_cache = oldmm->mmap_base;
67872 - mm->cached_hole_size = ~0UL;
67873 + mm->free_area_cache = oldmm->free_area_cache;
67874 + mm->cached_hole_size = oldmm->cached_hole_size;
67875 mm->map_count = 0;
67876 cpumask_clear(mm_cpumask(mm));
67877 mm->mm_rb = RB_ROOT;
67878 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67879
67880 prev = NULL;
67881 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67882 - struct file *file;
67883 -
67884 if (mpnt->vm_flags & VM_DONTCOPY) {
67885 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67886 -vma_pages(mpnt));
67887 continue;
67888 }
67889 - charge = 0;
67890 - if (mpnt->vm_flags & VM_ACCOUNT) {
67891 - unsigned long len = vma_pages(mpnt);
67892 -
67893 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67894 - goto fail_nomem;
67895 - charge = len;
67896 - }
67897 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67898 - if (!tmp)
67899 - goto fail_nomem;
67900 - *tmp = *mpnt;
67901 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67902 - pol = mpol_dup(vma_policy(mpnt));
67903 - retval = PTR_ERR(pol);
67904 - if (IS_ERR(pol))
67905 - goto fail_nomem_policy;
67906 - vma_set_policy(tmp, pol);
67907 - tmp->vm_mm = mm;
67908 - if (anon_vma_fork(tmp, mpnt))
67909 - goto fail_nomem_anon_vma_fork;
67910 - tmp->vm_flags &= ~VM_LOCKED;
67911 - tmp->vm_next = tmp->vm_prev = NULL;
67912 - file = tmp->vm_file;
67913 - if (file) {
67914 - struct inode *inode = file->f_path.dentry->d_inode;
67915 - struct address_space *mapping = file->f_mapping;
67916 -
67917 - get_file(file);
67918 - if (tmp->vm_flags & VM_DENYWRITE)
67919 - atomic_dec(&inode->i_writecount);
67920 - mutex_lock(&mapping->i_mmap_mutex);
67921 - if (tmp->vm_flags & VM_SHARED)
67922 - mapping->i_mmap_writable++;
67923 - flush_dcache_mmap_lock(mapping);
67924 - /* insert tmp into the share list, just after mpnt */
67925 - vma_prio_tree_add(tmp, mpnt);
67926 - flush_dcache_mmap_unlock(mapping);
67927 - mutex_unlock(&mapping->i_mmap_mutex);
67928 + tmp = dup_vma(mm, oldmm, mpnt);
67929 + if (!tmp) {
67930 + retval = -ENOMEM;
67931 + goto out;
67932 }
67933
67934 /*
67935 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67936 if (retval)
67937 goto out;
67938
67939 - if (file)
67940 + if (tmp->vm_file)
67941 uprobe_mmap(tmp);
67942 }
67943 +
67944 +#ifdef CONFIG_PAX_SEGMEXEC
67945 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67946 + struct vm_area_struct *mpnt_m;
67947 +
67948 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67949 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67950 +
67951 + if (!mpnt->vm_mirror)
67952 + continue;
67953 +
67954 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67955 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67956 + mpnt->vm_mirror = mpnt_m;
67957 + } else {
67958 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67959 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67960 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67961 + mpnt->vm_mirror->vm_mirror = mpnt;
67962 + }
67963 + }
67964 + BUG_ON(mpnt_m);
67965 + }
67966 +#endif
67967 +
67968 /* a new mm has just been created */
67969 arch_dup_mmap(oldmm, mm);
67970 retval = 0;
67971 @@ -466,14 +519,6 @@ out:
67972 flush_tlb_mm(oldmm);
67973 up_write(&oldmm->mmap_sem);
67974 return retval;
67975 -fail_nomem_anon_vma_fork:
67976 - mpol_put(pol);
67977 -fail_nomem_policy:
67978 - kmem_cache_free(vm_area_cachep, tmp);
67979 -fail_nomem:
67980 - retval = -ENOMEM;
67981 - vm_unacct_memory(charge);
67982 - goto out;
67983 }
67984
67985 static inline int mm_alloc_pgd(struct mm_struct *mm)
67986 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67987 return ERR_PTR(err);
67988
67989 mm = get_task_mm(task);
67990 - if (mm && mm != current->mm &&
67991 - !ptrace_may_access(task, mode)) {
67992 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67993 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67994 mmput(mm);
67995 mm = ERR_PTR(-EACCES);
67996 }
67997 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67998 spin_unlock(&fs->lock);
67999 return -EAGAIN;
68000 }
68001 - fs->users++;
68002 + atomic_inc(&fs->users);
68003 spin_unlock(&fs->lock);
68004 return 0;
68005 }
68006 tsk->fs = copy_fs_struct(fs);
68007 if (!tsk->fs)
68008 return -ENOMEM;
68009 + /* Carry through gr_chroot_dentry and is_chrooted instead
68010 + of recomputing it here. Already copied when the task struct
68011 + is duplicated. This allows pivot_root to not be treated as
68012 + a chroot
68013 + */
68014 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
68015 +
68016 return 0;
68017 }
68018
68019 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
68020 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
68021 #endif
68022 retval = -EAGAIN;
68023 +
68024 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
68025 +
68026 if (atomic_read(&p->real_cred->user->processes) >=
68027 task_rlimit(p, RLIMIT_NPROC)) {
68028 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
68029 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
68030 /* Need tasklist lock for parent etc handling! */
68031 write_lock_irq(&tasklist_lock);
68032
68033 + /* synchronizes with gr_set_acls() */
68034 + gr_copy_label(p);
68035 +
68036 /* CLONE_PARENT re-uses the old parent */
68037 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
68038 p->real_parent = current->real_parent;
68039 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
68040 bad_fork_free:
68041 free_task(p);
68042 fork_out:
68043 + gr_log_forkfail(retval);
68044 +
68045 return ERR_PTR(retval);
68046 }
68047
68048 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
68049 if (clone_flags & CLONE_PARENT_SETTID)
68050 put_user(nr, parent_tidptr);
68051
68052 + gr_handle_brute_check();
68053 +
68054 if (clone_flags & CLONE_VFORK) {
68055 p->vfork_done = &vfork;
68056 init_completion(&vfork);
68057 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
68058 return 0;
68059
68060 /* don't need lock here; in the worst case we'll do useless copy */
68061 - if (fs->users == 1)
68062 + if (atomic_read(&fs->users) == 1)
68063 return 0;
68064
68065 *new_fsp = copy_fs_struct(fs);
68066 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
68067 fs = current->fs;
68068 spin_lock(&fs->lock);
68069 current->fs = new_fs;
68070 - if (--fs->users)
68071 + gr_set_chroot_entries(current, &current->fs->root);
68072 + if (atomic_dec_return(&fs->users))
68073 new_fs = NULL;
68074 else
68075 new_fs = fs;
68076 diff --git a/kernel/futex.c b/kernel/futex.c
68077 index 20ef219..b3a0cb2 100644
68078 --- a/kernel/futex.c
68079 +++ b/kernel/futex.c
68080 @@ -54,6 +54,7 @@
68081 #include <linux/mount.h>
68082 #include <linux/pagemap.h>
68083 #include <linux/syscalls.h>
68084 +#include <linux/ptrace.h>
68085 #include <linux/signal.h>
68086 #include <linux/export.h>
68087 #include <linux/magic.h>
68088 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
68089 struct page *page, *page_head;
68090 int err, ro = 0;
68091
68092 +#ifdef CONFIG_PAX_SEGMEXEC
68093 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
68094 + return -EFAULT;
68095 +#endif
68096 +
68097 /*
68098 * The futex address must be "naturally" aligned.
68099 */
68100 @@ -2717,6 +2723,7 @@ static int __init futex_init(void)
68101 {
68102 u32 curval;
68103 int i;
68104 + mm_segment_t oldfs;
68105
68106 /*
68107 * This will fail and we want it. Some arch implementations do
68108 @@ -2728,8 +2735,11 @@ static int __init futex_init(void)
68109 * implementation, the non-functional ones will return
68110 * -ENOSYS.
68111 */
68112 + oldfs = get_fs();
68113 + set_fs(USER_DS);
68114 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
68115 futex_cmpxchg_enabled = 1;
68116 + set_fs(oldfs);
68117
68118 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
68119 plist_head_init(&futex_queues[i].chain);
68120 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
68121 index 9b22d03..6295b62 100644
68122 --- a/kernel/gcov/base.c
68123 +++ b/kernel/gcov/base.c
68124 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
68125 }
68126
68127 #ifdef CONFIG_MODULES
68128 -static inline int within(void *addr, void *start, unsigned long size)
68129 -{
68130 - return ((addr >= start) && (addr < start + size));
68131 -}
68132 -
68133 /* Update list and generate events when modules are unloaded. */
68134 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
68135 void *data)
68136 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
68137 prev = NULL;
68138 /* Remove entries located in module from linked list. */
68139 for (info = gcov_info_head; info; info = info->next) {
68140 - if (within(info, mod->module_core, mod->core_size)) {
68141 + if (within_module_core_rw((unsigned long)info, mod)) {
68142 if (prev)
68143 prev->next = info->next;
68144 else
68145 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
68146 index 6db7a5e..25b6648 100644
68147 --- a/kernel/hrtimer.c
68148 +++ b/kernel/hrtimer.c
68149 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
68150 local_irq_restore(flags);
68151 }
68152
68153 -static void run_hrtimer_softirq(struct softirq_action *h)
68154 +static void run_hrtimer_softirq(void)
68155 {
68156 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
68157
68158 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
68159 index 4304919..408c4c0 100644
68160 --- a/kernel/jump_label.c
68161 +++ b/kernel/jump_label.c
68162 @@ -13,6 +13,7 @@
68163 #include <linux/sort.h>
68164 #include <linux/err.h>
68165 #include <linux/static_key.h>
68166 +#include <linux/mm.h>
68167
68168 #ifdef HAVE_JUMP_LABEL
68169
68170 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
68171
68172 size = (((unsigned long)stop - (unsigned long)start)
68173 / sizeof(struct jump_entry));
68174 + pax_open_kernel();
68175 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
68176 + pax_close_kernel();
68177 }
68178
68179 static void jump_label_update(struct static_key *key, int enable);
68180 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
68181 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
68182 struct jump_entry *iter;
68183
68184 + pax_open_kernel();
68185 for (iter = iter_start; iter < iter_stop; iter++) {
68186 if (within_module_init(iter->code, mod))
68187 iter->code = 0;
68188 }
68189 + pax_close_kernel();
68190 }
68191
68192 static int
68193 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
68194 index 2169fee..45c017a 100644
68195 --- a/kernel/kallsyms.c
68196 +++ b/kernel/kallsyms.c
68197 @@ -11,6 +11,9 @@
68198 * Changed the compression method from stem compression to "table lookup"
68199 * compression (see scripts/kallsyms.c for a more complete description)
68200 */
68201 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68202 +#define __INCLUDED_BY_HIDESYM 1
68203 +#endif
68204 #include <linux/kallsyms.h>
68205 #include <linux/module.h>
68206 #include <linux/init.h>
68207 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
68208
68209 static inline int is_kernel_inittext(unsigned long addr)
68210 {
68211 + if (system_state != SYSTEM_BOOTING)
68212 + return 0;
68213 +
68214 if (addr >= (unsigned long)_sinittext
68215 && addr <= (unsigned long)_einittext)
68216 return 1;
68217 return 0;
68218 }
68219
68220 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68221 +#ifdef CONFIG_MODULES
68222 +static inline int is_module_text(unsigned long addr)
68223 +{
68224 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
68225 + return 1;
68226 +
68227 + addr = ktla_ktva(addr);
68228 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
68229 +}
68230 +#else
68231 +static inline int is_module_text(unsigned long addr)
68232 +{
68233 + return 0;
68234 +}
68235 +#endif
68236 +#endif
68237 +
68238 static inline int is_kernel_text(unsigned long addr)
68239 {
68240 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
68241 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
68242
68243 static inline int is_kernel(unsigned long addr)
68244 {
68245 +
68246 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68247 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
68248 + return 1;
68249 +
68250 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
68251 +#else
68252 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
68253 +#endif
68254 +
68255 return 1;
68256 return in_gate_area_no_mm(addr);
68257 }
68258
68259 static int is_ksym_addr(unsigned long addr)
68260 {
68261 +
68262 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68263 + if (is_module_text(addr))
68264 + return 0;
68265 +#endif
68266 +
68267 if (all_var)
68268 return is_kernel(addr);
68269
68270 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
68271
68272 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
68273 {
68274 - iter->name[0] = '\0';
68275 iter->nameoff = get_symbol_offset(new_pos);
68276 iter->pos = new_pos;
68277 }
68278 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
68279 {
68280 struct kallsym_iter *iter = m->private;
68281
68282 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68283 + if (current_uid())
68284 + return 0;
68285 +#endif
68286 +
68287 /* Some debugging symbols have no name. Ignore them. */
68288 if (!iter->name[0])
68289 return 0;
68290 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
68291 */
68292 type = iter->exported ? toupper(iter->type) :
68293 tolower(iter->type);
68294 +
68295 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
68296 type, iter->name, iter->module_name);
68297 } else
68298 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
68299 struct kallsym_iter *iter;
68300 int ret;
68301
68302 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
68303 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
68304 if (!iter)
68305 return -ENOMEM;
68306 reset_iter(iter, 0);
68307 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
68308 index 30b7b22..c726387 100644
68309 --- a/kernel/kcmp.c
68310 +++ b/kernel/kcmp.c
68311 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
68312 struct task_struct *task1, *task2;
68313 int ret;
68314
68315 +#ifdef CONFIG_GRKERNSEC
68316 + return -ENOSYS;
68317 +#endif
68318 +
68319 rcu_read_lock();
68320
68321 /*
68322 diff --git a/kernel/kexec.c b/kernel/kexec.c
68323 index 0668d58..591b6fc 100644
68324 --- a/kernel/kexec.c
68325 +++ b/kernel/kexec.c
68326 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
68327 unsigned long flags)
68328 {
68329 struct compat_kexec_segment in;
68330 - struct kexec_segment out, __user *ksegments;
68331 + struct kexec_segment out;
68332 + struct kexec_segment __user *ksegments;
68333 unsigned long i, result;
68334
68335 /* Don't allow clients that don't understand the native
68336 diff --git a/kernel/kmod.c b/kernel/kmod.c
68337 index 6f99aea..eb6e3a0 100644
68338 --- a/kernel/kmod.c
68339 +++ b/kernel/kmod.c
68340 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
68341 kfree(info->argv);
68342 }
68343
68344 -static int call_modprobe(char *module_name, int wait)
68345 +static int call_modprobe(char *module_name, char *module_param, int wait)
68346 {
68347 static char *envp[] = {
68348 "HOME=/",
68349 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
68350 NULL
68351 };
68352
68353 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
68354 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
68355 if (!argv)
68356 goto out;
68357
68358 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
68359 argv[1] = "-q";
68360 argv[2] = "--";
68361 argv[3] = module_name; /* check free_modprobe_argv() */
68362 - argv[4] = NULL;
68363 + argv[4] = module_param;
68364 + argv[5] = NULL;
68365
68366 return call_usermodehelper_fns(modprobe_path, argv, envp,
68367 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
68368 @@ -119,9 +120,8 @@ out:
68369 * If module auto-loading support is disabled then this function
68370 * becomes a no-operation.
68371 */
68372 -int __request_module(bool wait, const char *fmt, ...)
68373 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
68374 {
68375 - va_list args;
68376 char module_name[MODULE_NAME_LEN];
68377 unsigned int max_modprobes;
68378 int ret;
68379 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
68380 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
68381 static int kmod_loop_msg;
68382
68383 - va_start(args, fmt);
68384 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
68385 - va_end(args);
68386 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
68387 if (ret >= MODULE_NAME_LEN)
68388 return -ENAMETOOLONG;
68389
68390 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
68391 if (ret)
68392 return ret;
68393
68394 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68395 + if (!current_uid()) {
68396 + /* hack to workaround consolekit/udisks stupidity */
68397 + read_lock(&tasklist_lock);
68398 + if (!strcmp(current->comm, "mount") &&
68399 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
68400 + read_unlock(&tasklist_lock);
68401 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
68402 + return -EPERM;
68403 + }
68404 + read_unlock(&tasklist_lock);
68405 + }
68406 +#endif
68407 +
68408 /* If modprobe needs a service that is in a module, we get a recursive
68409 * loop. Limit the number of running kmod threads to max_threads/2 or
68410 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
68411 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
68412
68413 trace_module_request(module_name, wait, _RET_IP_);
68414
68415 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68416 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68417
68418 atomic_dec(&kmod_concurrent);
68419 return ret;
68420 }
68421 +
68422 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68423 +{
68424 + va_list args;
68425 + int ret;
68426 +
68427 + va_start(args, fmt);
68428 + ret = ____request_module(wait, module_param, fmt, args);
68429 + va_end(args);
68430 +
68431 + return ret;
68432 +}
68433 +
68434 +int __request_module(bool wait, const char *fmt, ...)
68435 +{
68436 + va_list args;
68437 + int ret;
68438 +
68439 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68440 + if (current_uid()) {
68441 + char module_param[MODULE_NAME_LEN];
68442 +
68443 + memset(module_param, 0, sizeof(module_param));
68444 +
68445 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68446 +
68447 + va_start(args, fmt);
68448 + ret = ____request_module(wait, module_param, fmt, args);
68449 + va_end(args);
68450 +
68451 + return ret;
68452 + }
68453 +#endif
68454 +
68455 + va_start(args, fmt);
68456 + ret = ____request_module(wait, NULL, fmt, args);
68457 + va_end(args);
68458 +
68459 + return ret;
68460 +}
68461 +
68462 EXPORT_SYMBOL(__request_module);
68463 #endif /* CONFIG_MODULES */
68464
68465 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
68466 *
68467 * Thus the __user pointer cast is valid here.
68468 */
68469 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
68470 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68471
68472 /*
68473 * If ret is 0, either ____call_usermodehelper failed and the
68474 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68475 index c62b854..6fc810d 100644
68476 --- a/kernel/kprobes.c
68477 +++ b/kernel/kprobes.c
68478 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68479 * kernel image and loaded module images reside. This is required
68480 * so x86_64 can correctly handle the %rip-relative fixups.
68481 */
68482 - kip->insns = module_alloc(PAGE_SIZE);
68483 + kip->insns = module_alloc_exec(PAGE_SIZE);
68484 if (!kip->insns) {
68485 kfree(kip);
68486 return NULL;
68487 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68488 */
68489 if (!list_is_singular(&kip->list)) {
68490 list_del(&kip->list);
68491 - module_free(NULL, kip->insns);
68492 + module_free_exec(NULL, kip->insns);
68493 kfree(kip);
68494 }
68495 return 1;
68496 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
68497 {
68498 int i, err = 0;
68499 unsigned long offset = 0, size = 0;
68500 - char *modname, namebuf[128];
68501 + char *modname, namebuf[KSYM_NAME_LEN];
68502 const char *symbol_name;
68503 void *addr;
68504 struct kprobe_blackpoint *kb;
68505 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68506 kprobe_type = "k";
68507
68508 if (sym)
68509 - seq_printf(pi, "%p %s %s+0x%x %s ",
68510 + seq_printf(pi, "%pK %s %s+0x%x %s ",
68511 p->addr, kprobe_type, sym, offset,
68512 (modname ? modname : " "));
68513 else
68514 - seq_printf(pi, "%p %s %p ",
68515 + seq_printf(pi, "%pK %s %pK ",
68516 p->addr, kprobe_type, p->addr);
68517
68518 if (!pp)
68519 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68520 const char *sym = NULL;
68521 unsigned int i = *(loff_t *) v;
68522 unsigned long offset = 0;
68523 - char *modname, namebuf[128];
68524 + char *modname, namebuf[KSYM_NAME_LEN];
68525
68526 head = &kprobe_table[i];
68527 preempt_disable();
68528 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68529 index 4e316e1..5501eef 100644
68530 --- a/kernel/ksysfs.c
68531 +++ b/kernel/ksysfs.c
68532 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68533 {
68534 if (count+1 > UEVENT_HELPER_PATH_LEN)
68535 return -ENOENT;
68536 + if (!capable(CAP_SYS_ADMIN))
68537 + return -EPERM;
68538 memcpy(uevent_helper, buf, count);
68539 uevent_helper[count] = '\0';
68540 if (count && uevent_helper[count-1] == '\n')
68541 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68542 index ea9ee45..67ebc8f 100644
68543 --- a/kernel/lockdep.c
68544 +++ b/kernel/lockdep.c
68545 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
68546 end = (unsigned long) &_end,
68547 addr = (unsigned long) obj;
68548
68549 +#ifdef CONFIG_PAX_KERNEXEC
68550 + start = ktla_ktva(start);
68551 +#endif
68552 +
68553 /*
68554 * static variable?
68555 */
68556 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68557 if (!static_obj(lock->key)) {
68558 debug_locks_off();
68559 printk("INFO: trying to register non-static key.\n");
68560 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68561 printk("the code is fine but needs lockdep annotation.\n");
68562 printk("turning off the locking correctness validator.\n");
68563 dump_stack();
68564 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68565 if (!class)
68566 return 0;
68567 }
68568 - atomic_inc((atomic_t *)&class->ops);
68569 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68570 if (very_verbose(class)) {
68571 printk("\nacquire class [%p] %s", class->key, class->name);
68572 if (class->name_version > 1)
68573 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68574 index 91c32a0..7b88d63 100644
68575 --- a/kernel/lockdep_proc.c
68576 +++ b/kernel/lockdep_proc.c
68577 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68578
68579 static void print_name(struct seq_file *m, struct lock_class *class)
68580 {
68581 - char str[128];
68582 + char str[KSYM_NAME_LEN];
68583 const char *name = class->name;
68584
68585 if (!name) {
68586 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68587 return 0;
68588 }
68589
68590 - seq_printf(m, "%p", class->key);
68591 + seq_printf(m, "%pK", class->key);
68592 #ifdef CONFIG_DEBUG_LOCKDEP
68593 seq_printf(m, " OPS:%8ld", class->ops);
68594 #endif
68595 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68596
68597 list_for_each_entry(entry, &class->locks_after, entry) {
68598 if (entry->distance == 1) {
68599 - seq_printf(m, " -> [%p] ", entry->class->key);
68600 + seq_printf(m, " -> [%pK] ", entry->class->key);
68601 print_name(m, entry->class);
68602 seq_puts(m, "\n");
68603 }
68604 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68605 if (!class->key)
68606 continue;
68607
68608 - seq_printf(m, "[%p] ", class->key);
68609 + seq_printf(m, "[%pK] ", class->key);
68610 print_name(m, class);
68611 seq_puts(m, "\n");
68612 }
68613 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68614 if (!i)
68615 seq_line(m, '-', 40-namelen, namelen);
68616
68617 - snprintf(ip, sizeof(ip), "[<%p>]",
68618 + snprintf(ip, sizeof(ip), "[<%pK>]",
68619 (void *)class->contention_point[i]);
68620 seq_printf(m, "%40s %14lu %29s %pS\n",
68621 name, stats->contention_point[i],
68622 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68623 if (!i)
68624 seq_line(m, '-', 40-namelen, namelen);
68625
68626 - snprintf(ip, sizeof(ip), "[<%p>]",
68627 + snprintf(ip, sizeof(ip), "[<%pK>]",
68628 (void *)class->contending_point[i]);
68629 seq_printf(m, "%40s %14lu %29s %pS\n",
68630 name, stats->contending_point[i],
68631 diff --git a/kernel/module.c b/kernel/module.c
68632 index 9ad9ee9..731c128 100644
68633 --- a/kernel/module.c
68634 +++ b/kernel/module.c
68635 @@ -58,6 +58,7 @@
68636 #include <linux/jump_label.h>
68637 #include <linux/pfn.h>
68638 #include <linux/bsearch.h>
68639 +#include <linux/grsecurity.h>
68640
68641 #define CREATE_TRACE_POINTS
68642 #include <trace/events/module.h>
68643 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68644
68645 /* Bounds of module allocation, for speeding __module_address.
68646 * Protected by module_mutex. */
68647 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68648 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68649 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68650
68651 int register_module_notifier(struct notifier_block * nb)
68652 {
68653 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68654 return true;
68655
68656 list_for_each_entry_rcu(mod, &modules, list) {
68657 - struct symsearch arr[] = {
68658 + struct symsearch modarr[] = {
68659 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68660 NOT_GPL_ONLY, false },
68661 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68662 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68663 #endif
68664 };
68665
68666 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68667 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68668 return true;
68669 }
68670 return false;
68671 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68672 static int percpu_modalloc(struct module *mod,
68673 unsigned long size, unsigned long align)
68674 {
68675 - if (align > PAGE_SIZE) {
68676 + if (align-1 >= PAGE_SIZE) {
68677 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68678 mod->name, align, PAGE_SIZE);
68679 align = PAGE_SIZE;
68680 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68681 static ssize_t show_coresize(struct module_attribute *mattr,
68682 struct module_kobject *mk, char *buffer)
68683 {
68684 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68685 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68686 }
68687
68688 static struct module_attribute modinfo_coresize =
68689 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68690 static ssize_t show_initsize(struct module_attribute *mattr,
68691 struct module_kobject *mk, char *buffer)
68692 {
68693 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68694 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68695 }
68696
68697 static struct module_attribute modinfo_initsize =
68698 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68699 */
68700 #ifdef CONFIG_SYSFS
68701
68702 -#ifdef CONFIG_KALLSYMS
68703 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68704 static inline bool sect_empty(const Elf_Shdr *sect)
68705 {
68706 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68707 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68708
68709 static void unset_module_core_ro_nx(struct module *mod)
68710 {
68711 - set_page_attributes(mod->module_core + mod->core_text_size,
68712 - mod->module_core + mod->core_size,
68713 + set_page_attributes(mod->module_core_rw,
68714 + mod->module_core_rw + mod->core_size_rw,
68715 set_memory_x);
68716 - set_page_attributes(mod->module_core,
68717 - mod->module_core + mod->core_ro_size,
68718 + set_page_attributes(mod->module_core_rx,
68719 + mod->module_core_rx + mod->core_size_rx,
68720 set_memory_rw);
68721 }
68722
68723 static void unset_module_init_ro_nx(struct module *mod)
68724 {
68725 - set_page_attributes(mod->module_init + mod->init_text_size,
68726 - mod->module_init + mod->init_size,
68727 + set_page_attributes(mod->module_init_rw,
68728 + mod->module_init_rw + mod->init_size_rw,
68729 set_memory_x);
68730 - set_page_attributes(mod->module_init,
68731 - mod->module_init + mod->init_ro_size,
68732 + set_page_attributes(mod->module_init_rx,
68733 + mod->module_init_rx + mod->init_size_rx,
68734 set_memory_rw);
68735 }
68736
68737 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68738
68739 mutex_lock(&module_mutex);
68740 list_for_each_entry_rcu(mod, &modules, list) {
68741 - if ((mod->module_core) && (mod->core_text_size)) {
68742 - set_page_attributes(mod->module_core,
68743 - mod->module_core + mod->core_text_size,
68744 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68745 + set_page_attributes(mod->module_core_rx,
68746 + mod->module_core_rx + mod->core_size_rx,
68747 set_memory_rw);
68748 }
68749 - if ((mod->module_init) && (mod->init_text_size)) {
68750 - set_page_attributes(mod->module_init,
68751 - mod->module_init + mod->init_text_size,
68752 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68753 + set_page_attributes(mod->module_init_rx,
68754 + mod->module_init_rx + mod->init_size_rx,
68755 set_memory_rw);
68756 }
68757 }
68758 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68759
68760 mutex_lock(&module_mutex);
68761 list_for_each_entry_rcu(mod, &modules, list) {
68762 - if ((mod->module_core) && (mod->core_text_size)) {
68763 - set_page_attributes(mod->module_core,
68764 - mod->module_core + mod->core_text_size,
68765 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68766 + set_page_attributes(mod->module_core_rx,
68767 + mod->module_core_rx + mod->core_size_rx,
68768 set_memory_ro);
68769 }
68770 - if ((mod->module_init) && (mod->init_text_size)) {
68771 - set_page_attributes(mod->module_init,
68772 - mod->module_init + mod->init_text_size,
68773 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68774 + set_page_attributes(mod->module_init_rx,
68775 + mod->module_init_rx + mod->init_size_rx,
68776 set_memory_ro);
68777 }
68778 }
68779 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68780
68781 /* This may be NULL, but that's OK */
68782 unset_module_init_ro_nx(mod);
68783 - module_free(mod, mod->module_init);
68784 + module_free(mod, mod->module_init_rw);
68785 + module_free_exec(mod, mod->module_init_rx);
68786 kfree(mod->args);
68787 percpu_modfree(mod);
68788
68789 /* Free lock-classes: */
68790 - lockdep_free_key_range(mod->module_core, mod->core_size);
68791 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68792 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68793
68794 /* Finally, free the core (containing the module structure) */
68795 unset_module_core_ro_nx(mod);
68796 - module_free(mod, mod->module_core);
68797 + module_free_exec(mod, mod->module_core_rx);
68798 + module_free(mod, mod->module_core_rw);
68799
68800 #ifdef CONFIG_MPU
68801 update_protections(current->mm);
68802 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68803 int ret = 0;
68804 const struct kernel_symbol *ksym;
68805
68806 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68807 + int is_fs_load = 0;
68808 + int register_filesystem_found = 0;
68809 + char *p;
68810 +
68811 + p = strstr(mod->args, "grsec_modharden_fs");
68812 + if (p) {
68813 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
68814 + /* copy \0 as well */
68815 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68816 + is_fs_load = 1;
68817 + }
68818 +#endif
68819 +
68820 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68821 const char *name = info->strtab + sym[i].st_name;
68822
68823 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68824 + /* it's a real shame this will never get ripped and copied
68825 + upstream! ;(
68826 + */
68827 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68828 + register_filesystem_found = 1;
68829 +#endif
68830 +
68831 switch (sym[i].st_shndx) {
68832 case SHN_COMMON:
68833 /* We compiled with -fno-common. These are not
68834 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68835 ksym = resolve_symbol_wait(mod, info, name);
68836 /* Ok if resolved. */
68837 if (ksym && !IS_ERR(ksym)) {
68838 + pax_open_kernel();
68839 sym[i].st_value = ksym->value;
68840 + pax_close_kernel();
68841 break;
68842 }
68843
68844 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68845 secbase = (unsigned long)mod_percpu(mod);
68846 else
68847 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68848 + pax_open_kernel();
68849 sym[i].st_value += secbase;
68850 + pax_close_kernel();
68851 break;
68852 }
68853 }
68854
68855 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68856 + if (is_fs_load && !register_filesystem_found) {
68857 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68858 + ret = -EPERM;
68859 + }
68860 +#endif
68861 +
68862 return ret;
68863 }
68864
68865 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68866 || s->sh_entsize != ~0UL
68867 || strstarts(sname, ".init"))
68868 continue;
68869 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68870 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68871 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68872 + else
68873 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68874 pr_debug("\t%s\n", sname);
68875 }
68876 - switch (m) {
68877 - case 0: /* executable */
68878 - mod->core_size = debug_align(mod->core_size);
68879 - mod->core_text_size = mod->core_size;
68880 - break;
68881 - case 1: /* RO: text and ro-data */
68882 - mod->core_size = debug_align(mod->core_size);
68883 - mod->core_ro_size = mod->core_size;
68884 - break;
68885 - case 3: /* whole core */
68886 - mod->core_size = debug_align(mod->core_size);
68887 - break;
68888 - }
68889 }
68890
68891 pr_debug("Init section allocation order:\n");
68892 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68893 || s->sh_entsize != ~0UL
68894 || !strstarts(sname, ".init"))
68895 continue;
68896 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68897 - | INIT_OFFSET_MASK);
68898 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68899 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68900 + else
68901 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68902 + s->sh_entsize |= INIT_OFFSET_MASK;
68903 pr_debug("\t%s\n", sname);
68904 }
68905 - switch (m) {
68906 - case 0: /* executable */
68907 - mod->init_size = debug_align(mod->init_size);
68908 - mod->init_text_size = mod->init_size;
68909 - break;
68910 - case 1: /* RO: text and ro-data */
68911 - mod->init_size = debug_align(mod->init_size);
68912 - mod->init_ro_size = mod->init_size;
68913 - break;
68914 - case 3: /* whole init */
68915 - mod->init_size = debug_align(mod->init_size);
68916 - break;
68917 - }
68918 }
68919 }
68920
68921 @@ -2266,28 +2284,33 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68922
68923 /* Put symbol section at end of init part of module. */
68924 symsect->sh_flags |= SHF_ALLOC;
68925 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68926 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68927 info->index.sym) | INIT_OFFSET_MASK;
68928 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68929
68930 src = (void *)info->hdr + symsect->sh_offset;
68931 nsrc = symsect->sh_size / sizeof(*src);
68932
68933 + /* strtab always starts with a nul, so offset 0 is the empty string. */
68934 + strtab_size = 1;
68935 +
68936 /* Compute total space required for the core symbols' strtab. */
68937 - for (ndst = i = strtab_size = 1; i < nsrc; ++i, ++src)
68938 - if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) {
68939 - strtab_size += strlen(&info->strtab[src->st_name]) + 1;
68940 + for (ndst = i = 0; i < nsrc; i++) {
68941 + if (i == 0 ||
68942 + is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
68943 + strtab_size += strlen(&info->strtab[src[i].st_name])+1;
68944 ndst++;
68945 }
68946 + }
68947
68948 /* Append room for core symbols at end of core part. */
68949 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68950 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68951 - mod->core_size += strtab_size;
68952 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68953 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68954 + mod->core_size_rx += strtab_size;
68955
68956 /* Put string table section at end of init part of module. */
68957 strsect->sh_flags |= SHF_ALLOC;
68958 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68959 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68960 info->index.str) | INIT_OFFSET_MASK;
68961 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68962 }
68963 @@ -2305,24 +2328,28 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68964 /* Make sure we get permanent strtab: don't use info->strtab. */
68965 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68966
68967 + pax_open_kernel();
68968 +
68969 /* Set types up while we still have access to sections. */
68970 for (i = 0; i < mod->num_symtab; i++)
68971 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68972
68973 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68974 - mod->core_strtab = s = mod->module_core + info->stroffs;
68975 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68976 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68977 src = mod->symtab;
68978 - *dst = *src;
68979 *s++ = 0;
68980 - for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
68981 - if (!is_core_symbol(src, info->sechdrs, info->hdr->e_shnum))
68982 - continue;
68983 -
68984 - dst[ndst] = *src;
68985 - dst[ndst++].st_name = s - mod->core_strtab;
68986 - s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68987 + for (ndst = i = 0; i < mod->num_symtab; i++) {
68988 + if (i == 0 ||
68989 + is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
68990 + dst[ndst] = src[i];
68991 + dst[ndst++].st_name = s - mod->core_strtab;
68992 + s += strlcpy(s, &mod->strtab[src[i].st_name],
68993 + KSYM_NAME_LEN) + 1;
68994 + }
68995 }
68996 mod->core_num_syms = ndst;
68997 +
68998 + pax_close_kernel();
68999 }
69000 #else
69001 static inline void layout_symtab(struct module *mod, struct load_info *info)
69002 @@ -2356,17 +2383,33 @@ void * __weak module_alloc(unsigned long size)
69003 return size == 0 ? NULL : vmalloc_exec(size);
69004 }
69005
69006 -static void *module_alloc_update_bounds(unsigned long size)
69007 +static void *module_alloc_update_bounds_rw(unsigned long size)
69008 {
69009 void *ret = module_alloc(size);
69010
69011 if (ret) {
69012 mutex_lock(&module_mutex);
69013 /* Update module bounds. */
69014 - if ((unsigned long)ret < module_addr_min)
69015 - module_addr_min = (unsigned long)ret;
69016 - if ((unsigned long)ret + size > module_addr_max)
69017 - module_addr_max = (unsigned long)ret + size;
69018 + if ((unsigned long)ret < module_addr_min_rw)
69019 + module_addr_min_rw = (unsigned long)ret;
69020 + if ((unsigned long)ret + size > module_addr_max_rw)
69021 + module_addr_max_rw = (unsigned long)ret + size;
69022 + mutex_unlock(&module_mutex);
69023 + }
69024 + return ret;
69025 +}
69026 +
69027 +static void *module_alloc_update_bounds_rx(unsigned long size)
69028 +{
69029 + void *ret = module_alloc_exec(size);
69030 +
69031 + if (ret) {
69032 + mutex_lock(&module_mutex);
69033 + /* Update module bounds. */
69034 + if ((unsigned long)ret < module_addr_min_rx)
69035 + module_addr_min_rx = (unsigned long)ret;
69036 + if ((unsigned long)ret + size > module_addr_max_rx)
69037 + module_addr_max_rx = (unsigned long)ret + size;
69038 mutex_unlock(&module_mutex);
69039 }
69040 return ret;
69041 @@ -2544,8 +2587,14 @@ static struct module *setup_load_info(struct load_info *info)
69042 static int check_modinfo(struct module *mod, struct load_info *info)
69043 {
69044 const char *modmagic = get_modinfo(info, "vermagic");
69045 + const char *license = get_modinfo(info, "license");
69046 int err;
69047
69048 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
69049 + if (!license || !license_is_gpl_compatible(license))
69050 + return -ENOEXEC;
69051 +#endif
69052 +
69053 /* This is allowed: modprobe --force will invalidate it. */
69054 if (!modmagic) {
69055 err = try_to_force_load(mod, "bad vermagic");
69056 @@ -2568,7 +2617,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
69057 }
69058
69059 /* Set up license info based on the info section */
69060 - set_license(mod, get_modinfo(info, "license"));
69061 + set_license(mod, license);
69062
69063 return 0;
69064 }
69065 @@ -2662,7 +2711,7 @@ static int move_module(struct module *mod, struct load_info *info)
69066 void *ptr;
69067
69068 /* Do the allocs. */
69069 - ptr = module_alloc_update_bounds(mod->core_size);
69070 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
69071 /*
69072 * The pointer to this block is stored in the module structure
69073 * which is inside the block. Just mark it as not being a
69074 @@ -2672,23 +2721,50 @@ static int move_module(struct module *mod, struct load_info *info)
69075 if (!ptr)
69076 return -ENOMEM;
69077
69078 - memset(ptr, 0, mod->core_size);
69079 - mod->module_core = ptr;
69080 + memset(ptr, 0, mod->core_size_rw);
69081 + mod->module_core_rw = ptr;
69082
69083 - ptr = module_alloc_update_bounds(mod->init_size);
69084 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
69085 /*
69086 * The pointer to this block is stored in the module structure
69087 * which is inside the block. This block doesn't need to be
69088 * scanned as it contains data and code that will be freed
69089 * after the module is initialized.
69090 */
69091 - kmemleak_ignore(ptr);
69092 - if (!ptr && mod->init_size) {
69093 - module_free(mod, mod->module_core);
69094 + kmemleak_not_leak(ptr);
69095 + if (!ptr && mod->init_size_rw) {
69096 + module_free(mod, mod->module_core_rw);
69097 return -ENOMEM;
69098 }
69099 - memset(ptr, 0, mod->init_size);
69100 - mod->module_init = ptr;
69101 + memset(ptr, 0, mod->init_size_rw);
69102 + mod->module_init_rw = ptr;
69103 +
69104 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
69105 + kmemleak_not_leak(ptr);
69106 + if (!ptr) {
69107 + module_free(mod, mod->module_init_rw);
69108 + module_free(mod, mod->module_core_rw);
69109 + return -ENOMEM;
69110 + }
69111 +
69112 + pax_open_kernel();
69113 + memset(ptr, 0, mod->core_size_rx);
69114 + pax_close_kernel();
69115 + mod->module_core_rx = ptr;
69116 +
69117 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
69118 + kmemleak_not_leak(ptr);
69119 + if (!ptr && mod->init_size_rx) {
69120 + module_free_exec(mod, mod->module_core_rx);
69121 + module_free(mod, mod->module_init_rw);
69122 + module_free(mod, mod->module_core_rw);
69123 + return -ENOMEM;
69124 + }
69125 +
69126 + pax_open_kernel();
69127 + memset(ptr, 0, mod->init_size_rx);
69128 + pax_close_kernel();
69129 + mod->module_init_rx = ptr;
69130
69131 /* Transfer each section which specifies SHF_ALLOC */
69132 pr_debug("final section addresses:\n");
69133 @@ -2699,16 +2775,45 @@ static int move_module(struct module *mod, struct load_info *info)
69134 if (!(shdr->sh_flags & SHF_ALLOC))
69135 continue;
69136
69137 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
69138 - dest = mod->module_init
69139 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69140 - else
69141 - dest = mod->module_core + shdr->sh_entsize;
69142 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
69143 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
69144 + dest = mod->module_init_rw
69145 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69146 + else
69147 + dest = mod->module_init_rx
69148 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69149 + } else {
69150 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
69151 + dest = mod->module_core_rw + shdr->sh_entsize;
69152 + else
69153 + dest = mod->module_core_rx + shdr->sh_entsize;
69154 + }
69155 +
69156 + if (shdr->sh_type != SHT_NOBITS) {
69157 +
69158 +#ifdef CONFIG_PAX_KERNEXEC
69159 +#ifdef CONFIG_X86_64
69160 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
69161 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
69162 +#endif
69163 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
69164 + pax_open_kernel();
69165 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
69166 + pax_close_kernel();
69167 + } else
69168 +#endif
69169
69170 - if (shdr->sh_type != SHT_NOBITS)
69171 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
69172 + }
69173 /* Update sh_addr to point to copy in image. */
69174 - shdr->sh_addr = (unsigned long)dest;
69175 +
69176 +#ifdef CONFIG_PAX_KERNEXEC
69177 + if (shdr->sh_flags & SHF_EXECINSTR)
69178 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
69179 + else
69180 +#endif
69181 +
69182 + shdr->sh_addr = (unsigned long)dest;
69183 pr_debug("\t0x%lx %s\n",
69184 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
69185 }
69186 @@ -2763,12 +2868,12 @@ static void flush_module_icache(const struct module *mod)
69187 * Do it before processing of module parameters, so the module
69188 * can provide parameter accessor functions of its own.
69189 */
69190 - if (mod->module_init)
69191 - flush_icache_range((unsigned long)mod->module_init,
69192 - (unsigned long)mod->module_init
69193 - + mod->init_size);
69194 - flush_icache_range((unsigned long)mod->module_core,
69195 - (unsigned long)mod->module_core + mod->core_size);
69196 + if (mod->module_init_rx)
69197 + flush_icache_range((unsigned long)mod->module_init_rx,
69198 + (unsigned long)mod->module_init_rx
69199 + + mod->init_size_rx);
69200 + flush_icache_range((unsigned long)mod->module_core_rx,
69201 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
69202
69203 set_fs(old_fs);
69204 }
69205 @@ -2838,8 +2943,10 @@ out:
69206 static void module_deallocate(struct module *mod, struct load_info *info)
69207 {
69208 percpu_modfree(mod);
69209 - module_free(mod, mod->module_init);
69210 - module_free(mod, mod->module_core);
69211 + module_free_exec(mod, mod->module_init_rx);
69212 + module_free_exec(mod, mod->module_core_rx);
69213 + module_free(mod, mod->module_init_rw);
69214 + module_free(mod, mod->module_core_rw);
69215 }
69216
69217 int __weak module_finalize(const Elf_Ehdr *hdr,
69218 @@ -2852,7 +2959,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
69219 static int post_relocation(struct module *mod, const struct load_info *info)
69220 {
69221 /* Sort exception table now relocations are done. */
69222 + pax_open_kernel();
69223 sort_extable(mod->extable, mod->extable + mod->num_exentries);
69224 + pax_close_kernel();
69225
69226 /* Copy relocated percpu area over. */
69227 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
69228 @@ -2903,9 +3012,38 @@ static struct module *load_module(void __user *umod,
69229 if (err)
69230 goto free_unload;
69231
69232 + /* Now copy in args */
69233 + mod->args = strndup_user(uargs, ~0UL >> 1);
69234 + if (IS_ERR(mod->args)) {
69235 + err = PTR_ERR(mod->args);
69236 + goto free_unload;
69237 + }
69238 +
69239 /* Set up MODINFO_ATTR fields */
69240 setup_modinfo(mod, &info);
69241
69242 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69243 + {
69244 + char *p, *p2;
69245 +
69246 + if (strstr(mod->args, "grsec_modharden_netdev")) {
69247 + 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);
69248 + err = -EPERM;
69249 + goto free_modinfo;
69250 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
69251 + p += sizeof("grsec_modharden_normal") - 1;
69252 + p2 = strstr(p, "_");
69253 + if (p2) {
69254 + *p2 = '\0';
69255 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
69256 + *p2 = '_';
69257 + }
69258 + err = -EPERM;
69259 + goto free_modinfo;
69260 + }
69261 + }
69262 +#endif
69263 +
69264 /* Fix up syms, so that st_value is a pointer to location. */
69265 err = simplify_symbols(mod, &info);
69266 if (err < 0)
69267 @@ -2921,13 +3059,6 @@ static struct module *load_module(void __user *umod,
69268
69269 flush_module_icache(mod);
69270
69271 - /* Now copy in args */
69272 - mod->args = strndup_user(uargs, ~0UL >> 1);
69273 - if (IS_ERR(mod->args)) {
69274 - err = PTR_ERR(mod->args);
69275 - goto free_arch_cleanup;
69276 - }
69277 -
69278 /* Mark state as coming so strong_try_module_get() ignores us. */
69279 mod->state = MODULE_STATE_COMING;
69280
69281 @@ -2985,11 +3116,10 @@ static struct module *load_module(void __user *umod,
69282 unlock:
69283 mutex_unlock(&module_mutex);
69284 synchronize_sched();
69285 - kfree(mod->args);
69286 - free_arch_cleanup:
69287 module_arch_cleanup(mod);
69288 free_modinfo:
69289 free_modinfo(mod);
69290 + kfree(mod->args);
69291 free_unload:
69292 module_unload_free(mod);
69293 free_module:
69294 @@ -3030,16 +3160,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69295 MODULE_STATE_COMING, mod);
69296
69297 /* Set RO and NX regions for core */
69298 - set_section_ro_nx(mod->module_core,
69299 - mod->core_text_size,
69300 - mod->core_ro_size,
69301 - mod->core_size);
69302 + set_section_ro_nx(mod->module_core_rx,
69303 + mod->core_size_rx,
69304 + mod->core_size_rx,
69305 + mod->core_size_rx);
69306
69307 /* Set RO and NX regions for init */
69308 - set_section_ro_nx(mod->module_init,
69309 - mod->init_text_size,
69310 - mod->init_ro_size,
69311 - mod->init_size);
69312 + set_section_ro_nx(mod->module_init_rx,
69313 + mod->init_size_rx,
69314 + mod->init_size_rx,
69315 + mod->init_size_rx);
69316
69317 do_mod_ctors(mod);
69318 /* Start the module */
69319 @@ -3085,11 +3215,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69320 mod->strtab = mod->core_strtab;
69321 #endif
69322 unset_module_init_ro_nx(mod);
69323 - module_free(mod, mod->module_init);
69324 - mod->module_init = NULL;
69325 - mod->init_size = 0;
69326 - mod->init_ro_size = 0;
69327 - mod->init_text_size = 0;
69328 + module_free(mod, mod->module_init_rw);
69329 + module_free_exec(mod, mod->module_init_rx);
69330 + mod->module_init_rw = NULL;
69331 + mod->module_init_rx = NULL;
69332 + mod->init_size_rw = 0;
69333 + mod->init_size_rx = 0;
69334 mutex_unlock(&module_mutex);
69335
69336 return 0;
69337 @@ -3120,10 +3251,16 @@ static const char *get_ksymbol(struct module *mod,
69338 unsigned long nextval;
69339
69340 /* At worse, next value is at end of module */
69341 - if (within_module_init(addr, mod))
69342 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
69343 + if (within_module_init_rx(addr, mod))
69344 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
69345 + else if (within_module_init_rw(addr, mod))
69346 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
69347 + else if (within_module_core_rx(addr, mod))
69348 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
69349 + else if (within_module_core_rw(addr, mod))
69350 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
69351 else
69352 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
69353 + return NULL;
69354
69355 /* Scan for closest preceding symbol, and next symbol. (ELF
69356 starts real symbols at 1). */
69357 @@ -3358,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
69358 char buf[8];
69359
69360 seq_printf(m, "%s %u",
69361 - mod->name, mod->init_size + mod->core_size);
69362 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
69363 print_unload_info(m, mod);
69364
69365 /* Informative for users. */
69366 @@ -3367,7 +3504,7 @@ static int m_show(struct seq_file *m, void *p)
69367 mod->state == MODULE_STATE_COMING ? "Loading":
69368 "Live");
69369 /* Used by oprofile and other similar tools. */
69370 - seq_printf(m, " 0x%pK", mod->module_core);
69371 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
69372
69373 /* Taints info */
69374 if (mod->taints)
69375 @@ -3403,7 +3540,17 @@ static const struct file_operations proc_modules_operations = {
69376
69377 static int __init proc_modules_init(void)
69378 {
69379 +#ifndef CONFIG_GRKERNSEC_HIDESYM
69380 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69381 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69382 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69383 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
69384 +#else
69385 proc_create("modules", 0, NULL, &proc_modules_operations);
69386 +#endif
69387 +#else
69388 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69389 +#endif
69390 return 0;
69391 }
69392 module_init(proc_modules_init);
69393 @@ -3462,12 +3609,12 @@ struct module *__module_address(unsigned long addr)
69394 {
69395 struct module *mod;
69396
69397 - if (addr < module_addr_min || addr > module_addr_max)
69398 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
69399 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
69400 return NULL;
69401
69402 list_for_each_entry_rcu(mod, &modules, list)
69403 - if (within_module_core(addr, mod)
69404 - || within_module_init(addr, mod))
69405 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
69406 return mod;
69407 return NULL;
69408 }
69409 @@ -3501,11 +3648,20 @@ bool is_module_text_address(unsigned long addr)
69410 */
69411 struct module *__module_text_address(unsigned long addr)
69412 {
69413 - struct module *mod = __module_address(addr);
69414 + struct module *mod;
69415 +
69416 +#ifdef CONFIG_X86_32
69417 + addr = ktla_ktva(addr);
69418 +#endif
69419 +
69420 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
69421 + return NULL;
69422 +
69423 + mod = __module_address(addr);
69424 +
69425 if (mod) {
69426 /* Make sure it's within the text section. */
69427 - if (!within(addr, mod->module_init, mod->init_text_size)
69428 - && !within(addr, mod->module_core, mod->core_text_size))
69429 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
69430 mod = NULL;
69431 }
69432 return mod;
69433 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
69434 index 7e3443f..b2a1e6b 100644
69435 --- a/kernel/mutex-debug.c
69436 +++ b/kernel/mutex-debug.c
69437 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
69438 }
69439
69440 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69441 - struct thread_info *ti)
69442 + struct task_struct *task)
69443 {
69444 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
69445
69446 /* Mark the current thread as blocked on the lock: */
69447 - ti->task->blocked_on = waiter;
69448 + task->blocked_on = waiter;
69449 }
69450
69451 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69452 - struct thread_info *ti)
69453 + struct task_struct *task)
69454 {
69455 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
69456 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
69457 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
69458 - ti->task->blocked_on = NULL;
69459 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
69460 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
69461 + task->blocked_on = NULL;
69462
69463 list_del_init(&waiter->list);
69464 waiter->task = NULL;
69465 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
69466 index 0799fd3..d06ae3b 100644
69467 --- a/kernel/mutex-debug.h
69468 +++ b/kernel/mutex-debug.h
69469 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
69470 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
69471 extern void debug_mutex_add_waiter(struct mutex *lock,
69472 struct mutex_waiter *waiter,
69473 - struct thread_info *ti);
69474 + struct task_struct *task);
69475 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69476 - struct thread_info *ti);
69477 + struct task_struct *task);
69478 extern void debug_mutex_unlock(struct mutex *lock);
69479 extern void debug_mutex_init(struct mutex *lock, const char *name,
69480 struct lock_class_key *key);
69481 diff --git a/kernel/mutex.c b/kernel/mutex.c
69482 index a307cc9..27fd2e9 100644
69483 --- a/kernel/mutex.c
69484 +++ b/kernel/mutex.c
69485 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69486 spin_lock_mutex(&lock->wait_lock, flags);
69487
69488 debug_mutex_lock_common(lock, &waiter);
69489 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69490 + debug_mutex_add_waiter(lock, &waiter, task);
69491
69492 /* add waiting tasks to the end of the waitqueue (FIFO): */
69493 list_add_tail(&waiter.list, &lock->wait_list);
69494 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69495 * TASK_UNINTERRUPTIBLE case.)
69496 */
69497 if (unlikely(signal_pending_state(state, task))) {
69498 - mutex_remove_waiter(lock, &waiter,
69499 - task_thread_info(task));
69500 + mutex_remove_waiter(lock, &waiter, task);
69501 mutex_release(&lock->dep_map, 1, ip);
69502 spin_unlock_mutex(&lock->wait_lock, flags);
69503
69504 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69505 done:
69506 lock_acquired(&lock->dep_map, ip);
69507 /* got the lock - rejoice! */
69508 - mutex_remove_waiter(lock, &waiter, current_thread_info());
69509 + mutex_remove_waiter(lock, &waiter, task);
69510 mutex_set_owner(lock);
69511
69512 /* set it to 0 if there are no waiters left: */
69513 diff --git a/kernel/panic.c b/kernel/panic.c
69514 index e1b2822..5edc1d9 100644
69515 --- a/kernel/panic.c
69516 +++ b/kernel/panic.c
69517 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69518 const char *board;
69519
69520 printk(KERN_WARNING "------------[ cut here ]------------\n");
69521 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69522 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69523 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69524 if (board)
69525 printk(KERN_WARNING "Hardware name: %s\n", board);
69526 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69527 */
69528 void __stack_chk_fail(void)
69529 {
69530 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
69531 + dump_stack();
69532 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69533 __builtin_return_address(0));
69534 }
69535 EXPORT_SYMBOL(__stack_chk_fail);
69536 diff --git a/kernel/pid.c b/kernel/pid.c
69537 index e86b291a..e8b0fb5 100644
69538 --- a/kernel/pid.c
69539 +++ b/kernel/pid.c
69540 @@ -33,6 +33,7 @@
69541 #include <linux/rculist.h>
69542 #include <linux/bootmem.h>
69543 #include <linux/hash.h>
69544 +#include <linux/security.h>
69545 #include <linux/pid_namespace.h>
69546 #include <linux/init_task.h>
69547 #include <linux/syscalls.h>
69548 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69549
69550 int pid_max = PID_MAX_DEFAULT;
69551
69552 -#define RESERVED_PIDS 300
69553 +#define RESERVED_PIDS 500
69554
69555 int pid_max_min = RESERVED_PIDS + 1;
69556 int pid_max_max = PID_MAX_LIMIT;
69557 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69558 */
69559 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69560 {
69561 + struct task_struct *task;
69562 +
69563 rcu_lockdep_assert(rcu_read_lock_held(),
69564 "find_task_by_pid_ns() needs rcu_read_lock()"
69565 " protection");
69566 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69567 +
69568 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69569 +
69570 + if (gr_pid_is_chrooted(task))
69571 + return NULL;
69572 +
69573 + return task;
69574 }
69575
69576 struct task_struct *find_task_by_vpid(pid_t vnr)
69577 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69578 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69579 }
69580
69581 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69582 +{
69583 + rcu_lockdep_assert(rcu_read_lock_held(),
69584 + "find_task_by_pid_ns() needs rcu_read_lock()"
69585 + " protection");
69586 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69587 +}
69588 +
69589 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69590 {
69591 struct pid *pid;
69592 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69593 index 125cb67..a4d1c30 100644
69594 --- a/kernel/posix-cpu-timers.c
69595 +++ b/kernel/posix-cpu-timers.c
69596 @@ -6,6 +6,7 @@
69597 #include <linux/posix-timers.h>
69598 #include <linux/errno.h>
69599 #include <linux/math64.h>
69600 +#include <linux/security.h>
69601 #include <asm/uaccess.h>
69602 #include <linux/kernel_stat.h>
69603 #include <trace/events/timer.h>
69604 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69605
69606 static __init int init_posix_cpu_timers(void)
69607 {
69608 - struct k_clock process = {
69609 + static struct k_clock process = {
69610 .clock_getres = process_cpu_clock_getres,
69611 .clock_get = process_cpu_clock_get,
69612 .timer_create = process_cpu_timer_create,
69613 .nsleep = process_cpu_nsleep,
69614 .nsleep_restart = process_cpu_nsleep_restart,
69615 };
69616 - struct k_clock thread = {
69617 + static struct k_clock thread = {
69618 .clock_getres = thread_cpu_clock_getres,
69619 .clock_get = thread_cpu_clock_get,
69620 .timer_create = thread_cpu_timer_create,
69621 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69622 index 69185ae..cc2847a 100644
69623 --- a/kernel/posix-timers.c
69624 +++ b/kernel/posix-timers.c
69625 @@ -43,6 +43,7 @@
69626 #include <linux/idr.h>
69627 #include <linux/posix-clock.h>
69628 #include <linux/posix-timers.h>
69629 +#include <linux/grsecurity.h>
69630 #include <linux/syscalls.h>
69631 #include <linux/wait.h>
69632 #include <linux/workqueue.h>
69633 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69634 * which we beg off on and pass to do_sys_settimeofday().
69635 */
69636
69637 -static struct k_clock posix_clocks[MAX_CLOCKS];
69638 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69639
69640 /*
69641 * These ones are defined below.
69642 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69643 */
69644 static __init int init_posix_timers(void)
69645 {
69646 - struct k_clock clock_realtime = {
69647 + static struct k_clock clock_realtime = {
69648 .clock_getres = hrtimer_get_res,
69649 .clock_get = posix_clock_realtime_get,
69650 .clock_set = posix_clock_realtime_set,
69651 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69652 .timer_get = common_timer_get,
69653 .timer_del = common_timer_del,
69654 };
69655 - struct k_clock clock_monotonic = {
69656 + static struct k_clock clock_monotonic = {
69657 .clock_getres = hrtimer_get_res,
69658 .clock_get = posix_ktime_get_ts,
69659 .nsleep = common_nsleep,
69660 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69661 .timer_get = common_timer_get,
69662 .timer_del = common_timer_del,
69663 };
69664 - struct k_clock clock_monotonic_raw = {
69665 + static struct k_clock clock_monotonic_raw = {
69666 .clock_getres = hrtimer_get_res,
69667 .clock_get = posix_get_monotonic_raw,
69668 };
69669 - struct k_clock clock_realtime_coarse = {
69670 + static struct k_clock clock_realtime_coarse = {
69671 .clock_getres = posix_get_coarse_res,
69672 .clock_get = posix_get_realtime_coarse,
69673 };
69674 - struct k_clock clock_monotonic_coarse = {
69675 + static struct k_clock clock_monotonic_coarse = {
69676 .clock_getres = posix_get_coarse_res,
69677 .clock_get = posix_get_monotonic_coarse,
69678 };
69679 - struct k_clock clock_boottime = {
69680 + static struct k_clock clock_boottime = {
69681 .clock_getres = hrtimer_get_res,
69682 .clock_get = posix_get_boottime,
69683 .nsleep = common_nsleep,
69684 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69685 return;
69686 }
69687
69688 - posix_clocks[clock_id] = *new_clock;
69689 + posix_clocks[clock_id] = new_clock;
69690 }
69691 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69692
69693 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69694 return (id & CLOCKFD_MASK) == CLOCKFD ?
69695 &clock_posix_dynamic : &clock_posix_cpu;
69696
69697 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69698 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69699 return NULL;
69700 - return &posix_clocks[id];
69701 + return posix_clocks[id];
69702 }
69703
69704 static int common_timer_create(struct k_itimer *new_timer)
69705 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69706 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69707 return -EFAULT;
69708
69709 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69710 + have their clock_set fptr set to a nosettime dummy function
69711 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69712 + call common_clock_set, which calls do_sys_settimeofday, which
69713 + we hook
69714 + */
69715 +
69716 return kc->clock_set(which_clock, &new_tp);
69717 }
69718
69719 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69720 index d523593..68197a4 100644
69721 --- a/kernel/power/poweroff.c
69722 +++ b/kernel/power/poweroff.c
69723 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69724 .enable_mask = SYSRQ_ENABLE_BOOT,
69725 };
69726
69727 -static int pm_sysrq_init(void)
69728 +static int __init pm_sysrq_init(void)
69729 {
69730 register_sysrq_key('o', &sysrq_poweroff_op);
69731 return 0;
69732 diff --git a/kernel/power/process.c b/kernel/power/process.c
69733 index 19db29f..33b52b6 100644
69734 --- a/kernel/power/process.c
69735 +++ b/kernel/power/process.c
69736 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69737 u64 elapsed_csecs64;
69738 unsigned int elapsed_csecs;
69739 bool wakeup = false;
69740 + bool timedout = false;
69741
69742 do_gettimeofday(&start);
69743
69744 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69745
69746 while (true) {
69747 todo = 0;
69748 + if (time_after(jiffies, end_time))
69749 + timedout = true;
69750 read_lock(&tasklist_lock);
69751 do_each_thread(g, p) {
69752 if (p == current || !freeze_task(p))
69753 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69754 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69755 * transition can't race with task state testing here.
69756 */
69757 - if (!task_is_stopped_or_traced(p) &&
69758 - !freezer_should_skip(p))
69759 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69760 todo++;
69761 + if (timedout) {
69762 + printk(KERN_ERR "Task refusing to freeze:\n");
69763 + sched_show_task(p);
69764 + }
69765 + }
69766 } while_each_thread(g, p);
69767 read_unlock(&tasklist_lock);
69768
69769 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69770 todo += wq_busy;
69771 }
69772
69773 - if (!todo || time_after(jiffies, end_time))
69774 + if (!todo || timedout)
69775 break;
69776
69777 if (pm_wakeup_pending()) {
69778 diff --git a/kernel/printk.c b/kernel/printk.c
69779 index 66a2ea3..10f3a01 100644
69780 --- a/kernel/printk.c
69781 +++ b/kernel/printk.c
69782 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69783 if (from_file && type != SYSLOG_ACTION_OPEN)
69784 return 0;
69785
69786 +#ifdef CONFIG_GRKERNSEC_DMESG
69787 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69788 + return -EPERM;
69789 +#endif
69790 +
69791 if (syslog_action_restricted(type)) {
69792 if (capable(CAP_SYSLOG))
69793 return 0;
69794 diff --git a/kernel/profile.c b/kernel/profile.c
69795 index 76b8e77..a2930e8 100644
69796 --- a/kernel/profile.c
69797 +++ b/kernel/profile.c
69798 @@ -39,7 +39,7 @@ struct profile_hit {
69799 /* Oprofile timer tick hook */
69800 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69801
69802 -static atomic_t *prof_buffer;
69803 +static atomic_unchecked_t *prof_buffer;
69804 static unsigned long prof_len, prof_shift;
69805
69806 int prof_on __read_mostly;
69807 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69808 hits[i].pc = 0;
69809 continue;
69810 }
69811 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69812 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69813 hits[i].hits = hits[i].pc = 0;
69814 }
69815 }
69816 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69817 * Add the current hit(s) and flush the write-queue out
69818 * to the global buffer:
69819 */
69820 - atomic_add(nr_hits, &prof_buffer[pc]);
69821 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69822 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69823 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69824 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69825 hits[i].pc = hits[i].hits = 0;
69826 }
69827 out:
69828 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69829 {
69830 unsigned long pc;
69831 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69832 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69833 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69834 }
69835 #endif /* !CONFIG_SMP */
69836
69837 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69838 return -EFAULT;
69839 buf++; p++; count--; read++;
69840 }
69841 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69842 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69843 if (copy_to_user(buf, (void *)pnt, count))
69844 return -EFAULT;
69845 read += count;
69846 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69847 }
69848 #endif
69849 profile_discard_flip_buffers();
69850 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69851 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69852 return count;
69853 }
69854
69855 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69856 index a232bb5..2a65ef9 100644
69857 --- a/kernel/ptrace.c
69858 +++ b/kernel/ptrace.c
69859 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69860
69861 if (seize)
69862 flags |= PT_SEIZED;
69863 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69864 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69865 flags |= PT_PTRACE_CAP;
69866 task->ptrace = flags;
69867
69868 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69869 break;
69870 return -EIO;
69871 }
69872 - if (copy_to_user(dst, buf, retval))
69873 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69874 return -EFAULT;
69875 copied += retval;
69876 src += retval;
69877 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69878 bool seized = child->ptrace & PT_SEIZED;
69879 int ret = -EIO;
69880 siginfo_t siginfo, *si;
69881 - void __user *datavp = (void __user *) data;
69882 + void __user *datavp = (__force void __user *) data;
69883 unsigned long __user *datalp = datavp;
69884 unsigned long flags;
69885
69886 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69887 goto out;
69888 }
69889
69890 + if (gr_handle_ptrace(child, request)) {
69891 + ret = -EPERM;
69892 + goto out_put_task_struct;
69893 + }
69894 +
69895 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69896 ret = ptrace_attach(child, request, addr, data);
69897 /*
69898 * Some architectures need to do book-keeping after
69899 * a ptrace attach.
69900 */
69901 - if (!ret)
69902 + if (!ret) {
69903 arch_ptrace_attach(child);
69904 + gr_audit_ptrace(child);
69905 + }
69906 goto out_put_task_struct;
69907 }
69908
69909 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69910 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69911 if (copied != sizeof(tmp))
69912 return -EIO;
69913 - return put_user(tmp, (unsigned long __user *)data);
69914 + return put_user(tmp, (__force unsigned long __user *)data);
69915 }
69916
69917 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69918 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69919 goto out;
69920 }
69921
69922 + if (gr_handle_ptrace(child, request)) {
69923 + ret = -EPERM;
69924 + goto out_put_task_struct;
69925 + }
69926 +
69927 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69928 ret = ptrace_attach(child, request, addr, data);
69929 /*
69930 * Some architectures need to do book-keeping after
69931 * a ptrace attach.
69932 */
69933 - if (!ret)
69934 + if (!ret) {
69935 arch_ptrace_attach(child);
69936 + gr_audit_ptrace(child);
69937 + }
69938 goto out_put_task_struct;
69939 }
69940
69941 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69942 index 547b1fe..65e874e 100644
69943 --- a/kernel/rcutiny.c
69944 +++ b/kernel/rcutiny.c
69945 @@ -46,7 +46,7 @@
69946 struct rcu_ctrlblk;
69947 static void invoke_rcu_callbacks(void);
69948 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69949 -static void rcu_process_callbacks(struct softirq_action *unused);
69950 +static void rcu_process_callbacks(void);
69951 static void __call_rcu(struct rcu_head *head,
69952 void (*func)(struct rcu_head *rcu),
69953 struct rcu_ctrlblk *rcp);
69954 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69955 rcu_is_callbacks_kthread()));
69956 }
69957
69958 -static void rcu_process_callbacks(struct softirq_action *unused)
69959 +static void rcu_process_callbacks(void)
69960 {
69961 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69962 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69963 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69964 index 918fd1e..85089bb 100644
69965 --- a/kernel/rcutiny_plugin.h
69966 +++ b/kernel/rcutiny_plugin.h
69967 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69968 have_rcu_kthread_work = morework;
69969 local_irq_restore(flags);
69970 if (work)
69971 - rcu_process_callbacks(NULL);
69972 + rcu_process_callbacks();
69973 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69974 }
69975
69976 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69977 index 25b1503..1988a74 100644
69978 --- a/kernel/rcutorture.c
69979 +++ b/kernel/rcutorture.c
69980 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69981 { 0 };
69982 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69983 { 0 };
69984 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69985 -static atomic_t n_rcu_torture_alloc;
69986 -static atomic_t n_rcu_torture_alloc_fail;
69987 -static atomic_t n_rcu_torture_free;
69988 -static atomic_t n_rcu_torture_mberror;
69989 -static atomic_t n_rcu_torture_error;
69990 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69991 +static atomic_unchecked_t n_rcu_torture_alloc;
69992 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69993 +static atomic_unchecked_t n_rcu_torture_free;
69994 +static atomic_unchecked_t n_rcu_torture_mberror;
69995 +static atomic_unchecked_t n_rcu_torture_error;
69996 static long n_rcu_torture_barrier_error;
69997 static long n_rcu_torture_boost_ktrerror;
69998 static long n_rcu_torture_boost_rterror;
69999 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
70000
70001 spin_lock_bh(&rcu_torture_lock);
70002 if (list_empty(&rcu_torture_freelist)) {
70003 - atomic_inc(&n_rcu_torture_alloc_fail);
70004 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
70005 spin_unlock_bh(&rcu_torture_lock);
70006 return NULL;
70007 }
70008 - atomic_inc(&n_rcu_torture_alloc);
70009 + atomic_inc_unchecked(&n_rcu_torture_alloc);
70010 p = rcu_torture_freelist.next;
70011 list_del_init(p);
70012 spin_unlock_bh(&rcu_torture_lock);
70013 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
70014 static void
70015 rcu_torture_free(struct rcu_torture *p)
70016 {
70017 - atomic_inc(&n_rcu_torture_free);
70018 + atomic_inc_unchecked(&n_rcu_torture_free);
70019 spin_lock_bh(&rcu_torture_lock);
70020 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
70021 spin_unlock_bh(&rcu_torture_lock);
70022 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
70023 i = rp->rtort_pipe_count;
70024 if (i > RCU_TORTURE_PIPE_LEN)
70025 i = RCU_TORTURE_PIPE_LEN;
70026 - atomic_inc(&rcu_torture_wcount[i]);
70027 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
70028 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
70029 rp->rtort_mbtest = 0;
70030 rcu_torture_free(rp);
70031 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
70032 i = rp->rtort_pipe_count;
70033 if (i > RCU_TORTURE_PIPE_LEN)
70034 i = RCU_TORTURE_PIPE_LEN;
70035 - atomic_inc(&rcu_torture_wcount[i]);
70036 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
70037 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
70038 rp->rtort_mbtest = 0;
70039 list_del(&rp->rtort_free);
70040 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
70041 i = old_rp->rtort_pipe_count;
70042 if (i > RCU_TORTURE_PIPE_LEN)
70043 i = RCU_TORTURE_PIPE_LEN;
70044 - atomic_inc(&rcu_torture_wcount[i]);
70045 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
70046 old_rp->rtort_pipe_count++;
70047 cur_ops->deferred_free(old_rp);
70048 }
70049 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
70050 }
70051 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
70052 if (p->rtort_mbtest == 0)
70053 - atomic_inc(&n_rcu_torture_mberror);
70054 + atomic_inc_unchecked(&n_rcu_torture_mberror);
70055 spin_lock(&rand_lock);
70056 cur_ops->read_delay(&rand);
70057 n_rcu_torture_timers++;
70058 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
70059 }
70060 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
70061 if (p->rtort_mbtest == 0)
70062 - atomic_inc(&n_rcu_torture_mberror);
70063 + atomic_inc_unchecked(&n_rcu_torture_mberror);
70064 cur_ops->read_delay(&rand);
70065 preempt_disable();
70066 pipe_count = p->rtort_pipe_count;
70067 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
70068 rcu_torture_current,
70069 rcu_torture_current_version,
70070 list_empty(&rcu_torture_freelist),
70071 - atomic_read(&n_rcu_torture_alloc),
70072 - atomic_read(&n_rcu_torture_alloc_fail),
70073 - atomic_read(&n_rcu_torture_free));
70074 + atomic_read_unchecked(&n_rcu_torture_alloc),
70075 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
70076 + atomic_read_unchecked(&n_rcu_torture_free));
70077 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
70078 - atomic_read(&n_rcu_torture_mberror),
70079 + atomic_read_unchecked(&n_rcu_torture_mberror),
70080 n_rcu_torture_boost_ktrerror,
70081 n_rcu_torture_boost_rterror);
70082 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
70083 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
70084 n_barrier_attempts,
70085 n_rcu_torture_barrier_error);
70086 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
70087 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
70088 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
70089 n_rcu_torture_barrier_error != 0 ||
70090 n_rcu_torture_boost_ktrerror != 0 ||
70091 n_rcu_torture_boost_rterror != 0 ||
70092 n_rcu_torture_boost_failure != 0 ||
70093 i > 1) {
70094 cnt += sprintf(&page[cnt], "!!! ");
70095 - atomic_inc(&n_rcu_torture_error);
70096 + atomic_inc_unchecked(&n_rcu_torture_error);
70097 WARN_ON_ONCE(1);
70098 }
70099 cnt += sprintf(&page[cnt], "Reader Pipe: ");
70100 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
70101 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
70102 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
70103 cnt += sprintf(&page[cnt], " %d",
70104 - atomic_read(&rcu_torture_wcount[i]));
70105 + atomic_read_unchecked(&rcu_torture_wcount[i]));
70106 }
70107 cnt += sprintf(&page[cnt], "\n");
70108 if (cur_ops->stats)
70109 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
70110
70111 if (cur_ops->cleanup)
70112 cur_ops->cleanup();
70113 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
70114 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
70115 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
70116 else if (n_online_successes != n_online_attempts ||
70117 n_offline_successes != n_offline_attempts)
70118 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
70119
70120 rcu_torture_current = NULL;
70121 rcu_torture_current_version = 0;
70122 - atomic_set(&n_rcu_torture_alloc, 0);
70123 - atomic_set(&n_rcu_torture_alloc_fail, 0);
70124 - atomic_set(&n_rcu_torture_free, 0);
70125 - atomic_set(&n_rcu_torture_mberror, 0);
70126 - atomic_set(&n_rcu_torture_error, 0);
70127 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
70128 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
70129 + atomic_set_unchecked(&n_rcu_torture_free, 0);
70130 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
70131 + atomic_set_unchecked(&n_rcu_torture_error, 0);
70132 n_rcu_torture_barrier_error = 0;
70133 n_rcu_torture_boost_ktrerror = 0;
70134 n_rcu_torture_boost_rterror = 0;
70135 n_rcu_torture_boost_failure = 0;
70136 n_rcu_torture_boosts = 0;
70137 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
70138 - atomic_set(&rcu_torture_wcount[i], 0);
70139 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
70140 for_each_possible_cpu(cpu) {
70141 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
70142 per_cpu(rcu_torture_count, cpu)[i] = 0;
70143 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
70144 index f7bcd9e..8973e14 100644
70145 --- a/kernel/rcutree.c
70146 +++ b/kernel/rcutree.c
70147 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
70148 rcu_prepare_for_idle(smp_processor_id());
70149 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
70150 smp_mb__before_atomic_inc(); /* See above. */
70151 - atomic_inc(&rdtp->dynticks);
70152 + atomic_inc_unchecked(&rdtp->dynticks);
70153 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
70154 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
70155 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
70156
70157 /*
70158 * The idle task is not permitted to enter the idle loop while
70159 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
70160 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
70161 {
70162 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
70163 - atomic_inc(&rdtp->dynticks);
70164 + atomic_inc_unchecked(&rdtp->dynticks);
70165 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
70166 smp_mb__after_atomic_inc(); /* See above. */
70167 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
70168 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
70169 rcu_cleanup_after_idle(smp_processor_id());
70170 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
70171 if (!is_idle_task(current)) {
70172 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
70173 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
70174
70175 if (rdtp->dynticks_nmi_nesting == 0 &&
70176 - (atomic_read(&rdtp->dynticks) & 0x1))
70177 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
70178 return;
70179 rdtp->dynticks_nmi_nesting++;
70180 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
70181 - atomic_inc(&rdtp->dynticks);
70182 + atomic_inc_unchecked(&rdtp->dynticks);
70183 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
70184 smp_mb__after_atomic_inc(); /* See above. */
70185 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
70186 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
70187 }
70188
70189 /**
70190 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
70191 return;
70192 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
70193 smp_mb__before_atomic_inc(); /* See above. */
70194 - atomic_inc(&rdtp->dynticks);
70195 + atomic_inc_unchecked(&rdtp->dynticks);
70196 smp_mb__after_atomic_inc(); /* Force delay to next write. */
70197 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
70198 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
70199 }
70200
70201 /**
70202 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
70203 int ret;
70204
70205 preempt_disable();
70206 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
70207 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
70208 preempt_enable();
70209 return ret;
70210 }
70211 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
70212 */
70213 static int dyntick_save_progress_counter(struct rcu_data *rdp)
70214 {
70215 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
70216 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
70217 return (rdp->dynticks_snap & 0x1) == 0;
70218 }
70219
70220 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
70221 unsigned int curr;
70222 unsigned int snap;
70223
70224 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
70225 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
70226 snap = (unsigned int)rdp->dynticks_snap;
70227
70228 /*
70229 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
70230 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
70231 */
70232 if (till_stall_check < 3) {
70233 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
70234 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
70235 till_stall_check = 3;
70236 } else if (till_stall_check > 300) {
70237 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
70238 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
70239 till_stall_check = 300;
70240 }
70241 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
70242 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
70243 rsp->qlen += rdp->qlen;
70244 rdp->n_cbs_orphaned += rdp->qlen;
70245 rdp->qlen_lazy = 0;
70246 - ACCESS_ONCE(rdp->qlen) = 0;
70247 + ACCESS_ONCE_RW(rdp->qlen) = 0;
70248 }
70249
70250 /*
70251 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
70252 }
70253 smp_mb(); /* List handling before counting for rcu_barrier(). */
70254 rdp->qlen_lazy -= count_lazy;
70255 - ACCESS_ONCE(rdp->qlen) -= count;
70256 + ACCESS_ONCE_RW(rdp->qlen) -= count;
70257 rdp->n_cbs_invoked += count;
70258
70259 /* Reinstate batch limit if we have worked down the excess. */
70260 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
70261 /*
70262 * Do RCU core processing for the current CPU.
70263 */
70264 -static void rcu_process_callbacks(struct softirq_action *unused)
70265 +static void rcu_process_callbacks(void)
70266 {
70267 struct rcu_state *rsp;
70268
70269 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
70270 rdp = this_cpu_ptr(rsp->rda);
70271
70272 /* Add the callback to our list. */
70273 - ACCESS_ONCE(rdp->qlen)++;
70274 + ACCESS_ONCE_RW(rdp->qlen)++;
70275 if (lazy)
70276 rdp->qlen_lazy++;
70277 else
70278 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
70279 }
70280 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
70281
70282 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
70283 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
70284 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
70285 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
70286
70287 static int synchronize_sched_expedited_cpu_stop(void *data)
70288 {
70289 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
70290 int firstsnap, s, snap, trycount = 0;
70291
70292 /* Note that atomic_inc_return() implies full memory barrier. */
70293 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
70294 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
70295 get_online_cpus();
70296 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
70297
70298 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
70299 }
70300
70301 /* Check to see if someone else did our work for us. */
70302 - s = atomic_read(&sync_sched_expedited_done);
70303 + s = atomic_read_unchecked(&sync_sched_expedited_done);
70304 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
70305 smp_mb(); /* ensure test happens before caller kfree */
70306 return;
70307 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
70308 * grace period works for us.
70309 */
70310 get_online_cpus();
70311 - snap = atomic_read(&sync_sched_expedited_started);
70312 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
70313 smp_mb(); /* ensure read is before try_stop_cpus(). */
70314 }
70315
70316 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
70317 * than we did beat us to the punch.
70318 */
70319 do {
70320 - s = atomic_read(&sync_sched_expedited_done);
70321 + s = atomic_read_unchecked(&sync_sched_expedited_done);
70322 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
70323 smp_mb(); /* ensure test happens before caller kfree */
70324 break;
70325 }
70326 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
70327 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
70328
70329 put_online_cpus();
70330 }
70331 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70332 * ACCESS_ONCE() to prevent the compiler from speculating
70333 * the increment to precede the early-exit check.
70334 */
70335 - ACCESS_ONCE(rsp->n_barrier_done)++;
70336 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70337 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
70338 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
70339 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
70340 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70341
70342 /* Increment ->n_barrier_done to prevent duplicate work. */
70343 smp_mb(); /* Keep increment after above mechanism. */
70344 - ACCESS_ONCE(rsp->n_barrier_done)++;
70345 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70346 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
70347 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
70348 smp_mb(); /* Keep increment before caller's subsequent code. */
70349 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
70350 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
70351 init_callback_list(rdp);
70352 rdp->qlen_lazy = 0;
70353 - ACCESS_ONCE(rdp->qlen) = 0;
70354 + ACCESS_ONCE_RW(rdp->qlen) = 0;
70355 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
70356 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
70357 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
70358 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
70359 rdp->cpu = cpu;
70360 rdp->rsp = rsp;
70361 raw_spin_unlock_irqrestore(&rnp->lock, flags);
70362 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
70363 rdp->n_force_qs_snap = rsp->n_force_qs;
70364 rdp->blimit = blimit;
70365 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
70366 - atomic_set(&rdp->dynticks->dynticks,
70367 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
70368 + atomic_set_unchecked(&rdp->dynticks->dynticks,
70369 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
70370 rcu_prepare_for_idle_init(cpu);
70371 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
70372
70373 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
70374 index 4d29169..d104a3c 100644
70375 --- a/kernel/rcutree.h
70376 +++ b/kernel/rcutree.h
70377 @@ -86,7 +86,7 @@ struct rcu_dynticks {
70378 long long dynticks_nesting; /* Track irq/process nesting level. */
70379 /* Process level is worth LLONG_MAX/2. */
70380 int dynticks_nmi_nesting; /* Track NMI nesting level. */
70381 - atomic_t dynticks; /* Even value for idle, else odd. */
70382 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
70383 #ifdef CONFIG_RCU_FAST_NO_HZ
70384 int dyntick_drain; /* Prepare-for-idle state variable. */
70385 unsigned long dyntick_holdoff;
70386 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
70387 index 7f3244c..417d606 100644
70388 --- a/kernel/rcutree_plugin.h
70389 +++ b/kernel/rcutree_plugin.h
70390 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
70391
70392 /* Clean up and exit. */
70393 smp_mb(); /* ensure expedited GP seen before counter increment. */
70394 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
70395 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
70396 unlock_mb_ret:
70397 mutex_unlock(&sync_rcu_preempt_exp_mutex);
70398 mb_ret:
70399 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
70400 index abffb48..cbfa6d3 100644
70401 --- a/kernel/rcutree_trace.c
70402 +++ b/kernel/rcutree_trace.c
70403 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
70404 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70405 rdp->qs_pending);
70406 seq_printf(m, " dt=%d/%llx/%d df=%lu",
70407 - atomic_read(&rdp->dynticks->dynticks),
70408 + atomic_read_unchecked(&rdp->dynticks->dynticks),
70409 rdp->dynticks->dynticks_nesting,
70410 rdp->dynticks->dynticks_nmi_nesting,
70411 rdp->dynticks_fqs);
70412 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
70413 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70414 rdp->qs_pending);
70415 seq_printf(m, ",%d,%llx,%d,%lu",
70416 - atomic_read(&rdp->dynticks->dynticks),
70417 + atomic_read_unchecked(&rdp->dynticks->dynticks),
70418 rdp->dynticks->dynticks_nesting,
70419 rdp->dynticks->dynticks_nmi_nesting,
70420 rdp->dynticks_fqs);
70421 diff --git a/kernel/resource.c b/kernel/resource.c
70422 index 34d4588..10baa6a 100644
70423 --- a/kernel/resource.c
70424 +++ b/kernel/resource.c
70425 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
70426
70427 static int __init ioresources_init(void)
70428 {
70429 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70430 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70431 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
70432 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
70433 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70434 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
70435 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
70436 +#endif
70437 +#else
70438 proc_create("ioports", 0, NULL, &proc_ioports_operations);
70439 proc_create("iomem", 0, NULL, &proc_iomem_operations);
70440 +#endif
70441 return 0;
70442 }
70443 __initcall(ioresources_init);
70444 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
70445 index 98ec494..4241d6d 100644
70446 --- a/kernel/rtmutex-tester.c
70447 +++ b/kernel/rtmutex-tester.c
70448 @@ -20,7 +20,7 @@
70449 #define MAX_RT_TEST_MUTEXES 8
70450
70451 static spinlock_t rttest_lock;
70452 -static atomic_t rttest_event;
70453 +static atomic_unchecked_t rttest_event;
70454
70455 struct test_thread_data {
70456 int opcode;
70457 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70458
70459 case RTTEST_LOCKCONT:
70460 td->mutexes[td->opdata] = 1;
70461 - td->event = atomic_add_return(1, &rttest_event);
70462 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70463 return 0;
70464
70465 case RTTEST_RESET:
70466 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70467 return 0;
70468
70469 case RTTEST_RESETEVENT:
70470 - atomic_set(&rttest_event, 0);
70471 + atomic_set_unchecked(&rttest_event, 0);
70472 return 0;
70473
70474 default:
70475 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70476 return ret;
70477
70478 td->mutexes[id] = 1;
70479 - td->event = atomic_add_return(1, &rttest_event);
70480 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70481 rt_mutex_lock(&mutexes[id]);
70482 - td->event = atomic_add_return(1, &rttest_event);
70483 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70484 td->mutexes[id] = 4;
70485 return 0;
70486
70487 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70488 return ret;
70489
70490 td->mutexes[id] = 1;
70491 - td->event = atomic_add_return(1, &rttest_event);
70492 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70493 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70494 - td->event = atomic_add_return(1, &rttest_event);
70495 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70496 td->mutexes[id] = ret ? 0 : 4;
70497 return ret ? -EINTR : 0;
70498
70499 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70500 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70501 return ret;
70502
70503 - td->event = atomic_add_return(1, &rttest_event);
70504 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70505 rt_mutex_unlock(&mutexes[id]);
70506 - td->event = atomic_add_return(1, &rttest_event);
70507 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70508 td->mutexes[id] = 0;
70509 return 0;
70510
70511 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70512 break;
70513
70514 td->mutexes[dat] = 2;
70515 - td->event = atomic_add_return(1, &rttest_event);
70516 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70517 break;
70518
70519 default:
70520 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70521 return;
70522
70523 td->mutexes[dat] = 3;
70524 - td->event = atomic_add_return(1, &rttest_event);
70525 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70526 break;
70527
70528 case RTTEST_LOCKNOWAIT:
70529 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70530 return;
70531
70532 td->mutexes[dat] = 1;
70533 - td->event = atomic_add_return(1, &rttest_event);
70534 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70535 return;
70536
70537 default:
70538 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70539 index 0984a21..939f183 100644
70540 --- a/kernel/sched/auto_group.c
70541 +++ b/kernel/sched/auto_group.c
70542 @@ -11,7 +11,7 @@
70543
70544 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70545 static struct autogroup autogroup_default;
70546 -static atomic_t autogroup_seq_nr;
70547 +static atomic_unchecked_t autogroup_seq_nr;
70548
70549 void __init autogroup_init(struct task_struct *init_task)
70550 {
70551 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70552
70553 kref_init(&ag->kref);
70554 init_rwsem(&ag->lock);
70555 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70556 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70557 ag->tg = tg;
70558 #ifdef CONFIG_RT_GROUP_SCHED
70559 /*
70560 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70561 index 1a48cdb..d3949ff 100644
70562 --- a/kernel/sched/core.c
70563 +++ b/kernel/sched/core.c
70564 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
70565 /* convert nice value [19,-20] to rlimit style value [1,40] */
70566 int nice_rlim = 20 - nice;
70567
70568 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70569 +
70570 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70571 capable(CAP_SYS_NICE));
70572 }
70573 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70574 if (nice > 19)
70575 nice = 19;
70576
70577 - if (increment < 0 && !can_nice(current, nice))
70578 + if (increment < 0 && (!can_nice(current, nice) ||
70579 + gr_handle_chroot_nice()))
70580 return -EPERM;
70581
70582 retval = security_task_setnice(current, nice);
70583 @@ -4290,6 +4293,7 @@ recheck:
70584 unsigned long rlim_rtprio =
70585 task_rlimit(p, RLIMIT_RTPRIO);
70586
70587 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70588 /* can't set/change the rt policy */
70589 if (policy != p->policy && !rlim_rtprio)
70590 return -EPERM;
70591 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70592 index 96e2b18..bb31eec 100644
70593 --- a/kernel/sched/fair.c
70594 +++ b/kernel/sched/fair.c
70595 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70596 * run_rebalance_domains is triggered when needed from the scheduler tick.
70597 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70598 */
70599 -static void run_rebalance_domains(struct softirq_action *h)
70600 +static void run_rebalance_domains(void)
70601 {
70602 int this_cpu = smp_processor_id();
70603 struct rq *this_rq = cpu_rq(this_cpu);
70604 diff --git a/kernel/signal.c b/kernel/signal.c
70605 index be4f856..453401c 100644
70606 --- a/kernel/signal.c
70607 +++ b/kernel/signal.c
70608 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
70609
70610 int print_fatal_signals __read_mostly;
70611
70612 -static void __user *sig_handler(struct task_struct *t, int sig)
70613 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70614 {
70615 return t->sighand->action[sig - 1].sa.sa_handler;
70616 }
70617
70618 -static int sig_handler_ignored(void __user *handler, int sig)
70619 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70620 {
70621 /* Is it explicitly or implicitly ignored? */
70622 return handler == SIG_IGN ||
70623 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70624
70625 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70626 {
70627 - void __user *handler;
70628 + __sighandler_t handler;
70629
70630 handler = sig_handler(t, sig);
70631
70632 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70633 atomic_inc(&user->sigpending);
70634 rcu_read_unlock();
70635
70636 + if (!override_rlimit)
70637 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70638 +
70639 if (override_rlimit ||
70640 atomic_read(&user->sigpending) <=
70641 task_rlimit(t, RLIMIT_SIGPENDING)) {
70642 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70643
70644 int unhandled_signal(struct task_struct *tsk, int sig)
70645 {
70646 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70647 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70648 if (is_global_init(tsk))
70649 return 1;
70650 if (handler != SIG_IGN && handler != SIG_DFL)
70651 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70652 }
70653 }
70654
70655 + /* allow glibc communication via tgkill to other threads in our
70656 + thread group */
70657 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70658 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70659 + && gr_handle_signal(t, sig))
70660 + return -EPERM;
70661 +
70662 return security_task_kill(t, info, sig, 0);
70663 }
70664
70665 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70666 return send_signal(sig, info, p, 1);
70667 }
70668
70669 -static int
70670 +int
70671 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70672 {
70673 return send_signal(sig, info, t, 0);
70674 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70675 unsigned long int flags;
70676 int ret, blocked, ignored;
70677 struct k_sigaction *action;
70678 + int is_unhandled = 0;
70679
70680 spin_lock_irqsave(&t->sighand->siglock, flags);
70681 action = &t->sighand->action[sig-1];
70682 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70683 }
70684 if (action->sa.sa_handler == SIG_DFL)
70685 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70686 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70687 + is_unhandled = 1;
70688 ret = specific_send_sig_info(sig, info, t);
70689 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70690
70691 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70692 + normal operation */
70693 + if (is_unhandled) {
70694 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70695 + gr_handle_crash(t, sig);
70696 + }
70697 +
70698 return ret;
70699 }
70700
70701 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70702 ret = check_kill_permission(sig, info, p);
70703 rcu_read_unlock();
70704
70705 - if (!ret && sig)
70706 + if (!ret && sig) {
70707 ret = do_send_sig_info(sig, info, p, true);
70708 + if (!ret)
70709 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70710 + }
70711
70712 return ret;
70713 }
70714 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70715 int error = -ESRCH;
70716
70717 rcu_read_lock();
70718 - p = find_task_by_vpid(pid);
70719 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70720 + /* allow glibc communication via tgkill to other threads in our
70721 + thread group */
70722 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70723 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70724 + p = find_task_by_vpid_unrestricted(pid);
70725 + else
70726 +#endif
70727 + p = find_task_by_vpid(pid);
70728 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70729 error = check_kill_permission(sig, info, p);
70730 /*
70731 diff --git a/kernel/softirq.c b/kernel/softirq.c
70732 index b73e681..645ab62 100644
70733 --- a/kernel/softirq.c
70734 +++ b/kernel/softirq.c
70735 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70736
70737 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70738
70739 -char *softirq_to_name[NR_SOFTIRQS] = {
70740 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70741 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70742 "TASKLET", "SCHED", "HRTIMER", "RCU"
70743 };
70744 @@ -243,7 +243,7 @@ restart:
70745 kstat_incr_softirqs_this_cpu(vec_nr);
70746
70747 trace_softirq_entry(vec_nr);
70748 - h->action(h);
70749 + h->action();
70750 trace_softirq_exit(vec_nr);
70751 if (unlikely(prev_count != preempt_count())) {
70752 printk(KERN_ERR "huh, entered softirq %u %s %p"
70753 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70754 or_softirq_pending(1UL << nr);
70755 }
70756
70757 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70758 +void open_softirq(int nr, void (*action)(void))
70759 {
70760 - softirq_vec[nr].action = action;
70761 + pax_open_kernel();
70762 + *(void **)&softirq_vec[nr].action = action;
70763 + pax_close_kernel();
70764 }
70765
70766 /*
70767 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70768
70769 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70770
70771 -static void tasklet_action(struct softirq_action *a)
70772 +static void tasklet_action(void)
70773 {
70774 struct tasklet_struct *list;
70775
70776 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70777 }
70778 }
70779
70780 -static void tasklet_hi_action(struct softirq_action *a)
70781 +static void tasklet_hi_action(void)
70782 {
70783 struct tasklet_struct *list;
70784
70785 diff --git a/kernel/srcu.c b/kernel/srcu.c
70786 index 2095be3..9a5b89d 100644
70787 --- a/kernel/srcu.c
70788 +++ b/kernel/srcu.c
70789 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70790 preempt_disable();
70791 idx = rcu_dereference_index_check(sp->completed,
70792 rcu_read_lock_sched_held()) & 0x1;
70793 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70794 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70795 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70796 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70797 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70798 preempt_enable();
70799 return idx;
70800 }
70801 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70802 {
70803 preempt_disable();
70804 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70805 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70806 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70807 preempt_enable();
70808 }
70809 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70810 diff --git a/kernel/sys.c b/kernel/sys.c
70811 index 909148a..cd51acf 100644
70812 --- a/kernel/sys.c
70813 +++ b/kernel/sys.c
70814 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70815 error = -EACCES;
70816 goto out;
70817 }
70818 +
70819 + if (gr_handle_chroot_setpriority(p, niceval)) {
70820 + error = -EACCES;
70821 + goto out;
70822 + }
70823 +
70824 no_nice = security_task_setnice(p, niceval);
70825 if (no_nice) {
70826 error = no_nice;
70827 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70828 goto error;
70829 }
70830
70831 + if (gr_check_group_change(new->gid, new->egid, -1))
70832 + goto error;
70833 +
70834 if (rgid != (gid_t) -1 ||
70835 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70836 new->sgid = new->egid;
70837 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70838 old = current_cred();
70839
70840 retval = -EPERM;
70841 +
70842 + if (gr_check_group_change(kgid, kgid, kgid))
70843 + goto error;
70844 +
70845 if (nsown_capable(CAP_SETGID))
70846 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70847 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70848 @@ -647,7 +660,7 @@ error:
70849 /*
70850 * change the user struct in a credentials set to match the new UID
70851 */
70852 -static int set_user(struct cred *new)
70853 +int set_user(struct cred *new)
70854 {
70855 struct user_struct *new_user;
70856
70857 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70858 goto error;
70859 }
70860
70861 + if (gr_check_user_change(new->uid, new->euid, -1))
70862 + goto error;
70863 +
70864 if (!uid_eq(new->uid, old->uid)) {
70865 retval = set_user(new);
70866 if (retval < 0)
70867 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70868 old = current_cred();
70869
70870 retval = -EPERM;
70871 +
70872 + if (gr_check_crash_uid(kuid))
70873 + goto error;
70874 + if (gr_check_user_change(kuid, kuid, kuid))
70875 + goto error;
70876 +
70877 if (nsown_capable(CAP_SETUID)) {
70878 new->suid = new->uid = kuid;
70879 if (!uid_eq(kuid, old->uid)) {
70880 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70881 goto error;
70882 }
70883
70884 + if (gr_check_user_change(kruid, keuid, -1))
70885 + goto error;
70886 +
70887 if (ruid != (uid_t) -1) {
70888 new->uid = kruid;
70889 if (!uid_eq(kruid, old->uid)) {
70890 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70891 goto error;
70892 }
70893
70894 + if (gr_check_group_change(krgid, kegid, -1))
70895 + goto error;
70896 +
70897 if (rgid != (gid_t) -1)
70898 new->gid = krgid;
70899 if (egid != (gid_t) -1)
70900 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70901 if (!uid_valid(kuid))
70902 return old_fsuid;
70903
70904 + if (gr_check_user_change(-1, -1, kuid))
70905 + goto error;
70906 +
70907 new = prepare_creds();
70908 if (!new)
70909 return old_fsuid;
70910 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70911 }
70912 }
70913
70914 +error:
70915 abort_creds(new);
70916 return old_fsuid;
70917
70918 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70919 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70920 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70921 nsown_capable(CAP_SETGID)) {
70922 + if (gr_check_group_change(-1, -1, kgid))
70923 + goto error;
70924 +
70925 if (!gid_eq(kgid, old->fsgid)) {
70926 new->fsgid = kgid;
70927 goto change_okay;
70928 }
70929 }
70930
70931 +error:
70932 abort_creds(new);
70933 return old_fsgid;
70934
70935 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70936 return -EFAULT;
70937
70938 down_read(&uts_sem);
70939 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70940 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70941 __OLD_UTS_LEN);
70942 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70943 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70944 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70945 __OLD_UTS_LEN);
70946 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70947 - error |= __copy_to_user(&name->release, &utsname()->release,
70948 + error |= __copy_to_user(name->release, &utsname()->release,
70949 __OLD_UTS_LEN);
70950 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70951 - error |= __copy_to_user(&name->version, &utsname()->version,
70952 + error |= __copy_to_user(name->version, &utsname()->version,
70953 __OLD_UTS_LEN);
70954 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70955 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70956 + error |= __copy_to_user(name->machine, &utsname()->machine,
70957 __OLD_UTS_LEN);
70958 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70959 up_read(&uts_sem);
70960 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70961 error = get_dumpable(me->mm);
70962 break;
70963 case PR_SET_DUMPABLE:
70964 - if (arg2 < 0 || arg2 > 1) {
70965 + if (arg2 > 1) {
70966 error = -EINVAL;
70967 break;
70968 }
70969 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70970 index 87174ef..68cbb82 100644
70971 --- a/kernel/sysctl.c
70972 +++ b/kernel/sysctl.c
70973 @@ -92,7 +92,6 @@
70974
70975
70976 #if defined(CONFIG_SYSCTL)
70977 -
70978 /* External variables not in a header file. */
70979 extern int sysctl_overcommit_memory;
70980 extern int sysctl_overcommit_ratio;
70981 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70982 void __user *buffer, size_t *lenp, loff_t *ppos);
70983 #endif
70984
70985 -#ifdef CONFIG_PRINTK
70986 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70987 void __user *buffer, size_t *lenp, loff_t *ppos);
70988 -#endif
70989
70990 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70991 void __user *buffer, size_t *lenp, loff_t *ppos);
70992 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70993
70994 #endif
70995
70996 +extern struct ctl_table grsecurity_table[];
70997 +
70998 static struct ctl_table kern_table[];
70999 static struct ctl_table vm_table[];
71000 static struct ctl_table fs_table[];
71001 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
71002 int sysctl_legacy_va_layout;
71003 #endif
71004
71005 +#ifdef CONFIG_PAX_SOFTMODE
71006 +static ctl_table pax_table[] = {
71007 + {
71008 + .procname = "softmode",
71009 + .data = &pax_softmode,
71010 + .maxlen = sizeof(unsigned int),
71011 + .mode = 0600,
71012 + .proc_handler = &proc_dointvec,
71013 + },
71014 +
71015 + { }
71016 +};
71017 +#endif
71018 +
71019 /* The default sysctl tables: */
71020
71021 static struct ctl_table sysctl_base_table[] = {
71022 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
71023 #endif
71024
71025 static struct ctl_table kern_table[] = {
71026 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
71027 + {
71028 + .procname = "grsecurity",
71029 + .mode = 0500,
71030 + .child = grsecurity_table,
71031 + },
71032 +#endif
71033 +
71034 +#ifdef CONFIG_PAX_SOFTMODE
71035 + {
71036 + .procname = "pax",
71037 + .mode = 0500,
71038 + .child = pax_table,
71039 + },
71040 +#endif
71041 +
71042 {
71043 .procname = "sched_child_runs_first",
71044 .data = &sysctl_sched_child_runs_first,
71045 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
71046 .data = &modprobe_path,
71047 .maxlen = KMOD_PATH_LEN,
71048 .mode = 0644,
71049 - .proc_handler = proc_dostring,
71050 + .proc_handler = proc_dostring_modpriv,
71051 },
71052 {
71053 .procname = "modules_disabled",
71054 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
71055 .extra1 = &zero,
71056 .extra2 = &one,
71057 },
71058 +#endif
71059 {
71060 .procname = "kptr_restrict",
71061 .data = &kptr_restrict,
71062 .maxlen = sizeof(int),
71063 .mode = 0644,
71064 .proc_handler = proc_dointvec_minmax_sysadmin,
71065 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71066 + .extra1 = &two,
71067 +#else
71068 .extra1 = &zero,
71069 +#endif
71070 .extra2 = &two,
71071 },
71072 -#endif
71073 {
71074 .procname = "ngroups_max",
71075 .data = &ngroups_max,
71076 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
71077 .proc_handler = proc_dointvec_minmax,
71078 .extra1 = &zero,
71079 },
71080 + {
71081 + .procname = "heap_stack_gap",
71082 + .data = &sysctl_heap_stack_gap,
71083 + .maxlen = sizeof(sysctl_heap_stack_gap),
71084 + .mode = 0644,
71085 + .proc_handler = proc_doulongvec_minmax,
71086 + },
71087 #else
71088 {
71089 .procname = "nr_trim_pages",
71090 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
71091 buffer, lenp, ppos);
71092 }
71093
71094 +int proc_dostring_modpriv(struct ctl_table *table, int write,
71095 + void __user *buffer, size_t *lenp, loff_t *ppos)
71096 +{
71097 + if (write && !capable(CAP_SYS_MODULE))
71098 + return -EPERM;
71099 +
71100 + return _proc_do_string(table->data, table->maxlen, write,
71101 + buffer, lenp, ppos);
71102 +}
71103 +
71104 static size_t proc_skip_spaces(char **buf)
71105 {
71106 size_t ret;
71107 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
71108 len = strlen(tmp);
71109 if (len > *size)
71110 len = *size;
71111 + if (len > sizeof(tmp))
71112 + len = sizeof(tmp);
71113 if (copy_to_user(*buf, tmp, len))
71114 return -EFAULT;
71115 *size -= len;
71116 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
71117 return err;
71118 }
71119
71120 -#ifdef CONFIG_PRINTK
71121 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71122 void __user *buffer, size_t *lenp, loff_t *ppos)
71123 {
71124 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71125
71126 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
71127 }
71128 -#endif
71129
71130 struct do_proc_dointvec_minmax_conv_param {
71131 int *min;
71132 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
71133 *i = val;
71134 } else {
71135 val = convdiv * (*i) / convmul;
71136 - if (!first)
71137 + if (!first) {
71138 err = proc_put_char(&buffer, &left, '\t');
71139 + if (err)
71140 + break;
71141 + }
71142 err = proc_put_long(&buffer, &left, val, false);
71143 if (err)
71144 break;
71145 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
71146 return -ENOSYS;
71147 }
71148
71149 +int proc_dostring_modpriv(struct ctl_table *table, int write,
71150 + void __user *buffer, size_t *lenp, loff_t *ppos)
71151 +{
71152 + return -ENOSYS;
71153 +}
71154 +
71155 int proc_dointvec(struct ctl_table *table, int write,
71156 void __user *buffer, size_t *lenp, loff_t *ppos)
71157 {
71158 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
71159 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
71160 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
71161 EXPORT_SYMBOL(proc_dostring);
71162 +EXPORT_SYMBOL(proc_dostring_modpriv);
71163 EXPORT_SYMBOL(proc_doulongvec_minmax);
71164 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
71165 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
71166 index 65bdcf1..21eb831 100644
71167 --- a/kernel/sysctl_binary.c
71168 +++ b/kernel/sysctl_binary.c
71169 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
71170 int i;
71171
71172 set_fs(KERNEL_DS);
71173 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
71174 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
71175 set_fs(old_fs);
71176 if (result < 0)
71177 goto out_kfree;
71178 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
71179 }
71180
71181 set_fs(KERNEL_DS);
71182 - result = vfs_write(file, buffer, str - buffer, &pos);
71183 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
71184 set_fs(old_fs);
71185 if (result < 0)
71186 goto out_kfree;
71187 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
71188 int i;
71189
71190 set_fs(KERNEL_DS);
71191 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
71192 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
71193 set_fs(old_fs);
71194 if (result < 0)
71195 goto out_kfree;
71196 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
71197 }
71198
71199 set_fs(KERNEL_DS);
71200 - result = vfs_write(file, buffer, str - buffer, &pos);
71201 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
71202 set_fs(old_fs);
71203 if (result < 0)
71204 goto out_kfree;
71205 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
71206 int i;
71207
71208 set_fs(KERNEL_DS);
71209 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
71210 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
71211 set_fs(old_fs);
71212 if (result < 0)
71213 goto out;
71214 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
71215 __le16 dnaddr;
71216
71217 set_fs(KERNEL_DS);
71218 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
71219 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
71220 set_fs(old_fs);
71221 if (result < 0)
71222 goto out;
71223 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
71224 le16_to_cpu(dnaddr) & 0x3ff);
71225
71226 set_fs(KERNEL_DS);
71227 - result = vfs_write(file, buf, len, &pos);
71228 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
71229 set_fs(old_fs);
71230 if (result < 0)
71231 goto out;
71232 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
71233 index d0a3279..db0ad99 100644
71234 --- a/kernel/taskstats.c
71235 +++ b/kernel/taskstats.c
71236 @@ -27,9 +27,12 @@
71237 #include <linux/cgroup.h>
71238 #include <linux/fs.h>
71239 #include <linux/file.h>
71240 +#include <linux/grsecurity.h>
71241 #include <net/genetlink.h>
71242 #include <linux/atomic.h>
71243
71244 +extern int gr_is_taskstats_denied(int pid);
71245 +
71246 /*
71247 * Maximum length of a cpumask that can be specified in
71248 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
71249 @@ -561,6 +564,9 @@ err:
71250
71251 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
71252 {
71253 + if (gr_is_taskstats_denied(current->pid))
71254 + return -EACCES;
71255 +
71256 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
71257 return cmd_attr_register_cpumask(info);
71258 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
71259 diff --git a/kernel/time.c b/kernel/time.c
71260 index ba744cf..267b7c5 100644
71261 --- a/kernel/time.c
71262 +++ b/kernel/time.c
71263 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
71264 return error;
71265
71266 if (tz) {
71267 + /* we log in do_settimeofday called below, so don't log twice
71268 + */
71269 + if (!tv)
71270 + gr_log_timechange();
71271 +
71272 sys_tz = *tz;
71273 update_vsyscall_tz();
71274 if (firsttime) {
71275 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
71276 index aa27d39..34d221c 100644
71277 --- a/kernel/time/alarmtimer.c
71278 +++ b/kernel/time/alarmtimer.c
71279 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
71280 struct platform_device *pdev;
71281 int error = 0;
71282 int i;
71283 - struct k_clock alarm_clock = {
71284 + static struct k_clock alarm_clock = {
71285 .clock_getres = alarm_clock_getres,
71286 .clock_get = alarm_clock_get,
71287 .timer_create = alarm_timer_create,
71288 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
71289 index f113755..ec24223 100644
71290 --- a/kernel/time/tick-broadcast.c
71291 +++ b/kernel/time/tick-broadcast.c
71292 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
71293 * then clear the broadcast bit.
71294 */
71295 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
71296 - int cpu = smp_processor_id();
71297 + cpu = smp_processor_id();
71298
71299 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
71300 tick_broadcast_clear_oneshot(cpu);
71301 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
71302 index f791637..00051de 100644
71303 --- a/kernel/time/timekeeping.c
71304 +++ b/kernel/time/timekeeping.c
71305 @@ -14,6 +14,7 @@
71306 #include <linux/init.h>
71307 #include <linux/mm.h>
71308 #include <linux/sched.h>
71309 +#include <linux/grsecurity.h>
71310 #include <linux/syscore_ops.h>
71311 #include <linux/clocksource.h>
71312 #include <linux/jiffies.h>
71313 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
71314 if (!timespec_valid_strict(tv))
71315 return -EINVAL;
71316
71317 + gr_log_timechange();
71318 +
71319 write_seqlock_irqsave(&tk->lock, flags);
71320
71321 timekeeping_forward_now(tk);
71322 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
71323 index af5a7e9..715611a 100644
71324 --- a/kernel/time/timer_list.c
71325 +++ b/kernel/time/timer_list.c
71326 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
71327
71328 static void print_name_offset(struct seq_file *m, void *sym)
71329 {
71330 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71331 + SEQ_printf(m, "<%p>", NULL);
71332 +#else
71333 char symname[KSYM_NAME_LEN];
71334
71335 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
71336 SEQ_printf(m, "<%pK>", sym);
71337 else
71338 SEQ_printf(m, "%s", symname);
71339 +#endif
71340 }
71341
71342 static void
71343 @@ -112,7 +116,11 @@ next_one:
71344 static void
71345 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
71346 {
71347 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71348 + SEQ_printf(m, " .base: %p\n", NULL);
71349 +#else
71350 SEQ_printf(m, " .base: %pK\n", base);
71351 +#endif
71352 SEQ_printf(m, " .index: %d\n",
71353 base->index);
71354 SEQ_printf(m, " .resolution: %Lu nsecs\n",
71355 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
71356 {
71357 struct proc_dir_entry *pe;
71358
71359 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71360 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
71361 +#else
71362 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
71363 +#endif
71364 if (!pe)
71365 return -ENOMEM;
71366 return 0;
71367 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
71368 index 0b537f2..40d6c20 100644
71369 --- a/kernel/time/timer_stats.c
71370 +++ b/kernel/time/timer_stats.c
71371 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
71372 static unsigned long nr_entries;
71373 static struct entry entries[MAX_ENTRIES];
71374
71375 -static atomic_t overflow_count;
71376 +static atomic_unchecked_t overflow_count;
71377
71378 /*
71379 * The entries are in a hash-table, for fast lookup:
71380 @@ -140,7 +140,7 @@ static void reset_entries(void)
71381 nr_entries = 0;
71382 memset(entries, 0, sizeof(entries));
71383 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
71384 - atomic_set(&overflow_count, 0);
71385 + atomic_set_unchecked(&overflow_count, 0);
71386 }
71387
71388 static struct entry *alloc_entry(void)
71389 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71390 if (likely(entry))
71391 entry->count++;
71392 else
71393 - atomic_inc(&overflow_count);
71394 + atomic_inc_unchecked(&overflow_count);
71395
71396 out_unlock:
71397 raw_spin_unlock_irqrestore(lock, flags);
71398 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71399
71400 static void print_name_offset(struct seq_file *m, unsigned long addr)
71401 {
71402 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71403 + seq_printf(m, "<%p>", NULL);
71404 +#else
71405 char symname[KSYM_NAME_LEN];
71406
71407 if (lookup_symbol_name(addr, symname) < 0)
71408 - seq_printf(m, "<%p>", (void *)addr);
71409 + seq_printf(m, "<%pK>", (void *)addr);
71410 else
71411 seq_printf(m, "%s", symname);
71412 +#endif
71413 }
71414
71415 static int tstats_show(struct seq_file *m, void *v)
71416 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
71417
71418 seq_puts(m, "Timer Stats Version: v0.2\n");
71419 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
71420 - if (atomic_read(&overflow_count))
71421 + if (atomic_read_unchecked(&overflow_count))
71422 seq_printf(m, "Overflow: %d entries\n",
71423 - atomic_read(&overflow_count));
71424 + atomic_read_unchecked(&overflow_count));
71425
71426 for (i = 0; i < nr_entries; i++) {
71427 entry = entries + i;
71428 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
71429 {
71430 struct proc_dir_entry *pe;
71431
71432 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71433 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
71434 +#else
71435 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
71436 +#endif
71437 if (!pe)
71438 return -ENOMEM;
71439 return 0;
71440 diff --git a/kernel/timer.c b/kernel/timer.c
71441 index 46ef2b1..ad081f144 100644
71442 --- a/kernel/timer.c
71443 +++ b/kernel/timer.c
71444 @@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
71445 /*
71446 * This function runs timers and the timer-tq in bottom half context.
71447 */
71448 -static void run_timer_softirq(struct softirq_action *h)
71449 +static void run_timer_softirq(void)
71450 {
71451 struct tvec_base *base = __this_cpu_read(tvec_bases);
71452
71453 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
71454 index c0bd030..62a1927 100644
71455 --- a/kernel/trace/blktrace.c
71456 +++ b/kernel/trace/blktrace.c
71457 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
71458 struct blk_trace *bt = filp->private_data;
71459 char buf[16];
71460
71461 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
71462 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
71463
71464 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
71465 }
71466 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
71467 return 1;
71468
71469 bt = buf->chan->private_data;
71470 - atomic_inc(&bt->dropped);
71471 + atomic_inc_unchecked(&bt->dropped);
71472 return 0;
71473 }
71474
71475 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71476
71477 bt->dir = dir;
71478 bt->dev = dev;
71479 - atomic_set(&bt->dropped, 0);
71480 + atomic_set_unchecked(&bt->dropped, 0);
71481
71482 ret = -EIO;
71483 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71484 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71485 index b4f20fb..483c5fa 100644
71486 --- a/kernel/trace/ftrace.c
71487 +++ b/kernel/trace/ftrace.c
71488 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71489 if (unlikely(ftrace_disabled))
71490 return 0;
71491
71492 + ret = ftrace_arch_code_modify_prepare();
71493 + FTRACE_WARN_ON(ret);
71494 + if (ret)
71495 + return 0;
71496 +
71497 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71498 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71499 if (ret) {
71500 ftrace_bug(ret, ip);
71501 - return 0;
71502 }
71503 - return 1;
71504 + return ret ? 0 : 1;
71505 }
71506
71507 /*
71508 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71509
71510 int
71511 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71512 - void *data)
71513 + void *data)
71514 {
71515 struct ftrace_func_probe *entry;
71516 struct ftrace_page *pg;
71517 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
71518 if (!count)
71519 return 0;
71520
71521 + pax_open_kernel();
71522 sort(start, count, sizeof(*start),
71523 ftrace_cmp_ips, ftrace_swap_ips);
71524 + pax_close_kernel();
71525
71526 start_pg = ftrace_allocate_pages(count);
71527 if (!start_pg)
71528 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71529 index 5c38c81..88012af 100644
71530 --- a/kernel/trace/trace.c
71531 +++ b/kernel/trace/trace.c
71532 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71533 };
71534 #endif
71535
71536 -static struct dentry *d_tracer;
71537 -
71538 struct dentry *tracing_init_dentry(void)
71539 {
71540 + static struct dentry *d_tracer;
71541 static int once;
71542
71543 if (d_tracer)
71544 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
71545 return d_tracer;
71546 }
71547
71548 -static struct dentry *d_percpu;
71549 -
71550 struct dentry *tracing_dentry_percpu(void)
71551 {
71552 + static struct dentry *d_percpu;
71553 static int once;
71554 struct dentry *d_tracer;
71555
71556 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71557 index 29111da..d190fe2 100644
71558 --- a/kernel/trace/trace_events.c
71559 +++ b/kernel/trace/trace_events.c
71560 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
71561 struct ftrace_module_file_ops {
71562 struct list_head list;
71563 struct module *mod;
71564 - struct file_operations id;
71565 - struct file_operations enable;
71566 - struct file_operations format;
71567 - struct file_operations filter;
71568 };
71569
71570 static struct ftrace_module_file_ops *
71571 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
71572
71573 file_ops->mod = mod;
71574
71575 - file_ops->id = ftrace_event_id_fops;
71576 - file_ops->id.owner = mod;
71577 -
71578 - file_ops->enable = ftrace_enable_fops;
71579 - file_ops->enable.owner = mod;
71580 -
71581 - file_ops->filter = ftrace_event_filter_fops;
71582 - file_ops->filter.owner = mod;
71583 -
71584 - file_ops->format = ftrace_event_format_fops;
71585 - file_ops->format.owner = mod;
71586 + pax_open_kernel();
71587 + *(void **)&mod->trace_id.owner = mod;
71588 + *(void **)&mod->trace_enable.owner = mod;
71589 + *(void **)&mod->trace_filter.owner = mod;
71590 + *(void **)&mod->trace_format.owner = mod;
71591 + pax_close_kernel();
71592
71593 list_add(&file_ops->list, &ftrace_module_file_list);
71594
71595 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
71596
71597 for_each_event(call, start, end) {
71598 __trace_add_event_call(*call, mod,
71599 - &file_ops->id, &file_ops->enable,
71600 - &file_ops->filter, &file_ops->format);
71601 + &mod->trace_id, &mod->trace_enable,
71602 + &mod->trace_filter, &mod->trace_format);
71603 }
71604 }
71605
71606 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71607 index fd3c8aa..5f324a6 100644
71608 --- a/kernel/trace/trace_mmiotrace.c
71609 +++ b/kernel/trace/trace_mmiotrace.c
71610 @@ -24,7 +24,7 @@ struct header_iter {
71611 static struct trace_array *mmio_trace_array;
71612 static bool overrun_detected;
71613 static unsigned long prev_overruns;
71614 -static atomic_t dropped_count;
71615 +static atomic_unchecked_t dropped_count;
71616
71617 static void mmio_reset_data(struct trace_array *tr)
71618 {
71619 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71620
71621 static unsigned long count_overruns(struct trace_iterator *iter)
71622 {
71623 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71624 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71625 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71626
71627 if (over > prev_overruns)
71628 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71629 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71630 sizeof(*entry), 0, pc);
71631 if (!event) {
71632 - atomic_inc(&dropped_count);
71633 + atomic_inc_unchecked(&dropped_count);
71634 return;
71635 }
71636 entry = ring_buffer_event_data(event);
71637 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71638 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71639 sizeof(*entry), 0, pc);
71640 if (!event) {
71641 - atomic_inc(&dropped_count);
71642 + atomic_inc_unchecked(&dropped_count);
71643 return;
71644 }
71645 entry = ring_buffer_event_data(event);
71646 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71647 index 123b189..97b81f5 100644
71648 --- a/kernel/trace/trace_output.c
71649 +++ b/kernel/trace/trace_output.c
71650 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71651
71652 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71653 if (!IS_ERR(p)) {
71654 - p = mangle_path(s->buffer + s->len, p, "\n");
71655 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71656 if (p) {
71657 s->len = p - s->buffer;
71658 return 1;
71659 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71660 index d4545f4..a9010a1 100644
71661 --- a/kernel/trace/trace_stack.c
71662 +++ b/kernel/trace/trace_stack.c
71663 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71664 return;
71665
71666 /* we do not handle interrupt stacks yet */
71667 - if (!object_is_on_stack(&this_size))
71668 + if (!object_starts_on_stack(&this_size))
71669 return;
71670
71671 local_irq_save(flags);
71672 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71673 index 872bd6d..31601a2 100644
71674 --- a/kernel/workqueue.c
71675 +++ b/kernel/workqueue.c
71676 @@ -1422,7 +1422,7 @@ retry:
71677 /* morph UNBOUND to REBIND atomically */
71678 worker_flags &= ~WORKER_UNBOUND;
71679 worker_flags |= WORKER_REBIND;
71680 - ACCESS_ONCE(worker->flags) = worker_flags;
71681 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71682
71683 idle_rebind.cnt++;
71684 worker->idle_rebind = &idle_rebind;
71685 @@ -1448,7 +1448,7 @@ retry:
71686 /* morph UNBOUND to REBIND atomically */
71687 worker_flags &= ~WORKER_UNBOUND;
71688 worker_flags |= WORKER_REBIND;
71689 - ACCESS_ONCE(worker->flags) = worker_flags;
71690 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71691
71692 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71693 work_data_bits(rebind_work)))
71694 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71695 index 2403a63..5c4be4c 100644
71696 --- a/lib/Kconfig.debug
71697 +++ b/lib/Kconfig.debug
71698 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71699 depends on DEBUG_KERNEL
71700 depends on STACKTRACE_SUPPORT
71701 depends on PROC_FS
71702 + depends on !GRKERNSEC_HIDESYM
71703 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71704 select KALLSYMS
71705 select KALLSYMS_ALL
71706 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71707
71708 config PROVIDE_OHCI1394_DMA_INIT
71709 bool "Remote debugging over FireWire early on boot"
71710 - depends on PCI && X86
71711 + depends on PCI && X86 && !GRKERNSEC
71712 help
71713 If you want to debug problems which hang or crash the kernel early
71714 on boot and the crashing machine has a FireWire port, you can use
71715 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71716
71717 config FIREWIRE_OHCI_REMOTE_DMA
71718 bool "Remote debugging over FireWire with firewire-ohci"
71719 - depends on FIREWIRE_OHCI
71720 + depends on FIREWIRE_OHCI && !GRKERNSEC
71721 help
71722 This option lets you use the FireWire bus for remote debugging
71723 with help of the firewire-ohci driver. It enables unfiltered
71724 diff --git a/lib/bitmap.c b/lib/bitmap.c
71725 index 06fdfa1..97c5c7d 100644
71726 --- a/lib/bitmap.c
71727 +++ b/lib/bitmap.c
71728 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71729 {
71730 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71731 u32 chunk;
71732 - const char __user __force *ubuf = (const char __user __force *)buf;
71733 + const char __user *ubuf = (const char __force_user *)buf;
71734
71735 bitmap_zero(maskp, nmaskbits);
71736
71737 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71738 {
71739 if (!access_ok(VERIFY_READ, ubuf, ulen))
71740 return -EFAULT;
71741 - return __bitmap_parse((const char __force *)ubuf,
71742 + return __bitmap_parse((const char __force_kernel *)ubuf,
71743 ulen, 1, maskp, nmaskbits);
71744
71745 }
71746 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71747 {
71748 unsigned a, b;
71749 int c, old_c, totaldigits;
71750 - const char __user __force *ubuf = (const char __user __force *)buf;
71751 + const char __user *ubuf = (const char __force_user *)buf;
71752 int exp_digit, in_range;
71753
71754 totaldigits = c = 0;
71755 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71756 {
71757 if (!access_ok(VERIFY_READ, ubuf, ulen))
71758 return -EFAULT;
71759 - return __bitmap_parselist((const char __force *)ubuf,
71760 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71761 ulen, 1, maskp, nmaskbits);
71762 }
71763 EXPORT_SYMBOL(bitmap_parselist_user);
71764 diff --git a/lib/bug.c b/lib/bug.c
71765 index a28c141..2bd3d95 100644
71766 --- a/lib/bug.c
71767 +++ b/lib/bug.c
71768 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71769 return BUG_TRAP_TYPE_NONE;
71770
71771 bug = find_bug(bugaddr);
71772 + if (!bug)
71773 + return BUG_TRAP_TYPE_NONE;
71774
71775 file = NULL;
71776 line = 0;
71777 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71778 index d11808c..dc2d6f8 100644
71779 --- a/lib/debugobjects.c
71780 +++ b/lib/debugobjects.c
71781 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71782 if (limit > 4)
71783 return;
71784
71785 - is_on_stack = object_is_on_stack(addr);
71786 + is_on_stack = object_starts_on_stack(addr);
71787 if (is_on_stack == onstack)
71788 return;
71789
71790 diff --git a/lib/devres.c b/lib/devres.c
71791 index 80b9c76..9e32279 100644
71792 --- a/lib/devres.c
71793 +++ b/lib/devres.c
71794 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71795 void devm_iounmap(struct device *dev, void __iomem *addr)
71796 {
71797 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71798 - (void *)addr));
71799 + (void __force *)addr));
71800 iounmap(addr);
71801 }
71802 EXPORT_SYMBOL(devm_iounmap);
71803 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71804 {
71805 ioport_unmap(addr);
71806 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71807 - devm_ioport_map_match, (void *)addr));
71808 + devm_ioport_map_match, (void __force *)addr));
71809 }
71810 EXPORT_SYMBOL(devm_ioport_unmap);
71811
71812 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71813 index 66ce414..6f0a0dd 100644
71814 --- a/lib/dma-debug.c
71815 +++ b/lib/dma-debug.c
71816 @@ -924,7 +924,7 @@ out:
71817
71818 static void check_for_stack(struct device *dev, void *addr)
71819 {
71820 - if (object_is_on_stack(addr))
71821 + if (object_starts_on_stack(addr))
71822 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71823 "stack [addr=%p]\n", addr);
71824 }
71825 diff --git a/lib/inflate.c b/lib/inflate.c
71826 index 013a761..c28f3fc 100644
71827 --- a/lib/inflate.c
71828 +++ b/lib/inflate.c
71829 @@ -269,7 +269,7 @@ static void free(void *where)
71830 malloc_ptr = free_mem_ptr;
71831 }
71832 #else
71833 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71834 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71835 #define free(a) kfree(a)
71836 #endif
71837
71838 diff --git a/lib/ioremap.c b/lib/ioremap.c
71839 index 0c9216c..863bd89 100644
71840 --- a/lib/ioremap.c
71841 +++ b/lib/ioremap.c
71842 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71843 unsigned long next;
71844
71845 phys_addr -= addr;
71846 - pmd = pmd_alloc(&init_mm, pud, addr);
71847 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71848 if (!pmd)
71849 return -ENOMEM;
71850 do {
71851 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71852 unsigned long next;
71853
71854 phys_addr -= addr;
71855 - pud = pud_alloc(&init_mm, pgd, addr);
71856 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71857 if (!pud)
71858 return -ENOMEM;
71859 do {
71860 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71861 index bd2bea9..6b3c95e 100644
71862 --- a/lib/is_single_threaded.c
71863 +++ b/lib/is_single_threaded.c
71864 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71865 struct task_struct *p, *t;
71866 bool ret;
71867
71868 + if (!mm)
71869 + return true;
71870 +
71871 if (atomic_read(&task->signal->live) != 1)
71872 return false;
71873
71874 diff --git a/lib/list_debug.c b/lib/list_debug.c
71875 index c24c2f7..bef49ee 100644
71876 --- a/lib/list_debug.c
71877 +++ b/lib/list_debug.c
71878 @@ -23,17 +23,19 @@ void __list_add(struct list_head *new,
71879 struct list_head *prev,
71880 struct list_head *next)
71881 {
71882 - WARN(next->prev != prev,
71883 + if (WARN(next->prev != prev,
71884 "list_add corruption. next->prev should be "
71885 "prev (%p), but was %p. (next=%p).\n",
71886 - prev, next->prev, next);
71887 - WARN(prev->next != next,
71888 + prev, next->prev, next) ||
71889 + WARN(prev->next != next,
71890 "list_add corruption. prev->next should be "
71891 "next (%p), but was %p. (prev=%p).\n",
71892 - next, prev->next, prev);
71893 - WARN(new == prev || new == next,
71894 + next, prev->next, prev) ||
71895 + WARN(new == prev || new == next,
71896 "list_add double add: new=%p, prev=%p, next=%p.\n",
71897 - new, prev, next);
71898 + new, prev, next))
71899 + return;
71900 +
71901 next->prev = new;
71902 new->next = next;
71903 new->prev = prev;
71904 @@ -86,12 +88,14 @@ EXPORT_SYMBOL(list_del);
71905 void __list_add_rcu(struct list_head *new,
71906 struct list_head *prev, struct list_head *next)
71907 {
71908 - WARN(next->prev != prev,
71909 + if (WARN(next->prev != prev,
71910 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
71911 - prev, next->prev, next);
71912 - WARN(prev->next != next,
71913 + prev, next->prev, next) ||
71914 + WARN(prev->next != next,
71915 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
71916 - next, prev->next, prev);
71917 + next, prev->next, prev))
71918 + return;
71919 +
71920 new->next = next;
71921 new->prev = prev;
71922 rcu_assign_pointer(list_next_rcu(prev), new);
71923 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71924 index e796429..6e38f9f 100644
71925 --- a/lib/radix-tree.c
71926 +++ b/lib/radix-tree.c
71927 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71928 int nr;
71929 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71930 };
71931 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71932 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71933
71934 static inline void *ptr_to_indirect(void *ptr)
71935 {
71936 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
71937 index bb2b201..46abaf9 100644
71938 --- a/lib/strncpy_from_user.c
71939 +++ b/lib/strncpy_from_user.c
71940 @@ -21,7 +21,7 @@
71941 */
71942 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
71943 {
71944 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71945 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71946 long res = 0;
71947
71948 /*
71949 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
71950 index a28df52..3d55877 100644
71951 --- a/lib/strnlen_user.c
71952 +++ b/lib/strnlen_user.c
71953 @@ -26,7 +26,7 @@
71954 */
71955 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
71956 {
71957 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71958 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71959 long align, res = 0;
71960 unsigned long c;
71961
71962 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71963 index 0e33754..50a0e63 100644
71964 --- a/lib/vsprintf.c
71965 +++ b/lib/vsprintf.c
71966 @@ -16,6 +16,9 @@
71967 * - scnprintf and vscnprintf
71968 */
71969
71970 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71971 +#define __INCLUDED_BY_HIDESYM 1
71972 +#endif
71973 #include <stdarg.h>
71974 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71975 #include <linux/types.h>
71976 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71977 char sym[KSYM_SYMBOL_LEN];
71978 if (ext == 'B')
71979 sprint_backtrace(sym, value);
71980 - else if (ext != 'f' && ext != 's')
71981 + else if (ext != 'f' && ext != 's' && ext != 'a')
71982 sprint_symbol(sym, value);
71983 else
71984 sprint_symbol_no_offset(sym, value);
71985 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71986 return number(buf, end, *(const netdev_features_t *)addr, spec);
71987 }
71988
71989 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71990 +int kptr_restrict __read_mostly = 2;
71991 +#else
71992 int kptr_restrict __read_mostly;
71993 +#endif
71994
71995 /*
71996 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71997 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71998 * - 'S' For symbolic direct pointers with offset
71999 * - 's' For symbolic direct pointers without offset
72000 * - 'B' For backtraced symbolic direct pointers with offset
72001 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
72002 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
72003 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
72004 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
72005 * - 'M' For a 6-byte MAC address, it prints the address in the
72006 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72007
72008 if (!ptr && *fmt != 'K') {
72009 /*
72010 - * Print (null) with the same width as a pointer so it makes
72011 + * Print (nil) with the same width as a pointer so it makes
72012 * tabular output look nice.
72013 */
72014 if (spec.field_width == -1)
72015 spec.field_width = default_width;
72016 - return string(buf, end, "(null)", spec);
72017 + return string(buf, end, "(nil)", spec);
72018 }
72019
72020 switch (*fmt) {
72021 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72022 /* Fallthrough */
72023 case 'S':
72024 case 's':
72025 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72026 + break;
72027 +#else
72028 + return symbol_string(buf, end, ptr, spec, *fmt);
72029 +#endif
72030 + case 'A':
72031 + case 'a':
72032 case 'B':
72033 return symbol_string(buf, end, ptr, spec, *fmt);
72034 case 'R':
72035 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72036 va_end(va);
72037 return buf;
72038 }
72039 + case 'P':
72040 + break;
72041 case 'K':
72042 /*
72043 * %pK cannot be used in IRQ context because its test
72044 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72045 }
72046 break;
72047 }
72048 +
72049 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72050 + /* 'P' = approved pointers to copy to userland,
72051 + as in the /proc/kallsyms case, as we make it display nothing
72052 + for non-root users, and the real contents for root users
72053 + Also ignore 'K' pointers, since we force their NULLing for non-root users
72054 + above
72055 + */
72056 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
72057 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
72058 + dump_stack();
72059 + ptr = NULL;
72060 + }
72061 +#endif
72062 +
72063 spec.flags |= SMALL;
72064 if (spec.field_width == -1) {
72065 spec.field_width = default_width;
72066 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
72067 typeof(type) value; \
72068 if (sizeof(type) == 8) { \
72069 args = PTR_ALIGN(args, sizeof(u32)); \
72070 - *(u32 *)&value = *(u32 *)args; \
72071 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
72072 + *(u32 *)&value = *(const u32 *)args; \
72073 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
72074 } else { \
72075 args = PTR_ALIGN(args, sizeof(type)); \
72076 - value = *(typeof(type) *)args; \
72077 + value = *(const typeof(type) *)args; \
72078 } \
72079 args += sizeof(type); \
72080 value; \
72081 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
72082 case FORMAT_TYPE_STR: {
72083 const char *str_arg = args;
72084 args += strlen(str_arg) + 1;
72085 - str = string(str, end, (char *)str_arg, spec);
72086 + str = string(str, end, str_arg, spec);
72087 break;
72088 }
72089
72090 diff --git a/localversion-grsec b/localversion-grsec
72091 new file mode 100644
72092 index 0000000..7cd6065
72093 --- /dev/null
72094 +++ b/localversion-grsec
72095 @@ -0,0 +1 @@
72096 +-grsec
72097 diff --git a/mm/Kconfig b/mm/Kconfig
72098 index d5c8019..f513038 100644
72099 --- a/mm/Kconfig
72100 +++ b/mm/Kconfig
72101 @@ -251,10 +251,10 @@ config KSM
72102 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
72103
72104 config DEFAULT_MMAP_MIN_ADDR
72105 - int "Low address space to protect from user allocation"
72106 + int "Low address space to protect from user allocation"
72107 depends on MMU
72108 - default 4096
72109 - help
72110 + default 65536
72111 + help
72112 This is the portion of low virtual memory which should be protected
72113 from userspace allocation. Keeping a user from writing to low pages
72114 can help reduce the impact of kernel NULL pointer bugs.
72115 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
72116
72117 config HWPOISON_INJECT
72118 tristate "HWPoison pages injector"
72119 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
72120 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
72121 select PROC_PAGE_MONITOR
72122
72123 config NOMMU_INITIAL_TRIM_EXCESS
72124 diff --git a/mm/filemap.c b/mm/filemap.c
72125 index 3843445..4fe6833 100644
72126 --- a/mm/filemap.c
72127 +++ b/mm/filemap.c
72128 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
72129 struct address_space *mapping = file->f_mapping;
72130
72131 if (!mapping->a_ops->readpage)
72132 - return -ENOEXEC;
72133 + return -ENODEV;
72134 file_accessed(file);
72135 vma->vm_ops = &generic_file_vm_ops;
72136 vma->vm_flags |= VM_CAN_NONLINEAR;
72137 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
72138 *pos = i_size_read(inode);
72139
72140 if (limit != RLIM_INFINITY) {
72141 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
72142 if (*pos >= limit) {
72143 send_sig(SIGXFSZ, current, 0);
72144 return -EFBIG;
72145 diff --git a/mm/fremap.c b/mm/fremap.c
72146 index 9ed4fd4..c42648d 100644
72147 --- a/mm/fremap.c
72148 +++ b/mm/fremap.c
72149 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
72150 retry:
72151 vma = find_vma(mm, start);
72152
72153 +#ifdef CONFIG_PAX_SEGMEXEC
72154 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
72155 + goto out;
72156 +#endif
72157 +
72158 /*
72159 * Make sure the vma is shared, that it supports prefaulting,
72160 * and that the remapped range is valid and fully within
72161 diff --git a/mm/highmem.c b/mm/highmem.c
72162 index d517cd1..9568fec 100644
72163 --- a/mm/highmem.c
72164 +++ b/mm/highmem.c
72165 @@ -98,7 +98,7 @@ struct page *kmap_to_page(void *vaddr)
72166 {
72167 unsigned long addr = (unsigned long)vaddr;
72168
72169 - if (addr >= PKMAP_ADDR(0) && addr <= PKMAP_ADDR(LAST_PKMAP)) {
72170 + if (addr >= PKMAP_ADDR(0) && addr < PKMAP_ADDR(LAST_PKMAP)) {
72171 int i = (addr - PKMAP_ADDR(0)) >> PAGE_SHIFT;
72172 return pte_page(pkmap_page_table[i]);
72173 }
72174 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
72175 * So no dangers, even with speculative execution.
72176 */
72177 page = pte_page(pkmap_page_table[i]);
72178 + pax_open_kernel();
72179 pte_clear(&init_mm, (unsigned long)page_address(page),
72180 &pkmap_page_table[i]);
72181 -
72182 + pax_close_kernel();
72183 set_page_address(page, NULL);
72184 need_flush = 1;
72185 }
72186 @@ -198,9 +199,11 @@ start:
72187 }
72188 }
72189 vaddr = PKMAP_ADDR(last_pkmap_nr);
72190 +
72191 + pax_open_kernel();
72192 set_pte_at(&init_mm, vaddr,
72193 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
72194 -
72195 + pax_close_kernel();
72196 pkmap_count[last_pkmap_nr] = 1;
72197 set_page_address(page, (void *)vaddr);
72198
72199 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
72200 index 141dbb6..ebff057 100644
72201 --- a/mm/huge_memory.c
72202 +++ b/mm/huge_memory.c
72203 @@ -735,7 +735,7 @@ out:
72204 * run pte_offset_map on the pmd, if an huge pmd could
72205 * materialize from under us from a different thread.
72206 */
72207 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
72208 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72209 return VM_FAULT_OOM;
72210 /* if an huge pmd materialized from under us just retry later */
72211 if (unlikely(pmd_trans_huge(*pmd)))
72212 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
72213 index 3adceaf..dccfea3 100644
72214 --- a/mm/hugetlb.c
72215 +++ b/mm/hugetlb.c
72216 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
72217 return 1;
72218 }
72219
72220 +#ifdef CONFIG_PAX_SEGMEXEC
72221 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
72222 +{
72223 + struct mm_struct *mm = vma->vm_mm;
72224 + struct vm_area_struct *vma_m;
72225 + unsigned long address_m;
72226 + pte_t *ptep_m;
72227 +
72228 + vma_m = pax_find_mirror_vma(vma);
72229 + if (!vma_m)
72230 + return;
72231 +
72232 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72233 + address_m = address + SEGMEXEC_TASK_SIZE;
72234 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
72235 + get_page(page_m);
72236 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
72237 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
72238 +}
72239 +#endif
72240 +
72241 /*
72242 * Hugetlb_cow() should be called with page lock of the original hugepage held.
72243 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
72244 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
72245 make_huge_pte(vma, new_page, 1));
72246 page_remove_rmap(old_page);
72247 hugepage_add_new_anon_rmap(new_page, vma, address);
72248 +
72249 +#ifdef CONFIG_PAX_SEGMEXEC
72250 + pax_mirror_huge_pte(vma, address, new_page);
72251 +#endif
72252 +
72253 /* Make the old page be freed below */
72254 new_page = old_page;
72255 mmu_notifier_invalidate_range_end(mm,
72256 @@ -2786,6 +2812,10 @@ retry:
72257 && (vma->vm_flags & VM_SHARED)));
72258 set_huge_pte_at(mm, address, ptep, new_pte);
72259
72260 +#ifdef CONFIG_PAX_SEGMEXEC
72261 + pax_mirror_huge_pte(vma, address, page);
72262 +#endif
72263 +
72264 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
72265 /* Optimization, do the COW without a second fault */
72266 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
72267 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72268 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
72269 struct hstate *h = hstate_vma(vma);
72270
72271 +#ifdef CONFIG_PAX_SEGMEXEC
72272 + struct vm_area_struct *vma_m;
72273 +#endif
72274 +
72275 address &= huge_page_mask(h);
72276
72277 ptep = huge_pte_offset(mm, address);
72278 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72279 VM_FAULT_SET_HINDEX(hstate_index(h));
72280 }
72281
72282 +#ifdef CONFIG_PAX_SEGMEXEC
72283 + vma_m = pax_find_mirror_vma(vma);
72284 + if (vma_m) {
72285 + unsigned long address_m;
72286 +
72287 + if (vma->vm_start > vma_m->vm_start) {
72288 + address_m = address;
72289 + address -= SEGMEXEC_TASK_SIZE;
72290 + vma = vma_m;
72291 + h = hstate_vma(vma);
72292 + } else
72293 + address_m = address + SEGMEXEC_TASK_SIZE;
72294 +
72295 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
72296 + return VM_FAULT_OOM;
72297 + address_m &= HPAGE_MASK;
72298 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
72299 + }
72300 +#endif
72301 +
72302 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
72303 if (!ptep)
72304 return VM_FAULT_OOM;
72305 diff --git a/mm/internal.h b/mm/internal.h
72306 index b8c91b3..93e95a3 100644
72307 --- a/mm/internal.h
72308 +++ b/mm/internal.h
72309 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
72310 * in mm/page_alloc.c
72311 */
72312 extern void __free_pages_bootmem(struct page *page, unsigned int order);
72313 +extern void free_compound_page(struct page *page);
72314 extern void prep_compound_page(struct page *page, unsigned long order);
72315 #ifdef CONFIG_MEMORY_FAILURE
72316 extern bool is_free_buddy_page(struct page *page);
72317 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
72318 index 45eb621..6ccd8ea 100644
72319 --- a/mm/kmemleak.c
72320 +++ b/mm/kmemleak.c
72321 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
72322
72323 for (i = 0; i < object->trace_len; i++) {
72324 void *ptr = (void *)object->trace[i];
72325 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
72326 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
72327 }
72328 }
72329
72330 diff --git a/mm/maccess.c b/mm/maccess.c
72331 index d53adf9..03a24bf 100644
72332 --- a/mm/maccess.c
72333 +++ b/mm/maccess.c
72334 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
72335 set_fs(KERNEL_DS);
72336 pagefault_disable();
72337 ret = __copy_from_user_inatomic(dst,
72338 - (__force const void __user *)src, size);
72339 + (const void __force_user *)src, size);
72340 pagefault_enable();
72341 set_fs(old_fs);
72342
72343 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
72344
72345 set_fs(KERNEL_DS);
72346 pagefault_disable();
72347 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
72348 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
72349 pagefault_enable();
72350 set_fs(old_fs);
72351
72352 diff --git a/mm/madvise.c b/mm/madvise.c
72353 index 14d260f..b2a80fd 100644
72354 --- a/mm/madvise.c
72355 +++ b/mm/madvise.c
72356 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
72357 pgoff_t pgoff;
72358 unsigned long new_flags = vma->vm_flags;
72359
72360 +#ifdef CONFIG_PAX_SEGMEXEC
72361 + struct vm_area_struct *vma_m;
72362 +#endif
72363 +
72364 switch (behavior) {
72365 case MADV_NORMAL:
72366 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
72367 @@ -119,6 +123,13 @@ success:
72368 /*
72369 * vm_flags is protected by the mmap_sem held in write mode.
72370 */
72371 +
72372 +#ifdef CONFIG_PAX_SEGMEXEC
72373 + vma_m = pax_find_mirror_vma(vma);
72374 + if (vma_m)
72375 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
72376 +#endif
72377 +
72378 vma->vm_flags = new_flags;
72379
72380 out:
72381 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72382 struct vm_area_struct ** prev,
72383 unsigned long start, unsigned long end)
72384 {
72385 +
72386 +#ifdef CONFIG_PAX_SEGMEXEC
72387 + struct vm_area_struct *vma_m;
72388 +#endif
72389 +
72390 *prev = vma;
72391 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
72392 return -EINVAL;
72393 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72394 zap_page_range(vma, start, end - start, &details);
72395 } else
72396 zap_page_range(vma, start, end - start, NULL);
72397 +
72398 +#ifdef CONFIG_PAX_SEGMEXEC
72399 + vma_m = pax_find_mirror_vma(vma);
72400 + if (vma_m) {
72401 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
72402 + struct zap_details details = {
72403 + .nonlinear_vma = vma_m,
72404 + .last_index = ULONG_MAX,
72405 + };
72406 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
72407 + } else
72408 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
72409 + }
72410 +#endif
72411 +
72412 return 0;
72413 }
72414
72415 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
72416 if (end < start)
72417 goto out;
72418
72419 +#ifdef CONFIG_PAX_SEGMEXEC
72420 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72421 + if (end > SEGMEXEC_TASK_SIZE)
72422 + goto out;
72423 + } else
72424 +#endif
72425 +
72426 + if (end > TASK_SIZE)
72427 + goto out;
72428 +
72429 error = 0;
72430 if (end == start)
72431 goto out;
72432 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
72433 index a6e2141..eaf5aad 100644
72434 --- a/mm/memory-failure.c
72435 +++ b/mm/memory-failure.c
72436 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
72437
72438 int sysctl_memory_failure_recovery __read_mostly = 1;
72439
72440 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72441 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72442
72443 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72444
72445 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
72446 pfn, t->comm, t->pid);
72447 si.si_signo = SIGBUS;
72448 si.si_errno = 0;
72449 - si.si_addr = (void *)addr;
72450 + si.si_addr = (void __user *)addr;
72451 #ifdef __ARCH_SI_TRAPNO
72452 si.si_trapno = trapno;
72453 #endif
72454 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72455 }
72456
72457 nr_pages = 1 << compound_trans_order(hpage);
72458 - atomic_long_add(nr_pages, &mce_bad_pages);
72459 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72460
72461 /*
72462 * We need/can do nothing about count=0 pages.
72463 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72464 if (!PageHWPoison(hpage)
72465 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72466 || (p != hpage && TestSetPageHWPoison(hpage))) {
72467 - atomic_long_sub(nr_pages, &mce_bad_pages);
72468 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72469 return 0;
72470 }
72471 set_page_hwpoison_huge_page(hpage);
72472 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72473 }
72474 if (hwpoison_filter(p)) {
72475 if (TestClearPageHWPoison(p))
72476 - atomic_long_sub(nr_pages, &mce_bad_pages);
72477 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72478 unlock_page(hpage);
72479 put_page(hpage);
72480 return 0;
72481 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
72482 return 0;
72483 }
72484 if (TestClearPageHWPoison(p))
72485 - atomic_long_sub(nr_pages, &mce_bad_pages);
72486 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72487 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72488 return 0;
72489 }
72490 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
72491 */
72492 if (TestClearPageHWPoison(page)) {
72493 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72494 - atomic_long_sub(nr_pages, &mce_bad_pages);
72495 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72496 freeit = 1;
72497 if (PageHuge(page))
72498 clear_page_hwpoison_huge_page(page);
72499 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
72500 }
72501 done:
72502 if (!PageHWPoison(hpage))
72503 - atomic_long_add(1 << compound_trans_order(hpage),
72504 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
72505 &mce_bad_pages);
72506 set_page_hwpoison_huge_page(hpage);
72507 dequeue_hwpoisoned_huge_page(hpage);
72508 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
72509 return ret;
72510
72511 done:
72512 - atomic_long_add(1, &mce_bad_pages);
72513 + atomic_long_add_unchecked(1, &mce_bad_pages);
72514 SetPageHWPoison(page);
72515 /* keep elevated page count for bad page */
72516 return ret;
72517 diff --git a/mm/memory.c b/mm/memory.c
72518 index 5736170..8e04800 100644
72519 --- a/mm/memory.c
72520 +++ b/mm/memory.c
72521 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72522 free_pte_range(tlb, pmd, addr);
72523 } while (pmd++, addr = next, addr != end);
72524
72525 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
72526 start &= PUD_MASK;
72527 if (start < floor)
72528 return;
72529 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72530 pmd = pmd_offset(pud, start);
72531 pud_clear(pud);
72532 pmd_free_tlb(tlb, pmd, start);
72533 +#endif
72534 +
72535 }
72536
72537 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72538 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72539 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72540 } while (pud++, addr = next, addr != end);
72541
72542 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72543 start &= PGDIR_MASK;
72544 if (start < floor)
72545 return;
72546 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72547 pud = pud_offset(pgd, start);
72548 pgd_clear(pgd);
72549 pud_free_tlb(tlb, pud, start);
72550 +#endif
72551 +
72552 }
72553
72554 /*
72555 @@ -1614,12 +1620,6 @@ no_page_table:
72556 return page;
72557 }
72558
72559 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72560 -{
72561 - return stack_guard_page_start(vma, addr) ||
72562 - stack_guard_page_end(vma, addr+PAGE_SIZE);
72563 -}
72564 -
72565 /**
72566 * __get_user_pages() - pin user pages in memory
72567 * @tsk: task_struct of target task
72568 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72569 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72570 i = 0;
72571
72572 - do {
72573 + while (nr_pages) {
72574 struct vm_area_struct *vma;
72575
72576 - vma = find_extend_vma(mm, start);
72577 + vma = find_vma(mm, start);
72578 if (!vma && in_gate_area(mm, start)) {
72579 unsigned long pg = start & PAGE_MASK;
72580 pgd_t *pgd;
72581 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72582 goto next_page;
72583 }
72584
72585 - if (!vma ||
72586 + if (!vma || start < vma->vm_start ||
72587 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72588 !(vm_flags & vma->vm_flags))
72589 return i ? : -EFAULT;
72590 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72591 int ret;
72592 unsigned int fault_flags = 0;
72593
72594 - /* For mlock, just skip the stack guard page. */
72595 - if (foll_flags & FOLL_MLOCK) {
72596 - if (stack_guard_page(vma, start))
72597 - goto next_page;
72598 - }
72599 if (foll_flags & FOLL_WRITE)
72600 fault_flags |= FAULT_FLAG_WRITE;
72601 if (nonblocking)
72602 @@ -1848,7 +1843,7 @@ next_page:
72603 start += PAGE_SIZE;
72604 nr_pages--;
72605 } while (nr_pages && start < vma->vm_end);
72606 - } while (nr_pages);
72607 + }
72608 return i;
72609 }
72610 EXPORT_SYMBOL(__get_user_pages);
72611 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72612 page_add_file_rmap(page);
72613 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72614
72615 +#ifdef CONFIG_PAX_SEGMEXEC
72616 + pax_mirror_file_pte(vma, addr, page, ptl);
72617 +#endif
72618 +
72619 retval = 0;
72620 pte_unmap_unlock(pte, ptl);
72621 return retval;
72622 @@ -2089,10 +2088,22 @@ out:
72623 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72624 struct page *page)
72625 {
72626 +
72627 +#ifdef CONFIG_PAX_SEGMEXEC
72628 + struct vm_area_struct *vma_m;
72629 +#endif
72630 +
72631 if (addr < vma->vm_start || addr >= vma->vm_end)
72632 return -EFAULT;
72633 if (!page_count(page))
72634 return -EINVAL;
72635 +
72636 +#ifdef CONFIG_PAX_SEGMEXEC
72637 + vma_m = pax_find_mirror_vma(vma);
72638 + if (vma_m)
72639 + vma_m->vm_flags |= VM_INSERTPAGE;
72640 +#endif
72641 +
72642 vma->vm_flags |= VM_INSERTPAGE;
72643 return insert_page(vma, addr, page, vma->vm_page_prot);
72644 }
72645 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72646 unsigned long pfn)
72647 {
72648 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72649 + BUG_ON(vma->vm_mirror);
72650
72651 if (addr < vma->vm_start || addr >= vma->vm_end)
72652 return -EFAULT;
72653 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72654
72655 BUG_ON(pud_huge(*pud));
72656
72657 - pmd = pmd_alloc(mm, pud, addr);
72658 + pmd = (mm == &init_mm) ?
72659 + pmd_alloc_kernel(mm, pud, addr) :
72660 + pmd_alloc(mm, pud, addr);
72661 if (!pmd)
72662 return -ENOMEM;
72663 do {
72664 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72665 unsigned long next;
72666 int err;
72667
72668 - pud = pud_alloc(mm, pgd, addr);
72669 + pud = (mm == &init_mm) ?
72670 + pud_alloc_kernel(mm, pgd, addr) :
72671 + pud_alloc(mm, pgd, addr);
72672 if (!pud)
72673 return -ENOMEM;
72674 do {
72675 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72676 copy_user_highpage(dst, src, va, vma);
72677 }
72678
72679 +#ifdef CONFIG_PAX_SEGMEXEC
72680 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72681 +{
72682 + struct mm_struct *mm = vma->vm_mm;
72683 + spinlock_t *ptl;
72684 + pte_t *pte, entry;
72685 +
72686 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72687 + entry = *pte;
72688 + if (!pte_present(entry)) {
72689 + if (!pte_none(entry)) {
72690 + BUG_ON(pte_file(entry));
72691 + free_swap_and_cache(pte_to_swp_entry(entry));
72692 + pte_clear_not_present_full(mm, address, pte, 0);
72693 + }
72694 + } else {
72695 + struct page *page;
72696 +
72697 + flush_cache_page(vma, address, pte_pfn(entry));
72698 + entry = ptep_clear_flush(vma, address, pte);
72699 + BUG_ON(pte_dirty(entry));
72700 + page = vm_normal_page(vma, address, entry);
72701 + if (page) {
72702 + update_hiwater_rss(mm);
72703 + if (PageAnon(page))
72704 + dec_mm_counter_fast(mm, MM_ANONPAGES);
72705 + else
72706 + dec_mm_counter_fast(mm, MM_FILEPAGES);
72707 + page_remove_rmap(page);
72708 + page_cache_release(page);
72709 + }
72710 + }
72711 + pte_unmap_unlock(pte, ptl);
72712 +}
72713 +
72714 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
72715 + *
72716 + * the ptl of the lower mapped page is held on entry and is not released on exit
72717 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72718 + */
72719 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72720 +{
72721 + struct mm_struct *mm = vma->vm_mm;
72722 + unsigned long address_m;
72723 + spinlock_t *ptl_m;
72724 + struct vm_area_struct *vma_m;
72725 + pmd_t *pmd_m;
72726 + pte_t *pte_m, entry_m;
72727 +
72728 + BUG_ON(!page_m || !PageAnon(page_m));
72729 +
72730 + vma_m = pax_find_mirror_vma(vma);
72731 + if (!vma_m)
72732 + return;
72733 +
72734 + BUG_ON(!PageLocked(page_m));
72735 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72736 + address_m = address + SEGMEXEC_TASK_SIZE;
72737 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72738 + pte_m = pte_offset_map(pmd_m, address_m);
72739 + ptl_m = pte_lockptr(mm, pmd_m);
72740 + if (ptl != ptl_m) {
72741 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72742 + if (!pte_none(*pte_m))
72743 + goto out;
72744 + }
72745 +
72746 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72747 + page_cache_get(page_m);
72748 + page_add_anon_rmap(page_m, vma_m, address_m);
72749 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72750 + set_pte_at(mm, address_m, pte_m, entry_m);
72751 + update_mmu_cache(vma_m, address_m, entry_m);
72752 +out:
72753 + if (ptl != ptl_m)
72754 + spin_unlock(ptl_m);
72755 + pte_unmap(pte_m);
72756 + unlock_page(page_m);
72757 +}
72758 +
72759 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72760 +{
72761 + struct mm_struct *mm = vma->vm_mm;
72762 + unsigned long address_m;
72763 + spinlock_t *ptl_m;
72764 + struct vm_area_struct *vma_m;
72765 + pmd_t *pmd_m;
72766 + pte_t *pte_m, entry_m;
72767 +
72768 + BUG_ON(!page_m || PageAnon(page_m));
72769 +
72770 + vma_m = pax_find_mirror_vma(vma);
72771 + if (!vma_m)
72772 + return;
72773 +
72774 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72775 + address_m = address + SEGMEXEC_TASK_SIZE;
72776 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72777 + pte_m = pte_offset_map(pmd_m, address_m);
72778 + ptl_m = pte_lockptr(mm, pmd_m);
72779 + if (ptl != ptl_m) {
72780 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72781 + if (!pte_none(*pte_m))
72782 + goto out;
72783 + }
72784 +
72785 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72786 + page_cache_get(page_m);
72787 + page_add_file_rmap(page_m);
72788 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72789 + set_pte_at(mm, address_m, pte_m, entry_m);
72790 + update_mmu_cache(vma_m, address_m, entry_m);
72791 +out:
72792 + if (ptl != ptl_m)
72793 + spin_unlock(ptl_m);
72794 + pte_unmap(pte_m);
72795 +}
72796 +
72797 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72798 +{
72799 + struct mm_struct *mm = vma->vm_mm;
72800 + unsigned long address_m;
72801 + spinlock_t *ptl_m;
72802 + struct vm_area_struct *vma_m;
72803 + pmd_t *pmd_m;
72804 + pte_t *pte_m, entry_m;
72805 +
72806 + vma_m = pax_find_mirror_vma(vma);
72807 + if (!vma_m)
72808 + return;
72809 +
72810 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72811 + address_m = address + SEGMEXEC_TASK_SIZE;
72812 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72813 + pte_m = pte_offset_map(pmd_m, address_m);
72814 + ptl_m = pte_lockptr(mm, pmd_m);
72815 + if (ptl != ptl_m) {
72816 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72817 + if (!pte_none(*pte_m))
72818 + goto out;
72819 + }
72820 +
72821 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72822 + set_pte_at(mm, address_m, pte_m, entry_m);
72823 +out:
72824 + if (ptl != ptl_m)
72825 + spin_unlock(ptl_m);
72826 + pte_unmap(pte_m);
72827 +}
72828 +
72829 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72830 +{
72831 + struct page *page_m;
72832 + pte_t entry;
72833 +
72834 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72835 + goto out;
72836 +
72837 + entry = *pte;
72838 + page_m = vm_normal_page(vma, address, entry);
72839 + if (!page_m)
72840 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72841 + else if (PageAnon(page_m)) {
72842 + if (pax_find_mirror_vma(vma)) {
72843 + pte_unmap_unlock(pte, ptl);
72844 + lock_page(page_m);
72845 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72846 + if (pte_same(entry, *pte))
72847 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72848 + else
72849 + unlock_page(page_m);
72850 + }
72851 + } else
72852 + pax_mirror_file_pte(vma, address, page_m, ptl);
72853 +
72854 +out:
72855 + pte_unmap_unlock(pte, ptl);
72856 +}
72857 +#endif
72858 +
72859 /*
72860 * This routine handles present pages, when users try to write
72861 * to a shared page. It is done by copying the page to a new address
72862 @@ -2703,6 +2899,12 @@ gotten:
72863 */
72864 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72865 if (likely(pte_same(*page_table, orig_pte))) {
72866 +
72867 +#ifdef CONFIG_PAX_SEGMEXEC
72868 + if (pax_find_mirror_vma(vma))
72869 + BUG_ON(!trylock_page(new_page));
72870 +#endif
72871 +
72872 if (old_page) {
72873 if (!PageAnon(old_page)) {
72874 dec_mm_counter_fast(mm, MM_FILEPAGES);
72875 @@ -2754,6 +2956,10 @@ gotten:
72876 page_remove_rmap(old_page);
72877 }
72878
72879 +#ifdef CONFIG_PAX_SEGMEXEC
72880 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72881 +#endif
72882 +
72883 /* Free the old page.. */
72884 new_page = old_page;
72885 ret |= VM_FAULT_WRITE;
72886 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72887 swap_free(entry);
72888 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72889 try_to_free_swap(page);
72890 +
72891 +#ifdef CONFIG_PAX_SEGMEXEC
72892 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72893 +#endif
72894 +
72895 unlock_page(page);
72896 if (swapcache) {
72897 /*
72898 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72899
72900 /* No need to invalidate - it was non-present before */
72901 update_mmu_cache(vma, address, page_table);
72902 +
72903 +#ifdef CONFIG_PAX_SEGMEXEC
72904 + pax_mirror_anon_pte(vma, address, page, ptl);
72905 +#endif
72906 +
72907 unlock:
72908 pte_unmap_unlock(page_table, ptl);
72909 out:
72910 @@ -3075,40 +3291,6 @@ out_release:
72911 }
72912
72913 /*
72914 - * This is like a special single-page "expand_{down|up}wards()",
72915 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72916 - * doesn't hit another vma.
72917 - */
72918 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72919 -{
72920 - address &= PAGE_MASK;
72921 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72922 - struct vm_area_struct *prev = vma->vm_prev;
72923 -
72924 - /*
72925 - * Is there a mapping abutting this one below?
72926 - *
72927 - * That's only ok if it's the same stack mapping
72928 - * that has gotten split..
72929 - */
72930 - if (prev && prev->vm_end == address)
72931 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72932 -
72933 - expand_downwards(vma, address - PAGE_SIZE);
72934 - }
72935 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72936 - struct vm_area_struct *next = vma->vm_next;
72937 -
72938 - /* As VM_GROWSDOWN but s/below/above/ */
72939 - if (next && next->vm_start == address + PAGE_SIZE)
72940 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72941 -
72942 - expand_upwards(vma, address + PAGE_SIZE);
72943 - }
72944 - return 0;
72945 -}
72946 -
72947 -/*
72948 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72949 * but allow concurrent faults), and pte mapped but not yet locked.
72950 * We return with mmap_sem still held, but pte unmapped and unlocked.
72951 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72952 unsigned long address, pte_t *page_table, pmd_t *pmd,
72953 unsigned int flags)
72954 {
72955 - struct page *page;
72956 + struct page *page = NULL;
72957 spinlock_t *ptl;
72958 pte_t entry;
72959
72960 - pte_unmap(page_table);
72961 -
72962 - /* Check if we need to add a guard page to the stack */
72963 - if (check_stack_guard_page(vma, address) < 0)
72964 - return VM_FAULT_SIGBUS;
72965 -
72966 - /* Use the zero-page for reads */
72967 if (!(flags & FAULT_FLAG_WRITE)) {
72968 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72969 vma->vm_page_prot));
72970 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72971 + ptl = pte_lockptr(mm, pmd);
72972 + spin_lock(ptl);
72973 if (!pte_none(*page_table))
72974 goto unlock;
72975 goto setpte;
72976 }
72977
72978 /* Allocate our own private page. */
72979 + pte_unmap(page_table);
72980 +
72981 if (unlikely(anon_vma_prepare(vma)))
72982 goto oom;
72983 page = alloc_zeroed_user_highpage_movable(vma, address);
72984 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72985 if (!pte_none(*page_table))
72986 goto release;
72987
72988 +#ifdef CONFIG_PAX_SEGMEXEC
72989 + if (pax_find_mirror_vma(vma))
72990 + BUG_ON(!trylock_page(page));
72991 +#endif
72992 +
72993 inc_mm_counter_fast(mm, MM_ANONPAGES);
72994 page_add_new_anon_rmap(page, vma, address);
72995 setpte:
72996 @@ -3163,6 +3346,12 @@ setpte:
72997
72998 /* No need to invalidate - it was non-present before */
72999 update_mmu_cache(vma, address, page_table);
73000 +
73001 +#ifdef CONFIG_PAX_SEGMEXEC
73002 + if (page)
73003 + pax_mirror_anon_pte(vma, address, page, ptl);
73004 +#endif
73005 +
73006 unlock:
73007 pte_unmap_unlock(page_table, ptl);
73008 return 0;
73009 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73010 */
73011 /* Only go through if we didn't race with anybody else... */
73012 if (likely(pte_same(*page_table, orig_pte))) {
73013 +
73014 +#ifdef CONFIG_PAX_SEGMEXEC
73015 + if (anon && pax_find_mirror_vma(vma))
73016 + BUG_ON(!trylock_page(page));
73017 +#endif
73018 +
73019 flush_icache_page(vma, page);
73020 entry = mk_pte(page, vma->vm_page_prot);
73021 if (flags & FAULT_FLAG_WRITE)
73022 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73023
73024 /* no need to invalidate: a not-present page won't be cached */
73025 update_mmu_cache(vma, address, page_table);
73026 +
73027 +#ifdef CONFIG_PAX_SEGMEXEC
73028 + if (anon)
73029 + pax_mirror_anon_pte(vma, address, page, ptl);
73030 + else
73031 + pax_mirror_file_pte(vma, address, page, ptl);
73032 +#endif
73033 +
73034 } else {
73035 if (cow_page)
73036 mem_cgroup_uncharge_page(cow_page);
73037 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
73038 if (flags & FAULT_FLAG_WRITE)
73039 flush_tlb_fix_spurious_fault(vma, address);
73040 }
73041 +
73042 +#ifdef CONFIG_PAX_SEGMEXEC
73043 + pax_mirror_pte(vma, address, pte, pmd, ptl);
73044 + return 0;
73045 +#endif
73046 +
73047 unlock:
73048 pte_unmap_unlock(pte, ptl);
73049 return 0;
73050 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73051 pmd_t *pmd;
73052 pte_t *pte;
73053
73054 +#ifdef CONFIG_PAX_SEGMEXEC
73055 + struct vm_area_struct *vma_m;
73056 +#endif
73057 +
73058 __set_current_state(TASK_RUNNING);
73059
73060 count_vm_event(PGFAULT);
73061 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73062 if (unlikely(is_vm_hugetlb_page(vma)))
73063 return hugetlb_fault(mm, vma, address, flags);
73064
73065 +#ifdef CONFIG_PAX_SEGMEXEC
73066 + vma_m = pax_find_mirror_vma(vma);
73067 + if (vma_m) {
73068 + unsigned long address_m;
73069 + pgd_t *pgd_m;
73070 + pud_t *pud_m;
73071 + pmd_t *pmd_m;
73072 +
73073 + if (vma->vm_start > vma_m->vm_start) {
73074 + address_m = address;
73075 + address -= SEGMEXEC_TASK_SIZE;
73076 + vma = vma_m;
73077 + } else
73078 + address_m = address + SEGMEXEC_TASK_SIZE;
73079 +
73080 + pgd_m = pgd_offset(mm, address_m);
73081 + pud_m = pud_alloc(mm, pgd_m, address_m);
73082 + if (!pud_m)
73083 + return VM_FAULT_OOM;
73084 + pmd_m = pmd_alloc(mm, pud_m, address_m);
73085 + if (!pmd_m)
73086 + return VM_FAULT_OOM;
73087 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
73088 + return VM_FAULT_OOM;
73089 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
73090 + }
73091 +#endif
73092 +
73093 retry:
73094 pgd = pgd_offset(mm, address);
73095 pud = pud_alloc(mm, pgd, address);
73096 @@ -3547,7 +3788,7 @@ retry:
73097 * run pte_offset_map on the pmd, if an huge pmd could
73098 * materialize from under us from a different thread.
73099 */
73100 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
73101 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
73102 return VM_FAULT_OOM;
73103 /* if an huge pmd materialized from under us just retry later */
73104 if (unlikely(pmd_trans_huge(*pmd)))
73105 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73106 spin_unlock(&mm->page_table_lock);
73107 return 0;
73108 }
73109 +
73110 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73111 +{
73112 + pud_t *new = pud_alloc_one(mm, address);
73113 + if (!new)
73114 + return -ENOMEM;
73115 +
73116 + smp_wmb(); /* See comment in __pte_alloc */
73117 +
73118 + spin_lock(&mm->page_table_lock);
73119 + if (pgd_present(*pgd)) /* Another has populated it */
73120 + pud_free(mm, new);
73121 + else
73122 + pgd_populate_kernel(mm, pgd, new);
73123 + spin_unlock(&mm->page_table_lock);
73124 + return 0;
73125 +}
73126 #endif /* __PAGETABLE_PUD_FOLDED */
73127
73128 #ifndef __PAGETABLE_PMD_FOLDED
73129 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
73130 spin_unlock(&mm->page_table_lock);
73131 return 0;
73132 }
73133 +
73134 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
73135 +{
73136 + pmd_t *new = pmd_alloc_one(mm, address);
73137 + if (!new)
73138 + return -ENOMEM;
73139 +
73140 + smp_wmb(); /* See comment in __pte_alloc */
73141 +
73142 + spin_lock(&mm->page_table_lock);
73143 +#ifndef __ARCH_HAS_4LEVEL_HACK
73144 + if (pud_present(*pud)) /* Another has populated it */
73145 + pmd_free(mm, new);
73146 + else
73147 + pud_populate_kernel(mm, pud, new);
73148 +#else
73149 + if (pgd_present(*pud)) /* Another has populated it */
73150 + pmd_free(mm, new);
73151 + else
73152 + pgd_populate_kernel(mm, pud, new);
73153 +#endif /* __ARCH_HAS_4LEVEL_HACK */
73154 + spin_unlock(&mm->page_table_lock);
73155 + return 0;
73156 +}
73157 #endif /* __PAGETABLE_PMD_FOLDED */
73158
73159 int make_pages_present(unsigned long addr, unsigned long end)
73160 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
73161 gate_vma.vm_start = FIXADDR_USER_START;
73162 gate_vma.vm_end = FIXADDR_USER_END;
73163 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
73164 - gate_vma.vm_page_prot = __P101;
73165 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
73166
73167 return 0;
73168 }
73169 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
73170 index 3d64b36..c6ab69c 100644
73171 --- a/mm/mempolicy.c
73172 +++ b/mm/mempolicy.c
73173 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
73174 unsigned long vmstart;
73175 unsigned long vmend;
73176
73177 +#ifdef CONFIG_PAX_SEGMEXEC
73178 + struct vm_area_struct *vma_m;
73179 +#endif
73180 +
73181 vma = find_vma(mm, start);
73182 if (!vma || vma->vm_start > start)
73183 return -EFAULT;
73184 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
73185 if (err)
73186 goto out;
73187 }
73188 +
73189 err = vma_replace_policy(vma, new_pol);
73190 if (err)
73191 goto out;
73192 +
73193 +#ifdef CONFIG_PAX_SEGMEXEC
73194 + vma_m = pax_find_mirror_vma(vma);
73195 + if (vma_m) {
73196 + err = vma_replace_policy(vma_m, new_pol);
73197 + if (err)
73198 + goto out;
73199 + }
73200 +#endif
73201 +
73202 }
73203
73204 out:
73205 @@ -1147,6 +1162,17 @@ static long do_mbind(unsigned long start, unsigned long len,
73206
73207 if (end < start)
73208 return -EINVAL;
73209 +
73210 +#ifdef CONFIG_PAX_SEGMEXEC
73211 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73212 + if (end > SEGMEXEC_TASK_SIZE)
73213 + return -EINVAL;
73214 + } else
73215 +#endif
73216 +
73217 + if (end > TASK_SIZE)
73218 + return -EINVAL;
73219 +
73220 if (end == start)
73221 return 0;
73222
73223 @@ -1370,8 +1396,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73224 */
73225 tcred = __task_cred(task);
73226 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73227 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73228 - !capable(CAP_SYS_NICE)) {
73229 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73230 rcu_read_unlock();
73231 err = -EPERM;
73232 goto out_put;
73233 @@ -1402,6 +1427,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73234 goto out;
73235 }
73236
73237 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
73238 + if (mm != current->mm &&
73239 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
73240 + mmput(mm);
73241 + err = -EPERM;
73242 + goto out;
73243 + }
73244 +#endif
73245 +
73246 err = do_migrate_pages(mm, old, new,
73247 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
73248
73249 diff --git a/mm/migrate.c b/mm/migrate.c
73250 index 77ed2d7..317d528 100644
73251 --- a/mm/migrate.c
73252 +++ b/mm/migrate.c
73253 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
73254 */
73255 tcred = __task_cred(task);
73256 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73257 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73258 - !capable(CAP_SYS_NICE)) {
73259 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73260 rcu_read_unlock();
73261 err = -EPERM;
73262 goto out;
73263 diff --git a/mm/mlock.c b/mm/mlock.c
73264 index ef726e8..cd7f1ec 100644
73265 --- a/mm/mlock.c
73266 +++ b/mm/mlock.c
73267 @@ -13,6 +13,7 @@
73268 #include <linux/pagemap.h>
73269 #include <linux/mempolicy.h>
73270 #include <linux/syscalls.h>
73271 +#include <linux/security.h>
73272 #include <linux/sched.h>
73273 #include <linux/export.h>
73274 #include <linux/rmap.h>
73275 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
73276 {
73277 unsigned long nstart, end, tmp;
73278 struct vm_area_struct * vma, * prev;
73279 - int error;
73280 + int error = 0;
73281
73282 VM_BUG_ON(start & ~PAGE_MASK);
73283 VM_BUG_ON(len != PAGE_ALIGN(len));
73284 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
73285 return -EINVAL;
73286 if (end == start)
73287 return 0;
73288 + if (end > TASK_SIZE)
73289 + return -EINVAL;
73290 +
73291 vma = find_vma(current->mm, start);
73292 if (!vma || vma->vm_start > start)
73293 return -ENOMEM;
73294 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
73295 for (nstart = start ; ; ) {
73296 vm_flags_t newflags;
73297
73298 +#ifdef CONFIG_PAX_SEGMEXEC
73299 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73300 + break;
73301 +#endif
73302 +
73303 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
73304
73305 newflags = vma->vm_flags | VM_LOCKED;
73306 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
73307 lock_limit >>= PAGE_SHIFT;
73308
73309 /* check against resource limits */
73310 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
73311 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
73312 error = do_mlock(start, len, 1);
73313 up_write(&current->mm->mmap_sem);
73314 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
73315 static int do_mlockall(int flags)
73316 {
73317 struct vm_area_struct * vma, * prev = NULL;
73318 - unsigned int def_flags = 0;
73319
73320 if (flags & MCL_FUTURE)
73321 - def_flags = VM_LOCKED;
73322 - current->mm->def_flags = def_flags;
73323 + current->mm->def_flags |= VM_LOCKED;
73324 + else
73325 + current->mm->def_flags &= ~VM_LOCKED;
73326 if (flags == MCL_FUTURE)
73327 goto out;
73328
73329 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
73330 vm_flags_t newflags;
73331
73332 +#ifdef CONFIG_PAX_SEGMEXEC
73333 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73334 + break;
73335 +#endif
73336 +
73337 + BUG_ON(vma->vm_end > TASK_SIZE);
73338 newflags = vma->vm_flags | VM_LOCKED;
73339 if (!(flags & MCL_CURRENT))
73340 newflags &= ~VM_LOCKED;
73341 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
73342 lock_limit >>= PAGE_SHIFT;
73343
73344 ret = -ENOMEM;
73345 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
73346 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
73347 capable(CAP_IPC_LOCK))
73348 ret = do_mlockall(flags);
73349 diff --git a/mm/mmap.c b/mm/mmap.c
73350 index ae18a48..86cf99e 100644
73351 --- a/mm/mmap.c
73352 +++ b/mm/mmap.c
73353 @@ -47,6 +47,16 @@
73354 #define arch_rebalance_pgtables(addr, len) (addr)
73355 #endif
73356
73357 +static inline void verify_mm_writelocked(struct mm_struct *mm)
73358 +{
73359 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
73360 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73361 + up_read(&mm->mmap_sem);
73362 + BUG();
73363 + }
73364 +#endif
73365 +}
73366 +
73367 static void unmap_region(struct mm_struct *mm,
73368 struct vm_area_struct *vma, struct vm_area_struct *prev,
73369 unsigned long start, unsigned long end);
73370 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
73371 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
73372 *
73373 */
73374 -pgprot_t protection_map[16] = {
73375 +pgprot_t protection_map[16] __read_only = {
73376 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
73377 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
73378 };
73379
73380 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
73381 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
73382 {
73383 - return __pgprot(pgprot_val(protection_map[vm_flags &
73384 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
73385 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
73386 pgprot_val(arch_vm_get_page_prot(vm_flags)));
73387 +
73388 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73389 + if (!(__supported_pte_mask & _PAGE_NX) &&
73390 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
73391 + (vm_flags & (VM_READ | VM_WRITE)))
73392 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
73393 +#endif
73394 +
73395 + return prot;
73396 }
73397 EXPORT_SYMBOL(vm_get_page_prot);
73398
73399 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
73400 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
73401 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
73402 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
73403 /*
73404 * Make sure vm_committed_as in one cacheline and not cacheline shared with
73405 * other variables. It can be updated by several CPUs frequently.
73406 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
73407 struct vm_area_struct *next = vma->vm_next;
73408
73409 might_sleep();
73410 + BUG_ON(vma->vm_mirror);
73411 if (vma->vm_ops && vma->vm_ops->close)
73412 vma->vm_ops->close(vma);
73413 if (vma->vm_file) {
73414 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
73415 * not page aligned -Ram Gupta
73416 */
73417 rlim = rlimit(RLIMIT_DATA);
73418 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
73419 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
73420 (mm->end_data - mm->start_data) > rlim)
73421 goto out;
73422 @@ -708,6 +730,12 @@ static int
73423 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
73424 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73425 {
73426 +
73427 +#ifdef CONFIG_PAX_SEGMEXEC
73428 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
73429 + return 0;
73430 +#endif
73431 +
73432 if (is_mergeable_vma(vma, file, vm_flags) &&
73433 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73434 if (vma->vm_pgoff == vm_pgoff)
73435 @@ -727,6 +755,12 @@ static int
73436 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73437 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73438 {
73439 +
73440 +#ifdef CONFIG_PAX_SEGMEXEC
73441 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
73442 + return 0;
73443 +#endif
73444 +
73445 if (is_mergeable_vma(vma, file, vm_flags) &&
73446 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73447 pgoff_t vm_pglen;
73448 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73449 struct vm_area_struct *vma_merge(struct mm_struct *mm,
73450 struct vm_area_struct *prev, unsigned long addr,
73451 unsigned long end, unsigned long vm_flags,
73452 - struct anon_vma *anon_vma, struct file *file,
73453 + struct anon_vma *anon_vma, struct file *file,
73454 pgoff_t pgoff, struct mempolicy *policy)
73455 {
73456 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
73457 struct vm_area_struct *area, *next;
73458 int err;
73459
73460 +#ifdef CONFIG_PAX_SEGMEXEC
73461 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
73462 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
73463 +
73464 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
73465 +#endif
73466 +
73467 /*
73468 * We later require that vma->vm_flags == vm_flags,
73469 * so this tests vma->vm_flags & VM_SPECIAL, too.
73470 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73471 if (next && next->vm_end == end) /* cases 6, 7, 8 */
73472 next = next->vm_next;
73473
73474 +#ifdef CONFIG_PAX_SEGMEXEC
73475 + if (prev)
73476 + prev_m = pax_find_mirror_vma(prev);
73477 + if (area)
73478 + area_m = pax_find_mirror_vma(area);
73479 + if (next)
73480 + next_m = pax_find_mirror_vma(next);
73481 +#endif
73482 +
73483 /*
73484 * Can it merge with the predecessor?
73485 */
73486 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73487 /* cases 1, 6 */
73488 err = vma_adjust(prev, prev->vm_start,
73489 next->vm_end, prev->vm_pgoff, NULL);
73490 - } else /* cases 2, 5, 7 */
73491 +
73492 +#ifdef CONFIG_PAX_SEGMEXEC
73493 + if (!err && prev_m)
73494 + err = vma_adjust(prev_m, prev_m->vm_start,
73495 + next_m->vm_end, prev_m->vm_pgoff, NULL);
73496 +#endif
73497 +
73498 + } else { /* cases 2, 5, 7 */
73499 err = vma_adjust(prev, prev->vm_start,
73500 end, prev->vm_pgoff, NULL);
73501 +
73502 +#ifdef CONFIG_PAX_SEGMEXEC
73503 + if (!err && prev_m)
73504 + err = vma_adjust(prev_m, prev_m->vm_start,
73505 + end_m, prev_m->vm_pgoff, NULL);
73506 +#endif
73507 +
73508 + }
73509 if (err)
73510 return NULL;
73511 khugepaged_enter_vma_merge(prev);
73512 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73513 mpol_equal(policy, vma_policy(next)) &&
73514 can_vma_merge_before(next, vm_flags,
73515 anon_vma, file, pgoff+pglen)) {
73516 - if (prev && addr < prev->vm_end) /* case 4 */
73517 + if (prev && addr < prev->vm_end) { /* case 4 */
73518 err = vma_adjust(prev, prev->vm_start,
73519 addr, prev->vm_pgoff, NULL);
73520 - else /* cases 3, 8 */
73521 +
73522 +#ifdef CONFIG_PAX_SEGMEXEC
73523 + if (!err && prev_m)
73524 + err = vma_adjust(prev_m, prev_m->vm_start,
73525 + addr_m, prev_m->vm_pgoff, NULL);
73526 +#endif
73527 +
73528 + } else { /* cases 3, 8 */
73529 err = vma_adjust(area, addr, next->vm_end,
73530 next->vm_pgoff - pglen, NULL);
73531 +
73532 +#ifdef CONFIG_PAX_SEGMEXEC
73533 + if (!err && area_m)
73534 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
73535 + next_m->vm_pgoff - pglen, NULL);
73536 +#endif
73537 +
73538 + }
73539 if (err)
73540 return NULL;
73541 khugepaged_enter_vma_merge(area);
73542 @@ -940,16 +1020,13 @@ none:
73543 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73544 struct file *file, long pages)
73545 {
73546 - const unsigned long stack_flags
73547 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73548 -
73549 mm->total_vm += pages;
73550
73551 if (file) {
73552 mm->shared_vm += pages;
73553 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73554 mm->exec_vm += pages;
73555 - } else if (flags & stack_flags)
73556 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73557 mm->stack_vm += pages;
73558 if (flags & (VM_RESERVED|VM_IO))
73559 mm->reserved_vm += pages;
73560 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73561 * (the exception is when the underlying filesystem is noexec
73562 * mounted, in which case we dont add PROT_EXEC.)
73563 */
73564 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73565 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73566 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73567 prot |= PROT_EXEC;
73568
73569 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73570 /* Obtain the address to map to. we verify (or select) it and ensure
73571 * that it represents a valid section of the address space.
73572 */
73573 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
73574 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73575 if (addr & ~PAGE_MASK)
73576 return addr;
73577
73578 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73579 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73580 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73581
73582 +#ifdef CONFIG_PAX_MPROTECT
73583 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73584 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73585 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73586 + gr_log_rwxmmap(file);
73587 +
73588 +#ifdef CONFIG_PAX_EMUPLT
73589 + vm_flags &= ~VM_EXEC;
73590 +#else
73591 + return -EPERM;
73592 +#endif
73593 +
73594 + }
73595 +
73596 + if (!(vm_flags & VM_EXEC))
73597 + vm_flags &= ~VM_MAYEXEC;
73598 +#else
73599 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73600 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73601 +#endif
73602 + else
73603 + vm_flags &= ~VM_MAYWRITE;
73604 + }
73605 +#endif
73606 +
73607 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73608 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73609 + vm_flags &= ~VM_PAGEEXEC;
73610 +#endif
73611 +
73612 if (flags & MAP_LOCKED)
73613 if (!can_do_mlock())
73614 return -EPERM;
73615 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73616 locked += mm->locked_vm;
73617 lock_limit = rlimit(RLIMIT_MEMLOCK);
73618 lock_limit >>= PAGE_SHIFT;
73619 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73620 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73621 return -EAGAIN;
73622 }
73623 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73624 }
73625 }
73626
73627 + if (!gr_acl_handle_mmap(file, prot))
73628 + return -EACCES;
73629 +
73630 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73631 }
73632
73633 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73634 vm_flags_t vm_flags = vma->vm_flags;
73635
73636 /* If it was private or non-writable, the write bit is already clear */
73637 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73638 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73639 return 0;
73640
73641 /* The backer wishes to know when pages are first written to? */
73642 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73643 unsigned long charged = 0;
73644 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73645
73646 +#ifdef CONFIG_PAX_SEGMEXEC
73647 + struct vm_area_struct *vma_m = NULL;
73648 +#endif
73649 +
73650 + /*
73651 + * mm->mmap_sem is required to protect against another thread
73652 + * changing the mappings in case we sleep.
73653 + */
73654 + verify_mm_writelocked(mm);
73655 +
73656 /* Clear old maps */
73657 error = -ENOMEM;
73658 -munmap_back:
73659 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73660 if (vma && vma->vm_start < addr + len) {
73661 if (do_munmap(mm, addr, len))
73662 return -ENOMEM;
73663 - goto munmap_back;
73664 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73665 + BUG_ON(vma && vma->vm_start < addr + len);
73666 }
73667
73668 /* Check against address space limit. */
73669 @@ -1282,6 +1403,16 @@ munmap_back:
73670 goto unacct_error;
73671 }
73672
73673 +#ifdef CONFIG_PAX_SEGMEXEC
73674 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73675 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73676 + if (!vma_m) {
73677 + error = -ENOMEM;
73678 + goto free_vma;
73679 + }
73680 + }
73681 +#endif
73682 +
73683 vma->vm_mm = mm;
73684 vma->vm_start = addr;
73685 vma->vm_end = addr + len;
73686 @@ -1306,6 +1437,19 @@ munmap_back:
73687 error = file->f_op->mmap(file, vma);
73688 if (error)
73689 goto unmap_and_free_vma;
73690 +
73691 +#ifdef CONFIG_PAX_SEGMEXEC
73692 + if (vma_m && (vm_flags & VM_EXECUTABLE))
73693 + added_exe_file_vma(mm);
73694 +#endif
73695 +
73696 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73697 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73698 + vma->vm_flags |= VM_PAGEEXEC;
73699 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73700 + }
73701 +#endif
73702 +
73703 if (vm_flags & VM_EXECUTABLE)
73704 added_exe_file_vma(mm);
73705
73706 @@ -1343,6 +1487,11 @@ munmap_back:
73707 vma_link(mm, vma, prev, rb_link, rb_parent);
73708 file = vma->vm_file;
73709
73710 +#ifdef CONFIG_PAX_SEGMEXEC
73711 + if (vma_m)
73712 + BUG_ON(pax_mirror_vma(vma_m, vma));
73713 +#endif
73714 +
73715 /* Once vma denies write, undo our temporary denial count */
73716 if (correct_wcount)
73717 atomic_inc(&inode->i_writecount);
73718 @@ -1350,6 +1499,7 @@ out:
73719 perf_event_mmap(vma);
73720
73721 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73722 + track_exec_limit(mm, addr, addr + len, vm_flags);
73723 if (vm_flags & VM_LOCKED) {
73724 if (!mlock_vma_pages_range(vma, addr, addr + len))
73725 mm->locked_vm += (len >> PAGE_SHIFT);
73726 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
73727 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73728 charged = 0;
73729 free_vma:
73730 +
73731 +#ifdef CONFIG_PAX_SEGMEXEC
73732 + if (vma_m)
73733 + kmem_cache_free(vm_area_cachep, vma_m);
73734 +#endif
73735 +
73736 kmem_cache_free(vm_area_cachep, vma);
73737 unacct_error:
73738 if (charged)
73739 @@ -1378,6 +1534,44 @@ unacct_error:
73740 return error;
73741 }
73742
73743 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73744 +{
73745 + if (!vma) {
73746 +#ifdef CONFIG_STACK_GROWSUP
73747 + if (addr > sysctl_heap_stack_gap)
73748 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73749 + else
73750 + vma = find_vma(current->mm, 0);
73751 + if (vma && (vma->vm_flags & VM_GROWSUP))
73752 + return false;
73753 +#endif
73754 + return true;
73755 + }
73756 +
73757 + if (addr + len > vma->vm_start)
73758 + return false;
73759 +
73760 + if (vma->vm_flags & VM_GROWSDOWN)
73761 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73762 +#ifdef CONFIG_STACK_GROWSUP
73763 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73764 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73765 +#endif
73766 +
73767 + return true;
73768 +}
73769 +
73770 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73771 +{
73772 + if (vma->vm_start < len)
73773 + return -ENOMEM;
73774 + if (!(vma->vm_flags & VM_GROWSDOWN))
73775 + return vma->vm_start - len;
73776 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73777 + return vma->vm_start - len - sysctl_heap_stack_gap;
73778 + return -ENOMEM;
73779 +}
73780 +
73781 /* Get an address range which is currently unmapped.
73782 * For shmat() with addr=0.
73783 *
73784 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73785 if (flags & MAP_FIXED)
73786 return addr;
73787
73788 +#ifdef CONFIG_PAX_RANDMMAP
73789 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73790 +#endif
73791 +
73792 if (addr) {
73793 addr = PAGE_ALIGN(addr);
73794 - vma = find_vma(mm, addr);
73795 - if (TASK_SIZE - len >= addr &&
73796 - (!vma || addr + len <= vma->vm_start))
73797 - return addr;
73798 + if (TASK_SIZE - len >= addr) {
73799 + vma = find_vma(mm, addr);
73800 + if (check_heap_stack_gap(vma, addr, len))
73801 + return addr;
73802 + }
73803 }
73804 if (len > mm->cached_hole_size) {
73805 - start_addr = addr = mm->free_area_cache;
73806 + start_addr = addr = mm->free_area_cache;
73807 } else {
73808 - start_addr = addr = TASK_UNMAPPED_BASE;
73809 - mm->cached_hole_size = 0;
73810 + start_addr = addr = mm->mmap_base;
73811 + mm->cached_hole_size = 0;
73812 }
73813
73814 full_search:
73815 @@ -1426,34 +1625,40 @@ full_search:
73816 * Start a new search - just in case we missed
73817 * some holes.
73818 */
73819 - if (start_addr != TASK_UNMAPPED_BASE) {
73820 - addr = TASK_UNMAPPED_BASE;
73821 - start_addr = addr;
73822 + if (start_addr != mm->mmap_base) {
73823 + start_addr = addr = mm->mmap_base;
73824 mm->cached_hole_size = 0;
73825 goto full_search;
73826 }
73827 return -ENOMEM;
73828 }
73829 - if (!vma || addr + len <= vma->vm_start) {
73830 - /*
73831 - * Remember the place where we stopped the search:
73832 - */
73833 - mm->free_area_cache = addr + len;
73834 - return addr;
73835 - }
73836 + if (check_heap_stack_gap(vma, addr, len))
73837 + break;
73838 if (addr + mm->cached_hole_size < vma->vm_start)
73839 mm->cached_hole_size = vma->vm_start - addr;
73840 addr = vma->vm_end;
73841 }
73842 +
73843 + /*
73844 + * Remember the place where we stopped the search:
73845 + */
73846 + mm->free_area_cache = addr + len;
73847 + return addr;
73848 }
73849 #endif
73850
73851 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73852 {
73853 +
73854 +#ifdef CONFIG_PAX_SEGMEXEC
73855 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73856 + return;
73857 +#endif
73858 +
73859 /*
73860 * Is this a new hole at the lowest possible address?
73861 */
73862 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73863 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73864 mm->free_area_cache = addr;
73865 }
73866
73867 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73868 {
73869 struct vm_area_struct *vma;
73870 struct mm_struct *mm = current->mm;
73871 - unsigned long addr = addr0, start_addr;
73872 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73873
73874 /* requested length too big for entire address space */
73875 if (len > TASK_SIZE)
73876 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73877 if (flags & MAP_FIXED)
73878 return addr;
73879
73880 +#ifdef CONFIG_PAX_RANDMMAP
73881 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73882 +#endif
73883 +
73884 /* requesting a specific address */
73885 if (addr) {
73886 addr = PAGE_ALIGN(addr);
73887 - vma = find_vma(mm, addr);
73888 - if (TASK_SIZE - len >= addr &&
73889 - (!vma || addr + len <= vma->vm_start))
73890 - return addr;
73891 + if (TASK_SIZE - len >= addr) {
73892 + vma = find_vma(mm, addr);
73893 + if (check_heap_stack_gap(vma, addr, len))
73894 + return addr;
73895 + }
73896 }
73897
73898 /* check if free_area_cache is useful for us */
73899 @@ -1508,7 +1718,7 @@ try_again:
73900 * return with success:
73901 */
73902 vma = find_vma(mm, addr);
73903 - if (!vma || addr+len <= vma->vm_start)
73904 + if (check_heap_stack_gap(vma, addr, len))
73905 /* remember the address as a hint for next time */
73906 return (mm->free_area_cache = addr);
73907
73908 @@ -1517,8 +1727,8 @@ try_again:
73909 mm->cached_hole_size = vma->vm_start - addr;
73910
73911 /* try just below the current vma->vm_start */
73912 - addr = vma->vm_start-len;
73913 - } while (len < vma->vm_start);
73914 + addr = skip_heap_stack_gap(vma, len);
73915 + } while (!IS_ERR_VALUE(addr));
73916
73917 fail:
73918 /*
73919 @@ -1541,13 +1751,21 @@ fail:
73920 * can happen with large stack limits and large mmap()
73921 * allocations.
73922 */
73923 + mm->mmap_base = TASK_UNMAPPED_BASE;
73924 +
73925 +#ifdef CONFIG_PAX_RANDMMAP
73926 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73927 + mm->mmap_base += mm->delta_mmap;
73928 +#endif
73929 +
73930 + mm->free_area_cache = mm->mmap_base;
73931 mm->cached_hole_size = ~0UL;
73932 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73933 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73934 /*
73935 * Restore the topdown base:
73936 */
73937 - mm->free_area_cache = mm->mmap_base;
73938 + mm->mmap_base = base;
73939 + mm->free_area_cache = base;
73940 mm->cached_hole_size = ~0UL;
73941
73942 return addr;
73943 @@ -1556,6 +1774,12 @@ fail:
73944
73945 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73946 {
73947 +
73948 +#ifdef CONFIG_PAX_SEGMEXEC
73949 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73950 + return;
73951 +#endif
73952 +
73953 /*
73954 * Is this a new hole at the highest possible address?
73955 */
73956 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73957 mm->free_area_cache = addr;
73958
73959 /* dont allow allocations above current base */
73960 - if (mm->free_area_cache > mm->mmap_base)
73961 + if (mm->free_area_cache > mm->mmap_base) {
73962 mm->free_area_cache = mm->mmap_base;
73963 + mm->cached_hole_size = ~0UL;
73964 + }
73965 }
73966
73967 unsigned long
73968 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73969 return vma;
73970 }
73971
73972 +#ifdef CONFIG_PAX_SEGMEXEC
73973 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73974 +{
73975 + struct vm_area_struct *vma_m;
73976 +
73977 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73978 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73979 + BUG_ON(vma->vm_mirror);
73980 + return NULL;
73981 + }
73982 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73983 + vma_m = vma->vm_mirror;
73984 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73985 + BUG_ON(vma->vm_file != vma_m->vm_file);
73986 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73987 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73988 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73989 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73990 + return vma_m;
73991 +}
73992 +#endif
73993 +
73994 /*
73995 * Verify that the stack growth is acceptable and
73996 * update accounting. This is shared with both the
73997 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73998 return -ENOMEM;
73999
74000 /* Stack limit test */
74001 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
74002 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
74003 return -ENOMEM;
74004
74005 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
74006 locked = mm->locked_vm + grow;
74007 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
74008 limit >>= PAGE_SHIFT;
74009 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
74010 if (locked > limit && !capable(CAP_IPC_LOCK))
74011 return -ENOMEM;
74012 }
74013 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
74014 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
74015 * vma is the last one with address > vma->vm_end. Have to extend vma.
74016 */
74017 +#ifndef CONFIG_IA64
74018 +static
74019 +#endif
74020 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
74021 {
74022 int error;
74023 + bool locknext;
74024
74025 if (!(vma->vm_flags & VM_GROWSUP))
74026 return -EFAULT;
74027
74028 + /* Also guard against wrapping around to address 0. */
74029 + if (address < PAGE_ALIGN(address+1))
74030 + address = PAGE_ALIGN(address+1);
74031 + else
74032 + return -ENOMEM;
74033 +
74034 /*
74035 * We must make sure the anon_vma is allocated
74036 * so that the anon_vma locking is not a noop.
74037 */
74038 if (unlikely(anon_vma_prepare(vma)))
74039 return -ENOMEM;
74040 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
74041 + if (locknext && anon_vma_prepare(vma->vm_next))
74042 + return -ENOMEM;
74043 vma_lock_anon_vma(vma);
74044 + if (locknext)
74045 + vma_lock_anon_vma(vma->vm_next);
74046
74047 /*
74048 * vma->vm_start/vm_end cannot change under us because the caller
74049 * is required to hold the mmap_sem in read mode. We need the
74050 - * anon_vma lock to serialize against concurrent expand_stacks.
74051 - * Also guard against wrapping around to address 0.
74052 + * anon_vma locks to serialize against concurrent expand_stacks
74053 + * and expand_upwards.
74054 */
74055 - if (address < PAGE_ALIGN(address+4))
74056 - address = PAGE_ALIGN(address+4);
74057 - else {
74058 - vma_unlock_anon_vma(vma);
74059 - return -ENOMEM;
74060 - }
74061 error = 0;
74062
74063 /* Somebody else might have raced and expanded it already */
74064 - if (address > vma->vm_end) {
74065 + 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)
74066 + error = -ENOMEM;
74067 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
74068 unsigned long size, grow;
74069
74070 size = address - vma->vm_start;
74071 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
74072 }
74073 }
74074 }
74075 + if (locknext)
74076 + vma_unlock_anon_vma(vma->vm_next);
74077 vma_unlock_anon_vma(vma);
74078 khugepaged_enter_vma_merge(vma);
74079 return error;
74080 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
74081 unsigned long address)
74082 {
74083 int error;
74084 + bool lockprev = false;
74085 + struct vm_area_struct *prev;
74086
74087 /*
74088 * We must make sure the anon_vma is allocated
74089 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
74090 if (error)
74091 return error;
74092
74093 + prev = vma->vm_prev;
74094 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
74095 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
74096 +#endif
74097 + if (lockprev && anon_vma_prepare(prev))
74098 + return -ENOMEM;
74099 + if (lockprev)
74100 + vma_lock_anon_vma(prev);
74101 +
74102 vma_lock_anon_vma(vma);
74103
74104 /*
74105 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
74106 */
74107
74108 /* Somebody else might have raced and expanded it already */
74109 - if (address < vma->vm_start) {
74110 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
74111 + error = -ENOMEM;
74112 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
74113 unsigned long size, grow;
74114
74115 +#ifdef CONFIG_PAX_SEGMEXEC
74116 + struct vm_area_struct *vma_m;
74117 +
74118 + vma_m = pax_find_mirror_vma(vma);
74119 +#endif
74120 +
74121 size = vma->vm_end - address;
74122 grow = (vma->vm_start - address) >> PAGE_SHIFT;
74123
74124 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
74125 if (!error) {
74126 vma->vm_start = address;
74127 vma->vm_pgoff -= grow;
74128 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
74129 +
74130 +#ifdef CONFIG_PAX_SEGMEXEC
74131 + if (vma_m) {
74132 + vma_m->vm_start -= grow << PAGE_SHIFT;
74133 + vma_m->vm_pgoff -= grow;
74134 + }
74135 +#endif
74136 +
74137 perf_event_mmap(vma);
74138 }
74139 }
74140 }
74141 vma_unlock_anon_vma(vma);
74142 + if (lockprev)
74143 + vma_unlock_anon_vma(prev);
74144 khugepaged_enter_vma_merge(vma);
74145 return error;
74146 }
74147 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
74148 do {
74149 long nrpages = vma_pages(vma);
74150
74151 +#ifdef CONFIG_PAX_SEGMEXEC
74152 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
74153 + vma = remove_vma(vma);
74154 + continue;
74155 + }
74156 +#endif
74157 +
74158 if (vma->vm_flags & VM_ACCOUNT)
74159 nr_accounted += nrpages;
74160 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
74161 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
74162 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
74163 vma->vm_prev = NULL;
74164 do {
74165 +
74166 +#ifdef CONFIG_PAX_SEGMEXEC
74167 + if (vma->vm_mirror) {
74168 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
74169 + vma->vm_mirror->vm_mirror = NULL;
74170 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
74171 + vma->vm_mirror = NULL;
74172 + }
74173 +#endif
74174 +
74175 rb_erase(&vma->vm_rb, &mm->mm_rb);
74176 mm->map_count--;
74177 tail_vma = vma;
74178 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74179 struct vm_area_struct *new;
74180 int err = -ENOMEM;
74181
74182 +#ifdef CONFIG_PAX_SEGMEXEC
74183 + struct vm_area_struct *vma_m, *new_m = NULL;
74184 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
74185 +#endif
74186 +
74187 if (is_vm_hugetlb_page(vma) && (addr &
74188 ~(huge_page_mask(hstate_vma(vma)))))
74189 return -EINVAL;
74190
74191 +#ifdef CONFIG_PAX_SEGMEXEC
74192 + vma_m = pax_find_mirror_vma(vma);
74193 +#endif
74194 +
74195 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74196 if (!new)
74197 goto out_err;
74198
74199 +#ifdef CONFIG_PAX_SEGMEXEC
74200 + if (vma_m) {
74201 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74202 + if (!new_m) {
74203 + kmem_cache_free(vm_area_cachep, new);
74204 + goto out_err;
74205 + }
74206 + }
74207 +#endif
74208 +
74209 /* most fields are the same, copy all, and then fixup */
74210 *new = *vma;
74211
74212 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74213 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
74214 }
74215
74216 +#ifdef CONFIG_PAX_SEGMEXEC
74217 + if (vma_m) {
74218 + *new_m = *vma_m;
74219 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
74220 + new_m->vm_mirror = new;
74221 + new->vm_mirror = new_m;
74222 +
74223 + if (new_below)
74224 + new_m->vm_end = addr_m;
74225 + else {
74226 + new_m->vm_start = addr_m;
74227 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
74228 + }
74229 + }
74230 +#endif
74231 +
74232 pol = mpol_dup(vma_policy(vma));
74233 if (IS_ERR(pol)) {
74234 err = PTR_ERR(pol);
74235 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74236 else
74237 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
74238
74239 +#ifdef CONFIG_PAX_SEGMEXEC
74240 + if (!err && vma_m) {
74241 + if (anon_vma_clone(new_m, vma_m))
74242 + goto out_free_mpol;
74243 +
74244 + mpol_get(pol);
74245 + vma_set_policy(new_m, pol);
74246 +
74247 + if (new_m->vm_file) {
74248 + get_file(new_m->vm_file);
74249 + if (vma_m->vm_flags & VM_EXECUTABLE)
74250 + added_exe_file_vma(mm);
74251 + }
74252 +
74253 + if (new_m->vm_ops && new_m->vm_ops->open)
74254 + new_m->vm_ops->open(new_m);
74255 +
74256 + if (new_below)
74257 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
74258 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
74259 + else
74260 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
74261 +
74262 + if (err) {
74263 + if (new_m->vm_ops && new_m->vm_ops->close)
74264 + new_m->vm_ops->close(new_m);
74265 + if (new_m->vm_file) {
74266 + if (vma_m->vm_flags & VM_EXECUTABLE)
74267 + removed_exe_file_vma(mm);
74268 + fput(new_m->vm_file);
74269 + }
74270 + mpol_put(pol);
74271 + }
74272 + }
74273 +#endif
74274 +
74275 /* Success. */
74276 if (!err)
74277 return 0;
74278 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74279 removed_exe_file_vma(mm);
74280 fput(new->vm_file);
74281 }
74282 - unlink_anon_vmas(new);
74283 out_free_mpol:
74284 mpol_put(pol);
74285 out_free_vma:
74286 +
74287 +#ifdef CONFIG_PAX_SEGMEXEC
74288 + if (new_m) {
74289 + unlink_anon_vmas(new_m);
74290 + kmem_cache_free(vm_area_cachep, new_m);
74291 + }
74292 +#endif
74293 +
74294 + unlink_anon_vmas(new);
74295 kmem_cache_free(vm_area_cachep, new);
74296 out_err:
74297 return err;
74298 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74299 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74300 unsigned long addr, int new_below)
74301 {
74302 +
74303 +#ifdef CONFIG_PAX_SEGMEXEC
74304 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
74305 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
74306 + if (mm->map_count >= sysctl_max_map_count-1)
74307 + return -ENOMEM;
74308 + } else
74309 +#endif
74310 +
74311 if (mm->map_count >= sysctl_max_map_count)
74312 return -ENOMEM;
74313
74314 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74315 * work. This now handles partial unmappings.
74316 * Jeremy Fitzhardinge <jeremy@goop.org>
74317 */
74318 +#ifdef CONFIG_PAX_SEGMEXEC
74319 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74320 {
74321 + int ret = __do_munmap(mm, start, len);
74322 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
74323 + return ret;
74324 +
74325 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
74326 +}
74327 +
74328 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74329 +#else
74330 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74331 +#endif
74332 +{
74333 unsigned long end;
74334 struct vm_area_struct *vma, *prev, *last;
74335
74336 + /*
74337 + * mm->mmap_sem is required to protect against another thread
74338 + * changing the mappings in case we sleep.
74339 + */
74340 + verify_mm_writelocked(mm);
74341 +
74342 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
74343 return -EINVAL;
74344
74345 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74346 /* Fix up all other VM information */
74347 remove_vma_list(mm, vma);
74348
74349 + track_exec_limit(mm, start, end, 0UL);
74350 +
74351 return 0;
74352 }
74353
74354 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
74355 int ret;
74356 struct mm_struct *mm = current->mm;
74357
74358 +
74359 +#ifdef CONFIG_PAX_SEGMEXEC
74360 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
74361 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
74362 + return -EINVAL;
74363 +#endif
74364 +
74365 down_write(&mm->mmap_sem);
74366 ret = do_munmap(mm, start, len);
74367 up_write(&mm->mmap_sem);
74368 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
74369 return vm_munmap(addr, len);
74370 }
74371
74372 -static inline void verify_mm_writelocked(struct mm_struct *mm)
74373 -{
74374 -#ifdef CONFIG_DEBUG_VM
74375 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
74376 - WARN_ON(1);
74377 - up_read(&mm->mmap_sem);
74378 - }
74379 -#endif
74380 -}
74381 -
74382 /*
74383 * this is really a simplified "do_mmap". it only handles
74384 * anonymous maps. eventually we may be able to do some
74385 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74386 struct rb_node ** rb_link, * rb_parent;
74387 pgoff_t pgoff = addr >> PAGE_SHIFT;
74388 int error;
74389 + unsigned long charged;
74390
74391 len = PAGE_ALIGN(len);
74392 if (!len)
74393 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74394
74395 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
74396
74397 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
74398 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
74399 + flags &= ~VM_EXEC;
74400 +
74401 +#ifdef CONFIG_PAX_MPROTECT
74402 + if (mm->pax_flags & MF_PAX_MPROTECT)
74403 + flags &= ~VM_MAYEXEC;
74404 +#endif
74405 +
74406 + }
74407 +#endif
74408 +
74409 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
74410 if (error & ~PAGE_MASK)
74411 return error;
74412
74413 + charged = len >> PAGE_SHIFT;
74414 +
74415 /*
74416 * mlock MCL_FUTURE?
74417 */
74418 if (mm->def_flags & VM_LOCKED) {
74419 unsigned long locked, lock_limit;
74420 - locked = len >> PAGE_SHIFT;
74421 + locked = charged;
74422 locked += mm->locked_vm;
74423 lock_limit = rlimit(RLIMIT_MEMLOCK);
74424 lock_limit >>= PAGE_SHIFT;
74425 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74426 /*
74427 * Clear old maps. this also does some error checking for us
74428 */
74429 - munmap_back:
74430 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74431 if (vma && vma->vm_start < addr + len) {
74432 if (do_munmap(mm, addr, len))
74433 return -ENOMEM;
74434 - goto munmap_back;
74435 - }
74436 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74437 + BUG_ON(vma && vma->vm_start < addr + len);
74438 + }
74439
74440 /* Check against address space limits *after* clearing old maps... */
74441 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
74442 + if (!may_expand_vm(mm, charged))
74443 return -ENOMEM;
74444
74445 if (mm->map_count > sysctl_max_map_count)
74446 return -ENOMEM;
74447
74448 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
74449 + if (security_vm_enough_memory_mm(mm, charged))
74450 return -ENOMEM;
74451
74452 /* Can we just expand an old private anonymous mapping? */
74453 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74454 */
74455 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74456 if (!vma) {
74457 - vm_unacct_memory(len >> PAGE_SHIFT);
74458 + vm_unacct_memory(charged);
74459 return -ENOMEM;
74460 }
74461
74462 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74463 vma_link(mm, vma, prev, rb_link, rb_parent);
74464 out:
74465 perf_event_mmap(vma);
74466 - mm->total_vm += len >> PAGE_SHIFT;
74467 + mm->total_vm += charged;
74468 if (flags & VM_LOCKED) {
74469 if (!mlock_vma_pages_range(vma, addr, addr + len))
74470 - mm->locked_vm += (len >> PAGE_SHIFT);
74471 + mm->locked_vm += charged;
74472 }
74473 + track_exec_limit(mm, addr, addr + len, flags);
74474 return addr;
74475 }
74476
74477 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
74478 while (vma) {
74479 if (vma->vm_flags & VM_ACCOUNT)
74480 nr_accounted += vma_pages(vma);
74481 + vma->vm_mirror = NULL;
74482 vma = remove_vma(vma);
74483 }
74484 vm_unacct_memory(nr_accounted);
74485 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74486 struct vm_area_struct * __vma, * prev;
74487 struct rb_node ** rb_link, * rb_parent;
74488
74489 +#ifdef CONFIG_PAX_SEGMEXEC
74490 + struct vm_area_struct *vma_m = NULL;
74491 +#endif
74492 +
74493 + if (security_mmap_addr(vma->vm_start))
74494 + return -EPERM;
74495 +
74496 /*
74497 * The vm_pgoff of a purely anonymous vma should be irrelevant
74498 * until its first write fault, when page's anon_vma and index
74499 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74500 security_vm_enough_memory_mm(mm, vma_pages(vma)))
74501 return -ENOMEM;
74502
74503 +#ifdef CONFIG_PAX_SEGMEXEC
74504 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
74505 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74506 + if (!vma_m)
74507 + return -ENOMEM;
74508 + }
74509 +#endif
74510 +
74511 vma_link(mm, vma, prev, rb_link, rb_parent);
74512 +
74513 +#ifdef CONFIG_PAX_SEGMEXEC
74514 + if (vma_m)
74515 + BUG_ON(pax_mirror_vma(vma_m, vma));
74516 +#endif
74517 +
74518 return 0;
74519 }
74520
74521 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74522 struct mempolicy *pol;
74523 bool faulted_in_anon_vma = true;
74524
74525 + BUG_ON(vma->vm_mirror);
74526 +
74527 /*
74528 * If anonymous vma has not yet been faulted, update new pgoff
74529 * to match new location, to increase its chance of merging.
74530 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74531 return NULL;
74532 }
74533
74534 +#ifdef CONFIG_PAX_SEGMEXEC
74535 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74536 +{
74537 + struct vm_area_struct *prev_m;
74538 + struct rb_node **rb_link_m, *rb_parent_m;
74539 + struct mempolicy *pol_m;
74540 +
74541 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74542 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74543 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74544 + *vma_m = *vma;
74545 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74546 + if (anon_vma_clone(vma_m, vma))
74547 + return -ENOMEM;
74548 + pol_m = vma_policy(vma_m);
74549 + mpol_get(pol_m);
74550 + vma_set_policy(vma_m, pol_m);
74551 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74552 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74553 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74554 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74555 + if (vma_m->vm_file)
74556 + get_file(vma_m->vm_file);
74557 + if (vma_m->vm_ops && vma_m->vm_ops->open)
74558 + vma_m->vm_ops->open(vma_m);
74559 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
74560 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74561 + vma_m->vm_mirror = vma;
74562 + vma->vm_mirror = vma_m;
74563 + return 0;
74564 +}
74565 +#endif
74566 +
74567 /*
74568 * Return true if the calling process may expand its vm space by the passed
74569 * number of pages
74570 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74571
74572 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74573
74574 +#ifdef CONFIG_PAX_RANDMMAP
74575 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74576 + cur -= mm->brk_gap;
74577 +#endif
74578 +
74579 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74580 if (cur + npages > lim)
74581 return 0;
74582 return 1;
74583 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
74584 vma->vm_start = addr;
74585 vma->vm_end = addr + len;
74586
74587 +#ifdef CONFIG_PAX_MPROTECT
74588 + if (mm->pax_flags & MF_PAX_MPROTECT) {
74589 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
74590 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74591 + return -EPERM;
74592 + if (!(vm_flags & VM_EXEC))
74593 + vm_flags &= ~VM_MAYEXEC;
74594 +#else
74595 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74596 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74597 +#endif
74598 + else
74599 + vm_flags &= ~VM_MAYWRITE;
74600 + }
74601 +#endif
74602 +
74603 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74604 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74605
74606 diff --git a/mm/mprotect.c b/mm/mprotect.c
74607 index a409926..8b32e6d 100644
74608 --- a/mm/mprotect.c
74609 +++ b/mm/mprotect.c
74610 @@ -23,10 +23,17 @@
74611 #include <linux/mmu_notifier.h>
74612 #include <linux/migrate.h>
74613 #include <linux/perf_event.h>
74614 +
74615 +#ifdef CONFIG_PAX_MPROTECT
74616 +#include <linux/elf.h>
74617 +#include <linux/binfmts.h>
74618 +#endif
74619 +
74620 #include <asm/uaccess.h>
74621 #include <asm/pgtable.h>
74622 #include <asm/cacheflush.h>
74623 #include <asm/tlbflush.h>
74624 +#include <asm/mmu_context.h>
74625
74626 #ifndef pgprot_modify
74627 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74628 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74629 flush_tlb_range(vma, start, end);
74630 }
74631
74632 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74633 +/* called while holding the mmap semaphor for writing except stack expansion */
74634 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74635 +{
74636 + unsigned long oldlimit, newlimit = 0UL;
74637 +
74638 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74639 + return;
74640 +
74641 + spin_lock(&mm->page_table_lock);
74642 + oldlimit = mm->context.user_cs_limit;
74643 + if ((prot & VM_EXEC) && oldlimit < end)
74644 + /* USER_CS limit moved up */
74645 + newlimit = end;
74646 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74647 + /* USER_CS limit moved down */
74648 + newlimit = start;
74649 +
74650 + if (newlimit) {
74651 + mm->context.user_cs_limit = newlimit;
74652 +
74653 +#ifdef CONFIG_SMP
74654 + wmb();
74655 + cpus_clear(mm->context.cpu_user_cs_mask);
74656 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74657 +#endif
74658 +
74659 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74660 + }
74661 + spin_unlock(&mm->page_table_lock);
74662 + if (newlimit == end) {
74663 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
74664 +
74665 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
74666 + if (is_vm_hugetlb_page(vma))
74667 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74668 + else
74669 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74670 + }
74671 +}
74672 +#endif
74673 +
74674 int
74675 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74676 unsigned long start, unsigned long end, unsigned long newflags)
74677 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74678 int error;
74679 int dirty_accountable = 0;
74680
74681 +#ifdef CONFIG_PAX_SEGMEXEC
74682 + struct vm_area_struct *vma_m = NULL;
74683 + unsigned long start_m, end_m;
74684 +
74685 + start_m = start + SEGMEXEC_TASK_SIZE;
74686 + end_m = end + SEGMEXEC_TASK_SIZE;
74687 +#endif
74688 +
74689 if (newflags == oldflags) {
74690 *pprev = vma;
74691 return 0;
74692 }
74693
74694 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74695 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74696 +
74697 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74698 + return -ENOMEM;
74699 +
74700 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74701 + return -ENOMEM;
74702 + }
74703 +
74704 /*
74705 * If we make a private mapping writable we increase our commit;
74706 * but (without finer accounting) cannot reduce our commit if we
74707 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74708 }
74709 }
74710
74711 +#ifdef CONFIG_PAX_SEGMEXEC
74712 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74713 + if (start != vma->vm_start) {
74714 + error = split_vma(mm, vma, start, 1);
74715 + if (error)
74716 + goto fail;
74717 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74718 + *pprev = (*pprev)->vm_next;
74719 + }
74720 +
74721 + if (end != vma->vm_end) {
74722 + error = split_vma(mm, vma, end, 0);
74723 + if (error)
74724 + goto fail;
74725 + }
74726 +
74727 + if (pax_find_mirror_vma(vma)) {
74728 + error = __do_munmap(mm, start_m, end_m - start_m);
74729 + if (error)
74730 + goto fail;
74731 + } else {
74732 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74733 + if (!vma_m) {
74734 + error = -ENOMEM;
74735 + goto fail;
74736 + }
74737 + vma->vm_flags = newflags;
74738 + error = pax_mirror_vma(vma_m, vma);
74739 + if (error) {
74740 + vma->vm_flags = oldflags;
74741 + goto fail;
74742 + }
74743 + }
74744 + }
74745 +#endif
74746 +
74747 /*
74748 * First try to merge with previous and/or next vma.
74749 */
74750 @@ -204,9 +307,21 @@ success:
74751 * vm_flags and vm_page_prot are protected by the mmap_sem
74752 * held in write mode.
74753 */
74754 +
74755 +#ifdef CONFIG_PAX_SEGMEXEC
74756 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74757 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74758 +#endif
74759 +
74760 vma->vm_flags = newflags;
74761 +
74762 +#ifdef CONFIG_PAX_MPROTECT
74763 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74764 + mm->binfmt->handle_mprotect(vma, newflags);
74765 +#endif
74766 +
74767 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74768 - vm_get_page_prot(newflags));
74769 + vm_get_page_prot(vma->vm_flags));
74770
74771 if (vma_wants_writenotify(vma)) {
74772 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74773 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74774 end = start + len;
74775 if (end <= start)
74776 return -ENOMEM;
74777 +
74778 +#ifdef CONFIG_PAX_SEGMEXEC
74779 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74780 + if (end > SEGMEXEC_TASK_SIZE)
74781 + return -EINVAL;
74782 + } else
74783 +#endif
74784 +
74785 + if (end > TASK_SIZE)
74786 + return -EINVAL;
74787 +
74788 if (!arch_validate_prot(prot))
74789 return -EINVAL;
74790
74791 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74792 /*
74793 * Does the application expect PROT_READ to imply PROT_EXEC:
74794 */
74795 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74796 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74797 prot |= PROT_EXEC;
74798
74799 vm_flags = calc_vm_prot_bits(prot);
74800 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74801 if (start > vma->vm_start)
74802 prev = vma;
74803
74804 +#ifdef CONFIG_PAX_MPROTECT
74805 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74806 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74807 +#endif
74808 +
74809 for (nstart = start ; ; ) {
74810 unsigned long newflags;
74811
74812 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74813
74814 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74815 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74816 + if (prot & (PROT_WRITE | PROT_EXEC))
74817 + gr_log_rwxmprotect(vma->vm_file);
74818 +
74819 + error = -EACCES;
74820 + goto out;
74821 + }
74822 +
74823 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74824 error = -EACCES;
74825 goto out;
74826 }
74827 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74828 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74829 if (error)
74830 goto out;
74831 +
74832 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74833 +
74834 nstart = tmp;
74835
74836 if (nstart < prev->vm_end)
74837 diff --git a/mm/mremap.c b/mm/mremap.c
74838 index cc06d0e..40b5d18 100644
74839 --- a/mm/mremap.c
74840 +++ b/mm/mremap.c
74841 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74842 continue;
74843 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74844 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74845 +
74846 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74847 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74848 + pte = pte_exprotect(pte);
74849 +#endif
74850 +
74851 set_pte_at(mm, new_addr, new_pte, pte);
74852 }
74853
74854 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74855 if (is_vm_hugetlb_page(vma))
74856 goto Einval;
74857
74858 +#ifdef CONFIG_PAX_SEGMEXEC
74859 + if (pax_find_mirror_vma(vma))
74860 + goto Einval;
74861 +#endif
74862 +
74863 /* We can't remap across vm area boundaries */
74864 if (old_len > vma->vm_end - addr)
74865 goto Efault;
74866 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74867 unsigned long ret = -EINVAL;
74868 unsigned long charged = 0;
74869 unsigned long map_flags;
74870 + unsigned long pax_task_size = TASK_SIZE;
74871
74872 if (new_addr & ~PAGE_MASK)
74873 goto out;
74874
74875 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74876 +#ifdef CONFIG_PAX_SEGMEXEC
74877 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74878 + pax_task_size = SEGMEXEC_TASK_SIZE;
74879 +#endif
74880 +
74881 + pax_task_size -= PAGE_SIZE;
74882 +
74883 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74884 goto out;
74885
74886 /* Check if the location we're moving into overlaps the
74887 * old location at all, and fail if it does.
74888 */
74889 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74890 - goto out;
74891 -
74892 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74893 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74894 goto out;
74895
74896 ret = do_munmap(mm, new_addr, new_len);
74897 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74898 struct vm_area_struct *vma;
74899 unsigned long ret = -EINVAL;
74900 unsigned long charged = 0;
74901 + unsigned long pax_task_size = TASK_SIZE;
74902
74903 down_write(&current->mm->mmap_sem);
74904
74905 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74906 if (!new_len)
74907 goto out;
74908
74909 +#ifdef CONFIG_PAX_SEGMEXEC
74910 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74911 + pax_task_size = SEGMEXEC_TASK_SIZE;
74912 +#endif
74913 +
74914 + pax_task_size -= PAGE_SIZE;
74915 +
74916 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74917 + old_len > pax_task_size || addr > pax_task_size-old_len)
74918 + goto out;
74919 +
74920 if (flags & MREMAP_FIXED) {
74921 if (flags & MREMAP_MAYMOVE)
74922 ret = mremap_to(addr, old_len, new_addr, new_len);
74923 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74924 addr + new_len);
74925 }
74926 ret = addr;
74927 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74928 goto out;
74929 }
74930 }
74931 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74932 goto out;
74933 }
74934
74935 + map_flags = vma->vm_flags;
74936 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74937 + if (!(ret & ~PAGE_MASK)) {
74938 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74939 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74940 + }
74941 }
74942 out:
74943 if (ret & ~PAGE_MASK)
74944 diff --git a/mm/nommu.c b/mm/nommu.c
74945 index d4b0c10..ed421b5 100644
74946 --- a/mm/nommu.c
74947 +++ b/mm/nommu.c
74948 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74949 int sysctl_overcommit_ratio = 50; /* default is 50% */
74950 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74951 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74952 -int heap_stack_gap = 0;
74953
74954 atomic_long_t mmap_pages_allocated;
74955
74956 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74957 EXPORT_SYMBOL(find_vma);
74958
74959 /*
74960 - * find a VMA
74961 - * - we don't extend stack VMAs under NOMMU conditions
74962 - */
74963 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74964 -{
74965 - return find_vma(mm, addr);
74966 -}
74967 -
74968 -/*
74969 * expand a stack to a given address
74970 * - not supported under NOMMU conditions
74971 */
74972 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74973
74974 /* most fields are the same, copy all, and then fixup */
74975 *new = *vma;
74976 + INIT_LIST_HEAD(&new->anon_vma_chain);
74977 *region = *vma->vm_region;
74978 new->vm_region = region;
74979
74980 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74981 index c13ea75..081ab2c 100644
74982 --- a/mm/page_alloc.c
74983 +++ b/mm/page_alloc.c
74984 @@ -340,7 +340,7 @@ out:
74985 * This usage means that zero-order pages may not be compound.
74986 */
74987
74988 -static void free_compound_page(struct page *page)
74989 +void free_compound_page(struct page *page)
74990 {
74991 __free_pages_ok(page, compound_order(page));
74992 }
74993 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74994 int i;
74995 int bad = 0;
74996
74997 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74998 + unsigned long index = 1UL << order;
74999 +#endif
75000 +
75001 trace_mm_page_free(page, order);
75002 kmemcheck_free_shadow(page, order);
75003
75004 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
75005 debug_check_no_obj_freed(page_address(page),
75006 PAGE_SIZE << order);
75007 }
75008 +
75009 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
75010 + for (; index; --index)
75011 + sanitize_highpage(page + index - 1);
75012 +#endif
75013 +
75014 arch_free_page(page, order);
75015 kernel_map_pages(page, 1 << order, 0);
75016
75017 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
75018 arch_alloc_page(page, order);
75019 kernel_map_pages(page, 1 << order, 1);
75020
75021 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
75022 if (gfp_flags & __GFP_ZERO)
75023 prep_zero_page(page, order, gfp_flags);
75024 +#endif
75025
75026 if (order && (gfp_flags & __GFP_COMP))
75027 prep_compound_page(page, order);
75028 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
75029 unsigned long pfn;
75030
75031 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
75032 +#ifdef CONFIG_X86_32
75033 + /* boot failures in VMware 8 on 32bit vanilla since
75034 + this change */
75035 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
75036 +#else
75037 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
75038 +#endif
75039 return 1;
75040 }
75041 return 0;
75042 diff --git a/mm/percpu.c b/mm/percpu.c
75043 index bb4be74..a43ea85 100644
75044 --- a/mm/percpu.c
75045 +++ b/mm/percpu.c
75046 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
75047 static unsigned int pcpu_high_unit_cpu __read_mostly;
75048
75049 /* the address of the first chunk which starts with the kernel static area */
75050 -void *pcpu_base_addr __read_mostly;
75051 +void *pcpu_base_addr __read_only;
75052 EXPORT_SYMBOL_GPL(pcpu_base_addr);
75053
75054 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
75055 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
75056 index 926b466..b23df53 100644
75057 --- a/mm/process_vm_access.c
75058 +++ b/mm/process_vm_access.c
75059 @@ -13,6 +13,7 @@
75060 #include <linux/uio.h>
75061 #include <linux/sched.h>
75062 #include <linux/highmem.h>
75063 +#include <linux/security.h>
75064 #include <linux/ptrace.h>
75065 #include <linux/slab.h>
75066 #include <linux/syscalls.h>
75067 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
75068 size_t iov_l_curr_offset = 0;
75069 ssize_t iov_len;
75070
75071 + return -ENOSYS; // PaX: until properly audited
75072 +
75073 /*
75074 * Work out how many pages of struct pages we're going to need
75075 * when eventually calling get_user_pages
75076 */
75077 for (i = 0; i < riovcnt; i++) {
75078 iov_len = rvec[i].iov_len;
75079 - if (iov_len > 0) {
75080 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
75081 - + iov_len)
75082 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
75083 - / PAGE_SIZE + 1;
75084 - nr_pages = max(nr_pages, nr_pages_iov);
75085 - }
75086 + if (iov_len <= 0)
75087 + continue;
75088 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
75089 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
75090 + nr_pages = max(nr_pages, nr_pages_iov);
75091 }
75092
75093 if (nr_pages == 0)
75094 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
75095 goto free_proc_pages;
75096 }
75097
75098 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
75099 + rc = -EPERM;
75100 + goto put_task_struct;
75101 + }
75102 +
75103 mm = mm_access(task, PTRACE_MODE_ATTACH);
75104 if (!mm || IS_ERR(mm)) {
75105 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
75106 diff --git a/mm/rmap.c b/mm/rmap.c
75107 index aa95e59..b681a63 100644
75108 --- a/mm/rmap.c
75109 +++ b/mm/rmap.c
75110 @@ -168,6 +168,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75111 struct anon_vma *anon_vma = vma->anon_vma;
75112 struct anon_vma_chain *avc;
75113
75114 +#ifdef CONFIG_PAX_SEGMEXEC
75115 + struct anon_vma_chain *avc_m = NULL;
75116 +#endif
75117 +
75118 might_sleep();
75119 if (unlikely(!anon_vma)) {
75120 struct mm_struct *mm = vma->vm_mm;
75121 @@ -177,6 +181,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75122 if (!avc)
75123 goto out_enomem;
75124
75125 +#ifdef CONFIG_PAX_SEGMEXEC
75126 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
75127 + if (!avc_m)
75128 + goto out_enomem_free_avc;
75129 +#endif
75130 +
75131 anon_vma = find_mergeable_anon_vma(vma);
75132 allocated = NULL;
75133 if (!anon_vma) {
75134 @@ -190,6 +200,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75135 /* page_table_lock to protect against threads */
75136 spin_lock(&mm->page_table_lock);
75137 if (likely(!vma->anon_vma)) {
75138 +
75139 +#ifdef CONFIG_PAX_SEGMEXEC
75140 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
75141 +
75142 + if (vma_m) {
75143 + BUG_ON(vma_m->anon_vma);
75144 + vma_m->anon_vma = anon_vma;
75145 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
75146 + avc_m = NULL;
75147 + }
75148 +#endif
75149 +
75150 vma->anon_vma = anon_vma;
75151 anon_vma_chain_link(vma, avc, anon_vma);
75152 allocated = NULL;
75153 @@ -200,12 +222,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75154
75155 if (unlikely(allocated))
75156 put_anon_vma(allocated);
75157 +
75158 +#ifdef CONFIG_PAX_SEGMEXEC
75159 + if (unlikely(avc_m))
75160 + anon_vma_chain_free(avc_m);
75161 +#endif
75162 +
75163 if (unlikely(avc))
75164 anon_vma_chain_free(avc);
75165 }
75166 return 0;
75167
75168 out_enomem_free_avc:
75169 +
75170 +#ifdef CONFIG_PAX_SEGMEXEC
75171 + if (avc_m)
75172 + anon_vma_chain_free(avc_m);
75173 +#endif
75174 +
75175 anon_vma_chain_free(avc);
75176 out_enomem:
75177 return -ENOMEM;
75178 @@ -241,7 +275,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
75179 * Attach the anon_vmas from src to dst.
75180 * Returns 0 on success, -ENOMEM on failure.
75181 */
75182 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
75183 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
75184 {
75185 struct anon_vma_chain *avc, *pavc;
75186 struct anon_vma *root = NULL;
75187 @@ -319,7 +353,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
75188 * the corresponding VMA in the parent process is attached to.
75189 * Returns 0 on success, non-zero on failure.
75190 */
75191 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
75192 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
75193 {
75194 struct anon_vma_chain *avc;
75195 struct anon_vma *anon_vma;
75196 diff --git a/mm/shmem.c b/mm/shmem.c
75197 index d2eeca1..92f3123 100644
75198 --- a/mm/shmem.c
75199 +++ b/mm/shmem.c
75200 @@ -31,7 +31,7 @@
75201 #include <linux/export.h>
75202 #include <linux/swap.h>
75203
75204 -static struct vfsmount *shm_mnt;
75205 +struct vfsmount *shm_mnt;
75206
75207 #ifdef CONFIG_SHMEM
75208 /*
75209 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
75210 #define BOGO_DIRENT_SIZE 20
75211
75212 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
75213 -#define SHORT_SYMLINK_LEN 128
75214 +#define SHORT_SYMLINK_LEN 64
75215
75216 struct shmem_xattr {
75217 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
75218 @@ -2207,6 +2207,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
75219 static int shmem_xattr_validate(const char *name)
75220 {
75221 struct { const char *prefix; size_t len; } arr[] = {
75222 +
75223 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75224 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
75225 +#endif
75226 +
75227 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
75228 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
75229 };
75230 @@ -2260,6 +2265,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
75231 if (err)
75232 return err;
75233
75234 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75235 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
75236 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
75237 + return -EOPNOTSUPP;
75238 + if (size > 8)
75239 + return -EINVAL;
75240 + }
75241 +#endif
75242 +
75243 if (size == 0)
75244 value = ""; /* empty EA, do not remove */
75245
75246 @@ -2594,8 +2608,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
75247 int err = -ENOMEM;
75248
75249 /* Round up to L1_CACHE_BYTES to resist false sharing */
75250 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
75251 - L1_CACHE_BYTES), GFP_KERNEL);
75252 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
75253 if (!sbinfo)
75254 return -ENOMEM;
75255
75256 diff --git a/mm/slab.c b/mm/slab.c
75257 index d066037..5bb78d9 100644
75258 --- a/mm/slab.c
75259 +++ b/mm/slab.c
75260 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
75261
75262 /* Legal flag mask for kmem_cache_create(). */
75263 #if DEBUG
75264 -# define CREATE_MASK (SLAB_RED_ZONE | \
75265 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
75266 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
75267 SLAB_CACHE_DMA | \
75268 SLAB_STORE_USER | \
75269 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
75270 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75271 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
75272 #else
75273 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
75274 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
75275 SLAB_CACHE_DMA | \
75276 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
75277 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75278 @@ -322,7 +322,7 @@ struct kmem_list3 {
75279 * Need this for bootstrapping a per node allocator.
75280 */
75281 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
75282 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
75283 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
75284 #define CACHE_CACHE 0
75285 #define SIZE_AC MAX_NUMNODES
75286 #define SIZE_L3 (2 * MAX_NUMNODES)
75287 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
75288 if ((x)->max_freeable < i) \
75289 (x)->max_freeable = i; \
75290 } while (0)
75291 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
75292 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
75293 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
75294 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
75295 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
75296 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
75297 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
75298 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
75299 #else
75300 #define STATS_INC_ACTIVE(x) do { } while (0)
75301 #define STATS_DEC_ACTIVE(x) do { } while (0)
75302 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
75303 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
75304 */
75305 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
75306 - const struct slab *slab, void *obj)
75307 + const struct slab *slab, const void *obj)
75308 {
75309 u32 offset = (obj - slab->s_mem);
75310 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
75311 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
75312 struct cache_names {
75313 char *name;
75314 char *name_dma;
75315 + char *name_usercopy;
75316 };
75317
75318 static struct cache_names __initdata cache_names[] = {
75319 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
75320 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
75321 #include <linux/kmalloc_sizes.h>
75322 - {NULL,}
75323 + {NULL}
75324 #undef CACHE
75325 };
75326
75327 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
75328 if (unlikely(gfpflags & GFP_DMA))
75329 return csizep->cs_dmacachep;
75330 #endif
75331 +
75332 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75333 + if (unlikely(gfpflags & GFP_USERCOPY))
75334 + return csizep->cs_usercopycachep;
75335 +#endif
75336 +
75337 return csizep->cs_cachep;
75338 }
75339
75340 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
75341 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
75342 sizes[INDEX_AC].cs_size,
75343 ARCH_KMALLOC_MINALIGN,
75344 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75345 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75346 NULL);
75347
75348 if (INDEX_AC != INDEX_L3) {
75349 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
75350 __kmem_cache_create(names[INDEX_L3].name,
75351 sizes[INDEX_L3].cs_size,
75352 ARCH_KMALLOC_MINALIGN,
75353 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75354 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75355 NULL);
75356 }
75357
75358 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
75359 sizes->cs_cachep = __kmem_cache_create(names->name,
75360 sizes->cs_size,
75361 ARCH_KMALLOC_MINALIGN,
75362 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75363 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75364 NULL);
75365 }
75366 #ifdef CONFIG_ZONE_DMA
75367 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
75368 SLAB_PANIC,
75369 NULL);
75370 #endif
75371 +
75372 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75373 + sizes->cs_usercopycachep = kmem_cache_create(
75374 + names->name_usercopy,
75375 + sizes->cs_size,
75376 + ARCH_KMALLOC_MINALIGN,
75377 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75378 + NULL);
75379 +#endif
75380 +
75381 sizes++;
75382 names++;
75383 }
75384 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
75385 }
75386 /* cpu stats */
75387 {
75388 - unsigned long allochit = atomic_read(&cachep->allochit);
75389 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
75390 - unsigned long freehit = atomic_read(&cachep->freehit);
75391 - unsigned long freemiss = atomic_read(&cachep->freemiss);
75392 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
75393 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
75394 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
75395 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
75396
75397 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
75398 allochit, allocmiss, freehit, freemiss);
75399 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
75400 {
75401 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
75402 #ifdef CONFIG_DEBUG_SLAB_LEAK
75403 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
75404 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
75405 #endif
75406 return 0;
75407 }
75408 module_init(slab_proc_init);
75409 #endif
75410
75411 +bool is_usercopy_object(const void *ptr)
75412 +{
75413 + struct page *page;
75414 + struct kmem_cache *cachep;
75415 +
75416 + if (ZERO_OR_NULL_PTR(ptr))
75417 + return false;
75418 +
75419 + if (!slab_is_available())
75420 + return false;
75421 +
75422 + if (!virt_addr_valid(ptr))
75423 + return false;
75424 +
75425 + page = virt_to_head_page(ptr);
75426 +
75427 + if (!PageSlab(page))
75428 + return false;
75429 +
75430 + cachep = page_get_cache(page);
75431 + return cachep->flags & SLAB_USERCOPY;
75432 +}
75433 +
75434 +#ifdef CONFIG_PAX_USERCOPY
75435 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75436 +{
75437 + struct page *page;
75438 + struct kmem_cache *cachep;
75439 + struct slab *slabp;
75440 + unsigned int objnr;
75441 + unsigned long offset;
75442 +
75443 + if (ZERO_OR_NULL_PTR(ptr))
75444 + return "<null>";
75445 +
75446 + if (!virt_addr_valid(ptr))
75447 + return NULL;
75448 +
75449 + page = virt_to_head_page(ptr);
75450 +
75451 + if (!PageSlab(page))
75452 + return NULL;
75453 +
75454 + cachep = page_get_cache(page);
75455 + if (!(cachep->flags & SLAB_USERCOPY))
75456 + return cachep->name;
75457 +
75458 + slabp = page->slab_page;
75459 + objnr = obj_to_index(cachep, slabp, ptr);
75460 + BUG_ON(objnr >= cachep->num);
75461 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
75462 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
75463 + return NULL;
75464 +
75465 + return cachep->name;
75466 +}
75467 +#endif
75468 +
75469 /**
75470 * ksize - get the actual amount of memory allocated for a given object
75471 * @objp: Pointer to the object
75472 diff --git a/mm/slob.c b/mm/slob.c
75473 index 45d4ca7..88943c1 100644
75474 --- a/mm/slob.c
75475 +++ b/mm/slob.c
75476 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
75477 /*
75478 * Return the size of a slob block.
75479 */
75480 -static slobidx_t slob_units(slob_t *s)
75481 +static slobidx_t slob_units(const slob_t *s)
75482 {
75483 if (s->units > 0)
75484 return s->units;
75485 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
75486 /*
75487 * Return the next free slob block pointer after this one.
75488 */
75489 -static slob_t *slob_next(slob_t *s)
75490 +static slob_t *slob_next(const slob_t *s)
75491 {
75492 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
75493 slobidx_t next;
75494 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
75495 /*
75496 * Returns true if s is the last free block in its page.
75497 */
75498 -static int slob_last(slob_t *s)
75499 +static int slob_last(const slob_t *s)
75500 {
75501 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
75502 }
75503
75504 -static void *slob_new_pages(gfp_t gfp, int order, int node)
75505 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
75506 {
75507 - void *page;
75508 + struct page *page;
75509
75510 #ifdef CONFIG_NUMA
75511 if (node != -1)
75512 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
75513 if (!page)
75514 return NULL;
75515
75516 - return page_address(page);
75517 + __SetPageSlab(page);
75518 + return page;
75519 }
75520
75521 -static void slob_free_pages(void *b, int order)
75522 +static void slob_free_pages(struct page *sp, int order)
75523 {
75524 if (current->reclaim_state)
75525 current->reclaim_state->reclaimed_slab += 1 << order;
75526 - free_pages((unsigned long)b, order);
75527 + __ClearPageSlab(sp);
75528 + reset_page_mapcount(sp);
75529 + sp->private = 0;
75530 + __free_pages(sp, order);
75531 }
75532
75533 /*
75534 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
75535
75536 /* Not enough space: must allocate a new page */
75537 if (!b) {
75538 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75539 - if (!b)
75540 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75541 + if (!sp)
75542 return NULL;
75543 - sp = virt_to_page(b);
75544 - __SetPageSlab(sp);
75545 + b = page_address(sp);
75546
75547 spin_lock_irqsave(&slob_lock, flags);
75548 sp->units = SLOB_UNITS(PAGE_SIZE);
75549 sp->freelist = b;
75550 + sp->private = 0;
75551 INIT_LIST_HEAD(&sp->list);
75552 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
75553 set_slob_page_free(sp, slob_list);
75554 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
75555 if (slob_page_free(sp))
75556 clear_slob_page_free(sp);
75557 spin_unlock_irqrestore(&slob_lock, flags);
75558 - __ClearPageSlab(sp);
75559 - reset_page_mapcount(sp);
75560 - slob_free_pages(b, 0);
75561 + slob_free_pages(sp, 0);
75562 return;
75563 }
75564
75565 @@ -425,11 +427,10 @@ out:
75566 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
75567 */
75568
75569 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75570 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
75571 {
75572 - unsigned int *m;
75573 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75574 - void *ret;
75575 + slob_t *m;
75576 + void *ret = NULL;
75577
75578 gfp &= gfp_allowed_mask;
75579
75580 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75581
75582 if (!m)
75583 return NULL;
75584 - *m = size;
75585 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75586 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75587 + m[0].units = size;
75588 + m[1].units = align;
75589 ret = (void *)m + align;
75590
75591 trace_kmalloc_node(_RET_IP_, ret,
75592 size, size + align, gfp, node);
75593 } else {
75594 unsigned int order = get_order(size);
75595 + struct page *page;
75596
75597 if (likely(order))
75598 gfp |= __GFP_COMP;
75599 - ret = slob_new_pages(gfp, order, node);
75600 - if (ret) {
75601 - struct page *page;
75602 - page = virt_to_page(ret);
75603 + page = slob_new_pages(gfp, order, node);
75604 + if (page) {
75605 + ret = page_address(page);
75606 page->private = size;
75607 }
75608
75609 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75610 size, PAGE_SIZE << order, gfp, node);
75611 }
75612
75613 - kmemleak_alloc(ret, size, 1, gfp);
75614 + return ret;
75615 +}
75616 +
75617 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75618 +{
75619 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75620 + void *ret = __kmalloc_node_align(size, gfp, node, align);
75621 +
75622 + if (!ZERO_OR_NULL_PTR(ret))
75623 + kmemleak_alloc(ret, size, 1, gfp);
75624 return ret;
75625 }
75626 EXPORT_SYMBOL(__kmalloc_node);
75627 @@ -480,15 +493,91 @@ void kfree(const void *block)
75628 kmemleak_free(block);
75629
75630 sp = virt_to_page(block);
75631 - if (PageSlab(sp)) {
75632 + VM_BUG_ON(!PageSlab(sp));
75633 + if (!sp->private) {
75634 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75635 - unsigned int *m = (unsigned int *)(block - align);
75636 - slob_free(m, *m + align);
75637 - } else
75638 + slob_t *m = (slob_t *)(block - align);
75639 + slob_free(m, m[0].units + align);
75640 + } else {
75641 + __ClearPageSlab(sp);
75642 + reset_page_mapcount(sp);
75643 + sp->private = 0;
75644 put_page(sp);
75645 + }
75646 }
75647 EXPORT_SYMBOL(kfree);
75648
75649 +bool is_usercopy_object(const void *ptr)
75650 +{
75651 + if (!slab_is_available())
75652 + return false;
75653 +
75654 + // PAX: TODO
75655 +
75656 + return false;
75657 +}
75658 +
75659 +#ifdef CONFIG_PAX_USERCOPY
75660 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75661 +{
75662 + struct page *page;
75663 + const slob_t *free;
75664 + const void *base;
75665 + unsigned long flags;
75666 +
75667 + if (ZERO_OR_NULL_PTR(ptr))
75668 + return "<null>";
75669 +
75670 + if (!virt_addr_valid(ptr))
75671 + return NULL;
75672 +
75673 + page = virt_to_head_page(ptr);
75674 + if (!PageSlab(page))
75675 + return NULL;
75676 +
75677 + if (page->private) {
75678 + base = page;
75679 + if (base <= ptr && n <= page->private - (ptr - base))
75680 + return NULL;
75681 + return "<slob>";
75682 + }
75683 +
75684 + /* some tricky double walking to find the chunk */
75685 + spin_lock_irqsave(&slob_lock, flags);
75686 + base = (void *)((unsigned long)ptr & PAGE_MASK);
75687 + free = page->freelist;
75688 +
75689 + while (!slob_last(free) && (void *)free <= ptr) {
75690 + base = free + slob_units(free);
75691 + free = slob_next(free);
75692 + }
75693 +
75694 + while (base < (void *)free) {
75695 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75696 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
75697 + int offset;
75698 +
75699 + if (ptr < base + align)
75700 + break;
75701 +
75702 + offset = ptr - base - align;
75703 + if (offset >= m) {
75704 + base += size;
75705 + continue;
75706 + }
75707 +
75708 + if (n > m - offset)
75709 + break;
75710 +
75711 + spin_unlock_irqrestore(&slob_lock, flags);
75712 + return NULL;
75713 + }
75714 +
75715 + spin_unlock_irqrestore(&slob_lock, flags);
75716 + return "<slob>";
75717 +}
75718 +#endif
75719 +
75720 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75721 size_t ksize(const void *block)
75722 {
75723 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
75724 return 0;
75725
75726 sp = virt_to_page(block);
75727 - if (PageSlab(sp)) {
75728 + VM_BUG_ON(!PageSlab(sp));
75729 + if (!sp->private) {
75730 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75731 - unsigned int *m = (unsigned int *)(block - align);
75732 - return SLOB_UNITS(*m) * SLOB_UNIT;
75733 + slob_t *m = (slob_t *)(block - align);
75734 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75735 } else
75736 return sp->private;
75737 }
75738 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75739 {
75740 struct kmem_cache *c;
75741
75742 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75743 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
75744 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
75745 +#else
75746 c = slob_alloc(sizeof(struct kmem_cache),
75747 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
75748 +#endif
75749
75750 if (c) {
75751 c->name = name;
75752 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
75753
75754 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75755 {
75756 - void *b;
75757 + void *b = NULL;
75758
75759 flags &= gfp_allowed_mask;
75760
75761 lockdep_trace_alloc(flags);
75762
75763 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75764 + b = __kmalloc_node_align(c->size, flags, node, c->align);
75765 +#else
75766 if (c->size < PAGE_SIZE) {
75767 b = slob_alloc(c->size, flags, c->align, node);
75768 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75769 SLOB_UNITS(c->size) * SLOB_UNIT,
75770 flags, node);
75771 } else {
75772 - b = slob_new_pages(flags, get_order(c->size), node);
75773 + struct page *sp;
75774 +
75775 + sp = slob_new_pages(flags, get_order(c->size), node);
75776 + if (sp) {
75777 + b = page_address(sp);
75778 + sp->private = c->size;
75779 + }
75780 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75781 PAGE_SIZE << get_order(c->size),
75782 flags, node);
75783 }
75784 +#endif
75785
75786 if (c->ctor)
75787 c->ctor(b);
75788 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75789
75790 static void __kmem_cache_free(void *b, int size)
75791 {
75792 - if (size < PAGE_SIZE)
75793 + struct page *sp;
75794 +
75795 + sp = virt_to_page(b);
75796 + BUG_ON(!PageSlab(sp));
75797 + if (!sp->private)
75798 slob_free(b, size);
75799 else
75800 - slob_free_pages(b, get_order(size));
75801 + slob_free_pages(sp, get_order(size));
75802 }
75803
75804 static void kmem_rcu_free(struct rcu_head *head)
75805 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75806
75807 void kmem_cache_free(struct kmem_cache *c, void *b)
75808 {
75809 + int size = c->size;
75810 +
75811 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75812 + if (size + c->align < PAGE_SIZE) {
75813 + size += c->align;
75814 + b -= c->align;
75815 + }
75816 +#endif
75817 +
75818 kmemleak_free_recursive(b, c->flags);
75819 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75820 struct slob_rcu *slob_rcu;
75821 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75822 - slob_rcu->size = c->size;
75823 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75824 + slob_rcu->size = size;
75825 call_rcu(&slob_rcu->head, kmem_rcu_free);
75826 } else {
75827 - __kmem_cache_free(b, c->size);
75828 + __kmem_cache_free(b, size);
75829 }
75830
75831 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75832 + trace_kfree(_RET_IP_, b);
75833 +#else
75834 trace_kmem_cache_free(_RET_IP_, b);
75835 +#endif
75836 +
75837 }
75838 EXPORT_SYMBOL(kmem_cache_free);
75839
75840 diff --git a/mm/slub.c b/mm/slub.c
75841 index 2fdd96f..1e2f893 100644
75842 --- a/mm/slub.c
75843 +++ b/mm/slub.c
75844 @@ -201,7 +201,7 @@ struct track {
75845
75846 enum track_item { TRACK_ALLOC, TRACK_FREE };
75847
75848 -#ifdef CONFIG_SYSFS
75849 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75850 static int sysfs_slab_add(struct kmem_cache *);
75851 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75852 static void sysfs_slab_remove(struct kmem_cache *);
75853 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75854 if (!t->addr)
75855 return;
75856
75857 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75858 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75859 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75860 #ifdef CONFIG_STACKTRACE
75861 {
75862 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75863
75864 page = virt_to_head_page(x);
75865
75866 + BUG_ON(!PageSlab(page));
75867 +
75868 slab_free(s, page, x, _RET_IP_);
75869
75870 trace_kmem_cache_free(_RET_IP_, x);
75871 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75872 * Merge control. If this is set then no merging of slab caches will occur.
75873 * (Could be removed. This was introduced to pacify the merge skeptics.)
75874 */
75875 -static int slub_nomerge;
75876 +static int slub_nomerge = 1;
75877
75878 /*
75879 * Calculate the order of allocation given an slab object size.
75880 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75881 else
75882 s->cpu_partial = 30;
75883
75884 - s->refcount = 1;
75885 + atomic_set(&s->refcount, 1);
75886 #ifdef CONFIG_NUMA
75887 s->remote_node_defrag_ratio = 1000;
75888 #endif
75889 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75890 void kmem_cache_destroy(struct kmem_cache *s)
75891 {
75892 mutex_lock(&slab_mutex);
75893 - s->refcount--;
75894 - if (!s->refcount) {
75895 + if (atomic_dec_and_test(&s->refcount)) {
75896 list_del(&s->list);
75897 mutex_unlock(&slab_mutex);
75898 if (kmem_cache_close(s)) {
75899 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75900 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75901 #endif
75902
75903 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75904 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75905 +#endif
75906 +
75907 static int __init setup_slub_min_order(char *str)
75908 {
75909 get_option(&str, &slub_min_order);
75910 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75911 return kmalloc_dma_caches[index];
75912
75913 #endif
75914 +
75915 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75916 + if (flags & SLAB_USERCOPY)
75917 + return kmalloc_usercopy_caches[index];
75918 +
75919 +#endif
75920 +
75921 return kmalloc_caches[index];
75922 }
75923
75924 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75925 EXPORT_SYMBOL(__kmalloc_node);
75926 #endif
75927
75928 +bool is_usercopy_object(const void *ptr)
75929 +{
75930 + struct page *page;
75931 + struct kmem_cache *s;
75932 +
75933 + if (ZERO_OR_NULL_PTR(ptr))
75934 + return false;
75935 +
75936 + if (!slab_is_available())
75937 + return false;
75938 +
75939 + if (!virt_addr_valid(ptr))
75940 + return false;
75941 +
75942 + page = virt_to_head_page(ptr);
75943 +
75944 + if (!PageSlab(page))
75945 + return false;
75946 +
75947 + s = page->slab;
75948 + return s->flags & SLAB_USERCOPY;
75949 +}
75950 +
75951 +#ifdef CONFIG_PAX_USERCOPY
75952 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75953 +{
75954 + struct page *page;
75955 + struct kmem_cache *s;
75956 + unsigned long offset;
75957 +
75958 + if (ZERO_OR_NULL_PTR(ptr))
75959 + return "<null>";
75960 +
75961 + if (!virt_addr_valid(ptr))
75962 + return NULL;
75963 +
75964 + page = virt_to_head_page(ptr);
75965 +
75966 + if (!PageSlab(page))
75967 + return NULL;
75968 +
75969 + s = page->slab;
75970 + if (!(s->flags & SLAB_USERCOPY))
75971 + return s->name;
75972 +
75973 + offset = (ptr - page_address(page)) % s->size;
75974 + if (offset <= s->object_size && n <= s->object_size - offset)
75975 + return NULL;
75976 +
75977 + return s->name;
75978 +}
75979 +#endif
75980 +
75981 size_t ksize(const void *object)
75982 {
75983 struct page *page;
75984 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75985 int node;
75986
75987 list_add(&s->list, &slab_caches);
75988 - s->refcount = -1;
75989 + atomic_set(&s->refcount, -1);
75990
75991 for_each_node_state(node, N_NORMAL_MEMORY) {
75992 struct kmem_cache_node *n = get_node(s, node);
75993 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75994
75995 /* Caches that are not of the two-to-the-power-of size */
75996 if (KMALLOC_MIN_SIZE <= 32) {
75997 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75998 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75999 caches++;
76000 }
76001
76002 if (KMALLOC_MIN_SIZE <= 64) {
76003 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
76004 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
76005 caches++;
76006 }
76007
76008 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
76009 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
76010 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
76011 caches++;
76012 }
76013
76014 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
76015 }
76016 }
76017 #endif
76018 +
76019 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76020 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
76021 + struct kmem_cache *s = kmalloc_caches[i];
76022 +
76023 + if (s && s->size) {
76024 + char *name = kasprintf(GFP_NOWAIT,
76025 + "usercopy-kmalloc-%d", s->object_size);
76026 +
76027 + BUG_ON(!name);
76028 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
76029 + s->object_size, SLAB_USERCOPY);
76030 + }
76031 + }
76032 +#endif
76033 +
76034 printk(KERN_INFO
76035 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
76036 " CPUs=%d, Nodes=%d\n",
76037 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
76038 /*
76039 * We may have set a slab to be unmergeable during bootstrap.
76040 */
76041 - if (s->refcount < 0)
76042 + if (atomic_read(&s->refcount) < 0)
76043 return 1;
76044
76045 return 0;
76046 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
76047
76048 s = find_mergeable(size, align, flags, name, ctor);
76049 if (s) {
76050 - s->refcount++;
76051 + atomic_inc(&s->refcount);
76052 /*
76053 * Adjust the object sizes so that we clear
76054 * the complete object on kzalloc.
76055 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
76056 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
76057
76058 if (sysfs_slab_alias(s, name)) {
76059 - s->refcount--;
76060 + atomic_dec(&s->refcount);
76061 return NULL;
76062 }
76063 return s;
76064 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
76065 }
76066 #endif
76067
76068 -#ifdef CONFIG_SYSFS
76069 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76070 static int count_inuse(struct page *page)
76071 {
76072 return page->inuse;
76073 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
76074 validate_slab_cache(kmalloc_caches[9]);
76075 }
76076 #else
76077 -#ifdef CONFIG_SYSFS
76078 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76079 static void resiliency_test(void) {};
76080 #endif
76081 #endif
76082
76083 -#ifdef CONFIG_SYSFS
76084 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76085 enum slab_stat_type {
76086 SL_ALL, /* All slabs */
76087 SL_PARTIAL, /* Only partially allocated slabs */
76088 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
76089
76090 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
76091 {
76092 - return sprintf(buf, "%d\n", s->refcount - 1);
76093 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
76094 }
76095 SLAB_ATTR_RO(aliases);
76096
76097 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
76098 return name;
76099 }
76100
76101 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76102 static int sysfs_slab_add(struct kmem_cache *s)
76103 {
76104 int err;
76105 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
76106 kobject_del(&s->kobj);
76107 kobject_put(&s->kobj);
76108 }
76109 +#endif
76110
76111 /*
76112 * Need to buffer aliases during bootup until sysfs becomes
76113 @@ -5354,6 +5437,7 @@ struct saved_alias {
76114
76115 static struct saved_alias *alias_list;
76116
76117 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76118 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
76119 {
76120 struct saved_alias *al;
76121 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
76122 alias_list = al;
76123 return 0;
76124 }
76125 +#endif
76126
76127 static int __init slab_sysfs_init(void)
76128 {
76129 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
76130 index 1b7e22a..3fcd4f3 100644
76131 --- a/mm/sparse-vmemmap.c
76132 +++ b/mm/sparse-vmemmap.c
76133 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
76134 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
76135 if (!p)
76136 return NULL;
76137 - pud_populate(&init_mm, pud, p);
76138 + pud_populate_kernel(&init_mm, pud, p);
76139 }
76140 return pud;
76141 }
76142 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
76143 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
76144 if (!p)
76145 return NULL;
76146 - pgd_populate(&init_mm, pgd, p);
76147 + pgd_populate_kernel(&init_mm, pgd, p);
76148 }
76149 return pgd;
76150 }
76151 diff --git a/mm/swap.c b/mm/swap.c
76152 index 7782588..228c784 100644
76153 --- a/mm/swap.c
76154 +++ b/mm/swap.c
76155 @@ -30,6 +30,7 @@
76156 #include <linux/backing-dev.h>
76157 #include <linux/memcontrol.h>
76158 #include <linux/gfp.h>
76159 +#include <linux/hugetlb.h>
76160
76161 #include "internal.h"
76162
76163 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
76164
76165 __page_cache_release(page);
76166 dtor = get_compound_page_dtor(page);
76167 + if (!PageHuge(page))
76168 + BUG_ON(dtor != free_compound_page);
76169 (*dtor)(page);
76170 }
76171
76172 diff --git a/mm/swapfile.c b/mm/swapfile.c
76173 index 14e254c..a6af32c 100644
76174 --- a/mm/swapfile.c
76175 +++ b/mm/swapfile.c
76176 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
76177
76178 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
76179 /* Activity counter to indicate that a swapon or swapoff has occurred */
76180 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
76181 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
76182
76183 static inline unsigned char swap_count(unsigned char ent)
76184 {
76185 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
76186 }
76187 filp_close(swap_file, NULL);
76188 err = 0;
76189 - atomic_inc(&proc_poll_event);
76190 + atomic_inc_unchecked(&proc_poll_event);
76191 wake_up_interruptible(&proc_poll_wait);
76192
76193 out_dput:
76194 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
76195
76196 poll_wait(file, &proc_poll_wait, wait);
76197
76198 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
76199 - seq->poll_event = atomic_read(&proc_poll_event);
76200 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
76201 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
76202 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
76203 }
76204
76205 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
76206 return ret;
76207
76208 seq = file->private_data;
76209 - seq->poll_event = atomic_read(&proc_poll_event);
76210 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
76211 return 0;
76212 }
76213
76214 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
76215 (frontswap_map) ? "FS" : "");
76216
76217 mutex_unlock(&swapon_mutex);
76218 - atomic_inc(&proc_poll_event);
76219 + atomic_inc_unchecked(&proc_poll_event);
76220 wake_up_interruptible(&proc_poll_wait);
76221
76222 if (S_ISREG(inode->i_mode))
76223 diff --git a/mm/util.c b/mm/util.c
76224 index 8c7265a..c96d884 100644
76225 --- a/mm/util.c
76226 +++ b/mm/util.c
76227 @@ -285,6 +285,12 @@ done:
76228 void arch_pick_mmap_layout(struct mm_struct *mm)
76229 {
76230 mm->mmap_base = TASK_UNMAPPED_BASE;
76231 +
76232 +#ifdef CONFIG_PAX_RANDMMAP
76233 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76234 + mm->mmap_base += mm->delta_mmap;
76235 +#endif
76236 +
76237 mm->get_unmapped_area = arch_get_unmapped_area;
76238 mm->unmap_area = arch_unmap_area;
76239 }
76240 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
76241 index 2bb90b1..3795e47 100644
76242 --- a/mm/vmalloc.c
76243 +++ b/mm/vmalloc.c
76244 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
76245
76246 pte = pte_offset_kernel(pmd, addr);
76247 do {
76248 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76249 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76250 +
76251 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76252 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
76253 + BUG_ON(!pte_exec(*pte));
76254 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
76255 + continue;
76256 + }
76257 +#endif
76258 +
76259 + {
76260 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76261 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76262 + }
76263 } while (pte++, addr += PAGE_SIZE, addr != end);
76264 }
76265
76266 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
76267 pte = pte_alloc_kernel(pmd, addr);
76268 if (!pte)
76269 return -ENOMEM;
76270 +
76271 + pax_open_kernel();
76272 do {
76273 struct page *page = pages[*nr];
76274
76275 - if (WARN_ON(!pte_none(*pte)))
76276 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76277 + if (pgprot_val(prot) & _PAGE_NX)
76278 +#endif
76279 +
76280 + if (!pte_none(*pte)) {
76281 + pax_close_kernel();
76282 + WARN_ON(1);
76283 return -EBUSY;
76284 - if (WARN_ON(!page))
76285 + }
76286 + if (!page) {
76287 + pax_close_kernel();
76288 + WARN_ON(1);
76289 return -ENOMEM;
76290 + }
76291 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
76292 (*nr)++;
76293 } while (pte++, addr += PAGE_SIZE, addr != end);
76294 + pax_close_kernel();
76295 return 0;
76296 }
76297
76298 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
76299 pmd_t *pmd;
76300 unsigned long next;
76301
76302 - pmd = pmd_alloc(&init_mm, pud, addr);
76303 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
76304 if (!pmd)
76305 return -ENOMEM;
76306 do {
76307 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
76308 pud_t *pud;
76309 unsigned long next;
76310
76311 - pud = pud_alloc(&init_mm, pgd, addr);
76312 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
76313 if (!pud)
76314 return -ENOMEM;
76315 do {
76316 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
76317 * and fall back on vmalloc() if that fails. Others
76318 * just put it in the vmalloc space.
76319 */
76320 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
76321 +#ifdef CONFIG_MODULES
76322 +#ifdef MODULES_VADDR
76323 unsigned long addr = (unsigned long)x;
76324 if (addr >= MODULES_VADDR && addr < MODULES_END)
76325 return 1;
76326 #endif
76327 +
76328 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76329 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
76330 + return 1;
76331 +#endif
76332 +
76333 +#endif
76334 +
76335 return is_vmalloc_addr(x);
76336 }
76337
76338 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
76339
76340 if (!pgd_none(*pgd)) {
76341 pud_t *pud = pud_offset(pgd, addr);
76342 +#ifdef CONFIG_X86
76343 + if (!pud_large(*pud))
76344 +#endif
76345 if (!pud_none(*pud)) {
76346 pmd_t *pmd = pmd_offset(pud, addr);
76347 +#ifdef CONFIG_X86
76348 + if (!pmd_large(*pmd))
76349 +#endif
76350 if (!pmd_none(*pmd)) {
76351 pte_t *ptep, pte;
76352
76353 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
76354 * Allocate a region of KVA of the specified size and alignment, within the
76355 * vstart and vend.
76356 */
76357 -static struct vmap_area *alloc_vmap_area(unsigned long size,
76358 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
76359 unsigned long align,
76360 unsigned long vstart, unsigned long vend,
76361 int node, gfp_t gfp_mask)
76362 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
76363 struct vm_struct *area;
76364
76365 BUG_ON(in_interrupt());
76366 +
76367 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76368 + if (flags & VM_KERNEXEC) {
76369 + if (start != VMALLOC_START || end != VMALLOC_END)
76370 + return NULL;
76371 + start = (unsigned long)MODULES_EXEC_VADDR;
76372 + end = (unsigned long)MODULES_EXEC_END;
76373 + }
76374 +#endif
76375 +
76376 if (flags & VM_IOREMAP) {
76377 int bit = fls(size);
76378
76379 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
76380 if (count > totalram_pages)
76381 return NULL;
76382
76383 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76384 + if (!(pgprot_val(prot) & _PAGE_NX))
76385 + flags |= VM_KERNEXEC;
76386 +#endif
76387 +
76388 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
76389 __builtin_return_address(0));
76390 if (!area)
76391 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
76392 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
76393 goto fail;
76394
76395 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76396 + if (!(pgprot_val(prot) & _PAGE_NX))
76397 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
76398 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
76399 + else
76400 +#endif
76401 +
76402 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
76403 start, end, node, gfp_mask, caller);
76404 if (!area)
76405 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
76406 * For tight control over page level allocator and protection flags
76407 * use __vmalloc() instead.
76408 */
76409 -
76410 void *vmalloc_exec(unsigned long size)
76411 {
76412 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
76413 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
76414 -1, __builtin_return_address(0));
76415 }
76416
76417 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
76418 unsigned long uaddr = vma->vm_start;
76419 unsigned long usize = vma->vm_end - vma->vm_start;
76420
76421 + BUG_ON(vma->vm_mirror);
76422 +
76423 if ((PAGE_SIZE-1) & (unsigned long)addr)
76424 return -EINVAL;
76425
76426 @@ -2572,7 +2634,7 @@ static int s_show(struct seq_file *m, void *p)
76427 {
76428 struct vm_struct *v = p;
76429
76430 - seq_printf(m, "0x%p-0x%p %7ld",
76431 + seq_printf(m, "0x%pK-0x%pK %7ld",
76432 v->addr, v->addr + v->size, v->size);
76433
76434 if (v->caller)
76435 diff --git a/mm/vmscan.c b/mm/vmscan.c
76436 index 99b434b..a018dfc 100644
76437 --- a/mm/vmscan.c
76438 +++ b/mm/vmscan.c
76439 @@ -2953,6 +2953,8 @@ static int kswapd(void *p)
76440 &balanced_classzone_idx);
76441 }
76442 }
76443 +
76444 + current->reclaim_state = NULL;
76445 return 0;
76446 }
76447
76448 diff --git a/mm/vmstat.c b/mm/vmstat.c
76449 index df7a674..8b4a4f3 100644
76450 --- a/mm/vmstat.c
76451 +++ b/mm/vmstat.c
76452 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
76453 *
76454 * vm_stat contains the global counters
76455 */
76456 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76457 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76458 EXPORT_SYMBOL(vm_stat);
76459
76460 #ifdef CONFIG_SMP
76461 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
76462 v = p->vm_stat_diff[i];
76463 p->vm_stat_diff[i] = 0;
76464 local_irq_restore(flags);
76465 - atomic_long_add(v, &zone->vm_stat[i]);
76466 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76467 global_diff[i] += v;
76468 #ifdef CONFIG_NUMA
76469 /* 3 seconds idle till flush */
76470 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
76471
76472 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
76473 if (global_diff[i])
76474 - atomic_long_add(global_diff[i], &vm_stat[i]);
76475 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
76476 }
76477
76478 #endif
76479 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
76480 start_cpu_timer(cpu);
76481 #endif
76482 #ifdef CONFIG_PROC_FS
76483 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
76484 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
76485 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
76486 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
76487 + {
76488 + mode_t gr_mode = S_IRUGO;
76489 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
76490 + gr_mode = S_IRUSR;
76491 +#endif
76492 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
76493 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
76494 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
76495 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
76496 +#else
76497 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
76498 +#endif
76499 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
76500 + }
76501 #endif
76502 return 0;
76503 }
76504 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
76505 index 9096bcb..43ed7bb 100644
76506 --- a/net/8021q/vlan.c
76507 +++ b/net/8021q/vlan.c
76508 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
76509 err = -EPERM;
76510 if (!capable(CAP_NET_ADMIN))
76511 break;
76512 - if ((args.u.name_type >= 0) &&
76513 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
76514 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
76515 struct vlan_net *vn;
76516
76517 vn = net_generic(net, vlan_net_id);
76518 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
76519 index 6449bae..8c1f454 100644
76520 --- a/net/9p/trans_fd.c
76521 +++ b/net/9p/trans_fd.c
76522 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
76523 oldfs = get_fs();
76524 set_fs(get_ds());
76525 /* The cast to a user pointer is valid due to the set_fs() */
76526 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
76527 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
76528 set_fs(oldfs);
76529
76530 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
76531 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
76532 index 876fbe8..8bbea9f 100644
76533 --- a/net/atm/atm_misc.c
76534 +++ b/net/atm/atm_misc.c
76535 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
76536 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
76537 return 1;
76538 atm_return(vcc, truesize);
76539 - atomic_inc(&vcc->stats->rx_drop);
76540 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76541 return 0;
76542 }
76543 EXPORT_SYMBOL(atm_charge);
76544 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
76545 }
76546 }
76547 atm_return(vcc, guess);
76548 - atomic_inc(&vcc->stats->rx_drop);
76549 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76550 return NULL;
76551 }
76552 EXPORT_SYMBOL(atm_alloc_charge);
76553 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
76554
76555 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76556 {
76557 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76558 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76559 __SONET_ITEMS
76560 #undef __HANDLE_ITEM
76561 }
76562 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76563
76564 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76565 {
76566 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76567 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76568 __SONET_ITEMS
76569 #undef __HANDLE_ITEM
76570 }
76571 diff --git a/net/atm/lec.h b/net/atm/lec.h
76572 index a86aff9..3a0d6f6 100644
76573 --- a/net/atm/lec.h
76574 +++ b/net/atm/lec.h
76575 @@ -48,7 +48,7 @@ struct lane2_ops {
76576 const u8 *tlvs, u32 sizeoftlvs);
76577 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76578 const u8 *tlvs, u32 sizeoftlvs);
76579 -};
76580 +} __no_const;
76581
76582 /*
76583 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76584 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76585 index 0919a88..a23d54e 100644
76586 --- a/net/atm/mpc.h
76587 +++ b/net/atm/mpc.h
76588 @@ -33,7 +33,7 @@ struct mpoa_client {
76589 struct mpc_parameters parameters; /* parameters for this client */
76590
76591 const struct net_device_ops *old_ops;
76592 - struct net_device_ops new_ops;
76593 + net_device_ops_no_const new_ops;
76594 };
76595
76596
76597 diff --git a/net/atm/proc.c b/net/atm/proc.c
76598 index 0d020de..011c7bb 100644
76599 --- a/net/atm/proc.c
76600 +++ b/net/atm/proc.c
76601 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76602 const struct k_atm_aal_stats *stats)
76603 {
76604 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76605 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76606 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76607 - atomic_read(&stats->rx_drop));
76608 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76609 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76610 + atomic_read_unchecked(&stats->rx_drop));
76611 }
76612
76613 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76614 diff --git a/net/atm/resources.c b/net/atm/resources.c
76615 index 23f45ce..c748f1a 100644
76616 --- a/net/atm/resources.c
76617 +++ b/net/atm/resources.c
76618 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76619 static void copy_aal_stats(struct k_atm_aal_stats *from,
76620 struct atm_aal_stats *to)
76621 {
76622 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76623 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76624 __AAL_STAT_ITEMS
76625 #undef __HANDLE_ITEM
76626 }
76627 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76628 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76629 struct atm_aal_stats *to)
76630 {
76631 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76632 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76633 __AAL_STAT_ITEMS
76634 #undef __HANDLE_ITEM
76635 }
76636 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76637 index 469daab..262851c 100644
76638 --- a/net/batman-adv/bat_iv_ogm.c
76639 +++ b/net/batman-adv/bat_iv_ogm.c
76640 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76641
76642 /* randomize initial seqno to avoid collision */
76643 get_random_bytes(&random_seqno, sizeof(random_seqno));
76644 - atomic_set(&hard_iface->seqno, random_seqno);
76645 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76646
76647 hard_iface->packet_len = BATADV_OGM_HLEN;
76648 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76649 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76650
76651 /* change sequence number to network order */
76652 batadv_ogm_packet->seqno =
76653 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
76654 - atomic_inc(&hard_iface->seqno);
76655 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
76656 + atomic_inc_unchecked(&hard_iface->seqno);
76657
76658 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
76659 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
76660 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76661 return;
76662
76663 /* could be changed by schedule_own_packet() */
76664 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
76665 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76666
76667 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76668 has_directlink_flag = 1;
76669 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76670 index 282bf6e..4b2603d 100644
76671 --- a/net/batman-adv/hard-interface.c
76672 +++ b/net/batman-adv/hard-interface.c
76673 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76674 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76675 dev_add_pack(&hard_iface->batman_adv_ptype);
76676
76677 - atomic_set(&hard_iface->frag_seqno, 1);
76678 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76679 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76680 hard_iface->net_dev->name);
76681
76682 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76683 /* This can't be called via a bat_priv callback because
76684 * we have no bat_priv yet.
76685 */
76686 - atomic_set(&hard_iface->seqno, 1);
76687 + atomic_set_unchecked(&hard_iface->seqno, 1);
76688 hard_iface->packet_buff = NULL;
76689
76690 return hard_iface;
76691 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76692 index 21c5357..768be1a 100644
76693 --- a/net/batman-adv/soft-interface.c
76694 +++ b/net/batman-adv/soft-interface.c
76695 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76696
76697 /* set broadcast sequence number */
76698 bcast_packet->seqno =
76699 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
76700 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
76701
76702 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76703
76704 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
76705 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76706
76707 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76708 - atomic_set(&bat_priv->bcast_seqno, 1);
76709 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76710 atomic_set(&bat_priv->ttvn, 0);
76711 atomic_set(&bat_priv->tt_local_changes, 0);
76712 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
76713 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76714 index 12635fd..d99d837 100644
76715 --- a/net/batman-adv/types.h
76716 +++ b/net/batman-adv/types.h
76717 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
76718 int16_t if_num;
76719 char if_status;
76720 struct net_device *net_dev;
76721 - atomic_t seqno;
76722 - atomic_t frag_seqno;
76723 + atomic_unchecked_t seqno;
76724 + atomic_unchecked_t frag_seqno;
76725 unsigned char *packet_buff;
76726 int packet_len;
76727 struct kobject *hardif_obj;
76728 @@ -176,7 +176,7 @@ struct batadv_priv {
76729 atomic_t orig_interval; /* uint */
76730 atomic_t hop_penalty; /* uint */
76731 atomic_t log_level; /* uint */
76732 - atomic_t bcast_seqno;
76733 + atomic_unchecked_t bcast_seqno;
76734 atomic_t bcast_queue_left;
76735 atomic_t batman_queue_left;
76736 atomic_t ttvn; /* translation table version number */
76737 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76738 index 0016464..0ef3e53 100644
76739 --- a/net/batman-adv/unicast.c
76740 +++ b/net/batman-adv/unicast.c
76741 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76742 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76743 frag2->flags = large_tail;
76744
76745 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76746 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76747 frag1->seqno = htons(seqno - 1);
76748 frag2->seqno = htons(seqno);
76749
76750 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76751 index d5ace1e..231c4bf 100644
76752 --- a/net/bluetooth/hci_sock.c
76753 +++ b/net/bluetooth/hci_sock.c
76754 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76755 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76756 }
76757
76758 - len = min_t(unsigned int, len, sizeof(uf));
76759 + len = min((size_t)len, sizeof(uf));
76760 if (copy_from_user(&uf, optval, len)) {
76761 err = -EFAULT;
76762 break;
76763 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76764 index 38c00f1..e9d566e 100644
76765 --- a/net/bluetooth/l2cap_core.c
76766 +++ b/net/bluetooth/l2cap_core.c
76767 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76768 break;
76769
76770 case L2CAP_CONF_RFC:
76771 - if (olen == sizeof(rfc))
76772 - memcpy(&rfc, (void *)val, olen);
76773 + if (olen != sizeof(rfc))
76774 + break;
76775 +
76776 + memcpy(&rfc, (void *)val, olen);
76777
76778 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76779 rfc.mode != chan->mode)
76780 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76781 index 34bbe1c..451c19b 100644
76782 --- a/net/bluetooth/l2cap_sock.c
76783 +++ b/net/bluetooth/l2cap_sock.c
76784 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76785 struct sock *sk = sock->sk;
76786 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76787 struct l2cap_options opts;
76788 - int len, err = 0;
76789 + int err = 0;
76790 + size_t len = optlen;
76791 u32 opt;
76792
76793 BT_DBG("sk %p", sk);
76794 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76795 opts.max_tx = chan->max_tx;
76796 opts.txwin_size = chan->tx_win;
76797
76798 - len = min_t(unsigned int, sizeof(opts), optlen);
76799 + len = min(sizeof(opts), len);
76800 if (copy_from_user((char *) &opts, optval, len)) {
76801 err = -EFAULT;
76802 break;
76803 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76804 struct bt_security sec;
76805 struct bt_power pwr;
76806 struct l2cap_conn *conn;
76807 - int len, err = 0;
76808 + int err = 0;
76809 + size_t len = optlen;
76810 u32 opt;
76811
76812 BT_DBG("sk %p", sk);
76813 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76814
76815 sec.level = BT_SECURITY_LOW;
76816
76817 - len = min_t(unsigned int, sizeof(sec), optlen);
76818 + len = min(sizeof(sec), len);
76819 if (copy_from_user((char *) &sec, optval, len)) {
76820 err = -EFAULT;
76821 break;
76822 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76823
76824 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76825
76826 - len = min_t(unsigned int, sizeof(pwr), optlen);
76827 + len = min(sizeof(pwr), len);
76828 if (copy_from_user((char *) &pwr, optval, len)) {
76829 err = -EFAULT;
76830 break;
76831 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76832 index 1a17850..65a3129 100644
76833 --- a/net/bluetooth/rfcomm/sock.c
76834 +++ b/net/bluetooth/rfcomm/sock.c
76835 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76836 struct sock *sk = sock->sk;
76837 struct bt_security sec;
76838 int err = 0;
76839 - size_t len;
76840 + size_t len = optlen;
76841 u32 opt;
76842
76843 BT_DBG("sk %p", sk);
76844 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76845
76846 sec.level = BT_SECURITY_LOW;
76847
76848 - len = min_t(unsigned int, sizeof(sec), optlen);
76849 + len = min(sizeof(sec), len);
76850 if (copy_from_user((char *) &sec, optval, len)) {
76851 err = -EFAULT;
76852 break;
76853 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76854 index 56f1823..da44330 100644
76855 --- a/net/bluetooth/rfcomm/tty.c
76856 +++ b/net/bluetooth/rfcomm/tty.c
76857 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76858 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76859
76860 spin_lock_irqsave(&dev->port.lock, flags);
76861 - if (dev->port.count > 0) {
76862 + if (atomic_read(&dev->port.count) > 0) {
76863 spin_unlock_irqrestore(&dev->port.lock, flags);
76864 return;
76865 }
76866 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76867 return -ENODEV;
76868
76869 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76870 - dev->channel, dev->port.count);
76871 + dev->channel, atomic_read(&dev->port.count));
76872
76873 spin_lock_irqsave(&dev->port.lock, flags);
76874 - if (++dev->port.count > 1) {
76875 + if (atomic_inc_return(&dev->port.count) > 1) {
76876 spin_unlock_irqrestore(&dev->port.lock, flags);
76877 return 0;
76878 }
76879 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76880 return;
76881
76882 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76883 - dev->port.count);
76884 + atomic_read(&dev->port.count));
76885
76886 spin_lock_irqsave(&dev->port.lock, flags);
76887 - if (!--dev->port.count) {
76888 + if (!atomic_dec_return(&dev->port.count)) {
76889 spin_unlock_irqrestore(&dev->port.lock, flags);
76890 if (dev->tty_dev->parent)
76891 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76892 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76893 index 5fe2ff3..121d696 100644
76894 --- a/net/bridge/netfilter/ebtables.c
76895 +++ b/net/bridge/netfilter/ebtables.c
76896 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76897 tmp.valid_hooks = t->table->valid_hooks;
76898 }
76899 mutex_unlock(&ebt_mutex);
76900 - if (copy_to_user(user, &tmp, *len) != 0){
76901 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76902 BUGPRINT("c2u Didn't work\n");
76903 ret = -EFAULT;
76904 break;
76905 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76906 goto out;
76907 tmp.valid_hooks = t->valid_hooks;
76908
76909 - if (copy_to_user(user, &tmp, *len) != 0) {
76910 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76911 ret = -EFAULT;
76912 break;
76913 }
76914 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76915 tmp.entries_size = t->table->entries_size;
76916 tmp.valid_hooks = t->table->valid_hooks;
76917
76918 - if (copy_to_user(user, &tmp, *len) != 0) {
76919 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76920 ret = -EFAULT;
76921 break;
76922 }
76923 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76924 index 44f270f..1f5602d 100644
76925 --- a/net/caif/cfctrl.c
76926 +++ b/net/caif/cfctrl.c
76927 @@ -10,6 +10,7 @@
76928 #include <linux/spinlock.h>
76929 #include <linux/slab.h>
76930 #include <linux/pkt_sched.h>
76931 +#include <linux/sched.h>
76932 #include <net/caif/caif_layer.h>
76933 #include <net/caif/cfpkt.h>
76934 #include <net/caif/cfctrl.h>
76935 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76936 memset(&dev_info, 0, sizeof(dev_info));
76937 dev_info.id = 0xff;
76938 cfsrvl_init(&this->serv, 0, &dev_info, false);
76939 - atomic_set(&this->req_seq_no, 1);
76940 - atomic_set(&this->rsp_seq_no, 1);
76941 + atomic_set_unchecked(&this->req_seq_no, 1);
76942 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76943 this->serv.layer.receive = cfctrl_recv;
76944 sprintf(this->serv.layer.name, "ctrl");
76945 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76946 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76947 struct cfctrl_request_info *req)
76948 {
76949 spin_lock_bh(&ctrl->info_list_lock);
76950 - atomic_inc(&ctrl->req_seq_no);
76951 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76952 + atomic_inc_unchecked(&ctrl->req_seq_no);
76953 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76954 list_add_tail(&req->list, &ctrl->list);
76955 spin_unlock_bh(&ctrl->info_list_lock);
76956 }
76957 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76958 if (p != first)
76959 pr_warn("Requests are not received in order\n");
76960
76961 - atomic_set(&ctrl->rsp_seq_no,
76962 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76963 p->sequence_no);
76964 list_del(&p->list);
76965 goto out;
76966 diff --git a/net/can/gw.c b/net/can/gw.c
76967 index b54d5e6..91c3b25 100644
76968 --- a/net/can/gw.c
76969 +++ b/net/can/gw.c
76970 @@ -96,7 +96,7 @@ struct cf_mod {
76971 struct {
76972 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76973 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76974 - } csumfunc;
76975 + } __no_const csumfunc;
76976 };
76977
76978
76979 diff --git a/net/compat.c b/net/compat.c
76980 index 74ed1d7..3695bd9 100644
76981 --- a/net/compat.c
76982 +++ b/net/compat.c
76983 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76984 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76985 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76986 return -EFAULT;
76987 - kmsg->msg_name = compat_ptr(tmp1);
76988 - kmsg->msg_iov = compat_ptr(tmp2);
76989 - kmsg->msg_control = compat_ptr(tmp3);
76990 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76991 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76992 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76993 return 0;
76994 }
76995
76996 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76997
76998 if (kern_msg->msg_namelen) {
76999 if (mode == VERIFY_READ) {
77000 - int err = move_addr_to_kernel(kern_msg->msg_name,
77001 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
77002 kern_msg->msg_namelen,
77003 kern_address);
77004 if (err < 0)
77005 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
77006 kern_msg->msg_name = NULL;
77007
77008 tot_len = iov_from_user_compat_to_kern(kern_iov,
77009 - (struct compat_iovec __user *)kern_msg->msg_iov,
77010 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
77011 kern_msg->msg_iovlen);
77012 if (tot_len >= 0)
77013 kern_msg->msg_iov = kern_iov;
77014 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
77015
77016 #define CMSG_COMPAT_FIRSTHDR(msg) \
77017 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
77018 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
77019 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
77020 (struct compat_cmsghdr __user *)NULL)
77021
77022 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
77023 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
77024 (ucmlen) <= (unsigned long) \
77025 ((mhdr)->msg_controllen - \
77026 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
77027 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
77028
77029 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
77030 struct compat_cmsghdr __user *cmsg, int cmsg_len)
77031 {
77032 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
77033 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
77034 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
77035 msg->msg_controllen)
77036 return NULL;
77037 return (struct compat_cmsghdr __user *)ptr;
77038 @@ -219,7 +219,7 @@ Efault:
77039
77040 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
77041 {
77042 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
77043 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
77044 struct compat_cmsghdr cmhdr;
77045 struct compat_timeval ctv;
77046 struct compat_timespec cts[3];
77047 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
77048
77049 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
77050 {
77051 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
77052 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
77053 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
77054 int fdnum = scm->fp->count;
77055 struct file **fp = scm->fp->fp;
77056 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
77057 return -EFAULT;
77058 old_fs = get_fs();
77059 set_fs(KERNEL_DS);
77060 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
77061 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
77062 set_fs(old_fs);
77063
77064 return err;
77065 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
77066 len = sizeof(ktime);
77067 old_fs = get_fs();
77068 set_fs(KERNEL_DS);
77069 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
77070 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
77071 set_fs(old_fs);
77072
77073 if (!err) {
77074 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77075 case MCAST_JOIN_GROUP:
77076 case MCAST_LEAVE_GROUP:
77077 {
77078 - struct compat_group_req __user *gr32 = (void *)optval;
77079 + struct compat_group_req __user *gr32 = (void __user *)optval;
77080 struct group_req __user *kgr =
77081 compat_alloc_user_space(sizeof(struct group_req));
77082 u32 interface;
77083 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77084 case MCAST_BLOCK_SOURCE:
77085 case MCAST_UNBLOCK_SOURCE:
77086 {
77087 - struct compat_group_source_req __user *gsr32 = (void *)optval;
77088 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
77089 struct group_source_req __user *kgsr = compat_alloc_user_space(
77090 sizeof(struct group_source_req));
77091 u32 interface;
77092 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77093 }
77094 case MCAST_MSFILTER:
77095 {
77096 - struct compat_group_filter __user *gf32 = (void *)optval;
77097 + struct compat_group_filter __user *gf32 = (void __user *)optval;
77098 struct group_filter __user *kgf;
77099 u32 interface, fmode, numsrc;
77100
77101 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
77102 char __user *optval, int __user *optlen,
77103 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
77104 {
77105 - struct compat_group_filter __user *gf32 = (void *)optval;
77106 + struct compat_group_filter __user *gf32 = (void __user *)optval;
77107 struct group_filter __user *kgf;
77108 int __user *koptlen;
77109 u32 interface, fmode, numsrc;
77110 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
77111
77112 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
77113 return -EINVAL;
77114 - if (copy_from_user(a, args, nas[call]))
77115 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
77116 return -EFAULT;
77117 a0 = a[0];
77118 a1 = a[1];
77119 diff --git a/net/core/datagram.c b/net/core/datagram.c
77120 index 0337e2b..47914a0 100644
77121 --- a/net/core/datagram.c
77122 +++ b/net/core/datagram.c
77123 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
77124 }
77125
77126 kfree_skb(skb);
77127 - atomic_inc(&sk->sk_drops);
77128 + atomic_inc_unchecked(&sk->sk_drops);
77129 sk_mem_reclaim_partial(sk);
77130
77131 return err;
77132 diff --git a/net/core/dev.c b/net/core/dev.c
77133 index aed87a4..72cc526 100644
77134 --- a/net/core/dev.c
77135 +++ b/net/core/dev.c
77136 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
77137 if (no_module && capable(CAP_NET_ADMIN))
77138 no_module = request_module("netdev-%s", name);
77139 if (no_module && capable(CAP_SYS_MODULE)) {
77140 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
77141 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
77142 +#else
77143 if (!request_module("%s", name))
77144 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
77145 name);
77146 +#endif
77147 }
77148 }
77149 EXPORT_SYMBOL(dev_load);
77150 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
77151 {
77152 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
77153 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
77154 - atomic_long_inc(&dev->rx_dropped);
77155 + atomic_long_inc_unchecked(&dev->rx_dropped);
77156 kfree_skb(skb);
77157 return NET_RX_DROP;
77158 }
77159 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
77160 nf_reset(skb);
77161
77162 if (unlikely(!is_skb_forwardable(dev, skb))) {
77163 - atomic_long_inc(&dev->rx_dropped);
77164 + atomic_long_inc_unchecked(&dev->rx_dropped);
77165 kfree_skb(skb);
77166 return NET_RX_DROP;
77167 }
77168 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
77169
77170 struct dev_gso_cb {
77171 void (*destructor)(struct sk_buff *skb);
77172 -};
77173 +} __no_const;
77174
77175 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
77176
77177 @@ -2928,7 +2932,7 @@ enqueue:
77178
77179 local_irq_restore(flags);
77180
77181 - atomic_long_inc(&skb->dev->rx_dropped);
77182 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
77183 kfree_skb(skb);
77184 return NET_RX_DROP;
77185 }
77186 @@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
77187 }
77188 EXPORT_SYMBOL(netif_rx_ni);
77189
77190 -static void net_tx_action(struct softirq_action *h)
77191 +static void net_tx_action(void)
77192 {
77193 struct softnet_data *sd = &__get_cpu_var(softnet_data);
77194
77195 @@ -3331,7 +3335,7 @@ ncls:
77196 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
77197 } else {
77198 drop:
77199 - atomic_long_inc(&skb->dev->rx_dropped);
77200 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
77201 kfree_skb(skb);
77202 /* Jamal, now you will not able to escape explaining
77203 * me how you were going to use this. :-)
77204 @@ -3898,7 +3902,7 @@ void netif_napi_del(struct napi_struct *napi)
77205 }
77206 EXPORT_SYMBOL(netif_napi_del);
77207
77208 -static void net_rx_action(struct softirq_action *h)
77209 +static void net_rx_action(void)
77210 {
77211 struct softnet_data *sd = &__get_cpu_var(softnet_data);
77212 unsigned long time_limit = jiffies + 2;
77213 @@ -4368,8 +4372,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
77214 else
77215 seq_printf(seq, "%04x", ntohs(pt->type));
77216
77217 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77218 + seq_printf(seq, " %-8s %p\n",
77219 + pt->dev ? pt->dev->name : "", NULL);
77220 +#else
77221 seq_printf(seq, " %-8s %pF\n",
77222 pt->dev ? pt->dev->name : "", pt->func);
77223 +#endif
77224 }
77225
77226 return 0;
77227 @@ -5922,7 +5931,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
77228 } else {
77229 netdev_stats_to_stats64(storage, &dev->stats);
77230 }
77231 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
77232 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
77233 return storage;
77234 }
77235 EXPORT_SYMBOL(dev_get_stats);
77236 diff --git a/net/core/flow.c b/net/core/flow.c
77237 index e318c7e..168b1d0 100644
77238 --- a/net/core/flow.c
77239 +++ b/net/core/flow.c
77240 @@ -61,7 +61,7 @@ struct flow_cache {
77241 struct timer_list rnd_timer;
77242 };
77243
77244 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
77245 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
77246 EXPORT_SYMBOL(flow_cache_genid);
77247 static struct flow_cache flow_cache_global;
77248 static struct kmem_cache *flow_cachep __read_mostly;
77249 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
77250
77251 static int flow_entry_valid(struct flow_cache_entry *fle)
77252 {
77253 - if (atomic_read(&flow_cache_genid) != fle->genid)
77254 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
77255 return 0;
77256 if (fle->object && !fle->object->ops->check(fle->object))
77257 return 0;
77258 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
77259 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
77260 fcp->hash_count++;
77261 }
77262 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
77263 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
77264 flo = fle->object;
77265 if (!flo)
77266 goto ret_object;
77267 @@ -280,7 +280,7 @@ nocache:
77268 }
77269 flo = resolver(net, key, family, dir, flo, ctx);
77270 if (fle) {
77271 - fle->genid = atomic_read(&flow_cache_genid);
77272 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
77273 if (!IS_ERR(flo))
77274 fle->object = flo;
77275 else
77276 diff --git a/net/core/iovec.c b/net/core/iovec.c
77277 index 7e7aeb0..2a998cb 100644
77278 --- a/net/core/iovec.c
77279 +++ b/net/core/iovec.c
77280 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77281 if (m->msg_namelen) {
77282 if (mode == VERIFY_READ) {
77283 void __user *namep;
77284 - namep = (void __user __force *) m->msg_name;
77285 + namep = (void __force_user *) m->msg_name;
77286 err = move_addr_to_kernel(namep, m->msg_namelen,
77287 address);
77288 if (err < 0)
77289 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77290 }
77291
77292 size = m->msg_iovlen * sizeof(struct iovec);
77293 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
77294 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
77295 return -EFAULT;
77296
77297 m->msg_iov = iov;
77298 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
77299 index 2c5a0a0..a45f90c 100644
77300 --- a/net/core/rtnetlink.c
77301 +++ b/net/core/rtnetlink.c
77302 @@ -58,7 +58,7 @@ struct rtnl_link {
77303 rtnl_doit_func doit;
77304 rtnl_dumpit_func dumpit;
77305 rtnl_calcit_func calcit;
77306 -};
77307 +} __no_const;
77308
77309 static DEFINE_MUTEX(rtnl_mutex);
77310
77311 diff --git a/net/core/scm.c b/net/core/scm.c
77312 index 040cebe..5b1e312 100644
77313 --- a/net/core/scm.c
77314 +++ b/net/core/scm.c
77315 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
77316 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77317 {
77318 struct cmsghdr __user *cm
77319 - = (__force struct cmsghdr __user *)msg->msg_control;
77320 + = (struct cmsghdr __force_user *)msg->msg_control;
77321 struct cmsghdr cmhdr;
77322 int cmlen = CMSG_LEN(len);
77323 int err;
77324 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77325 err = -EFAULT;
77326 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
77327 goto out;
77328 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
77329 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
77330 goto out;
77331 cmlen = CMSG_SPACE(len);
77332 if (msg->msg_controllen < cmlen)
77333 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
77334 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77335 {
77336 struct cmsghdr __user *cm
77337 - = (__force struct cmsghdr __user*)msg->msg_control;
77338 + = (struct cmsghdr __force_user *)msg->msg_control;
77339
77340 int fdmax = 0;
77341 int fdnum = scm->fp->count;
77342 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77343 if (fdnum < fdmax)
77344 fdmax = fdnum;
77345
77346 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
77347 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
77348 i++, cmfptr++)
77349 {
77350 struct socket *sock;
77351 diff --git a/net/core/sock.c b/net/core/sock.c
77352 index a6000fb..d4aee72 100644
77353 --- a/net/core/sock.c
77354 +++ b/net/core/sock.c
77355 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77356 struct sk_buff_head *list = &sk->sk_receive_queue;
77357
77358 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
77359 - atomic_inc(&sk->sk_drops);
77360 + atomic_inc_unchecked(&sk->sk_drops);
77361 trace_sock_rcvqueue_full(sk, skb);
77362 return -ENOMEM;
77363 }
77364 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77365 return err;
77366
77367 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
77368 - atomic_inc(&sk->sk_drops);
77369 + atomic_inc_unchecked(&sk->sk_drops);
77370 return -ENOBUFS;
77371 }
77372
77373 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77374 skb_dst_force(skb);
77375
77376 spin_lock_irqsave(&list->lock, flags);
77377 - skb->dropcount = atomic_read(&sk->sk_drops);
77378 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77379 __skb_queue_tail(list, skb);
77380 spin_unlock_irqrestore(&list->lock, flags);
77381
77382 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77383 skb->dev = NULL;
77384
77385 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
77386 - atomic_inc(&sk->sk_drops);
77387 + atomic_inc_unchecked(&sk->sk_drops);
77388 goto discard_and_relse;
77389 }
77390 if (nested)
77391 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77392 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
77393 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
77394 bh_unlock_sock(sk);
77395 - atomic_inc(&sk->sk_drops);
77396 + atomic_inc_unchecked(&sk->sk_drops);
77397 goto discard_and_relse;
77398 }
77399
77400 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77401 struct timeval tm;
77402 } v;
77403
77404 - int lv = sizeof(int);
77405 - int len;
77406 + unsigned int lv = sizeof(int);
77407 + unsigned int len;
77408
77409 if (get_user(len, optlen))
77410 return -EFAULT;
77411 - if (len < 0)
77412 + if (len > INT_MAX)
77413 return -EINVAL;
77414
77415 memset(&v, 0, sizeof(v));
77416 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77417
77418 case SO_PEERNAME:
77419 {
77420 - char address[128];
77421 + char address[_K_SS_MAXSIZE];
77422
77423 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
77424 return -ENOTCONN;
77425 - if (lv < len)
77426 + if (lv < len || sizeof address < len)
77427 return -EINVAL;
77428 if (copy_to_user(optval, address, len))
77429 return -EFAULT;
77430 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77431
77432 if (len > lv)
77433 len = lv;
77434 - if (copy_to_user(optval, &v, len))
77435 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
77436 return -EFAULT;
77437 lenout:
77438 if (put_user(len, optlen))
77439 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
77440 */
77441 smp_wmb();
77442 atomic_set(&sk->sk_refcnt, 1);
77443 - atomic_set(&sk->sk_drops, 0);
77444 + atomic_set_unchecked(&sk->sk_drops, 0);
77445 }
77446 EXPORT_SYMBOL(sock_init_data);
77447
77448 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
77449 index 9d8755e..26de8bc 100644
77450 --- a/net/core/sock_diag.c
77451 +++ b/net/core/sock_diag.c
77452 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
77453
77454 int sock_diag_check_cookie(void *sk, __u32 *cookie)
77455 {
77456 +#ifndef CONFIG_GRKERNSEC_HIDESYM
77457 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
77458 cookie[1] != INET_DIAG_NOCOOKIE) &&
77459 ((u32)(unsigned long)sk != cookie[0] ||
77460 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
77461 return -ESTALE;
77462 else
77463 +#endif
77464 return 0;
77465 }
77466 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
77467
77468 void sock_diag_save_cookie(void *sk, __u32 *cookie)
77469 {
77470 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77471 + cookie[0] = 0;
77472 + cookie[1] = 0;
77473 +#else
77474 cookie[0] = (u32)(unsigned long)sk;
77475 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
77476 +#endif
77477 }
77478 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
77479
77480 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
77481 index a55eecc..dd8428c 100644
77482 --- a/net/decnet/sysctl_net_decnet.c
77483 +++ b/net/decnet/sysctl_net_decnet.c
77484 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
77485
77486 if (len > *lenp) len = *lenp;
77487
77488 - if (copy_to_user(buffer, addr, len))
77489 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
77490 return -EFAULT;
77491
77492 *lenp = len;
77493 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
77494
77495 if (len > *lenp) len = *lenp;
77496
77497 - if (copy_to_user(buffer, devname, len))
77498 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
77499 return -EFAULT;
77500
77501 *lenp = len;
77502 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
77503 index f444ac7..b7bdda9 100644
77504 --- a/net/ipv4/fib_frontend.c
77505 +++ b/net/ipv4/fib_frontend.c
77506 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
77507 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77508 fib_sync_up(dev);
77509 #endif
77510 - atomic_inc(&net->ipv4.dev_addr_genid);
77511 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77512 rt_cache_flush(dev_net(dev));
77513 break;
77514 case NETDEV_DOWN:
77515 fib_del_ifaddr(ifa, NULL);
77516 - atomic_inc(&net->ipv4.dev_addr_genid);
77517 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77518 if (ifa->ifa_dev->ifa_list == NULL) {
77519 /* Last address was deleted from this interface.
77520 * Disable IP.
77521 @@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
77522 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77523 fib_sync_up(dev);
77524 #endif
77525 - atomic_inc(&net->ipv4.dev_addr_genid);
77526 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77527 rt_cache_flush(dev_net(dev));
77528 break;
77529 case NETDEV_DOWN:
77530 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
77531 index 9633661..4e0bc08 100644
77532 --- a/net/ipv4/fib_semantics.c
77533 +++ b/net/ipv4/fib_semantics.c
77534 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
77535 nh->nh_saddr = inet_select_addr(nh->nh_dev,
77536 nh->nh_gw,
77537 nh->nh_parent->fib_scope);
77538 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
77539 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
77540
77541 return nh->nh_saddr;
77542 }
77543 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
77544 index 7880af9..70f92a3 100644
77545 --- a/net/ipv4/inet_hashtables.c
77546 +++ b/net/ipv4/inet_hashtables.c
77547 @@ -18,12 +18,15 @@
77548 #include <linux/sched.h>
77549 #include <linux/slab.h>
77550 #include <linux/wait.h>
77551 +#include <linux/security.h>
77552
77553 #include <net/inet_connection_sock.h>
77554 #include <net/inet_hashtables.h>
77555 #include <net/secure_seq.h>
77556 #include <net/ip.h>
77557
77558 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
77559 +
77560 /*
77561 * Allocate and initialize a new local port bind bucket.
77562 * The bindhash mutex for snum's hash chain must be held here.
77563 @@ -530,6 +533,8 @@ ok:
77564 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77565 spin_unlock(&head->lock);
77566
77567 + gr_update_task_in_ip_table(current, inet_sk(sk));
77568 +
77569 if (tw) {
77570 inet_twsk_deschedule(tw, death_row);
77571 while (twrefcnt) {
77572 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77573 index c7527f6..d8bba61 100644
77574 --- a/net/ipv4/inetpeer.c
77575 +++ b/net/ipv4/inetpeer.c
77576 @@ -503,8 +503,8 @@ relookup:
77577 if (p) {
77578 p->daddr = *daddr;
77579 atomic_set(&p->refcnt, 1);
77580 - atomic_set(&p->rid, 0);
77581 - atomic_set(&p->ip_id_count,
77582 + atomic_set_unchecked(&p->rid, 0);
77583 + atomic_set_unchecked(&p->ip_id_count,
77584 (daddr->family == AF_INET) ?
77585 secure_ip_id(daddr->addr.a4) :
77586 secure_ipv6_id(daddr->addr.a6));
77587 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77588 index 8d07c97..d0812ef 100644
77589 --- a/net/ipv4/ip_fragment.c
77590 +++ b/net/ipv4/ip_fragment.c
77591 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77592 return 0;
77593
77594 start = qp->rid;
77595 - end = atomic_inc_return(&peer->rid);
77596 + end = atomic_inc_return_unchecked(&peer->rid);
77597 qp->rid = end;
77598
77599 rc = qp->q.fragments && (end - start) > max;
77600 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77601 index 5eea4a8..49819c2 100644
77602 --- a/net/ipv4/ip_sockglue.c
77603 +++ b/net/ipv4/ip_sockglue.c
77604 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77605 len = min_t(unsigned int, len, opt->optlen);
77606 if (put_user(len, optlen))
77607 return -EFAULT;
77608 - if (copy_to_user(optval, opt->__data, len))
77609 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77610 + copy_to_user(optval, opt->__data, len))
77611 return -EFAULT;
77612 return 0;
77613 }
77614 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77615 if (sk->sk_type != SOCK_STREAM)
77616 return -ENOPROTOOPT;
77617
77618 - msg.msg_control = optval;
77619 + msg.msg_control = (void __force_kernel *)optval;
77620 msg.msg_controllen = len;
77621 msg.msg_flags = flags;
77622
77623 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77624 index 67e8a6b..386764d 100644
77625 --- a/net/ipv4/ipconfig.c
77626 +++ b/net/ipv4/ipconfig.c
77627 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77628
77629 mm_segment_t oldfs = get_fs();
77630 set_fs(get_ds());
77631 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77632 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77633 set_fs(oldfs);
77634 return res;
77635 }
77636 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77637
77638 mm_segment_t oldfs = get_fs();
77639 set_fs(get_ds());
77640 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77641 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77642 set_fs(oldfs);
77643 return res;
77644 }
77645 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77646
77647 mm_segment_t oldfs = get_fs();
77648 set_fs(get_ds());
77649 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77650 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77651 set_fs(oldfs);
77652 return res;
77653 }
77654 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77655 index 97e61ea..cac1bbb 100644
77656 --- a/net/ipv4/netfilter/arp_tables.c
77657 +++ b/net/ipv4/netfilter/arp_tables.c
77658 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77659 #endif
77660
77661 static int get_info(struct net *net, void __user *user,
77662 - const int *len, int compat)
77663 + int len, int compat)
77664 {
77665 char name[XT_TABLE_MAXNAMELEN];
77666 struct xt_table *t;
77667 int ret;
77668
77669 - if (*len != sizeof(struct arpt_getinfo)) {
77670 - duprintf("length %u != %Zu\n", *len,
77671 + if (len != sizeof(struct arpt_getinfo)) {
77672 + duprintf("length %u != %Zu\n", len,
77673 sizeof(struct arpt_getinfo));
77674 return -EINVAL;
77675 }
77676 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77677 info.size = private->size;
77678 strcpy(info.name, name);
77679
77680 - if (copy_to_user(user, &info, *len) != 0)
77681 + if (copy_to_user(user, &info, len) != 0)
77682 ret = -EFAULT;
77683 else
77684 ret = 0;
77685 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77686
77687 switch (cmd) {
77688 case ARPT_SO_GET_INFO:
77689 - ret = get_info(sock_net(sk), user, len, 1);
77690 + ret = get_info(sock_net(sk), user, *len, 1);
77691 break;
77692 case ARPT_SO_GET_ENTRIES:
77693 ret = compat_get_entries(sock_net(sk), user, len);
77694 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77695
77696 switch (cmd) {
77697 case ARPT_SO_GET_INFO:
77698 - ret = get_info(sock_net(sk), user, len, 0);
77699 + ret = get_info(sock_net(sk), user, *len, 0);
77700 break;
77701
77702 case ARPT_SO_GET_ENTRIES:
77703 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77704 index 170b1fd..6105b91 100644
77705 --- a/net/ipv4/netfilter/ip_tables.c
77706 +++ b/net/ipv4/netfilter/ip_tables.c
77707 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77708 #endif
77709
77710 static int get_info(struct net *net, void __user *user,
77711 - const int *len, int compat)
77712 + int len, int compat)
77713 {
77714 char name[XT_TABLE_MAXNAMELEN];
77715 struct xt_table *t;
77716 int ret;
77717
77718 - if (*len != sizeof(struct ipt_getinfo)) {
77719 - duprintf("length %u != %zu\n", *len,
77720 + if (len != sizeof(struct ipt_getinfo)) {
77721 + duprintf("length %u != %zu\n", len,
77722 sizeof(struct ipt_getinfo));
77723 return -EINVAL;
77724 }
77725 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77726 info.size = private->size;
77727 strcpy(info.name, name);
77728
77729 - if (copy_to_user(user, &info, *len) != 0)
77730 + if (copy_to_user(user, &info, len) != 0)
77731 ret = -EFAULT;
77732 else
77733 ret = 0;
77734 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77735
77736 switch (cmd) {
77737 case IPT_SO_GET_INFO:
77738 - ret = get_info(sock_net(sk), user, len, 1);
77739 + ret = get_info(sock_net(sk), user, *len, 1);
77740 break;
77741 case IPT_SO_GET_ENTRIES:
77742 ret = compat_get_entries(sock_net(sk), user, len);
77743 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77744
77745 switch (cmd) {
77746 case IPT_SO_GET_INFO:
77747 - ret = get_info(sock_net(sk), user, len, 0);
77748 + ret = get_info(sock_net(sk), user, *len, 0);
77749 break;
77750
77751 case IPT_SO_GET_ENTRIES:
77752 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77753 index 6232d47..6b88607 100644
77754 --- a/net/ipv4/ping.c
77755 +++ b/net/ipv4/ping.c
77756 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77757 sk_rmem_alloc_get(sp),
77758 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77759 atomic_read(&sp->sk_refcnt), sp,
77760 - atomic_read(&sp->sk_drops), len);
77761 + atomic_read_unchecked(&sp->sk_drops), len);
77762 }
77763
77764 static int ping_seq_show(struct seq_file *seq, void *v)
77765 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77766 index d23c657..cb69cc2 100644
77767 --- a/net/ipv4/raw.c
77768 +++ b/net/ipv4/raw.c
77769 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77770 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77771 {
77772 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77773 - atomic_inc(&sk->sk_drops);
77774 + atomic_inc_unchecked(&sk->sk_drops);
77775 kfree_skb(skb);
77776 return NET_RX_DROP;
77777 }
77778 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77779
77780 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77781 {
77782 + struct icmp_filter filter;
77783 +
77784 if (optlen > sizeof(struct icmp_filter))
77785 optlen = sizeof(struct icmp_filter);
77786 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77787 + if (copy_from_user(&filter, optval, optlen))
77788 return -EFAULT;
77789 + raw_sk(sk)->filter = filter;
77790 return 0;
77791 }
77792
77793 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77794 {
77795 int len, ret = -EFAULT;
77796 + struct icmp_filter filter;
77797
77798 if (get_user(len, optlen))
77799 goto out;
77800 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77801 if (len > sizeof(struct icmp_filter))
77802 len = sizeof(struct icmp_filter);
77803 ret = -EFAULT;
77804 - if (put_user(len, optlen) ||
77805 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77806 + filter = raw_sk(sk)->filter;
77807 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77808 goto out;
77809 ret = 0;
77810 out: return ret;
77811 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77812 sk_wmem_alloc_get(sp),
77813 sk_rmem_alloc_get(sp),
77814 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77815 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77816 + atomic_read(&sp->sk_refcnt),
77817 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77818 + NULL,
77819 +#else
77820 + sp,
77821 +#endif
77822 + atomic_read_unchecked(&sp->sk_drops));
77823 }
77824
77825 static int raw_seq_show(struct seq_file *seq, void *v)
77826 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77827 index c017cb1..9eb15b7d 100644
77828 --- a/net/ipv4/route.c
77829 +++ b/net/ipv4/route.c
77830 @@ -2526,7 +2526,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77831
77832 static __net_init int rt_genid_init(struct net *net)
77833 {
77834 - atomic_set(&net->rt_genid, 0);
77835 + atomic_set_unchecked(&net->rt_genid, 0);
77836 get_random_bytes(&net->ipv4.dev_addr_genid,
77837 sizeof(net->ipv4.dev_addr_genid));
77838 return 0;
77839 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77840 index c92c4da..f19e3ec 100644
77841 --- a/net/ipv4/tcp_input.c
77842 +++ b/net/ipv4/tcp_input.c
77843 @@ -4731,7 +4731,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77844 * simplifies code)
77845 */
77846 static void
77847 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77848 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77849 struct sk_buff *head, struct sk_buff *tail,
77850 u32 start, u32 end)
77851 {
77852 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77853 index db7bfad..bfea796 100644
77854 --- a/net/ipv4/tcp_ipv4.c
77855 +++ b/net/ipv4/tcp_ipv4.c
77856 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77857 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77858
77859
77860 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77861 +extern int grsec_enable_blackhole;
77862 +#endif
77863 +
77864 #ifdef CONFIG_TCP_MD5SIG
77865 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77866 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77867 @@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77868 return 0;
77869
77870 reset:
77871 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77872 + if (!grsec_enable_blackhole)
77873 +#endif
77874 tcp_v4_send_reset(rsk, skb);
77875 discard:
77876 kfree_skb(skb);
77877 @@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77878 TCP_SKB_CB(skb)->sacked = 0;
77879
77880 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77881 - if (!sk)
77882 + if (!sk) {
77883 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77884 + ret = 1;
77885 +#endif
77886 goto no_tcp_socket;
77887 -
77888 + }
77889 process:
77890 - if (sk->sk_state == TCP_TIME_WAIT)
77891 + if (sk->sk_state == TCP_TIME_WAIT) {
77892 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77893 + ret = 2;
77894 +#endif
77895 goto do_time_wait;
77896 + }
77897
77898 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77899 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77900 @@ -1820,6 +1834,10 @@ no_tcp_socket:
77901 bad_packet:
77902 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77903 } else {
77904 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77905 + if (!grsec_enable_blackhole || (ret == 1 &&
77906 + (skb->dev->flags & IFF_LOOPBACK)))
77907 +#endif
77908 tcp_v4_send_reset(NULL, skb);
77909 }
77910
77911 @@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77912 0, /* non standard timer */
77913 0, /* open_requests have no inode */
77914 atomic_read(&sk->sk_refcnt),
77915 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77916 + NULL,
77917 +#else
77918 req,
77919 +#endif
77920 len);
77921 }
77922
77923 @@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77924 sock_i_uid(sk),
77925 icsk->icsk_probes_out,
77926 sock_i_ino(sk),
77927 - atomic_read(&sk->sk_refcnt), sk,
77928 + atomic_read(&sk->sk_refcnt),
77929 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77930 + NULL,
77931 +#else
77932 + sk,
77933 +#endif
77934 jiffies_to_clock_t(icsk->icsk_rto),
77935 jiffies_to_clock_t(icsk->icsk_ack.ato),
77936 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77937 @@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77938 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77939 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77940 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77941 - atomic_read(&tw->tw_refcnt), tw, len);
77942 + atomic_read(&tw->tw_refcnt),
77943 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77944 + NULL,
77945 +#else
77946 + tw,
77947 +#endif
77948 + len);
77949 }
77950
77951 #define TMPSZ 150
77952 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77953 index 6ff7f10..38de56e 100644
77954 --- a/net/ipv4/tcp_minisocks.c
77955 +++ b/net/ipv4/tcp_minisocks.c
77956 @@ -27,6 +27,10 @@
77957 #include <net/inet_common.h>
77958 #include <net/xfrm.h>
77959
77960 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77961 +extern int grsec_enable_blackhole;
77962 +#endif
77963 +
77964 int sysctl_tcp_syncookies __read_mostly = 1;
77965 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77966
77967 @@ -707,6 +711,10 @@ listen_overflow:
77968
77969 embryonic_reset:
77970 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77971 +
77972 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77973 + if (!grsec_enable_blackhole)
77974 +#endif
77975 if (!(flg & TCP_FLAG_RST))
77976 req->rsk_ops->send_reset(sk, skb);
77977
77978 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77979 index 4526fe6..1a34e43 100644
77980 --- a/net/ipv4/tcp_probe.c
77981 +++ b/net/ipv4/tcp_probe.c
77982 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77983 if (cnt + width >= len)
77984 break;
77985
77986 - if (copy_to_user(buf + cnt, tbuf, width))
77987 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77988 return -EFAULT;
77989 cnt += width;
77990 }
77991 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77992 index b774a03..3873efe 100644
77993 --- a/net/ipv4/tcp_timer.c
77994 +++ b/net/ipv4/tcp_timer.c
77995 @@ -22,6 +22,10 @@
77996 #include <linux/gfp.h>
77997 #include <net/tcp.h>
77998
77999 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78000 +extern int grsec_lastack_retries;
78001 +#endif
78002 +
78003 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
78004 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
78005 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
78006 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
78007 }
78008 }
78009
78010 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78011 + if ((sk->sk_state == TCP_LAST_ACK) &&
78012 + (grsec_lastack_retries > 0) &&
78013 + (grsec_lastack_retries < retry_until))
78014 + retry_until = grsec_lastack_retries;
78015 +#endif
78016 +
78017 if (retransmits_timed_out(sk, retry_until,
78018 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
78019 /* Has it gone just too far? */
78020 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
78021 index 2814f66..fa2b223 100644
78022 --- a/net/ipv4/udp.c
78023 +++ b/net/ipv4/udp.c
78024 @@ -87,6 +87,7 @@
78025 #include <linux/types.h>
78026 #include <linux/fcntl.h>
78027 #include <linux/module.h>
78028 +#include <linux/security.h>
78029 #include <linux/socket.h>
78030 #include <linux/sockios.h>
78031 #include <linux/igmp.h>
78032 @@ -111,6 +112,10 @@
78033 #include <trace/events/skb.h>
78034 #include "udp_impl.h"
78035
78036 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78037 +extern int grsec_enable_blackhole;
78038 +#endif
78039 +
78040 struct udp_table udp_table __read_mostly;
78041 EXPORT_SYMBOL(udp_table);
78042
78043 @@ -569,6 +574,9 @@ found:
78044 return s;
78045 }
78046
78047 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
78048 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
78049 +
78050 /*
78051 * This routine is called by the ICMP module when it gets some
78052 * sort of error condition. If err < 0 then the socket should
78053 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
78054 dport = usin->sin_port;
78055 if (dport == 0)
78056 return -EINVAL;
78057 +
78058 + err = gr_search_udp_sendmsg(sk, usin);
78059 + if (err)
78060 + return err;
78061 } else {
78062 if (sk->sk_state != TCP_ESTABLISHED)
78063 return -EDESTADDRREQ;
78064 +
78065 + err = gr_search_udp_sendmsg(sk, NULL);
78066 + if (err)
78067 + return err;
78068 +
78069 daddr = inet->inet_daddr;
78070 dport = inet->inet_dport;
78071 /* Open fast path for connected socket.
78072 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
78073 udp_lib_checksum_complete(skb)) {
78074 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78075 IS_UDPLITE(sk));
78076 - atomic_inc(&sk->sk_drops);
78077 + atomic_inc_unchecked(&sk->sk_drops);
78078 __skb_unlink(skb, rcvq);
78079 __skb_queue_tail(&list_kill, skb);
78080 }
78081 @@ -1194,6 +1211,10 @@ try_again:
78082 if (!skb)
78083 goto out;
78084
78085 + err = gr_search_udp_recvmsg(sk, skb);
78086 + if (err)
78087 + goto out_free;
78088 +
78089 ulen = skb->len - sizeof(struct udphdr);
78090 copied = len;
78091 if (copied > ulen)
78092 @@ -1227,7 +1248,7 @@ try_again:
78093 if (unlikely(err)) {
78094 trace_kfree_skb(skb, udp_recvmsg);
78095 if (!peeked) {
78096 - atomic_inc(&sk->sk_drops);
78097 + atomic_inc_unchecked(&sk->sk_drops);
78098 UDP_INC_STATS_USER(sock_net(sk),
78099 UDP_MIB_INERRORS, is_udplite);
78100 }
78101 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78102
78103 drop:
78104 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78105 - atomic_inc(&sk->sk_drops);
78106 + atomic_inc_unchecked(&sk->sk_drops);
78107 kfree_skb(skb);
78108 return -1;
78109 }
78110 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78111 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78112
78113 if (!skb1) {
78114 - atomic_inc(&sk->sk_drops);
78115 + atomic_inc_unchecked(&sk->sk_drops);
78116 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78117 IS_UDPLITE(sk));
78118 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78119 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78120 goto csum_error;
78121
78122 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78123 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78124 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78125 +#endif
78126 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
78127
78128 /*
78129 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
78130 sk_wmem_alloc_get(sp),
78131 sk_rmem_alloc_get(sp),
78132 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
78133 - atomic_read(&sp->sk_refcnt), sp,
78134 - atomic_read(&sp->sk_drops), len);
78135 + atomic_read(&sp->sk_refcnt),
78136 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78137 + NULL,
78138 +#else
78139 + sp,
78140 +#endif
78141 + atomic_read_unchecked(&sp->sk_drops), len);
78142 }
78143
78144 int udp4_seq_show(struct seq_file *seq, void *v)
78145 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
78146 index b10374d..0baa1f9 100644
78147 --- a/net/ipv6/addrconf.c
78148 +++ b/net/ipv6/addrconf.c
78149 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
78150 p.iph.ihl = 5;
78151 p.iph.protocol = IPPROTO_IPV6;
78152 p.iph.ttl = 64;
78153 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
78154 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
78155
78156 if (ops->ndo_do_ioctl) {
78157 mm_segment_t oldfs = get_fs();
78158 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
78159 index ba6d13d..6899122 100644
78160 --- a/net/ipv6/ipv6_sockglue.c
78161 +++ b/net/ipv6/ipv6_sockglue.c
78162 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
78163 if (sk->sk_type != SOCK_STREAM)
78164 return -ENOPROTOOPT;
78165
78166 - msg.msg_control = optval;
78167 + msg.msg_control = (void __force_kernel *)optval;
78168 msg.msg_controllen = len;
78169 msg.msg_flags = flags;
78170
78171 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
78172 index d7cb045..8c0ded6 100644
78173 --- a/net/ipv6/netfilter/ip6_tables.c
78174 +++ b/net/ipv6/netfilter/ip6_tables.c
78175 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
78176 #endif
78177
78178 static int get_info(struct net *net, void __user *user,
78179 - const int *len, int compat)
78180 + int len, int compat)
78181 {
78182 char name[XT_TABLE_MAXNAMELEN];
78183 struct xt_table *t;
78184 int ret;
78185
78186 - if (*len != sizeof(struct ip6t_getinfo)) {
78187 - duprintf("length %u != %zu\n", *len,
78188 + if (len != sizeof(struct ip6t_getinfo)) {
78189 + duprintf("length %u != %zu\n", len,
78190 sizeof(struct ip6t_getinfo));
78191 return -EINVAL;
78192 }
78193 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
78194 info.size = private->size;
78195 strcpy(info.name, name);
78196
78197 - if (copy_to_user(user, &info, *len) != 0)
78198 + if (copy_to_user(user, &info, len) != 0)
78199 ret = -EFAULT;
78200 else
78201 ret = 0;
78202 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78203
78204 switch (cmd) {
78205 case IP6T_SO_GET_INFO:
78206 - ret = get_info(sock_net(sk), user, len, 1);
78207 + ret = get_info(sock_net(sk), user, *len, 1);
78208 break;
78209 case IP6T_SO_GET_ENTRIES:
78210 ret = compat_get_entries(sock_net(sk), user, len);
78211 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78212
78213 switch (cmd) {
78214 case IP6T_SO_GET_INFO:
78215 - ret = get_info(sock_net(sk), user, len, 0);
78216 + ret = get_info(sock_net(sk), user, *len, 0);
78217 break;
78218
78219 case IP6T_SO_GET_ENTRIES:
78220 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
78221 index 4a5f78b..3f22ebe 100644
78222 --- a/net/ipv6/raw.c
78223 +++ b/net/ipv6/raw.c
78224 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
78225 {
78226 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
78227 skb_checksum_complete(skb)) {
78228 - atomic_inc(&sk->sk_drops);
78229 + atomic_inc_unchecked(&sk->sk_drops);
78230 kfree_skb(skb);
78231 return NET_RX_DROP;
78232 }
78233 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
78234 struct raw6_sock *rp = raw6_sk(sk);
78235
78236 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
78237 - atomic_inc(&sk->sk_drops);
78238 + atomic_inc_unchecked(&sk->sk_drops);
78239 kfree_skb(skb);
78240 return NET_RX_DROP;
78241 }
78242 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
78243
78244 if (inet->hdrincl) {
78245 if (skb_checksum_complete(skb)) {
78246 - atomic_inc(&sk->sk_drops);
78247 + atomic_inc_unchecked(&sk->sk_drops);
78248 kfree_skb(skb);
78249 return NET_RX_DROP;
78250 }
78251 @@ -604,7 +604,7 @@ out:
78252 return err;
78253 }
78254
78255 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
78256 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
78257 struct flowi6 *fl6, struct dst_entry **dstp,
78258 unsigned int flags)
78259 {
78260 @@ -916,12 +916,15 @@ do_confirm:
78261 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
78262 char __user *optval, int optlen)
78263 {
78264 + struct icmp6_filter filter;
78265 +
78266 switch (optname) {
78267 case ICMPV6_FILTER:
78268 if (optlen > sizeof(struct icmp6_filter))
78269 optlen = sizeof(struct icmp6_filter);
78270 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
78271 + if (copy_from_user(&filter, optval, optlen))
78272 return -EFAULT;
78273 + raw6_sk(sk)->filter = filter;
78274 return 0;
78275 default:
78276 return -ENOPROTOOPT;
78277 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
78278 char __user *optval, int __user *optlen)
78279 {
78280 int len;
78281 + struct icmp6_filter filter;
78282
78283 switch (optname) {
78284 case ICMPV6_FILTER:
78285 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
78286 len = sizeof(struct icmp6_filter);
78287 if (put_user(len, optlen))
78288 return -EFAULT;
78289 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
78290 + filter = raw6_sk(sk)->filter;
78291 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
78292 return -EFAULT;
78293 return 0;
78294 default:
78295 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
78296 0, 0L, 0,
78297 sock_i_uid(sp), 0,
78298 sock_i_ino(sp),
78299 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
78300 + atomic_read(&sp->sk_refcnt),
78301 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78302 + NULL,
78303 +#else
78304 + sp,
78305 +#endif
78306 + atomic_read_unchecked(&sp->sk_drops));
78307 }
78308
78309 static int raw6_seq_show(struct seq_file *seq, void *v)
78310 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
78311 index 7e32d42..5d975ba 100644
78312 --- a/net/ipv6/tcp_ipv6.c
78313 +++ b/net/ipv6/tcp_ipv6.c
78314 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
78315 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
78316 }
78317
78318 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78319 +extern int grsec_enable_blackhole;
78320 +#endif
78321 +
78322 static void tcp_v6_hash(struct sock *sk)
78323 {
78324 if (sk->sk_state != TCP_CLOSE) {
78325 @@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
78326 return 0;
78327
78328 reset:
78329 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78330 + if (!grsec_enable_blackhole)
78331 +#endif
78332 tcp_v6_send_reset(sk, skb);
78333 discard:
78334 if (opt_skb)
78335 @@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
78336 TCP_SKB_CB(skb)->sacked = 0;
78337
78338 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
78339 - if (!sk)
78340 + if (!sk) {
78341 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78342 + ret = 1;
78343 +#endif
78344 goto no_tcp_socket;
78345 + }
78346
78347 process:
78348 - if (sk->sk_state == TCP_TIME_WAIT)
78349 + if (sk->sk_state == TCP_TIME_WAIT) {
78350 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78351 + ret = 2;
78352 +#endif
78353 goto do_time_wait;
78354 + }
78355
78356 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
78357 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
78358 @@ -1646,6 +1661,10 @@ no_tcp_socket:
78359 bad_packet:
78360 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
78361 } else {
78362 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78363 + if (!grsec_enable_blackhole || (ret == 1 &&
78364 + (skb->dev->flags & IFF_LOOPBACK)))
78365 +#endif
78366 tcp_v6_send_reset(NULL, skb);
78367 }
78368
78369 @@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
78370 uid,
78371 0, /* non standard timer */
78372 0, /* open_requests have no inode */
78373 - 0, req);
78374 + 0,
78375 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78376 + NULL
78377 +#else
78378 + req
78379 +#endif
78380 + );
78381 }
78382
78383 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78384 @@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78385 sock_i_uid(sp),
78386 icsk->icsk_probes_out,
78387 sock_i_ino(sp),
78388 - atomic_read(&sp->sk_refcnt), sp,
78389 + atomic_read(&sp->sk_refcnt),
78390 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78391 + NULL,
78392 +#else
78393 + sp,
78394 +#endif
78395 jiffies_to_clock_t(icsk->icsk_rto),
78396 jiffies_to_clock_t(icsk->icsk_ack.ato),
78397 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
78398 @@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
78399 dest->s6_addr32[2], dest->s6_addr32[3], destp,
78400 tw->tw_substate, 0, 0,
78401 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
78402 - atomic_read(&tw->tw_refcnt), tw);
78403 + atomic_read(&tw->tw_refcnt),
78404 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78405 + NULL
78406 +#else
78407 + tw
78408 +#endif
78409 + );
78410 }
78411
78412 static int tcp6_seq_show(struct seq_file *seq, void *v)
78413 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
78414 index 07e2bfe..328dae8 100644
78415 --- a/net/ipv6/udp.c
78416 +++ b/net/ipv6/udp.c
78417 @@ -51,6 +51,10 @@
78418 #include <trace/events/skb.h>
78419 #include "udp_impl.h"
78420
78421 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78422 +extern int grsec_enable_blackhole;
78423 +#endif
78424 +
78425 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
78426 {
78427 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
78428 @@ -395,7 +399,7 @@ try_again:
78429 if (unlikely(err)) {
78430 trace_kfree_skb(skb, udpv6_recvmsg);
78431 if (!peeked) {
78432 - atomic_inc(&sk->sk_drops);
78433 + atomic_inc_unchecked(&sk->sk_drops);
78434 if (is_udp4)
78435 UDP_INC_STATS_USER(sock_net(sk),
78436 UDP_MIB_INERRORS,
78437 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78438 return rc;
78439 drop:
78440 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78441 - atomic_inc(&sk->sk_drops);
78442 + atomic_inc_unchecked(&sk->sk_drops);
78443 kfree_skb(skb);
78444 return -1;
78445 }
78446 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78447 if (likely(skb1 == NULL))
78448 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78449 if (!skb1) {
78450 - atomic_inc(&sk->sk_drops);
78451 + atomic_inc_unchecked(&sk->sk_drops);
78452 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78453 IS_UDPLITE(sk));
78454 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78455 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78456 goto discard;
78457
78458 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78459 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78460 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78461 +#endif
78462 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
78463
78464 kfree_skb(skb);
78465 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
78466 0, 0L, 0,
78467 sock_i_uid(sp), 0,
78468 sock_i_ino(sp),
78469 - atomic_read(&sp->sk_refcnt), sp,
78470 - atomic_read(&sp->sk_drops));
78471 + atomic_read(&sp->sk_refcnt),
78472 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78473 + NULL,
78474 +#else
78475 + sp,
78476 +#endif
78477 + atomic_read_unchecked(&sp->sk_drops));
78478 }
78479
78480 int udp6_seq_show(struct seq_file *seq, void *v)
78481 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
78482 index 6b9d5a0..4dffaf1 100644
78483 --- a/net/irda/ircomm/ircomm_tty.c
78484 +++ b/net/irda/ircomm/ircomm_tty.c
78485 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78486 add_wait_queue(&self->open_wait, &wait);
78487
78488 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
78489 - __FILE__,__LINE__, tty->driver->name, self->open_count );
78490 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78491
78492 /* As far as I can see, we protect open_count - Jean II */
78493 spin_lock_irqsave(&self->spinlock, flags);
78494 if (!tty_hung_up_p(filp)) {
78495 extra_count = 1;
78496 - self->open_count--;
78497 + local_dec(&self->open_count);
78498 }
78499 spin_unlock_irqrestore(&self->spinlock, flags);
78500 - self->blocked_open++;
78501 + local_inc(&self->blocked_open);
78502
78503 while (1) {
78504 if (tty->termios->c_cflag & CBAUD) {
78505 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78506 }
78507
78508 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
78509 - __FILE__,__LINE__, tty->driver->name, self->open_count );
78510 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78511
78512 schedule();
78513 }
78514 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78515 if (extra_count) {
78516 /* ++ is not atomic, so this should be protected - Jean II */
78517 spin_lock_irqsave(&self->spinlock, flags);
78518 - self->open_count++;
78519 + local_inc(&self->open_count);
78520 spin_unlock_irqrestore(&self->spinlock, flags);
78521 }
78522 - self->blocked_open--;
78523 + local_dec(&self->blocked_open);
78524
78525 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
78526 - __FILE__,__LINE__, tty->driver->name, self->open_count);
78527 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
78528
78529 if (!retval)
78530 self->flags |= ASYNC_NORMAL_ACTIVE;
78531 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78532 }
78533 /* ++ is not atomic, so this should be protected - Jean II */
78534 spin_lock_irqsave(&self->spinlock, flags);
78535 - self->open_count++;
78536 + local_inc(&self->open_count);
78537
78538 tty->driver_data = self;
78539 self->tty = tty;
78540 spin_unlock_irqrestore(&self->spinlock, flags);
78541
78542 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78543 - self->line, self->open_count);
78544 + self->line, local_read(&self->open_count));
78545
78546 /* Not really used by us, but lets do it anyway */
78547 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78548 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78549 return;
78550 }
78551
78552 - if ((tty->count == 1) && (self->open_count != 1)) {
78553 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
78554 /*
78555 * Uh, oh. tty->count is 1, which means that the tty
78556 * structure will be freed. state->count should always
78557 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78558 */
78559 IRDA_DEBUG(0, "%s(), bad serial port count; "
78560 "tty->count is 1, state->count is %d\n", __func__ ,
78561 - self->open_count);
78562 - self->open_count = 1;
78563 + local_read(&self->open_count));
78564 + local_set(&self->open_count, 1);
78565 }
78566
78567 - if (--self->open_count < 0) {
78568 + if (local_dec_return(&self->open_count) < 0) {
78569 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
78570 - __func__, self->line, self->open_count);
78571 - self->open_count = 0;
78572 + __func__, self->line, local_read(&self->open_count));
78573 + local_set(&self->open_count, 0);
78574 }
78575 - if (self->open_count) {
78576 + if (local_read(&self->open_count)) {
78577 spin_unlock_irqrestore(&self->spinlock, flags);
78578
78579 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
78580 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78581 tty->closing = 0;
78582 self->tty = NULL;
78583
78584 - if (self->blocked_open) {
78585 + if (local_read(&self->blocked_open)) {
78586 if (self->close_delay)
78587 schedule_timeout_interruptible(self->close_delay);
78588 wake_up_interruptible(&self->open_wait);
78589 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78590 spin_lock_irqsave(&self->spinlock, flags);
78591 self->flags &= ~ASYNC_NORMAL_ACTIVE;
78592 self->tty = NULL;
78593 - self->open_count = 0;
78594 + local_set(&self->open_count, 0);
78595 spin_unlock_irqrestore(&self->spinlock, flags);
78596
78597 wake_up_interruptible(&self->open_wait);
78598 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78599 seq_putc(m, '\n');
78600
78601 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78602 - seq_printf(m, "Open count: %d\n", self->open_count);
78603 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
78604 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78605 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78606
78607 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78608 index cd6f7a9..e63fe89 100644
78609 --- a/net/iucv/af_iucv.c
78610 +++ b/net/iucv/af_iucv.c
78611 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78612
78613 write_lock_bh(&iucv_sk_list.lock);
78614
78615 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78616 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78617 while (__iucv_get_sock_by_name(name)) {
78618 sprintf(name, "%08x",
78619 - atomic_inc_return(&iucv_sk_list.autobind_name));
78620 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78621 }
78622
78623 write_unlock_bh(&iucv_sk_list.lock);
78624 diff --git a/net/key/af_key.c b/net/key/af_key.c
78625 index 34e4185..8823368 100644
78626 --- a/net/key/af_key.c
78627 +++ b/net/key/af_key.c
78628 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78629 static u32 get_acqseq(void)
78630 {
78631 u32 res;
78632 - static atomic_t acqseq;
78633 + static atomic_unchecked_t acqseq;
78634
78635 do {
78636 - res = atomic_inc_return(&acqseq);
78637 + res = atomic_inc_return_unchecked(&acqseq);
78638 } while (!res);
78639 return res;
78640 }
78641 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78642 index bb61f77..3788d63 100644
78643 --- a/net/mac80211/ieee80211_i.h
78644 +++ b/net/mac80211/ieee80211_i.h
78645 @@ -28,6 +28,7 @@
78646 #include <net/ieee80211_radiotap.h>
78647 #include <net/cfg80211.h>
78648 #include <net/mac80211.h>
78649 +#include <asm/local.h>
78650 #include "key.h"
78651 #include "sta_info.h"
78652 #include "debug.h"
78653 @@ -840,7 +841,7 @@ struct ieee80211_local {
78654 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78655 spinlock_t queue_stop_reason_lock;
78656
78657 - int open_count;
78658 + local_t open_count;
78659 int monitors, cooked_mntrs;
78660 /* number of interfaces with corresponding FIF_ flags */
78661 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78662 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78663 index c93d395..a305570 100644
78664 --- a/net/mac80211/iface.c
78665 +++ b/net/mac80211/iface.c
78666 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78667 break;
78668 }
78669
78670 - if (local->open_count == 0) {
78671 + if (local_read(&local->open_count) == 0) {
78672 res = drv_start(local);
78673 if (res)
78674 goto err_del_bss;
78675 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78676 break;
78677 }
78678
78679 - if (local->monitors == 0 && local->open_count == 0) {
78680 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78681 res = ieee80211_add_virtual_monitor(local);
78682 if (res)
78683 goto err_stop;
78684 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78685 mutex_unlock(&local->mtx);
78686
78687 if (coming_up)
78688 - local->open_count++;
78689 + local_inc(&local->open_count);
78690
78691 if (hw_reconf_flags)
78692 ieee80211_hw_config(local, hw_reconf_flags);
78693 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78694 err_del_interface:
78695 drv_remove_interface(local, sdata);
78696 err_stop:
78697 - if (!local->open_count)
78698 + if (!local_read(&local->open_count))
78699 drv_stop(local);
78700 err_del_bss:
78701 sdata->bss = NULL;
78702 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78703 }
78704
78705 if (going_down)
78706 - local->open_count--;
78707 + local_dec(&local->open_count);
78708
78709 switch (sdata->vif.type) {
78710 case NL80211_IFTYPE_AP_VLAN:
78711 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78712
78713 ieee80211_recalc_ps(local, -1);
78714
78715 - if (local->open_count == 0) {
78716 + if (local_read(&local->open_count) == 0) {
78717 if (local->ops->napi_poll)
78718 napi_disable(&local->napi);
78719 ieee80211_clear_tx_pending(local);
78720 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78721 }
78722 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78723
78724 - if (local->monitors == local->open_count && local->monitors > 0)
78725 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78726 ieee80211_add_virtual_monitor(local);
78727 }
78728
78729 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78730 index c26e231..8916637 100644
78731 --- a/net/mac80211/main.c
78732 +++ b/net/mac80211/main.c
78733 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78734 local->hw.conf.power_level = power;
78735 }
78736
78737 - if (changed && local->open_count) {
78738 + if (changed && local_read(&local->open_count)) {
78739 ret = drv_config(local, changed);
78740 /*
78741 * Goal:
78742 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78743 index 5c572e7..ecf75ce 100644
78744 --- a/net/mac80211/pm.c
78745 +++ b/net/mac80211/pm.c
78746 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78747 struct ieee80211_sub_if_data *sdata;
78748 struct sta_info *sta;
78749
78750 - if (!local->open_count)
78751 + if (!local_read(&local->open_count))
78752 goto suspend;
78753
78754 ieee80211_scan_cancel(local);
78755 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78756 cancel_work_sync(&local->dynamic_ps_enable_work);
78757 del_timer_sync(&local->dynamic_ps_timer);
78758
78759 - local->wowlan = wowlan && local->open_count;
78760 + local->wowlan = wowlan && local_read(&local->open_count);
78761 if (local->wowlan) {
78762 int err = drv_suspend(local, wowlan);
78763 if (err < 0) {
78764 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78765 drv_remove_interface(local, sdata);
78766
78767 /* stop hardware - this must stop RX */
78768 - if (local->open_count)
78769 + if (local_read(&local->open_count))
78770 ieee80211_stop_device(local);
78771
78772 suspend:
78773 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78774 index 3313c11..bec9f17 100644
78775 --- a/net/mac80211/rate.c
78776 +++ b/net/mac80211/rate.c
78777 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78778
78779 ASSERT_RTNL();
78780
78781 - if (local->open_count)
78782 + if (local_read(&local->open_count))
78783 return -EBUSY;
78784
78785 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78786 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78787 index c97a065..ff61928 100644
78788 --- a/net/mac80211/rc80211_pid_debugfs.c
78789 +++ b/net/mac80211/rc80211_pid_debugfs.c
78790 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78791
78792 spin_unlock_irqrestore(&events->lock, status);
78793
78794 - if (copy_to_user(buf, pb, p))
78795 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78796 return -EFAULT;
78797
78798 return p;
78799 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78800 index 1cfe6d5..c428ba3 100644
78801 --- a/net/mac80211/util.c
78802 +++ b/net/mac80211/util.c
78803 @@ -1279,7 +1279,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78804 }
78805 #endif
78806 /* everything else happens only if HW was up & running */
78807 - if (!local->open_count)
78808 + if (!local_read(&local->open_count))
78809 goto wake_up;
78810
78811 /*
78812 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78813 index c19b214..471fad1 100644
78814 --- a/net/netfilter/Kconfig
78815 +++ b/net/netfilter/Kconfig
78816 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78817
78818 To compile it as a module, choose M here. If unsure, say N.
78819
78820 +config NETFILTER_XT_MATCH_GRADM
78821 + tristate '"gradm" match support'
78822 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78823 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78824 + ---help---
78825 + The gradm match allows to match on grsecurity RBAC being enabled.
78826 + It is useful when iptables rules are applied early on bootup to
78827 + prevent connections to the machine (except from a trusted host)
78828 + while the RBAC system is disabled.
78829 +
78830 config NETFILTER_XT_MATCH_HASHLIMIT
78831 tristate '"hashlimit" match support'
78832 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78833 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78834 index 1c5160f..145ae21 100644
78835 --- a/net/netfilter/Makefile
78836 +++ b/net/netfilter/Makefile
78837 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78838 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78839 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78840 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78841 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78842 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78843 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78844 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78845 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78846 index 1548df9..98ad9b4 100644
78847 --- a/net/netfilter/ipvs/ip_vs_conn.c
78848 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78849 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78850 /* Increase the refcnt counter of the dest */
78851 atomic_inc(&dest->refcnt);
78852
78853 - conn_flags = atomic_read(&dest->conn_flags);
78854 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78855 if (cp->protocol != IPPROTO_UDP)
78856 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78857 flags = cp->flags;
78858 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78859 atomic_set(&cp->refcnt, 1);
78860
78861 atomic_set(&cp->n_control, 0);
78862 - atomic_set(&cp->in_pkts, 0);
78863 + atomic_set_unchecked(&cp->in_pkts, 0);
78864
78865 atomic_inc(&ipvs->conn_count);
78866 if (flags & IP_VS_CONN_F_NO_CPORT)
78867 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78868
78869 /* Don't drop the entry if its number of incoming packets is not
78870 located in [0, 8] */
78871 - i = atomic_read(&cp->in_pkts);
78872 + i = atomic_read_unchecked(&cp->in_pkts);
78873 if (i > 8 || i < 0) return 0;
78874
78875 if (!todrop_rate[i]) return 0;
78876 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78877 index b54ecce..fc5f6cf 100644
78878 --- a/net/netfilter/ipvs/ip_vs_core.c
78879 +++ b/net/netfilter/ipvs/ip_vs_core.c
78880 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78881 ret = cp->packet_xmit(skb, cp, pd->pp);
78882 /* do not touch skb anymore */
78883
78884 - atomic_inc(&cp->in_pkts);
78885 + atomic_inc_unchecked(&cp->in_pkts);
78886 ip_vs_conn_put(cp);
78887 return ret;
78888 }
78889 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78890 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78891 pkts = sysctl_sync_threshold(ipvs);
78892 else
78893 - pkts = atomic_add_return(1, &cp->in_pkts);
78894 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78895
78896 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78897 ip_vs_sync_conn(net, cp, pkts);
78898 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78899 index f51013c..c99ee52 100644
78900 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78901 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78902 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78903 ip_vs_rs_hash(ipvs, dest);
78904 write_unlock_bh(&ipvs->rs_lock);
78905 }
78906 - atomic_set(&dest->conn_flags, conn_flags);
78907 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78908
78909 /* bind the service */
78910 if (!dest->svc) {
78911 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78912 " %-7s %-6d %-10d %-10d\n",
78913 &dest->addr.in6,
78914 ntohs(dest->port),
78915 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78916 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78917 atomic_read(&dest->weight),
78918 atomic_read(&dest->activeconns),
78919 atomic_read(&dest->inactconns));
78920 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78921 "%-7s %-6d %-10d %-10d\n",
78922 ntohl(dest->addr.ip),
78923 ntohs(dest->port),
78924 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78925 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78926 atomic_read(&dest->weight),
78927 atomic_read(&dest->activeconns),
78928 atomic_read(&dest->inactconns));
78929 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78930
78931 entry.addr = dest->addr.ip;
78932 entry.port = dest->port;
78933 - entry.conn_flags = atomic_read(&dest->conn_flags);
78934 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78935 entry.weight = atomic_read(&dest->weight);
78936 entry.u_threshold = dest->u_threshold;
78937 entry.l_threshold = dest->l_threshold;
78938 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78939 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78940 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78941 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78942 - (atomic_read(&dest->conn_flags) &
78943 + (atomic_read_unchecked(&dest->conn_flags) &
78944 IP_VS_CONN_F_FWD_MASK)) ||
78945 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78946 atomic_read(&dest->weight)) ||
78947 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78948 index effa10c..9058928 100644
78949 --- a/net/netfilter/ipvs/ip_vs_sync.c
78950 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78951 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78952 cp = cp->control;
78953 if (cp) {
78954 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78955 - pkts = atomic_add_return(1, &cp->in_pkts);
78956 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78957 else
78958 pkts = sysctl_sync_threshold(ipvs);
78959 ip_vs_sync_conn(net, cp->control, pkts);
78960 @@ -758,7 +758,7 @@ control:
78961 if (!cp)
78962 return;
78963 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78964 - pkts = atomic_add_return(1, &cp->in_pkts);
78965 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78966 else
78967 pkts = sysctl_sync_threshold(ipvs);
78968 goto sloop;
78969 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78970
78971 if (opt)
78972 memcpy(&cp->in_seq, opt, sizeof(*opt));
78973 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78974 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78975 cp->state = state;
78976 cp->old_state = cp->state;
78977 /*
78978 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78979 index c3c6291..3376d73 100644
78980 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78981 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78982 @@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78983 else
78984 rc = NF_ACCEPT;
78985 /* do not touch skb anymore */
78986 - atomic_inc(&cp->in_pkts);
78987 + atomic_inc_unchecked(&cp->in_pkts);
78988 goto out;
78989 }
78990
78991 @@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78992 else
78993 rc = NF_ACCEPT;
78994 /* do not touch skb anymore */
78995 - atomic_inc(&cp->in_pkts);
78996 + atomic_inc_unchecked(&cp->in_pkts);
78997 goto out;
78998 }
78999
79000 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
79001 index 2ceec64..a5b8a61 100644
79002 --- a/net/netfilter/nf_conntrack_core.c
79003 +++ b/net/netfilter/nf_conntrack_core.c
79004 @@ -1529,6 +1529,10 @@ err_extend:
79005 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
79006 #define DYING_NULLS_VAL ((1<<30)+1)
79007
79008 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79009 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
79010 +#endif
79011 +
79012 static int nf_conntrack_init_net(struct net *net)
79013 {
79014 int ret;
79015 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
79016 goto err_stat;
79017 }
79018
79019 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79020 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
79021 +#else
79022 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
79023 +#endif
79024 if (!net->ct.slabname) {
79025 ret = -ENOMEM;
79026 goto err_slabname;
79027 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
79028 index 5cfb5be..217c6d8 100644
79029 --- a/net/netfilter/nfnetlink_log.c
79030 +++ b/net/netfilter/nfnetlink_log.c
79031 @@ -70,7 +70,7 @@ struct nfulnl_instance {
79032 };
79033
79034 static DEFINE_SPINLOCK(instances_lock);
79035 -static atomic_t global_seq;
79036 +static atomic_unchecked_t global_seq;
79037
79038 #define INSTANCE_BUCKETS 16
79039 static struct hlist_head instance_table[INSTANCE_BUCKETS];
79040 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
79041 /* global sequence number */
79042 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
79043 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
79044 - htonl(atomic_inc_return(&global_seq))))
79045 + htonl(atomic_inc_return_unchecked(&global_seq))))
79046 goto nla_put_failure;
79047
79048 if (data_len) {
79049 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
79050 new file mode 100644
79051 index 0000000..c566332
79052 --- /dev/null
79053 +++ b/net/netfilter/xt_gradm.c
79054 @@ -0,0 +1,51 @@
79055 +/*
79056 + * gradm match for netfilter
79057 + * Copyright © Zbigniew Krzystolik, 2010
79058 + *
79059 + * This program is free software; you can redistribute it and/or modify
79060 + * it under the terms of the GNU General Public License; either version
79061 + * 2 or 3 as published by the Free Software Foundation.
79062 + */
79063 +#include <linux/module.h>
79064 +#include <linux/moduleparam.h>
79065 +#include <linux/skbuff.h>
79066 +#include <linux/netfilter/x_tables.h>
79067 +#include <linux/grsecurity.h>
79068 +#include <linux/netfilter/xt_gradm.h>
79069 +
79070 +static bool
79071 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
79072 +{
79073 + const struct xt_gradm_mtinfo *info = par->matchinfo;
79074 + bool retval = false;
79075 + if (gr_acl_is_enabled())
79076 + retval = true;
79077 + return retval ^ info->invflags;
79078 +}
79079 +
79080 +static struct xt_match gradm_mt_reg __read_mostly = {
79081 + .name = "gradm",
79082 + .revision = 0,
79083 + .family = NFPROTO_UNSPEC,
79084 + .match = gradm_mt,
79085 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
79086 + .me = THIS_MODULE,
79087 +};
79088 +
79089 +static int __init gradm_mt_init(void)
79090 +{
79091 + return xt_register_match(&gradm_mt_reg);
79092 +}
79093 +
79094 +static void __exit gradm_mt_exit(void)
79095 +{
79096 + xt_unregister_match(&gradm_mt_reg);
79097 +}
79098 +
79099 +module_init(gradm_mt_init);
79100 +module_exit(gradm_mt_exit);
79101 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
79102 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
79103 +MODULE_LICENSE("GPL");
79104 +MODULE_ALIAS("ipt_gradm");
79105 +MODULE_ALIAS("ip6t_gradm");
79106 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
79107 index 4fe4fb4..87a89e5 100644
79108 --- a/net/netfilter/xt_statistic.c
79109 +++ b/net/netfilter/xt_statistic.c
79110 @@ -19,7 +19,7 @@
79111 #include <linux/module.h>
79112
79113 struct xt_statistic_priv {
79114 - atomic_t count;
79115 + atomic_unchecked_t count;
79116 } ____cacheline_aligned_in_smp;
79117
79118 MODULE_LICENSE("GPL");
79119 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
79120 break;
79121 case XT_STATISTIC_MODE_NTH:
79122 do {
79123 - oval = atomic_read(&info->master->count);
79124 + oval = atomic_read_unchecked(&info->master->count);
79125 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
79126 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
79127 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
79128 if (nval == 0)
79129 ret = !ret;
79130 break;
79131 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
79132 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
79133 if (info->master == NULL)
79134 return -ENOMEM;
79135 - atomic_set(&info->master->count, info->u.nth.count);
79136 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
79137
79138 return 0;
79139 }
79140 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
79141 index 0426b67..d6ddaca 100644
79142 --- a/net/netlink/af_netlink.c
79143 +++ b/net/netlink/af_netlink.c
79144 @@ -780,7 +780,7 @@ static void netlink_overrun(struct sock *sk)
79145 sk->sk_error_report(sk);
79146 }
79147 }
79148 - atomic_inc(&sk->sk_drops);
79149 + atomic_inc_unchecked(&sk->sk_drops);
79150 }
79151
79152 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
79153 @@ -2070,7 +2070,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
79154 sk_wmem_alloc_get(s),
79155 nlk->cb,
79156 atomic_read(&s->sk_refcnt),
79157 - atomic_read(&s->sk_drops),
79158 + atomic_read_unchecked(&s->sk_drops),
79159 sock_i_ino(s)
79160 );
79161
79162 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
79163 index 7261eb8..44e8ac6 100644
79164 --- a/net/netrom/af_netrom.c
79165 +++ b/net/netrom/af_netrom.c
79166 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
79167 struct sock *sk = sock->sk;
79168 struct nr_sock *nr = nr_sk(sk);
79169
79170 + memset(sax, 0, sizeof(*sax));
79171 lock_sock(sk);
79172 if (peer != 0) {
79173 if (sk->sk_state != TCP_ESTABLISHED) {
79174 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
79175 *uaddr_len = sizeof(struct full_sockaddr_ax25);
79176 } else {
79177 sax->fsa_ax25.sax25_family = AF_NETROM;
79178 - sax->fsa_ax25.sax25_ndigis = 0;
79179 sax->fsa_ax25.sax25_call = nr->source_addr;
79180 *uaddr_len = sizeof(struct sockaddr_ax25);
79181 }
79182 diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
79183 index ddeb9aa..e18fffd 100644
79184 --- a/net/nfc/llcp/sock.c
79185 +++ b/net/nfc/llcp/sock.c
79186 @@ -443,15 +443,11 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
79187 pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
79188
79189 if (!addr || len < sizeof(struct sockaddr_nfc) ||
79190 - addr->sa_family != AF_NFC) {
79191 - pr_err("Invalid socket\n");
79192 + addr->sa_family != AF_NFC)
79193 return -EINVAL;
79194 - }
79195
79196 - if (addr->service_name_len == 0 && addr->dsap == 0) {
79197 - pr_err("Missing service name or dsap\n");
79198 + if (addr->service_name_len == 0 && addr->dsap == 0)
79199 return -EINVAL;
79200 - }
79201
79202 pr_debug("addr dev_idx=%u target_idx=%u protocol=%u\n", addr->dev_idx,
79203 addr->target_idx, addr->nfc_protocol);
79204 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
79205 index c5c9e2a..4814ab1 100644
79206 --- a/net/packet/af_packet.c
79207 +++ b/net/packet/af_packet.c
79208 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
79209
79210 spin_lock(&sk->sk_receive_queue.lock);
79211 po->stats.tp_packets++;
79212 - skb->dropcount = atomic_read(&sk->sk_drops);
79213 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79214 __skb_queue_tail(&sk->sk_receive_queue, skb);
79215 spin_unlock(&sk->sk_receive_queue.lock);
79216 sk->sk_data_ready(sk, skb->len);
79217 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
79218 drop_n_acct:
79219 spin_lock(&sk->sk_receive_queue.lock);
79220 po->stats.tp_drops++;
79221 - atomic_inc(&sk->sk_drops);
79222 + atomic_inc_unchecked(&sk->sk_drops);
79223 spin_unlock(&sk->sk_receive_queue.lock);
79224
79225 drop_n_restore:
79226 @@ -2642,6 +2642,7 @@ out:
79227
79228 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
79229 {
79230 + struct sock_extended_err ee;
79231 struct sock_exterr_skb *serr;
79232 struct sk_buff *skb, *skb2;
79233 int copied, err;
79234 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
79235 sock_recv_timestamp(msg, sk, skb);
79236
79237 serr = SKB_EXT_ERR(skb);
79238 + ee = serr->ee;
79239 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
79240 - sizeof(serr->ee), &serr->ee);
79241 + sizeof ee, &ee);
79242
79243 msg->msg_flags |= MSG_ERRQUEUE;
79244 err = copied;
79245 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
79246 case PACKET_HDRLEN:
79247 if (len > sizeof(int))
79248 len = sizeof(int);
79249 - if (copy_from_user(&val, optval, len))
79250 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
79251 return -EFAULT;
79252 switch (val) {
79253 case TPACKET_V1:
79254 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
79255 len = lv;
79256 if (put_user(len, optlen))
79257 return -EFAULT;
79258 - if (copy_to_user(optval, data, len))
79259 + if (len > sizeof(st) || copy_to_user(optval, data, len))
79260 return -EFAULT;
79261 return 0;
79262 }
79263 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
79264 index 5a940db..f0b9c12 100644
79265 --- a/net/phonet/af_phonet.c
79266 +++ b/net/phonet/af_phonet.c
79267 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
79268 {
79269 struct phonet_protocol *pp;
79270
79271 - if (protocol >= PHONET_NPROTO)
79272 + if (protocol < 0 || protocol >= PHONET_NPROTO)
79273 return NULL;
79274
79275 rcu_read_lock();
79276 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
79277 {
79278 int err = 0;
79279
79280 - if (protocol >= PHONET_NPROTO)
79281 + if (protocol < 0 || protocol >= PHONET_NPROTO)
79282 return -EINVAL;
79283
79284 err = proto_register(pp->prot, 1);
79285 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
79286 index 576f22c..bc7a71b 100644
79287 --- a/net/phonet/pep.c
79288 +++ b/net/phonet/pep.c
79289 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
79290
79291 case PNS_PEP_CTRL_REQ:
79292 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
79293 - atomic_inc(&sk->sk_drops);
79294 + atomic_inc_unchecked(&sk->sk_drops);
79295 break;
79296 }
79297 __skb_pull(skb, 4);
79298 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
79299 }
79300
79301 if (pn->rx_credits == 0) {
79302 - atomic_inc(&sk->sk_drops);
79303 + atomic_inc_unchecked(&sk->sk_drops);
79304 err = -ENOBUFS;
79305 break;
79306 }
79307 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
79308 }
79309
79310 if (pn->rx_credits == 0) {
79311 - atomic_inc(&sk->sk_drops);
79312 + atomic_inc_unchecked(&sk->sk_drops);
79313 err = NET_RX_DROP;
79314 break;
79315 }
79316 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
79317 index 0acc943..c727611 100644
79318 --- a/net/phonet/socket.c
79319 +++ b/net/phonet/socket.c
79320 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
79321 pn->resource, sk->sk_state,
79322 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
79323 sock_i_uid(sk), sock_i_ino(sk),
79324 - atomic_read(&sk->sk_refcnt), sk,
79325 - atomic_read(&sk->sk_drops), &len);
79326 + atomic_read(&sk->sk_refcnt),
79327 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79328 + NULL,
79329 +#else
79330 + sk,
79331 +#endif
79332 + atomic_read_unchecked(&sk->sk_drops), &len);
79333 }
79334 seq_printf(seq, "%*s\n", 127 - len, "");
79335 return 0;
79336 diff --git a/net/rds/cong.c b/net/rds/cong.c
79337 index e5b65ac..f3b6fb7 100644
79338 --- a/net/rds/cong.c
79339 +++ b/net/rds/cong.c
79340 @@ -78,7 +78,7 @@
79341 * finds that the saved generation number is smaller than the global generation
79342 * number, it wakes up the process.
79343 */
79344 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
79345 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
79346
79347 /*
79348 * Congestion monitoring
79349 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
79350 rdsdebug("waking map %p for %pI4\n",
79351 map, &map->m_addr);
79352 rds_stats_inc(s_cong_update_received);
79353 - atomic_inc(&rds_cong_generation);
79354 + atomic_inc_unchecked(&rds_cong_generation);
79355 if (waitqueue_active(&map->m_waitq))
79356 wake_up(&map->m_waitq);
79357 if (waitqueue_active(&rds_poll_waitq))
79358 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
79359
79360 int rds_cong_updated_since(unsigned long *recent)
79361 {
79362 - unsigned long gen = atomic_read(&rds_cong_generation);
79363 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
79364
79365 if (likely(*recent == gen))
79366 return 0;
79367 diff --git a/net/rds/ib.h b/net/rds/ib.h
79368 index 8d2b3d5..227ec5b 100644
79369 --- a/net/rds/ib.h
79370 +++ b/net/rds/ib.h
79371 @@ -128,7 +128,7 @@ struct rds_ib_connection {
79372 /* sending acks */
79373 unsigned long i_ack_flags;
79374 #ifdef KERNEL_HAS_ATOMIC64
79375 - atomic64_t i_ack_next; /* next ACK to send */
79376 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79377 #else
79378 spinlock_t i_ack_lock; /* protect i_ack_next */
79379 u64 i_ack_next; /* next ACK to send */
79380 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
79381 index a1e1162..265e129 100644
79382 --- a/net/rds/ib_cm.c
79383 +++ b/net/rds/ib_cm.c
79384 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
79385 /* Clear the ACK state */
79386 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79387 #ifdef KERNEL_HAS_ATOMIC64
79388 - atomic64_set(&ic->i_ack_next, 0);
79389 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79390 #else
79391 ic->i_ack_next = 0;
79392 #endif
79393 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
79394 index 8d19491..05a3e65 100644
79395 --- a/net/rds/ib_recv.c
79396 +++ b/net/rds/ib_recv.c
79397 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79398 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
79399 int ack_required)
79400 {
79401 - atomic64_set(&ic->i_ack_next, seq);
79402 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79403 if (ack_required) {
79404 smp_mb__before_clear_bit();
79405 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79406 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79407 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79408 smp_mb__after_clear_bit();
79409
79410 - return atomic64_read(&ic->i_ack_next);
79411 + return atomic64_read_unchecked(&ic->i_ack_next);
79412 }
79413 #endif
79414
79415 diff --git a/net/rds/iw.h b/net/rds/iw.h
79416 index 04ce3b1..48119a6 100644
79417 --- a/net/rds/iw.h
79418 +++ b/net/rds/iw.h
79419 @@ -134,7 +134,7 @@ struct rds_iw_connection {
79420 /* sending acks */
79421 unsigned long i_ack_flags;
79422 #ifdef KERNEL_HAS_ATOMIC64
79423 - atomic64_t i_ack_next; /* next ACK to send */
79424 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79425 #else
79426 spinlock_t i_ack_lock; /* protect i_ack_next */
79427 u64 i_ack_next; /* next ACK to send */
79428 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
79429 index a91e1db..cf3053f 100644
79430 --- a/net/rds/iw_cm.c
79431 +++ b/net/rds/iw_cm.c
79432 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
79433 /* Clear the ACK state */
79434 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79435 #ifdef KERNEL_HAS_ATOMIC64
79436 - atomic64_set(&ic->i_ack_next, 0);
79437 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79438 #else
79439 ic->i_ack_next = 0;
79440 #endif
79441 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
79442 index 4503335..db566b4 100644
79443 --- a/net/rds/iw_recv.c
79444 +++ b/net/rds/iw_recv.c
79445 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79446 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
79447 int ack_required)
79448 {
79449 - atomic64_set(&ic->i_ack_next, seq);
79450 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79451 if (ack_required) {
79452 smp_mb__before_clear_bit();
79453 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79454 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79455 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79456 smp_mb__after_clear_bit();
79457
79458 - return atomic64_read(&ic->i_ack_next);
79459 + return atomic64_read_unchecked(&ic->i_ack_next);
79460 }
79461 #endif
79462
79463 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
79464 index edac9ef..16bcb98 100644
79465 --- a/net/rds/tcp.c
79466 +++ b/net/rds/tcp.c
79467 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
79468 int val = 1;
79469
79470 set_fs(KERNEL_DS);
79471 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
79472 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
79473 sizeof(val));
79474 set_fs(oldfs);
79475 }
79476 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
79477 index 1b4fd68..2234175 100644
79478 --- a/net/rds/tcp_send.c
79479 +++ b/net/rds/tcp_send.c
79480 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
79481
79482 oldfs = get_fs();
79483 set_fs(KERNEL_DS);
79484 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
79485 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
79486 sizeof(val));
79487 set_fs(oldfs);
79488 }
79489 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
79490 index 05996d0..5a1dfe0 100644
79491 --- a/net/rxrpc/af_rxrpc.c
79492 +++ b/net/rxrpc/af_rxrpc.c
79493 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
79494 __be32 rxrpc_epoch;
79495
79496 /* current debugging ID */
79497 -atomic_t rxrpc_debug_id;
79498 +atomic_unchecked_t rxrpc_debug_id;
79499
79500 /* count of skbs currently in use */
79501 atomic_t rxrpc_n_skbs;
79502 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
79503 index e4d9cbc..b229649 100644
79504 --- a/net/rxrpc/ar-ack.c
79505 +++ b/net/rxrpc/ar-ack.c
79506 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79507
79508 _enter("{%d,%d,%d,%d},",
79509 call->acks_hard, call->acks_unacked,
79510 - atomic_read(&call->sequence),
79511 + atomic_read_unchecked(&call->sequence),
79512 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
79513
79514 stop = 0;
79515 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79516
79517 /* each Tx packet has a new serial number */
79518 sp->hdr.serial =
79519 - htonl(atomic_inc_return(&call->conn->serial));
79520 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
79521
79522 hdr = (struct rxrpc_header *) txb->head;
79523 hdr->serial = sp->hdr.serial;
79524 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
79525 */
79526 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
79527 {
79528 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
79529 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
79530 }
79531
79532 /*
79533 @@ -629,7 +629,7 @@ process_further:
79534
79535 latest = ntohl(sp->hdr.serial);
79536 hard = ntohl(ack.firstPacket);
79537 - tx = atomic_read(&call->sequence);
79538 + tx = atomic_read_unchecked(&call->sequence);
79539
79540 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79541 latest,
79542 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
79543 goto maybe_reschedule;
79544
79545 send_ACK_with_skew:
79546 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
79547 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
79548 ntohl(ack.serial));
79549 send_ACK:
79550 mtu = call->conn->trans->peer->if_mtu;
79551 @@ -1173,7 +1173,7 @@ send_ACK:
79552 ackinfo.rxMTU = htonl(5692);
79553 ackinfo.jumbo_max = htonl(4);
79554
79555 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79556 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79557 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79558 ntohl(hdr.serial),
79559 ntohs(ack.maxSkew),
79560 @@ -1191,7 +1191,7 @@ send_ACK:
79561 send_message:
79562 _debug("send message");
79563
79564 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79565 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79566 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
79567 send_message_2:
79568
79569 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
79570 index a3bbb36..3341fb9 100644
79571 --- a/net/rxrpc/ar-call.c
79572 +++ b/net/rxrpc/ar-call.c
79573 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
79574 spin_lock_init(&call->lock);
79575 rwlock_init(&call->state_lock);
79576 atomic_set(&call->usage, 1);
79577 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
79578 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79579 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
79580
79581 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
79582 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
79583 index 4106ca9..a338d7a 100644
79584 --- a/net/rxrpc/ar-connection.c
79585 +++ b/net/rxrpc/ar-connection.c
79586 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
79587 rwlock_init(&conn->lock);
79588 spin_lock_init(&conn->state_lock);
79589 atomic_set(&conn->usage, 1);
79590 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
79591 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79592 conn->avail_calls = RXRPC_MAXCALLS;
79593 conn->size_align = 4;
79594 conn->header_size = sizeof(struct rxrpc_header);
79595 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
79596 index e7ed43a..6afa140 100644
79597 --- a/net/rxrpc/ar-connevent.c
79598 +++ b/net/rxrpc/ar-connevent.c
79599 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
79600
79601 len = iov[0].iov_len + iov[1].iov_len;
79602
79603 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79604 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79605 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
79606
79607 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79608 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
79609 index 529572f..c758ca7 100644
79610 --- a/net/rxrpc/ar-input.c
79611 +++ b/net/rxrpc/ar-input.c
79612 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
79613 /* track the latest serial number on this connection for ACK packet
79614 * information */
79615 serial = ntohl(sp->hdr.serial);
79616 - hi_serial = atomic_read(&call->conn->hi_serial);
79617 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
79618 while (serial > hi_serial)
79619 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
79620 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
79621 serial);
79622
79623 /* request ACK generation for any ACK or DATA packet that requests
79624 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
79625 index a693aca..81e7293 100644
79626 --- a/net/rxrpc/ar-internal.h
79627 +++ b/net/rxrpc/ar-internal.h
79628 @@ -272,8 +272,8 @@ struct rxrpc_connection {
79629 int error; /* error code for local abort */
79630 int debug_id; /* debug ID for printks */
79631 unsigned int call_counter; /* call ID counter */
79632 - atomic_t serial; /* packet serial number counter */
79633 - atomic_t hi_serial; /* highest serial number received */
79634 + atomic_unchecked_t serial; /* packet serial number counter */
79635 + atomic_unchecked_t hi_serial; /* highest serial number received */
79636 u8 avail_calls; /* number of calls available */
79637 u8 size_align; /* data size alignment (for security) */
79638 u8 header_size; /* rxrpc + security header size */
79639 @@ -346,7 +346,7 @@ struct rxrpc_call {
79640 spinlock_t lock;
79641 rwlock_t state_lock; /* lock for state transition */
79642 atomic_t usage;
79643 - atomic_t sequence; /* Tx data packet sequence counter */
79644 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
79645 u32 abort_code; /* local/remote abort code */
79646 enum { /* current state of call */
79647 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
79648 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
79649 */
79650 extern atomic_t rxrpc_n_skbs;
79651 extern __be32 rxrpc_epoch;
79652 -extern atomic_t rxrpc_debug_id;
79653 +extern atomic_unchecked_t rxrpc_debug_id;
79654 extern struct workqueue_struct *rxrpc_workqueue;
79655
79656 /*
79657 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
79658 index 87f7135..74d3703 100644
79659 --- a/net/rxrpc/ar-local.c
79660 +++ b/net/rxrpc/ar-local.c
79661 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
79662 spin_lock_init(&local->lock);
79663 rwlock_init(&local->services_lock);
79664 atomic_set(&local->usage, 1);
79665 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
79666 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79667 memcpy(&local->srx, srx, sizeof(*srx));
79668 }
79669
79670 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
79671 index e1ac183..b43e10e 100644
79672 --- a/net/rxrpc/ar-output.c
79673 +++ b/net/rxrpc/ar-output.c
79674 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
79675 sp->hdr.cid = call->cid;
79676 sp->hdr.callNumber = call->call_id;
79677 sp->hdr.seq =
79678 - htonl(atomic_inc_return(&call->sequence));
79679 + htonl(atomic_inc_return_unchecked(&call->sequence));
79680 sp->hdr.serial =
79681 - htonl(atomic_inc_return(&conn->serial));
79682 + htonl(atomic_inc_return_unchecked(&conn->serial));
79683 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
79684 sp->hdr.userStatus = 0;
79685 sp->hdr.securityIndex = conn->security_ix;
79686 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
79687 index bebaa43..2644591 100644
79688 --- a/net/rxrpc/ar-peer.c
79689 +++ b/net/rxrpc/ar-peer.c
79690 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
79691 INIT_LIST_HEAD(&peer->error_targets);
79692 spin_lock_init(&peer->lock);
79693 atomic_set(&peer->usage, 1);
79694 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
79695 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79696 memcpy(&peer->srx, srx, sizeof(*srx));
79697
79698 rxrpc_assess_MTU_size(peer);
79699 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
79700 index 38047f7..9f48511 100644
79701 --- a/net/rxrpc/ar-proc.c
79702 +++ b/net/rxrpc/ar-proc.c
79703 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
79704 atomic_read(&conn->usage),
79705 rxrpc_conn_states[conn->state],
79706 key_serial(conn->key),
79707 - atomic_read(&conn->serial),
79708 - atomic_read(&conn->hi_serial));
79709 + atomic_read_unchecked(&conn->serial),
79710 + atomic_read_unchecked(&conn->hi_serial));
79711
79712 return 0;
79713 }
79714 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
79715 index 92df566..87ec1bf 100644
79716 --- a/net/rxrpc/ar-transport.c
79717 +++ b/net/rxrpc/ar-transport.c
79718 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
79719 spin_lock_init(&trans->client_lock);
79720 rwlock_init(&trans->conn_lock);
79721 atomic_set(&trans->usage, 1);
79722 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
79723 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79724
79725 if (peer->srx.transport.family == AF_INET) {
79726 switch (peer->srx.transport_type) {
79727 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
79728 index f226709..0e735a8 100644
79729 --- a/net/rxrpc/rxkad.c
79730 +++ b/net/rxrpc/rxkad.c
79731 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
79732
79733 len = iov[0].iov_len + iov[1].iov_len;
79734
79735 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79736 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79737 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
79738
79739 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79740 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
79741
79742 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
79743
79744 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
79745 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79746 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
79747
79748 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
79749 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
79750 index 1e2eee8..ce3967e 100644
79751 --- a/net/sctp/proc.c
79752 +++ b/net/sctp/proc.c
79753 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
79754 seq_printf(seq,
79755 "%8pK %8pK %-3d %-3d %-2d %-4d "
79756 "%4d %8d %8d %7d %5lu %-5d %5d ",
79757 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
79758 + assoc, sk,
79759 + sctp_sk(sk)->type, sk->sk_state,
79760 assoc->state, hash,
79761 assoc->assoc_id,
79762 assoc->sndbuf_used,
79763 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
79764 index 5e25981..dbda919 100644
79765 --- a/net/sctp/socket.c
79766 +++ b/net/sctp/socket.c
79767 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79768 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79769 if (space_left < addrlen)
79770 return -ENOMEM;
79771 + if (addrlen > sizeof(temp) || addrlen < 0)
79772 + return -EFAULT;
79773 if (copy_to_user(to, &temp, addrlen))
79774 return -EFAULT;
79775 to += addrlen;
79776 diff --git a/net/socket.c b/net/socket.c
79777 index edc3c4a..4b4e4a8 100644
79778 --- a/net/socket.c
79779 +++ b/net/socket.c
79780 @@ -88,6 +88,7 @@
79781 #include <linux/nsproxy.h>
79782 #include <linux/magic.h>
79783 #include <linux/slab.h>
79784 +#include <linux/in.h>
79785
79786 #include <asm/uaccess.h>
79787 #include <asm/unistd.h>
79788 @@ -105,6 +106,8 @@
79789 #include <linux/sockios.h>
79790 #include <linux/atalk.h>
79791
79792 +#include <linux/grsock.h>
79793 +
79794 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79795 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79796 unsigned long nr_segs, loff_t pos);
79797 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79798 &sockfs_dentry_operations, SOCKFS_MAGIC);
79799 }
79800
79801 -static struct vfsmount *sock_mnt __read_mostly;
79802 +struct vfsmount *sock_mnt __read_mostly;
79803
79804 static struct file_system_type sock_fs_type = {
79805 .name = "sockfs",
79806 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79807 return -EAFNOSUPPORT;
79808 if (type < 0 || type >= SOCK_MAX)
79809 return -EINVAL;
79810 + if (protocol < 0)
79811 + return -EINVAL;
79812
79813 /* Compatibility.
79814
79815 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79816 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79817 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79818
79819 + if(!gr_search_socket(family, type, protocol)) {
79820 + retval = -EACCES;
79821 + goto out;
79822 + }
79823 +
79824 + if (gr_handle_sock_all(family, type, protocol)) {
79825 + retval = -EACCES;
79826 + goto out;
79827 + }
79828 +
79829 retval = sock_create(family, type, protocol, &sock);
79830 if (retval < 0)
79831 goto out;
79832 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79833 if (sock) {
79834 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79835 if (err >= 0) {
79836 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79837 + err = -EACCES;
79838 + goto error;
79839 + }
79840 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79841 + if (err)
79842 + goto error;
79843 +
79844 err = security_socket_bind(sock,
79845 (struct sockaddr *)&address,
79846 addrlen);
79847 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79848 (struct sockaddr *)
79849 &address, addrlen);
79850 }
79851 +error:
79852 fput_light(sock->file, fput_needed);
79853 }
79854 return err;
79855 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79856 if ((unsigned int)backlog > somaxconn)
79857 backlog = somaxconn;
79858
79859 + if (gr_handle_sock_server_other(sock->sk)) {
79860 + err = -EPERM;
79861 + goto error;
79862 + }
79863 +
79864 + err = gr_search_listen(sock);
79865 + if (err)
79866 + goto error;
79867 +
79868 err = security_socket_listen(sock, backlog);
79869 if (!err)
79870 err = sock->ops->listen(sock, backlog);
79871
79872 +error:
79873 fput_light(sock->file, fput_needed);
79874 }
79875 return err;
79876 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79877 newsock->type = sock->type;
79878 newsock->ops = sock->ops;
79879
79880 + if (gr_handle_sock_server_other(sock->sk)) {
79881 + err = -EPERM;
79882 + sock_release(newsock);
79883 + goto out_put;
79884 + }
79885 +
79886 + err = gr_search_accept(sock);
79887 + if (err) {
79888 + sock_release(newsock);
79889 + goto out_put;
79890 + }
79891 +
79892 /*
79893 * We don't need try_module_get here, as the listening socket (sock)
79894 * has the protocol module (sock->ops->owner) held.
79895 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79896 fd_install(newfd, newfile);
79897 err = newfd;
79898
79899 + gr_attach_curr_ip(newsock->sk);
79900 +
79901 out_put:
79902 fput_light(sock->file, fput_needed);
79903 out:
79904 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79905 int, addrlen)
79906 {
79907 struct socket *sock;
79908 + struct sockaddr *sck;
79909 struct sockaddr_storage address;
79910 int err, fput_needed;
79911
79912 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79913 if (err < 0)
79914 goto out_put;
79915
79916 + sck = (struct sockaddr *)&address;
79917 +
79918 + if (gr_handle_sock_client(sck)) {
79919 + err = -EACCES;
79920 + goto out_put;
79921 + }
79922 +
79923 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79924 + if (err)
79925 + goto out_put;
79926 +
79927 err =
79928 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79929 if (err)
79930 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79931 * checking falls down on this.
79932 */
79933 if (copy_from_user(ctl_buf,
79934 - (void __user __force *)msg_sys->msg_control,
79935 + (void __force_user *)msg_sys->msg_control,
79936 ctl_len))
79937 goto out_freectl;
79938 msg_sys->msg_control = ctl_buf;
79939 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79940 * kernel msghdr to use the kernel address space)
79941 */
79942
79943 - uaddr = (__force void __user *)msg_sys->msg_name;
79944 + uaddr = (void __force_user *)msg_sys->msg_name;
79945 uaddr_len = COMPAT_NAMELEN(msg);
79946 if (MSG_CMSG_COMPAT & flags) {
79947 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79948 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79949 }
79950
79951 ifr = compat_alloc_user_space(buf_size);
79952 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79953 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79954
79955 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79956 return -EFAULT;
79957 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79958 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79959
79960 if (copy_in_user(rxnfc, compat_rxnfc,
79961 - (void *)(&rxnfc->fs.m_ext + 1) -
79962 - (void *)rxnfc) ||
79963 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79964 + (void __user *)rxnfc) ||
79965 copy_in_user(&rxnfc->fs.ring_cookie,
79966 &compat_rxnfc->fs.ring_cookie,
79967 - (void *)(&rxnfc->fs.location + 1) -
79968 - (void *)&rxnfc->fs.ring_cookie) ||
79969 + (void __user *)(&rxnfc->fs.location + 1) -
79970 + (void __user *)&rxnfc->fs.ring_cookie) ||
79971 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79972 sizeof(rxnfc->rule_cnt)))
79973 return -EFAULT;
79974 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79975
79976 if (convert_out) {
79977 if (copy_in_user(compat_rxnfc, rxnfc,
79978 - (const void *)(&rxnfc->fs.m_ext + 1) -
79979 - (const void *)rxnfc) ||
79980 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79981 + (const void __user *)rxnfc) ||
79982 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79983 &rxnfc->fs.ring_cookie,
79984 - (const void *)(&rxnfc->fs.location + 1) -
79985 - (const void *)&rxnfc->fs.ring_cookie) ||
79986 + (const void __user *)(&rxnfc->fs.location + 1) -
79987 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79988 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79989 sizeof(rxnfc->rule_cnt)))
79990 return -EFAULT;
79991 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79992 old_fs = get_fs();
79993 set_fs(KERNEL_DS);
79994 err = dev_ioctl(net, cmd,
79995 - (struct ifreq __user __force *) &kifr);
79996 + (struct ifreq __force_user *) &kifr);
79997 set_fs(old_fs);
79998
79999 return err;
80000 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
80001
80002 old_fs = get_fs();
80003 set_fs(KERNEL_DS);
80004 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
80005 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
80006 set_fs(old_fs);
80007
80008 if (cmd == SIOCGIFMAP && !err) {
80009 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
80010 ret |= __get_user(rtdev, &(ur4->rt_dev));
80011 if (rtdev) {
80012 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
80013 - r4.rt_dev = (char __user __force *)devname;
80014 + r4.rt_dev = (char __force_user *)devname;
80015 devname[15] = 0;
80016 } else
80017 r4.rt_dev = NULL;
80018 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
80019 int __user *uoptlen;
80020 int err;
80021
80022 - uoptval = (char __user __force *) optval;
80023 - uoptlen = (int __user __force *) optlen;
80024 + uoptval = (char __force_user *) optval;
80025 + uoptlen = (int __force_user *) optlen;
80026
80027 set_fs(KERNEL_DS);
80028 if (level == SOL_SOCKET)
80029 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
80030 char __user *uoptval;
80031 int err;
80032
80033 - uoptval = (char __user __force *) optval;
80034 + uoptval = (char __force_user *) optval;
80035
80036 set_fs(KERNEL_DS);
80037 if (level == SOL_SOCKET)
80038 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
80039 index 128494e..775d0e0 100644
80040 --- a/net/sunrpc/sched.c
80041 +++ b/net/sunrpc/sched.c
80042 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
80043 #ifdef RPC_DEBUG
80044 static void rpc_task_set_debuginfo(struct rpc_task *task)
80045 {
80046 - static atomic_t rpc_pid;
80047 + static atomic_unchecked_t rpc_pid;
80048
80049 - task->tk_pid = atomic_inc_return(&rpc_pid);
80050 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
80051 }
80052 #else
80053 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
80054 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
80055 index 8343737..677025e 100644
80056 --- a/net/sunrpc/xprtrdma/svc_rdma.c
80057 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
80058 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
80059 static unsigned int min_max_inline = 4096;
80060 static unsigned int max_max_inline = 65536;
80061
80062 -atomic_t rdma_stat_recv;
80063 -atomic_t rdma_stat_read;
80064 -atomic_t rdma_stat_write;
80065 -atomic_t rdma_stat_sq_starve;
80066 -atomic_t rdma_stat_rq_starve;
80067 -atomic_t rdma_stat_rq_poll;
80068 -atomic_t rdma_stat_rq_prod;
80069 -atomic_t rdma_stat_sq_poll;
80070 -atomic_t rdma_stat_sq_prod;
80071 +atomic_unchecked_t rdma_stat_recv;
80072 +atomic_unchecked_t rdma_stat_read;
80073 +atomic_unchecked_t rdma_stat_write;
80074 +atomic_unchecked_t rdma_stat_sq_starve;
80075 +atomic_unchecked_t rdma_stat_rq_starve;
80076 +atomic_unchecked_t rdma_stat_rq_poll;
80077 +atomic_unchecked_t rdma_stat_rq_prod;
80078 +atomic_unchecked_t rdma_stat_sq_poll;
80079 +atomic_unchecked_t rdma_stat_sq_prod;
80080
80081 /* Temporary NFS request map and context caches */
80082 struct kmem_cache *svc_rdma_map_cachep;
80083 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
80084 len -= *ppos;
80085 if (len > *lenp)
80086 len = *lenp;
80087 - if (len && copy_to_user(buffer, str_buf, len))
80088 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
80089 return -EFAULT;
80090 *lenp = len;
80091 *ppos += len;
80092 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
80093 {
80094 .procname = "rdma_stat_read",
80095 .data = &rdma_stat_read,
80096 - .maxlen = sizeof(atomic_t),
80097 + .maxlen = sizeof(atomic_unchecked_t),
80098 .mode = 0644,
80099 .proc_handler = read_reset_stat,
80100 },
80101 {
80102 .procname = "rdma_stat_recv",
80103 .data = &rdma_stat_recv,
80104 - .maxlen = sizeof(atomic_t),
80105 + .maxlen = sizeof(atomic_unchecked_t),
80106 .mode = 0644,
80107 .proc_handler = read_reset_stat,
80108 },
80109 {
80110 .procname = "rdma_stat_write",
80111 .data = &rdma_stat_write,
80112 - .maxlen = sizeof(atomic_t),
80113 + .maxlen = sizeof(atomic_unchecked_t),
80114 .mode = 0644,
80115 .proc_handler = read_reset_stat,
80116 },
80117 {
80118 .procname = "rdma_stat_sq_starve",
80119 .data = &rdma_stat_sq_starve,
80120 - .maxlen = sizeof(atomic_t),
80121 + .maxlen = sizeof(atomic_unchecked_t),
80122 .mode = 0644,
80123 .proc_handler = read_reset_stat,
80124 },
80125 {
80126 .procname = "rdma_stat_rq_starve",
80127 .data = &rdma_stat_rq_starve,
80128 - .maxlen = sizeof(atomic_t),
80129 + .maxlen = sizeof(atomic_unchecked_t),
80130 .mode = 0644,
80131 .proc_handler = read_reset_stat,
80132 },
80133 {
80134 .procname = "rdma_stat_rq_poll",
80135 .data = &rdma_stat_rq_poll,
80136 - .maxlen = sizeof(atomic_t),
80137 + .maxlen = sizeof(atomic_unchecked_t),
80138 .mode = 0644,
80139 .proc_handler = read_reset_stat,
80140 },
80141 {
80142 .procname = "rdma_stat_rq_prod",
80143 .data = &rdma_stat_rq_prod,
80144 - .maxlen = sizeof(atomic_t),
80145 + .maxlen = sizeof(atomic_unchecked_t),
80146 .mode = 0644,
80147 .proc_handler = read_reset_stat,
80148 },
80149 {
80150 .procname = "rdma_stat_sq_poll",
80151 .data = &rdma_stat_sq_poll,
80152 - .maxlen = sizeof(atomic_t),
80153 + .maxlen = sizeof(atomic_unchecked_t),
80154 .mode = 0644,
80155 .proc_handler = read_reset_stat,
80156 },
80157 {
80158 .procname = "rdma_stat_sq_prod",
80159 .data = &rdma_stat_sq_prod,
80160 - .maxlen = sizeof(atomic_t),
80161 + .maxlen = sizeof(atomic_unchecked_t),
80162 .mode = 0644,
80163 .proc_handler = read_reset_stat,
80164 },
80165 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
80166 index 41cb63b..c4a1489 100644
80167 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
80168 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
80169 @@ -501,7 +501,7 @@ next_sge:
80170 svc_rdma_put_context(ctxt, 0);
80171 goto out;
80172 }
80173 - atomic_inc(&rdma_stat_read);
80174 + atomic_inc_unchecked(&rdma_stat_read);
80175
80176 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
80177 chl_map->ch[ch_no].count -= read_wr.num_sge;
80178 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
80179 dto_q);
80180 list_del_init(&ctxt->dto_q);
80181 } else {
80182 - atomic_inc(&rdma_stat_rq_starve);
80183 + atomic_inc_unchecked(&rdma_stat_rq_starve);
80184 clear_bit(XPT_DATA, &xprt->xpt_flags);
80185 ctxt = NULL;
80186 }
80187 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
80188 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
80189 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
80190 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
80191 - atomic_inc(&rdma_stat_recv);
80192 + atomic_inc_unchecked(&rdma_stat_recv);
80193
80194 /* Build up the XDR from the receive buffers. */
80195 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
80196 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
80197 index 42eb7ba..c887c45 100644
80198 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
80199 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
80200 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
80201 write_wr.wr.rdma.remote_addr = to;
80202
80203 /* Post It */
80204 - atomic_inc(&rdma_stat_write);
80205 + atomic_inc_unchecked(&rdma_stat_write);
80206 if (svc_rdma_send(xprt, &write_wr))
80207 goto err;
80208 return 0;
80209 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
80210 index 73b428b..5f3f8f3 100644
80211 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
80212 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
80213 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
80214 return;
80215
80216 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
80217 - atomic_inc(&rdma_stat_rq_poll);
80218 + atomic_inc_unchecked(&rdma_stat_rq_poll);
80219
80220 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
80221 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
80222 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
80223 }
80224
80225 if (ctxt)
80226 - atomic_inc(&rdma_stat_rq_prod);
80227 + atomic_inc_unchecked(&rdma_stat_rq_prod);
80228
80229 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
80230 /*
80231 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
80232 return;
80233
80234 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
80235 - atomic_inc(&rdma_stat_sq_poll);
80236 + atomic_inc_unchecked(&rdma_stat_sq_poll);
80237 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
80238 if (wc.status != IB_WC_SUCCESS)
80239 /* Close the transport */
80240 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
80241 }
80242
80243 if (ctxt)
80244 - atomic_inc(&rdma_stat_sq_prod);
80245 + atomic_inc_unchecked(&rdma_stat_sq_prod);
80246 }
80247
80248 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
80249 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
80250 spin_lock_bh(&xprt->sc_lock);
80251 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
80252 spin_unlock_bh(&xprt->sc_lock);
80253 - atomic_inc(&rdma_stat_sq_starve);
80254 + atomic_inc_unchecked(&rdma_stat_sq_starve);
80255
80256 /* See if we can opportunistically reap SQ WR to make room */
80257 sq_cq_reap(xprt);
80258 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
80259 index e3a6e37..be2ea77 100644
80260 --- a/net/sysctl_net.c
80261 +++ b/net/sysctl_net.c
80262 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
80263 struct ctl_table *table)
80264 {
80265 /* Allow network administrator to have same access as root. */
80266 - if (capable(CAP_NET_ADMIN)) {
80267 + if (capable_nolog(CAP_NET_ADMIN)) {
80268 int mode = (table->mode >> 6) & 7;
80269 return (mode << 6) | (mode << 3) | mode;
80270 }
80271 diff --git a/net/tipc/link.c b/net/tipc/link.c
80272 index 1c1e615..113e0ae 100644
80273 --- a/net/tipc/link.c
80274 +++ b/net/tipc/link.c
80275 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
80276 struct tipc_msg fragm_hdr;
80277 struct sk_buff *buf, *buf_chain, *prev;
80278 u32 fragm_crs, fragm_rest, hsz, sect_rest;
80279 - const unchar *sect_crs;
80280 + const unchar __user *sect_crs;
80281 int curr_sect;
80282 u32 fragm_no;
80283
80284 @@ -1212,7 +1212,7 @@ again:
80285
80286 if (!sect_rest) {
80287 sect_rest = msg_sect[++curr_sect].iov_len;
80288 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
80289 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
80290 }
80291
80292 if (sect_rest < fragm_rest)
80293 @@ -1231,7 +1231,7 @@ error:
80294 }
80295 } else
80296 skb_copy_to_linear_data_offset(buf, fragm_crs,
80297 - sect_crs, sz);
80298 + (const void __force_kernel *)sect_crs, sz);
80299 sect_crs += sz;
80300 sect_rest -= sz;
80301 fragm_crs += sz;
80302 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
80303 index f2db8a8..9245aa4 100644
80304 --- a/net/tipc/msg.c
80305 +++ b/net/tipc/msg.c
80306 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
80307 msg_sect[cnt].iov_len);
80308 else
80309 skb_copy_to_linear_data_offset(*buf, pos,
80310 - msg_sect[cnt].iov_base,
80311 + (const void __force_kernel *)msg_sect[cnt].iov_base,
80312 msg_sect[cnt].iov_len);
80313 pos += msg_sect[cnt].iov_len;
80314 }
80315 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
80316 index 5ed5965..90abe34 100644
80317 --- a/net/tipc/subscr.c
80318 +++ b/net/tipc/subscr.c
80319 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
80320 {
80321 struct iovec msg_sect;
80322
80323 - msg_sect.iov_base = (void *)&sub->evt;
80324 + msg_sect.iov_base = (void __force_user *)&sub->evt;
80325 msg_sect.iov_len = sizeof(struct tipc_event);
80326
80327 sub->evt.event = htohl(event, sub->swap);
80328 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
80329 index c5ee4ff..e905948 100644
80330 --- a/net/unix/af_unix.c
80331 +++ b/net/unix/af_unix.c
80332 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
80333 err = -ECONNREFUSED;
80334 if (!S_ISSOCK(inode->i_mode))
80335 goto put_fail;
80336 +
80337 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
80338 + err = -EACCES;
80339 + goto put_fail;
80340 + }
80341 +
80342 u = unix_find_socket_byinode(inode);
80343 if (!u)
80344 goto put_fail;
80345 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
80346 if (u) {
80347 struct dentry *dentry;
80348 dentry = unix_sk(u)->path.dentry;
80349 +
80350 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
80351 + err = -EPERM;
80352 + sock_put(u);
80353 + goto fail;
80354 + }
80355 +
80356 if (dentry)
80357 touch_atime(&unix_sk(u)->path);
80358 } else
80359 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
80360 */
80361 err = security_path_mknod(&path, dentry, mode, 0);
80362 if (!err) {
80363 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
80364 + err = -EACCES;
80365 + goto out;
80366 + }
80367 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
80368 if (!err) {
80369 res->mnt = mntget(path.mnt);
80370 res->dentry = dget(dentry);
80371 + gr_handle_create(dentry, path.mnt);
80372 }
80373 }
80374 +out:
80375 done_path_create(&path, dentry);
80376 return err;
80377 }
80378 diff --git a/net/wireless/core.h b/net/wireless/core.h
80379 index bc7430b..35349de 100644
80380 --- a/net/wireless/core.h
80381 +++ b/net/wireless/core.h
80382 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
80383 struct mutex mtx;
80384
80385 /* rfkill support */
80386 - struct rfkill_ops rfkill_ops;
80387 + rfkill_ops_no_const rfkill_ops;
80388 struct rfkill *rfkill;
80389 struct work_struct rfkill_sync;
80390
80391 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
80392 index b0eb7aa..7d73e82 100644
80393 --- a/net/wireless/wext-core.c
80394 +++ b/net/wireless/wext-core.c
80395 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80396 */
80397
80398 /* Support for very large requests */
80399 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
80400 - (user_length > descr->max_tokens)) {
80401 + if (user_length > descr->max_tokens) {
80402 /* Allow userspace to GET more than max so
80403 * we can support any size GET requests.
80404 * There is still a limit : -ENOMEM.
80405 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80406 }
80407 }
80408
80409 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
80410 - /*
80411 - * If this is a GET, but not NOMAX, it means that the extra
80412 - * data is not bounded by userspace, but by max_tokens. Thus
80413 - * set the length to max_tokens. This matches the extra data
80414 - * allocation.
80415 - * The driver should fill it with the number of tokens it
80416 - * provided, and it may check iwp->length rather than having
80417 - * knowledge of max_tokens. If the driver doesn't change the
80418 - * iwp->length, this ioctl just copies back max_token tokens
80419 - * filled with zeroes. Hopefully the driver isn't claiming
80420 - * them to be valid data.
80421 - */
80422 - iwp->length = descr->max_tokens;
80423 - }
80424 -
80425 err = handler(dev, info, (union iwreq_data *) iwp, extra);
80426
80427 iwp->length += essid_compat;
80428 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
80429 index 387848e..a6667a2 100644
80430 --- a/net/xfrm/xfrm_policy.c
80431 +++ b/net/xfrm/xfrm_policy.c
80432 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
80433 {
80434 policy->walk.dead = 1;
80435
80436 - atomic_inc(&policy->genid);
80437 + atomic_inc_unchecked(&policy->genid);
80438
80439 if (del_timer(&policy->timer))
80440 xfrm_pol_put(policy);
80441 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
80442 hlist_add_head(&policy->bydst, chain);
80443 xfrm_pol_hold(policy);
80444 net->xfrm.policy_count[dir]++;
80445 - atomic_inc(&flow_cache_genid);
80446 + atomic_inc_unchecked(&flow_cache_genid);
80447 rt_genid_bump(net);
80448 if (delpol)
80449 __xfrm_policy_unlink(delpol, dir);
80450 @@ -1533,7 +1533,7 @@ free_dst:
80451 goto out;
80452 }
80453
80454 -static int inline
80455 +static inline int
80456 xfrm_dst_alloc_copy(void **target, const void *src, int size)
80457 {
80458 if (!*target) {
80459 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
80460 return 0;
80461 }
80462
80463 -static int inline
80464 +static inline int
80465 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80466 {
80467 #ifdef CONFIG_XFRM_SUB_POLICY
80468 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80469 #endif
80470 }
80471
80472 -static int inline
80473 +static inline int
80474 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
80475 {
80476 #ifdef CONFIG_XFRM_SUB_POLICY
80477 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
80478
80479 xdst->num_pols = num_pols;
80480 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
80481 - xdst->policy_genid = atomic_read(&pols[0]->genid);
80482 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
80483
80484 return xdst;
80485 }
80486 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
80487 if (xdst->xfrm_genid != dst->xfrm->genid)
80488 return 0;
80489 if (xdst->num_pols > 0 &&
80490 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
80491 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
80492 return 0;
80493
80494 mtu = dst_mtu(dst->child);
80495 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
80496 sizeof(pol->xfrm_vec[i].saddr));
80497 pol->xfrm_vec[i].encap_family = mp->new_family;
80498 /* flush bundles */
80499 - atomic_inc(&pol->genid);
80500 + atomic_inc_unchecked(&pol->genid);
80501 }
80502 }
80503
80504 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
80505 index ff1720d..ed8475e 100644
80506 --- a/scripts/Makefile.build
80507 +++ b/scripts/Makefile.build
80508 @@ -111,7 +111,7 @@ endif
80509 endif
80510
80511 # Do not include host rules unless needed
80512 -ifneq ($(hostprogs-y)$(hostprogs-m),)
80513 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
80514 include scripts/Makefile.host
80515 endif
80516
80517 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
80518 index 686cb0d..9d653bf 100644
80519 --- a/scripts/Makefile.clean
80520 +++ b/scripts/Makefile.clean
80521 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
80522 __clean-files := $(extra-y) $(always) \
80523 $(targets) $(clean-files) \
80524 $(host-progs) \
80525 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
80526 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
80527 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
80528
80529 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
80530
80531 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
80532 index 1ac414f..38575f7 100644
80533 --- a/scripts/Makefile.host
80534 +++ b/scripts/Makefile.host
80535 @@ -31,6 +31,8 @@
80536 # Note: Shared libraries consisting of C++ files are not supported
80537
80538 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
80539 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
80540 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
80541
80542 # C code
80543 # Executables compiled from a single .c file
80544 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
80545 # Shared libaries (only .c supported)
80546 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
80547 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
80548 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
80549 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
80550 # Remove .so files from "xxx-objs"
80551 host-cobjs := $(filter-out %.so,$(host-cobjs))
80552 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
80553
80554 -#Object (.o) files used by the shared libaries
80555 +# Object (.o) files used by the shared libaries
80556 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
80557 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
80558
80559 # output directory for programs/.o files
80560 # hostprogs-y := tools/build may have been specified. Retrieve directory
80561 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
80562 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
80563 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
80564 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
80565 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
80566 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
80567 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
80568 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
80569
80570 obj-dirs += $(host-objdirs)
80571 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
80572 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
80573 $(call if_changed_dep,host-cshobjs)
80574
80575 +# Compile .c file, create position independent .o file
80576 +# host-cxxshobjs -> .o
80577 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
80578 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
80579 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
80580 + $(call if_changed_dep,host-cxxshobjs)
80581 +
80582 # Link a shared library, based on position independent .o files
80583 # *.o -> .so shared library (host-cshlib)
80584 quiet_cmd_host-cshlib = HOSTLLD -shared $@
80585 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
80586 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
80587 $(call if_changed,host-cshlib)
80588
80589 +# Link a shared library, based on position independent .o files
80590 +# *.o -> .so shared library (host-cxxshlib)
80591 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
80592 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
80593 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
80594 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
80595 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
80596 + $(call if_changed,host-cxxshlib)
80597 +
80598 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
80599 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
80600 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
80601
80602 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
80603 index cb1f50c..cef2a7c 100644
80604 --- a/scripts/basic/fixdep.c
80605 +++ b/scripts/basic/fixdep.c
80606 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
80607 /*
80608 * Lookup a value in the configuration string.
80609 */
80610 -static int is_defined_config(const char *name, int len, unsigned int hash)
80611 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
80612 {
80613 struct item *aux;
80614
80615 @@ -211,10 +211,10 @@ static void clear_config(void)
80616 /*
80617 * Record the use of a CONFIG_* word.
80618 */
80619 -static void use_config(const char *m, int slen)
80620 +static void use_config(const char *m, unsigned int slen)
80621 {
80622 unsigned int hash = strhash(m, slen);
80623 - int c, i;
80624 + unsigned int c, i;
80625
80626 if (is_defined_config(m, slen, hash))
80627 return;
80628 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
80629
80630 static void parse_config_file(const char *map, size_t len)
80631 {
80632 - const int *end = (const int *) (map + len);
80633 + const unsigned int *end = (const unsigned int *) (map + len);
80634 /* start at +1, so that p can never be < map */
80635 - const int *m = (const int *) map + 1;
80636 + const unsigned int *m = (const unsigned int *) map + 1;
80637 const char *p, *q;
80638
80639 for (; m < end; m++) {
80640 @@ -406,7 +406,7 @@ static void print_deps(void)
80641 static void traps(void)
80642 {
80643 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
80644 - int *p = (int *)test;
80645 + unsigned int *p = (unsigned int *)test;
80646
80647 if (*p != INT_CONF) {
80648 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
80649 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
80650 new file mode 100644
80651 index 0000000..008ac1a
80652 --- /dev/null
80653 +++ b/scripts/gcc-plugin.sh
80654 @@ -0,0 +1,17 @@
80655 +#!/bin/bash
80656 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
80657 +#include "gcc-plugin.h"
80658 +#include "tree.h"
80659 +#include "tm.h"
80660 +#include "rtl.h"
80661 +#ifdef ENABLE_BUILD_WITH_CXX
80662 +#warning $2
80663 +#else
80664 +#warning $1
80665 +#endif
80666 +EOF`
80667 +if [ $? -eq 0 ]
80668 +then
80669 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
80670 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
80671 +fi
80672 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
80673 index b3d907e..a4782ab 100644
80674 --- a/scripts/link-vmlinux.sh
80675 +++ b/scripts/link-vmlinux.sh
80676 @@ -152,7 +152,7 @@ else
80677 fi;
80678
80679 # final build of init/
80680 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
80681 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
80682
80683 kallsymso=""
80684 kallsyms_vmlinux=""
80685 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
80686 index 7ed6864..b6e90e6 100644
80687 --- a/scripts/mod/file2alias.c
80688 +++ b/scripts/mod/file2alias.c
80689 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
80690 unsigned long size, unsigned long id_size,
80691 void *symval)
80692 {
80693 - int i;
80694 + unsigned int i;
80695
80696 if (size % id_size || size < id_size) {
80697 if (cross_build != 0)
80698 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
80699 /* USB is special because the bcdDevice can be matched against a numeric range */
80700 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
80701 static void do_usb_entry(struct usb_device_id *id,
80702 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
80703 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
80704 unsigned char range_lo, unsigned char range_hi,
80705 unsigned char max, struct module *mod)
80706 {
80707 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
80708 {
80709 unsigned int devlo, devhi;
80710 unsigned char chi, clo, max;
80711 - int ndigits;
80712 + unsigned int ndigits;
80713
80714 id->match_flags = TO_NATIVE(id->match_flags);
80715 id->idVendor = TO_NATIVE(id->idVendor);
80716 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
80717 for (i = 0; i < count; i++) {
80718 const char *id = (char *)devs[i].id;
80719 char acpi_id[sizeof(devs[0].id)];
80720 - int j;
80721 + unsigned int j;
80722
80723 buf_printf(&mod->dev_table_buf,
80724 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80725 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80726
80727 for (j = 0; j < PNP_MAX_DEVICES; j++) {
80728 const char *id = (char *)card->devs[j].id;
80729 - int i2, j2;
80730 + unsigned int i2, j2;
80731 int dup = 0;
80732
80733 if (!id[0])
80734 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80735 /* add an individual alias for every device entry */
80736 if (!dup) {
80737 char acpi_id[sizeof(card->devs[0].id)];
80738 - int k;
80739 + unsigned int k;
80740
80741 buf_printf(&mod->dev_table_buf,
80742 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80743 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
80744 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
80745 char *alias)
80746 {
80747 - int i, j;
80748 + unsigned int i, j;
80749
80750 sprintf(alias, "dmi*");
80751
80752 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
80753 index 68e9f5e..ac7759b 100644
80754 --- a/scripts/mod/modpost.c
80755 +++ b/scripts/mod/modpost.c
80756 @@ -930,6 +930,7 @@ enum mismatch {
80757 ANY_INIT_TO_ANY_EXIT,
80758 ANY_EXIT_TO_ANY_INIT,
80759 EXPORT_TO_INIT_EXIT,
80760 + DATA_TO_TEXT
80761 };
80762
80763 struct sectioncheck {
80764 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
80765 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
80766 .mismatch = EXPORT_TO_INIT_EXIT,
80767 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80768 +},
80769 +/* Do not reference code from writable data */
80770 +{
80771 + .fromsec = { DATA_SECTIONS, NULL },
80772 + .tosec = { TEXT_SECTIONS, NULL },
80773 + .mismatch = DATA_TO_TEXT
80774 }
80775 };
80776
80777 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80778 continue;
80779 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80780 continue;
80781 - if (sym->st_value == addr)
80782 - return sym;
80783 /* Find a symbol nearby - addr are maybe negative */
80784 d = sym->st_value - addr;
80785 + if (d == 0)
80786 + return sym;
80787 if (d < 0)
80788 d = addr - sym->st_value;
80789 if (d < distance) {
80790 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
80791 tosym, prl_to, prl_to, tosym);
80792 free(prl_to);
80793 break;
80794 + case DATA_TO_TEXT:
80795 +#if 0
80796 + fprintf(stderr,
80797 + "The %s %s:%s references\n"
80798 + "the %s %s:%s%s\n",
80799 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80800 +#endif
80801 + break;
80802 }
80803 fprintf(stderr, "\n");
80804 }
80805 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80806 static void check_sec_ref(struct module *mod, const char *modname,
80807 struct elf_info *elf)
80808 {
80809 - int i;
80810 + unsigned int i;
80811 Elf_Shdr *sechdrs = elf->sechdrs;
80812
80813 /* Walk through all sections */
80814 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80815 va_end(ap);
80816 }
80817
80818 -void buf_write(struct buffer *buf, const char *s, int len)
80819 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80820 {
80821 if (buf->size - buf->pos < len) {
80822 buf->size += len + SZ;
80823 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80824 if (fstat(fileno(file), &st) < 0)
80825 goto close_write;
80826
80827 - if (st.st_size != b->pos)
80828 + if (st.st_size != (off_t)b->pos)
80829 goto close_write;
80830
80831 tmp = NOFAIL(malloc(b->pos));
80832 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80833 index 51207e4..f7d603d 100644
80834 --- a/scripts/mod/modpost.h
80835 +++ b/scripts/mod/modpost.h
80836 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80837
80838 struct buffer {
80839 char *p;
80840 - int pos;
80841 - int size;
80842 + unsigned int pos;
80843 + unsigned int size;
80844 };
80845
80846 void __attribute__((format(printf, 2, 3)))
80847 buf_printf(struct buffer *buf, const char *fmt, ...);
80848
80849 void
80850 -buf_write(struct buffer *buf, const char *s, int len);
80851 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80852
80853 struct module {
80854 struct module *next;
80855 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80856 index 9dfcd6d..099068e 100644
80857 --- a/scripts/mod/sumversion.c
80858 +++ b/scripts/mod/sumversion.c
80859 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80860 goto out;
80861 }
80862
80863 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80864 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80865 warn("writing sum in %s failed: %s\n",
80866 filename, strerror(errno));
80867 goto out;
80868 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80869 index 5c11312..72742b5 100644
80870 --- a/scripts/pnmtologo.c
80871 +++ b/scripts/pnmtologo.c
80872 @@ -237,14 +237,14 @@ static void write_header(void)
80873 fprintf(out, " * Linux logo %s\n", logoname);
80874 fputs(" */\n\n", out);
80875 fputs("#include <linux/linux_logo.h>\n\n", out);
80876 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80877 + fprintf(out, "static unsigned char %s_data[] = {\n",
80878 logoname);
80879 }
80880
80881 static void write_footer(void)
80882 {
80883 fputs("\n};\n\n", out);
80884 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80885 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80886 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80887 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80888 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80889 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80890 fputs("\n};\n\n", out);
80891
80892 /* write logo clut */
80893 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80894 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80895 logoname);
80896 write_hex_cnt = 0;
80897 for (i = 0; i < logo_clutsize; i++) {
80898 diff --git a/security/Kconfig b/security/Kconfig
80899 index e9c6ac7..e7feb0d 100644
80900 --- a/security/Kconfig
80901 +++ b/security/Kconfig
80902 @@ -4,6 +4,896 @@
80903
80904 menu "Security options"
80905
80906 +menu "Grsecurity"
80907 +
80908 + config ARCH_TRACK_EXEC_LIMIT
80909 + bool
80910 +
80911 + config PAX_KERNEXEC_PLUGIN
80912 + bool
80913 +
80914 + config PAX_PER_CPU_PGD
80915 + bool
80916 +
80917 + config TASK_SIZE_MAX_SHIFT
80918 + int
80919 + depends on X86_64
80920 + default 47 if !PAX_PER_CPU_PGD
80921 + default 42 if PAX_PER_CPU_PGD
80922 +
80923 + config PAX_ENABLE_PAE
80924 + bool
80925 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80926 +
80927 + config PAX_USERCOPY_SLABS
80928 + bool
80929 +
80930 +config GRKERNSEC
80931 + bool "Grsecurity"
80932 + select CRYPTO
80933 + select CRYPTO_SHA256
80934 + select PROC_FS
80935 + select STOP_MACHINE
80936 + help
80937 + If you say Y here, you will be able to configure many features
80938 + that will enhance the security of your system. It is highly
80939 + recommended that you say Y here and read through the help
80940 + for each option so that you fully understand the features and
80941 + can evaluate their usefulness for your machine.
80942 +
80943 +choice
80944 + prompt "Configuration Method"
80945 + depends on GRKERNSEC
80946 + default GRKERNSEC_CONFIG_CUSTOM
80947 + help
80948 +
80949 +config GRKERNSEC_CONFIG_AUTO
80950 + bool "Automatic"
80951 + help
80952 + If you choose this configuration method, you'll be able to answer a small
80953 + number of simple questions about how you plan to use this kernel.
80954 + The settings of grsecurity and PaX will be automatically configured for
80955 + the highest commonly-used settings within the provided constraints.
80956 +
80957 + If you require additional configuration, custom changes can still be made
80958 + from the "custom configuration" menu.
80959 +
80960 +config GRKERNSEC_CONFIG_CUSTOM
80961 + bool "Custom"
80962 + help
80963 + If you choose this configuration method, you'll be able to configure all
80964 + grsecurity and PaX settings manually. Via this method, no options are
80965 + automatically enabled.
80966 +
80967 +endchoice
80968 +
80969 +choice
80970 + prompt "Usage Type"
80971 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80972 + default GRKERNSEC_CONFIG_SERVER
80973 + help
80974 +
80975 +config GRKERNSEC_CONFIG_SERVER
80976 + bool "Server"
80977 + help
80978 + Choose this option if you plan to use this kernel on a server.
80979 +
80980 +config GRKERNSEC_CONFIG_DESKTOP
80981 + bool "Desktop"
80982 + help
80983 + Choose this option if you plan to use this kernel on a desktop.
80984 +
80985 +endchoice
80986 +
80987 +choice
80988 + prompt "Virtualization Type"
80989 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80990 + default GRKERNSEC_CONFIG_VIRT_NONE
80991 + help
80992 +
80993 +config GRKERNSEC_CONFIG_VIRT_NONE
80994 + bool "None"
80995 + help
80996 + Choose this option if this kernel will be run on bare metal.
80997 +
80998 +config GRKERNSEC_CONFIG_VIRT_GUEST
80999 + bool "Guest"
81000 + help
81001 + Choose this option if this kernel will be run as a VM guest.
81002 +
81003 +config GRKERNSEC_CONFIG_VIRT_HOST
81004 + bool "Host"
81005 + help
81006 + Choose this option if this kernel will be run as a VM host.
81007 +
81008 +endchoice
81009 +
81010 +choice
81011 + prompt "Virtualization Hardware"
81012 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
81013 + help
81014 +
81015 +config GRKERNSEC_CONFIG_VIRT_EPT
81016 + bool "EPT/RVI Processor Support"
81017 + depends on X86
81018 + help
81019 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
81020 + hardware virtualization. This allows for additional kernel hardening protections
81021 + to operate without additional performance impact.
81022 +
81023 + To see if your Intel processor supports EPT, see:
81024 + http://ark.intel.com/Products/VirtualizationTechnology
81025 + (Most Core i3/5/7 support EPT)
81026 +
81027 + To see if your AMD processor supports RVI, see:
81028 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
81029 +
81030 +config GRKERNSEC_CONFIG_VIRT_SOFT
81031 + bool "First-gen/No Hardware Virtualization"
81032 + help
81033 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
81034 + support hardware virtualization or doesn't support the EPT/RVI extensions.
81035 +
81036 +endchoice
81037 +
81038 +choice
81039 + prompt "Virtualization Software"
81040 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
81041 + help
81042 +
81043 +config GRKERNSEC_CONFIG_VIRT_XEN
81044 + bool "Xen"
81045 + help
81046 + Choose this option if this kernel is running as a Xen guest or host.
81047 +
81048 +config GRKERNSEC_CONFIG_VIRT_VMWARE
81049 + bool "VMWare"
81050 + help
81051 + Choose this option if this kernel is running as a VMWare guest or host.
81052 +
81053 +config GRKERNSEC_CONFIG_VIRT_KVM
81054 + bool "KVM"
81055 + help
81056 + Choose this option if this kernel is running as a KVM guest or host.
81057 +
81058 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
81059 + bool "VirtualBox"
81060 + help
81061 + Choose this option if this kernel is running as a VirtualBox guest or host.
81062 +
81063 +endchoice
81064 +
81065 +choice
81066 + prompt "Required Priorities"
81067 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
81068 + default GRKERNSEC_CONFIG_PRIORITY_PERF
81069 + help
81070 +
81071 +config GRKERNSEC_CONFIG_PRIORITY_PERF
81072 + bool "Performance"
81073 + help
81074 + Choose this option if performance is of highest priority for this deployment
81075 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
81076 + and freed memory sanitizing will be disabled.
81077 +
81078 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
81079 + bool "Security"
81080 + help
81081 + Choose this option if security is of highest priority for this deployment of
81082 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
81083 + be enabled for this kernel. In a worst-case scenario, these features can
81084 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
81085 +
81086 +endchoice
81087 +
81088 +menu "Default Special Groups"
81089 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
81090 +
81091 +config GRKERNSEC_PROC_GID
81092 + int "GID exempted from /proc restrictions"
81093 + default 1001
81094 + help
81095 + Setting this GID determines which group will be exempted from
81096 + grsecurity's /proc restrictions, allowing users of the specified
81097 + group to view network statistics and the existence of other users'
81098 + processes on the system. This GID may also be chosen at boot time
81099 + via "grsec_proc_gid=" on the kernel commandline.
81100 +
81101 +config GRKERNSEC_TPE_UNTRUSTED_GID
81102 + int "GID for TPE-untrusted users"
81103 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
81104 + default 1005
81105 + help
81106 + Setting this GID determines which group untrusted users should
81107 + be added to. These users will be placed under grsecurity's Trusted Path
81108 + Execution mechanism, preventing them from executing their own binaries.
81109 + The users will only be able to execute binaries in directories owned and
81110 + writable only by the root user. If the sysctl option is enabled, a sysctl
81111 + option with name "tpe_gid" is created.
81112 +
81113 +config GRKERNSEC_TPE_TRUSTED_GID
81114 + int "GID for TPE-trusted users"
81115 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
81116 + default 1005
81117 + help
81118 + Setting this GID determines what group TPE restrictions will be
81119 + *disabled* for. If the sysctl option is enabled, a sysctl option
81120 + with name "tpe_gid" is created.
81121 +
81122 +config GRKERNSEC_SYMLINKOWN_GID
81123 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
81124 + depends on GRKERNSEC_CONFIG_SERVER
81125 + default 1006
81126 + help
81127 + Setting this GID determines what group kernel-enforced
81128 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
81129 + is enabled, a sysctl option with name "symlinkown_gid" is created.
81130 +
81131 +
81132 +endmenu
81133 +
81134 +menu "Customize Configuration"
81135 +depends on GRKERNSEC
81136 +
81137 +menu "PaX"
81138 +
81139 +config PAX
81140 + bool "Enable various PaX features"
81141 + default y if GRKERNSEC_CONFIG_AUTO
81142 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
81143 + help
81144 + This allows you to enable various PaX features. PaX adds
81145 + intrusion prevention mechanisms to the kernel that reduce
81146 + the risks posed by exploitable memory corruption bugs.
81147 +
81148 +menu "PaX Control"
81149 + depends on PAX
81150 +
81151 +config PAX_SOFTMODE
81152 + bool 'Support soft mode'
81153 + help
81154 + Enabling this option will allow you to run PaX in soft mode, that
81155 + is, PaX features will not be enforced by default, only on executables
81156 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
81157 + support as they are the only way to mark executables for soft mode use.
81158 +
81159 + Soft mode can be activated by using the "pax_softmode=1" kernel command
81160 + line option on boot. Furthermore you can control various PaX features
81161 + at runtime via the entries in /proc/sys/kernel/pax.
81162 +
81163 +config PAX_EI_PAX
81164 + bool 'Use legacy ELF header marking'
81165 + default y if GRKERNSEC_CONFIG_AUTO
81166 + help
81167 + Enabling this option will allow you to control PaX features on
81168 + a per executable basis via the 'chpax' utility available at
81169 + http://pax.grsecurity.net/. The control flags will be read from
81170 + an otherwise reserved part of the ELF header. This marking has
81171 + numerous drawbacks (no support for soft-mode, toolchain does not
81172 + know about the non-standard use of the ELF header) therefore it
81173 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
81174 + support.
81175 +
81176 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
81177 + support as well, they will override the legacy EI_PAX marks.
81178 +
81179 + If you enable none of the marking options then all applications
81180 + will run with PaX enabled on them by default.
81181 +
81182 +config PAX_PT_PAX_FLAGS
81183 + bool 'Use ELF program header marking'
81184 + default y if GRKERNSEC_CONFIG_AUTO
81185 + help
81186 + Enabling this option will allow you to control PaX features on
81187 + a per executable basis via the 'paxctl' utility available at
81188 + http://pax.grsecurity.net/. The control flags will be read from
81189 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
81190 + has the benefits of supporting both soft mode and being fully
81191 + integrated into the toolchain (the binutils patch is available
81192 + from http://pax.grsecurity.net).
81193 +
81194 + Note that if you enable the legacy EI_PAX marking support as well,
81195 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
81196 +
81197 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
81198 + must make sure that the marks are the same if a binary has both marks.
81199 +
81200 + If you enable none of the marking options then all applications
81201 + will run with PaX enabled on them by default.
81202 +
81203 +config PAX_XATTR_PAX_FLAGS
81204 + bool 'Use filesystem extended attributes marking'
81205 + default y if GRKERNSEC_CONFIG_AUTO
81206 + select CIFS_XATTR if CIFS
81207 + select EXT2_FS_XATTR if EXT2_FS
81208 + select EXT3_FS_XATTR if EXT3_FS
81209 + select EXT4_FS_XATTR if EXT4_FS
81210 + select JFFS2_FS_XATTR if JFFS2_FS
81211 + select REISERFS_FS_XATTR if REISERFS_FS
81212 + select SQUASHFS_XATTR if SQUASHFS
81213 + select TMPFS_XATTR if TMPFS
81214 + select UBIFS_FS_XATTR if UBIFS_FS
81215 + help
81216 + Enabling this option will allow you to control PaX features on
81217 + a per executable basis via the 'setfattr' utility. The control
81218 + flags will be read from the user.pax.flags extended attribute of
81219 + the file. This marking has the benefit of supporting binary-only
81220 + applications that self-check themselves (e.g., skype) and would
81221 + not tolerate chpax/paxctl changes. The main drawback is that
81222 + extended attributes are not supported by some filesystems (e.g.,
81223 + isofs, udf, vfat) so copying files through such filesystems will
81224 + lose the extended attributes and these PaX markings.
81225 +
81226 + Note that if you enable the legacy EI_PAX marking support as well,
81227 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
81228 +
81229 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
81230 + must make sure that the marks are the same if a binary has both marks.
81231 +
81232 + If you enable none of the marking options then all applications
81233 + will run with PaX enabled on them by default.
81234 +
81235 +choice
81236 + prompt 'MAC system integration'
81237 + default PAX_HAVE_ACL_FLAGS
81238 + help
81239 + Mandatory Access Control systems have the option of controlling
81240 + PaX flags on a per executable basis, choose the method supported
81241 + by your particular system.
81242 +
81243 + - "none": if your MAC system does not interact with PaX,
81244 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
81245 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
81246 +
81247 + NOTE: this option is for developers/integrators only.
81248 +
81249 + config PAX_NO_ACL_FLAGS
81250 + bool 'none'
81251 +
81252 + config PAX_HAVE_ACL_FLAGS
81253 + bool 'direct'
81254 +
81255 + config PAX_HOOK_ACL_FLAGS
81256 + bool 'hook'
81257 +endchoice
81258 +
81259 +endmenu
81260 +
81261 +menu "Non-executable pages"
81262 + depends on PAX
81263 +
81264 +config PAX_NOEXEC
81265 + bool "Enforce non-executable pages"
81266 + default y if GRKERNSEC_CONFIG_AUTO
81267 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
81268 + help
81269 + By design some architectures do not allow for protecting memory
81270 + pages against execution or even if they do, Linux does not make
81271 + use of this feature. In practice this means that if a page is
81272 + readable (such as the stack or heap) it is also executable.
81273 +
81274 + There is a well known exploit technique that makes use of this
81275 + fact and a common programming mistake where an attacker can
81276 + introduce code of his choice somewhere in the attacked program's
81277 + memory (typically the stack or the heap) and then execute it.
81278 +
81279 + If the attacked program was running with different (typically
81280 + higher) privileges than that of the attacker, then he can elevate
81281 + his own privilege level (e.g. get a root shell, write to files for
81282 + which he does not have write access to, etc).
81283 +
81284 + Enabling this option will let you choose from various features
81285 + that prevent the injection and execution of 'foreign' code in
81286 + a program.
81287 +
81288 + This will also break programs that rely on the old behaviour and
81289 + expect that dynamically allocated memory via the malloc() family
81290 + of functions is executable (which it is not). Notable examples
81291 + are the XFree86 4.x server, the java runtime and wine.
81292 +
81293 +config PAX_PAGEEXEC
81294 + bool "Paging based non-executable pages"
81295 + default y if GRKERNSEC_CONFIG_AUTO
81296 + 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)
81297 + select S390_SWITCH_AMODE if S390
81298 + select S390_EXEC_PROTECT if S390
81299 + select ARCH_TRACK_EXEC_LIMIT if X86_32
81300 + help
81301 + This implementation is based on the paging feature of the CPU.
81302 + On i386 without hardware non-executable bit support there is a
81303 + variable but usually low performance impact, however on Intel's
81304 + P4 core based CPUs it is very high so you should not enable this
81305 + for kernels meant to be used on such CPUs.
81306 +
81307 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
81308 + with hardware non-executable bit support there is no performance
81309 + impact, on ppc the impact is negligible.
81310 +
81311 + Note that several architectures require various emulations due to
81312 + badly designed userland ABIs, this will cause a performance impact
81313 + but will disappear as soon as userland is fixed. For example, ppc
81314 + userland MUST have been built with secure-plt by a recent toolchain.
81315 +
81316 +config PAX_SEGMEXEC
81317 + bool "Segmentation based non-executable pages"
81318 + default y if GRKERNSEC_CONFIG_AUTO
81319 + depends on PAX_NOEXEC && X86_32
81320 + help
81321 + This implementation is based on the segmentation feature of the
81322 + CPU and has a very small performance impact, however applications
81323 + will be limited to a 1.5 GB address space instead of the normal
81324 + 3 GB.
81325 +
81326 +config PAX_EMUTRAMP
81327 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
81328 + default y if PARISC
81329 + help
81330 + There are some programs and libraries that for one reason or
81331 + another attempt to execute special small code snippets from
81332 + non-executable memory pages. Most notable examples are the
81333 + signal handler return code generated by the kernel itself and
81334 + the GCC trampolines.
81335 +
81336 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
81337 + such programs will no longer work under your kernel.
81338 +
81339 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
81340 + utilities to enable trampoline emulation for the affected programs
81341 + yet still have the protection provided by the non-executable pages.
81342 +
81343 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
81344 + your system will not even boot.
81345 +
81346 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
81347 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
81348 + for the affected files.
81349 +
81350 + NOTE: enabling this feature *may* open up a loophole in the
81351 + protection provided by non-executable pages that an attacker
81352 + could abuse. Therefore the best solution is to not have any
81353 + files on your system that would require this option. This can
81354 + be achieved by not using libc5 (which relies on the kernel
81355 + signal handler return code) and not using or rewriting programs
81356 + that make use of the nested function implementation of GCC.
81357 + Skilled users can just fix GCC itself so that it implements
81358 + nested function calls in a way that does not interfere with PaX.
81359 +
81360 +config PAX_EMUSIGRT
81361 + bool "Automatically emulate sigreturn trampolines"
81362 + depends on PAX_EMUTRAMP && PARISC
81363 + default y
81364 + help
81365 + Enabling this option will have the kernel automatically detect
81366 + and emulate signal return trampolines executing on the stack
81367 + that would otherwise lead to task termination.
81368 +
81369 + This solution is intended as a temporary one for users with
81370 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
81371 + Modula-3 runtime, etc) or executables linked to such, basically
81372 + everything that does not specify its own SA_RESTORER function in
81373 + normal executable memory like glibc 2.1+ does.
81374 +
81375 + On parisc you MUST enable this option, otherwise your system will
81376 + not even boot.
81377 +
81378 + NOTE: this feature cannot be disabled on a per executable basis
81379 + and since it *does* open up a loophole in the protection provided
81380 + by non-executable pages, the best solution is to not have any
81381 + files on your system that would require this option.
81382 +
81383 +config PAX_MPROTECT
81384 + bool "Restrict mprotect()"
81385 + default y if GRKERNSEC_CONFIG_AUTO
81386 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
81387 + help
81388 + Enabling this option will prevent programs from
81389 + - changing the executable status of memory pages that were
81390 + not originally created as executable,
81391 + - making read-only executable pages writable again,
81392 + - creating executable pages from anonymous memory,
81393 + - making read-only-after-relocations (RELRO) data pages writable again.
81394 +
81395 + You should say Y here to complete the protection provided by
81396 + the enforcement of non-executable pages.
81397 +
81398 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81399 + this feature on a per file basis.
81400 +
81401 +config PAX_MPROTECT_COMPAT
81402 + bool "Use legacy/compat protection demoting (read help)"
81403 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81404 + depends on PAX_MPROTECT
81405 + help
81406 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
81407 + by sending the proper error code to the application. For some broken
81408 + userland, this can cause problems with Python or other applications. The
81409 + current implementation however allows for applications like clamav to
81410 + detect if JIT compilation/execution is allowed and to fall back gracefully
81411 + to an interpreter-based mode if it does not. While we encourage everyone
81412 + to use the current implementation as-is and push upstream to fix broken
81413 + userland (note that the RWX logging option can assist with this), in some
81414 + environments this may not be possible. Having to disable MPROTECT
81415 + completely on certain binaries reduces the security benefit of PaX,
81416 + so this option is provided for those environments to revert to the old
81417 + behavior.
81418 +
81419 +config PAX_ELFRELOCS
81420 + bool "Allow ELF text relocations (read help)"
81421 + depends on PAX_MPROTECT
81422 + default n
81423 + help
81424 + Non-executable pages and mprotect() restrictions are effective
81425 + in preventing the introduction of new executable code into an
81426 + attacked task's address space. There remain only two venues
81427 + for this kind of attack: if the attacker can execute already
81428 + existing code in the attacked task then he can either have it
81429 + create and mmap() a file containing his code or have it mmap()
81430 + an already existing ELF library that does not have position
81431 + independent code in it and use mprotect() on it to make it
81432 + writable and copy his code there. While protecting against
81433 + the former approach is beyond PaX, the latter can be prevented
81434 + by having only PIC ELF libraries on one's system (which do not
81435 + need to relocate their code). If you are sure this is your case,
81436 + as is the case with all modern Linux distributions, then leave
81437 + this option disabled. You should say 'n' here.
81438 +
81439 +config PAX_ETEXECRELOCS
81440 + bool "Allow ELF ET_EXEC text relocations"
81441 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
81442 + select PAX_ELFRELOCS
81443 + default y
81444 + help
81445 + On some architectures there are incorrectly created applications
81446 + that require text relocations and would not work without enabling
81447 + this option. If you are an alpha, ia64 or parisc user, you should
81448 + enable this option and disable it once you have made sure that
81449 + none of your applications need it.
81450 +
81451 +config PAX_EMUPLT
81452 + bool "Automatically emulate ELF PLT"
81453 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
81454 + default y
81455 + help
81456 + Enabling this option will have the kernel automatically detect
81457 + and emulate the Procedure Linkage Table entries in ELF files.
81458 + On some architectures such entries are in writable memory, and
81459 + become non-executable leading to task termination. Therefore
81460 + it is mandatory that you enable this option on alpha, parisc,
81461 + sparc and sparc64, otherwise your system would not even boot.
81462 +
81463 + NOTE: this feature *does* open up a loophole in the protection
81464 + provided by the non-executable pages, therefore the proper
81465 + solution is to modify the toolchain to produce a PLT that does
81466 + not need to be writable.
81467 +
81468 +config PAX_DLRESOLVE
81469 + bool 'Emulate old glibc resolver stub'
81470 + depends on PAX_EMUPLT && SPARC
81471 + default n
81472 + help
81473 + This option is needed if userland has an old glibc (before 2.4)
81474 + that puts a 'save' instruction into the runtime generated resolver
81475 + stub that needs special emulation.
81476 +
81477 +config PAX_KERNEXEC
81478 + bool "Enforce non-executable kernel pages"
81479 + 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))
81480 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
81481 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
81482 + select PAX_KERNEXEC_PLUGIN if X86_64
81483 + help
81484 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
81485 + that is, enabling this option will make it harder to inject
81486 + and execute 'foreign' code in kernel memory itself.
81487 +
81488 +choice
81489 + prompt "Return Address Instrumentation Method"
81490 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
81491 + depends on PAX_KERNEXEC_PLUGIN
81492 + help
81493 + Select the method used to instrument function pointer dereferences.
81494 + Note that binary modules cannot be instrumented by this approach.
81495 +
81496 + Note that the implementation requires a gcc with plugin support,
81497 + i.e., gcc 4.5 or newer. You may need to install the supporting
81498 + headers explicitly in addition to the normal gcc package.
81499 +
81500 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
81501 + bool "bts"
81502 + help
81503 + This method is compatible with binary only modules but has
81504 + a higher runtime overhead.
81505 +
81506 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
81507 + bool "or"
81508 + depends on !PARAVIRT
81509 + help
81510 + This method is incompatible with binary only modules but has
81511 + a lower runtime overhead.
81512 +endchoice
81513 +
81514 +config PAX_KERNEXEC_PLUGIN_METHOD
81515 + string
81516 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
81517 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
81518 + default ""
81519 +
81520 +config PAX_KERNEXEC_MODULE_TEXT
81521 + int "Minimum amount of memory reserved for module code"
81522 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
81523 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81524 + depends on PAX_KERNEXEC && X86_32 && MODULES
81525 + help
81526 + Due to implementation details the kernel must reserve a fixed
81527 + amount of memory for module code at compile time that cannot be
81528 + changed at runtime. Here you can specify the minimum amount
81529 + in MB that will be reserved. Due to the same implementation
81530 + details this size will always be rounded up to the next 2/4 MB
81531 + boundary (depends on PAE) so the actually available memory for
81532 + module code will usually be more than this minimum.
81533 +
81534 + The default 4 MB should be enough for most users but if you have
81535 + an excessive number of modules (e.g., most distribution configs
81536 + compile many drivers as modules) or use huge modules such as
81537 + nvidia's kernel driver, you will need to adjust this amount.
81538 + A good rule of thumb is to look at your currently loaded kernel
81539 + modules and add up their sizes.
81540 +
81541 +endmenu
81542 +
81543 +menu "Address Space Layout Randomization"
81544 + depends on PAX
81545 +
81546 +config PAX_ASLR
81547 + bool "Address Space Layout Randomization"
81548 + default y if GRKERNSEC_CONFIG_AUTO
81549 + help
81550 + Many if not most exploit techniques rely on the knowledge of
81551 + certain addresses in the attacked program. The following options
81552 + will allow the kernel to apply a certain amount of randomization
81553 + to specific parts of the program thereby forcing an attacker to
81554 + guess them in most cases. Any failed guess will most likely crash
81555 + the attacked program which allows the kernel to detect such attempts
81556 + and react on them. PaX itself provides no reaction mechanisms,
81557 + instead it is strongly encouraged that you make use of Nergal's
81558 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
81559 + (http://www.grsecurity.net/) built-in crash detection features or
81560 + develop one yourself.
81561 +
81562 + By saying Y here you can choose to randomize the following areas:
81563 + - top of the task's kernel stack
81564 + - top of the task's userland stack
81565 + - base address for mmap() requests that do not specify one
81566 + (this includes all libraries)
81567 + - base address of the main executable
81568 +
81569 + It is strongly recommended to say Y here as address space layout
81570 + randomization has negligible impact on performance yet it provides
81571 + a very effective protection.
81572 +
81573 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81574 + this feature on a per file basis.
81575 +
81576 +config PAX_RANDKSTACK
81577 + bool "Randomize kernel stack base"
81578 + default y if GRKERNSEC_CONFIG_AUTO
81579 + depends on X86_TSC && X86
81580 + help
81581 + By saying Y here the kernel will randomize every task's kernel
81582 + stack on every system call. This will not only force an attacker
81583 + to guess it but also prevent him from making use of possible
81584 + leaked information about it.
81585 +
81586 + Since the kernel stack is a rather scarce resource, randomization
81587 + may cause unexpected stack overflows, therefore you should very
81588 + carefully test your system. Note that once enabled in the kernel
81589 + configuration, this feature cannot be disabled on a per file basis.
81590 +
81591 +config PAX_RANDUSTACK
81592 + bool "Randomize user stack base"
81593 + default y if GRKERNSEC_CONFIG_AUTO
81594 + depends on PAX_ASLR
81595 + help
81596 + By saying Y here the kernel will randomize every task's userland
81597 + stack. The randomization is done in two steps where the second
81598 + one may apply a big amount of shift to the top of the stack and
81599 + cause problems for programs that want to use lots of memory (more
81600 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
81601 + For this reason the second step can be controlled by 'chpax' or
81602 + 'paxctl' on a per file basis.
81603 +
81604 +config PAX_RANDMMAP
81605 + bool "Randomize mmap() base"
81606 + default y if GRKERNSEC_CONFIG_AUTO
81607 + depends on PAX_ASLR
81608 + help
81609 + By saying Y here the kernel will use a randomized base address for
81610 + mmap() requests that do not specify one themselves. As a result
81611 + all dynamically loaded libraries will appear at random addresses
81612 + and therefore be harder to exploit by a technique where an attacker
81613 + attempts to execute library code for his purposes (e.g. spawn a
81614 + shell from an exploited program that is running at an elevated
81615 + privilege level).
81616 +
81617 + Furthermore, if a program is relinked as a dynamic ELF file, its
81618 + base address will be randomized as well, completing the full
81619 + randomization of the address space layout. Attacking such programs
81620 + becomes a guess game. You can find an example of doing this at
81621 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
81622 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
81623 +
81624 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
81625 + feature on a per file basis.
81626 +
81627 +endmenu
81628 +
81629 +menu "Miscellaneous hardening features"
81630 +
81631 +config PAX_MEMORY_SANITIZE
81632 + bool "Sanitize all freed memory"
81633 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81634 + depends on !HIBERNATION
81635 + help
81636 + By saying Y here the kernel will erase memory pages as soon as they
81637 + are freed. This in turn reduces the lifetime of data stored in the
81638 + pages, making it less likely that sensitive information such as
81639 + passwords, cryptographic secrets, etc stay in memory for too long.
81640 +
81641 + This is especially useful for programs whose runtime is short, long
81642 + lived processes and the kernel itself benefit from this as long as
81643 + they operate on whole memory pages and ensure timely freeing of pages
81644 + that may hold sensitive information.
81645 +
81646 + The tradeoff is performance impact, on a single CPU system kernel
81647 + compilation sees a 3% slowdown, other systems and workloads may vary
81648 + and you are advised to test this feature on your expected workload
81649 + before deploying it.
81650 +
81651 + Note that this feature does not protect data stored in live pages,
81652 + e.g., process memory swapped to disk may stay there for a long time.
81653 +
81654 +config PAX_MEMORY_STACKLEAK
81655 + bool "Sanitize kernel stack"
81656 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81657 + depends on X86
81658 + help
81659 + By saying Y here the kernel will erase the kernel stack before it
81660 + returns from a system call. This in turn reduces the information
81661 + that a kernel stack leak bug can reveal.
81662 +
81663 + Note that such a bug can still leak information that was put on
81664 + the stack by the current system call (the one eventually triggering
81665 + the bug) but traces of earlier system calls on the kernel stack
81666 + cannot leak anymore.
81667 +
81668 + The tradeoff is performance impact: on a single CPU system kernel
81669 + compilation sees a 1% slowdown, other systems and workloads may vary
81670 + and you are advised to test this feature on your expected workload
81671 + before deploying it.
81672 +
81673 + Note that the full feature requires a gcc with plugin support,
81674 + i.e., gcc 4.5 or newer. You may need to install the supporting
81675 + headers explicitly in addition to the normal gcc package. Using
81676 + older gcc versions means that functions with large enough stack
81677 + frames may leave uninitialized memory behind that may be exposed
81678 + to a later syscall leaking the stack.
81679 +
81680 +config PAX_MEMORY_UDEREF
81681 + bool "Prevent invalid userland pointer dereference"
81682 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
81683 + depends on X86 && !UML_X86 && !XEN
81684 + select PAX_PER_CPU_PGD if X86_64
81685 + help
81686 + By saying Y here the kernel will be prevented from dereferencing
81687 + userland pointers in contexts where the kernel expects only kernel
81688 + pointers. This is both a useful runtime debugging feature and a
81689 + security measure that prevents exploiting a class of kernel bugs.
81690 +
81691 + The tradeoff is that some virtualization solutions may experience
81692 + a huge slowdown and therefore you should not enable this feature
81693 + for kernels meant to run in such environments. Whether a given VM
81694 + solution is affected or not is best determined by simply trying it
81695 + out, the performance impact will be obvious right on boot as this
81696 + mechanism engages from very early on. A good rule of thumb is that
81697 + VMs running on CPUs without hardware virtualization support (i.e.,
81698 + the majority of IA-32 CPUs) will likely experience the slowdown.
81699 +
81700 +config PAX_REFCOUNT
81701 + bool "Prevent various kernel object reference counter overflows"
81702 + default y if GRKERNSEC_CONFIG_AUTO
81703 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
81704 + help
81705 + By saying Y here the kernel will detect and prevent overflowing
81706 + various (but not all) kinds of object reference counters. Such
81707 + overflows can normally occur due to bugs only and are often, if
81708 + not always, exploitable.
81709 +
81710 + The tradeoff is that data structures protected by an overflowed
81711 + refcount will never be freed and therefore will leak memory. Note
81712 + that this leak also happens even without this protection but in
81713 + that case the overflow can eventually trigger the freeing of the
81714 + data structure while it is still being used elsewhere, resulting
81715 + in the exploitable situation that this feature prevents.
81716 +
81717 + Since this has a negligible performance impact, you should enable
81718 + this feature.
81719 +
81720 +config PAX_USERCOPY
81721 + bool "Harden heap object copies between kernel and userland"
81722 + default y if GRKERNSEC_CONFIG_AUTO
81723 + depends on X86 || PPC || SPARC || ARM
81724 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
81725 + select PAX_USERCOPY_SLABS
81726 + help
81727 + By saying Y here the kernel will enforce the size of heap objects
81728 + when they are copied in either direction between the kernel and
81729 + userland, even if only a part of the heap object is copied.
81730 +
81731 + Specifically, this checking prevents information leaking from the
81732 + kernel heap during kernel to userland copies (if the kernel heap
81733 + object is otherwise fully initialized) and prevents kernel heap
81734 + overflows during userland to kernel copies.
81735 +
81736 + Note that the current implementation provides the strictest bounds
81737 + checks for the SLUB allocator.
81738 +
81739 + Enabling this option also enables per-slab cache protection against
81740 + data in a given cache being copied into/out of via userland
81741 + accessors. Though the whitelist of regions will be reduced over
81742 + time, it notably protects important data structures like task structs.
81743 +
81744 + If frame pointers are enabled on x86, this option will also restrict
81745 + copies into and out of the kernel stack to local variables within a
81746 + single frame.
81747 +
81748 + Since this has a negligible performance impact, you should enable
81749 + this feature.
81750 +
81751 +config PAX_SIZE_OVERFLOW
81752 + bool "Prevent various integer overflows in function size parameters"
81753 + default y if GRKERNSEC_CONFIG_AUTO
81754 + depends on X86
81755 + help
81756 + By saying Y here the kernel recomputes expressions of function
81757 + arguments marked by a size_overflow attribute with double integer
81758 + precision (DImode/TImode for 32/64 bit integer types).
81759 +
81760 + The recomputed argument is checked against TYPE_MAX and an event
81761 + is logged on overflow and the triggering process is killed.
81762 +
81763 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
81764 +
81765 + Note that the implementation requires a gcc with plugin support,
81766 + i.e., gcc 4.5 or newer. You may need to install the supporting
81767 + headers explicitly in addition to the normal gcc package.
81768 +
81769 +config PAX_LATENT_ENTROPY
81770 + bool "Generate some entropy during boot"
81771 + default y if GRKERNSEC_CONFIG_AUTO
81772 + help
81773 + By saying Y here the kernel will instrument early boot code to
81774 + extract some entropy from both original and artificially created
81775 + program state. This will help especially embedded systems where
81776 + there is little 'natural' source of entropy normally. The cost
81777 + is some slowdown of the boot process.
81778 +
81779 + Note that the implementation requires a gcc with plugin support,
81780 + i.e., gcc 4.5 or newer. You may need to install the supporting
81781 + headers explicitly in addition to the normal gcc package.
81782 +
81783 + Note that entropy extracted this way is not cryptographically
81784 + secure!
81785 +
81786 +endmenu
81787 +
81788 +endmenu
81789 +
81790 +source grsecurity/Kconfig
81791 +
81792 +endmenu
81793 +
81794 +endmenu
81795 +
81796 source security/keys/Kconfig
81797
81798 config SECURITY_DMESG_RESTRICT
81799 @@ -103,7 +993,7 @@ config INTEL_TXT
81800 config LSM_MMAP_MIN_ADDR
81801 int "Low address space for LSM to protect from user allocation"
81802 depends on SECURITY && SECURITY_SELINUX
81803 - default 32768 if ARM
81804 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81805 default 65536
81806 help
81807 This is the portion of low virtual memory which should be protected
81808 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81809 index 8ea39aa..8569ac5 100644
81810 --- a/security/apparmor/lsm.c
81811 +++ b/security/apparmor/lsm.c
81812 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81813 return error;
81814 }
81815
81816 -static struct security_operations apparmor_ops = {
81817 +static struct security_operations apparmor_ops __read_only = {
81818 .name = "apparmor",
81819
81820 .ptrace_access_check = apparmor_ptrace_access_check,
81821 diff --git a/security/commoncap.c b/security/commoncap.c
81822 index 6dbae46..d5611fd 100644
81823 --- a/security/commoncap.c
81824 +++ b/security/commoncap.c
81825 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81826 return 0;
81827 }
81828
81829 +/* returns:
81830 + 1 for suid privilege
81831 + 2 for sgid privilege
81832 + 3 for fscap privilege
81833 +*/
81834 +int is_privileged_binary(const struct dentry *dentry)
81835 +{
81836 + struct cpu_vfs_cap_data capdata;
81837 + struct inode *inode = dentry->d_inode;
81838 +
81839 + if (!inode || S_ISDIR(inode->i_mode))
81840 + return 0;
81841 +
81842 + if (inode->i_mode & S_ISUID)
81843 + return 1;
81844 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81845 + return 2;
81846 +
81847 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81848 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81849 + return 3;
81850 + }
81851 +
81852 + return 0;
81853 +}
81854 +
81855 /*
81856 * Attempt to get the on-exec apply capability sets for an executable file from
81857 * its xattrs and, if present, apply them to the proposed credentials being
81858 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81859 const struct cred *cred = current_cred();
81860 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81861
81862 + if (gr_acl_enable_at_secure())
81863 + return 1;
81864 +
81865 if (!uid_eq(cred->uid, root_uid)) {
81866 if (bprm->cap_effective)
81867 return 1;
81868 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81869 index e7c99fd..5b2fa24 100644
81870 --- a/security/integrity/ima/ima.h
81871 +++ b/security/integrity/ima/ima.h
81872 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81873 extern spinlock_t ima_queue_lock;
81874
81875 struct ima_h_table {
81876 - atomic_long_t len; /* number of stored measurements in the list */
81877 - atomic_long_t violations;
81878 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81879 + atomic_long_unchecked_t violations;
81880 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81881 };
81882 extern struct ima_h_table ima_htable;
81883 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81884 index 032ff03..c428a74 100644
81885 --- a/security/integrity/ima/ima_api.c
81886 +++ b/security/integrity/ima/ima_api.c
81887 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81888 int result;
81889
81890 /* can overflow, only indicator */
81891 - atomic_long_inc(&ima_htable.violations);
81892 + atomic_long_inc_unchecked(&ima_htable.violations);
81893
81894 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81895 if (!entry) {
81896 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81897 index 38477c9..87a60c7 100644
81898 --- a/security/integrity/ima/ima_fs.c
81899 +++ b/security/integrity/ima/ima_fs.c
81900 @@ -28,12 +28,12 @@
81901 static int valid_policy = 1;
81902 #define TMPBUFLEN 12
81903 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81904 - loff_t *ppos, atomic_long_t *val)
81905 + loff_t *ppos, atomic_long_unchecked_t *val)
81906 {
81907 char tmpbuf[TMPBUFLEN];
81908 ssize_t len;
81909
81910 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81911 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81912 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81913 }
81914
81915 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81916 index 55a6271..ad829c3 100644
81917 --- a/security/integrity/ima/ima_queue.c
81918 +++ b/security/integrity/ima/ima_queue.c
81919 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81920 INIT_LIST_HEAD(&qe->later);
81921 list_add_tail_rcu(&qe->later, &ima_measurements);
81922
81923 - atomic_long_inc(&ima_htable.len);
81924 + atomic_long_inc_unchecked(&ima_htable.len);
81925 key = ima_hash_key(entry->digest);
81926 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81927 return 0;
81928 diff --git a/security/keys/compat.c b/security/keys/compat.c
81929 index 1c26176..64a1ba2 100644
81930 --- a/security/keys/compat.c
81931 +++ b/security/keys/compat.c
81932 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81933 if (ret == 0)
81934 goto no_payload_free;
81935
81936 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81937 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81938
81939 if (iov != iovstack)
81940 kfree(iov);
81941 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81942 index 3364fbf..1f10f31 100644
81943 --- a/security/keys/keyctl.c
81944 +++ b/security/keys/keyctl.c
81945 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81946 /*
81947 * Copy the iovec data from userspace
81948 */
81949 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81950 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81951 unsigned ioc)
81952 {
81953 for (; ioc > 0; ioc--) {
81954 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81955 * If successful, 0 will be returned.
81956 */
81957 long keyctl_instantiate_key_common(key_serial_t id,
81958 - const struct iovec *payload_iov,
81959 + const struct iovec __user *payload_iov,
81960 unsigned ioc,
81961 size_t plen,
81962 key_serial_t ringid)
81963 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
81964 [0].iov_len = plen
81965 };
81966
81967 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81968 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81969 }
81970
81971 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81972 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81973 if (ret == 0)
81974 goto no_payload_free;
81975
81976 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81977 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81978
81979 if (iov != iovstack)
81980 kfree(iov);
81981 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81982 index 81e7852..2b2ecc3 100644
81983 --- a/security/keys/keyring.c
81984 +++ b/security/keys/keyring.c
81985 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81986 ret = -EFAULT;
81987
81988 for (loop = 0; loop < klist->nkeys; loop++) {
81989 + key_serial_t serial;
81990 key = rcu_deref_link_locked(klist, loop,
81991 keyring);
81992 + serial = key->serial;
81993
81994 tmp = sizeof(key_serial_t);
81995 if (tmp > buflen)
81996 tmp = buflen;
81997
81998 - if (copy_to_user(buffer,
81999 - &key->serial,
82000 - tmp) != 0)
82001 + if (copy_to_user(buffer, &serial, tmp))
82002 goto error;
82003
82004 buflen -= tmp;
82005 diff --git a/security/min_addr.c b/security/min_addr.c
82006 index f728728..6457a0c 100644
82007 --- a/security/min_addr.c
82008 +++ b/security/min_addr.c
82009 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
82010 */
82011 static void update_mmap_min_addr(void)
82012 {
82013 +#ifndef SPARC
82014 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
82015 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
82016 mmap_min_addr = dac_mmap_min_addr;
82017 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
82018 #else
82019 mmap_min_addr = dac_mmap_min_addr;
82020 #endif
82021 +#endif
82022 }
82023
82024 /*
82025 diff --git a/security/security.c b/security/security.c
82026 index 860aeb3..45765c0 100644
82027 --- a/security/security.c
82028 +++ b/security/security.c
82029 @@ -20,6 +20,7 @@
82030 #include <linux/ima.h>
82031 #include <linux/evm.h>
82032 #include <linux/fsnotify.h>
82033 +#include <linux/mm.h>
82034 #include <linux/mman.h>
82035 #include <linux/mount.h>
82036 #include <linux/personality.h>
82037 @@ -32,8 +33,8 @@
82038 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
82039 CONFIG_DEFAULT_SECURITY;
82040
82041 -static struct security_operations *security_ops;
82042 -static struct security_operations default_security_ops = {
82043 +static struct security_operations *security_ops __read_only;
82044 +static struct security_operations default_security_ops __read_only = {
82045 .name = "default",
82046 };
82047
82048 @@ -74,7 +75,9 @@ int __init security_init(void)
82049
82050 void reset_security_ops(void)
82051 {
82052 + pax_open_kernel();
82053 security_ops = &default_security_ops;
82054 + pax_close_kernel();
82055 }
82056
82057 /* Save user chosen LSM */
82058 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
82059 index 6c77f63..7496c76 100644
82060 --- a/security/selinux/hooks.c
82061 +++ b/security/selinux/hooks.c
82062 @@ -95,8 +95,6 @@
82063
82064 #define NUM_SEL_MNT_OPTS 5
82065
82066 -extern struct security_operations *security_ops;
82067 -
82068 /* SECMARK reference count */
82069 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
82070
82071 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
82072
82073 #endif
82074
82075 -static struct security_operations selinux_ops = {
82076 +static struct security_operations selinux_ops __read_only = {
82077 .name = "selinux",
82078
82079 .ptrace_access_check = selinux_ptrace_access_check,
82080 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
82081 index 65f67cb..3f141ef 100644
82082 --- a/security/selinux/include/xfrm.h
82083 +++ b/security/selinux/include/xfrm.h
82084 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
82085
82086 static inline void selinux_xfrm_notify_policyload(void)
82087 {
82088 - atomic_inc(&flow_cache_genid);
82089 + atomic_inc_unchecked(&flow_cache_genid);
82090 rt_genid_bump(&init_net);
82091 }
82092 #else
82093 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
82094 index 8221514..5c4775f 100644
82095 --- a/security/smack/smack_lsm.c
82096 +++ b/security/smack/smack_lsm.c
82097 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
82098 return 0;
82099 }
82100
82101 -struct security_operations smack_ops = {
82102 +struct security_operations smack_ops __read_only = {
82103 .name = "smack",
82104
82105 .ptrace_access_check = smack_ptrace_access_check,
82106 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
82107 index c2d04a5..e6a1aeb 100644
82108 --- a/security/tomoyo/tomoyo.c
82109 +++ b/security/tomoyo/tomoyo.c
82110 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
82111 * tomoyo_security_ops is a "struct security_operations" which is used for
82112 * registering TOMOYO.
82113 */
82114 -static struct security_operations tomoyo_security_ops = {
82115 +static struct security_operations tomoyo_security_ops __read_only = {
82116 .name = "tomoyo",
82117 .cred_alloc_blank = tomoyo_cred_alloc_blank,
82118 .cred_prepare = tomoyo_cred_prepare,
82119 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
82120 index 51d6709..1f3dbe2 100644
82121 --- a/security/yama/Kconfig
82122 +++ b/security/yama/Kconfig
82123 @@ -1,6 +1,6 @@
82124 config SECURITY_YAMA
82125 bool "Yama support"
82126 - depends on SECURITY
82127 + depends on SECURITY && !GRKERNSEC
82128 select SECURITYFS
82129 select SECURITY_PATH
82130 default n
82131 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
82132 index 4cedc69..e59d8a3 100644
82133 --- a/sound/aoa/codecs/onyx.c
82134 +++ b/sound/aoa/codecs/onyx.c
82135 @@ -54,7 +54,7 @@ struct onyx {
82136 spdif_locked:1,
82137 analog_locked:1,
82138 original_mute:2;
82139 - int open_count;
82140 + local_t open_count;
82141 struct codec_info *codec_info;
82142
82143 /* mutex serializes concurrent access to the device
82144 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
82145 struct onyx *onyx = cii->codec_data;
82146
82147 mutex_lock(&onyx->mutex);
82148 - onyx->open_count++;
82149 + local_inc(&onyx->open_count);
82150 mutex_unlock(&onyx->mutex);
82151
82152 return 0;
82153 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
82154 struct onyx *onyx = cii->codec_data;
82155
82156 mutex_lock(&onyx->mutex);
82157 - onyx->open_count--;
82158 - if (!onyx->open_count)
82159 + if (local_dec_and_test(&onyx->open_count))
82160 onyx->spdif_locked = onyx->analog_locked = 0;
82161 mutex_unlock(&onyx->mutex);
82162
82163 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
82164 index ffd2025..df062c9 100644
82165 --- a/sound/aoa/codecs/onyx.h
82166 +++ b/sound/aoa/codecs/onyx.h
82167 @@ -11,6 +11,7 @@
82168 #include <linux/i2c.h>
82169 #include <asm/pmac_low_i2c.h>
82170 #include <asm/prom.h>
82171 +#include <asm/local.h>
82172
82173 /* PCM3052 register definitions */
82174
82175 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
82176 index 4c1cc51..16040040 100644
82177 --- a/sound/core/oss/pcm_oss.c
82178 +++ b/sound/core/oss/pcm_oss.c
82179 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
82180 if (in_kernel) {
82181 mm_segment_t fs;
82182 fs = snd_enter_user();
82183 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
82184 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
82185 snd_leave_user(fs);
82186 } else {
82187 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
82188 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
82189 }
82190 if (ret != -EPIPE && ret != -ESTRPIPE)
82191 break;
82192 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
82193 if (in_kernel) {
82194 mm_segment_t fs;
82195 fs = snd_enter_user();
82196 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
82197 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
82198 snd_leave_user(fs);
82199 } else {
82200 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
82201 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
82202 }
82203 if (ret == -EPIPE) {
82204 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
82205 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
82206 struct snd_pcm_plugin_channel *channels;
82207 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
82208 if (!in_kernel) {
82209 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
82210 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
82211 return -EFAULT;
82212 buf = runtime->oss.buffer;
82213 }
82214 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
82215 }
82216 } else {
82217 tmp = snd_pcm_oss_write2(substream,
82218 - (const char __force *)buf,
82219 + (const char __force_kernel *)buf,
82220 runtime->oss.period_bytes, 0);
82221 if (tmp <= 0)
82222 goto err;
82223 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
82224 struct snd_pcm_runtime *runtime = substream->runtime;
82225 snd_pcm_sframes_t frames, frames1;
82226 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
82227 - char __user *final_dst = (char __force __user *)buf;
82228 + char __user *final_dst = (char __force_user *)buf;
82229 if (runtime->oss.plugin_first) {
82230 struct snd_pcm_plugin_channel *channels;
82231 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
82232 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
82233 xfer += tmp;
82234 runtime->oss.buffer_used -= tmp;
82235 } else {
82236 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
82237 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
82238 runtime->oss.period_bytes, 0);
82239 if (tmp <= 0)
82240 goto err;
82241 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
82242 size1);
82243 size1 /= runtime->channels; /* frames */
82244 fs = snd_enter_user();
82245 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
82246 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
82247 snd_leave_user(fs);
82248 }
82249 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
82250 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
82251 index 91cdf94..4085161 100644
82252 --- a/sound/core/pcm_compat.c
82253 +++ b/sound/core/pcm_compat.c
82254 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
82255 int err;
82256
82257 fs = snd_enter_user();
82258 - err = snd_pcm_delay(substream, &delay);
82259 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
82260 snd_leave_user(fs);
82261 if (err < 0)
82262 return err;
82263 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
82264 index bf3bf43..3826cbc 100644
82265 --- a/sound/core/pcm_native.c
82266 +++ b/sound/core/pcm_native.c
82267 @@ -2803,11 +2803,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
82268 switch (substream->stream) {
82269 case SNDRV_PCM_STREAM_PLAYBACK:
82270 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
82271 - (void __user *)arg);
82272 + (void __force_user *)arg);
82273 break;
82274 case SNDRV_PCM_STREAM_CAPTURE:
82275 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
82276 - (void __user *)arg);
82277 + (void __force_user *)arg);
82278 break;
82279 default:
82280 result = -EINVAL;
82281 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
82282 index 5cf8d65..912a79c 100644
82283 --- a/sound/core/seq/seq_device.c
82284 +++ b/sound/core/seq/seq_device.c
82285 @@ -64,7 +64,7 @@ struct ops_list {
82286 int argsize; /* argument size */
82287
82288 /* operators */
82289 - struct snd_seq_dev_ops ops;
82290 + struct snd_seq_dev_ops *ops;
82291
82292 /* registred devices */
82293 struct list_head dev_list; /* list of devices */
82294 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
82295
82296 mutex_lock(&ops->reg_mutex);
82297 /* copy driver operators */
82298 - ops->ops = *entry;
82299 + ops->ops = entry;
82300 ops->driver |= DRIVER_LOADED;
82301 ops->argsize = argsize;
82302
82303 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
82304 dev->name, ops->id, ops->argsize, dev->argsize);
82305 return -EINVAL;
82306 }
82307 - if (ops->ops.init_device(dev) >= 0) {
82308 + if (ops->ops->init_device(dev) >= 0) {
82309 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
82310 ops->num_init_devices++;
82311 } else {
82312 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
82313 dev->name, ops->id, ops->argsize, dev->argsize);
82314 return -EINVAL;
82315 }
82316 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
82317 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
82318 dev->status = SNDRV_SEQ_DEVICE_FREE;
82319 dev->driver_data = NULL;
82320 ops->num_init_devices--;
82321 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
82322 index 2d5514b..3afae9c 100644
82323 --- a/sound/drivers/mts64.c
82324 +++ b/sound/drivers/mts64.c
82325 @@ -29,6 +29,7 @@
82326 #include <sound/initval.h>
82327 #include <sound/rawmidi.h>
82328 #include <sound/control.h>
82329 +#include <asm/local.h>
82330
82331 #define CARD_NAME "Miditerminal 4140"
82332 #define DRIVER_NAME "MTS64"
82333 @@ -67,7 +68,7 @@ struct mts64 {
82334 struct pardevice *pardev;
82335 int pardev_claimed;
82336
82337 - int open_count;
82338 + local_t open_count;
82339 int current_midi_output_port;
82340 int current_midi_input_port;
82341 u8 mode[MTS64_NUM_INPUT_PORTS];
82342 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
82343 {
82344 struct mts64 *mts = substream->rmidi->private_data;
82345
82346 - if (mts->open_count == 0) {
82347 + if (local_read(&mts->open_count) == 0) {
82348 /* We don't need a spinlock here, because this is just called
82349 if the device has not been opened before.
82350 So there aren't any IRQs from the device */
82351 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
82352
82353 msleep(50);
82354 }
82355 - ++(mts->open_count);
82356 + local_inc(&mts->open_count);
82357
82358 return 0;
82359 }
82360 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82361 struct mts64 *mts = substream->rmidi->private_data;
82362 unsigned long flags;
82363
82364 - --(mts->open_count);
82365 - if (mts->open_count == 0) {
82366 + if (local_dec_return(&mts->open_count) == 0) {
82367 /* We need the spinlock_irqsave here because we can still
82368 have IRQs at this point */
82369 spin_lock_irqsave(&mts->lock, flags);
82370 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82371
82372 msleep(500);
82373
82374 - } else if (mts->open_count < 0)
82375 - mts->open_count = 0;
82376 + } else if (local_read(&mts->open_count) < 0)
82377 + local_set(&mts->open_count, 0);
82378
82379 return 0;
82380 }
82381 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
82382 index b953fb4..1999c01 100644
82383 --- a/sound/drivers/opl4/opl4_lib.c
82384 +++ b/sound/drivers/opl4/opl4_lib.c
82385 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
82386 MODULE_DESCRIPTION("OPL4 driver");
82387 MODULE_LICENSE("GPL");
82388
82389 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
82390 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
82391 {
82392 int timeout = 10;
82393 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
82394 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
82395 index 8364855..59f2e2b 100644
82396 --- a/sound/drivers/portman2x4.c
82397 +++ b/sound/drivers/portman2x4.c
82398 @@ -48,6 +48,7 @@
82399 #include <sound/initval.h>
82400 #include <sound/rawmidi.h>
82401 #include <sound/control.h>
82402 +#include <asm/local.h>
82403
82404 #define CARD_NAME "Portman 2x4"
82405 #define DRIVER_NAME "portman"
82406 @@ -85,7 +86,7 @@ struct portman {
82407 struct pardevice *pardev;
82408 int pardev_claimed;
82409
82410 - int open_count;
82411 + local_t open_count;
82412 int mode[PORTMAN_NUM_INPUT_PORTS];
82413 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
82414 };
82415 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
82416 index ea995af..f1bfa37 100644
82417 --- a/sound/firewire/amdtp.c
82418 +++ b/sound/firewire/amdtp.c
82419 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
82420 ptr = s->pcm_buffer_pointer + data_blocks;
82421 if (ptr >= pcm->runtime->buffer_size)
82422 ptr -= pcm->runtime->buffer_size;
82423 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
82424 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
82425
82426 s->pcm_period_pointer += data_blocks;
82427 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
82428 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
82429 */
82430 void amdtp_out_stream_update(struct amdtp_out_stream *s)
82431 {
82432 - ACCESS_ONCE(s->source_node_id_field) =
82433 + ACCESS_ONCE_RW(s->source_node_id_field) =
82434 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
82435 }
82436 EXPORT_SYMBOL(amdtp_out_stream_update);
82437 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
82438 index b680c5e..061b7a0 100644
82439 --- a/sound/firewire/amdtp.h
82440 +++ b/sound/firewire/amdtp.h
82441 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
82442 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
82443 struct snd_pcm_substream *pcm)
82444 {
82445 - ACCESS_ONCE(s->pcm) = pcm;
82446 + ACCESS_ONCE_RW(s->pcm) = pcm;
82447 }
82448
82449 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
82450 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
82451 index d428ffe..751ef78 100644
82452 --- a/sound/firewire/isight.c
82453 +++ b/sound/firewire/isight.c
82454 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
82455 ptr += count;
82456 if (ptr >= runtime->buffer_size)
82457 ptr -= runtime->buffer_size;
82458 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
82459 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
82460
82461 isight->period_counter += count;
82462 if (isight->period_counter >= runtime->period_size) {
82463 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
82464 if (err < 0)
82465 return err;
82466
82467 - ACCESS_ONCE(isight->pcm_active) = true;
82468 + ACCESS_ONCE_RW(isight->pcm_active) = true;
82469
82470 return 0;
82471 }
82472 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
82473 {
82474 struct isight *isight = substream->private_data;
82475
82476 - ACCESS_ONCE(isight->pcm_active) = false;
82477 + ACCESS_ONCE_RW(isight->pcm_active) = false;
82478
82479 mutex_lock(&isight->mutex);
82480 isight_stop_streaming(isight);
82481 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
82482
82483 switch (cmd) {
82484 case SNDRV_PCM_TRIGGER_START:
82485 - ACCESS_ONCE(isight->pcm_running) = true;
82486 + ACCESS_ONCE_RW(isight->pcm_running) = true;
82487 break;
82488 case SNDRV_PCM_TRIGGER_STOP:
82489 - ACCESS_ONCE(isight->pcm_running) = false;
82490 + ACCESS_ONCE_RW(isight->pcm_running) = false;
82491 break;
82492 default:
82493 return -EINVAL;
82494 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
82495 index 7bd5e33..1fcab12 100644
82496 --- a/sound/isa/cmi8330.c
82497 +++ b/sound/isa/cmi8330.c
82498 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
82499
82500 struct snd_pcm *pcm;
82501 struct snd_cmi8330_stream {
82502 - struct snd_pcm_ops ops;
82503 + snd_pcm_ops_no_const ops;
82504 snd_pcm_open_callback_t open;
82505 void *private_data; /* sb or wss */
82506 } streams[2];
82507 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
82508 index b2b3c01..e1c1e1f 100644
82509 --- a/sound/oss/sb_audio.c
82510 +++ b/sound/oss/sb_audio.c
82511 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
82512 buf16 = (signed short *)(localbuf + localoffs);
82513 while (c)
82514 {
82515 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82516 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82517 if (copy_from_user(lbuf8,
82518 userbuf+useroffs + p,
82519 locallen))
82520 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
82521 index 7d8803a..559f8d0 100644
82522 --- a/sound/oss/swarm_cs4297a.c
82523 +++ b/sound/oss/swarm_cs4297a.c
82524 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
82525 {
82526 struct cs4297a_state *s;
82527 u32 pwr, id;
82528 - mm_segment_t fs;
82529 int rval;
82530 #ifndef CONFIG_BCM_CS4297A_CSWARM
82531 u64 cfg;
82532 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
82533 if (!rval) {
82534 char *sb1250_duart_present;
82535
82536 +#if 0
82537 + mm_segment_t fs;
82538 fs = get_fs();
82539 set_fs(KERNEL_DS);
82540 -#if 0
82541 val = SOUND_MASK_LINE;
82542 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
82543 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
82544 val = initvol[i].vol;
82545 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
82546 }
82547 + set_fs(fs);
82548 // cs4297a_write_ac97(s, 0x18, 0x0808);
82549 #else
82550 // cs4297a_write_ac97(s, 0x5e, 0x180);
82551 cs4297a_write_ac97(s, 0x02, 0x0808);
82552 cs4297a_write_ac97(s, 0x18, 0x0808);
82553 #endif
82554 - set_fs(fs);
82555
82556 list_add(&s->list, &cs4297a_devs);
82557
82558 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
82559 index e5a7e19..4049063 100644
82560 --- a/sound/pci/hda/hda_codec.h
82561 +++ b/sound/pci/hda/hda_codec.h
82562 @@ -614,7 +614,7 @@ struct hda_bus_ops {
82563 /* notify power-up/down from codec to controller */
82564 void (*pm_notify)(struct hda_bus *bus);
82565 #endif
82566 -};
82567 +} __no_const;
82568
82569 /* template to pass to the bus constructor */
82570 struct hda_bus_template {
82571 @@ -714,6 +714,7 @@ struct hda_codec_ops {
82572 #endif
82573 void (*reboot_notify)(struct hda_codec *codec);
82574 };
82575 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
82576
82577 /* record for amp information cache */
82578 struct hda_cache_head {
82579 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
82580 struct snd_pcm_substream *substream);
82581 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
82582 struct snd_pcm_substream *substream);
82583 -};
82584 +} __no_const;
82585
82586 /* PCM information for each substream */
82587 struct hda_pcm_stream {
82588 @@ -802,7 +803,7 @@ struct hda_codec {
82589 const char *modelname; /* model name for preset */
82590
82591 /* set by patch */
82592 - struct hda_codec_ops patch_ops;
82593 + hda_codec_ops_no_const patch_ops;
82594
82595 /* PCM to create, set by patch_ops.build_pcms callback */
82596 unsigned int num_pcms;
82597 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
82598 index 0da778a..bc38b84 100644
82599 --- a/sound/pci/ice1712/ice1712.h
82600 +++ b/sound/pci/ice1712/ice1712.h
82601 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
82602 unsigned int mask_flags; /* total mask bits */
82603 struct snd_akm4xxx_ops {
82604 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
82605 - } ops;
82606 + } __no_const ops;
82607 };
82608
82609 struct snd_ice1712_spdif {
82610 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
82611 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82612 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82613 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82614 - } ops;
82615 + } __no_const ops;
82616 };
82617
82618
82619 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
82620 index bddc405..2c0733c 100644
82621 --- a/sound/pci/ymfpci/ymfpci.h
82622 +++ b/sound/pci/ymfpci/ymfpci.h
82623 @@ -358,7 +358,7 @@ struct snd_ymfpci {
82624 spinlock_t reg_lock;
82625 spinlock_t voice_lock;
82626 wait_queue_head_t interrupt_sleep;
82627 - atomic_t interrupt_sleep_count;
82628 + atomic_unchecked_t interrupt_sleep_count;
82629 struct snd_info_entry *proc_entry;
82630 const struct firmware *dsp_microcode;
82631 const struct firmware *controller_microcode;
82632 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
82633 index 62b2363..ee77972 100644
82634 --- a/sound/pci/ymfpci/ymfpci_main.c
82635 +++ b/sound/pci/ymfpci/ymfpci_main.c
82636 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
82637 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
82638 break;
82639 }
82640 - if (atomic_read(&chip->interrupt_sleep_count)) {
82641 - atomic_set(&chip->interrupt_sleep_count, 0);
82642 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82643 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82644 wake_up(&chip->interrupt_sleep);
82645 }
82646 __end:
82647 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
82648 continue;
82649 init_waitqueue_entry(&wait, current);
82650 add_wait_queue(&chip->interrupt_sleep, &wait);
82651 - atomic_inc(&chip->interrupt_sleep_count);
82652 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
82653 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
82654 remove_wait_queue(&chip->interrupt_sleep, &wait);
82655 }
82656 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
82657 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
82658 spin_unlock(&chip->reg_lock);
82659
82660 - if (atomic_read(&chip->interrupt_sleep_count)) {
82661 - atomic_set(&chip->interrupt_sleep_count, 0);
82662 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82663 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82664 wake_up(&chip->interrupt_sleep);
82665 }
82666 }
82667 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
82668 spin_lock_init(&chip->reg_lock);
82669 spin_lock_init(&chip->voice_lock);
82670 init_waitqueue_head(&chip->interrupt_sleep);
82671 - atomic_set(&chip->interrupt_sleep_count, 0);
82672 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82673 chip->card = card;
82674 chip->pci = pci;
82675 chip->irq = -1;
82676 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
82677 new file mode 100644
82678 index 0000000..50f2f2f
82679 --- /dev/null
82680 +++ b/tools/gcc/.gitignore
82681 @@ -0,0 +1 @@
82682 +size_overflow_hash.h
82683 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
82684 new file mode 100644
82685 index 0000000..1d09b7e
82686 --- /dev/null
82687 +++ b/tools/gcc/Makefile
82688 @@ -0,0 +1,43 @@
82689 +#CC := gcc
82690 +#PLUGIN_SOURCE_FILES := pax_plugin.c
82691 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
82692 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
82693 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
82694 +
82695 +ifeq ($(PLUGINCC),$(HOSTCC))
82696 +HOSTLIBS := hostlibs
82697 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
82698 +else
82699 +HOSTLIBS := hostcxxlibs
82700 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
82701 +endif
82702 +
82703 +$(HOSTLIBS)-y := constify_plugin.so
82704 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
82705 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
82706 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
82707 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
82708 +$(HOSTLIBS)-y += colorize_plugin.so
82709 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
82710 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
82711 +
82712 +always := $($(HOSTLIBS)-y)
82713 +
82714 +constify_plugin-objs := constify_plugin.o
82715 +stackleak_plugin-objs := stackleak_plugin.o
82716 +kallocstat_plugin-objs := kallocstat_plugin.o
82717 +kernexec_plugin-objs := kernexec_plugin.o
82718 +checker_plugin-objs := checker_plugin.o
82719 +colorize_plugin-objs := colorize_plugin.o
82720 +size_overflow_plugin-objs := size_overflow_plugin.o
82721 +latent_entropy_plugin-objs := latent_entropy_plugin.o
82722 +
82723 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
82724 +
82725 +quiet_cmd_build_size_overflow_hash = GENHASH $@
82726 + cmd_build_size_overflow_hash = \
82727 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
82728 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
82729 + $(call if_changed,build_size_overflow_hash)
82730 +
82731 +targets += size_overflow_hash.h
82732 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
82733 new file mode 100644
82734 index 0000000..d41b5af
82735 --- /dev/null
82736 +++ b/tools/gcc/checker_plugin.c
82737 @@ -0,0 +1,171 @@
82738 +/*
82739 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82740 + * Licensed under the GPL v2
82741 + *
82742 + * Note: the choice of the license means that the compilation process is
82743 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82744 + * but for the kernel it doesn't matter since it doesn't link against
82745 + * any of the gcc libraries
82746 + *
82747 + * gcc plugin to implement various sparse (source code checker) features
82748 + *
82749 + * TODO:
82750 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
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 +#include "tree-flow.h"
82775 +#include "target.h"
82776 +
82777 +extern void c_register_addr_space (const char *str, addr_space_t as);
82778 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82779 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82780 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82781 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82782 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82783 +
82784 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82785 +extern rtx emit_move_insn(rtx x, rtx y);
82786 +
82787 +int plugin_is_GPL_compatible;
82788 +
82789 +static struct plugin_info checker_plugin_info = {
82790 + .version = "201111150100",
82791 +};
82792 +
82793 +#define ADDR_SPACE_KERNEL 0
82794 +#define ADDR_SPACE_FORCE_KERNEL 1
82795 +#define ADDR_SPACE_USER 2
82796 +#define ADDR_SPACE_FORCE_USER 3
82797 +#define ADDR_SPACE_IOMEM 0
82798 +#define ADDR_SPACE_FORCE_IOMEM 0
82799 +#define ADDR_SPACE_PERCPU 0
82800 +#define ADDR_SPACE_FORCE_PERCPU 0
82801 +#define ADDR_SPACE_RCU 0
82802 +#define ADDR_SPACE_FORCE_RCU 0
82803 +
82804 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82805 +{
82806 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82807 +}
82808 +
82809 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82810 +{
82811 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82812 +}
82813 +
82814 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82815 +{
82816 + return default_addr_space_valid_pointer_mode(mode, as);
82817 +}
82818 +
82819 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82820 +{
82821 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82822 +}
82823 +
82824 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82825 +{
82826 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82827 +}
82828 +
82829 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82830 +{
82831 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82832 + return true;
82833 +
82834 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82835 + return true;
82836 +
82837 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82838 + return true;
82839 +
82840 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82841 + return true;
82842 +
82843 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82844 + return true;
82845 +
82846 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82847 + return true;
82848 +
82849 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82850 + return true;
82851 +
82852 + return subset == superset;
82853 +}
82854 +
82855 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82856 +{
82857 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82858 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82859 +
82860 + return op;
82861 +}
82862 +
82863 +static void register_checker_address_spaces(void *event_data, void *data)
82864 +{
82865 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82866 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82867 + c_register_addr_space("__user", ADDR_SPACE_USER);
82868 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82869 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82870 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82871 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82872 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82873 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82874 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82875 +
82876 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82877 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82878 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82879 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82880 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82881 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82882 + targetm.addr_space.convert = checker_addr_space_convert;
82883 +}
82884 +
82885 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82886 +{
82887 + const char * const plugin_name = plugin_info->base_name;
82888 + const int argc = plugin_info->argc;
82889 + const struct plugin_argument * const argv = plugin_info->argv;
82890 + int i;
82891 +
82892 + if (!plugin_default_version_check(version, &gcc_version)) {
82893 + error(G_("incompatible gcc/plugin versions"));
82894 + return 1;
82895 + }
82896 +
82897 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82898 +
82899 + for (i = 0; i < argc; ++i)
82900 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82901 +
82902 + if (TARGET_64BIT == 0)
82903 + return 0;
82904 +
82905 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82906 +
82907 + return 0;
82908 +}
82909 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82910 new file mode 100644
82911 index 0000000..846aeb0
82912 --- /dev/null
82913 +++ b/tools/gcc/colorize_plugin.c
82914 @@ -0,0 +1,148 @@
82915 +/*
82916 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82917 + * Licensed under the GPL v2
82918 + *
82919 + * Note: the choice of the license means that the compilation process is
82920 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82921 + * but for the kernel it doesn't matter since it doesn't link against
82922 + * any of the gcc libraries
82923 + *
82924 + * gcc plugin to colorize diagnostic output
82925 + *
82926 + */
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 "diagnostic.h"
82939 +#include "plugin-version.h"
82940 +#include "tm.h"
82941 +
82942 +int plugin_is_GPL_compatible;
82943 +
82944 +static struct plugin_info colorize_plugin_info = {
82945 + .version = "201203092200",
82946 + .help = NULL,
82947 +};
82948 +
82949 +#define GREEN "\033[32m\033[2m"
82950 +#define LIGHTGREEN "\033[32m\033[1m"
82951 +#define YELLOW "\033[33m\033[2m"
82952 +#define LIGHTYELLOW "\033[33m\033[1m"
82953 +#define RED "\033[31m\033[2m"
82954 +#define LIGHTRED "\033[31m\033[1m"
82955 +#define BLUE "\033[34m\033[2m"
82956 +#define LIGHTBLUE "\033[34m\033[1m"
82957 +#define BRIGHT "\033[m\033[1m"
82958 +#define NORMAL "\033[m"
82959 +
82960 +static diagnostic_starter_fn old_starter;
82961 +static diagnostic_finalizer_fn old_finalizer;
82962 +
82963 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82964 +{
82965 + const char *color;
82966 + char *newprefix;
82967 +
82968 + switch (diagnostic->kind) {
82969 + case DK_NOTE:
82970 + color = LIGHTBLUE;
82971 + break;
82972 +
82973 + case DK_PEDWARN:
82974 + case DK_WARNING:
82975 + color = LIGHTYELLOW;
82976 + break;
82977 +
82978 + case DK_ERROR:
82979 + case DK_FATAL:
82980 + case DK_ICE:
82981 + case DK_PERMERROR:
82982 + case DK_SORRY:
82983 + color = LIGHTRED;
82984 + break;
82985 +
82986 + default:
82987 + color = NORMAL;
82988 + }
82989 +
82990 + old_starter(context, diagnostic);
82991 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82992 + return;
82993 + pp_destroy_prefix(context->printer);
82994 + pp_set_prefix(context->printer, newprefix);
82995 +}
82996 +
82997 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82998 +{
82999 + old_finalizer(context, diagnostic);
83000 +}
83001 +
83002 +static void colorize_arm(void)
83003 +{
83004 + old_starter = diagnostic_starter(global_dc);
83005 + old_finalizer = diagnostic_finalizer(global_dc);
83006 +
83007 + diagnostic_starter(global_dc) = start_colorize;
83008 + diagnostic_finalizer(global_dc) = finalize_colorize;
83009 +}
83010 +
83011 +static unsigned int execute_colorize_rearm(void)
83012 +{
83013 + if (diagnostic_starter(global_dc) == start_colorize)
83014 + return 0;
83015 +
83016 + colorize_arm();
83017 + return 0;
83018 +}
83019 +
83020 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
83021 + .pass = {
83022 + .type = SIMPLE_IPA_PASS,
83023 + .name = "colorize_rearm",
83024 + .gate = NULL,
83025 + .execute = execute_colorize_rearm,
83026 + .sub = NULL,
83027 + .next = NULL,
83028 + .static_pass_number = 0,
83029 + .tv_id = TV_NONE,
83030 + .properties_required = 0,
83031 + .properties_provided = 0,
83032 + .properties_destroyed = 0,
83033 + .todo_flags_start = 0,
83034 + .todo_flags_finish = 0
83035 + }
83036 +};
83037 +
83038 +static void colorize_start_unit(void *gcc_data, void *user_data)
83039 +{
83040 + colorize_arm();
83041 +}
83042 +
83043 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83044 +{
83045 + const char * const plugin_name = plugin_info->base_name;
83046 + struct register_pass_info colorize_rearm_pass_info = {
83047 + .pass = &pass_ipa_colorize_rearm.pass,
83048 + .reference_pass_name = "*free_lang_data",
83049 + .ref_pass_instance_number = 1,
83050 + .pos_op = PASS_POS_INSERT_AFTER
83051 + };
83052 +
83053 + if (!plugin_default_version_check(version, &gcc_version)) {
83054 + error(G_("incompatible gcc/plugin versions"));
83055 + return 1;
83056 + }
83057 +
83058 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
83059 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
83060 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
83061 + return 0;
83062 +}
83063 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
83064 new file mode 100644
83065 index 0000000..92ed719
83066 --- /dev/null
83067 +++ b/tools/gcc/constify_plugin.c
83068 @@ -0,0 +1,331 @@
83069 +/*
83070 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
83071 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
83072 + * Licensed under the GPL v2, or (at your option) v3
83073 + *
83074 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
83075 + *
83076 + * Homepage:
83077 + * http://www.grsecurity.net/~ephox/const_plugin/
83078 + *
83079 + * Usage:
83080 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
83081 + * $ gcc -fplugin=constify_plugin.so test.c -O2
83082 + */
83083 +
83084 +#include "gcc-plugin.h"
83085 +#include "config.h"
83086 +#include "system.h"
83087 +#include "coretypes.h"
83088 +#include "tree.h"
83089 +#include "tree-pass.h"
83090 +#include "flags.h"
83091 +#include "intl.h"
83092 +#include "toplev.h"
83093 +#include "plugin.h"
83094 +#include "diagnostic.h"
83095 +#include "plugin-version.h"
83096 +#include "tm.h"
83097 +#include "function.h"
83098 +#include "basic-block.h"
83099 +#include "gimple.h"
83100 +#include "rtl.h"
83101 +#include "emit-rtl.h"
83102 +#include "tree-flow.h"
83103 +
83104 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
83105 +
83106 +int plugin_is_GPL_compatible;
83107 +
83108 +static struct plugin_info const_plugin_info = {
83109 + .version = "201205300030",
83110 + .help = "no-constify\tturn off constification\n",
83111 +};
83112 +
83113 +static void deconstify_tree(tree node);
83114 +
83115 +static void deconstify_type(tree type)
83116 +{
83117 + tree field;
83118 +
83119 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
83120 + tree type = TREE_TYPE(field);
83121 +
83122 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
83123 + continue;
83124 + if (!TYPE_READONLY(type))
83125 + continue;
83126 +
83127 + deconstify_tree(field);
83128 + }
83129 + TYPE_READONLY(type) = 0;
83130 + C_TYPE_FIELDS_READONLY(type) = 0;
83131 +}
83132 +
83133 +static void deconstify_tree(tree node)
83134 +{
83135 + tree old_type, new_type, field;
83136 +
83137 + old_type = TREE_TYPE(node);
83138 +
83139 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
83140 +
83141 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
83142 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
83143 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
83144 + DECL_FIELD_CONTEXT(field) = new_type;
83145 +
83146 + deconstify_type(new_type);
83147 +
83148 + TREE_READONLY(node) = 0;
83149 + TREE_TYPE(node) = new_type;
83150 +}
83151 +
83152 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83153 +{
83154 + tree type;
83155 +
83156 + *no_add_attrs = true;
83157 + if (TREE_CODE(*node) == FUNCTION_DECL) {
83158 + error("%qE attribute does not apply to functions", name);
83159 + return NULL_TREE;
83160 + }
83161 +
83162 + if (TREE_CODE(*node) == VAR_DECL) {
83163 + error("%qE attribute does not apply to variables", name);
83164 + return NULL_TREE;
83165 + }
83166 +
83167 + if (TYPE_P(*node)) {
83168 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
83169 + *no_add_attrs = false;
83170 + else
83171 + error("%qE attribute applies to struct and union types only", name);
83172 + return NULL_TREE;
83173 + }
83174 +
83175 + type = TREE_TYPE(*node);
83176 +
83177 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
83178 + error("%qE attribute applies to struct and union types only", name);
83179 + return NULL_TREE;
83180 + }
83181 +
83182 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
83183 + error("%qE attribute is already applied to the type", name);
83184 + return NULL_TREE;
83185 + }
83186 +
83187 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
83188 + error("%qE attribute used on type that is not constified", name);
83189 + return NULL_TREE;
83190 + }
83191 +
83192 + if (TREE_CODE(*node) == TYPE_DECL) {
83193 + deconstify_tree(*node);
83194 + return NULL_TREE;
83195 + }
83196 +
83197 + return NULL_TREE;
83198 +}
83199 +
83200 +static void constify_type(tree type)
83201 +{
83202 + TYPE_READONLY(type) = 1;
83203 + C_TYPE_FIELDS_READONLY(type) = 1;
83204 +}
83205 +
83206 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83207 +{
83208 + *no_add_attrs = true;
83209 + if (!TYPE_P(*node)) {
83210 + error("%qE attribute applies to types only", name);
83211 + return NULL_TREE;
83212 + }
83213 +
83214 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
83215 + error("%qE attribute applies to struct and union types only", name);
83216 + return NULL_TREE;
83217 + }
83218 +
83219 + *no_add_attrs = false;
83220 + constify_type(*node);
83221 + return NULL_TREE;
83222 +}
83223 +
83224 +static struct attribute_spec no_const_attr = {
83225 + .name = "no_const",
83226 + .min_length = 0,
83227 + .max_length = 0,
83228 + .decl_required = false,
83229 + .type_required = false,
83230 + .function_type_required = false,
83231 + .handler = handle_no_const_attribute,
83232 +#if BUILDING_GCC_VERSION >= 4007
83233 + .affects_type_identity = true
83234 +#endif
83235 +};
83236 +
83237 +static struct attribute_spec do_const_attr = {
83238 + .name = "do_const",
83239 + .min_length = 0,
83240 + .max_length = 0,
83241 + .decl_required = false,
83242 + .type_required = false,
83243 + .function_type_required = false,
83244 + .handler = handle_do_const_attribute,
83245 +#if BUILDING_GCC_VERSION >= 4007
83246 + .affects_type_identity = true
83247 +#endif
83248 +};
83249 +
83250 +static void register_attributes(void *event_data, void *data)
83251 +{
83252 + register_attribute(&no_const_attr);
83253 + register_attribute(&do_const_attr);
83254 +}
83255 +
83256 +static bool is_fptr(tree field)
83257 +{
83258 + tree ptr = TREE_TYPE(field);
83259 +
83260 + if (TREE_CODE(ptr) != POINTER_TYPE)
83261 + return false;
83262 +
83263 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
83264 +}
83265 +
83266 +static bool walk_struct(tree node)
83267 +{
83268 + tree field;
83269 +
83270 + if (TYPE_FIELDS(node) == NULL_TREE)
83271 + return false;
83272 +
83273 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
83274 + gcc_assert(!TYPE_READONLY(node));
83275 + deconstify_type(node);
83276 + return false;
83277 + }
83278 +
83279 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
83280 + tree type = TREE_TYPE(field);
83281 + enum tree_code code = TREE_CODE(type);
83282 +
83283 + if (node == type)
83284 + return false;
83285 + if (code == RECORD_TYPE || code == UNION_TYPE) {
83286 + if (!(walk_struct(type)))
83287 + return false;
83288 + } else if (!is_fptr(field) && !TREE_READONLY(field))
83289 + return false;
83290 + }
83291 + return true;
83292 +}
83293 +
83294 +static void finish_type(void *event_data, void *data)
83295 +{
83296 + tree type = (tree)event_data;
83297 +
83298 + if (type == NULL_TREE || type == error_mark_node)
83299 + return;
83300 +
83301 + if (TYPE_READONLY(type))
83302 + return;
83303 +
83304 + if (walk_struct(type))
83305 + constify_type(type);
83306 +}
83307 +
83308 +static unsigned int check_local_variables(void);
83309 +
83310 +struct gimple_opt_pass pass_local_variable = {
83311 + {
83312 + .type = GIMPLE_PASS,
83313 + .name = "check_local_variables",
83314 + .gate = NULL,
83315 + .execute = check_local_variables,
83316 + .sub = NULL,
83317 + .next = NULL,
83318 + .static_pass_number = 0,
83319 + .tv_id = TV_NONE,
83320 + .properties_required = 0,
83321 + .properties_provided = 0,
83322 + .properties_destroyed = 0,
83323 + .todo_flags_start = 0,
83324 + .todo_flags_finish = 0
83325 + }
83326 +};
83327 +
83328 +static unsigned int check_local_variables(void)
83329 +{
83330 + tree var;
83331 + referenced_var_iterator rvi;
83332 +
83333 +#if BUILDING_GCC_VERSION == 4005
83334 + FOR_EACH_REFERENCED_VAR(var, rvi) {
83335 +#else
83336 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
83337 +#endif
83338 + tree type = TREE_TYPE(var);
83339 +
83340 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
83341 + continue;
83342 +
83343 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
83344 + continue;
83345 +
83346 + if (!TYPE_READONLY(type))
83347 + continue;
83348 +
83349 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
83350 +// continue;
83351 +
83352 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
83353 +// continue;
83354 +
83355 + if (walk_struct(type)) {
83356 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
83357 + return 1;
83358 + }
83359 + }
83360 + return 0;
83361 +}
83362 +
83363 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83364 +{
83365 + const char * const plugin_name = plugin_info->base_name;
83366 + const int argc = plugin_info->argc;
83367 + const struct plugin_argument * const argv = plugin_info->argv;
83368 + int i;
83369 + bool constify = true;
83370 +
83371 + struct register_pass_info local_variable_pass_info = {
83372 + .pass = &pass_local_variable.pass,
83373 + .reference_pass_name = "*referenced_vars",
83374 + .ref_pass_instance_number = 1,
83375 + .pos_op = PASS_POS_INSERT_AFTER
83376 + };
83377 +
83378 + if (!plugin_default_version_check(version, &gcc_version)) {
83379 + error(G_("incompatible gcc/plugin versions"));
83380 + return 1;
83381 + }
83382 +
83383 + for (i = 0; i < argc; ++i) {
83384 + if (!(strcmp(argv[i].key, "no-constify"))) {
83385 + constify = false;
83386 + continue;
83387 + }
83388 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83389 + }
83390 +
83391 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
83392 + if (constify) {
83393 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
83394 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
83395 + }
83396 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83397 +
83398 + return 0;
83399 +}
83400 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
83401 new file mode 100755
83402 index 0000000..02c6bec
83403 --- /dev/null
83404 +++ b/tools/gcc/generate_size_overflow_hash.sh
83405 @@ -0,0 +1,94 @@
83406 +#!/bin/bash
83407 +
83408 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
83409 +
83410 +header1="size_overflow_hash.h"
83411 +database="size_overflow_hash.data"
83412 +n=65536
83413 +
83414 +usage() {
83415 +cat <<EOF
83416 +usage: $0 options
83417 +OPTIONS:
83418 + -h|--help help
83419 + -o header file
83420 + -d database file
83421 + -n hash array size
83422 +EOF
83423 + return 0
83424 +}
83425 +
83426 +while true
83427 +do
83428 + case "$1" in
83429 + -h|--help) usage && exit 0;;
83430 + -n) n=$2; shift 2;;
83431 + -o) header1="$2"; shift 2;;
83432 + -d) database="$2"; shift 2;;
83433 + --) shift 1; break ;;
83434 + *) break ;;
83435 + esac
83436 +done
83437 +
83438 +create_defines() {
83439 + for i in `seq 1 32`
83440 + do
83441 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
83442 + done
83443 + echo >> "$header1"
83444 +}
83445 +
83446 +create_structs () {
83447 + rm -f "$header1"
83448 +
83449 + create_defines
83450 +
83451 + cat "$database" | while read data
83452 + do
83453 + data_array=($data)
83454 + struct_hash_name="${data_array[0]}"
83455 + funcn="${data_array[1]}"
83456 + params="${data_array[2]}"
83457 + next="${data_array[5]}"
83458 +
83459 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
83460 +
83461 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
83462 + echo -en "\t.param\t= " >> "$header1"
83463 + line=
83464 + for param_num in ${params//-/ };
83465 + do
83466 + line="${line}PARAM"$param_num"|"
83467 + done
83468 +
83469 + echo -e "${line%?},\n};\n" >> "$header1"
83470 + done
83471 +}
83472 +
83473 +create_headers () {
83474 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
83475 +}
83476 +
83477 +create_array_elements () {
83478 + index=0
83479 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
83480 + do
83481 + data_array=($data)
83482 + i="${data_array[3]}"
83483 + hash="${data_array[4]}"
83484 + while [[ $index -lt $i ]]
83485 + do
83486 + echo -e "\t["$index"]\t= NULL," >> "$header1"
83487 + index=$(($index + 1))
83488 + done
83489 + index=$(($index + 1))
83490 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
83491 + done
83492 + echo '};' >> $header1
83493 +}
83494 +
83495 +create_structs
83496 +create_headers
83497 +create_array_elements
83498 +
83499 +exit 0
83500 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
83501 new file mode 100644
83502 index 0000000..a86e422
83503 --- /dev/null
83504 +++ b/tools/gcc/kallocstat_plugin.c
83505 @@ -0,0 +1,167 @@
83506 +/*
83507 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83508 + * Licensed under the GPL v2
83509 + *
83510 + * Note: the choice of the license means that the compilation process is
83511 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83512 + * but for the kernel it doesn't matter since it doesn't link against
83513 + * any of the gcc libraries
83514 + *
83515 + * gcc plugin to find the distribution of k*alloc sizes
83516 + *
83517 + * TODO:
83518 + *
83519 + * BUGS:
83520 + * - none known
83521 + */
83522 +#include "gcc-plugin.h"
83523 +#include "config.h"
83524 +#include "system.h"
83525 +#include "coretypes.h"
83526 +#include "tree.h"
83527 +#include "tree-pass.h"
83528 +#include "flags.h"
83529 +#include "intl.h"
83530 +#include "toplev.h"
83531 +#include "plugin.h"
83532 +//#include "expr.h" where are you...
83533 +#include "diagnostic.h"
83534 +#include "plugin-version.h"
83535 +#include "tm.h"
83536 +#include "function.h"
83537 +#include "basic-block.h"
83538 +#include "gimple.h"
83539 +#include "rtl.h"
83540 +#include "emit-rtl.h"
83541 +
83542 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83543 +
83544 +int plugin_is_GPL_compatible;
83545 +
83546 +static const char * const kalloc_functions[] = {
83547 + "__kmalloc",
83548 + "kmalloc",
83549 + "kmalloc_large",
83550 + "kmalloc_node",
83551 + "kmalloc_order",
83552 + "kmalloc_order_trace",
83553 + "kmalloc_slab",
83554 + "kzalloc",
83555 + "kzalloc_node",
83556 +};
83557 +
83558 +static struct plugin_info kallocstat_plugin_info = {
83559 + .version = "201111150100",
83560 +};
83561 +
83562 +static unsigned int execute_kallocstat(void);
83563 +
83564 +static struct gimple_opt_pass kallocstat_pass = {
83565 + .pass = {
83566 + .type = GIMPLE_PASS,
83567 + .name = "kallocstat",
83568 + .gate = NULL,
83569 + .execute = execute_kallocstat,
83570 + .sub = NULL,
83571 + .next = NULL,
83572 + .static_pass_number = 0,
83573 + .tv_id = TV_NONE,
83574 + .properties_required = 0,
83575 + .properties_provided = 0,
83576 + .properties_destroyed = 0,
83577 + .todo_flags_start = 0,
83578 + .todo_flags_finish = 0
83579 + }
83580 +};
83581 +
83582 +static bool is_kalloc(const char *fnname)
83583 +{
83584 + size_t i;
83585 +
83586 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
83587 + if (!strcmp(fnname, kalloc_functions[i]))
83588 + return true;
83589 + return false;
83590 +}
83591 +
83592 +static unsigned int execute_kallocstat(void)
83593 +{
83594 + basic_block bb;
83595 +
83596 + // 1. loop through BBs and GIMPLE statements
83597 + FOR_EACH_BB(bb) {
83598 + gimple_stmt_iterator gsi;
83599 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83600 + // gimple match:
83601 + tree fndecl, size;
83602 + gimple call_stmt;
83603 + const char *fnname;
83604 +
83605 + // is it a call
83606 + call_stmt = gsi_stmt(gsi);
83607 + if (!is_gimple_call(call_stmt))
83608 + continue;
83609 + fndecl = gimple_call_fndecl(call_stmt);
83610 + if (fndecl == NULL_TREE)
83611 + continue;
83612 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
83613 + continue;
83614 +
83615 + // is it a call to k*alloc
83616 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
83617 + if (!is_kalloc(fnname))
83618 + continue;
83619 +
83620 + // is the size arg the result of a simple const assignment
83621 + size = gimple_call_arg(call_stmt, 0);
83622 + while (true) {
83623 + gimple def_stmt;
83624 + expanded_location xloc;
83625 + size_t size_val;
83626 +
83627 + if (TREE_CODE(size) != SSA_NAME)
83628 + break;
83629 + def_stmt = SSA_NAME_DEF_STMT(size);
83630 + if (!def_stmt || !is_gimple_assign(def_stmt))
83631 + break;
83632 + if (gimple_num_ops(def_stmt) != 2)
83633 + break;
83634 + size = gimple_assign_rhs1(def_stmt);
83635 + if (!TREE_CONSTANT(size))
83636 + continue;
83637 + xloc = expand_location(gimple_location(def_stmt));
83638 + if (!xloc.file)
83639 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
83640 + size_val = TREE_INT_CST_LOW(size);
83641 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
83642 + break;
83643 + }
83644 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83645 +//debug_tree(gimple_call_fn(call_stmt));
83646 +//print_node(stderr, "pax", fndecl, 4);
83647 + }
83648 + }
83649 +
83650 + return 0;
83651 +}
83652 +
83653 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83654 +{
83655 + const char * const plugin_name = plugin_info->base_name;
83656 + struct register_pass_info kallocstat_pass_info = {
83657 + .pass = &kallocstat_pass.pass,
83658 + .reference_pass_name = "ssa",
83659 + .ref_pass_instance_number = 1,
83660 + .pos_op = PASS_POS_INSERT_AFTER
83661 + };
83662 +
83663 + if (!plugin_default_version_check(version, &gcc_version)) {
83664 + error(G_("incompatible gcc/plugin versions"));
83665 + return 1;
83666 + }
83667 +
83668 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
83669 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
83670 +
83671 + return 0;
83672 +}
83673 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
83674 new file mode 100644
83675 index 0000000..8856202
83676 --- /dev/null
83677 +++ b/tools/gcc/kernexec_plugin.c
83678 @@ -0,0 +1,432 @@
83679 +/*
83680 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83681 + * Licensed under the GPL v2
83682 + *
83683 + * Note: the choice of the license means that the compilation process is
83684 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83685 + * but for the kernel it doesn't matter since it doesn't link against
83686 + * any of the gcc libraries
83687 + *
83688 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
83689 + *
83690 + * TODO:
83691 + *
83692 + * BUGS:
83693 + * - none known
83694 + */
83695 +#include "gcc-plugin.h"
83696 +#include "config.h"
83697 +#include "system.h"
83698 +#include "coretypes.h"
83699 +#include "tree.h"
83700 +#include "tree-pass.h"
83701 +#include "flags.h"
83702 +#include "intl.h"
83703 +#include "toplev.h"
83704 +#include "plugin.h"
83705 +//#include "expr.h" where are you...
83706 +#include "diagnostic.h"
83707 +#include "plugin-version.h"
83708 +#include "tm.h"
83709 +#include "function.h"
83710 +#include "basic-block.h"
83711 +#include "gimple.h"
83712 +#include "rtl.h"
83713 +#include "emit-rtl.h"
83714 +#include "tree-flow.h"
83715 +
83716 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83717 +extern rtx emit_move_insn(rtx x, rtx y);
83718 +
83719 +#if BUILDING_GCC_VERSION <= 4006
83720 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
83721 +#endif
83722 +
83723 +int plugin_is_GPL_compatible;
83724 +
83725 +static struct plugin_info kernexec_plugin_info = {
83726 + .version = "201111291120",
83727 + .help = "method=[bts|or]\tinstrumentation method\n"
83728 +};
83729 +
83730 +static unsigned int execute_kernexec_reload(void);
83731 +static unsigned int execute_kernexec_fptr(void);
83732 +static unsigned int execute_kernexec_retaddr(void);
83733 +static bool kernexec_cmodel_check(void);
83734 +
83735 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
83736 +static void (*kernexec_instrument_retaddr)(rtx);
83737 +
83738 +static struct gimple_opt_pass kernexec_reload_pass = {
83739 + .pass = {
83740 + .type = GIMPLE_PASS,
83741 + .name = "kernexec_reload",
83742 + .gate = kernexec_cmodel_check,
83743 + .execute = execute_kernexec_reload,
83744 + .sub = NULL,
83745 + .next = NULL,
83746 + .static_pass_number = 0,
83747 + .tv_id = TV_NONE,
83748 + .properties_required = 0,
83749 + .properties_provided = 0,
83750 + .properties_destroyed = 0,
83751 + .todo_flags_start = 0,
83752 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83753 + }
83754 +};
83755 +
83756 +static struct gimple_opt_pass kernexec_fptr_pass = {
83757 + .pass = {
83758 + .type = GIMPLE_PASS,
83759 + .name = "kernexec_fptr",
83760 + .gate = kernexec_cmodel_check,
83761 + .execute = execute_kernexec_fptr,
83762 + .sub = NULL,
83763 + .next = NULL,
83764 + .static_pass_number = 0,
83765 + .tv_id = TV_NONE,
83766 + .properties_required = 0,
83767 + .properties_provided = 0,
83768 + .properties_destroyed = 0,
83769 + .todo_flags_start = 0,
83770 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83771 + }
83772 +};
83773 +
83774 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83775 + .pass = {
83776 + .type = RTL_PASS,
83777 + .name = "kernexec_retaddr",
83778 + .gate = kernexec_cmodel_check,
83779 + .execute = execute_kernexec_retaddr,
83780 + .sub = NULL,
83781 + .next = NULL,
83782 + .static_pass_number = 0,
83783 + .tv_id = TV_NONE,
83784 + .properties_required = 0,
83785 + .properties_provided = 0,
83786 + .properties_destroyed = 0,
83787 + .todo_flags_start = 0,
83788 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83789 + }
83790 +};
83791 +
83792 +static bool kernexec_cmodel_check(void)
83793 +{
83794 + tree section;
83795 +
83796 + if (ix86_cmodel != CM_KERNEL)
83797 + return false;
83798 +
83799 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83800 + if (!section || !TREE_VALUE(section))
83801 + return true;
83802 +
83803 + section = TREE_VALUE(TREE_VALUE(section));
83804 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83805 + return true;
83806 +
83807 + return false;
83808 +}
83809 +
83810 +/*
83811 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83812 + */
83813 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83814 +{
83815 + gimple asm_movabs_stmt;
83816 +
83817 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83818 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83819 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83820 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83821 + update_stmt(asm_movabs_stmt);
83822 +}
83823 +
83824 +/*
83825 + * find all asm() stmts that clobber r10 and add a reload of r10
83826 + */
83827 +static unsigned int execute_kernexec_reload(void)
83828 +{
83829 + basic_block bb;
83830 +
83831 + // 1. loop through BBs and GIMPLE statements
83832 + FOR_EACH_BB(bb) {
83833 + gimple_stmt_iterator gsi;
83834 +
83835 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83836 + // gimple match: __asm__ ("" : : : "r10");
83837 + gimple asm_stmt;
83838 + size_t nclobbers;
83839 +
83840 + // is it an asm ...
83841 + asm_stmt = gsi_stmt(gsi);
83842 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83843 + continue;
83844 +
83845 + // ... clobbering r10
83846 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83847 + while (nclobbers--) {
83848 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83849 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83850 + continue;
83851 + kernexec_reload_fptr_mask(&gsi);
83852 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83853 + break;
83854 + }
83855 + }
83856 + }
83857 +
83858 + return 0;
83859 +}
83860 +
83861 +/*
83862 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83863 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83864 + */
83865 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83866 +{
83867 + gimple assign_intptr, assign_new_fptr, call_stmt;
83868 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83869 +
83870 + call_stmt = gsi_stmt(*gsi);
83871 + old_fptr = gimple_call_fn(call_stmt);
83872 +
83873 + // create temporary unsigned long variable used for bitops and cast fptr to it
83874 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83875 + add_referenced_var(intptr);
83876 + mark_sym_for_renaming(intptr);
83877 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83878 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83879 + update_stmt(assign_intptr);
83880 +
83881 + // apply logical or to temporary unsigned long and bitmask
83882 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83883 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83884 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83885 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83886 + update_stmt(assign_intptr);
83887 +
83888 + // cast temporary unsigned long back to a temporary fptr variable
83889 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83890 + add_referenced_var(new_fptr);
83891 + mark_sym_for_renaming(new_fptr);
83892 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83893 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83894 + update_stmt(assign_new_fptr);
83895 +
83896 + // replace call stmt fn with the new fptr
83897 + gimple_call_set_fn(call_stmt, new_fptr);
83898 + update_stmt(call_stmt);
83899 +}
83900 +
83901 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83902 +{
83903 + gimple asm_or_stmt, call_stmt;
83904 + tree old_fptr, new_fptr, input, output;
83905 + VEC(tree, gc) *inputs = NULL;
83906 + VEC(tree, gc) *outputs = NULL;
83907 +
83908 + call_stmt = gsi_stmt(*gsi);
83909 + old_fptr = gimple_call_fn(call_stmt);
83910 +
83911 + // create temporary fptr variable
83912 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83913 + add_referenced_var(new_fptr);
83914 + mark_sym_for_renaming(new_fptr);
83915 +
83916 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83917 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83918 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83919 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83920 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83921 + VEC_safe_push(tree, gc, inputs, input);
83922 + VEC_safe_push(tree, gc, outputs, output);
83923 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83924 + gimple_asm_set_volatile(asm_or_stmt, true);
83925 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83926 + update_stmt(asm_or_stmt);
83927 +
83928 + // replace call stmt fn with the new fptr
83929 + gimple_call_set_fn(call_stmt, new_fptr);
83930 + update_stmt(call_stmt);
83931 +}
83932 +
83933 +/*
83934 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83935 + */
83936 +static unsigned int execute_kernexec_fptr(void)
83937 +{
83938 + basic_block bb;
83939 +
83940 + // 1. loop through BBs and GIMPLE statements
83941 + FOR_EACH_BB(bb) {
83942 + gimple_stmt_iterator gsi;
83943 +
83944 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83945 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83946 + tree fn;
83947 + gimple call_stmt;
83948 +
83949 + // is it a call ...
83950 + call_stmt = gsi_stmt(gsi);
83951 + if (!is_gimple_call(call_stmt))
83952 + continue;
83953 + fn = gimple_call_fn(call_stmt);
83954 + if (TREE_CODE(fn) == ADDR_EXPR)
83955 + continue;
83956 + if (TREE_CODE(fn) != SSA_NAME)
83957 + gcc_unreachable();
83958 +
83959 + // ... through a function pointer
83960 + fn = SSA_NAME_VAR(fn);
83961 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83962 + continue;
83963 + fn = TREE_TYPE(fn);
83964 + if (TREE_CODE(fn) != POINTER_TYPE)
83965 + continue;
83966 + fn = TREE_TYPE(fn);
83967 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83968 + continue;
83969 +
83970 + kernexec_instrument_fptr(&gsi);
83971 +
83972 +//debug_tree(gimple_call_fn(call_stmt));
83973 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83974 + }
83975 + }
83976 +
83977 + return 0;
83978 +}
83979 +
83980 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83981 +static void kernexec_instrument_retaddr_bts(rtx insn)
83982 +{
83983 + rtx btsq;
83984 + rtvec argvec, constraintvec, labelvec;
83985 + int line;
83986 +
83987 + // create asm volatile("btsq $63,(%%rsp)":::)
83988 + argvec = rtvec_alloc(0);
83989 + constraintvec = rtvec_alloc(0);
83990 + labelvec = rtvec_alloc(0);
83991 + line = expand_location(RTL_LOCATION(insn)).line;
83992 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83993 + MEM_VOLATILE_P(btsq) = 1;
83994 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83995 + emit_insn_before(btsq, insn);
83996 +}
83997 +
83998 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83999 +static void kernexec_instrument_retaddr_or(rtx insn)
84000 +{
84001 + rtx orq;
84002 + rtvec argvec, constraintvec, labelvec;
84003 + int line;
84004 +
84005 + // create asm volatile("orq %%r10,(%%rsp)":::)
84006 + argvec = rtvec_alloc(0);
84007 + constraintvec = rtvec_alloc(0);
84008 + labelvec = rtvec_alloc(0);
84009 + line = expand_location(RTL_LOCATION(insn)).line;
84010 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
84011 + MEM_VOLATILE_P(orq) = 1;
84012 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
84013 + emit_insn_before(orq, insn);
84014 +}
84015 +
84016 +/*
84017 + * find all asm level function returns and forcibly set the highest bit of the return address
84018 + */
84019 +static unsigned int execute_kernexec_retaddr(void)
84020 +{
84021 + rtx insn;
84022 +
84023 + // 1. find function returns
84024 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
84025 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
84026 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
84027 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
84028 + rtx body;
84029 +
84030 + // is it a retn
84031 + if (!JUMP_P(insn))
84032 + continue;
84033 + body = PATTERN(insn);
84034 + if (GET_CODE(body) == PARALLEL)
84035 + body = XVECEXP(body, 0, 0);
84036 + if (!ANY_RETURN_P(body))
84037 + continue;
84038 + kernexec_instrument_retaddr(insn);
84039 + }
84040 +
84041 +// print_simple_rtl(stderr, get_insns());
84042 +// print_rtl(stderr, get_insns());
84043 +
84044 + return 0;
84045 +}
84046 +
84047 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84048 +{
84049 + const char * const plugin_name = plugin_info->base_name;
84050 + const int argc = plugin_info->argc;
84051 + const struct plugin_argument * const argv = plugin_info->argv;
84052 + int i;
84053 + struct register_pass_info kernexec_reload_pass_info = {
84054 + .pass = &kernexec_reload_pass.pass,
84055 + .reference_pass_name = "ssa",
84056 + .ref_pass_instance_number = 1,
84057 + .pos_op = PASS_POS_INSERT_AFTER
84058 + };
84059 + struct register_pass_info kernexec_fptr_pass_info = {
84060 + .pass = &kernexec_fptr_pass.pass,
84061 + .reference_pass_name = "ssa",
84062 + .ref_pass_instance_number = 1,
84063 + .pos_op = PASS_POS_INSERT_AFTER
84064 + };
84065 + struct register_pass_info kernexec_retaddr_pass_info = {
84066 + .pass = &kernexec_retaddr_pass.pass,
84067 + .reference_pass_name = "pro_and_epilogue",
84068 + .ref_pass_instance_number = 1,
84069 + .pos_op = PASS_POS_INSERT_AFTER
84070 + };
84071 +
84072 + if (!plugin_default_version_check(version, &gcc_version)) {
84073 + error(G_("incompatible gcc/plugin versions"));
84074 + return 1;
84075 + }
84076 +
84077 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
84078 +
84079 + if (TARGET_64BIT == 0)
84080 + return 0;
84081 +
84082 + for (i = 0; i < argc; ++i) {
84083 + if (!strcmp(argv[i].key, "method")) {
84084 + if (!argv[i].value) {
84085 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84086 + continue;
84087 + }
84088 + if (!strcmp(argv[i].value, "bts")) {
84089 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
84090 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
84091 + } else if (!strcmp(argv[i].value, "or")) {
84092 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
84093 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
84094 + fix_register("r10", 1, 1);
84095 + } else
84096 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
84097 + continue;
84098 + }
84099 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84100 + }
84101 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
84102 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
84103 +
84104 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
84105 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
84106 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
84107 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
84108 +
84109 + return 0;
84110 +}
84111 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
84112 new file mode 100644
84113 index 0000000..b8008f7
84114 --- /dev/null
84115 +++ b/tools/gcc/latent_entropy_plugin.c
84116 @@ -0,0 +1,295 @@
84117 +/*
84118 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
84119 + * Licensed under the GPL v2
84120 + *
84121 + * Note: the choice of the license means that the compilation process is
84122 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84123 + * but for the kernel it doesn't matter since it doesn't link against
84124 + * any of the gcc libraries
84125 + *
84126 + * gcc plugin to help generate a little bit of entropy from program state,
84127 + * used during boot in the kernel
84128 + *
84129 + * TODO:
84130 + * - add ipa pass to identify not explicitly marked candidate functions
84131 + * - mix in more program state (function arguments/return values, loop variables, etc)
84132 + * - more instrumentation control via attribute parameters
84133 + *
84134 + * BUGS:
84135 + * - LTO needs -flto-partition=none for now
84136 + */
84137 +#include "gcc-plugin.h"
84138 +#include "config.h"
84139 +#include "system.h"
84140 +#include "coretypes.h"
84141 +#include "tree.h"
84142 +#include "tree-pass.h"
84143 +#include "flags.h"
84144 +#include "intl.h"
84145 +#include "toplev.h"
84146 +#include "plugin.h"
84147 +//#include "expr.h" where are you...
84148 +#include "diagnostic.h"
84149 +#include "plugin-version.h"
84150 +#include "tm.h"
84151 +#include "function.h"
84152 +#include "basic-block.h"
84153 +#include "gimple.h"
84154 +#include "rtl.h"
84155 +#include "emit-rtl.h"
84156 +#include "tree-flow.h"
84157 +
84158 +int plugin_is_GPL_compatible;
84159 +
84160 +static tree latent_entropy_decl;
84161 +
84162 +static struct plugin_info latent_entropy_plugin_info = {
84163 + .version = "201207271820",
84164 + .help = NULL
84165 +};
84166 +
84167 +static unsigned int execute_latent_entropy(void);
84168 +static bool gate_latent_entropy(void);
84169 +
84170 +static struct gimple_opt_pass latent_entropy_pass = {
84171 + .pass = {
84172 + .type = GIMPLE_PASS,
84173 + .name = "latent_entropy",
84174 + .gate = gate_latent_entropy,
84175 + .execute = execute_latent_entropy,
84176 + .sub = NULL,
84177 + .next = NULL,
84178 + .static_pass_number = 0,
84179 + .tv_id = TV_NONE,
84180 + .properties_required = PROP_gimple_leh | PROP_cfg,
84181 + .properties_provided = 0,
84182 + .properties_destroyed = 0,
84183 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
84184 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
84185 + }
84186 +};
84187 +
84188 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
84189 +{
84190 + if (TREE_CODE(*node) != FUNCTION_DECL) {
84191 + *no_add_attrs = true;
84192 + error("%qE attribute only applies to functions", name);
84193 + }
84194 + return NULL_TREE;
84195 +}
84196 +
84197 +static struct attribute_spec latent_entropy_attr = {
84198 + .name = "latent_entropy",
84199 + .min_length = 0,
84200 + .max_length = 0,
84201 + .decl_required = true,
84202 + .type_required = false,
84203 + .function_type_required = false,
84204 + .handler = handle_latent_entropy_attribute,
84205 +#if BUILDING_GCC_VERSION >= 4007
84206 + .affects_type_identity = false
84207 +#endif
84208 +};
84209 +
84210 +static void register_attributes(void *event_data, void *data)
84211 +{
84212 + register_attribute(&latent_entropy_attr);
84213 +}
84214 +
84215 +static bool gate_latent_entropy(void)
84216 +{
84217 + tree latent_entropy_attr;
84218 +
84219 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
84220 + return latent_entropy_attr != NULL_TREE;
84221 +}
84222 +
84223 +static unsigned HOST_WIDE_INT seed;
84224 +static unsigned HOST_WIDE_INT get_random_const(void)
84225 +{
84226 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
84227 + return seed;
84228 +}
84229 +
84230 +static enum tree_code get_op(tree *rhs)
84231 +{
84232 + static enum tree_code op;
84233 + unsigned HOST_WIDE_INT random_const;
84234 +
84235 + random_const = get_random_const();
84236 +
84237 + switch (op) {
84238 + case BIT_XOR_EXPR:
84239 + op = PLUS_EXPR;
84240 + break;
84241 +
84242 + case PLUS_EXPR:
84243 + if (rhs) {
84244 + op = LROTATE_EXPR;
84245 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
84246 + break;
84247 + }
84248 +
84249 + case LROTATE_EXPR:
84250 + default:
84251 + op = BIT_XOR_EXPR;
84252 + break;
84253 + }
84254 + if (rhs)
84255 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
84256 + return op;
84257 +}
84258 +
84259 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
84260 +{
84261 + gimple_stmt_iterator gsi;
84262 + gimple assign;
84263 + tree addxorrol, rhs;
84264 + enum tree_code op;
84265 +
84266 + op = get_op(&rhs);
84267 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
84268 + assign = gimple_build_assign(local_entropy, addxorrol);
84269 + find_referenced_vars_in(assign);
84270 +//debug_bb(bb);
84271 + gsi = gsi_after_labels(bb);
84272 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
84273 + update_stmt(assign);
84274 +}
84275 +
84276 +static void perturb_latent_entropy(basic_block bb, tree rhs)
84277 +{
84278 + gimple_stmt_iterator gsi;
84279 + gimple assign;
84280 + tree addxorrol, temp;
84281 +
84282 + // 1. create temporary copy of latent_entropy
84283 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
84284 + add_referenced_var(temp);
84285 + mark_sym_for_renaming(temp);
84286 +
84287 + // 2. read...
84288 + assign = gimple_build_assign(temp, latent_entropy_decl);
84289 + find_referenced_vars_in(assign);
84290 + gsi = gsi_after_labels(bb);
84291 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84292 + update_stmt(assign);
84293 +
84294 + // 3. ...modify...
84295 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
84296 + assign = gimple_build_assign(temp, addxorrol);
84297 + find_referenced_vars_in(assign);
84298 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84299 + update_stmt(assign);
84300 +
84301 + // 4. ...write latent_entropy
84302 + assign = gimple_build_assign(latent_entropy_decl, temp);
84303 + find_referenced_vars_in(assign);
84304 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84305 + update_stmt(assign);
84306 +}
84307 +
84308 +static unsigned int execute_latent_entropy(void)
84309 +{
84310 + basic_block bb;
84311 + gimple assign;
84312 + gimple_stmt_iterator gsi;
84313 + tree local_entropy;
84314 +
84315 + if (!latent_entropy_decl) {
84316 + struct varpool_node *node;
84317 +
84318 + for (node = varpool_nodes; node; node = node->next) {
84319 + tree var = node->decl;
84320 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
84321 + continue;
84322 + latent_entropy_decl = var;
84323 +// debug_tree(var);
84324 + break;
84325 + }
84326 + if (!latent_entropy_decl) {
84327 +// debug_tree(current_function_decl);
84328 + return 0;
84329 + }
84330 + }
84331 +
84332 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
84333 +
84334 + // 1. create local entropy variable
84335 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
84336 + add_referenced_var(local_entropy);
84337 + mark_sym_for_renaming(local_entropy);
84338 +
84339 + // 2. initialize local entropy variable
84340 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
84341 + if (dom_info_available_p(CDI_DOMINATORS))
84342 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
84343 + gsi = gsi_start_bb(bb);
84344 +
84345 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
84346 +// gimple_set_location(assign, loc);
84347 + find_referenced_vars_in(assign);
84348 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84349 + update_stmt(assign);
84350 + bb = bb->next_bb;
84351 +
84352 + // 3. instrument each BB with an operation on the local entropy variable
84353 + while (bb != EXIT_BLOCK_PTR) {
84354 + perturb_local_entropy(bb, local_entropy);
84355 + bb = bb->next_bb;
84356 + };
84357 +
84358 + // 4. mix local entropy into the global entropy variable
84359 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
84360 + return 0;
84361 +}
84362 +
84363 +static void start_unit_callback(void *gcc_data, void *user_data)
84364 +{
84365 +#if BUILDING_GCC_VERSION >= 4007
84366 + seed = get_random_seed(false);
84367 +#else
84368 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
84369 + seed *= seed;
84370 +#endif
84371 +
84372 + if (in_lto_p)
84373 + return;
84374 +
84375 + // extern u64 latent_entropy
84376 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
84377 +
84378 + TREE_STATIC(latent_entropy_decl) = 1;
84379 + TREE_PUBLIC(latent_entropy_decl) = 1;
84380 + TREE_USED(latent_entropy_decl) = 1;
84381 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
84382 + DECL_EXTERNAL(latent_entropy_decl) = 1;
84383 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
84384 + DECL_INITIAL(latent_entropy_decl) = NULL;
84385 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
84386 +// varpool_finalize_decl(latent_entropy_decl);
84387 +// varpool_mark_needed_node(latent_entropy_decl);
84388 +}
84389 +
84390 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84391 +{
84392 + const char * const plugin_name = plugin_info->base_name;
84393 + struct register_pass_info latent_entropy_pass_info = {
84394 + .pass = &latent_entropy_pass.pass,
84395 + .reference_pass_name = "optimized",
84396 + .ref_pass_instance_number = 1,
84397 + .pos_op = PASS_POS_INSERT_BEFORE
84398 + };
84399 +
84400 + if (!plugin_default_version_check(version, &gcc_version)) {
84401 + error(G_("incompatible gcc/plugin versions"));
84402 + return 1;
84403 + }
84404 +
84405 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
84406 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84407 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
84408 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84409 +
84410 + return 0;
84411 +}
84412 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
84413 new file mode 100644
84414 index 0000000..67468e3
84415 --- /dev/null
84416 +++ b/tools/gcc/size_overflow_hash.data
84417 @@ -0,0 +1,3600 @@
84418 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
84419 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
84420 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
84421 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
84422 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
84423 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
84424 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
84425 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
84426 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
84427 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
84428 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
84429 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
84430 +_000014_hash kmemdup 2 64015 _000014_hash NULL
84431 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
84432 +_000016_hash memdup_user 2 59590 _000016_hash NULL
84433 +_000017_hash module_alloc 1 63630 _000017_hash NULL
84434 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
84435 +_000019_hash read_kcore 3 63488 _000019_hash NULL
84436 +_000020_hash read_ldt 2 47570 _000020_hash NULL
84437 +_000021_hash read_zero 3 19366 _000021_hash NULL
84438 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
84439 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
84440 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
84441 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
84442 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
84443 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
84444 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
84445 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
84446 +_000031_hash adu_write 3 30487 _000031_hash NULL
84447 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
84448 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
84449 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
84450 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
84451 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
84452 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
84453 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
84454 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
84455 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
84456 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
84457 +_000044_hash alloc_context 1 3194 _000044_hash NULL
84458 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
84459 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
84460 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
84461 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
84462 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
84463 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
84464 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
84465 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
84466 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
84467 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
84468 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
84469 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
84470 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
84471 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
84472 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
84473 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
84474 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
84475 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
84476 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
84477 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
84478 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
84479 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
84480 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
84481 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
84482 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
84483 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
84484 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
84485 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
84486 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
84487 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
84488 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
84489 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
84490 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
84491 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
84492 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
84493 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
84494 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
84495 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
84496 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
84497 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
84498 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
84499 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
84500 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
84501 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
84502 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
84503 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
84504 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
84505 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
84506 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
84507 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
84508 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
84509 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
84510 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
84511 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
84512 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
84513 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
84514 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
84515 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
84516 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
84517 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
84518 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
84519 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
84520 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
84521 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
84522 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
84523 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
84524 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
84525 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
84526 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
84527 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
84528 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
84529 +_000122_hash change_xattr 5 61390 _000122_hash NULL
84530 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
84531 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
84532 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
84533 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
84534 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
84535 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
84536 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
84537 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
84538 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
84539 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
84540 +_000133_hash cmm_write 3 2896 _000133_hash NULL
84541 +_000134_hash cm_write 3 36858 _000134_hash NULL
84542 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
84543 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
84544 +_000137_hash command_file_write 3 31318 _000137_hash NULL
84545 +_000138_hash command_write 3 58841 _000138_hash NULL
84546 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
84547 +_000140_hash concat_writev 3 21451 _000140_hash NULL
84548 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
84549 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
84550 +_000143_hash copy_items 6 50140 _000143_hash NULL
84551 +_000144_hash copy_macs 4 45534 _000144_hash NULL
84552 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
84553 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
84554 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
84555 +_000148_hash cosa_write 3 1774 _000148_hash NULL
84556 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
84557 +_000150_hash create_entry 2 33479 _000150_hash NULL
84558 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
84559 +_000153_hash create_xattr 5 54106 _000153_hash NULL
84560 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
84561 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
84562 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
84563 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
84564 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
84565 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
84566 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
84567 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
84568 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
84569 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
84570 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
84571 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
84572 +_000168_hash dev_config 3 8506 _000168_hash NULL
84573 +_000169_hash device_write 3 45156 _000169_hash NULL
84574 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
84575 +_000171_hash devres_alloc 2 551 _000171_hash NULL
84576 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
84577 +_000173_hash direct_entry 3 38836 _000173_hash NULL
84578 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
84579 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
84580 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
84581 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
84582 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
84583 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
84584 +_000180_hash dm_read 3 15674 _000180_hash NULL
84585 +_000181_hash dm_write 3 2513 _000181_hash NULL
84586 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
84587 +_000183_hash dns_query 3 9676 _000183_hash NULL
84588 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
84589 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
84590 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
84591 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
84592 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
84593 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
84594 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
84595 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
84596 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
84597 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
84598 +_000194_hash dsp_write 2 46218 _000194_hash NULL
84599 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
84600 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
84601 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
84602 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
84603 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
84604 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
84605 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
84606 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
84607 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
84608 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
84609 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
84610 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
84611 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
84612 +_000208_hash ep_read 3 58813 _000208_hash NULL
84613 +_000209_hash ep_write 3 59008 _000209_hash NULL
84614 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
84615 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
84616 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
84617 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
84618 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
84619 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
84620 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
84621 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
84622 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
84623 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
84624 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
84625 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
84626 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
84627 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
84628 +_000225_hash fl_create 5 56435 _000225_hash NULL
84629 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
84630 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
84631 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
84632 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
84633 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
84634 +_000231_hash get_arg 3 5694 _000231_hash NULL
84635 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
84636 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
84637 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
84638 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
84639 +_000236_hash get_registers 3 26187 _000236_hash NULL
84640 +_000237_hash get_scq 2 10897 _000237_hash NULL
84641 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
84642 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
84643 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
84644 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
84645 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
84646 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
84647 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
84648 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
84649 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
84650 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
84651 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
84652 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
84653 +_000250_hash handle_request 9 10024 _000250_hash NULL
84654 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
84655 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
84656 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
84657 +_000254_hash heap_init 2 49617 _000254_hash NULL
84658 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
84659 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
84660 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
84661 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
84662 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
84663 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
84664 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
84665 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
84666 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
84667 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
84668 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
84669 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
84670 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
84671 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
84672 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
84673 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
84674 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
84675 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
84676 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
84677 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
84678 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
84679 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
84680 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
84681 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
84682 +_000279_hash if_write 3 51756 _000279_hash NULL
84683 +_000280_hash ilo_write 3 64378 _000280_hash NULL
84684 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
84685 +_000282_hash init_data_container 1 60709 _000282_hash NULL
84686 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
84687 +_000284_hash insert_dent 7 65034 _000284_hash NULL
84688 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
84689 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
84690 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
84691 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
84692 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
84693 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
84694 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
84695 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
84696 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
84697 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
84698 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
84699 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
84700 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
84701 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
84702 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
84703 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
84704 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
84705 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
84706 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
84707 +_000304_hash isdn_read 3 50021 _000304_hash NULL
84708 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
84709 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
84710 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
84711 +_000308_hash iso_callback 3 43208 _000308_hash NULL
84712 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
84713 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
84714 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
84715 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
84716 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
84717 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
84718 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
84719 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
84720 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
84721 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
84722 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
84723 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
84724 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
84725 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
84726 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
84727 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
84728 +_000328_hash kone_receive 4 4690 _000328_hash NULL
84729 +_000329_hash kone_send 4 63435 _000329_hash NULL
84730 +_000330_hash krealloc 2 14908 _000330_hash NULL
84731 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
84732 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
84733 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
84734 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
84735 +_000335_hash kzalloc 1 54740 _000335_hash NULL
84736 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
84737 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
84738 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
84739 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
84740 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
84741 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
84742 +_000342_hash __lgread 4 31668 _000342_hash NULL
84743 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
84744 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
84745 +_000345_hash listxattr 3 12769 _000345_hash NULL
84746 +_000346_hash load_msg 2 95 _000346_hash NULL
84747 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
84748 +_000348_hash lp_write 3 9511 _000348_hash NULL
84749 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
84750 +_000350_hash mce_write 3 26201 _000350_hash NULL
84751 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
84752 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
84753 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
84754 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
84755 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
84756 +_000357_hash mem_rw 3 22085 _000357_hash NULL
84757 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
84758 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
84759 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
84760 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
84761 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
84762 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
84763 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
84764 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
84765 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
84766 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
84767 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
84768 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
84769 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
84770 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
84771 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
84772 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
84773 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
84774 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
84775 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
84776 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
84777 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
84778 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
84779 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
84780 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
84781 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
84782 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
84783 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
84784 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
84785 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
84786 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
84787 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
84788 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
84789 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
84790 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
84791 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
84792 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
84793 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
84794 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
84795 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
84796 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
84797 +_000404_hash nvram_write 3 3894 _000404_hash NULL
84798 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
84799 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
84800 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
84801 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
84802 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
84803 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
84804 +_000411_hash opticon_write 4 60775 _000411_hash NULL
84805 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
84806 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
84807 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
84808 +_000415_hash parse_command 2 37079 _000415_hash NULL
84809 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
84810 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
84811 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
84812 +_000419_hash pg_write 3 40766 _000419_hash NULL
84813 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
84814 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
84815 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
84816 +_000423_hash pkt_add 3 39897 _000423_hash NULL
84817 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
84818 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
84819 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
84820 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
84821 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
84822 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
84823 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
84824 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
84825 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
84826 +_000433_hash ppp_write 3 34034 _000433_hash NULL
84827 +_000434_hash pp_read 3 33210 _000434_hash NULL
84828 +_000435_hash pp_write 3 39554 _000435_hash NULL
84829 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
84830 +_000437_hash printer_write 3 60276 _000437_hash NULL
84831 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
84832 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
84833 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
84834 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
84835 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
84836 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
84837 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
84838 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
84839 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
84840 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
84841 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
84842 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
84843 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
84844 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
84845 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
84846 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
84847 +_000456_hash pt_write 3 40159 _000456_hash NULL
84848 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
84849 +_000458_hash r3964_write 4 57662 _000458_hash NULL
84850 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
84851 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
84852 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
84853 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
84854 +_000463_hash rbd_add 3 16366 _000463_hash NULL
84855 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
84856 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
84857 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
84858 +_000467_hash read 3 9397 _000467_hash NULL
84859 +_000468_hash read_buf 2 20469 _000468_hash NULL
84860 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
84861 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
84862 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
84863 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
84864 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
84865 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
84866 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
84867 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
84868 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
84869 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
84870 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
84871 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
84872 +_000481_hash revalidate 2 19043 _000481_hash NULL
84873 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
84874 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
84875 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
84876 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
84877 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
84878 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
84879 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
84880 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
84881 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
84882 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
84883 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
84884 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
84885 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
84886 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
84887 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
84888 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
84889 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
84890 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
84891 +_000500_hash savemem 3 58129 _000500_hash NULL
84892 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
84893 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
84894 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
84895 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
84896 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
84897 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
84898 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
84899 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
84900 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
84901 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
84902 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
84903 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
84904 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
84905 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
84906 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
84907 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
84908 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
84909 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
84910 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
84911 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
84912 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
84913 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
84914 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
84915 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
84916 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
84917 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
84918 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
84919 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
84920 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
84921 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
84922 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
84923 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
84924 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
84925 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
84926 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
84927 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
84928 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
84929 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
84930 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
84931 +_000542_hash set_registers 3 53582 _000542_hash NULL
84932 +_000543_hash setsockopt 5 54539 _000543_hash NULL
84933 +_000544_hash setup_req 3 5848 _000544_hash NULL
84934 +_000545_hash setxattr 4 37006 _000545_hash NULL
84935 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
84936 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
84937 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
84938 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
84939 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
84940 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
84941 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
84942 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
84943 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
84944 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
84945 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
84946 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
84947 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
84948 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
84949 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
84950 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
84951 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
84952 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
84953 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
84954 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
84955 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
84956 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
84957 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
84958 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
84959 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
84960 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
84961 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
84962 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
84963 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
84964 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
84965 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
84966 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
84967 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
84968 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
84969 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
84970 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
84971 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
84972 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
84973 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
84974 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
84975 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
84976 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
84977 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
84978 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
84979 +_000592_hash spidev_write 3 44510 _000592_hash NULL
84980 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
84981 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
84982 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
84983 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
84984 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
84985 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
84986 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
84987 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
84988 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
84989 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
84990 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
84991 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
84992 +_000606_hash tower_write 3 8580 _000606_hash NULL
84993 +_000607_hash tpm_write 3 50798 _000607_hash NULL
84994 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
84995 +_000609_hash trusted_update 3 12664 _000609_hash NULL
84996 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
84997 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
84998 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
84999 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
85000 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
85001 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
85002 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
85003 +_000617_hash uea_request 4 47613 _000617_hash NULL
85004 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
85005 +_000619_hash uio_write 3 43202 _000619_hash NULL
85006 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
85007 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
85008 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
85009 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
85010 +_000624_hash usblp_write 3 23178 _000624_hash NULL
85011 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
85012 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
85013 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
85014 +_000629_hash user_update 3 41332 _000629_hash NULL
85015 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
85016 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
85017 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
85018 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
85019 +_000635_hash vcs_write 3 3910 _000635_hash NULL
85020 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
85021 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
85022 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
85023 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
85024 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
85025 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
85026 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
85027 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
85028 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
85029 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
85030 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
85031 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
85032 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
85033 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
85034 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
85035 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
85036 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
85037 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
85038 +_000656_hash wdm_write 3 53735 _000656_hash NULL
85039 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
85040 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
85041 +_000659_hash write 3 62671 _000659_hash NULL
85042 +_000660_hash write_flush 3 50803 _000660_hash NULL
85043 +_000661_hash write_rio 3 54837 _000661_hash NULL
85044 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
85045 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
85046 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
85047 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
85048 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
85049 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
85050 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
85051 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
85052 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
85053 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
85054 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
85055 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
85056 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
85057 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
85058 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
85059 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
85060 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
85061 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
85062 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
85063 +_000683_hash add_res_range 4 21310 _000683_hash NULL
85064 +_000684_hash addtgt 3 54703 _000684_hash NULL
85065 +_000685_hash add_uuid 4 49831 _000685_hash NULL
85066 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
85067 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
85068 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
85069 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
85070 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
85071 +_000691_hash alloc_async 1 14208 _000691_hash NULL
85072 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
85073 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
85074 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
85075 +_000695_hash alloc_context 1 41283 _000695_hash NULL
85076 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
85077 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
85078 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
85079 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
85080 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
85081 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
85082 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
85083 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
85084 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
85085 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
85086 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
85087 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
85088 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
85089 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
85090 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
85091 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
85092 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
85093 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
85094 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
85095 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
85096 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
85097 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
85098 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
85099 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
85100 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
85101 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
85102 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
85103 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
85104 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
85105 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
85106 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
85107 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
85108 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
85109 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
85110 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
85111 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
85112 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
85113 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
85114 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
85115 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
85116 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
85117 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
85118 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
85119 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
85120 +_000746_hash audit_expand 2 2098 _000746_hash NULL
85121 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
85122 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
85123 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
85124 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
85125 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
85126 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
85127 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
85128 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
85129 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
85130 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
85131 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
85132 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
85133 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
85134 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
85135 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
85136 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
85137 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
85138 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
85139 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
85140 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
85141 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
85142 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
85143 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
85144 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
85145 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
85146 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
85147 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
85148 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
85149 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
85150 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
85151 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
85152 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
85153 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
85154 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
85155 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
85156 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
85157 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
85158 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
85159 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
85160 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
85161 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
85162 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
85163 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
85164 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
85165 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
85166 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
85167 +_000799_hash construct_key 3 11329 _000799_hash NULL
85168 +_000800_hash context_alloc 3 24645 _000800_hash NULL
85169 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
85170 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
85171 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
85172 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
85173 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
85174 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
85175 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
85176 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
85177 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
85178 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
85179 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
85180 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
85181 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
85182 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
85183 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
85184 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
85185 +_000819_hash depth_write 3 3021 _000819_hash NULL
85186 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
85187 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
85188 +_000822_hash dev_write 3 7708 _000822_hash NULL
85189 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
85190 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
85191 +_000825_hash disconnect 4 32521 _000825_hash NULL
85192 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
85193 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
85194 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
85195 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
85196 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
85197 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
85198 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
85199 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
85200 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
85201 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
85202 +_000837_hash do_pselect 1 62061 _000837_hash NULL
85203 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
85204 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
85205 +_000840_hash do_sync 1 9604 _000840_hash NULL
85206 +_000841_hash dup_array 3 33551 _000841_hash NULL
85207 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
85208 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
85209 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
85210 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
85211 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
85212 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
85213 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
85214 +_000849_hash enable_write 3 30456 _000849_hash NULL
85215 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
85216 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
85217 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
85218 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
85219 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
85220 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
85221 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
85222 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
85223 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
85224 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
85225 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
85226 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
85227 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
85228 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
85229 +_000864_hash fillonedir 3 41746 _000864_hash NULL
85230 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
85231 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
85232 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
85233 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
85234 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
85235 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
85236 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
85237 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
85238 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
85239 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
85240 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
85241 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
85242 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
85243 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
85244 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
85245 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
85246 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
85247 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
85248 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
85249 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
85250 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
85251 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
85252 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
85253 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
85254 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
85255 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
85256 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
85257 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
85258 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
85259 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
85260 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
85261 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
85262 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
85263 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
85264 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
85265 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
85266 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
85267 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
85268 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
85269 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
85270 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
85271 +_000909_hash if_writecmd 2 815 _000909_hash NULL
85272 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
85273 +_000912_hash init_ipath 1 48187 _000912_hash NULL
85274 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
85275 +_000915_hash init_q 4 132 _000915_hash NULL
85276 +_000916_hash init_state 2 60165 _000916_hash NULL
85277 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
85278 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
85279 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
85280 +_000920_hash interfaces 2 38859 _000920_hash NULL
85281 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
85282 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
85283 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
85284 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
85285 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
85286 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
85287 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
85288 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
85289 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
85290 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
85291 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
85292 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
85293 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
85294 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
85295 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
85296 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
85297 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
85298 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
85299 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
85300 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
85301 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
85302 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
85303 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
85304 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
85305 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
85306 +_000948_hash isdn_write 3 45863 _000948_hash NULL
85307 +_000949_hash isku_receive 4 54130 _000949_hash NULL
85308 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
85309 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
85310 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
85311 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
85312 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
85313 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
85314 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
85315 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
85316 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
85317 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
85318 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
85319 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
85320 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
85321 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
85322 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
85323 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
85324 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
85325 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
85326 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
85327 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
85328 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
85329 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
85330 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
85331 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
85332 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
85333 +_000977_hash lc_create 3 48662 _000977_hash NULL
85334 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
85335 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
85336 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
85337 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
85338 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
85339 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
85340 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
85341 +_000985_hash mem_read 3 57631 _000985_hash NULL
85342 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
85343 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
85344 +_000988_hash mem_write 3 22232 _000988_hash NULL
85345 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
85346 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
85347 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
85348 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
85349 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
85350 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
85351 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
85352 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
85353 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
85354 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
85355 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
85356 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
85357 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
85358 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
85359 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
85360 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
85361 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
85362 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
85363 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
85364 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
85365 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
85366 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
85367 +_001014_hash new_dir 3 31919 _001014_hash NULL
85368 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
85369 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
85370 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
85371 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
85372 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
85373 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
85374 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
85375 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
85376 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
85377 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
85378 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
85379 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
85380 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
85381 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
85382 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
85383 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
85384 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
85385 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
85386 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
85387 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
85388 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
85389 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
85390 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
85391 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
85392 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
85393 +_001046_hash osst_write 3 31581 _001046_hash NULL
85394 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
85395 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
85396 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
85397 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
85398 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
85399 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
85400 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
85401 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
85402 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
85403 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
85404 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
85405 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
85406 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
85407 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
85408 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
85409 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
85410 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
85411 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
85412 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
85413 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
85414 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
85415 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
85416 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
85417 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
85418 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
85419 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
85420 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
85421 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
85422 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
85423 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
85424 +_001083_hash proc_write 3 51003 _001083_hash NULL
85425 +_001084_hash profile_load 3 58267 _001084_hash NULL
85426 +_001085_hash profile_remove 3 8556 _001085_hash NULL
85427 +_001086_hash profile_replace 3 14652 _001086_hash NULL
85428 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
85429 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
85430 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
85431 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
85432 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
85433 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
85434 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
85435 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
85436 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
85437 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
85438 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
85439 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
85440 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
85441 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
85442 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
85443 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
85444 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
85445 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
85446 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
85447 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
85448 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
85449 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
85450 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
85451 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
85452 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
85453 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
85454 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
85455 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
85456 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
85457 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
85458 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
85459 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
85460 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
85461 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
85462 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
85463 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
85464 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
85465 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
85466 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
85467 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
85468 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
85469 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
85470 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
85471 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
85472 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
85473 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
85474 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
85475 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
85476 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
85477 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
85478 +_001139_hash self_check_write 5 50856 _001139_hash NULL
85479 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
85480 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
85481 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
85482 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
85483 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
85484 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
85485 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
85486 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
85487 +_001148_hash set_connectable 4 56458 _001148_hash NULL
85488 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
85489 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
85490 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
85491 +_001152_hash setkey 3 14987 _001152_hash NULL
85492 +_001153_hash set_le 4 30581 _001153_hash NULL
85493 +_001154_hash set_link_security 4 4502 _001154_hash NULL
85494 +_001155_hash set_local_name 4 55757 _001155_hash NULL
85495 +_001156_hash set_powered 4 12129 _001156_hash NULL
85496 +_001157_hash set_ssp 4 62411 _001157_hash NULL
85497 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
85498 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
85499 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
85500 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
85501 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
85502 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
85503 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
85504 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
85505 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
85506 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
85507 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
85508 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
85509 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
85510 +_001174_hash skb_pad 2 17302 _001174_hash NULL
85511 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
85512 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
85513 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
85514 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
85515 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
85516 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
85517 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
85518 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
85519 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
85520 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
85521 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
85522 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
85523 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
85524 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
85525 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
85526 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
85527 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
85528 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
85529 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
85530 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
85531 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
85532 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
85533 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
85534 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
85535 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
85536 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
85537 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
85538 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
85539 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
85540 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
85541 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
85542 +_001208_hash sound_write 3 5102 _001208_hash NULL
85543 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
85544 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
85545 +_001213_hash spidev_message 3 5518 _001213_hash NULL
85546 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
85547 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
85548 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
85549 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
85550 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
85551 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
85552 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
85553 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
85554 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
85555 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
85556 +_001227_hash st_write 3 16874 _001227_hash NULL
85557 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
85558 +_001229_hash symtab_init 2 61050 _001229_hash NULL
85559 +_001230_hash sys_bind 3 10799 _001230_hash NULL
85560 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
85561 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
85562 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
85563 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
85564 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
85565 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
85566 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
85567 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
85568 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
85569 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
85570 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
85571 +_001242_hash sys_select 1 38827 _001242_hash NULL
85572 +_001243_hash sys_semop 3 39457 _001243_hash NULL
85573 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
85574 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
85575 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
85576 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
85577 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
85578 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
85579 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
85580 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
85581 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
85582 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
85583 +_001254_hash timeout_write 3 50991 _001254_hash NULL
85584 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
85585 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
85586 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
85587 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
85588 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
85589 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
85590 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
85591 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
85592 +_001264_hash tty_write 3 5494 _001264_hash NULL
85593 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
85594 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
85595 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
85596 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
85597 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
85598 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
85599 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
85600 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
85601 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
85602 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
85603 +_001277_hash vhci_write 3 2224 _001277_hash NULL
85604 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
85605 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
85606 +_001281_hash vmalloc 1 15464 _001281_hash NULL
85607 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
85608 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
85609 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
85610 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
85611 +_001286_hash vzalloc 1 47421 _001286_hash NULL
85612 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
85613 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
85614 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
85615 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
85616 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
85617 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
85618 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
85619 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
85620 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
85621 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
85622 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
85623 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
85624 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
85625 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
85626 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
85627 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
85628 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
85629 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
85630 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
85631 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
85632 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
85633 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
85634 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
85635 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
85636 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
85637 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
85638 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
85639 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
85640 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
85641 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
85642 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
85643 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
85644 +_001319_hash add_child 4 45201 _001319_hash NULL
85645 +_001320_hash add_port 2 54941 _001320_hash NULL
85646 +_001321_hash adu_read 3 24177 _001321_hash NULL
85647 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
85648 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
85649 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
85650 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
85651 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
85652 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
85653 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
85654 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
85655 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
85656 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
85657 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
85658 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
85659 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
85660 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
85661 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
85662 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
85663 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
85664 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
85665 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
85666 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
85667 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
85668 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
85669 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
85670 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
85671 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
85672 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
85673 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
85674 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
85675 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
85676 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
85677 +_001356_hash async_setkey 3 35521 _001356_hash NULL
85678 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
85679 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
85680 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
85681 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
85682 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
85683 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
85684 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
85685 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
85686 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
85687 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
85688 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
85689 +_001370_hash ax25_output 2 22736 _001370_hash NULL
85690 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
85691 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
85692 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
85693 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
85694 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
85695 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
85696 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
85697 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
85698 +_001380_hash bm_init 2 13529 _001380_hash NULL
85699 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
85700 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
85701 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
85702 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
85703 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
85704 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
85705 +_001387_hash cache_read 3 24790 _001387_hash NULL
85706 +_001388_hash cache_write 3 13589 _001388_hash NULL
85707 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
85708 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
85709 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
85710 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
85711 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
85712 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
85713 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
85714 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
85715 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
85716 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
85717 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
85718 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
85719 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
85720 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
85721 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
85722 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
85723 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
85724 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
85725 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
85726 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
85727 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
85728 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
85729 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
85730 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
85731 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
85732 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
85733 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
85734 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
85735 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
85736 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
85737 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
85738 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
85739 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
85740 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
85741 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
85742 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
85743 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
85744 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
85745 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
85746 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
85747 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
85748 +_001435_hash do_readlink 2 43518 _001435_hash NULL
85749 +_001436_hash __do_replace 5 37227 _001436_hash NULL
85750 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
85751 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
85752 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
85753 +_001440_hash dump_midi 3 51040 _001440_hash NULL
85754 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
85755 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
85756 +_001443_hash ep0_read 3 38095 _001443_hash NULL
85757 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
85758 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
85759 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
85760 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
85761 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
85762 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
85763 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
85764 +_001451_hash filldir 3 55137 _001451_hash NULL
85765 +_001452_hash filldir64 3 46469 _001452_hash NULL
85766 +_001453_hash find_skb 2 20431 _001453_hash NULL
85767 +_001454_hash from_buffer 3 18625 _001454_hash NULL
85768 +_001455_hash fsm_init 2 16134 _001455_hash NULL
85769 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
85770 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
85771 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
85772 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
85773 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
85774 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
85775 +_001462_hash get_packet 3 41914 _001462_hash NULL
85776 +_001463_hash get_packet 3 5747 _001463_hash NULL
85777 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
85778 +_001465_hash get_skb 2 63008 _001465_hash NULL
85779 +_001466_hash get_subdir 3 62581 _001466_hash NULL
85780 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
85781 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
85782 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
85783 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
85784 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
85785 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
85786 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
85787 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
85788 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
85789 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
85790 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
85791 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
85792 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
85793 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
85794 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
85795 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
85796 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
85797 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
85798 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
85799 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
85800 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
85801 +_001489_hash ilo_read 3 32531 _001489_hash NULL
85802 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
85803 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
85804 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
85805 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
85806 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
85807 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
85808 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
85809 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
85810 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
85811 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
85812 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
85813 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
85814 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
85815 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
85816 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
85817 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
85818 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
85819 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
85820 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
85821 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
85822 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
85823 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
85824 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
85825 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
85826 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
85827 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
85828 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
85829 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
85830 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
85831 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
85832 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
85833 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
85834 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
85835 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
85836 +_001530_hash keyring_read 3 13438 _001530_hash NULL
85837 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
85838 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
85839 +_001533_hash kmp_init 2 41373 _001533_hash NULL
85840 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
85841 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
85842 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
85843 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
85844 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
85845 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
85846 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
85847 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
85848 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
85849 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
85850 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
85851 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
85852 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
85853 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
85854 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
85855 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
85856 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
85857 +_001552_hash mempool_create 1 29437 _001552_hash NULL
85858 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
85859 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
85860 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
85861 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
85862 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
85863 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
85864 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
85865 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
85866 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
85867 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
85868 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
85869 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
85870 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
85871 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
85872 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
85873 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
85874 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
85875 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
85876 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
85877 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
85878 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
85879 +_001575_hash new_skb 1 21148 _001575_hash NULL
85880 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
85881 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
85882 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
85883 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
85884 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
85885 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
85886 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
85887 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
85888 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
85889 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
85890 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
85891 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
85892 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
85893 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
85894 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
85895 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
85896 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
85897 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
85898 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
85899 +_001599_hash override_release 2 52032 _001599_hash NULL
85900 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
85901 +_001601_hash packet_snd 3 13634 _001601_hash NULL
85902 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
85903 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
85904 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
85905 +_001605_hash pg_read 3 17276 _001605_hash NULL
85906 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
85907 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
85908 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
85909 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
85910 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
85911 +_001611_hash printer_read 3 54851 _001611_hash NULL
85912 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
85913 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
85914 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
85915 +_001615_hash ptp_read 4 63251 _001615_hash NULL
85916 +_001616_hash pt_read 3 49136 _001616_hash NULL
85917 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
85918 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
85919 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
85920 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
85921 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
85922 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
85923 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
85924 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
85925 +_001625_hash read_flush 3 43851 _001625_hash NULL
85926 +_001626_hash read_profile 3 27859 _001626_hash NULL
85927 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
85928 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
85929 +_001629_hash refill_pool 2 19477 _001629_hash NULL
85930 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
85931 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
85932 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
85933 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
85934 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
85935 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
85936 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
85937 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
85938 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
85939 +_001640_hash rx 4 57944 _001640_hash NULL
85940 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
85941 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
85942 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
85943 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
85944 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
85945 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
85946 +_001647_hash scsi_register 2 49094 _001647_hash NULL
85947 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
85948 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
85949 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
85950 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
85951 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
85952 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
85953 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
85954 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
85955 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
85956 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
85957 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
85958 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
85959 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
85960 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
85961 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
85962 +_001663_hash send_command 4 10832 _001663_hash NULL
85963 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
85964 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
85965 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
85966 +_001667_hash set_arg 3 42824 _001667_hash NULL
85967 +_001668_hash sg_read 3 25799 _001668_hash NULL
85968 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
85969 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
85970 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
85971 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
85972 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
85973 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
85974 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
85975 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
85976 +_001680_hash skb_cow 2 26138 _001680_hash NULL
85977 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
85978 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
85979 +_001683_hash skb_padto 2 50759 _001683_hash NULL
85980 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
85981 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
85982 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
85983 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
85984 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
85985 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
85986 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
85987 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
85988 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
85989 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
85990 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
85991 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
85992 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
85993 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
85994 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
85995 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
85996 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
85997 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
85998 +_001704_hash store_msg 3 56417 _001704_hash NULL
85999 +_001705_hash str_to_user 2 11411 _001705_hash NULL
86000 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
86001 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
86002 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
86003 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
86004 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
86005 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
86006 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
86007 +_001713_hash syslog_print 2 307 _001713_hash NULL
86008 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
86009 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
86010 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
86011 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
86012 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
86013 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
86014 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
86015 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
86016 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
86017 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
86018 +_001727_hash team_options_register 3 20091 _001727_hash NULL
86019 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
86020 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
86021 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
86022 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
86023 +_001732_hash tipc_send 4 51238 _001732_hash NULL
86024 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
86025 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
86026 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
86027 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
86028 +_001737_hash tpm_read 3 50344 _001737_hash NULL
86029 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
86030 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
86031 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
86032 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
86033 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
86034 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
86035 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
86036 +_001746_hash uio_read 3 49300 _001746_hash NULL
86037 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
86038 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
86039 +_001749_hash unlink1 3 63059 _001749_hash NULL
86040 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
86041 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
86042 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
86043 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
86044 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
86045 +_001756_hash user_read 3 51881 _001756_hash NULL
86046 +_001757_hash vcs_read 3 8017 _001757_hash NULL
86047 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
86048 +_001759_hash venus_create 4 20555 _001759_hash NULL
86049 +_001760_hash venus_link 5 32165 _001760_hash NULL
86050 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
86051 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
86052 +_001763_hash venus_remove 4 59781 _001763_hash NULL
86053 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
86054 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
86055 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
86056 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
86057 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
86058 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
86059 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
86060 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
86061 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
86062 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
86063 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
86064 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
86065 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
86066 +_001780_hash wdm_read 3 6549 _001780_hash NULL
86067 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
86068 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
86069 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
86070 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
86071 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
86072 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
86073 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
86074 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
86075 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
86076 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
86077 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
86078 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
86079 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
86080 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
86081 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
86082 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
86083 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
86084 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
86085 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
86086 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
86087 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
86088 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
86089 +_001803_hash add_partition 2 55588 _001803_hash NULL
86090 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
86091 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
86092 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
86093 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
86094 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
86095 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
86096 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
86097 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
86098 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
86099 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
86100 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
86101 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
86102 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
86103 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
86104 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
86105 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
86106 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
86107 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
86108 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
86109 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
86110 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
86111 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
86112 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
86113 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
86114 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
86115 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
86116 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
86117 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
86118 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
86119 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
86120 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
86121 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
86122 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
86123 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
86124 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
86125 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
86126 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
86127 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
86128 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
86129 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
86130 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
86131 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
86132 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
86133 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
86134 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
86135 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
86136 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
86137 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
86138 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
86139 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
86140 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
86141 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
86142 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
86143 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
86144 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
86145 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
86146 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
86147 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
86148 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
86149 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
86150 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
86151 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
86152 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
86153 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
86154 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
86155 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
86156 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
86157 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
86158 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
86159 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
86160 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
86161 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
86162 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
86163 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
86164 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
86165 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
86166 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
86167 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
86168 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
86169 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
86170 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
86171 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
86172 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
86173 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
86174 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
86175 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
86176 +_001892_hash check_header 2 56930 _001892_hash NULL
86177 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
86178 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
86179 +_001895_hash console_store 4 36007 _001895_hash NULL
86180 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
86181 +_001897_hash create_subvol 4 30836 _001897_hash NULL
86182 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
86183 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
86184 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
86185 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
86186 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
86187 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
86188 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
86189 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
86190 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
86191 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
86192 +_001912_hash debug_output 3 18575 _001912_hash NULL
86193 +_001913_hash debug_read 3 19322 _001913_hash NULL
86194 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
86195 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
86196 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
86197 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
86198 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
86199 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
86200 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
86201 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
86202 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
86203 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
86204 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
86205 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
86206 +_001927_hash do_syslog 3 56807 _001927_hash NULL
86207 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
86208 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
86209 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
86210 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
86211 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
86212 +_001933_hash filter_read 3 61692 _001933_hash NULL
86213 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
86214 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
86215 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
86216 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
86217 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
86218 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
86219 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
86220 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
86221 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
86222 +_001943_hash handle_response 5 55951 _001943_hash NULL
86223 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
86224 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
86225 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
86226 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
86227 +_001948_hash help 4 14971 _001948_hash NULL
86228 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
86229 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
86230 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
86231 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
86232 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
86233 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
86234 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
86235 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
86236 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
86237 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
86238 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
86239 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
86240 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
86241 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
86242 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
86243 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
86244 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
86245 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
86246 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
86247 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
86248 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
86249 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
86250 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
86251 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
86252 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
86253 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
86254 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
86255 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
86256 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
86257 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
86258 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
86259 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
86260 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
86261 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
86262 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
86263 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
86264 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
86265 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
86266 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
86267 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
86268 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
86269 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
86270 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
86271 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
86272 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
86273 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
86274 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
86275 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
86276 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
86277 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
86278 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
86279 +_002001_hash ipw_write 3 59807 _002001_hash NULL
86280 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
86281 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
86282 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
86283 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
86284 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
86285 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
86286 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
86287 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
86288 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
86289 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
86290 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
86291 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
86292 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
86293 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
86294 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
86295 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
86296 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
86297 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
86298 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
86299 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
86300 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
86301 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
86302 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
86303 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
86304 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
86305 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
86306 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
86307 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
86308 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
86309 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
86310 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
86311 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
86312 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
86313 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
86314 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
86315 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
86316 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
86317 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
86318 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
86319 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
86320 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
86321 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
86322 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
86323 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
86324 +_002046_hash key_key_read 3 3241 _002046_hash NULL
86325 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
86326 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
86327 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
86328 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
86329 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
86330 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
86331 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
86332 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
86333 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
86334 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
86335 +_002058_hash l2down_create 4 21755 _002058_hash NULL
86336 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
86337 +_002060_hash l2up_create 3 6430 _002060_hash NULL
86338 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
86339 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
86340 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
86341 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
86342 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
86343 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
86344 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
86345 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
86346 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
86347 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
86348 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
86349 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
86350 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
86351 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
86352 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
86353 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
86354 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
86355 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
86356 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
86357 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
86358 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
86359 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
86360 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
86361 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
86362 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
86363 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
86364 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
86365 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
86366 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
86367 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
86368 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
86369 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
86370 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
86371 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
86372 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
86373 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
86374 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
86375 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
86376 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
86377 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
86378 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
86379 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
86380 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
86381 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
86382 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
86383 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
86384 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
86385 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
86386 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
86387 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
86388 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
86389 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
86390 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
86391 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
86392 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
86393 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
86394 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
86395 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
86396 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
86397 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
86398 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
86399 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
86400 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
86401 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
86402 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
86403 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
86404 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
86405 +_002136_hash osst_read 3 40237 _002136_hash NULL
86406 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
86407 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
86408 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
86409 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
86410 +_002143_hash page_readlink 3 23346 _002143_hash NULL
86411 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
86412 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
86413 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
86414 +_002148_hash pep_reply 5 50582 _002148_hash NULL
86415 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
86416 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
86417 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
86418 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
86419 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
86420 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
86421 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
86422 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
86423 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
86424 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
86425 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
86426 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
86427 +_002161_hash proc_read 3 43614 _002161_hash NULL
86428 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
86429 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
86430 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
86431 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
86432 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
86433 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
86434 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
86435 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
86436 +_002170_hash queues_read 3 24877 _002170_hash NULL
86437 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
86438 +_002172_hash rcname_read 3 25919 _002172_hash NULL
86439 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
86440 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
86441 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
86442 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
86443 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
86444 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
86445 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
86446 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
86447 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
86448 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
86449 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
86450 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
86451 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
86452 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
86453 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
86454 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
86455 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
86456 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
86457 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
86458 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
86459 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
86460 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
86461 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
86462 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
86463 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
86464 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
86465 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
86466 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
86467 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
86468 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
86469 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
86470 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
86471 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
86472 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
86473 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
86474 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
86475 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
86476 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
86477 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
86478 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
86479 +_002213_hash receive_packet 2 12367 _002213_hash NULL
86480 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
86481 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
86482 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
86483 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
86484 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
86485 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
86486 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
86487 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
86488 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
86489 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
86490 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
86491 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
86492 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
86493 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
86494 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
86495 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
86496 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
86497 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
86498 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
86499 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
86500 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
86501 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
86502 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
86503 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
86504 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
86505 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
86506 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
86507 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
86508 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
86509 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
86510 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
86511 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
86512 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
86513 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
86514 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
86515 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
86516 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
86517 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
86518 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
86519 +_002254_hash send_msg 4 37323 _002254_hash NULL
86520 +_002255_hash send_packet 4 52960 _002255_hash NULL
86521 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
86522 +_002257_hash sge_rx 3 50594 _002257_hash NULL
86523 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
86524 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
86525 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
86526 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
86527 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
86528 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
86529 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
86530 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
86531 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
86532 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
86533 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
86534 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
86535 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
86536 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
86537 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
86538 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
86539 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
86540 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
86541 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
86542 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
86543 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
86544 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
86545 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
86546 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
86547 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
86548 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
86549 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
86550 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
86551 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
86552 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
86553 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
86554 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
86555 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
86556 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
86557 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
86558 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
86559 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
86560 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
86561 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
86562 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
86563 +_002306_hash st_read 3 51251 _002306_hash NULL
86564 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
86565 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
86566 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
86567 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
86568 +_002311_hash sys_readv 3 50664 _002311_hash NULL
86569 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
86570 +_002313_hash sys_writev 3 28384 _002313_hash NULL
86571 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
86572 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
86573 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
86574 +_002317_hash teiup_create 3 43201 _002317_hash NULL
86575 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
86576 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
86577 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
86578 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
86579 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
86580 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
86581 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
86582 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
86583 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
86584 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
86585 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
86586 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
86587 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
86588 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
86589 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
86590 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
86591 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
86592 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
86593 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
86594 +_002341_hash um_idi_read 3 850 _002341_hash NULL
86595 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
86596 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
86597 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
86598 +_002345_hash use_pool 2 64607 _002345_hash NULL
86599 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
86600 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
86601 +_002348_hash vhci_read 3 47878 _002348_hash NULL
86602 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
86603 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
86604 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
86605 +_002353_hash waiters_read 3 40902 _002353_hash NULL
86606 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
86607 +_002355_hash write_pbl 4 59583 _002355_hash NULL
86608 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
86609 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
86610 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
86611 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
86612 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
86613 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
86614 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
86615 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
86616 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
86617 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
86618 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
86619 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
86620 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
86621 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
86622 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
86623 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
86624 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
86625 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
86626 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
86627 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
86628 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
86629 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
86630 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
86631 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
86632 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
86633 +_002382_hash bioset_create 1 5580 _002382_hash NULL
86634 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
86635 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
86636 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
86637 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
86638 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
86639 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
86640 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
86641 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
86642 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
86643 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
86644 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
86645 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
86646 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
86647 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
86648 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
86649 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
86650 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
86651 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
86652 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
86653 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
86654 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
86655 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
86656 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
86657 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
86658 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
86659 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
86660 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
86661 +_002411_hash depth_read 3 31112 _002411_hash NULL
86662 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
86663 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
86664 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
86665 +_002415_hash divas_write 3 63901 _002415_hash NULL
86666 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
86667 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
86668 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
86669 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
86670 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
86671 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
86672 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
86673 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
86674 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
86675 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
86676 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
86677 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
86678 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
86679 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
86680 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
86681 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
86682 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
86683 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
86684 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
86685 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
86686 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
86687 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
86688 +_002439_hash got_frame 2 16028 _002439_hash NULL
86689 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
86690 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
86691 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
86692 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
86693 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
86694 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
86695 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
86696 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
86697 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
86698 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
86699 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
86700 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
86701 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
86702 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
86703 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
86704 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
86705 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
86706 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
86707 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
86708 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
86709 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
86710 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
86711 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
86712 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
86713 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
86714 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
86715 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
86716 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
86717 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
86718 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
86719 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
86720 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
86721 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
86722 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
86723 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
86724 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
86725 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
86726 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
86727 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
86728 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
86729 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
86730 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
86731 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
86732 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
86733 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
86734 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
86735 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
86736 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
86737 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
86738 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
86739 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
86740 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
86741 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
86742 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
86743 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
86744 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
86745 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
86746 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
86747 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
86748 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
86749 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
86750 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
86751 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
86752 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
86753 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
86754 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
86755 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
86756 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
86757 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
86758 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
86759 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
86760 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
86761 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
86762 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
86763 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
86764 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
86765 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
86766 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
86767 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
86768 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
86769 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
86770 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
86771 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
86772 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
86773 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
86774 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
86775 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
86776 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
86777 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
86778 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
86779 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
86780 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
86781 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
86782 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
86783 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
86784 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
86785 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
86786 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
86787 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
86788 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
86789 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
86790 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
86791 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
86792 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
86793 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
86794 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
86795 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
86796 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
86797 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
86798 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
86799 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
86800 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
86801 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
86802 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
86803 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
86804 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
86805 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
86806 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
86807 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
86808 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
86809 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
86810 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
86811 +_002570_hash map_addr 6 4666 _002570_hash NULL
86812 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
86813 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
86814 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
86815 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
86816 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
86817 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
86818 +_002577_hash named_distribute 4 48544 _002577_hash NULL
86819 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
86820 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
86821 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
86822 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
86823 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
86824 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
86825 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
86826 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
86827 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
86828 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
86829 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
86830 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
86831 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
86832 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
86833 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
86834 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
86835 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
86836 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
86837 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
86838 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
86839 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
86840 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
86841 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
86842 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
86843 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
86844 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
86845 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
86846 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
86847 +_002612_hash power_read 3 15939 _002612_hash NULL
86848 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
86849 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
86850 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
86851 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
86852 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
86853 +_002618_hash prison_create 1 43623 _002618_hash NULL
86854 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
86855 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
86856 +_002621_hash _queue_data 4 54983 _002621_hash NULL
86857 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
86858 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
86859 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
86860 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
86861 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
86862 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
86863 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
86864 +_002629_hash read_dma 3 55086 _002629_hash NULL
86865 +_002630_hash read_fifo 3 826 _002630_hash NULL
86866 +_002631_hash read_tree_block 3 841 _002631_hash NULL
86867 +_002632_hash receive_copy 3 12216 _002632_hash NULL
86868 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
86869 +_002635_hash recv_msg 4 48709 _002635_hash NULL
86870 +_002636_hash recv_stream 4 30138 _002636_hash NULL
86871 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
86872 +_002638_hash request_key_async 4 6990 _002638_hash NULL
86873 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
86874 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
86875 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
86876 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
86877 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
86878 +_002644_hash rx_data 4 60442 _002644_hash NULL
86879 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
86880 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
86881 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
86882 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
86883 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
86884 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
86885 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
86886 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
86887 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
86888 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
86889 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
86890 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
86891 +_002658_hash send_stream 4 3397 _002658_hash NULL
86892 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
86893 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
86894 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
86895 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
86896 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
86897 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
86898 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
86899 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
86900 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
86901 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
86902 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
86903 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
86904 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
86905 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
86906 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
86907 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
86908 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
86909 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
86910 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
86911 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
86912 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
86913 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
86914 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
86915 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
86916 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
86917 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
86918 +_002690_hash timeout_read 3 47915 _002690_hash NULL
86919 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
86920 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
86921 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
86922 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
86923 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
86924 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
86925 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
86926 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
86927 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
86928 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
86929 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
86930 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
86931 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
86932 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
86933 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
86934 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
86935 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
86936 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
86937 +_002711_hash user_power_read 3 39414 _002711_hash NULL
86938 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
86939 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
86940 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
86941 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
86942 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
86943 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
86944 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
86945 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
86946 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
86947 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
86948 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
86949 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
86950 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
86951 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
86952 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
86953 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
86954 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
86955 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
86956 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
86957 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
86958 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
86959 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
86960 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
86961 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
86962 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
86963 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
86964 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
86965 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
86966 +_002740_hash do_trimming 3 26952 _002740_hash NULL
86967 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
86968 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
86969 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
86970 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
86971 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
86972 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
86973 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
86974 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
86975 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
86976 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
86977 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
86978 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
86979 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
86980 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
86981 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
86982 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
86983 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
86984 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
86985 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
86986 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
86987 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
86988 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
86989 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
86990 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
86991 +_002770_hash push_rx 3 28939 _002770_hash NULL
86992 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
86993 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
86994 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
86995 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
86996 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
86997 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
86998 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
86999 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
87000 +_002781_hash spi_execute 5 28736 _002781_hash NULL
87001 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
87002 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
87003 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
87004 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
87005 +_002786_hash ti_recv 4 22027 _002786_hash NULL
87006 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
87007 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
87008 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
87009 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
87010 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
87011 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
87012 +_002794_hash write_leb 5 36957 _002794_hash NULL
87013 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
87014 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
87015 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
87016 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
87017 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
87018 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
87019 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
87020 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
87021 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
87022 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
87023 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
87024 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
87025 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
87026 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
87027 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
87028 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
87029 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
87030 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
87031 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
87032 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
87033 +_002820_hash lock_loop 1 61681 _002820_hash NULL
87034 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
87035 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
87036 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
87037 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
87038 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
87039 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
87040 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
87041 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
87042 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
87043 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
87044 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
87045 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
87046 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
87047 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
87048 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
87049 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
87050 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
87051 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
87052 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
87053 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
87054 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
87055 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
87056 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
87057 +_002846_hash recover_head 3 17904 _002846_hash NULL
87058 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
87059 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
87060 +_002849_hash tcp_push 3 10680 _002849_hash NULL
87061 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
87062 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
87063 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
87064 +_002853_hash write_head 4 30481 _002853_hash NULL
87065 +_002854_hash write_node 4 33121 _002854_hash NULL
87066 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
87067 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
87068 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
87069 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
87070 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
87071 +_002861_hash amthi_read 4 45831 _002861_hash NULL
87072 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
87073 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
87074 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
87075 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
87076 +_002866_hash card_send_command 3 40757 _002866_hash NULL
87077 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
87078 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
87079 +_002869_hash create_log 2 8225 _002869_hash NULL
87080 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
87081 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
87082 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
87083 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
87084 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
87085 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
87086 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
87087 +_002877_hash fir16_create 3 5574 _002877_hash NULL
87088 +_002878_hash get_nodes 3 39012 _002878_hash NULL
87089 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
87090 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
87091 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
87092 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
87093 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
87094 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
87095 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
87096 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
87097 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
87098 +_002889_hash keymap_store 4 45406 _002889_hash NULL
87099 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
87100 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
87101 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
87102 +_002893_hash _malloc 1 54077 _002893_hash NULL
87103 +_002894_hash mei_read 3 6507 _002894_hash NULL
87104 +_002895_hash mei_write 3 4005 _002895_hash NULL
87105 +_002896_hash msg_set 3 51725 _002896_hash NULL
87106 +_002897_hash newpart 6 47485 _002897_hash NULL
87107 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
87108 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
87109 +_002900_hash packet_came 3 18072 _002900_hash NULL
87110 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
87111 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
87112 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
87113 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
87114 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
87115 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
87116 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
87117 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
87118 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
87119 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
87120 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
87121 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
87122 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
87123 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
87124 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
87125 +_002923_hash sep_read 3 17161 _002923_hash NULL
87126 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
87127 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
87128 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
87129 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
87130 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
87131 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
87132 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
87133 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
87134 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
87135 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
87136 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
87137 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
87138 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
87139 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
87140 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
87141 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
87142 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
87143 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
87144 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
87145 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
87146 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
87147 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
87148 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
87149 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
87150 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
87151 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
87152 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
87153 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
87154 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
87155 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
87156 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
87157 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
87158 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
87159 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
87160 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
87161 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
87162 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
87163 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
87164 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
87165 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
87166 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
87167 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
87168 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
87169 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
87170 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
87171 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
87172 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
87173 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
87174 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
87175 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
87176 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
87177 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
87178 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
87179 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
87180 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
87181 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
87182 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
87183 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
87184 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
87185 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
87186 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
87187 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
87188 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
87189 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
87190 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
87191 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
87192 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
87193 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
87194 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
87195 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
87196 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
87197 +_003003_hash flash_read 3 57843 _003003_hash NULL
87198 +_003004_hash flash_write 3 62354 _003004_hash NULL
87199 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
87200 +_003006_hash gather_array 3 56641 _003006_hash NULL
87201 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
87202 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
87203 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
87204 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
87205 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
87206 +_003013_hash init_cdev 1 8274 _003013_hash NULL
87207 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
87208 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
87209 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
87210 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
87211 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
87212 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
87213 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
87214 +_003021_hash options_write 3 47243 _003021_hash NULL
87215 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
87216 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
87217 +_003024_hash portnames_read 3 41958 _003024_hash NULL
87218 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
87219 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
87220 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
87221 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
87222 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
87223 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
87224 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
87225 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
87226 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
87227 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
87228 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
87229 +_003036_hash queue_reply 3 22416 _003036_hash NULL
87230 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
87231 +_003038_hash split 2 11691 _003038_hash NULL
87232 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
87233 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
87234 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
87235 +_003042_hash tunables_read 3 36385 _003042_hash NULL
87236 +_003043_hash tunables_write 3 59563 _003043_hash NULL
87237 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
87238 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
87239 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
87240 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
87241 +_003049_hash xsd_read 3 15653 _003049_hash NULL
87242 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
87243 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
87244 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
87245 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
87246 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
87247 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
87248 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
87249 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
87250 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
87251 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
87252 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
87253 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
87254 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
87255 +_003064_hash compat_readv 3 30273 _003064_hash NULL
87256 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
87257 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
87258 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
87259 +_003070_hash compat_writev 3 60063 _003070_hash NULL
87260 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
87261 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
87262 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
87263 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
87264 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
87265 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
87266 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
87267 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
87268 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
87269 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
87270 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
87271 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
87272 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
87273 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
87274 +_003085_hash agp_remap 2 30665 _003085_hash NULL
87275 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
87276 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
87277 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
87278 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
87279 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
87280 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
87281 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
87282 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
87283 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
87284 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
87285 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
87286 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
87287 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
87288 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
87289 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
87290 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
87291 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
87292 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
87293 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
87294 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
87295 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
87296 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
87297 +_003108_hash conf_read 3 55786 _003108_hash NULL
87298 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
87299 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
87300 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
87301 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
87302 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
87303 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
87304 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
87305 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
87306 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
87307 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
87308 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
87309 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
87310 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
87311 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
87312 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
87313 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
87314 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
87315 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
87316 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
87317 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
87318 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
87319 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
87320 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
87321 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
87322 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
87323 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
87324 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
87325 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
87326 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
87327 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
87328 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
87329 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
87330 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
87331 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
87332 +_003146_hash dvb_play 3 50814 _003146_hash NULL
87333 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
87334 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
87335 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
87336 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
87337 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
87338 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
87339 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
87340 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
87341 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
87342 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
87343 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
87344 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
87345 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
87346 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
87347 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
87348 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
87349 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
87350 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
87351 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
87352 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
87353 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
87354 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
87355 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
87356 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
87357 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
87358 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
87359 +_003175_hash get_info 3 55681 _003175_hash NULL
87360 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
87361 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
87362 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
87363 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
87364 +_003180_hash hsc_write 3 55875 _003180_hash NULL
87365 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
87366 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
87367 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
87368 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
87369 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
87370 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
87371 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
87372 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
87373 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
87374 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
87375 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
87376 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
87377 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
87378 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
87379 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
87380 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
87381 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
87382 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
87383 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
87384 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
87385 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
87386 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
87387 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
87388 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
87389 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
87390 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
87391 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
87392 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
87393 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
87394 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
87395 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
87396 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
87397 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
87398 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
87399 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
87400 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
87401 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
87402 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
87403 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
87404 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
87405 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
87406 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
87407 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
87408 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
87409 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
87410 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
87411 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
87412 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
87413 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
87414 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
87415 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
87416 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
87417 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
87418 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
87419 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
87420 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
87421 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
87422 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
87423 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
87424 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
87425 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
87426 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
87427 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
87428 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
87429 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
87430 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
87431 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
87432 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
87433 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
87434 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
87435 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
87436 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
87437 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
87438 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
87439 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
87440 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
87441 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
87442 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
87443 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
87444 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
87445 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
87446 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
87447 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
87448 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
87449 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
87450 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
87451 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
87452 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
87453 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
87454 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
87455 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
87456 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
87457 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
87458 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
87459 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
87460 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
87461 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
87462 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
87463 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
87464 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
87465 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
87466 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
87467 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
87468 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
87469 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
87470 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
87471 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
87472 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
87473 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
87474 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
87475 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
87476 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
87477 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
87478 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
87479 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
87480 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
87481 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
87482 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
87483 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
87484 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
87485 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
87486 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
87487 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
87488 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
87489 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
87490 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
87491 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
87492 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
87493 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
87494 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
87495 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
87496 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
87497 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
87498 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
87499 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
87500 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
87501 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
87502 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
87503 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
87504 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
87505 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
87506 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
87507 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
87508 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
87509 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
87510 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
87511 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
87512 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
87513 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
87514 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
87515 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
87516 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
87517 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
87518 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
87519 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
87520 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
87521 +_003340_hash alloc_private 2 22399 _003340_hash NULL
87522 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
87523 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
87524 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
87525 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
87526 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
87527 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
87528 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
87529 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
87530 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
87531 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
87532 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
87533 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
87534 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
87535 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
87536 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
87537 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
87538 +_003359_hash comedi_read 3 13199 _003359_hash NULL
87539 +_003360_hash comedi_write 3 47926 _003360_hash NULL
87540 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
87541 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
87542 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
87543 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
87544 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
87545 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
87546 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
87547 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
87548 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
87549 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
87550 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
87551 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
87552 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
87553 +_003377_hash dev_read 3 56369 _003377_hash NULL
87554 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
87555 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
87556 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
87557 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
87558 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
87559 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
87560 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
87561 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
87562 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
87563 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
87564 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
87565 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
87566 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
87567 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
87568 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
87569 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
87570 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
87571 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
87572 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
87573 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
87574 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
87575 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
87576 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
87577 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
87578 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
87579 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
87580 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
87581 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
87582 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
87583 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
87584 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
87585 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
87586 +_003412_hash fb_read 3 33506 _003412_hash NULL
87587 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
87588 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
87589 +_003415_hash fb_write 3 46924 _003415_hash NULL
87590 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
87591 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
87592 +_003418_hash fops_read 3 40672 _003418_hash NULL
87593 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
87594 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
87595 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
87596 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
87597 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
87598 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
87599 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
87600 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
87601 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
87602 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
87603 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
87604 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
87605 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
87606 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
87607 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
87608 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
87609 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
87610 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
87611 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
87612 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
87613 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
87614 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
87615 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
87616 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
87617 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
87618 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
87619 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
87620 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
87621 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
87622 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
87623 +_003451_hash lirc_write 3 20604 _003451_hash NULL
87624 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
87625 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
87626 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
87627 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
87628 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
87629 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
87630 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
87631 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
87632 +_003461_hash mmio_read 4 40348 _003461_hash NULL
87633 +_003462_hash netlink_send 5 38434 _003462_hash NULL
87634 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
87635 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
87636 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
87637 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
87638 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
87639 +_003468_hash odev_update 2 50169 _003468_hash NULL
87640 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
87641 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
87642 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
87643 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
87644 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
87645 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
87646 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
87647 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
87648 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
87649 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
87650 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
87651 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
87652 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
87653 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
87654 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
87655 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
87656 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
87657 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
87658 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
87659 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
87660 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
87661 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
87662 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
87663 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
87664 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
87665 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
87666 +_003497_hash play_iframe 3 8219 _003497_hash NULL
87667 +_003498_hash probes_write 3 29711 _003498_hash NULL
87668 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
87669 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
87670 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
87671 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
87672 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
87673 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
87674 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
87675 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
87676 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
87677 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
87678 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
87679 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
87680 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
87681 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
87682 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
87683 +_003514_hash qc_capture 3 19298 _003514_hash NULL
87684 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
87685 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
87686 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
87687 +_003518_hash Realloc 2 34961 _003518_hash NULL
87688 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
87689 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
87690 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
87691 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
87692 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
87693 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
87694 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
87695 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
87696 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
87697 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
87698 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
87699 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
87700 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
87701 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
87702 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
87703 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
87704 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
87705 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
87706 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
87707 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
87708 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
87709 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
87710 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
87711 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
87712 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
87713 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
87714 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
87715 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
87716 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
87717 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
87718 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
87719 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
87720 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
87721 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
87722 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
87723 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
87724 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
87725 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
87726 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
87727 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
87728 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
87729 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
87730 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
87731 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
87732 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
87733 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
87734 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
87735 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
87736 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
87737 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
87738 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
87739 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
87740 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
87741 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
87742 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
87743 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
87744 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
87745 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
87746 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
87747 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
87748 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
87749 +_003584_hash ts_read 3 44687 _003584_hash NULL
87750 +_003585_hash ts_write 3 64336 _003585_hash NULL
87751 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
87752 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
87753 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
87754 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
87755 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
87756 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
87757 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
87758 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
87759 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
87760 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
87761 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
87762 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
87763 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
87764 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
87765 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
87766 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
87767 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
87768 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
87769 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
87770 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
87771 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
87772 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
87773 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
87774 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
87775 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
87776 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
87777 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
87778 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
87779 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
87780 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
87781 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
87782 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
87783 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
87784 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
87785 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
87786 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
87787 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
87788 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
87789 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
87790 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
87791 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
87792 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
87793 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
87794 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
87795 +_003630_hash unifi_read 3 14899 _003630_hash NULL
87796 +_003631_hash unifi_write 3 65012 _003631_hash NULL
87797 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
87798 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
87799 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
87800 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
87801 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
87802 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
87803 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
87804 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
87805 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
87806 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
87807 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
87808 +_003645_hash vfd_write 3 14717 _003645_hash NULL
87809 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
87810 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
87811 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
87812 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
87813 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
87814 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
87815 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
87816 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
87817 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
87818 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
87819 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
87820 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
87821 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
87822 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
87823 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
87824 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
87825 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
87826 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
87827 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
87828 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
87829 +_003667_hash zoran_write 3 22404 _003667_hash NULL
87830 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
87831 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
87832 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
87833 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
87834 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
87835 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
87836 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
87837 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
87838 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
87839 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
87840 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
87841 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
87842 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
87843 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
87844 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
87845 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
87846 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
87847 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
87848 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
87849 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
87850 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
87851 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
87852 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
87853 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
87854 +_003696_hash qcam_read 3 13977 _003696_hash NULL
87855 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
87856 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
87857 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
87858 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
87859 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
87860 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
87861 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
87862 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
87863 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
87864 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
87865 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
87866 +_003710_hash update_macheader 7 1775 _003710_hash NULL
87867 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
87868 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
87869 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
87870 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
87871 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
87872 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
87873 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
87874 +_003718_hash vb2_read 3 42703 _003718_hash NULL
87875 +_003719_hash vb2_write 3 31948 _003719_hash NULL
87876 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
87877 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
87878 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
87879 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
87880 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
87881 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
87882 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
87883 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
87884 +_003729_hash vmap 2 15025 _003729_hash NULL
87885 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
87886 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
87887 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
87888 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
87889 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
87890 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
87891 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
87892 +_003740_hash bttv_read 3 11432 _003740_hash NULL
87893 +_003741_hash cx18_read 3 23699 _003741_hash NULL
87894 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
87895 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
87896 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
87897 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
87898 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
87899 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
87900 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
87901 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
87902 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
87903 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
87904 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
87905 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
87906 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
87907 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
87908 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
87909 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
87910 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
87911 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
87912 +_003766_hash video_read 3 28148 _003766_hash NULL
87913 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
87914 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
87915 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
87916 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
87917 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
87918 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
87919 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
87920 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
87921 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
87922 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
87923 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
87924 +_003783_hash do_test 1 15766 _003783_hash NULL
87925 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
87926 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
87927 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
87928 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
87929 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
87930 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
87931 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
87932 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
87933 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
87934 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
87935 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
87936 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
87937 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
87938 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
87939 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
87940 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
87941 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
87942 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
87943 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
87944 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
87945 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
87946 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
87947 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
87948 +_003814_hash vbi_read 3 63673 _003814_hash NULL
87949 +_003815_hash viacam_read 3 54526 _003815_hash NULL
87950 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
87951 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
87952 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
87953 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
87954 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
87955 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
87956 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
87957 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
87958 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
87959 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
87960 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
87961 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
87962 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
87963 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
87964 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
87965 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
87966 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
87967 +_003839_hash doc_probe 1 23285 _003839_hash NULL
87968 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
87969 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
87970 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
87971 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
87972 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
87973 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
87974 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
87975 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
87976 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
87977 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
87978 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
87979 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
87980 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
87981 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
87982 +_003858_hash register_device 2-3 60015 _003858_hash NULL
87983 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
87984 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
87985 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
87986 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
87987 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
87988 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
87989 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
87990 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
87991 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
87992 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
87993 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
87994 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
87995 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
87996 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
87997 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
87998 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
87999 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
88000 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
88001 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
88002 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
88003 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
88004 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
88005 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
88006 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
88007 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
88008 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
88009 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
88010 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
88011 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
88012 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
88013 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
88014 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
88015 +_003897_hash acl_alloc 1 35979 _003897_hash NULL
88016 +_003898_hash acl_alloc_stack_init 1 60630 _003898_hash NULL
88017 +_003899_hash create_table 2 16213 _003899_hash NULL
88018 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
88019 new file mode 100644
88020 index 0000000..1aa0dce
88021 --- /dev/null
88022 +++ b/tools/gcc/size_overflow_plugin.c
88023 @@ -0,0 +1,1865 @@
88024 +/*
88025 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
88026 + * Licensed under the GPL v2, or (at your option) v3
88027 + *
88028 + * Homepage:
88029 + * http://www.grsecurity.net/~ephox/overflow_plugin/
88030 + *
88031 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
88032 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
88033 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
88034 + *
88035 + * Usage:
88036 + * $ 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
88037 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
88038 + */
88039 +
88040 +#include "gcc-plugin.h"
88041 +#include "config.h"
88042 +#include "system.h"
88043 +#include "coretypes.h"
88044 +#include "tree.h"
88045 +#include "tree-pass.h"
88046 +#include "intl.h"
88047 +#include "plugin-version.h"
88048 +#include "tm.h"
88049 +#include "toplev.h"
88050 +#include "function.h"
88051 +#include "tree-flow.h"
88052 +#include "plugin.h"
88053 +#include "gimple.h"
88054 +#include "c-common.h"
88055 +#include "diagnostic.h"
88056 +#include "cfgloop.h"
88057 +
88058 +#if BUILDING_GCC_VERSION >= 4007
88059 +#include "c-tree.h"
88060 +#else
88061 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
88062 +#endif
88063 +
88064 +struct size_overflow_hash {
88065 + const struct size_overflow_hash * const next;
88066 + const char * const name;
88067 + const unsigned int param;
88068 +};
88069 +
88070 +#include "size_overflow_hash.h"
88071 +
88072 +enum marked {
88073 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
88074 +};
88075 +
88076 +#define __unused __attribute__((__unused__))
88077 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
88078 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
88079 +#define BEFORE_STMT true
88080 +#define AFTER_STMT false
88081 +#define CREATE_NEW_VAR NULL_TREE
88082 +#define CODES_LIMIT 32
88083 +#define MAX_PARAM 32
88084 +#define MY_STMT GF_PLF_1
88085 +#define NO_CAST_CHECK GF_PLF_2
88086 +
88087 +#if BUILDING_GCC_VERSION == 4005
88088 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
88089 +#endif
88090 +
88091 +int plugin_is_GPL_compatible;
88092 +void debug_gimple_stmt(gimple gs);
88093 +
88094 +static tree expand(struct pointer_set_t *visited, tree lhs);
88095 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
88096 +static tree report_size_overflow_decl;
88097 +static const_tree const_char_ptr_type_node;
88098 +static unsigned int handle_function(void);
88099 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
88100 +static tree get_size_overflow_type(gimple stmt, const_tree node);
88101 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
88102 +
88103 +static struct plugin_info size_overflow_plugin_info = {
88104 + .version = "20121113beta",
88105 + .help = "no-size-overflow\tturn off size overflow checking\n",
88106 +};
88107 +
88108 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
88109 +{
88110 + unsigned int arg_count;
88111 + enum tree_code code = TREE_CODE(*node);
88112 +
88113 + switch (code) {
88114 + case FUNCTION_DECL:
88115 + arg_count = type_num_arguments(TREE_TYPE(*node));
88116 + break;
88117 + case FUNCTION_TYPE:
88118 + case METHOD_TYPE:
88119 + arg_count = type_num_arguments(*node);
88120 + break;
88121 + default:
88122 + *no_add_attrs = true;
88123 + error("%s: %qE attribute only applies to functions", __func__, name);
88124 + return NULL_TREE;
88125 + }
88126 +
88127 + for (; args; args = TREE_CHAIN(args)) {
88128 + tree position = TREE_VALUE(args);
88129 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
88130 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
88131 + *no_add_attrs = true;
88132 + }
88133 + }
88134 + return NULL_TREE;
88135 +}
88136 +
88137 +static const char* get_asm_name(tree node)
88138 +{
88139 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
88140 +}
88141 +
88142 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
88143 +{
88144 + unsigned int arg_count, arg_num;
88145 + enum tree_code code = TREE_CODE(*node);
88146 +
88147 + switch (code) {
88148 + case FUNCTION_DECL:
88149 + arg_count = type_num_arguments(TREE_TYPE(*node));
88150 + break;
88151 + case FUNCTION_TYPE:
88152 + case METHOD_TYPE:
88153 + arg_count = type_num_arguments(*node);
88154 + break;
88155 + case FIELD_DECL:
88156 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
88157 + if (arg_num != 0) {
88158 + *no_add_attrs = true;
88159 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
88160 + }
88161 + return NULL_TREE;
88162 + default:
88163 + *no_add_attrs = true;
88164 + error("%qE attribute only applies to functions", name);
88165 + return NULL_TREE;
88166 + }
88167 +
88168 + for (; args; args = TREE_CHAIN(args)) {
88169 + tree position = TREE_VALUE(args);
88170 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
88171 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
88172 + *no_add_attrs = true;
88173 + }
88174 + }
88175 + return NULL_TREE;
88176 +}
88177 +
88178 +static struct attribute_spec size_overflow_attr = {
88179 + .name = "size_overflow",
88180 + .min_length = 1,
88181 + .max_length = -1,
88182 + .decl_required = true,
88183 + .type_required = false,
88184 + .function_type_required = false,
88185 + .handler = handle_size_overflow_attribute,
88186 +#if BUILDING_GCC_VERSION >= 4007
88187 + .affects_type_identity = false
88188 +#endif
88189 +};
88190 +
88191 +static struct attribute_spec intentional_overflow_attr = {
88192 + .name = "intentional_overflow",
88193 + .min_length = 1,
88194 + .max_length = -1,
88195 + .decl_required = true,
88196 + .type_required = false,
88197 + .function_type_required = false,
88198 + .handler = handle_intentional_overflow_attribute,
88199 +#if BUILDING_GCC_VERSION >= 4007
88200 + .affects_type_identity = false
88201 +#endif
88202 +};
88203 +
88204 +static void register_attributes(void __unused *event_data, void __unused *data)
88205 +{
88206 + register_attribute(&size_overflow_attr);
88207 + register_attribute(&intentional_overflow_attr);
88208 +}
88209 +
88210 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
88211 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
88212 +{
88213 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
88214 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
88215 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
88216 +
88217 + unsigned int m = 0x57559429;
88218 + unsigned int n = 0x5052acdb;
88219 + const unsigned int *key4 = (const unsigned int *)key;
88220 + unsigned int h = len;
88221 + unsigned int k = len + seed + n;
88222 + unsigned long long p;
88223 +
88224 + while (len >= 8) {
88225 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
88226 + len -= 8;
88227 + }
88228 + if (len >= 4) {
88229 + cwmixb(key4[0]) key4 += 1;
88230 + len -= 4;
88231 + }
88232 + if (len)
88233 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
88234 + cwmixb(h ^ (k + n));
88235 + return k ^ h;
88236 +
88237 +#undef cwfold
88238 +#undef cwmixa
88239 +#undef cwmixb
88240 +}
88241 +
88242 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
88243 +{
88244 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
88245 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
88246 + return fn ^ codes;
88247 +}
88248 +
88249 +static inline tree get_original_function_decl(tree fndecl)
88250 +{
88251 + if (DECL_ABSTRACT_ORIGIN(fndecl))
88252 + return DECL_ABSTRACT_ORIGIN(fndecl);
88253 + return fndecl;
88254 +}
88255 +
88256 +static inline gimple get_def_stmt(const_tree node)
88257 +{
88258 + gcc_assert(node != NULL_TREE);
88259 + gcc_assert(TREE_CODE(node) == SSA_NAME);
88260 + return SSA_NAME_DEF_STMT(node);
88261 +}
88262 +
88263 +static unsigned char get_tree_code(const_tree type)
88264 +{
88265 + switch (TREE_CODE(type)) {
88266 + case ARRAY_TYPE:
88267 + return 0;
88268 + case BOOLEAN_TYPE:
88269 + return 1;
88270 + case ENUMERAL_TYPE:
88271 + return 2;
88272 + case FUNCTION_TYPE:
88273 + return 3;
88274 + case INTEGER_TYPE:
88275 + return 4;
88276 + case POINTER_TYPE:
88277 + return 5;
88278 + case RECORD_TYPE:
88279 + return 6;
88280 + case UNION_TYPE:
88281 + return 7;
88282 + case VOID_TYPE:
88283 + return 8;
88284 + case REAL_TYPE:
88285 + return 9;
88286 + case VECTOR_TYPE:
88287 + return 10;
88288 + case REFERENCE_TYPE:
88289 + return 11;
88290 + case OFFSET_TYPE:
88291 + return 12;
88292 + case COMPLEX_TYPE:
88293 + return 13;
88294 + default:
88295 + debug_tree((tree)type);
88296 + gcc_unreachable();
88297 + }
88298 +}
88299 +
88300 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
88301 +{
88302 + gcc_assert(type != NULL_TREE);
88303 +
88304 + while (type && len < CODES_LIMIT) {
88305 + tree_codes[len] = get_tree_code(type);
88306 + len++;
88307 + type = TREE_TYPE(type);
88308 + }
88309 + return len;
88310 +}
88311 +
88312 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
88313 +{
88314 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
88315 + enum tree_code code = TREE_CODE(type);
88316 + size_t len = 0;
88317 +
88318 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
88319 +
88320 + arg = TYPE_ARG_TYPES(type);
88321 + // skip builtins __builtin_constant_p
88322 + if (!arg && DECL_BUILT_IN(fndecl))
88323 + return 0;
88324 +
88325 + if (TREE_CODE_CLASS(code) == tcc_type)
88326 + result = type;
88327 + else
88328 + result = DECL_RESULT(fndecl);
88329 +
88330 + gcc_assert(result != NULL_TREE);
88331 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
88332 +
88333 + if (arg == NULL_TREE) {
88334 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
88335 + arg_field = DECL_ARGUMENT_FLD(fndecl);
88336 + if (arg_field == NULL_TREE)
88337 + return 0;
88338 + arg = TREE_TYPE(arg_field);
88339 + len = add_type_codes(arg, tree_codes, len);
88340 + gcc_assert(len != 0);
88341 + return len;
88342 + }
88343 +
88344 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
88345 + while (arg && len < CODES_LIMIT) {
88346 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
88347 + arg = TREE_CHAIN(arg);
88348 + }
88349 +
88350 + gcc_assert(len != 0);
88351 + return len;
88352 +}
88353 +
88354 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
88355 +{
88356 + unsigned int hash;
88357 + const struct size_overflow_hash *entry;
88358 + unsigned char tree_codes[CODES_LIMIT];
88359 + size_t len;
88360 + const char *func_name = get_asm_name(fndecl);
88361 +
88362 + len = get_function_decl(fndecl, tree_codes);
88363 + if (len == 0)
88364 + return NULL;
88365 +
88366 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
88367 +
88368 + entry = size_overflow_hash[hash];
88369 + while (entry) {
88370 + if (!strcmp(entry->name, func_name))
88371 + return entry;
88372 + entry = entry->next;
88373 + }
88374 +
88375 + return NULL;
88376 +}
88377 +
88378 +static void check_arg_type(const_tree arg)
88379 +{
88380 + const_tree type = TREE_TYPE(arg);
88381 + enum tree_code code = TREE_CODE(type);
88382 +
88383 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
88384 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
88385 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
88386 +}
88387 +
88388 +static int find_arg_number(const_tree arg, tree func)
88389 +{
88390 + tree var;
88391 + unsigned int argnum = 1;
88392 +
88393 + if (TREE_CODE(arg) == SSA_NAME)
88394 + arg = SSA_NAME_VAR(arg);
88395 +
88396 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
88397 + if (strcmp(NAME(arg), NAME(var))) {
88398 + argnum++;
88399 + continue;
88400 + }
88401 + check_arg_type(var);
88402 + return argnum;
88403 + }
88404 + gcc_unreachable();
88405 +}
88406 +
88407 +static tree create_new_var(tree type)
88408 +{
88409 + tree new_var = create_tmp_var(type, "cicus");
88410 +
88411 + add_referenced_var(new_var);
88412 + mark_sym_for_renaming(new_var);
88413 + return new_var;
88414 +}
88415 +
88416 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
88417 +{
88418 + gimple assign;
88419 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88420 + tree type = TREE_TYPE(rhs1);
88421 + tree lhs = create_new_var(type);
88422 +
88423 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
88424 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
88425 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88426 +
88427 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
88428 + update_stmt(assign);
88429 + gimple_set_plf(assign, MY_STMT, true);
88430 + return assign;
88431 +}
88432 +
88433 +static bool is_bool(const_tree node)
88434 +{
88435 + const_tree type;
88436 +
88437 + if (node == NULL_TREE)
88438 + return false;
88439 +
88440 + type = TREE_TYPE(node);
88441 + if (!INTEGRAL_TYPE_P(type))
88442 + return false;
88443 + if (TREE_CODE(type) == BOOLEAN_TYPE)
88444 + return true;
88445 + if (TYPE_PRECISION(type) == 1)
88446 + return true;
88447 + return false;
88448 +}
88449 +
88450 +static tree cast_a_tree(tree type, tree var)
88451 +{
88452 + gcc_assert(type != NULL_TREE);
88453 + gcc_assert(var != NULL_TREE);
88454 + gcc_assert(fold_convertible_p(type, var));
88455 +
88456 + return fold_convert(type, var);
88457 +}
88458 +
88459 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
88460 +{
88461 + gimple assign;
88462 +
88463 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
88464 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
88465 + gcc_unreachable();
88466 +
88467 + if (lhs == CREATE_NEW_VAR)
88468 + lhs = create_new_var(dst_type);
88469 +
88470 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
88471 +
88472 + if (!gsi_end_p(*gsi)) {
88473 + location_t loc = gimple_location(gsi_stmt(*gsi));
88474 + gimple_set_location(assign, loc);
88475 + }
88476 +
88477 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88478 +
88479 + if (before)
88480 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
88481 + else
88482 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
88483 + update_stmt(assign);
88484 + gimple_set_plf(assign, MY_STMT, true);
88485 +
88486 + return assign;
88487 +}
88488 +
88489 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
88490 +{
88491 + gimple assign;
88492 + gimple_stmt_iterator gsi;
88493 +
88494 + if (rhs == NULL_TREE)
88495 + return NULL_TREE;
88496 +
88497 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
88498 + return rhs;
88499 +
88500 + gsi = gsi_for_stmt(stmt);
88501 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
88502 + gimple_set_plf(assign, MY_STMT, true);
88503 + return gimple_get_lhs(assign);
88504 +}
88505 +
88506 +static tree cast_to_TI_type(gimple stmt, tree node)
88507 +{
88508 + gimple_stmt_iterator gsi;
88509 + gimple cast_stmt;
88510 + tree type = TREE_TYPE(node);
88511 +
88512 + if (types_compatible_p(type, intTI_type_node))
88513 + return node;
88514 +
88515 + gsi = gsi_for_stmt(stmt);
88516 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88517 + gimple_set_plf(cast_stmt, MY_STMT, true);
88518 + return gimple_get_lhs(cast_stmt);
88519 +}
88520 +
88521 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
88522 +{
88523 + tree lhs;
88524 + gimple_stmt_iterator gsi;
88525 +
88526 + if (rhs1 == NULL_TREE) {
88527 + debug_gimple_stmt(oldstmt);
88528 + error("%s: rhs1 is NULL_TREE", __func__);
88529 + gcc_unreachable();
88530 + }
88531 +
88532 + if (gimple_code(oldstmt) == GIMPLE_ASM)
88533 + lhs = rhs1;
88534 + else
88535 + lhs = gimple_get_lhs(oldstmt);
88536 +
88537 + gsi = gsi_for_stmt(oldstmt);
88538 + pointer_set_insert(visited, oldstmt);
88539 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
88540 + basic_block next_bb, cur_bb;
88541 + const_edge e;
88542 +
88543 + gcc_assert(before == false);
88544 + gcc_assert(stmt_can_throw_internal(oldstmt));
88545 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
88546 + gcc_assert(!gsi_end_p(gsi));
88547 +
88548 + cur_bb = gimple_bb(oldstmt);
88549 + next_bb = cur_bb->next_bb;
88550 + e = find_edge(cur_bb, next_bb);
88551 + gcc_assert(e != NULL);
88552 + gcc_assert(e->flags & EDGE_FALLTHRU);
88553 +
88554 + gsi = gsi_after_labels(next_bb);
88555 + gcc_assert(!gsi_end_p(gsi));
88556 +
88557 + before = true;
88558 + oldstmt = gsi_stmt(gsi);
88559 + }
88560 +
88561 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
88562 +}
88563 +
88564 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
88565 +{
88566 + gimple stmt;
88567 + gimple_stmt_iterator gsi;
88568 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
88569 +
88570 + if (gimple_plf(oldstmt, MY_STMT))
88571 + return lhs;
88572 +
88573 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
88574 + rhs1 = gimple_assign_rhs1(oldstmt);
88575 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
88576 + }
88577 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
88578 + rhs2 = gimple_assign_rhs2(oldstmt);
88579 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
88580 + }
88581 +
88582 + stmt = gimple_copy(oldstmt);
88583 + gimple_set_location(stmt, gimple_location(oldstmt));
88584 + gimple_set_plf(stmt, MY_STMT, true);
88585 +
88586 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
88587 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
88588 +
88589 + size_overflow_type = get_size_overflow_type(oldstmt, node);
88590 +
88591 + if (is_bool(lhs))
88592 + new_var = SSA_NAME_VAR(lhs);
88593 + else
88594 + new_var = create_new_var(size_overflow_type);
88595 + new_var = make_ssa_name(new_var, stmt);
88596 + gimple_set_lhs(stmt, new_var);
88597 +
88598 + if (rhs1 != NULL_TREE) {
88599 + if (!gimple_assign_cast_p(oldstmt) && TREE_CODE_CLASS(gimple_assign_rhs_code(oldstmt)) != tcc_comparison)
88600 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
88601 + gimple_assign_set_rhs1(stmt, rhs1);
88602 + }
88603 +
88604 + if (rhs2 != NULL_TREE)
88605 + gimple_assign_set_rhs2(stmt, rhs2);
88606 +#if BUILDING_GCC_VERSION >= 4007
88607 + if (rhs3 != NULL_TREE)
88608 + gimple_assign_set_rhs3(stmt, rhs3);
88609 +#endif
88610 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
88611 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
88612 +
88613 + gsi = gsi_for_stmt(oldstmt);
88614 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
88615 + update_stmt(stmt);
88616 + pointer_set_insert(visited, oldstmt);
88617 + return gimple_get_lhs(stmt);
88618 +}
88619 +
88620 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
88621 +{
88622 + basic_block bb;
88623 + gimple phi;
88624 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
88625 +
88626 + bb = gsi_bb(gsi);
88627 +
88628 + phi = create_phi_node(result, bb);
88629 + gsi = gsi_last(phi_nodes(bb));
88630 + gsi_remove(&gsi, false);
88631 +
88632 + gsi = gsi_for_stmt(oldstmt);
88633 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
88634 + gimple_set_bb(phi, bb);
88635 + gimple_set_plf(phi, MY_STMT, true);
88636 + return phi;
88637 +}
88638 +
88639 +static basic_block create_a_first_bb(void)
88640 +{
88641 + basic_block first_bb;
88642 +
88643 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88644 + if (dom_info_available_p(CDI_DOMINATORS))
88645 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
88646 + return first_bb;
88647 +}
88648 +
88649 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
88650 +{
88651 + basic_block bb;
88652 + const_gimple newstmt;
88653 + gimple_stmt_iterator gsi;
88654 + bool before = BEFORE_STMT;
88655 +
88656 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
88657 + gsi = gsi_for_stmt(get_def_stmt(arg));
88658 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
88659 + return gimple_get_lhs(newstmt);
88660 + }
88661 +
88662 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
88663 + gsi = gsi_after_labels(bb);
88664 + if (bb->index == 0) {
88665 + bb = create_a_first_bb();
88666 + gsi = gsi_start_bb(bb);
88667 + }
88668 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
88669 + return gimple_get_lhs(newstmt);
88670 +}
88671 +
88672 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
88673 +{
88674 + gimple newstmt;
88675 + gimple_stmt_iterator gsi;
88676 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
88677 + gimple def_newstmt = get_def_stmt(new_rhs);
88678 +
88679 + gsi_insert = gsi_insert_after;
88680 + gsi = gsi_for_stmt(def_newstmt);
88681 +
88682 + switch (gimple_code(get_def_stmt(arg))) {
88683 + case GIMPLE_PHI:
88684 + newstmt = gimple_build_assign(new_var, new_rhs);
88685 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
88686 + gsi_insert = gsi_insert_before;
88687 + break;
88688 + case GIMPLE_ASM:
88689 + case GIMPLE_CALL:
88690 + newstmt = gimple_build_assign(new_var, new_rhs);
88691 + break;
88692 + case GIMPLE_ASSIGN:
88693 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
88694 + break;
88695 + default:
88696 + /* unknown gimple_code (handle_build_new_phi_arg) */
88697 + gcc_unreachable();
88698 + }
88699 +
88700 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
88701 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
88702 + gimple_set_plf(newstmt, MY_STMT, true);
88703 + update_stmt(newstmt);
88704 + return newstmt;
88705 +}
88706 +
88707 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
88708 +{
88709 + const_gimple newstmt;
88710 + gimple def_stmt;
88711 + tree new_rhs;
88712 +
88713 + new_rhs = expand(visited, arg);
88714 + if (new_rhs == NULL_TREE)
88715 + return NULL_TREE;
88716 +
88717 + def_stmt = get_def_stmt(new_rhs);
88718 + if (gimple_code(def_stmt) == GIMPLE_NOP)
88719 + return NULL_TREE;
88720 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
88721 +
88722 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
88723 + return gimple_get_lhs(newstmt);
88724 +}
88725 +
88726 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
88727 +{
88728 + gimple phi, oldstmt = get_def_stmt(orig_result);
88729 + tree new_result, size_overflow_type;
88730 + unsigned int i;
88731 + unsigned int n = gimple_phi_num_args(oldstmt);
88732 +
88733 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
88734 +
88735 + new_result = create_new_var(size_overflow_type);
88736 +
88737 + pointer_set_insert(visited, oldstmt);
88738 + phi = overflow_create_phi_node(oldstmt, new_result);
88739 + for (i = 0; i < n; i++) {
88740 + tree arg, lhs;
88741 +
88742 + arg = gimple_phi_arg_def(oldstmt, i);
88743 + if (is_gimple_constant(arg))
88744 + arg = cast_a_tree(size_overflow_type, arg);
88745 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
88746 + if (lhs == NULL_TREE)
88747 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
88748 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
88749 + }
88750 +
88751 + update_stmt(phi);
88752 + return gimple_phi_result(phi);
88753 +}
88754 +
88755 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
88756 +{
88757 + const_gimple assign;
88758 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88759 + tree origtype = TREE_TYPE(orig_rhs);
88760 +
88761 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
88762 +
88763 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88764 + return gimple_get_lhs(assign);
88765 +}
88766 +
88767 +static void change_rhs1(gimple stmt, tree new_rhs1)
88768 +{
88769 + tree assign_rhs;
88770 + const_tree rhs = gimple_assign_rhs1(stmt);
88771 +
88772 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
88773 + gimple_assign_set_rhs1(stmt, assign_rhs);
88774 + update_stmt(stmt);
88775 +}
88776 +
88777 +static bool check_mode_type(const_gimple stmt)
88778 +{
88779 + const_tree lhs = gimple_get_lhs(stmt);
88780 + const_tree lhs_type = TREE_TYPE(lhs);
88781 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88782 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88783 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88784 +
88785 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88786 + return false;
88787 +
88788 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88789 + return false;
88790 +
88791 + return true;
88792 +}
88793 +
88794 +static bool check_undefined_integer_operation(const_gimple stmt)
88795 +{
88796 + const_gimple def_stmt;
88797 + const_tree lhs = gimple_get_lhs(stmt);
88798 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88799 + const_tree rhs1_type = TREE_TYPE(rhs1);
88800 + const_tree lhs_type = TREE_TYPE(lhs);
88801 +
88802 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88803 + return false;
88804 +
88805 + def_stmt = get_def_stmt(rhs1);
88806 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88807 + return false;
88808 +
88809 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88810 + return false;
88811 + return true;
88812 +}
88813 +
88814 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88815 +{
88816 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88817 + enum machine_mode lhs_mode, rhs_mode;
88818 + gimple def_stmt = get_def_stmt(no_const_rhs);
88819 +
88820 + if (!gimple_assign_cast_p(def_stmt))
88821 + return false;
88822 +
88823 + rhs1 = gimple_assign_rhs1(def_stmt);
88824 + lhs = gimple_get_lhs(def_stmt);
88825 + rhs1_type = TREE_TYPE(rhs1);
88826 + lhs_type = TREE_TYPE(lhs);
88827 + rhs_mode = TYPE_MODE(rhs1_type);
88828 + lhs_mode = TYPE_MODE(lhs_type);
88829 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88830 + return false;
88831 +
88832 + return true;
88833 +}
88834 +
88835 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88836 +{
88837 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88838 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88839 + const_tree rhs1_type = TREE_TYPE(rhs1);
88840 + const_tree lhs_type = TREE_TYPE(lhs);
88841 +
88842 + new_rhs1 = expand(visited, rhs1);
88843 +
88844 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88845 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88846 +
88847 + if (gimple_plf(stmt, MY_STMT))
88848 + return lhs;
88849 +
88850 + if (gimple_plf(stmt, NO_CAST_CHECK))
88851 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88852 +
88853 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88854 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88855 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88856 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88857 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88858 + }
88859 +
88860 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88861 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88862 +
88863 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88864 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88865 +
88866 + change_rhs1(stmt, new_rhs1);
88867 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88868 +
88869 + rhs1 = gimple_assign_rhs1(stmt);
88870 + rhs1_type = TREE_TYPE(rhs1);
88871 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
88872 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88873 +
88874 + if (!check_mode_type(stmt))
88875 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88876 +
88877 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88878 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88879 +
88880 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88881 +
88882 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88883 +}
88884 +
88885 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
88886 +{
88887 + gimple def_stmt = get_def_stmt(lhs);
88888 + tree rhs1 = gimple_assign_rhs1(def_stmt);
88889 +
88890 + if (is_gimple_constant(rhs1))
88891 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88892 +
88893 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88894 + switch (TREE_CODE(rhs1)) {
88895 + case SSA_NAME:
88896 + return handle_unary_rhs(visited, def_stmt);
88897 + case ARRAY_REF:
88898 + case BIT_FIELD_REF:
88899 + case ADDR_EXPR:
88900 + case COMPONENT_REF:
88901 + case INDIRECT_REF:
88902 +#if BUILDING_GCC_VERSION >= 4006
88903 + case MEM_REF:
88904 +#endif
88905 + case PARM_DECL:
88906 + case TARGET_MEM_REF:
88907 + case VAR_DECL:
88908 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88909 +
88910 + default:
88911 + debug_gimple_stmt(def_stmt);
88912 + debug_tree(rhs1);
88913 + gcc_unreachable();
88914 + }
88915 +}
88916 +
88917 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88918 +{
88919 + gimple cond_stmt;
88920 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88921 +
88922 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88923 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88924 + update_stmt(cond_stmt);
88925 +}
88926 +
88927 +static tree create_string_param(tree string)
88928 +{
88929 + tree i_type, a_type;
88930 + const int length = TREE_STRING_LENGTH(string);
88931 +
88932 + gcc_assert(length > 0);
88933 +
88934 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88935 + a_type = build_array_type(char_type_node, i_type);
88936 +
88937 + TREE_TYPE(string) = a_type;
88938 + TREE_CONSTANT(string) = 1;
88939 + TREE_READONLY(string) = 1;
88940 +
88941 + return build1(ADDR_EXPR, ptr_type_node, string);
88942 +}
88943 +
88944 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88945 +{
88946 + gimple func_stmt;
88947 + const_gimple def_stmt;
88948 + const_tree loc_line;
88949 + tree loc_file, ssa_name, current_func;
88950 + expanded_location xloc;
88951 + char ssa_name_buf[256];
88952 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88953 +
88954 + def_stmt = get_def_stmt(arg);
88955 + xloc = expand_location(gimple_location(def_stmt));
88956 +
88957 + if (!gimple_has_location(def_stmt)) {
88958 + xloc = expand_location(gimple_location(stmt));
88959 + if (!gimple_has_location(stmt))
88960 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88961 + }
88962 +
88963 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88964 +
88965 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88966 + loc_file = create_string_param(loc_file);
88967 +
88968 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88969 + current_func = create_string_param(current_func);
88970 +
88971 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
88972 + ssa_name = build_string(256, ssa_name_buf);
88973 + ssa_name = create_string_param(ssa_name);
88974 +
88975 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88976 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88977 +
88978 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88979 +}
88980 +
88981 +static void __unused print_the_code_insertions(const_gimple stmt)
88982 +{
88983 + location_t loc = gimple_location(stmt);
88984 +
88985 + inform(loc, "Integer size_overflow check applied here.");
88986 +}
88987 +
88988 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88989 +{
88990 + basic_block cond_bb, join_bb, bb_true;
88991 + edge e;
88992 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88993 +
88994 + cond_bb = gimple_bb(stmt);
88995 + if (before)
88996 + gsi_prev(&gsi);
88997 + if (gsi_end_p(gsi))
88998 + e = split_block_after_labels(cond_bb);
88999 + else
89000 + e = split_block(cond_bb, gsi_stmt(gsi));
89001 + cond_bb = e->src;
89002 + join_bb = e->dest;
89003 + e->flags = EDGE_FALSE_VALUE;
89004 + e->probability = REG_BR_PROB_BASE;
89005 +
89006 + bb_true = create_empty_bb(cond_bb);
89007 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
89008 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
89009 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
89010 +
89011 + if (dom_info_available_p(CDI_DOMINATORS)) {
89012 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
89013 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
89014 + }
89015 +
89016 + if (current_loops != NULL) {
89017 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
89018 + add_bb_to_loop(bb_true, cond_bb->loop_father);
89019 + }
89020 +
89021 + insert_cond(cond_bb, arg, cond_code, type_value);
89022 + insert_cond_result(bb_true, stmt, arg, min);
89023 +
89024 +// print_the_code_insertions(stmt);
89025 +}
89026 +
89027 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
89028 +{
89029 + const_tree rhs_type = TREE_TYPE(rhs);
89030 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
89031 +
89032 + gcc_assert(rhs_type != NULL_TREE);
89033 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
89034 + return;
89035 +
89036 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
89037 +
89038 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
89039 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
89040 +
89041 + gcc_assert(!TREE_OVERFLOW(type_max));
89042 +
89043 + cast_rhs_type = TREE_TYPE(cast_rhs);
89044 + type_max_type = TREE_TYPE(type_max);
89045 + type_min_type = TREE_TYPE(type_min);
89046 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
89047 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
89048 +
89049 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
89050 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
89051 +}
89052 +
89053 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
89054 +{
89055 + gimple change_rhs_def_stmt;
89056 + tree lhs = gimple_get_lhs(def_stmt);
89057 + tree lhs_type = TREE_TYPE(lhs);
89058 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
89059 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
89060 +
89061 + if (change_rhs == NULL_TREE)
89062 + return get_size_overflow_type(def_stmt, lhs);
89063 +
89064 + change_rhs_def_stmt = get_def_stmt(change_rhs);
89065 +
89066 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
89067 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
89068 +
89069 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
89070 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
89071 +
89072 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
89073 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
89074 +
89075 + if (!types_compatible_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
89076 + debug_gimple_stmt(def_stmt);
89077 + gcc_unreachable();
89078 + }
89079 +
89080 + return get_size_overflow_type(def_stmt, lhs);
89081 +}
89082 +
89083 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
89084 +{
89085 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
89086 + return false;
89087 + if (!is_gimple_constant(rhs))
89088 + return false;
89089 + return true;
89090 +}
89091 +
89092 +static bool is_subtraction_special(const_gimple stmt)
89093 +{
89094 + gimple rhs1_def_stmt, rhs2_def_stmt;
89095 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
89096 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
89097 + const_tree rhs1 = gimple_assign_rhs1(stmt);
89098 + const_tree rhs2 = gimple_assign_rhs2(stmt);
89099 +
89100 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
89101 + return false;
89102 +
89103 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
89104 +
89105 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
89106 + return false;
89107 +
89108 + rhs1_def_stmt = get_def_stmt(rhs1);
89109 + rhs2_def_stmt = get_def_stmt(rhs2);
89110 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
89111 + return false;
89112 +
89113 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
89114 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
89115 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
89116 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
89117 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
89118 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
89119 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
89120 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
89121 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
89122 + return false;
89123 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
89124 + return false;
89125 +
89126 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
89127 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
89128 + return true;
89129 +}
89130 +
89131 +static tree get_def_stmt_rhs(const_tree var)
89132 +{
89133 + tree rhs1, def_stmt_rhs1;
89134 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
89135 +
89136 + def_stmt = get_def_stmt(var);
89137 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
89138 +
89139 + rhs1 = gimple_assign_rhs1(def_stmt);
89140 + rhs1_def_stmt = get_def_stmt(rhs1);
89141 + gcc_assert(gimple_code(rhs1_def_stmt) != GIMPLE_NOP);
89142 + if (!gimple_assign_cast_p(rhs1_def_stmt))
89143 + return rhs1;
89144 +
89145 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
89146 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
89147 +
89148 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
89149 + case GIMPLE_CALL:
89150 + case GIMPLE_NOP:
89151 + case GIMPLE_ASM:
89152 + return def_stmt_rhs1;
89153 + case GIMPLE_ASSIGN:
89154 + return rhs1;
89155 + default:
89156 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
89157 + gcc_unreachable();
89158 + }
89159 +}
89160 +
89161 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
89162 +{
89163 + tree new_rhs1, new_rhs2;
89164 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
89165 + gimple assign, stmt = get_def_stmt(lhs);
89166 + tree rhs1 = gimple_assign_rhs1(stmt);
89167 + tree rhs2 = gimple_assign_rhs2(stmt);
89168 +
89169 + if (!is_subtraction_special(stmt))
89170 + return NULL_TREE;
89171 +
89172 + new_rhs1 = expand(visited, rhs1);
89173 + new_rhs2 = expand(visited, rhs2);
89174 +
89175 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
89176 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
89177 +
89178 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
89179 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
89180 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
89181 + }
89182 +
89183 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
89184 + new_lhs = gimple_get_lhs(assign);
89185 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
89186 +
89187 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
89188 +}
89189 +
89190 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
89191 +{
89192 + const_gimple def_stmt;
89193 +
89194 + if (TREE_CODE(rhs) != SSA_NAME)
89195 + return false;
89196 +
89197 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
89198 + return false;
89199 +
89200 + def_stmt = get_def_stmt(rhs);
89201 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
89202 + return false;
89203 +
89204 + return true;
89205 +}
89206 +
89207 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
89208 +{
89209 + tree new_rhs, size_overflow_type, orig_rhs;
89210 + void (*gimple_assign_set_rhs)(gimple, tree);
89211 + tree rhs1 = gimple_assign_rhs1(stmt);
89212 + tree rhs2 = gimple_assign_rhs2(stmt);
89213 + tree lhs = gimple_get_lhs(stmt);
89214 +
89215 + if (change_rhs == NULL_TREE)
89216 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89217 +
89218 + if (new_rhs2 == NULL_TREE) {
89219 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
89220 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
89221 + orig_rhs = rhs1;
89222 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
89223 + } else {
89224 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
89225 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
89226 + orig_rhs = rhs2;
89227 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
89228 + }
89229 +
89230 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
89231 +
89232 + if (check_overflow)
89233 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
89234 +
89235 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
89236 + gimple_assign_set_rhs(stmt, new_rhs);
89237 + update_stmt(stmt);
89238 +
89239 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89240 +}
89241 +
89242 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
89243 +{
89244 + tree rhs1, rhs2, new_lhs;
89245 + gimple def_stmt = get_def_stmt(lhs);
89246 + tree new_rhs1 = NULL_TREE;
89247 + tree new_rhs2 = NULL_TREE;
89248 +
89249 + rhs1 = gimple_assign_rhs1(def_stmt);
89250 + rhs2 = gimple_assign_rhs2(def_stmt);
89251 +
89252 + /* no DImode/TImode division in the 32/64 bit kernel */
89253 + switch (gimple_assign_rhs_code(def_stmt)) {
89254 + case RDIV_EXPR:
89255 + case TRUNC_DIV_EXPR:
89256 + case CEIL_DIV_EXPR:
89257 + case FLOOR_DIV_EXPR:
89258 + case ROUND_DIV_EXPR:
89259 + case TRUNC_MOD_EXPR:
89260 + case CEIL_MOD_EXPR:
89261 + case FLOOR_MOD_EXPR:
89262 + case ROUND_MOD_EXPR:
89263 + case EXACT_DIV_EXPR:
89264 + case POINTER_PLUS_EXPR:
89265 + case BIT_AND_EXPR:
89266 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89267 + default:
89268 + break;
89269 + }
89270 +
89271 + new_lhs = handle_integer_truncation(visited, lhs);
89272 + if (new_lhs != NULL_TREE)
89273 + return new_lhs;
89274 +
89275 + if (TREE_CODE(rhs1) == SSA_NAME)
89276 + new_rhs1 = expand(visited, rhs1);
89277 + if (TREE_CODE(rhs2) == SSA_NAME)
89278 + new_rhs2 = expand(visited, rhs2);
89279 +
89280 + if (is_a_neg_overflow(def_stmt, rhs2))
89281 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
89282 + if (is_a_neg_overflow(def_stmt, rhs1))
89283 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
89284 +
89285 + if (is_a_constant_overflow(def_stmt, rhs2))
89286 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
89287 + if (is_a_constant_overflow(def_stmt, rhs1))
89288 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
89289 +
89290 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
89291 +}
89292 +
89293 +#if BUILDING_GCC_VERSION >= 4007
89294 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
89295 +{
89296 + if (is_gimple_constant(rhs))
89297 + return cast_a_tree(size_overflow_type, rhs);
89298 + if (TREE_CODE(rhs) != SSA_NAME)
89299 + return NULL_TREE;
89300 + return expand(visited, rhs);
89301 +}
89302 +
89303 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
89304 +{
89305 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
89306 + gimple def_stmt = get_def_stmt(lhs);
89307 +
89308 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
89309 +
89310 + rhs1 = gimple_assign_rhs1(def_stmt);
89311 + rhs2 = gimple_assign_rhs2(def_stmt);
89312 + rhs3 = gimple_assign_rhs3(def_stmt);
89313 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
89314 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
89315 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
89316 +
89317 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
89318 +}
89319 +#endif
89320 +
89321 +static tree get_size_overflow_type(gimple stmt, const_tree node)
89322 +{
89323 + const_tree type;
89324 +
89325 + gcc_assert(node != NULL_TREE);
89326 +
89327 + type = TREE_TYPE(node);
89328 +
89329 + if (gimple_plf(stmt, MY_STMT))
89330 + return TREE_TYPE(node);
89331 +
89332 + switch (TYPE_MODE(type)) {
89333 + case QImode:
89334 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
89335 + case HImode:
89336 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
89337 + case SImode:
89338 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89339 + case DImode:
89340 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
89341 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89342 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
89343 + default:
89344 + debug_tree((tree)node);
89345 + error("%s: unsupported gcc configuration.", __func__);
89346 + gcc_unreachable();
89347 + }
89348 +}
89349 +
89350 +static tree expand_visited(gimple def_stmt)
89351 +{
89352 + const_gimple next_stmt;
89353 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
89354 +
89355 + gsi_next(&gsi);
89356 + next_stmt = gsi_stmt(gsi);
89357 +
89358 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
89359 +
89360 + switch (gimple_code(next_stmt)) {
89361 + case GIMPLE_ASSIGN:
89362 + return gimple_get_lhs(next_stmt);
89363 + case GIMPLE_PHI:
89364 + return gimple_phi_result(next_stmt);
89365 + case GIMPLE_CALL:
89366 + return gimple_call_lhs(next_stmt);
89367 + default:
89368 + return NULL_TREE;
89369 + }
89370 +}
89371 +
89372 +static tree expand(struct pointer_set_t *visited, tree lhs)
89373 +{
89374 + gimple def_stmt;
89375 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
89376 +
89377 + if (is_gimple_constant(lhs))
89378 + return NULL_TREE;
89379 +
89380 + if (TREE_CODE(lhs) == ADDR_EXPR)
89381 + return NULL_TREE;
89382 +
89383 + if (code == REAL_TYPE)
89384 + return NULL_TREE;
89385 +
89386 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
89387 +
89388 +
89389 + def_stmt = get_def_stmt(lhs);
89390 +
89391 + if (!def_stmt)
89392 + return NULL_TREE;
89393 +
89394 + if (gimple_plf(def_stmt, MY_STMT))
89395 + return lhs;
89396 +
89397 + if (pointer_set_contains(visited, def_stmt))
89398 + return expand_visited(def_stmt);
89399 +
89400 + switch (gimple_code(def_stmt)) {
89401 + case GIMPLE_NOP:
89402 + return NULL_TREE;
89403 + case GIMPLE_PHI:
89404 + return build_new_phi(visited, lhs);
89405 + case GIMPLE_CALL:
89406 + case GIMPLE_ASM:
89407 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89408 + case GIMPLE_ASSIGN:
89409 + switch (gimple_num_ops(def_stmt)) {
89410 + case 2:
89411 + return handle_unary_ops(visited, lhs);
89412 + case 3:
89413 + return handle_binary_ops(visited, lhs);
89414 +#if BUILDING_GCC_VERSION >= 4007
89415 + case 4:
89416 + return handle_ternary_ops(visited, lhs);
89417 +#endif
89418 + }
89419 + default:
89420 + debug_gimple_stmt(def_stmt);
89421 + error("%s: unknown gimple code", __func__);
89422 + gcc_unreachable();
89423 + }
89424 +}
89425 +
89426 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
89427 +{
89428 + const_gimple assign;
89429 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89430 + tree origtype = TREE_TYPE(origarg);
89431 +
89432 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
89433 +
89434 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89435 +
89436 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
89437 + update_stmt(stmt);
89438 +}
89439 +
89440 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
89441 +{
89442 + const char *origid;
89443 + tree arg;
89444 + const_tree origarg;
89445 +
89446 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
89447 + return true;
89448 +
89449 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
89450 + while (origarg && *argnum) {
89451 + (*argnum)--;
89452 + origarg = TREE_CHAIN(origarg);
89453 + }
89454 +
89455 + gcc_assert(*argnum == 0);
89456 +
89457 + gcc_assert(origarg != NULL_TREE);
89458 + origid = NAME(origarg);
89459 + *argnum = 0;
89460 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
89461 + if (!strcmp(origid, NAME(arg)))
89462 + return true;
89463 + (*argnum)++;
89464 + }
89465 + return false;
89466 +}
89467 +
89468 +static bool skip_types(const_tree var)
89469 +{
89470 + switch (TREE_CODE(var)) {
89471 + case ADDR_EXPR:
89472 +#if BUILDING_GCC_VERSION >= 4006
89473 + case MEM_REF:
89474 +#endif
89475 + case ARRAY_REF:
89476 + case BIT_FIELD_REF:
89477 + case INDIRECT_REF:
89478 + case TARGET_MEM_REF:
89479 + case VAR_DECL:
89480 + return true;
89481 + default:
89482 + break;
89483 + }
89484 + return false;
89485 +}
89486 +
89487 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
89488 +{
89489 + gimple phi = get_def_stmt(result);
89490 + unsigned int i, n = gimple_phi_num_args(phi);
89491 +
89492 + if (!phi)
89493 + return false;
89494 +
89495 + pointer_set_insert(visited, phi);
89496 + for (i = 0; i < n; i++) {
89497 + const_tree arg = gimple_phi_arg_def(phi, i);
89498 + if (pre_expand(visited, arg))
89499 + return true;
89500 + }
89501 + return false;
89502 +}
89503 +
89504 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
89505 +{
89506 + gimple def_stmt = get_def_stmt(lhs);
89507 + const_tree rhs;
89508 +
89509 + if (!def_stmt)
89510 + return false;
89511 +
89512 + rhs = gimple_assign_rhs1(def_stmt);
89513 + if (pre_expand(visited, rhs))
89514 + return true;
89515 + return false;
89516 +}
89517 +
89518 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
89519 +{
89520 + bool rhs1_found, rhs2_found;
89521 + gimple def_stmt = get_def_stmt(lhs);
89522 + const_tree rhs1, rhs2;
89523 +
89524 + if (!def_stmt)
89525 + return false;
89526 +
89527 + rhs1 = gimple_assign_rhs1(def_stmt);
89528 + rhs2 = gimple_assign_rhs2(def_stmt);
89529 + rhs1_found = pre_expand(visited, rhs1);
89530 + rhs2_found = pre_expand(visited, rhs2);
89531 +
89532 + return rhs1_found || rhs2_found;
89533 +}
89534 +
89535 +static const_tree search_field_decl(const_tree comp_ref)
89536 +{
89537 + const_tree field = NULL_TREE;
89538 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
89539 +
89540 + for (i = 0; i < len; i++) {
89541 + field = TREE_OPERAND(comp_ref, i);
89542 + if (TREE_CODE(field) == FIELD_DECL)
89543 + break;
89544 + }
89545 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
89546 + return field;
89547 +}
89548 +
89549 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
89550 +{
89551 + const_tree attr, p;
89552 +
89553 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
89554 + if (!attr || !TREE_VALUE(attr))
89555 + return MARKED_NO;
89556 +
89557 + p = TREE_VALUE(attr);
89558 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
89559 + return MARKED_NOT_INTENTIONAL;
89560 +
89561 + do {
89562 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
89563 + return MARKED_YES;
89564 + p = TREE_CHAIN(p);
89565 + } while (p);
89566 +
89567 + return MARKED_NO;
89568 +}
89569 +
89570 +static void print_missing_msg(tree func, unsigned int argnum)
89571 +{
89572 + unsigned int new_hash;
89573 + size_t len;
89574 + unsigned char tree_codes[CODES_LIMIT];
89575 + location_t loc = DECL_SOURCE_LOCATION(func);
89576 + const char *curfunc = get_asm_name(func);
89577 +
89578 + len = get_function_decl(func, tree_codes);
89579 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
89580 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
89581 +}
89582 +
89583 +static unsigned int search_missing_attribute(const_tree arg)
89584 +{
89585 + const_tree type = TREE_TYPE(arg);
89586 + tree func = get_original_function_decl(current_function_decl);
89587 + unsigned int argnum;
89588 + const struct size_overflow_hash *hash;
89589 +
89590 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
89591 +
89592 + if (TREE_CODE(type) == POINTER_TYPE)
89593 + return 0;
89594 +
89595 + argnum = find_arg_number(arg, func);
89596 + if (argnum == 0)
89597 + return 0;
89598 +
89599 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
89600 + return argnum;
89601 +
89602 + hash = get_function_hash(func);
89603 + if (!hash || !(hash->param & (1U << argnum))) {
89604 + print_missing_msg(func, argnum);
89605 + return 0;
89606 + }
89607 + return argnum;
89608 +}
89609 +
89610 +static bool is_already_marked(const_tree lhs)
89611 +{
89612 + unsigned int argnum;
89613 + const_tree fndecl;
89614 +
89615 + argnum = search_missing_attribute(lhs);
89616 + fndecl = get_original_function_decl(current_function_decl);
89617 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
89618 + return true;
89619 + return false;
89620 +}
89621 +
89622 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
89623 +{
89624 + const_gimple def_stmt;
89625 +
89626 + if (is_gimple_constant(lhs))
89627 + return false;
89628 +
89629 + if (skip_types(lhs))
89630 + return false;
89631 +
89632 + if (TREE_CODE(lhs) == PARM_DECL)
89633 + return is_already_marked(lhs);
89634 +
89635 + if (TREE_CODE(lhs) == COMPONENT_REF) {
89636 + const_tree field, attr;
89637 +
89638 + field = search_field_decl(lhs);
89639 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
89640 + if (!attr || !TREE_VALUE(attr))
89641 + return false;
89642 + return true;
89643 + }
89644 +
89645 + def_stmt = get_def_stmt(lhs);
89646 +
89647 + if (!def_stmt)
89648 + return false;
89649 +
89650 + if (pointer_set_contains(visited, def_stmt))
89651 + return false;
89652 +
89653 + switch (gimple_code(def_stmt)) {
89654 + case GIMPLE_NOP:
89655 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
89656 + return is_already_marked(lhs);
89657 + return false;
89658 + case GIMPLE_PHI:
89659 + return walk_phi(visited, lhs);
89660 + case GIMPLE_CALL:
89661 + case GIMPLE_ASM:
89662 + return false;
89663 + case GIMPLE_ASSIGN:
89664 + switch (gimple_num_ops(def_stmt)) {
89665 + case 2:
89666 + return walk_unary_ops(visited, lhs);
89667 + case 3:
89668 + return walk_binary_ops(visited, lhs);
89669 + }
89670 + default:
89671 + debug_gimple_stmt((gimple)def_stmt);
89672 + error("%s: unknown gimple code", __func__);
89673 + gcc_unreachable();
89674 + }
89675 +}
89676 +
89677 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
89678 +{
89679 + struct pointer_set_t *visited;
89680 + bool is_found;
89681 + enum marked is_marked;
89682 + location_t loc;
89683 +
89684 + visited = pointer_set_create();
89685 + is_found = pre_expand(visited, arg);
89686 + pointer_set_destroy(visited);
89687 +
89688 + is_marked = mark_status(fndecl, argnum + 1);
89689 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
89690 + return true;
89691 +
89692 + if (is_found) {
89693 + loc = DECL_SOURCE_LOCATION(fndecl);
89694 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
89695 + return true;
89696 + }
89697 + return false;
89698 +}
89699 +
89700 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
89701 +{
89702 + struct pointer_set_t *visited;
89703 + tree arg, newarg;
89704 + bool match;
89705 +
89706 + match = get_function_arg(&argnum, fndecl);
89707 + if (!match)
89708 + return;
89709 + gcc_assert(gimple_call_num_args(stmt) > argnum);
89710 + arg = gimple_call_arg(stmt, argnum);
89711 + if (arg == NULL_TREE)
89712 + return;
89713 +
89714 + if (is_gimple_constant(arg))
89715 + return;
89716 +
89717 + if (search_attributes(fndecl, arg, argnum))
89718 + return;
89719 +
89720 + if (TREE_CODE(arg) != SSA_NAME)
89721 + return;
89722 +
89723 + check_arg_type(arg);
89724 +
89725 + visited = pointer_set_create();
89726 + newarg = expand(visited, arg);
89727 + pointer_set_destroy(visited);
89728 +
89729 + if (newarg == NULL_TREE)
89730 + return;
89731 +
89732 + change_function_arg(stmt, arg, argnum, newarg);
89733 +
89734 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
89735 +}
89736 +
89737 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
89738 +{
89739 + tree p = TREE_VALUE(attr);
89740 + do {
89741 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
89742 + p = TREE_CHAIN(p);
89743 + } while (p);
89744 +}
89745 +
89746 +static void handle_function_by_hash(gimple stmt, tree fndecl)
89747 +{
89748 + tree orig_fndecl;
89749 + unsigned int num;
89750 + const struct size_overflow_hash *hash;
89751 +
89752 + orig_fndecl = get_original_function_decl(fndecl);
89753 + if (C_DECL_IMPLICIT(orig_fndecl))
89754 + return;
89755 + hash = get_function_hash(orig_fndecl);
89756 + if (!hash)
89757 + return;
89758 +
89759 + for (num = 1; num <= MAX_PARAM; num++)
89760 + if (hash->param & (1U << num))
89761 + handle_function_arg(stmt, fndecl, num - 1);
89762 +}
89763 +
89764 +static void set_plf_false(void)
89765 +{
89766 + basic_block bb;
89767 +
89768 + FOR_ALL_BB(bb) {
89769 + gimple_stmt_iterator si;
89770 +
89771 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89772 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89773 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89774 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89775 + }
89776 +}
89777 +
89778 +static unsigned int handle_function(void)
89779 +{
89780 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89781 +
89782 + set_plf_false();
89783 +
89784 + do {
89785 + gimple_stmt_iterator gsi;
89786 + next = bb->next_bb;
89787 +
89788 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89789 + tree fndecl, attr;
89790 + gimple stmt = gsi_stmt(gsi);
89791 +
89792 + if (!(is_gimple_call(stmt)))
89793 + continue;
89794 + fndecl = gimple_call_fndecl(stmt);
89795 + if (fndecl == NULL_TREE)
89796 + continue;
89797 + if (gimple_call_num_args(stmt) == 0)
89798 + continue;
89799 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89800 + if (!attr || !TREE_VALUE(attr))
89801 + handle_function_by_hash(stmt, fndecl);
89802 + else
89803 + handle_function_by_attribute(stmt, attr, fndecl);
89804 + gsi = gsi_for_stmt(stmt);
89805 + next = gimple_bb(stmt)->next_bb;
89806 + }
89807 + bb = next;
89808 + } while (bb);
89809 + return 0;
89810 +}
89811 +
89812 +static struct gimple_opt_pass size_overflow_pass = {
89813 + .pass = {
89814 + .type = GIMPLE_PASS,
89815 + .name = "size_overflow",
89816 + .gate = NULL,
89817 + .execute = handle_function,
89818 + .sub = NULL,
89819 + .next = NULL,
89820 + .static_pass_number = 0,
89821 + .tv_id = TV_NONE,
89822 + .properties_required = PROP_cfg | PROP_referenced_vars,
89823 + .properties_provided = 0,
89824 + .properties_destroyed = 0,
89825 + .todo_flags_start = 0,
89826 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi | TODO_cleanup_cfg | TODO_ggc_collect | TODO_verify_flow
89827 + }
89828 +};
89829 +
89830 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89831 +{
89832 + tree fntype;
89833 +
89834 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89835 +
89836 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89837 + fntype = build_function_type_list(void_type_node,
89838 + const_char_ptr_type_node,
89839 + unsigned_type_node,
89840 + const_char_ptr_type_node,
89841 + const_char_ptr_type_node,
89842 + NULL_TREE);
89843 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89844 +
89845 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89846 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89847 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89848 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89849 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89850 +}
89851 +
89852 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89853 +{
89854 + int i;
89855 + const char * const plugin_name = plugin_info->base_name;
89856 + const int argc = plugin_info->argc;
89857 + const struct plugin_argument * const argv = plugin_info->argv;
89858 + bool enable = true;
89859 +
89860 + struct register_pass_info size_overflow_pass_info = {
89861 + .pass = &size_overflow_pass.pass,
89862 + .reference_pass_name = "ssa",
89863 + .ref_pass_instance_number = 1,
89864 + .pos_op = PASS_POS_INSERT_AFTER
89865 + };
89866 +
89867 + if (!plugin_default_version_check(version, &gcc_version)) {
89868 + error(G_("incompatible gcc/plugin versions"));
89869 + return 1;
89870 + }
89871 +
89872 + for (i = 0; i < argc; ++i) {
89873 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89874 + enable = false;
89875 + continue;
89876 + }
89877 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89878 + }
89879 +
89880 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89881 + if (enable) {
89882 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89883 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89884 + }
89885 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89886 +
89887 + return 0;
89888 +}
89889 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89890 new file mode 100644
89891 index 0000000..38d2014
89892 --- /dev/null
89893 +++ b/tools/gcc/stackleak_plugin.c
89894 @@ -0,0 +1,313 @@
89895 +/*
89896 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89897 + * Licensed under the GPL v2
89898 + *
89899 + * Note: the choice of the license means that the compilation process is
89900 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89901 + * but for the kernel it doesn't matter since it doesn't link against
89902 + * any of the gcc libraries
89903 + *
89904 + * gcc plugin to help implement various PaX features
89905 + *
89906 + * - track lowest stack pointer
89907 + *
89908 + * TODO:
89909 + * - initialize all local variables
89910 + *
89911 + * BUGS:
89912 + * - none known
89913 + */
89914 +#include "gcc-plugin.h"
89915 +#include "config.h"
89916 +#include "system.h"
89917 +#include "coretypes.h"
89918 +#include "tree.h"
89919 +#include "tree-pass.h"
89920 +#include "flags.h"
89921 +#include "intl.h"
89922 +#include "toplev.h"
89923 +#include "plugin.h"
89924 +//#include "expr.h" where are you...
89925 +#include "diagnostic.h"
89926 +#include "plugin-version.h"
89927 +#include "tm.h"
89928 +#include "function.h"
89929 +#include "basic-block.h"
89930 +#include "gimple.h"
89931 +#include "rtl.h"
89932 +#include "emit-rtl.h"
89933 +
89934 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89935 +
89936 +int plugin_is_GPL_compatible;
89937 +
89938 +static int track_frame_size = -1;
89939 +static const char track_function[] = "pax_track_stack";
89940 +static const char check_function[] = "pax_check_alloca";
89941 +static bool init_locals;
89942 +
89943 +static struct plugin_info stackleak_plugin_info = {
89944 + .version = "201203140940",
89945 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89946 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89947 +};
89948 +
89949 +static bool gate_stackleak_track_stack(void);
89950 +static unsigned int execute_stackleak_tree_instrument(void);
89951 +static unsigned int execute_stackleak_final(void);
89952 +
89953 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89954 + .pass = {
89955 + .type = GIMPLE_PASS,
89956 + .name = "stackleak_tree_instrument",
89957 + .gate = gate_stackleak_track_stack,
89958 + .execute = execute_stackleak_tree_instrument,
89959 + .sub = NULL,
89960 + .next = NULL,
89961 + .static_pass_number = 0,
89962 + .tv_id = TV_NONE,
89963 + .properties_required = PROP_gimple_leh | PROP_cfg,
89964 + .properties_provided = 0,
89965 + .properties_destroyed = 0,
89966 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89967 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89968 + }
89969 +};
89970 +
89971 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89972 + .pass = {
89973 + .type = RTL_PASS,
89974 + .name = "stackleak_final",
89975 + .gate = gate_stackleak_track_stack,
89976 + .execute = execute_stackleak_final,
89977 + .sub = NULL,
89978 + .next = NULL,
89979 + .static_pass_number = 0,
89980 + .tv_id = TV_NONE,
89981 + .properties_required = 0,
89982 + .properties_provided = 0,
89983 + .properties_destroyed = 0,
89984 + .todo_flags_start = 0,
89985 + .todo_flags_finish = TODO_dump_func
89986 + }
89987 +};
89988 +
89989 +static bool gate_stackleak_track_stack(void)
89990 +{
89991 + return track_frame_size >= 0;
89992 +}
89993 +
89994 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89995 +{
89996 + gimple check_alloca;
89997 + tree fntype, fndecl, alloca_size;
89998 +
89999 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
90000 + fndecl = build_fn_decl(check_function, fntype);
90001 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
90002 +
90003 + // insert call to void pax_check_alloca(unsigned long size)
90004 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
90005 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
90006 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
90007 +}
90008 +
90009 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
90010 +{
90011 + gimple track_stack;
90012 + tree fntype, fndecl;
90013 +
90014 + fntype = build_function_type_list(void_type_node, NULL_TREE);
90015 + fndecl = build_fn_decl(track_function, fntype);
90016 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
90017 +
90018 + // insert call to void pax_track_stack(void)
90019 + track_stack = gimple_build_call(fndecl, 0);
90020 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
90021 +}
90022 +
90023 +#if BUILDING_GCC_VERSION == 4005
90024 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
90025 +{
90026 + tree fndecl;
90027 +
90028 + if (!is_gimple_call(stmt))
90029 + return false;
90030 + fndecl = gimple_call_fndecl(stmt);
90031 + if (!fndecl)
90032 + return false;
90033 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
90034 + return false;
90035 +// print_node(stderr, "pax", fndecl, 4);
90036 + return DECL_FUNCTION_CODE(fndecl) == code;
90037 +}
90038 +#endif
90039 +
90040 +static bool is_alloca(gimple stmt)
90041 +{
90042 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
90043 + return true;
90044 +
90045 +#if BUILDING_GCC_VERSION >= 4007
90046 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
90047 + return true;
90048 +#endif
90049 +
90050 + return false;
90051 +}
90052 +
90053 +static unsigned int execute_stackleak_tree_instrument(void)
90054 +{
90055 + basic_block bb, entry_bb;
90056 + bool prologue_instrumented = false, is_leaf = true;
90057 +
90058 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
90059 +
90060 + // 1. loop through BBs and GIMPLE statements
90061 + FOR_EACH_BB(bb) {
90062 + gimple_stmt_iterator gsi;
90063 +
90064 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
90065 + gimple stmt;
90066 +
90067 + stmt = gsi_stmt(gsi);
90068 +
90069 + if (is_gimple_call(stmt))
90070 + is_leaf = false;
90071 +
90072 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
90073 + if (!is_alloca(stmt))
90074 + continue;
90075 +
90076 + // 2. insert stack overflow check before each __builtin_alloca call
90077 + stackleak_check_alloca(&gsi);
90078 +
90079 + // 3. insert track call after each __builtin_alloca call
90080 + stackleak_add_instrumentation(&gsi);
90081 + if (bb == entry_bb)
90082 + prologue_instrumented = true;
90083 + }
90084 + }
90085 +
90086 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
90087 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
90088 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
90089 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
90090 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
90091 + return 0;
90092 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
90093 + return 0;
90094 +
90095 + // 4. insert track call at the beginning
90096 + if (!prologue_instrumented) {
90097 + gimple_stmt_iterator gsi;
90098 +
90099 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
90100 + if (dom_info_available_p(CDI_DOMINATORS))
90101 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
90102 + gsi = gsi_start_bb(bb);
90103 + stackleak_add_instrumentation(&gsi);
90104 + }
90105 +
90106 + return 0;
90107 +}
90108 +
90109 +static unsigned int execute_stackleak_final(void)
90110 +{
90111 + rtx insn;
90112 +
90113 + if (cfun->calls_alloca)
90114 + return 0;
90115 +
90116 + // keep calls only if function frame is big enough
90117 + if (get_frame_size() >= track_frame_size)
90118 + return 0;
90119 +
90120 + // 1. find pax_track_stack calls
90121 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
90122 + // rtl match: (call_insn 8 7 9 3 (call (mem (symbol_ref ("pax_track_stack") [flags 0x41] <function_decl 0xb7470e80 pax_track_stack>) [0 S1 A8]) (4)) -1 (nil) (nil))
90123 + rtx body;
90124 +
90125 + if (!CALL_P(insn))
90126 + continue;
90127 + body = PATTERN(insn);
90128 + if (GET_CODE(body) != CALL)
90129 + continue;
90130 + body = XEXP(body, 0);
90131 + if (GET_CODE(body) != MEM)
90132 + continue;
90133 + body = XEXP(body, 0);
90134 + if (GET_CODE(body) != SYMBOL_REF)
90135 + continue;
90136 + if (strcmp(XSTR(body, 0), track_function))
90137 + continue;
90138 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
90139 + // 2. delete call
90140 + insn = delete_insn_and_edges(insn);
90141 +#if BUILDING_GCC_VERSION >= 4007
90142 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
90143 + insn = delete_insn_and_edges(insn);
90144 +#endif
90145 + }
90146 +
90147 +// print_simple_rtl(stderr, get_insns());
90148 +// print_rtl(stderr, get_insns());
90149 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
90150 +
90151 + return 0;
90152 +}
90153 +
90154 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
90155 +{
90156 + const char * const plugin_name = plugin_info->base_name;
90157 + const int argc = plugin_info->argc;
90158 + const struct plugin_argument * const argv = plugin_info->argv;
90159 + int i;
90160 + struct register_pass_info stackleak_tree_instrument_pass_info = {
90161 + .pass = &stackleak_tree_instrument_pass.pass,
90162 +// .reference_pass_name = "tree_profile",
90163 + .reference_pass_name = "optimized",
90164 + .ref_pass_instance_number = 1,
90165 + .pos_op = PASS_POS_INSERT_BEFORE
90166 + };
90167 + struct register_pass_info stackleak_final_pass_info = {
90168 + .pass = &stackleak_final_rtl_opt_pass.pass,
90169 + .reference_pass_name = "final",
90170 + .ref_pass_instance_number = 1,
90171 + .pos_op = PASS_POS_INSERT_BEFORE
90172 + };
90173 +
90174 + if (!plugin_default_version_check(version, &gcc_version)) {
90175 + error(G_("incompatible gcc/plugin versions"));
90176 + return 1;
90177 + }
90178 +
90179 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
90180 +
90181 + for (i = 0; i < argc; ++i) {
90182 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
90183 + if (!argv[i].value) {
90184 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
90185 + continue;
90186 + }
90187 + track_frame_size = atoi(argv[i].value);
90188 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
90189 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
90190 + continue;
90191 + }
90192 + if (!strcmp(argv[i].key, "initialize-locals")) {
90193 + if (argv[i].value) {
90194 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
90195 + continue;
90196 + }
90197 + init_locals = true;
90198 + continue;
90199 + }
90200 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
90201 + }
90202 +
90203 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
90204 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
90205 +
90206 + return 0;
90207 +}
90208 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
90209 index 6789d78..4afd019e 100644
90210 --- a/tools/perf/util/include/asm/alternative-asm.h
90211 +++ b/tools/perf/util/include/asm/alternative-asm.h
90212 @@ -5,4 +5,7 @@
90213
90214 #define altinstruction_entry #
90215
90216 + .macro pax_force_retaddr rip=0, reload=0
90217 + .endm
90218 +
90219 #endif
90220 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
90221 index d617f69..6b445d2 100644
90222 --- a/virt/kvm/kvm_main.c
90223 +++ b/virt/kvm/kvm_main.c
90224 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
90225
90226 static cpumask_var_t cpus_hardware_enabled;
90227 static int kvm_usage_count = 0;
90228 -static atomic_t hardware_enable_failed;
90229 +static atomic_unchecked_t hardware_enable_failed;
90230
90231 struct kmem_cache *kvm_vcpu_cache;
90232 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
90233 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
90234 /* We can read the guest memory with __xxx_user() later on. */
90235 if (user_alloc &&
90236 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
90237 - !access_ok(VERIFY_WRITE,
90238 + !__access_ok(VERIFY_WRITE,
90239 (void __user *)(unsigned long)mem->userspace_addr,
90240 mem->memory_size)))
90241 goto out;
90242 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
90243
90244 if (r) {
90245 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
90246 - atomic_inc(&hardware_enable_failed);
90247 + atomic_inc_unchecked(&hardware_enable_failed);
90248 printk(KERN_INFO "kvm: enabling virtualization on "
90249 "CPU%d failed\n", cpu);
90250 }
90251 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
90252
90253 kvm_usage_count++;
90254 if (kvm_usage_count == 1) {
90255 - atomic_set(&hardware_enable_failed, 0);
90256 + atomic_set_unchecked(&hardware_enable_failed, 0);
90257 on_each_cpu(hardware_enable_nolock, NULL, 1);
90258
90259 - if (atomic_read(&hardware_enable_failed)) {
90260 + if (atomic_read_unchecked(&hardware_enable_failed)) {
90261 hardware_disable_all_nolock();
90262 r = -EBUSY;
90263 }
90264 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
90265 kvm_arch_vcpu_put(vcpu);
90266 }
90267
90268 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90269 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90270 struct module *module)
90271 {
90272 int r;
90273 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90274 if (!vcpu_align)
90275 vcpu_align = __alignof__(struct kvm_vcpu);
90276 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
90277 - 0, NULL);
90278 + SLAB_USERCOPY, NULL);
90279 if (!kvm_vcpu_cache) {
90280 r = -ENOMEM;
90281 goto out_free_3;
90282 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90283 if (r)
90284 goto out_free;
90285
90286 - kvm_chardev_ops.owner = module;
90287 - kvm_vm_fops.owner = module;
90288 - kvm_vcpu_fops.owner = module;
90289 + pax_open_kernel();
90290 + *(void **)&kvm_chardev_ops.owner = module;
90291 + *(void **)&kvm_vm_fops.owner = module;
90292 + *(void **)&kvm_vcpu_fops.owner = module;
90293 + pax_close_kernel();
90294
90295 r = misc_register(&kvm_dev);
90296 if (r) {