]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.10-201212101818.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.10-201212101818.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 686b83c..5e0a360 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/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3474 index f76c108..8117482 100644
3475 --- a/arch/parisc/kernel/sys_parisc.c
3476 +++ b/arch/parisc/kernel/sys_parisc.c
3477 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3478 /* At this point: (!vma || addr < vma->vm_end). */
3479 if (TASK_SIZE - len < addr)
3480 return -ENOMEM;
3481 - if (!vma || addr + len <= vma->vm_start)
3482 + if (check_heap_stack_gap(vma, addr, len))
3483 return addr;
3484 addr = vma->vm_end;
3485 }
3486 @@ -81,7 +81,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3487 /* At this point: (!vma || addr < vma->vm_end). */
3488 if (TASK_SIZE - len < addr)
3489 return -ENOMEM;
3490 - if (!vma || addr + len <= vma->vm_start)
3491 + if (check_heap_stack_gap(vma, addr, len))
3492 return addr;
3493 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3494 if (addr < vma->vm_end) /* handle wraparound */
3495 @@ -100,7 +100,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3496 if (flags & MAP_FIXED)
3497 return addr;
3498 if (!addr)
3499 - addr = TASK_UNMAPPED_BASE;
3500 + addr = current->mm->mmap_base;
3501
3502 if (filp) {
3503 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3504 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3505 index 45ba99f..8e22c33 100644
3506 --- a/arch/parisc/kernel/traps.c
3507 +++ b/arch/parisc/kernel/traps.c
3508 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3509
3510 down_read(&current->mm->mmap_sem);
3511 vma = find_vma(current->mm,regs->iaoq[0]);
3512 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3513 - && (vma->vm_flags & VM_EXEC)) {
3514 -
3515 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3516 fault_address = regs->iaoq[0];
3517 fault_space = regs->iasq[0];
3518
3519 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3520 index 18162ce..94de376 100644
3521 --- a/arch/parisc/mm/fault.c
3522 +++ b/arch/parisc/mm/fault.c
3523 @@ -15,6 +15,7 @@
3524 #include <linux/sched.h>
3525 #include <linux/interrupt.h>
3526 #include <linux/module.h>
3527 +#include <linux/unistd.h>
3528
3529 #include <asm/uaccess.h>
3530 #include <asm/traps.h>
3531 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3532 static unsigned long
3533 parisc_acctyp(unsigned long code, unsigned int inst)
3534 {
3535 - if (code == 6 || code == 16)
3536 + if (code == 6 || code == 7 || code == 16)
3537 return VM_EXEC;
3538
3539 switch (inst & 0xf0000000) {
3540 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3541 }
3542 #endif
3543
3544 +#ifdef CONFIG_PAX_PAGEEXEC
3545 +/*
3546 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3547 + *
3548 + * returns 1 when task should be killed
3549 + * 2 when rt_sigreturn trampoline was detected
3550 + * 3 when unpatched PLT trampoline was detected
3551 + */
3552 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3553 +{
3554 +
3555 +#ifdef CONFIG_PAX_EMUPLT
3556 + int err;
3557 +
3558 + do { /* PaX: unpatched PLT emulation */
3559 + unsigned int bl, depwi;
3560 +
3561 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3562 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3563 +
3564 + if (err)
3565 + break;
3566 +
3567 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3568 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3569 +
3570 + err = get_user(ldw, (unsigned int *)addr);
3571 + err |= get_user(bv, (unsigned int *)(addr+4));
3572 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3573 +
3574 + if (err)
3575 + break;
3576 +
3577 + if (ldw == 0x0E801096U &&
3578 + bv == 0xEAC0C000U &&
3579 + ldw2 == 0x0E881095U)
3580 + {
3581 + unsigned int resolver, map;
3582 +
3583 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3584 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3585 + if (err)
3586 + break;
3587 +
3588 + regs->gr[20] = instruction_pointer(regs)+8;
3589 + regs->gr[21] = map;
3590 + regs->gr[22] = resolver;
3591 + regs->iaoq[0] = resolver | 3UL;
3592 + regs->iaoq[1] = regs->iaoq[0] + 4;
3593 + return 3;
3594 + }
3595 + }
3596 + } while (0);
3597 +#endif
3598 +
3599 +#ifdef CONFIG_PAX_EMUTRAMP
3600 +
3601 +#ifndef CONFIG_PAX_EMUSIGRT
3602 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3603 + return 1;
3604 +#endif
3605 +
3606 + do { /* PaX: rt_sigreturn emulation */
3607 + unsigned int ldi1, ldi2, bel, nop;
3608 +
3609 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3610 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3611 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3612 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3613 +
3614 + if (err)
3615 + break;
3616 +
3617 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3618 + ldi2 == 0x3414015AU &&
3619 + bel == 0xE4008200U &&
3620 + nop == 0x08000240U)
3621 + {
3622 + regs->gr[25] = (ldi1 & 2) >> 1;
3623 + regs->gr[20] = __NR_rt_sigreturn;
3624 + regs->gr[31] = regs->iaoq[1] + 16;
3625 + regs->sr[0] = regs->iasq[1];
3626 + regs->iaoq[0] = 0x100UL;
3627 + regs->iaoq[1] = regs->iaoq[0] + 4;
3628 + regs->iasq[0] = regs->sr[2];
3629 + regs->iasq[1] = regs->sr[2];
3630 + return 2;
3631 + }
3632 + } while (0);
3633 +#endif
3634 +
3635 + return 1;
3636 +}
3637 +
3638 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3639 +{
3640 + unsigned long i;
3641 +
3642 + printk(KERN_ERR "PAX: bytes at PC: ");
3643 + for (i = 0; i < 5; i++) {
3644 + unsigned int c;
3645 + if (get_user(c, (unsigned int *)pc+i))
3646 + printk(KERN_CONT "???????? ");
3647 + else
3648 + printk(KERN_CONT "%08x ", c);
3649 + }
3650 + printk("\n");
3651 +}
3652 +#endif
3653 +
3654 int fixup_exception(struct pt_regs *regs)
3655 {
3656 const struct exception_table_entry *fix;
3657 @@ -192,8 +303,33 @@ good_area:
3658
3659 acc_type = parisc_acctyp(code,regs->iir);
3660
3661 - if ((vma->vm_flags & acc_type) != acc_type)
3662 + if ((vma->vm_flags & acc_type) != acc_type) {
3663 +
3664 +#ifdef CONFIG_PAX_PAGEEXEC
3665 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3666 + (address & ~3UL) == instruction_pointer(regs))
3667 + {
3668 + up_read(&mm->mmap_sem);
3669 + switch (pax_handle_fetch_fault(regs)) {
3670 +
3671 +#ifdef CONFIG_PAX_EMUPLT
3672 + case 3:
3673 + return;
3674 +#endif
3675 +
3676 +#ifdef CONFIG_PAX_EMUTRAMP
3677 + case 2:
3678 + return;
3679 +#endif
3680 +
3681 + }
3682 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3683 + do_group_exit(SIGKILL);
3684 + }
3685 +#endif
3686 +
3687 goto bad_area;
3688 + }
3689
3690 /*
3691 * If for any reason at all we couldn't handle the fault, make
3692 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3693 index da29032..f76c24c 100644
3694 --- a/arch/powerpc/include/asm/atomic.h
3695 +++ b/arch/powerpc/include/asm/atomic.h
3696 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3697 return t1;
3698 }
3699
3700 +#define atomic64_read_unchecked(v) atomic64_read(v)
3701 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3702 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3703 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3704 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3705 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3706 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3707 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3708 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3709 +
3710 #endif /* __powerpc64__ */
3711
3712 #endif /* __KERNEL__ */
3713 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3714 index 9e495c9..b6878e5 100644
3715 --- a/arch/powerpc/include/asm/cache.h
3716 +++ b/arch/powerpc/include/asm/cache.h
3717 @@ -3,6 +3,7 @@
3718
3719 #ifdef __KERNEL__
3720
3721 +#include <linux/const.h>
3722
3723 /* bytes per L1 cache line */
3724 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3725 @@ -22,7 +23,7 @@
3726 #define L1_CACHE_SHIFT 7
3727 #endif
3728
3729 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3730 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3731
3732 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3733
3734 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3735 index 3bf9cca..e7457d0 100644
3736 --- a/arch/powerpc/include/asm/elf.h
3737 +++ b/arch/powerpc/include/asm/elf.h
3738 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3739 the loader. We need to make sure that it is out of the way of the program
3740 that it will "exec", and that there is sufficient room for the brk. */
3741
3742 -extern unsigned long randomize_et_dyn(unsigned long base);
3743 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3744 +#define ELF_ET_DYN_BASE (0x20000000)
3745 +
3746 +#ifdef CONFIG_PAX_ASLR
3747 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3748 +
3749 +#ifdef __powerpc64__
3750 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3751 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3752 +#else
3753 +#define PAX_DELTA_MMAP_LEN 15
3754 +#define PAX_DELTA_STACK_LEN 15
3755 +#endif
3756 +#endif
3757
3758 /*
3759 * Our registers are always unsigned longs, whether we're a 32 bit
3760 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3761 (0x7ff >> (PAGE_SHIFT - 12)) : \
3762 (0x3ffff >> (PAGE_SHIFT - 12)))
3763
3764 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3765 -#define arch_randomize_brk arch_randomize_brk
3766 -
3767 #endif /* __KERNEL__ */
3768
3769 /*
3770 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3771 index 8196e9c..d83a9f3 100644
3772 --- a/arch/powerpc/include/asm/exec.h
3773 +++ b/arch/powerpc/include/asm/exec.h
3774 @@ -4,6 +4,6 @@
3775 #ifndef _ASM_POWERPC_EXEC_H
3776 #define _ASM_POWERPC_EXEC_H
3777
3778 -extern unsigned long arch_align_stack(unsigned long sp);
3779 +#define arch_align_stack(x) ((x) & ~0xfUL)
3780
3781 #endif /* _ASM_POWERPC_EXEC_H */
3782 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3783 index 5acabbd..7ea14fa 100644
3784 --- a/arch/powerpc/include/asm/kmap_types.h
3785 +++ b/arch/powerpc/include/asm/kmap_types.h
3786 @@ -10,7 +10,7 @@
3787 * 2 of the License, or (at your option) any later version.
3788 */
3789
3790 -#define KM_TYPE_NR 16
3791 +#define KM_TYPE_NR 17
3792
3793 #endif /* __KERNEL__ */
3794 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3795 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3796 index d4a7f64..451de1c 100644
3797 --- a/arch/powerpc/include/asm/mman.h
3798 +++ b/arch/powerpc/include/asm/mman.h
3799 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3800 }
3801 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3802
3803 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3804 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3805 {
3806 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3807 }
3808 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3809 index f072e97..b436dee 100644
3810 --- a/arch/powerpc/include/asm/page.h
3811 +++ b/arch/powerpc/include/asm/page.h
3812 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3813 * and needs to be executable. This means the whole heap ends
3814 * up being executable.
3815 */
3816 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3817 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3818 +#define VM_DATA_DEFAULT_FLAGS32 \
3819 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3820 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3821
3822 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3823 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3824 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3825 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3826 #endif
3827
3828 +#define ktla_ktva(addr) (addr)
3829 +#define ktva_ktla(addr) (addr)
3830 +
3831 /*
3832 * Use the top bit of the higher-level page table entries to indicate whether
3833 * the entries we point to contain hugepages. This works because we know that
3834 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3835 index fed85e6..da5c71b 100644
3836 --- a/arch/powerpc/include/asm/page_64.h
3837 +++ b/arch/powerpc/include/asm/page_64.h
3838 @@ -146,15 +146,18 @@ do { \
3839 * stack by default, so in the absence of a PT_GNU_STACK program header
3840 * we turn execute permission off.
3841 */
3842 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3843 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3844 +#define VM_STACK_DEFAULT_FLAGS32 \
3845 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3846 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3847
3848 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3849 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3850
3851 +#ifndef CONFIG_PAX_PAGEEXEC
3852 #define VM_STACK_DEFAULT_FLAGS \
3853 (is_32bit_task() ? \
3854 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3855 +#endif
3856
3857 #include <asm-generic/getorder.h>
3858
3859 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3860 index 292725c..f87ae14 100644
3861 --- a/arch/powerpc/include/asm/pgalloc-64.h
3862 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3863 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3864 #ifndef CONFIG_PPC_64K_PAGES
3865
3866 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3867 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3868
3869 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3870 {
3871 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3872 pud_set(pud, (unsigned long)pmd);
3873 }
3874
3875 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3876 +{
3877 + pud_populate(mm, pud, pmd);
3878 +}
3879 +
3880 #define pmd_populate(mm, pmd, pte_page) \
3881 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3882 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3883 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3884 #else /* CONFIG_PPC_64K_PAGES */
3885
3886 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3887 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3888
3889 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3890 pte_t *pte)
3891 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3892 index 2e0e411..7899c68 100644
3893 --- a/arch/powerpc/include/asm/pgtable.h
3894 +++ b/arch/powerpc/include/asm/pgtable.h
3895 @@ -2,6 +2,7 @@
3896 #define _ASM_POWERPC_PGTABLE_H
3897 #ifdef __KERNEL__
3898
3899 +#include <linux/const.h>
3900 #ifndef __ASSEMBLY__
3901 #include <asm/processor.h> /* For TASK_SIZE */
3902 #include <asm/mmu.h>
3903 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3904 index 4aad413..85d86bf 100644
3905 --- a/arch/powerpc/include/asm/pte-hash32.h
3906 +++ b/arch/powerpc/include/asm/pte-hash32.h
3907 @@ -21,6 +21,7 @@
3908 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3909 #define _PAGE_USER 0x004 /* usermode access allowed */
3910 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3911 +#define _PAGE_EXEC _PAGE_GUARDED
3912 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3913 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3914 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3915 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3916 index 6386086..6982225 100644
3917 --- a/arch/powerpc/include/asm/reg.h
3918 +++ b/arch/powerpc/include/asm/reg.h
3919 @@ -212,6 +212,7 @@
3920 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3921 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3922 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3923 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3924 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3925 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3926 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3927 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3928 index faf9352..ab2ccec 100644
3929 --- a/arch/powerpc/include/asm/thread_info.h
3930 +++ b/arch/powerpc/include/asm/thread_info.h
3931 @@ -97,12 +97,14 @@ static inline struct thread_info *current_thread_info(void)
3932 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3933 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3934 #define TIF_SINGLESTEP 8 /* singlestepping active */
3935 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3936 #define TIF_SECCOMP 10 /* secure computing */
3937 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3938 #define TIF_NOERROR 12 /* Force successful syscall return */
3939 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3940 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3941 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3942 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3943 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3944
3945 /* as above, but as bit values */
3946 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3947 @@ -119,8 +121,10 @@ static inline struct thread_info *current_thread_info(void)
3948 #define _TIF_NOERROR (1<<TIF_NOERROR)
3949 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3950 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3951 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3952 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3953 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3954 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3955 + _TIF_GRSEC_SETXID)
3956
3957 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3958 _TIF_NOTIFY_RESUME)
3959 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3960 index 17bb40c..353c98b 100644
3961 --- a/arch/powerpc/include/asm/uaccess.h
3962 +++ b/arch/powerpc/include/asm/uaccess.h
3963 @@ -13,6 +13,8 @@
3964 #define VERIFY_READ 0
3965 #define VERIFY_WRITE 1
3966
3967 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3968 +
3969 /*
3970 * The fs value determines whether argument validity checking should be
3971 * performed or not. If get_fs() == USER_DS, checking is performed, with
3972 @@ -329,52 +331,6 @@ do { \
3973 extern unsigned long __copy_tofrom_user(void __user *to,
3974 const void __user *from, unsigned long size);
3975
3976 -#ifndef __powerpc64__
3977 -
3978 -static inline unsigned long copy_from_user(void *to,
3979 - const void __user *from, unsigned long n)
3980 -{
3981 - unsigned long over;
3982 -
3983 - if (access_ok(VERIFY_READ, from, n))
3984 - return __copy_tofrom_user((__force void __user *)to, from, n);
3985 - if ((unsigned long)from < TASK_SIZE) {
3986 - over = (unsigned long)from + n - TASK_SIZE;
3987 - return __copy_tofrom_user((__force void __user *)to, from,
3988 - n - over) + over;
3989 - }
3990 - return n;
3991 -}
3992 -
3993 -static inline unsigned long copy_to_user(void __user *to,
3994 - const void *from, unsigned long n)
3995 -{
3996 - unsigned long over;
3997 -
3998 - if (access_ok(VERIFY_WRITE, to, n))
3999 - return __copy_tofrom_user(to, (__force void __user *)from, n);
4000 - if ((unsigned long)to < TASK_SIZE) {
4001 - over = (unsigned long)to + n - TASK_SIZE;
4002 - return __copy_tofrom_user(to, (__force void __user *)from,
4003 - n - over) + over;
4004 - }
4005 - return n;
4006 -}
4007 -
4008 -#else /* __powerpc64__ */
4009 -
4010 -#define __copy_in_user(to, from, size) \
4011 - __copy_tofrom_user((to), (from), (size))
4012 -
4013 -extern unsigned long copy_from_user(void *to, const void __user *from,
4014 - unsigned long n);
4015 -extern unsigned long copy_to_user(void __user *to, const void *from,
4016 - unsigned long n);
4017 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4018 - unsigned long n);
4019 -
4020 -#endif /* __powerpc64__ */
4021 -
4022 static inline unsigned long __copy_from_user_inatomic(void *to,
4023 const void __user *from, unsigned long n)
4024 {
4025 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4026 if (ret == 0)
4027 return 0;
4028 }
4029 +
4030 + if (!__builtin_constant_p(n))
4031 + check_object_size(to, n, false);
4032 +
4033 return __copy_tofrom_user((__force void __user *)to, from, n);
4034 }
4035
4036 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4037 if (ret == 0)
4038 return 0;
4039 }
4040 +
4041 + if (!__builtin_constant_p(n))
4042 + check_object_size(from, n, true);
4043 +
4044 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4045 }
4046
4047 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4048 return __copy_to_user_inatomic(to, from, size);
4049 }
4050
4051 +#ifndef __powerpc64__
4052 +
4053 +static inline unsigned long __must_check copy_from_user(void *to,
4054 + const void __user *from, unsigned long n)
4055 +{
4056 + unsigned long over;
4057 +
4058 + if ((long)n < 0)
4059 + return n;
4060 +
4061 + if (access_ok(VERIFY_READ, from, n)) {
4062 + if (!__builtin_constant_p(n))
4063 + check_object_size(to, n, false);
4064 + return __copy_tofrom_user((__force void __user *)to, from, n);
4065 + }
4066 + if ((unsigned long)from < TASK_SIZE) {
4067 + over = (unsigned long)from + n - TASK_SIZE;
4068 + if (!__builtin_constant_p(n - over))
4069 + check_object_size(to, n - over, false);
4070 + return __copy_tofrom_user((__force void __user *)to, from,
4071 + n - over) + over;
4072 + }
4073 + return n;
4074 +}
4075 +
4076 +static inline unsigned long __must_check copy_to_user(void __user *to,
4077 + const void *from, unsigned long n)
4078 +{
4079 + unsigned long over;
4080 +
4081 + if ((long)n < 0)
4082 + return n;
4083 +
4084 + if (access_ok(VERIFY_WRITE, to, n)) {
4085 + if (!__builtin_constant_p(n))
4086 + check_object_size(from, n, true);
4087 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4088 + }
4089 + if ((unsigned long)to < TASK_SIZE) {
4090 + over = (unsigned long)to + n - TASK_SIZE;
4091 + if (!__builtin_constant_p(n))
4092 + check_object_size(from, n - over, true);
4093 + return __copy_tofrom_user(to, (__force void __user *)from,
4094 + n - over) + over;
4095 + }
4096 + return n;
4097 +}
4098 +
4099 +#else /* __powerpc64__ */
4100 +
4101 +#define __copy_in_user(to, from, size) \
4102 + __copy_tofrom_user((to), (from), (size))
4103 +
4104 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4105 +{
4106 + if ((long)n < 0 || n > INT_MAX)
4107 + return n;
4108 +
4109 + if (!__builtin_constant_p(n))
4110 + check_object_size(to, n, false);
4111 +
4112 + if (likely(access_ok(VERIFY_READ, from, n)))
4113 + n = __copy_from_user(to, from, n);
4114 + else
4115 + memset(to, 0, n);
4116 + return n;
4117 +}
4118 +
4119 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4120 +{
4121 + if ((long)n < 0 || n > INT_MAX)
4122 + return n;
4123 +
4124 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4125 + if (!__builtin_constant_p(n))
4126 + check_object_size(from, n, true);
4127 + n = __copy_to_user(to, from, n);
4128 + }
4129 + return n;
4130 +}
4131 +
4132 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4133 + unsigned long n);
4134 +
4135 +#endif /* __powerpc64__ */
4136 +
4137 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4138
4139 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4140 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4141 index 98be7f0..8ef62de 100644
4142 --- a/arch/powerpc/kernel/exceptions-64e.S
4143 +++ b/arch/powerpc/kernel/exceptions-64e.S
4144 @@ -661,6 +661,7 @@ storage_fault_common:
4145 std r14,_DAR(r1)
4146 std r15,_DSISR(r1)
4147 addi r3,r1,STACK_FRAME_OVERHEAD
4148 + bl .save_nvgprs
4149 mr r4,r14
4150 mr r5,r15
4151 ld r14,PACA_EXGEN+EX_R14(r13)
4152 @@ -669,8 +670,7 @@ storage_fault_common:
4153 cmpdi r3,0
4154 bne- 1f
4155 b .ret_from_except_lite
4156 -1: bl .save_nvgprs
4157 - mr r5,r3
4158 +1: mr r5,r3
4159 addi r3,r1,STACK_FRAME_OVERHEAD
4160 ld r4,_DAR(r1)
4161 bl .bad_page_fault
4162 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4163 index 39aa97d..dc916ee 100644
4164 --- a/arch/powerpc/kernel/exceptions-64s.S
4165 +++ b/arch/powerpc/kernel/exceptions-64s.S
4166 @@ -890,10 +890,10 @@ handle_page_fault:
4167 11: ld r4,_DAR(r1)
4168 ld r5,_DSISR(r1)
4169 addi r3,r1,STACK_FRAME_OVERHEAD
4170 + bl .save_nvgprs
4171 bl .do_page_fault
4172 cmpdi r3,0
4173 beq+ 12f
4174 - bl .save_nvgprs
4175 mr r5,r3
4176 addi r3,r1,STACK_FRAME_OVERHEAD
4177 lwz r4,_DAR(r1)
4178 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4179 index 2e3200c..72095ce 100644
4180 --- a/arch/powerpc/kernel/module_32.c
4181 +++ b/arch/powerpc/kernel/module_32.c
4182 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4183 me->arch.core_plt_section = i;
4184 }
4185 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4186 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4187 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4188 return -ENOEXEC;
4189 }
4190
4191 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4192
4193 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4194 /* Init, or core PLT? */
4195 - if (location >= mod->module_core
4196 - && location < mod->module_core + mod->core_size)
4197 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4198 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4199 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4200 - else
4201 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4202 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4203 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4204 + else {
4205 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4206 + return ~0UL;
4207 + }
4208
4209 /* Find this entry, or if that fails, the next avail. entry */
4210 while (entry->jump[0]) {
4211 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4212 index 1a1f2dd..f4d1bb4 100644
4213 --- a/arch/powerpc/kernel/process.c
4214 +++ b/arch/powerpc/kernel/process.c
4215 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4216 * Lookup NIP late so we have the best change of getting the
4217 * above info out without failing
4218 */
4219 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4220 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4221 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4222 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4223 #endif
4224 show_stack(current, (unsigned long *) regs->gpr[1]);
4225 if (!user_mode(regs))
4226 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4227 newsp = stack[0];
4228 ip = stack[STACK_FRAME_LR_SAVE];
4229 if (!firstframe || ip != lr) {
4230 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4231 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4232 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4233 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4234 - printk(" (%pS)",
4235 + printk(" (%pA)",
4236 (void *)current->ret_stack[curr_frame].ret);
4237 curr_frame--;
4238 }
4239 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4240 struct pt_regs *regs = (struct pt_regs *)
4241 (sp + STACK_FRAME_OVERHEAD);
4242 lr = regs->link;
4243 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4244 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4245 regs->trap, (void *)regs->nip, (void *)lr);
4246 firstframe = 1;
4247 }
4248 @@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4249 mtspr(SPRN_CTRLT, ctrl);
4250 }
4251 #endif /* CONFIG_PPC64 */
4252 -
4253 -unsigned long arch_align_stack(unsigned long sp)
4254 -{
4255 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4256 - sp -= get_random_int() & ~PAGE_MASK;
4257 - return sp & ~0xf;
4258 -}
4259 -
4260 -static inline unsigned long brk_rnd(void)
4261 -{
4262 - unsigned long rnd = 0;
4263 -
4264 - /* 8MB for 32bit, 1GB for 64bit */
4265 - if (is_32bit_task())
4266 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4267 - else
4268 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4269 -
4270 - return rnd << PAGE_SHIFT;
4271 -}
4272 -
4273 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4274 -{
4275 - unsigned long base = mm->brk;
4276 - unsigned long ret;
4277 -
4278 -#ifdef CONFIG_PPC_STD_MMU_64
4279 - /*
4280 - * If we are using 1TB segments and we are allowed to randomise
4281 - * the heap, we can put it above 1TB so it is backed by a 1TB
4282 - * segment. Otherwise the heap will be in the bottom 1TB
4283 - * which always uses 256MB segments and this may result in a
4284 - * performance penalty.
4285 - */
4286 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4287 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4288 -#endif
4289 -
4290 - ret = PAGE_ALIGN(base + brk_rnd());
4291 -
4292 - if (ret < mm->brk)
4293 - return mm->brk;
4294 -
4295 - return ret;
4296 -}
4297 -
4298 -unsigned long randomize_et_dyn(unsigned long base)
4299 -{
4300 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4301 -
4302 - if (ret < base)
4303 - return base;
4304 -
4305 - return ret;
4306 -}
4307 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4308 index c10fc28..c4ef063 100644
4309 --- a/arch/powerpc/kernel/ptrace.c
4310 +++ b/arch/powerpc/kernel/ptrace.c
4311 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4312 return ret;
4313 }
4314
4315 +#ifdef CONFIG_GRKERNSEC_SETXID
4316 +extern void gr_delayed_cred_worker(void);
4317 +#endif
4318 +
4319 /*
4320 * We must return the syscall number to actually look up in the table.
4321 * This can be -1L to skip running any syscall at all.
4322 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4323
4324 secure_computing_strict(regs->gpr[0]);
4325
4326 +#ifdef CONFIG_GRKERNSEC_SETXID
4327 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4328 + gr_delayed_cred_worker();
4329 +#endif
4330 +
4331 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4332 tracehook_report_syscall_entry(regs))
4333 /*
4334 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4335 {
4336 int step;
4337
4338 +#ifdef CONFIG_GRKERNSEC_SETXID
4339 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4340 + gr_delayed_cred_worker();
4341 +#endif
4342 +
4343 audit_syscall_exit(regs);
4344
4345 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4346 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4347 index 8b4c049..dcd6ef3 100644
4348 --- a/arch/powerpc/kernel/signal_32.c
4349 +++ b/arch/powerpc/kernel/signal_32.c
4350 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4351 /* Save user registers on the stack */
4352 frame = &rt_sf->uc.uc_mcontext;
4353 addr = frame;
4354 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4355 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4356 if (save_user_regs(regs, frame, 0, 1))
4357 goto badframe;
4358 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4359 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4360 index d183f87..1867f1a 100644
4361 --- a/arch/powerpc/kernel/signal_64.c
4362 +++ b/arch/powerpc/kernel/signal_64.c
4363 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4364 current->thread.fpscr.val = 0;
4365
4366 /* Set up to return from userspace. */
4367 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4368 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4369 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4370 } else {
4371 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4372 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4373 index ae0843f..f16372c 100644
4374 --- a/arch/powerpc/kernel/traps.c
4375 +++ b/arch/powerpc/kernel/traps.c
4376 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4377 return flags;
4378 }
4379
4380 +extern void gr_handle_kernel_exploit(void);
4381 +
4382 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4383 int signr)
4384 {
4385 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4386 panic("Fatal exception in interrupt");
4387 if (panic_on_oops)
4388 panic("Fatal exception");
4389 +
4390 + gr_handle_kernel_exploit();
4391 +
4392 do_exit(signr);
4393 }
4394
4395 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4396 index b67db22..38825d2 100644
4397 --- a/arch/powerpc/kernel/vdso.c
4398 +++ b/arch/powerpc/kernel/vdso.c
4399 @@ -34,6 +34,7 @@
4400 #include <asm/firmware.h>
4401 #include <asm/vdso.h>
4402 #include <asm/vdso_datapage.h>
4403 +#include <asm/mman.h>
4404
4405 #include "setup.h"
4406
4407 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4408 vdso_base = VDSO32_MBASE;
4409 #endif
4410
4411 - current->mm->context.vdso_base = 0;
4412 + current->mm->context.vdso_base = ~0UL;
4413
4414 /* vDSO has a problem and was disabled, just don't "enable" it for the
4415 * process
4416 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4417 vdso_base = get_unmapped_area(NULL, vdso_base,
4418 (vdso_pages << PAGE_SHIFT) +
4419 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4420 - 0, 0);
4421 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4422 if (IS_ERR_VALUE(vdso_base)) {
4423 rc = vdso_base;
4424 goto fail_mmapsem;
4425 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4426 index 5eea6f3..5d10396 100644
4427 --- a/arch/powerpc/lib/usercopy_64.c
4428 +++ b/arch/powerpc/lib/usercopy_64.c
4429 @@ -9,22 +9,6 @@
4430 #include <linux/module.h>
4431 #include <asm/uaccess.h>
4432
4433 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4434 -{
4435 - if (likely(access_ok(VERIFY_READ, from, n)))
4436 - n = __copy_from_user(to, from, n);
4437 - else
4438 - memset(to, 0, n);
4439 - return n;
4440 -}
4441 -
4442 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4443 -{
4444 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4445 - n = __copy_to_user(to, from, n);
4446 - return n;
4447 -}
4448 -
4449 unsigned long copy_in_user(void __user *to, const void __user *from,
4450 unsigned long n)
4451 {
4452 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4453 return n;
4454 }
4455
4456 -EXPORT_SYMBOL(copy_from_user);
4457 -EXPORT_SYMBOL(copy_to_user);
4458 EXPORT_SYMBOL(copy_in_user);
4459
4460 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4461 index 08ffcf5..a0ab912 100644
4462 --- a/arch/powerpc/mm/fault.c
4463 +++ b/arch/powerpc/mm/fault.c
4464 @@ -32,6 +32,10 @@
4465 #include <linux/perf_event.h>
4466 #include <linux/magic.h>
4467 #include <linux/ratelimit.h>
4468 +#include <linux/slab.h>
4469 +#include <linux/pagemap.h>
4470 +#include <linux/compiler.h>
4471 +#include <linux/unistd.h>
4472
4473 #include <asm/firmware.h>
4474 #include <asm/page.h>
4475 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4476 }
4477 #endif
4478
4479 +#ifdef CONFIG_PAX_PAGEEXEC
4480 +/*
4481 + * PaX: decide what to do with offenders (regs->nip = fault address)
4482 + *
4483 + * returns 1 when task should be killed
4484 + */
4485 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4486 +{
4487 + return 1;
4488 +}
4489 +
4490 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4491 +{
4492 + unsigned long i;
4493 +
4494 + printk(KERN_ERR "PAX: bytes at PC: ");
4495 + for (i = 0; i < 5; i++) {
4496 + unsigned int c;
4497 + if (get_user(c, (unsigned int __user *)pc+i))
4498 + printk(KERN_CONT "???????? ");
4499 + else
4500 + printk(KERN_CONT "%08x ", c);
4501 + }
4502 + printk("\n");
4503 +}
4504 +#endif
4505 +
4506 /*
4507 * Check whether the instruction at regs->nip is a store using
4508 * an update addressing form which will update r1.
4509 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4510 * indicate errors in DSISR but can validly be set in SRR1.
4511 */
4512 if (trap == 0x400)
4513 - error_code &= 0x48200000;
4514 + error_code &= 0x58200000;
4515 else
4516 is_write = error_code & DSISR_ISSTORE;
4517 #else
4518 @@ -366,7 +397,7 @@ good_area:
4519 * "undefined". Of those that can be set, this is the only
4520 * one which seems bad.
4521 */
4522 - if (error_code & 0x10000000)
4523 + if (error_code & DSISR_GUARDED)
4524 /* Guarded storage error. */
4525 goto bad_area;
4526 #endif /* CONFIG_8xx */
4527 @@ -381,7 +412,7 @@ good_area:
4528 * processors use the same I/D cache coherency mechanism
4529 * as embedded.
4530 */
4531 - if (error_code & DSISR_PROTFAULT)
4532 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4533 goto bad_area;
4534 #endif /* CONFIG_PPC_STD_MMU */
4535
4536 @@ -463,6 +494,23 @@ bad_area:
4537 bad_area_nosemaphore:
4538 /* User mode accesses cause a SIGSEGV */
4539 if (user_mode(regs)) {
4540 +
4541 +#ifdef CONFIG_PAX_PAGEEXEC
4542 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4543 +#ifdef CONFIG_PPC_STD_MMU
4544 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4545 +#else
4546 + if (is_exec && regs->nip == address) {
4547 +#endif
4548 + switch (pax_handle_fetch_fault(regs)) {
4549 + }
4550 +
4551 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4552 + do_group_exit(SIGKILL);
4553 + }
4554 + }
4555 +#endif
4556 +
4557 _exception(SIGSEGV, regs, code, address);
4558 return 0;
4559 }
4560 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4561 index 67a42ed..1c7210c 100644
4562 --- a/arch/powerpc/mm/mmap_64.c
4563 +++ b/arch/powerpc/mm/mmap_64.c
4564 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4565 */
4566 if (mmap_is_legacy()) {
4567 mm->mmap_base = TASK_UNMAPPED_BASE;
4568 +
4569 +#ifdef CONFIG_PAX_RANDMMAP
4570 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4571 + mm->mmap_base += mm->delta_mmap;
4572 +#endif
4573 +
4574 mm->get_unmapped_area = arch_get_unmapped_area;
4575 mm->unmap_area = arch_unmap_area;
4576 } else {
4577 mm->mmap_base = mmap_base();
4578 +
4579 +#ifdef CONFIG_PAX_RANDMMAP
4580 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4581 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4582 +#endif
4583 +
4584 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4585 mm->unmap_area = arch_unmap_area_topdown;
4586 }
4587 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4588 index 73709f7..6b90313 100644
4589 --- a/arch/powerpc/mm/slice.c
4590 +++ b/arch/powerpc/mm/slice.c
4591 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4592 if ((mm->task_size - len) < addr)
4593 return 0;
4594 vma = find_vma(mm, addr);
4595 - return (!vma || (addr + len) <= vma->vm_start);
4596 + return check_heap_stack_gap(vma, addr, len);
4597 }
4598
4599 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4600 @@ -256,7 +256,7 @@ full_search:
4601 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4602 continue;
4603 }
4604 - if (!vma || addr + len <= vma->vm_start) {
4605 + if (check_heap_stack_gap(vma, addr, len)) {
4606 /*
4607 * Remember the place where we stopped the search:
4608 */
4609 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4610 }
4611 }
4612
4613 - addr = mm->mmap_base;
4614 - while (addr > len) {
4615 + if (mm->mmap_base < len)
4616 + addr = -ENOMEM;
4617 + else
4618 + addr = mm->mmap_base - len;
4619 +
4620 + while (!IS_ERR_VALUE(addr)) {
4621 /* Go down by chunk size */
4622 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4623 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4624
4625 /* Check for hit with different page size */
4626 mask = slice_range_to_mask(addr, len);
4627 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4628 * return with success:
4629 */
4630 vma = find_vma(mm, addr);
4631 - if (!vma || (addr + len) <= vma->vm_start) {
4632 + if (check_heap_stack_gap(vma, addr, len)) {
4633 /* remember the address as a hint for next time */
4634 if (use_cache)
4635 mm->free_area_cache = addr;
4636 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4637 mm->cached_hole_size = vma->vm_start - addr;
4638
4639 /* try just below the current vma->vm_start */
4640 - addr = vma->vm_start;
4641 + addr = skip_heap_stack_gap(vma, len);
4642 }
4643
4644 /*
4645 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4646 if (fixed && addr > (mm->task_size - len))
4647 return -EINVAL;
4648
4649 +#ifdef CONFIG_PAX_RANDMMAP
4650 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4651 + addr = 0;
4652 +#endif
4653 +
4654 /* If hint, make sure it matches our alignment restrictions */
4655 if (!fixed && addr) {
4656 addr = _ALIGN_UP(addr, 1ul << pshift);
4657 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4658 index c797832..ce575c8 100644
4659 --- a/arch/s390/include/asm/atomic.h
4660 +++ b/arch/s390/include/asm/atomic.h
4661 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4662 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4663 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4664
4665 +#define atomic64_read_unchecked(v) atomic64_read(v)
4666 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4667 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4668 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4669 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4670 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4671 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4672 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4673 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4674 +
4675 #define smp_mb__before_atomic_dec() smp_mb()
4676 #define smp_mb__after_atomic_dec() smp_mb()
4677 #define smp_mb__before_atomic_inc() smp_mb()
4678 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4679 index 4d7ccac..d03d0ad 100644
4680 --- a/arch/s390/include/asm/cache.h
4681 +++ b/arch/s390/include/asm/cache.h
4682 @@ -9,8 +9,10 @@
4683 #ifndef __ARCH_S390_CACHE_H
4684 #define __ARCH_S390_CACHE_H
4685
4686 -#define L1_CACHE_BYTES 256
4687 +#include <linux/const.h>
4688 +
4689 #define L1_CACHE_SHIFT 8
4690 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4691 #define NET_SKB_PAD 32
4692
4693 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4694 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4695 index 9b94a16..63d4034 100644
4696 --- a/arch/s390/include/asm/elf.h
4697 +++ b/arch/s390/include/asm/elf.h
4698 @@ -159,8 +159,14 @@ extern unsigned int vdso_enabled;
4699 the loader. We need to make sure that it is out of the way of the program
4700 that it will "exec", and that there is sufficient room for the brk. */
4701
4702 -extern unsigned long randomize_et_dyn(unsigned long base);
4703 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4704 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4705 +
4706 +#ifdef CONFIG_PAX_ASLR
4707 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4708 +
4709 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4710 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4711 +#endif
4712
4713 /* This yields a mask that user programs can use to figure out what
4714 instruction set this CPU supports. */
4715 @@ -209,7 +215,4 @@ struct linux_binprm;
4716 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4717 int arch_setup_additional_pages(struct linux_binprm *, int);
4718
4719 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4720 -#define arch_randomize_brk arch_randomize_brk
4721 -
4722 #endif
4723 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4724 index c4a93d6..4d2a9b4 100644
4725 --- a/arch/s390/include/asm/exec.h
4726 +++ b/arch/s390/include/asm/exec.h
4727 @@ -7,6 +7,6 @@
4728 #ifndef __ASM_EXEC_H
4729 #define __ASM_EXEC_H
4730
4731 -extern unsigned long arch_align_stack(unsigned long sp);
4732 +#define arch_align_stack(x) ((x) & ~0xfUL)
4733
4734 #endif /* __ASM_EXEC_H */
4735 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4736 index a8ab18b..75ddbf0 100644
4737 --- a/arch/s390/include/asm/uaccess.h
4738 +++ b/arch/s390/include/asm/uaccess.h
4739 @@ -239,6 +239,10 @@ static inline unsigned long __must_check
4740 copy_to_user(void __user *to, const void *from, unsigned long n)
4741 {
4742 might_fault();
4743 +
4744 + if ((long)n < 0)
4745 + return n;
4746 +
4747 if (access_ok(VERIFY_WRITE, to, n))
4748 n = __copy_to_user(to, from, n);
4749 return n;
4750 @@ -264,6 +268,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4751 static inline unsigned long __must_check
4752 __copy_from_user(void *to, const void __user *from, unsigned long n)
4753 {
4754 + if ((long)n < 0)
4755 + return n;
4756 +
4757 if (__builtin_constant_p(n) && (n <= 256))
4758 return uaccess.copy_from_user_small(n, from, to);
4759 else
4760 @@ -295,10 +302,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4761 static inline unsigned long __must_check
4762 copy_from_user(void *to, const void __user *from, unsigned long n)
4763 {
4764 - unsigned int sz = __compiletime_object_size(to);
4765 + size_t sz = __compiletime_object_size(to);
4766
4767 might_fault();
4768 - if (unlikely(sz != -1 && sz < n)) {
4769 +
4770 + if ((long)n < 0)
4771 + return n;
4772 +
4773 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4774 copy_from_user_overflow();
4775 return n;
4776 }
4777 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4778 index 46412b1..e32874f 100644
4779 --- a/arch/s390/kernel/module.c
4780 +++ b/arch/s390/kernel/module.c
4781 @@ -160,11 +160,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4782
4783 /* Increase core size by size of got & plt and set start
4784 offsets for got and plt. */
4785 - me->core_size = ALIGN(me->core_size, 4);
4786 - me->arch.got_offset = me->core_size;
4787 - me->core_size += me->arch.got_size;
4788 - me->arch.plt_offset = me->core_size;
4789 - me->core_size += me->arch.plt_size;
4790 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4791 + me->arch.got_offset = me->core_size_rw;
4792 + me->core_size_rw += me->arch.got_size;
4793 + me->arch.plt_offset = me->core_size_rx;
4794 + me->core_size_rx += me->arch.plt_size;
4795 return 0;
4796 }
4797
4798 @@ -241,7 +241,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4799 if (info->got_initialized == 0) {
4800 Elf_Addr *gotent;
4801
4802 - gotent = me->module_core + me->arch.got_offset +
4803 + gotent = me->module_core_rw + me->arch.got_offset +
4804 info->got_offset;
4805 *gotent = val;
4806 info->got_initialized = 1;
4807 @@ -265,7 +265,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4808 else if (r_type == R_390_GOTENT ||
4809 r_type == R_390_GOTPLTENT)
4810 *(unsigned int *) loc =
4811 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4812 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4813 else if (r_type == R_390_GOT64 ||
4814 r_type == R_390_GOTPLT64)
4815 *(unsigned long *) loc = val;
4816 @@ -279,7 +279,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4817 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4818 if (info->plt_initialized == 0) {
4819 unsigned int *ip;
4820 - ip = me->module_core + me->arch.plt_offset +
4821 + ip = me->module_core_rx + me->arch.plt_offset +
4822 info->plt_offset;
4823 #ifndef CONFIG_64BIT
4824 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4825 @@ -304,7 +304,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4826 val - loc + 0xffffUL < 0x1ffffeUL) ||
4827 (r_type == R_390_PLT32DBL &&
4828 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4829 - val = (Elf_Addr) me->module_core +
4830 + val = (Elf_Addr) me->module_core_rx +
4831 me->arch.plt_offset +
4832 info->plt_offset;
4833 val += rela->r_addend - loc;
4834 @@ -326,7 +326,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4835 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4836 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4837 val = val + rela->r_addend -
4838 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4839 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4840 if (r_type == R_390_GOTOFF16)
4841 *(unsigned short *) loc = val;
4842 else if (r_type == R_390_GOTOFF32)
4843 @@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4844 break;
4845 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4846 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4847 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4848 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4849 rela->r_addend - loc;
4850 if (r_type == R_390_GOTPC)
4851 *(unsigned int *) loc = val;
4852 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4853 index 7331753..dd71de4 100644
4854 --- a/arch/s390/kernel/process.c
4855 +++ b/arch/s390/kernel/process.c
4856 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4857 }
4858 return 0;
4859 }
4860 -
4861 -unsigned long arch_align_stack(unsigned long sp)
4862 -{
4863 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4864 - sp -= get_random_int() & ~PAGE_MASK;
4865 - return sp & ~0xf;
4866 -}
4867 -
4868 -static inline unsigned long brk_rnd(void)
4869 -{
4870 - /* 8MB for 32bit, 1GB for 64bit */
4871 - if (is_32bit_task())
4872 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4873 - else
4874 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4875 -}
4876 -
4877 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4878 -{
4879 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4880 -
4881 - if (ret < mm->brk)
4882 - return mm->brk;
4883 - return ret;
4884 -}
4885 -
4886 -unsigned long randomize_et_dyn(unsigned long base)
4887 -{
4888 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4889 -
4890 - if (!(current->flags & PF_RANDOMIZE))
4891 - return base;
4892 - if (ret < base)
4893 - return base;
4894 - return ret;
4895 -}
4896 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4897 index c59a5ef..3fae59c 100644
4898 --- a/arch/s390/mm/mmap.c
4899 +++ b/arch/s390/mm/mmap.c
4900 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4901 */
4902 if (mmap_is_legacy()) {
4903 mm->mmap_base = TASK_UNMAPPED_BASE;
4904 +
4905 +#ifdef CONFIG_PAX_RANDMMAP
4906 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4907 + mm->mmap_base += mm->delta_mmap;
4908 +#endif
4909 +
4910 mm->get_unmapped_area = arch_get_unmapped_area;
4911 mm->unmap_area = arch_unmap_area;
4912 } else {
4913 mm->mmap_base = mmap_base();
4914 +
4915 +#ifdef CONFIG_PAX_RANDMMAP
4916 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4917 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4918 +#endif
4919 +
4920 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4921 mm->unmap_area = arch_unmap_area_topdown;
4922 }
4923 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4924 */
4925 if (mmap_is_legacy()) {
4926 mm->mmap_base = TASK_UNMAPPED_BASE;
4927 +
4928 +#ifdef CONFIG_PAX_RANDMMAP
4929 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4930 + mm->mmap_base += mm->delta_mmap;
4931 +#endif
4932 +
4933 mm->get_unmapped_area = s390_get_unmapped_area;
4934 mm->unmap_area = arch_unmap_area;
4935 } else {
4936 mm->mmap_base = mmap_base();
4937 +
4938 +#ifdef CONFIG_PAX_RANDMMAP
4939 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4940 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4941 +#endif
4942 +
4943 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4944 mm->unmap_area = arch_unmap_area_topdown;
4945 }
4946 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4947 index ae3d59f..f65f075 100644
4948 --- a/arch/score/include/asm/cache.h
4949 +++ b/arch/score/include/asm/cache.h
4950 @@ -1,7 +1,9 @@
4951 #ifndef _ASM_SCORE_CACHE_H
4952 #define _ASM_SCORE_CACHE_H
4953
4954 +#include <linux/const.h>
4955 +
4956 #define L1_CACHE_SHIFT 4
4957 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4958 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4959
4960 #endif /* _ASM_SCORE_CACHE_H */
4961 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4962 index f9f3cd5..58ff438 100644
4963 --- a/arch/score/include/asm/exec.h
4964 +++ b/arch/score/include/asm/exec.h
4965 @@ -1,6 +1,6 @@
4966 #ifndef _ASM_SCORE_EXEC_H
4967 #define _ASM_SCORE_EXEC_H
4968
4969 -extern unsigned long arch_align_stack(unsigned long sp);
4970 +#define arch_align_stack(x) (x)
4971
4972 #endif /* _ASM_SCORE_EXEC_H */
4973 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4974 index 637970c..0b6556b 100644
4975 --- a/arch/score/kernel/process.c
4976 +++ b/arch/score/kernel/process.c
4977 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4978
4979 return task_pt_regs(task)->cp0_epc;
4980 }
4981 -
4982 -unsigned long arch_align_stack(unsigned long sp)
4983 -{
4984 - return sp;
4985 -}
4986 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4987 index ef9e555..331bd29 100644
4988 --- a/arch/sh/include/asm/cache.h
4989 +++ b/arch/sh/include/asm/cache.h
4990 @@ -9,10 +9,11 @@
4991 #define __ASM_SH_CACHE_H
4992 #ifdef __KERNEL__
4993
4994 +#include <linux/const.h>
4995 #include <linux/init.h>
4996 #include <cpu/cache.h>
4997
4998 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4999 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5000
5001 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5002
5003 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5004 index afeb710..d1d1289 100644
5005 --- a/arch/sh/mm/mmap.c
5006 +++ b/arch/sh/mm/mmap.c
5007 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5008 addr = PAGE_ALIGN(addr);
5009
5010 vma = find_vma(mm, addr);
5011 - if (TASK_SIZE - len >= addr &&
5012 - (!vma || addr + len <= vma->vm_start))
5013 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5014 return addr;
5015 }
5016
5017 @@ -106,7 +105,7 @@ full_search:
5018 }
5019 return -ENOMEM;
5020 }
5021 - if (likely(!vma || addr + len <= vma->vm_start)) {
5022 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5023 /*
5024 * Remember the place where we stopped the search:
5025 */
5026 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5027 addr = PAGE_ALIGN(addr);
5028
5029 vma = find_vma(mm, addr);
5030 - if (TASK_SIZE - len >= addr &&
5031 - (!vma || addr + len <= vma->vm_start))
5032 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5033 return addr;
5034 }
5035
5036 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5037 /* make sure it can fit in the remaining address space */
5038 if (likely(addr > len)) {
5039 vma = find_vma(mm, addr-len);
5040 - if (!vma || addr <= vma->vm_start) {
5041 + if (check_heap_stack_gap(vma, addr - len, len)) {
5042 /* remember the address as a hint for next time */
5043 return (mm->free_area_cache = addr-len);
5044 }
5045 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5046 if (unlikely(mm->mmap_base < len))
5047 goto bottomup;
5048
5049 - addr = mm->mmap_base-len;
5050 - if (do_colour_align)
5051 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5052 + addr = mm->mmap_base - len;
5053
5054 do {
5055 + if (do_colour_align)
5056 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5057 /*
5058 * Lookup failure means no vma is above this address,
5059 * else if new region fits below vma->vm_start,
5060 * return with success:
5061 */
5062 vma = find_vma(mm, addr);
5063 - if (likely(!vma || addr+len <= vma->vm_start)) {
5064 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5065 /* remember the address as a hint for next time */
5066 return (mm->free_area_cache = addr);
5067 }
5068 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5069 mm->cached_hole_size = vma->vm_start - addr;
5070
5071 /* try just below the current vma->vm_start */
5072 - addr = vma->vm_start-len;
5073 - if (do_colour_align)
5074 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5075 - } while (likely(len < vma->vm_start));
5076 + addr = skip_heap_stack_gap(vma, len);
5077 + } while (!IS_ERR_VALUE(addr));
5078
5079 bottomup:
5080 /*
5081 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5082 index ce35a1c..2e7b8f9 100644
5083 --- a/arch/sparc/include/asm/atomic_64.h
5084 +++ b/arch/sparc/include/asm/atomic_64.h
5085 @@ -14,18 +14,40 @@
5086 #define ATOMIC64_INIT(i) { (i) }
5087
5088 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5089 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5090 +{
5091 + return v->counter;
5092 +}
5093 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5094 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5095 +{
5096 + return v->counter;
5097 +}
5098
5099 #define atomic_set(v, i) (((v)->counter) = i)
5100 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5101 +{
5102 + v->counter = i;
5103 +}
5104 #define atomic64_set(v, i) (((v)->counter) = i)
5105 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5106 +{
5107 + v->counter = i;
5108 +}
5109
5110 extern void atomic_add(int, atomic_t *);
5111 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5112 extern void atomic64_add(long, atomic64_t *);
5113 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5114 extern void atomic_sub(int, atomic_t *);
5115 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5116 extern void atomic64_sub(long, atomic64_t *);
5117 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5118
5119 extern int atomic_add_ret(int, atomic_t *);
5120 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5121 extern long atomic64_add_ret(long, atomic64_t *);
5122 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5123 extern int atomic_sub_ret(int, atomic_t *);
5124 extern long atomic64_sub_ret(long, atomic64_t *);
5125
5126 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5127 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5128
5129 #define atomic_inc_return(v) atomic_add_ret(1, v)
5130 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5131 +{
5132 + return atomic_add_ret_unchecked(1, v);
5133 +}
5134 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5135 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5136 +{
5137 + return atomic64_add_ret_unchecked(1, v);
5138 +}
5139
5140 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5141 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5142
5143 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5144 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5145 +{
5146 + return atomic_add_ret_unchecked(i, v);
5147 +}
5148 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5149 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5150 +{
5151 + return atomic64_add_ret_unchecked(i, v);
5152 +}
5153
5154 /*
5155 * atomic_inc_and_test - increment and test
5156 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5157 * other cases.
5158 */
5159 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5160 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5161 +{
5162 + return atomic_inc_return_unchecked(v) == 0;
5163 +}
5164 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5165
5166 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5167 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5168 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5169
5170 #define atomic_inc(v) atomic_add(1, v)
5171 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5172 +{
5173 + atomic_add_unchecked(1, v);
5174 +}
5175 #define atomic64_inc(v) atomic64_add(1, v)
5176 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5177 +{
5178 + atomic64_add_unchecked(1, v);
5179 +}
5180
5181 #define atomic_dec(v) atomic_sub(1, v)
5182 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5183 +{
5184 + atomic_sub_unchecked(1, v);
5185 +}
5186 #define atomic64_dec(v) atomic64_sub(1, v)
5187 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5188 +{
5189 + atomic64_sub_unchecked(1, v);
5190 +}
5191
5192 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5193 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5194
5195 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5196 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5197 +{
5198 + return cmpxchg(&v->counter, old, new);
5199 +}
5200 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5201 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5202 +{
5203 + return xchg(&v->counter, new);
5204 +}
5205
5206 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5207 {
5208 - int c, old;
5209 + int c, old, new;
5210 c = atomic_read(v);
5211 for (;;) {
5212 - if (unlikely(c == (u)))
5213 + if (unlikely(c == u))
5214 break;
5215 - old = atomic_cmpxchg((v), c, c + (a));
5216 +
5217 + asm volatile("addcc %2, %0, %0\n"
5218 +
5219 +#ifdef CONFIG_PAX_REFCOUNT
5220 + "tvs %%icc, 6\n"
5221 +#endif
5222 +
5223 + : "=r" (new)
5224 + : "0" (c), "ir" (a)
5225 + : "cc");
5226 +
5227 + old = atomic_cmpxchg(v, c, new);
5228 if (likely(old == c))
5229 break;
5230 c = old;
5231 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5232 #define atomic64_cmpxchg(v, o, n) \
5233 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5234 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5235 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5236 +{
5237 + return xchg(&v->counter, new);
5238 +}
5239
5240 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5241 {
5242 - long c, old;
5243 + long c, old, new;
5244 c = atomic64_read(v);
5245 for (;;) {
5246 - if (unlikely(c == (u)))
5247 + if (unlikely(c == u))
5248 break;
5249 - old = atomic64_cmpxchg((v), c, c + (a));
5250 +
5251 + asm volatile("addcc %2, %0, %0\n"
5252 +
5253 +#ifdef CONFIG_PAX_REFCOUNT
5254 + "tvs %%xcc, 6\n"
5255 +#endif
5256 +
5257 + : "=r" (new)
5258 + : "0" (c), "ir" (a)
5259 + : "cc");
5260 +
5261 + old = atomic64_cmpxchg(v, c, new);
5262 if (likely(old == c))
5263 break;
5264 c = old;
5265 }
5266 - return c != (u);
5267 + return c != u;
5268 }
5269
5270 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5271 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5272 index 5bb6991..5c2132e 100644
5273 --- a/arch/sparc/include/asm/cache.h
5274 +++ b/arch/sparc/include/asm/cache.h
5275 @@ -7,10 +7,12 @@
5276 #ifndef _SPARC_CACHE_H
5277 #define _SPARC_CACHE_H
5278
5279 +#include <linux/const.h>
5280 +
5281 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5282
5283 #define L1_CACHE_SHIFT 5
5284 -#define L1_CACHE_BYTES 32
5285 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5286
5287 #ifdef CONFIG_SPARC32
5288 #define SMP_CACHE_BYTES_SHIFT 5
5289 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5290 index 2d4d755..81b6662 100644
5291 --- a/arch/sparc/include/asm/elf_32.h
5292 +++ b/arch/sparc/include/asm/elf_32.h
5293 @@ -114,6 +114,13 @@ typedef struct {
5294
5295 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5296
5297 +#ifdef CONFIG_PAX_ASLR
5298 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5299 +
5300 +#define PAX_DELTA_MMAP_LEN 16
5301 +#define PAX_DELTA_STACK_LEN 16
5302 +#endif
5303 +
5304 /* This yields a mask that user programs can use to figure out what
5305 instruction set this cpu supports. This can NOT be done in userspace
5306 on Sparc. */
5307 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5308 index 7df8b7f..4946269 100644
5309 --- a/arch/sparc/include/asm/elf_64.h
5310 +++ b/arch/sparc/include/asm/elf_64.h
5311 @@ -180,6 +180,13 @@ typedef struct {
5312 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5313 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5314
5315 +#ifdef CONFIG_PAX_ASLR
5316 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5317 +
5318 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5319 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5320 +#endif
5321 +
5322 extern unsigned long sparc64_elf_hwcap;
5323 #define ELF_HWCAP sparc64_elf_hwcap
5324
5325 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5326 index 9b1c36d..209298b 100644
5327 --- a/arch/sparc/include/asm/pgalloc_32.h
5328 +++ b/arch/sparc/include/asm/pgalloc_32.h
5329 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5330 }
5331
5332 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5333 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5334
5335 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5336 unsigned long address)
5337 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5338 index 40b2d7a..22a665b 100644
5339 --- a/arch/sparc/include/asm/pgalloc_64.h
5340 +++ b/arch/sparc/include/asm/pgalloc_64.h
5341 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5342 }
5343
5344 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5345 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5346
5347 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5348 {
5349 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5350 index 6fc1348..390c50a 100644
5351 --- a/arch/sparc/include/asm/pgtable_32.h
5352 +++ b/arch/sparc/include/asm/pgtable_32.h
5353 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5354 #define PAGE_SHARED SRMMU_PAGE_SHARED
5355 #define PAGE_COPY SRMMU_PAGE_COPY
5356 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5357 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5358 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5359 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5360 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5361
5362 /* Top-level page directory - dummy used by init-mm.
5363 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5364
5365 /* xwr */
5366 #define __P000 PAGE_NONE
5367 -#define __P001 PAGE_READONLY
5368 -#define __P010 PAGE_COPY
5369 -#define __P011 PAGE_COPY
5370 +#define __P001 PAGE_READONLY_NOEXEC
5371 +#define __P010 PAGE_COPY_NOEXEC
5372 +#define __P011 PAGE_COPY_NOEXEC
5373 #define __P100 PAGE_READONLY
5374 #define __P101 PAGE_READONLY
5375 #define __P110 PAGE_COPY
5376 #define __P111 PAGE_COPY
5377
5378 #define __S000 PAGE_NONE
5379 -#define __S001 PAGE_READONLY
5380 -#define __S010 PAGE_SHARED
5381 -#define __S011 PAGE_SHARED
5382 +#define __S001 PAGE_READONLY_NOEXEC
5383 +#define __S010 PAGE_SHARED_NOEXEC
5384 +#define __S011 PAGE_SHARED_NOEXEC
5385 #define __S100 PAGE_READONLY
5386 #define __S101 PAGE_READONLY
5387 #define __S110 PAGE_SHARED
5388 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5389 index 79da178..c2eede8 100644
5390 --- a/arch/sparc/include/asm/pgtsrmmu.h
5391 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5392 @@ -115,6 +115,11 @@
5393 SRMMU_EXEC | SRMMU_REF)
5394 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5395 SRMMU_EXEC | SRMMU_REF)
5396 +
5397 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5398 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5399 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5400 +
5401 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5402 SRMMU_DIRTY | SRMMU_REF)
5403
5404 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5405 index 9689176..63c18ea 100644
5406 --- a/arch/sparc/include/asm/spinlock_64.h
5407 +++ b/arch/sparc/include/asm/spinlock_64.h
5408 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5409
5410 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5411
5412 -static void inline arch_read_lock(arch_rwlock_t *lock)
5413 +static inline void arch_read_lock(arch_rwlock_t *lock)
5414 {
5415 unsigned long tmp1, tmp2;
5416
5417 __asm__ __volatile__ (
5418 "1: ldsw [%2], %0\n"
5419 " brlz,pn %0, 2f\n"
5420 -"4: add %0, 1, %1\n"
5421 +"4: addcc %0, 1, %1\n"
5422 +
5423 +#ifdef CONFIG_PAX_REFCOUNT
5424 +" tvs %%icc, 6\n"
5425 +#endif
5426 +
5427 " cas [%2], %0, %1\n"
5428 " cmp %0, %1\n"
5429 " bne,pn %%icc, 1b\n"
5430 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5431 " .previous"
5432 : "=&r" (tmp1), "=&r" (tmp2)
5433 : "r" (lock)
5434 - : "memory");
5435 + : "memory", "cc");
5436 }
5437
5438 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5439 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5440 {
5441 int tmp1, tmp2;
5442
5443 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5444 "1: ldsw [%2], %0\n"
5445 " brlz,a,pn %0, 2f\n"
5446 " mov 0, %0\n"
5447 -" add %0, 1, %1\n"
5448 +" addcc %0, 1, %1\n"
5449 +
5450 +#ifdef CONFIG_PAX_REFCOUNT
5451 +" tvs %%icc, 6\n"
5452 +#endif
5453 +
5454 " cas [%2], %0, %1\n"
5455 " cmp %0, %1\n"
5456 " bne,pn %%icc, 1b\n"
5457 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5458 return tmp1;
5459 }
5460
5461 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5462 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5463 {
5464 unsigned long tmp1, tmp2;
5465
5466 __asm__ __volatile__(
5467 "1: lduw [%2], %0\n"
5468 -" sub %0, 1, %1\n"
5469 +" subcc %0, 1, %1\n"
5470 +
5471 +#ifdef CONFIG_PAX_REFCOUNT
5472 +" tvs %%icc, 6\n"
5473 +#endif
5474 +
5475 " cas [%2], %0, %1\n"
5476 " cmp %0, %1\n"
5477 " bne,pn %%xcc, 1b\n"
5478 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5479 : "memory");
5480 }
5481
5482 -static void inline arch_write_lock(arch_rwlock_t *lock)
5483 +static inline void arch_write_lock(arch_rwlock_t *lock)
5484 {
5485 unsigned long mask, tmp1, tmp2;
5486
5487 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5488 : "memory");
5489 }
5490
5491 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5492 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5493 {
5494 __asm__ __volatile__(
5495 " stw %%g0, [%0]"
5496 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5497 : "memory");
5498 }
5499
5500 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5501 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5502 {
5503 unsigned long mask, tmp1, tmp2, result;
5504
5505 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5506 index e6cd224..3a71793 100644
5507 --- a/arch/sparc/include/asm/thread_info_32.h
5508 +++ b/arch/sparc/include/asm/thread_info_32.h
5509 @@ -49,6 +49,8 @@ struct thread_info {
5510 unsigned long w_saved;
5511
5512 struct restart_block restart_block;
5513 +
5514 + unsigned long lowest_stack;
5515 };
5516
5517 /*
5518 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5519 index cfa8c38..13f30d3 100644
5520 --- a/arch/sparc/include/asm/thread_info_64.h
5521 +++ b/arch/sparc/include/asm/thread_info_64.h
5522 @@ -63,6 +63,8 @@ struct thread_info {
5523 struct pt_regs *kern_una_regs;
5524 unsigned int kern_una_insn;
5525
5526 + unsigned long lowest_stack;
5527 +
5528 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5529 };
5530
5531 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5532 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5533 /* flag bit 6 is available */
5534 #define TIF_32BIT 7 /* 32-bit binary */
5535 -/* flag bit 8 is available */
5536 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5537 #define TIF_SECCOMP 9 /* secure computing */
5538 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5539 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5540 +
5541 /* NOTE: Thread flags >= 12 should be ones we have no interest
5542 * in using in assembly, else we can't use the mask as
5543 * an immediate value in instructions such as andcc.
5544 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5545 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5546 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5547 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5548 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5549
5550 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5551 _TIF_DO_NOTIFY_RESUME_MASK | \
5552 _TIF_NEED_RESCHED)
5553 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5554
5555 +#define _TIF_WORK_SYSCALL \
5556 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5557 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5558 +
5559 +
5560 /*
5561 * Thread-synchronous status.
5562 *
5563 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5564 index 0167d26..9acd8ed 100644
5565 --- a/arch/sparc/include/asm/uaccess.h
5566 +++ b/arch/sparc/include/asm/uaccess.h
5567 @@ -1,5 +1,13 @@
5568 #ifndef ___ASM_SPARC_UACCESS_H
5569 #define ___ASM_SPARC_UACCESS_H
5570 +
5571 +#ifdef __KERNEL__
5572 +#ifndef __ASSEMBLY__
5573 +#include <linux/types.h>
5574 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5575 +#endif
5576 +#endif
5577 +
5578 #if defined(__sparc__) && defined(__arch64__)
5579 #include <asm/uaccess_64.h>
5580 #else
5581 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5582 index 53a28dd..50c38c3 100644
5583 --- a/arch/sparc/include/asm/uaccess_32.h
5584 +++ b/arch/sparc/include/asm/uaccess_32.h
5585 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5586
5587 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5588 {
5589 - if (n && __access_ok((unsigned long) to, n))
5590 + if ((long)n < 0)
5591 + return n;
5592 +
5593 + if (n && __access_ok((unsigned long) to, n)) {
5594 + if (!__builtin_constant_p(n))
5595 + check_object_size(from, n, true);
5596 return __copy_user(to, (__force void __user *) from, n);
5597 - else
5598 + } else
5599 return n;
5600 }
5601
5602 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5603 {
5604 + if ((long)n < 0)
5605 + return n;
5606 +
5607 + if (!__builtin_constant_p(n))
5608 + check_object_size(from, n, true);
5609 +
5610 return __copy_user(to, (__force void __user *) from, n);
5611 }
5612
5613 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5614 {
5615 - if (n && __access_ok((unsigned long) from, n))
5616 + if ((long)n < 0)
5617 + return n;
5618 +
5619 + if (n && __access_ok((unsigned long) from, n)) {
5620 + if (!__builtin_constant_p(n))
5621 + check_object_size(to, n, false);
5622 return __copy_user((__force void __user *) to, from, n);
5623 - else
5624 + } else
5625 return n;
5626 }
5627
5628 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5629 {
5630 + if ((long)n < 0)
5631 + return n;
5632 +
5633 return __copy_user((__force void __user *) to, from, n);
5634 }
5635
5636 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5637 index 7c831d8..d440ca7 100644
5638 --- a/arch/sparc/include/asm/uaccess_64.h
5639 +++ b/arch/sparc/include/asm/uaccess_64.h
5640 @@ -10,6 +10,7 @@
5641 #include <linux/compiler.h>
5642 #include <linux/string.h>
5643 #include <linux/thread_info.h>
5644 +#include <linux/kernel.h>
5645 #include <asm/asi.h>
5646 #include <asm/spitfire.h>
5647 #include <asm-generic/uaccess-unaligned.h>
5648 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5649 static inline unsigned long __must_check
5650 copy_from_user(void *to, const void __user *from, unsigned long size)
5651 {
5652 - unsigned long ret = ___copy_from_user(to, from, size);
5653 + unsigned long ret;
5654
5655 + if ((long)size < 0 || size > INT_MAX)
5656 + return size;
5657 +
5658 + if (!__builtin_constant_p(size))
5659 + check_object_size(to, size, false);
5660 +
5661 + ret = ___copy_from_user(to, from, size);
5662 if (unlikely(ret))
5663 ret = copy_from_user_fixup(to, from, size);
5664
5665 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5666 static inline unsigned long __must_check
5667 copy_to_user(void __user *to, const void *from, unsigned long size)
5668 {
5669 - unsigned long ret = ___copy_to_user(to, from, size);
5670 + unsigned long ret;
5671
5672 + if ((long)size < 0 || size > INT_MAX)
5673 + return size;
5674 +
5675 + if (!__builtin_constant_p(size))
5676 + check_object_size(from, size, true);
5677 +
5678 + ret = ___copy_to_user(to, from, size);
5679 if (unlikely(ret))
5680 ret = copy_to_user_fixup(to, from, size);
5681 return ret;
5682 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5683 index 6cf591b..b49e65a 100644
5684 --- a/arch/sparc/kernel/Makefile
5685 +++ b/arch/sparc/kernel/Makefile
5686 @@ -3,7 +3,7 @@
5687 #
5688
5689 asflags-y := -ansi
5690 -ccflags-y := -Werror
5691 +#ccflags-y := -Werror
5692
5693 extra-y := head_$(BITS).o
5694
5695 diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
5696 index f8b6eee..87f60ee 100644
5697 --- a/arch/sparc/kernel/leon_kernel.c
5698 +++ b/arch/sparc/kernel/leon_kernel.c
5699 @@ -56,11 +56,13 @@ static inline unsigned int leon_eirq_get(int cpu)
5700 static void leon_handle_ext_irq(unsigned int irq, struct irq_desc *desc)
5701 {
5702 unsigned int eirq;
5703 + struct irq_bucket *p;
5704 int cpu = sparc_leon3_cpuid();
5705
5706 eirq = leon_eirq_get(cpu);
5707 - if ((eirq & 0x10) && irq_map[eirq]->irq) /* bit4 tells if IRQ happened */
5708 - generic_handle_irq(irq_map[eirq]->irq);
5709 + p = irq_map[eirq];
5710 + if ((eirq & 0x10) && p && p->irq) /* bit4 tells if IRQ happened */
5711 + generic_handle_irq(p->irq);
5712 }
5713
5714 /* The extended IRQ controller has been found, this function registers it */
5715 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5716 index 14006d8..8146238 100644
5717 --- a/arch/sparc/kernel/process_32.c
5718 +++ b/arch/sparc/kernel/process_32.c
5719 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5720
5721 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5722 r->psr, r->pc, r->npc, r->y, print_tainted());
5723 - printk("PC: <%pS>\n", (void *) r->pc);
5724 + printk("PC: <%pA>\n", (void *) r->pc);
5725 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5726 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5727 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5728 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5729 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5730 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5731 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5732 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5733
5734 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5735 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5736 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5737 rw = (struct reg_window32 *) fp;
5738 pc = rw->ins[7];
5739 printk("[%08lx : ", pc);
5740 - printk("%pS ] ", (void *) pc);
5741 + printk("%pA ] ", (void *) pc);
5742 fp = rw->ins[6];
5743 } while (++count < 16);
5744 printk("\n");
5745 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5746 index aff0c72..9067b39 100644
5747 --- a/arch/sparc/kernel/process_64.c
5748 +++ b/arch/sparc/kernel/process_64.c
5749 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5750 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5751 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5752 if (regs->tstate & TSTATE_PRIV)
5753 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5754 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5755 }
5756
5757 void show_regs(struct pt_regs *regs)
5758 {
5759 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5760 regs->tpc, regs->tnpc, regs->y, print_tainted());
5761 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5762 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5763 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5764 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5765 regs->u_regs[3]);
5766 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5767 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5768 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5769 regs->u_regs[15]);
5770 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5771 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5772 show_regwindow(regs);
5773 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5774 }
5775 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5776 ((tp && tp->task) ? tp->task->pid : -1));
5777
5778 if (gp->tstate & TSTATE_PRIV) {
5779 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5780 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5781 (void *) gp->tpc,
5782 (void *) gp->o7,
5783 (void *) gp->i7,
5784 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5785 index 484daba..0674139 100644
5786 --- a/arch/sparc/kernel/ptrace_64.c
5787 +++ b/arch/sparc/kernel/ptrace_64.c
5788 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5789 return ret;
5790 }
5791
5792 +#ifdef CONFIG_GRKERNSEC_SETXID
5793 +extern void gr_delayed_cred_worker(void);
5794 +#endif
5795 +
5796 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5797 {
5798 int ret = 0;
5799 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5800 /* do the secure computing check first */
5801 secure_computing_strict(regs->u_regs[UREG_G1]);
5802
5803 +#ifdef CONFIG_GRKERNSEC_SETXID
5804 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5805 + gr_delayed_cred_worker();
5806 +#endif
5807 +
5808 if (test_thread_flag(TIF_SYSCALL_TRACE))
5809 ret = tracehook_report_syscall_entry(regs);
5810
5811 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5812
5813 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5814 {
5815 +#ifdef CONFIG_GRKERNSEC_SETXID
5816 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5817 + gr_delayed_cred_worker();
5818 +#endif
5819 +
5820 audit_syscall_exit(regs);
5821
5822 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5823 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5824 index 0c9b31b..7cb7aee 100644
5825 --- a/arch/sparc/kernel/sys_sparc_32.c
5826 +++ b/arch/sparc/kernel/sys_sparc_32.c
5827 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5828 if (len > TASK_SIZE - PAGE_SIZE)
5829 return -ENOMEM;
5830 if (!addr)
5831 - addr = TASK_UNMAPPED_BASE;
5832 + addr = current->mm->mmap_base;
5833
5834 if (flags & MAP_SHARED)
5835 addr = COLOUR_ALIGN(addr);
5836 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5837 /* At this point: (!vmm || addr < vmm->vm_end). */
5838 if (TASK_SIZE - PAGE_SIZE - len < addr)
5839 return -ENOMEM;
5840 - if (!vmm || addr + len <= vmm->vm_start)
5841 + if (check_heap_stack_gap(vmm, addr, len))
5842 return addr;
5843 addr = vmm->vm_end;
5844 if (flags & MAP_SHARED)
5845 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5846 index 11c6c96..3ec33e8 100644
5847 --- a/arch/sparc/kernel/sys_sparc_64.c
5848 +++ b/arch/sparc/kernel/sys_sparc_64.c
5849 @@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5850 /* We do not accept a shared mapping if it would violate
5851 * cache aliasing constraints.
5852 */
5853 - if ((flags & MAP_SHARED) &&
5854 + if ((filp || (flags & MAP_SHARED)) &&
5855 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5856 return -EINVAL;
5857 return addr;
5858 @@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5859 if (filp || (flags & MAP_SHARED))
5860 do_color_align = 1;
5861
5862 +#ifdef CONFIG_PAX_RANDMMAP
5863 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5864 +#endif
5865 +
5866 if (addr) {
5867 if (do_color_align)
5868 addr = COLOUR_ALIGN(addr, pgoff);
5869 @@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5870 addr = PAGE_ALIGN(addr);
5871
5872 vma = find_vma(mm, addr);
5873 - if (task_size - len >= addr &&
5874 - (!vma || addr + len <= vma->vm_start))
5875 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5876 return addr;
5877 }
5878
5879 if (len > mm->cached_hole_size) {
5880 - start_addr = addr = mm->free_area_cache;
5881 + start_addr = addr = mm->free_area_cache;
5882 } else {
5883 - start_addr = addr = TASK_UNMAPPED_BASE;
5884 + start_addr = addr = mm->mmap_base;
5885 mm->cached_hole_size = 0;
5886 }
5887
5888 @@ -157,14 +160,14 @@ full_search:
5889 vma = find_vma(mm, VA_EXCLUDE_END);
5890 }
5891 if (unlikely(task_size < addr)) {
5892 - if (start_addr != TASK_UNMAPPED_BASE) {
5893 - start_addr = addr = TASK_UNMAPPED_BASE;
5894 + if (start_addr != mm->mmap_base) {
5895 + start_addr = addr = mm->mmap_base;
5896 mm->cached_hole_size = 0;
5897 goto full_search;
5898 }
5899 return -ENOMEM;
5900 }
5901 - if (likely(!vma || addr + len <= vma->vm_start)) {
5902 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5903 /*
5904 * Remember the place where we stopped the search:
5905 */
5906 @@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5907 /* We do not accept a shared mapping if it would violate
5908 * cache aliasing constraints.
5909 */
5910 - if ((flags & MAP_SHARED) &&
5911 + if ((filp || (flags & MAP_SHARED)) &&
5912 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5913 return -EINVAL;
5914 return addr;
5915 @@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5916 addr = PAGE_ALIGN(addr);
5917
5918 vma = find_vma(mm, addr);
5919 - if (task_size - len >= addr &&
5920 - (!vma || addr + len <= vma->vm_start))
5921 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5922 return addr;
5923 }
5924
5925 @@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5926 /* make sure it can fit in the remaining address space */
5927 if (likely(addr > len)) {
5928 vma = find_vma(mm, addr-len);
5929 - if (!vma || addr <= vma->vm_start) {
5930 + if (check_heap_stack_gap(vma, addr - len, len)) {
5931 /* remember the address as a hint for next time */
5932 return (mm->free_area_cache = addr-len);
5933 }
5934 @@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5935 if (unlikely(mm->mmap_base < len))
5936 goto bottomup;
5937
5938 - addr = mm->mmap_base-len;
5939 - if (do_color_align)
5940 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5941 + addr = mm->mmap_base - len;
5942
5943 do {
5944 + if (do_color_align)
5945 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5946 /*
5947 * Lookup failure means no vma is above this address,
5948 * else if new region fits below vma->vm_start,
5949 * return with success:
5950 */
5951 vma = find_vma(mm, addr);
5952 - if (likely(!vma || addr+len <= vma->vm_start)) {
5953 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5954 /* remember the address as a hint for next time */
5955 return (mm->free_area_cache = addr);
5956 }
5957 @@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5958 mm->cached_hole_size = vma->vm_start - addr;
5959
5960 /* try just below the current vma->vm_start */
5961 - addr = vma->vm_start-len;
5962 - if (do_color_align)
5963 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5964 - } while (likely(len < vma->vm_start));
5965 + addr = skip_heap_stack_gap(vma, len);
5966 + } while (!IS_ERR_VALUE(addr));
5967
5968 bottomup:
5969 /*
5970 @@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5971 gap == RLIM_INFINITY ||
5972 sysctl_legacy_va_layout) {
5973 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5974 +
5975 +#ifdef CONFIG_PAX_RANDMMAP
5976 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5977 + mm->mmap_base += mm->delta_mmap;
5978 +#endif
5979 +
5980 mm->get_unmapped_area = arch_get_unmapped_area;
5981 mm->unmap_area = arch_unmap_area;
5982 } else {
5983 @@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5984 gap = (task_size / 6 * 5);
5985
5986 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5987 +
5988 +#ifdef CONFIG_PAX_RANDMMAP
5989 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5990 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5991 +#endif
5992 +
5993 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5994 mm->unmap_area = arch_unmap_area_topdown;
5995 }
5996 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5997 index 7f5f65d..3308382 100644
5998 --- a/arch/sparc/kernel/syscalls.S
5999 +++ b/arch/sparc/kernel/syscalls.S
6000 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6001 #endif
6002 .align 32
6003 1: ldx [%g6 + TI_FLAGS], %l5
6004 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6005 + andcc %l5, _TIF_WORK_SYSCALL, %g0
6006 be,pt %icc, rtrap
6007 nop
6008 call syscall_trace_leave
6009 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
6010
6011 srl %i5, 0, %o5 ! IEU1
6012 srl %i2, 0, %o2 ! IEU0 Group
6013 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6014 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6015 bne,pn %icc, linux_syscall_trace32 ! CTI
6016 mov %i0, %l5 ! IEU1
6017 call %l7 ! CTI Group brk forced
6018 @@ -202,7 +202,7 @@ linux_sparc_syscall:
6019
6020 mov %i3, %o3 ! IEU1
6021 mov %i4, %o4 ! IEU0 Group
6022 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6023 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6024 bne,pn %icc, linux_syscall_trace ! CTI Group
6025 mov %i0, %l5 ! IEU0
6026 2: call %l7 ! CTI Group brk forced
6027 @@ -218,7 +218,7 @@ ret_sys_call:
6028
6029 cmp %o0, -ERESTART_RESTARTBLOCK
6030 bgeu,pn %xcc, 1f
6031 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6032 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6033 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
6034
6035 2:
6036 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6037 index a5785ea..405c5f7 100644
6038 --- a/arch/sparc/kernel/traps_32.c
6039 +++ b/arch/sparc/kernel/traps_32.c
6040 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6041 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6042 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6043
6044 +extern void gr_handle_kernel_exploit(void);
6045 +
6046 void die_if_kernel(char *str, struct pt_regs *regs)
6047 {
6048 static int die_counter;
6049 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6050 count++ < 30 &&
6051 (((unsigned long) rw) >= PAGE_OFFSET) &&
6052 !(((unsigned long) rw) & 0x7)) {
6053 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6054 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6055 (void *) rw->ins[7]);
6056 rw = (struct reg_window32 *)rw->ins[6];
6057 }
6058 }
6059 printk("Instruction DUMP:");
6060 instruction_dump ((unsigned long *) regs->pc);
6061 - if(regs->psr & PSR_PS)
6062 + if(regs->psr & PSR_PS) {
6063 + gr_handle_kernel_exploit();
6064 do_exit(SIGKILL);
6065 + }
6066 do_exit(SIGSEGV);
6067 }
6068
6069 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6070 index 3b05e66..6ea2917 100644
6071 --- a/arch/sparc/kernel/traps_64.c
6072 +++ b/arch/sparc/kernel/traps_64.c
6073 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6074 i + 1,
6075 p->trapstack[i].tstate, p->trapstack[i].tpc,
6076 p->trapstack[i].tnpc, p->trapstack[i].tt);
6077 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6078 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6079 }
6080 }
6081
6082 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6083
6084 lvl -= 0x100;
6085 if (regs->tstate & TSTATE_PRIV) {
6086 +
6087 +#ifdef CONFIG_PAX_REFCOUNT
6088 + if (lvl == 6)
6089 + pax_report_refcount_overflow(regs);
6090 +#endif
6091 +
6092 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6093 die_if_kernel(buffer, regs);
6094 }
6095 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6096 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6097 {
6098 char buffer[32];
6099 -
6100 +
6101 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6102 0, lvl, SIGTRAP) == NOTIFY_STOP)
6103 return;
6104
6105 +#ifdef CONFIG_PAX_REFCOUNT
6106 + if (lvl == 6)
6107 + pax_report_refcount_overflow(regs);
6108 +#endif
6109 +
6110 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6111
6112 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6113 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6114 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6115 printk("%s" "ERROR(%d): ",
6116 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6117 - printk("TPC<%pS>\n", (void *) regs->tpc);
6118 + printk("TPC<%pA>\n", (void *) regs->tpc);
6119 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6120 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6121 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6122 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6123 smp_processor_id(),
6124 (type & 0x1) ? 'I' : 'D',
6125 regs->tpc);
6126 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6127 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6128 panic("Irrecoverable Cheetah+ parity error.");
6129 }
6130
6131 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6132 smp_processor_id(),
6133 (type & 0x1) ? 'I' : 'D',
6134 regs->tpc);
6135 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6136 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6137 }
6138
6139 struct sun4v_error_entry {
6140 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6141
6142 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6143 regs->tpc, tl);
6144 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6145 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6146 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6147 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6148 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6149 (void *) regs->u_regs[UREG_I7]);
6150 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6151 "pte[%lx] error[%lx]\n",
6152 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6153
6154 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6155 regs->tpc, tl);
6156 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6157 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6158 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6159 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6160 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6161 (void *) regs->u_regs[UREG_I7]);
6162 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6163 "pte[%lx] error[%lx]\n",
6164 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6165 fp = (unsigned long)sf->fp + STACK_BIAS;
6166 }
6167
6168 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6169 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6170 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6171 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6172 int index = tsk->curr_ret_stack;
6173 if (tsk->ret_stack && index >= graph) {
6174 pc = tsk->ret_stack[index - graph].ret;
6175 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6176 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6177 graph++;
6178 }
6179 }
6180 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6181 return (struct reg_window *) (fp + STACK_BIAS);
6182 }
6183
6184 +extern void gr_handle_kernel_exploit(void);
6185 +
6186 void die_if_kernel(char *str, struct pt_regs *regs)
6187 {
6188 static int die_counter;
6189 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6190 while (rw &&
6191 count++ < 30 &&
6192 kstack_valid(tp, (unsigned long) rw)) {
6193 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6194 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6195 (void *) rw->ins[7]);
6196
6197 rw = kernel_stack_up(rw);
6198 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6199 }
6200 user_instruction_dump ((unsigned int __user *) regs->tpc);
6201 }
6202 - if (regs->tstate & TSTATE_PRIV)
6203 + if (regs->tstate & TSTATE_PRIV) {
6204 + gr_handle_kernel_exploit();
6205 do_exit(SIGKILL);
6206 + }
6207 do_exit(SIGSEGV);
6208 }
6209 EXPORT_SYMBOL(die_if_kernel);
6210 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6211 index f81d038..e7a4680 100644
6212 --- a/arch/sparc/kernel/unaligned_64.c
6213 +++ b/arch/sparc/kernel/unaligned_64.c
6214 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6215 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6216
6217 if (__ratelimit(&ratelimit)) {
6218 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6219 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6220 regs->tpc, (void *) regs->tpc);
6221 }
6222 }
6223 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6224 index dff4096..bd9a388 100644
6225 --- a/arch/sparc/lib/Makefile
6226 +++ b/arch/sparc/lib/Makefile
6227 @@ -2,7 +2,7 @@
6228 #
6229
6230 asflags-y := -ansi -DST_DIV0=0x02
6231 -ccflags-y := -Werror
6232 +#ccflags-y := -Werror
6233
6234 lib-$(CONFIG_SPARC32) += ashrdi3.o
6235 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6236 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6237 index 4d502da..527c48d 100644
6238 --- a/arch/sparc/lib/atomic_64.S
6239 +++ b/arch/sparc/lib/atomic_64.S
6240 @@ -17,7 +17,12 @@
6241 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6242 BACKOFF_SETUP(%o2)
6243 1: lduw [%o1], %g1
6244 - add %g1, %o0, %g7
6245 + addcc %g1, %o0, %g7
6246 +
6247 +#ifdef CONFIG_PAX_REFCOUNT
6248 + tvs %icc, 6
6249 +#endif
6250 +
6251 cas [%o1], %g1, %g7
6252 cmp %g1, %g7
6253 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6254 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6255 2: BACKOFF_SPIN(%o2, %o3, 1b)
6256 ENDPROC(atomic_add)
6257
6258 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6259 + BACKOFF_SETUP(%o2)
6260 +1: lduw [%o1], %g1
6261 + add %g1, %o0, %g7
6262 + cas [%o1], %g1, %g7
6263 + cmp %g1, %g7
6264 + bne,pn %icc, 2f
6265 + nop
6266 + retl
6267 + nop
6268 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6269 +ENDPROC(atomic_add_unchecked)
6270 +
6271 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6272 BACKOFF_SETUP(%o2)
6273 1: lduw [%o1], %g1
6274 - sub %g1, %o0, %g7
6275 + subcc %g1, %o0, %g7
6276 +
6277 +#ifdef CONFIG_PAX_REFCOUNT
6278 + tvs %icc, 6
6279 +#endif
6280 +
6281 cas [%o1], %g1, %g7
6282 cmp %g1, %g7
6283 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6284 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6285 2: BACKOFF_SPIN(%o2, %o3, 1b)
6286 ENDPROC(atomic_sub)
6287
6288 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6289 + BACKOFF_SETUP(%o2)
6290 +1: lduw [%o1], %g1
6291 + sub %g1, %o0, %g7
6292 + cas [%o1], %g1, %g7
6293 + cmp %g1, %g7
6294 + bne,pn %icc, 2f
6295 + nop
6296 + retl
6297 + nop
6298 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6299 +ENDPROC(atomic_sub_unchecked)
6300 +
6301 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6302 BACKOFF_SETUP(%o2)
6303 1: lduw [%o1], %g1
6304 - add %g1, %o0, %g7
6305 + addcc %g1, %o0, %g7
6306 +
6307 +#ifdef CONFIG_PAX_REFCOUNT
6308 + tvs %icc, 6
6309 +#endif
6310 +
6311 cas [%o1], %g1, %g7
6312 cmp %g1, %g7
6313 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6314 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6315 2: BACKOFF_SPIN(%o2, %o3, 1b)
6316 ENDPROC(atomic_add_ret)
6317
6318 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6319 + BACKOFF_SETUP(%o2)
6320 +1: lduw [%o1], %g1
6321 + addcc %g1, %o0, %g7
6322 + cas [%o1], %g1, %g7
6323 + cmp %g1, %g7
6324 + bne,pn %icc, 2f
6325 + add %g7, %o0, %g7
6326 + sra %g7, 0, %o0
6327 + retl
6328 + nop
6329 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6330 +ENDPROC(atomic_add_ret_unchecked)
6331 +
6332 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6333 BACKOFF_SETUP(%o2)
6334 1: lduw [%o1], %g1
6335 - sub %g1, %o0, %g7
6336 + subcc %g1, %o0, %g7
6337 +
6338 +#ifdef CONFIG_PAX_REFCOUNT
6339 + tvs %icc, 6
6340 +#endif
6341 +
6342 cas [%o1], %g1, %g7
6343 cmp %g1, %g7
6344 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6345 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6346 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6347 BACKOFF_SETUP(%o2)
6348 1: ldx [%o1], %g1
6349 - add %g1, %o0, %g7
6350 + addcc %g1, %o0, %g7
6351 +
6352 +#ifdef CONFIG_PAX_REFCOUNT
6353 + tvs %xcc, 6
6354 +#endif
6355 +
6356 casx [%o1], %g1, %g7
6357 cmp %g1, %g7
6358 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6359 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6360 2: BACKOFF_SPIN(%o2, %o3, 1b)
6361 ENDPROC(atomic64_add)
6362
6363 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6364 + BACKOFF_SETUP(%o2)
6365 +1: ldx [%o1], %g1
6366 + addcc %g1, %o0, %g7
6367 + casx [%o1], %g1, %g7
6368 + cmp %g1, %g7
6369 + bne,pn %xcc, 2f
6370 + nop
6371 + retl
6372 + nop
6373 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6374 +ENDPROC(atomic64_add_unchecked)
6375 +
6376 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6377 BACKOFF_SETUP(%o2)
6378 1: ldx [%o1], %g1
6379 - sub %g1, %o0, %g7
6380 + subcc %g1, %o0, %g7
6381 +
6382 +#ifdef CONFIG_PAX_REFCOUNT
6383 + tvs %xcc, 6
6384 +#endif
6385 +
6386 casx [%o1], %g1, %g7
6387 cmp %g1, %g7
6388 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6389 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6390 2: BACKOFF_SPIN(%o2, %o3, 1b)
6391 ENDPROC(atomic64_sub)
6392
6393 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6394 + BACKOFF_SETUP(%o2)
6395 +1: ldx [%o1], %g1
6396 + subcc %g1, %o0, %g7
6397 + casx [%o1], %g1, %g7
6398 + cmp %g1, %g7
6399 + bne,pn %xcc, 2f
6400 + nop
6401 + retl
6402 + nop
6403 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6404 +ENDPROC(atomic64_sub_unchecked)
6405 +
6406 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6407 BACKOFF_SETUP(%o2)
6408 1: ldx [%o1], %g1
6409 - add %g1, %o0, %g7
6410 + addcc %g1, %o0, %g7
6411 +
6412 +#ifdef CONFIG_PAX_REFCOUNT
6413 + tvs %xcc, 6
6414 +#endif
6415 +
6416 casx [%o1], %g1, %g7
6417 cmp %g1, %g7
6418 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6419 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6420 2: BACKOFF_SPIN(%o2, %o3, 1b)
6421 ENDPROC(atomic64_add_ret)
6422
6423 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6424 + BACKOFF_SETUP(%o2)
6425 +1: ldx [%o1], %g1
6426 + addcc %g1, %o0, %g7
6427 + casx [%o1], %g1, %g7
6428 + cmp %g1, %g7
6429 + bne,pn %xcc, 2f
6430 + add %g7, %o0, %g7
6431 + mov %g7, %o0
6432 + retl
6433 + nop
6434 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6435 +ENDPROC(atomic64_add_ret_unchecked)
6436 +
6437 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6438 BACKOFF_SETUP(%o2)
6439 1: ldx [%o1], %g1
6440 - sub %g1, %o0, %g7
6441 + subcc %g1, %o0, %g7
6442 +
6443 +#ifdef CONFIG_PAX_REFCOUNT
6444 + tvs %xcc, 6
6445 +#endif
6446 +
6447 casx [%o1], %g1, %g7
6448 cmp %g1, %g7
6449 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6450 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6451 index 3b31218..345c609 100644
6452 --- a/arch/sparc/lib/ksyms.c
6453 +++ b/arch/sparc/lib/ksyms.c
6454 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6455
6456 /* Atomic counter implementation. */
6457 EXPORT_SYMBOL(atomic_add);
6458 +EXPORT_SYMBOL(atomic_add_unchecked);
6459 EXPORT_SYMBOL(atomic_add_ret);
6460 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6461 EXPORT_SYMBOL(atomic_sub);
6462 +EXPORT_SYMBOL(atomic_sub_unchecked);
6463 EXPORT_SYMBOL(atomic_sub_ret);
6464 EXPORT_SYMBOL(atomic64_add);
6465 +EXPORT_SYMBOL(atomic64_add_unchecked);
6466 EXPORT_SYMBOL(atomic64_add_ret);
6467 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6468 EXPORT_SYMBOL(atomic64_sub);
6469 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6470 EXPORT_SYMBOL(atomic64_sub_ret);
6471
6472 /* Atomic bit operations. */
6473 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6474 index 30c3ecc..736f015 100644
6475 --- a/arch/sparc/mm/Makefile
6476 +++ b/arch/sparc/mm/Makefile
6477 @@ -2,7 +2,7 @@
6478 #
6479
6480 asflags-y := -ansi
6481 -ccflags-y := -Werror
6482 +#ccflags-y := -Werror
6483
6484 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6485 obj-y += fault_$(BITS).o
6486 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6487 index 77ac917..baf45db 100644
6488 --- a/arch/sparc/mm/fault_32.c
6489 +++ b/arch/sparc/mm/fault_32.c
6490 @@ -21,6 +21,9 @@
6491 #include <linux/perf_event.h>
6492 #include <linux/interrupt.h>
6493 #include <linux/kdebug.h>
6494 +#include <linux/slab.h>
6495 +#include <linux/pagemap.h>
6496 +#include <linux/compiler.h>
6497
6498 #include <asm/page.h>
6499 #include <asm/pgtable.h>
6500 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6501 return safe_compute_effective_address(regs, insn);
6502 }
6503
6504 +#ifdef CONFIG_PAX_PAGEEXEC
6505 +#ifdef CONFIG_PAX_DLRESOLVE
6506 +static void pax_emuplt_close(struct vm_area_struct *vma)
6507 +{
6508 + vma->vm_mm->call_dl_resolve = 0UL;
6509 +}
6510 +
6511 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6512 +{
6513 + unsigned int *kaddr;
6514 +
6515 + vmf->page = alloc_page(GFP_HIGHUSER);
6516 + if (!vmf->page)
6517 + return VM_FAULT_OOM;
6518 +
6519 + kaddr = kmap(vmf->page);
6520 + memset(kaddr, 0, PAGE_SIZE);
6521 + kaddr[0] = 0x9DE3BFA8U; /* save */
6522 + flush_dcache_page(vmf->page);
6523 + kunmap(vmf->page);
6524 + return VM_FAULT_MAJOR;
6525 +}
6526 +
6527 +static const struct vm_operations_struct pax_vm_ops = {
6528 + .close = pax_emuplt_close,
6529 + .fault = pax_emuplt_fault
6530 +};
6531 +
6532 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6533 +{
6534 + int ret;
6535 +
6536 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6537 + vma->vm_mm = current->mm;
6538 + vma->vm_start = addr;
6539 + vma->vm_end = addr + PAGE_SIZE;
6540 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6541 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6542 + vma->vm_ops = &pax_vm_ops;
6543 +
6544 + ret = insert_vm_struct(current->mm, vma);
6545 + if (ret)
6546 + return ret;
6547 +
6548 + ++current->mm->total_vm;
6549 + return 0;
6550 +}
6551 +#endif
6552 +
6553 +/*
6554 + * PaX: decide what to do with offenders (regs->pc = fault address)
6555 + *
6556 + * returns 1 when task should be killed
6557 + * 2 when patched PLT trampoline was detected
6558 + * 3 when unpatched PLT trampoline was detected
6559 + */
6560 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6561 +{
6562 +
6563 +#ifdef CONFIG_PAX_EMUPLT
6564 + int err;
6565 +
6566 + do { /* PaX: patched PLT emulation #1 */
6567 + unsigned int sethi1, sethi2, jmpl;
6568 +
6569 + err = get_user(sethi1, (unsigned int *)regs->pc);
6570 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6571 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6572 +
6573 + if (err)
6574 + break;
6575 +
6576 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6577 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6578 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6579 + {
6580 + unsigned int addr;
6581 +
6582 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6583 + addr = regs->u_regs[UREG_G1];
6584 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6585 + regs->pc = addr;
6586 + regs->npc = addr+4;
6587 + return 2;
6588 + }
6589 + } while (0);
6590 +
6591 + do { /* PaX: patched PLT emulation #2 */
6592 + unsigned int ba;
6593 +
6594 + err = get_user(ba, (unsigned int *)regs->pc);
6595 +
6596 + if (err)
6597 + break;
6598 +
6599 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6600 + unsigned int addr;
6601 +
6602 + if ((ba & 0xFFC00000U) == 0x30800000U)
6603 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6604 + else
6605 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6606 + regs->pc = addr;
6607 + regs->npc = addr+4;
6608 + return 2;
6609 + }
6610 + } while (0);
6611 +
6612 + do { /* PaX: patched PLT emulation #3 */
6613 + unsigned int sethi, bajmpl, nop;
6614 +
6615 + err = get_user(sethi, (unsigned int *)regs->pc);
6616 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6617 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6618 +
6619 + if (err)
6620 + break;
6621 +
6622 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6623 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6624 + nop == 0x01000000U)
6625 + {
6626 + unsigned int addr;
6627 +
6628 + addr = (sethi & 0x003FFFFFU) << 10;
6629 + regs->u_regs[UREG_G1] = addr;
6630 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6631 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6632 + else
6633 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6634 + regs->pc = addr;
6635 + regs->npc = addr+4;
6636 + return 2;
6637 + }
6638 + } while (0);
6639 +
6640 + do { /* PaX: unpatched PLT emulation step 1 */
6641 + unsigned int sethi, ba, nop;
6642 +
6643 + err = get_user(sethi, (unsigned int *)regs->pc);
6644 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6645 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6646 +
6647 + if (err)
6648 + break;
6649 +
6650 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6651 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6652 + nop == 0x01000000U)
6653 + {
6654 + unsigned int addr, save, call;
6655 +
6656 + if ((ba & 0xFFC00000U) == 0x30800000U)
6657 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6658 + else
6659 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6660 +
6661 + err = get_user(save, (unsigned int *)addr);
6662 + err |= get_user(call, (unsigned int *)(addr+4));
6663 + err |= get_user(nop, (unsigned int *)(addr+8));
6664 + if (err)
6665 + break;
6666 +
6667 +#ifdef CONFIG_PAX_DLRESOLVE
6668 + if (save == 0x9DE3BFA8U &&
6669 + (call & 0xC0000000U) == 0x40000000U &&
6670 + nop == 0x01000000U)
6671 + {
6672 + struct vm_area_struct *vma;
6673 + unsigned long call_dl_resolve;
6674 +
6675 + down_read(&current->mm->mmap_sem);
6676 + call_dl_resolve = current->mm->call_dl_resolve;
6677 + up_read(&current->mm->mmap_sem);
6678 + if (likely(call_dl_resolve))
6679 + goto emulate;
6680 +
6681 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6682 +
6683 + down_write(&current->mm->mmap_sem);
6684 + if (current->mm->call_dl_resolve) {
6685 + call_dl_resolve = current->mm->call_dl_resolve;
6686 + up_write(&current->mm->mmap_sem);
6687 + if (vma)
6688 + kmem_cache_free(vm_area_cachep, vma);
6689 + goto emulate;
6690 + }
6691 +
6692 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6693 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6694 + up_write(&current->mm->mmap_sem);
6695 + if (vma)
6696 + kmem_cache_free(vm_area_cachep, vma);
6697 + return 1;
6698 + }
6699 +
6700 + if (pax_insert_vma(vma, call_dl_resolve)) {
6701 + up_write(&current->mm->mmap_sem);
6702 + kmem_cache_free(vm_area_cachep, vma);
6703 + return 1;
6704 + }
6705 +
6706 + current->mm->call_dl_resolve = call_dl_resolve;
6707 + up_write(&current->mm->mmap_sem);
6708 +
6709 +emulate:
6710 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6711 + regs->pc = call_dl_resolve;
6712 + regs->npc = addr+4;
6713 + return 3;
6714 + }
6715 +#endif
6716 +
6717 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6718 + if ((save & 0xFFC00000U) == 0x05000000U &&
6719 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6720 + nop == 0x01000000U)
6721 + {
6722 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6723 + regs->u_regs[UREG_G2] = addr + 4;
6724 + addr = (save & 0x003FFFFFU) << 10;
6725 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6726 + regs->pc = addr;
6727 + regs->npc = addr+4;
6728 + return 3;
6729 + }
6730 + }
6731 + } while (0);
6732 +
6733 + do { /* PaX: unpatched PLT emulation step 2 */
6734 + unsigned int save, call, nop;
6735 +
6736 + err = get_user(save, (unsigned int *)(regs->pc-4));
6737 + err |= get_user(call, (unsigned int *)regs->pc);
6738 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6739 + if (err)
6740 + break;
6741 +
6742 + if (save == 0x9DE3BFA8U &&
6743 + (call & 0xC0000000U) == 0x40000000U &&
6744 + nop == 0x01000000U)
6745 + {
6746 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6747 +
6748 + regs->u_regs[UREG_RETPC] = regs->pc;
6749 + regs->pc = dl_resolve;
6750 + regs->npc = dl_resolve+4;
6751 + return 3;
6752 + }
6753 + } while (0);
6754 +#endif
6755 +
6756 + return 1;
6757 +}
6758 +
6759 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6760 +{
6761 + unsigned long i;
6762 +
6763 + printk(KERN_ERR "PAX: bytes at PC: ");
6764 + for (i = 0; i < 8; i++) {
6765 + unsigned int c;
6766 + if (get_user(c, (unsigned int *)pc+i))
6767 + printk(KERN_CONT "???????? ");
6768 + else
6769 + printk(KERN_CONT "%08x ", c);
6770 + }
6771 + printk("\n");
6772 +}
6773 +#endif
6774 +
6775 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6776 int text_fault)
6777 {
6778 @@ -230,6 +504,24 @@ good_area:
6779 if (!(vma->vm_flags & VM_WRITE))
6780 goto bad_area;
6781 } else {
6782 +
6783 +#ifdef CONFIG_PAX_PAGEEXEC
6784 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6785 + up_read(&mm->mmap_sem);
6786 + switch (pax_handle_fetch_fault(regs)) {
6787 +
6788 +#ifdef CONFIG_PAX_EMUPLT
6789 + case 2:
6790 + case 3:
6791 + return;
6792 +#endif
6793 +
6794 + }
6795 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6796 + do_group_exit(SIGKILL);
6797 + }
6798 +#endif
6799 +
6800 /* Allow reads even for write-only mappings */
6801 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6802 goto bad_area;
6803 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6804 index 1fe0429..8dd5dd5 100644
6805 --- a/arch/sparc/mm/fault_64.c
6806 +++ b/arch/sparc/mm/fault_64.c
6807 @@ -21,6 +21,9 @@
6808 #include <linux/kprobes.h>
6809 #include <linux/kdebug.h>
6810 #include <linux/percpu.h>
6811 +#include <linux/slab.h>
6812 +#include <linux/pagemap.h>
6813 +#include <linux/compiler.h>
6814
6815 #include <asm/page.h>
6816 #include <asm/pgtable.h>
6817 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6818 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6819 regs->tpc);
6820 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6821 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6822 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6823 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6824 dump_stack();
6825 unhandled_fault(regs->tpc, current, regs);
6826 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6827 show_regs(regs);
6828 }
6829
6830 +#ifdef CONFIG_PAX_PAGEEXEC
6831 +#ifdef CONFIG_PAX_DLRESOLVE
6832 +static void pax_emuplt_close(struct vm_area_struct *vma)
6833 +{
6834 + vma->vm_mm->call_dl_resolve = 0UL;
6835 +}
6836 +
6837 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6838 +{
6839 + unsigned int *kaddr;
6840 +
6841 + vmf->page = alloc_page(GFP_HIGHUSER);
6842 + if (!vmf->page)
6843 + return VM_FAULT_OOM;
6844 +
6845 + kaddr = kmap(vmf->page);
6846 + memset(kaddr, 0, PAGE_SIZE);
6847 + kaddr[0] = 0x9DE3BFA8U; /* save */
6848 + flush_dcache_page(vmf->page);
6849 + kunmap(vmf->page);
6850 + return VM_FAULT_MAJOR;
6851 +}
6852 +
6853 +static const struct vm_operations_struct pax_vm_ops = {
6854 + .close = pax_emuplt_close,
6855 + .fault = pax_emuplt_fault
6856 +};
6857 +
6858 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6859 +{
6860 + int ret;
6861 +
6862 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6863 + vma->vm_mm = current->mm;
6864 + vma->vm_start = addr;
6865 + vma->vm_end = addr + PAGE_SIZE;
6866 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6867 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6868 + vma->vm_ops = &pax_vm_ops;
6869 +
6870 + ret = insert_vm_struct(current->mm, vma);
6871 + if (ret)
6872 + return ret;
6873 +
6874 + ++current->mm->total_vm;
6875 + return 0;
6876 +}
6877 +#endif
6878 +
6879 +/*
6880 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6881 + *
6882 + * returns 1 when task should be killed
6883 + * 2 when patched PLT trampoline was detected
6884 + * 3 when unpatched PLT trampoline was detected
6885 + */
6886 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6887 +{
6888 +
6889 +#ifdef CONFIG_PAX_EMUPLT
6890 + int err;
6891 +
6892 + do { /* PaX: patched PLT emulation #1 */
6893 + unsigned int sethi1, sethi2, jmpl;
6894 +
6895 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6896 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6897 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6898 +
6899 + if (err)
6900 + break;
6901 +
6902 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6903 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6904 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6905 + {
6906 + unsigned long addr;
6907 +
6908 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6909 + addr = regs->u_regs[UREG_G1];
6910 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6911 +
6912 + if (test_thread_flag(TIF_32BIT))
6913 + addr &= 0xFFFFFFFFUL;
6914 +
6915 + regs->tpc = addr;
6916 + regs->tnpc = addr+4;
6917 + return 2;
6918 + }
6919 + } while (0);
6920 +
6921 + do { /* PaX: patched PLT emulation #2 */
6922 + unsigned int ba;
6923 +
6924 + err = get_user(ba, (unsigned int *)regs->tpc);
6925 +
6926 + if (err)
6927 + break;
6928 +
6929 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6930 + unsigned long addr;
6931 +
6932 + if ((ba & 0xFFC00000U) == 0x30800000U)
6933 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6934 + else
6935 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6936 +
6937 + if (test_thread_flag(TIF_32BIT))
6938 + addr &= 0xFFFFFFFFUL;
6939 +
6940 + regs->tpc = addr;
6941 + regs->tnpc = addr+4;
6942 + return 2;
6943 + }
6944 + } while (0);
6945 +
6946 + do { /* PaX: patched PLT emulation #3 */
6947 + unsigned int sethi, bajmpl, nop;
6948 +
6949 + err = get_user(sethi, (unsigned int *)regs->tpc);
6950 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6951 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6952 +
6953 + if (err)
6954 + break;
6955 +
6956 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6957 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6958 + nop == 0x01000000U)
6959 + {
6960 + unsigned long addr;
6961 +
6962 + addr = (sethi & 0x003FFFFFU) << 10;
6963 + regs->u_regs[UREG_G1] = addr;
6964 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6965 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6966 + else
6967 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6968 +
6969 + if (test_thread_flag(TIF_32BIT))
6970 + addr &= 0xFFFFFFFFUL;
6971 +
6972 + regs->tpc = addr;
6973 + regs->tnpc = addr+4;
6974 + return 2;
6975 + }
6976 + } while (0);
6977 +
6978 + do { /* PaX: patched PLT emulation #4 */
6979 + unsigned int sethi, mov1, call, mov2;
6980 +
6981 + err = get_user(sethi, (unsigned int *)regs->tpc);
6982 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6983 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6984 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6985 +
6986 + if (err)
6987 + break;
6988 +
6989 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6990 + mov1 == 0x8210000FU &&
6991 + (call & 0xC0000000U) == 0x40000000U &&
6992 + mov2 == 0x9E100001U)
6993 + {
6994 + unsigned long addr;
6995 +
6996 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6997 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6998 +
6999 + if (test_thread_flag(TIF_32BIT))
7000 + addr &= 0xFFFFFFFFUL;
7001 +
7002 + regs->tpc = addr;
7003 + regs->tnpc = addr+4;
7004 + return 2;
7005 + }
7006 + } while (0);
7007 +
7008 + do { /* PaX: patched PLT emulation #5 */
7009 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7010 +
7011 + err = get_user(sethi, (unsigned int *)regs->tpc);
7012 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7013 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7014 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7015 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7016 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7017 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7018 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7019 +
7020 + if (err)
7021 + break;
7022 +
7023 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7024 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7025 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7026 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7027 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7028 + sllx == 0x83287020U &&
7029 + jmpl == 0x81C04005U &&
7030 + nop == 0x01000000U)
7031 + {
7032 + unsigned long addr;
7033 +
7034 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7035 + regs->u_regs[UREG_G1] <<= 32;
7036 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7037 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7038 + regs->tpc = addr;
7039 + regs->tnpc = addr+4;
7040 + return 2;
7041 + }
7042 + } while (0);
7043 +
7044 + do { /* PaX: patched PLT emulation #6 */
7045 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7046 +
7047 + err = get_user(sethi, (unsigned int *)regs->tpc);
7048 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7049 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7050 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7051 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7052 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7053 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7054 +
7055 + if (err)
7056 + break;
7057 +
7058 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7059 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7060 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7061 + sllx == 0x83287020U &&
7062 + (or & 0xFFFFE000U) == 0x8A116000U &&
7063 + jmpl == 0x81C04005U &&
7064 + nop == 0x01000000U)
7065 + {
7066 + unsigned long addr;
7067 +
7068 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7069 + regs->u_regs[UREG_G1] <<= 32;
7070 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7071 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7072 + regs->tpc = addr;
7073 + regs->tnpc = addr+4;
7074 + return 2;
7075 + }
7076 + } while (0);
7077 +
7078 + do { /* PaX: unpatched PLT emulation step 1 */
7079 + unsigned int sethi, ba, nop;
7080 +
7081 + err = get_user(sethi, (unsigned int *)regs->tpc);
7082 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7083 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7084 +
7085 + if (err)
7086 + break;
7087 +
7088 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7089 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7090 + nop == 0x01000000U)
7091 + {
7092 + unsigned long addr;
7093 + unsigned int save, call;
7094 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7095 +
7096 + if ((ba & 0xFFC00000U) == 0x30800000U)
7097 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7098 + else
7099 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7100 +
7101 + if (test_thread_flag(TIF_32BIT))
7102 + addr &= 0xFFFFFFFFUL;
7103 +
7104 + err = get_user(save, (unsigned int *)addr);
7105 + err |= get_user(call, (unsigned int *)(addr+4));
7106 + err |= get_user(nop, (unsigned int *)(addr+8));
7107 + if (err)
7108 + break;
7109 +
7110 +#ifdef CONFIG_PAX_DLRESOLVE
7111 + if (save == 0x9DE3BFA8U &&
7112 + (call & 0xC0000000U) == 0x40000000U &&
7113 + nop == 0x01000000U)
7114 + {
7115 + struct vm_area_struct *vma;
7116 + unsigned long call_dl_resolve;
7117 +
7118 + down_read(&current->mm->mmap_sem);
7119 + call_dl_resolve = current->mm->call_dl_resolve;
7120 + up_read(&current->mm->mmap_sem);
7121 + if (likely(call_dl_resolve))
7122 + goto emulate;
7123 +
7124 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7125 +
7126 + down_write(&current->mm->mmap_sem);
7127 + if (current->mm->call_dl_resolve) {
7128 + call_dl_resolve = current->mm->call_dl_resolve;
7129 + up_write(&current->mm->mmap_sem);
7130 + if (vma)
7131 + kmem_cache_free(vm_area_cachep, vma);
7132 + goto emulate;
7133 + }
7134 +
7135 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7136 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7137 + up_write(&current->mm->mmap_sem);
7138 + if (vma)
7139 + kmem_cache_free(vm_area_cachep, vma);
7140 + return 1;
7141 + }
7142 +
7143 + if (pax_insert_vma(vma, call_dl_resolve)) {
7144 + up_write(&current->mm->mmap_sem);
7145 + kmem_cache_free(vm_area_cachep, vma);
7146 + return 1;
7147 + }
7148 +
7149 + current->mm->call_dl_resolve = call_dl_resolve;
7150 + up_write(&current->mm->mmap_sem);
7151 +
7152 +emulate:
7153 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7154 + regs->tpc = call_dl_resolve;
7155 + regs->tnpc = addr+4;
7156 + return 3;
7157 + }
7158 +#endif
7159 +
7160 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7161 + if ((save & 0xFFC00000U) == 0x05000000U &&
7162 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7163 + nop == 0x01000000U)
7164 + {
7165 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7166 + regs->u_regs[UREG_G2] = addr + 4;
7167 + addr = (save & 0x003FFFFFU) << 10;
7168 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7169 +
7170 + if (test_thread_flag(TIF_32BIT))
7171 + addr &= 0xFFFFFFFFUL;
7172 +
7173 + regs->tpc = addr;
7174 + regs->tnpc = addr+4;
7175 + return 3;
7176 + }
7177 +
7178 + /* PaX: 64-bit PLT stub */
7179 + err = get_user(sethi1, (unsigned int *)addr);
7180 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7181 + err |= get_user(or1, (unsigned int *)(addr+8));
7182 + err |= get_user(or2, (unsigned int *)(addr+12));
7183 + err |= get_user(sllx, (unsigned int *)(addr+16));
7184 + err |= get_user(add, (unsigned int *)(addr+20));
7185 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7186 + err |= get_user(nop, (unsigned int *)(addr+28));
7187 + if (err)
7188 + break;
7189 +
7190 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7191 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7192 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7193 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7194 + sllx == 0x89293020U &&
7195 + add == 0x8A010005U &&
7196 + jmpl == 0x89C14000U &&
7197 + nop == 0x01000000U)
7198 + {
7199 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7200 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7201 + regs->u_regs[UREG_G4] <<= 32;
7202 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7203 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7204 + regs->u_regs[UREG_G4] = addr + 24;
7205 + addr = regs->u_regs[UREG_G5];
7206 + regs->tpc = addr;
7207 + regs->tnpc = addr+4;
7208 + return 3;
7209 + }
7210 + }
7211 + } while (0);
7212 +
7213 +#ifdef CONFIG_PAX_DLRESOLVE
7214 + do { /* PaX: unpatched PLT emulation step 2 */
7215 + unsigned int save, call, nop;
7216 +
7217 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7218 + err |= get_user(call, (unsigned int *)regs->tpc);
7219 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7220 + if (err)
7221 + break;
7222 +
7223 + if (save == 0x9DE3BFA8U &&
7224 + (call & 0xC0000000U) == 0x40000000U &&
7225 + nop == 0x01000000U)
7226 + {
7227 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7228 +
7229 + if (test_thread_flag(TIF_32BIT))
7230 + dl_resolve &= 0xFFFFFFFFUL;
7231 +
7232 + regs->u_regs[UREG_RETPC] = regs->tpc;
7233 + regs->tpc = dl_resolve;
7234 + regs->tnpc = dl_resolve+4;
7235 + return 3;
7236 + }
7237 + } while (0);
7238 +#endif
7239 +
7240 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7241 + unsigned int sethi, ba, nop;
7242 +
7243 + err = get_user(sethi, (unsigned int *)regs->tpc);
7244 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7245 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7246 +
7247 + if (err)
7248 + break;
7249 +
7250 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7251 + (ba & 0xFFF00000U) == 0x30600000U &&
7252 + nop == 0x01000000U)
7253 + {
7254 + unsigned long addr;
7255 +
7256 + addr = (sethi & 0x003FFFFFU) << 10;
7257 + regs->u_regs[UREG_G1] = addr;
7258 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7259 +
7260 + if (test_thread_flag(TIF_32BIT))
7261 + addr &= 0xFFFFFFFFUL;
7262 +
7263 + regs->tpc = addr;
7264 + regs->tnpc = addr+4;
7265 + return 2;
7266 + }
7267 + } while (0);
7268 +
7269 +#endif
7270 +
7271 + return 1;
7272 +}
7273 +
7274 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7275 +{
7276 + unsigned long i;
7277 +
7278 + printk(KERN_ERR "PAX: bytes at PC: ");
7279 + for (i = 0; i < 8; i++) {
7280 + unsigned int c;
7281 + if (get_user(c, (unsigned int *)pc+i))
7282 + printk(KERN_CONT "???????? ");
7283 + else
7284 + printk(KERN_CONT "%08x ", c);
7285 + }
7286 + printk("\n");
7287 +}
7288 +#endif
7289 +
7290 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7291 {
7292 struct mm_struct *mm = current->mm;
7293 @@ -343,6 +806,29 @@ retry:
7294 if (!vma)
7295 goto bad_area;
7296
7297 +#ifdef CONFIG_PAX_PAGEEXEC
7298 + /* PaX: detect ITLB misses on non-exec pages */
7299 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7300 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7301 + {
7302 + if (address != regs->tpc)
7303 + goto good_area;
7304 +
7305 + up_read(&mm->mmap_sem);
7306 + switch (pax_handle_fetch_fault(regs)) {
7307 +
7308 +#ifdef CONFIG_PAX_EMUPLT
7309 + case 2:
7310 + case 3:
7311 + return;
7312 +#endif
7313 +
7314 + }
7315 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7316 + do_group_exit(SIGKILL);
7317 + }
7318 +#endif
7319 +
7320 /* Pure DTLB misses do not tell us whether the fault causing
7321 * load/store/atomic was a write or not, it only says that there
7322 * was no match. So in such a case we (carefully) read the
7323 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7324 index 07e1453..0a7d9e9 100644
7325 --- a/arch/sparc/mm/hugetlbpage.c
7326 +++ b/arch/sparc/mm/hugetlbpage.c
7327 @@ -67,7 +67,7 @@ full_search:
7328 }
7329 return -ENOMEM;
7330 }
7331 - if (likely(!vma || addr + len <= vma->vm_start)) {
7332 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7333 /*
7334 * Remember the place where we stopped the search:
7335 */
7336 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7337 /* make sure it can fit in the remaining address space */
7338 if (likely(addr > len)) {
7339 vma = find_vma(mm, addr-len);
7340 - if (!vma || addr <= vma->vm_start) {
7341 + if (check_heap_stack_gap(vma, addr - len, len)) {
7342 /* remember the address as a hint for next time */
7343 return (mm->free_area_cache = addr-len);
7344 }
7345 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7346 if (unlikely(mm->mmap_base < len))
7347 goto bottomup;
7348
7349 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7350 + addr = mm->mmap_base - len;
7351
7352 do {
7353 + addr &= HPAGE_MASK;
7354 /*
7355 * Lookup failure means no vma is above this address,
7356 * else if new region fits below vma->vm_start,
7357 * return with success:
7358 */
7359 vma = find_vma(mm, addr);
7360 - if (likely(!vma || addr+len <= vma->vm_start)) {
7361 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7362 /* remember the address as a hint for next time */
7363 return (mm->free_area_cache = addr);
7364 }
7365 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7366 mm->cached_hole_size = vma->vm_start - addr;
7367
7368 /* try just below the current vma->vm_start */
7369 - addr = (vma->vm_start-len) & HPAGE_MASK;
7370 - } while (likely(len < vma->vm_start));
7371 + addr = skip_heap_stack_gap(vma, len);
7372 + } while (!IS_ERR_VALUE(addr));
7373
7374 bottomup:
7375 /*
7376 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7377 if (addr) {
7378 addr = ALIGN(addr, HPAGE_SIZE);
7379 vma = find_vma(mm, addr);
7380 - if (task_size - len >= addr &&
7381 - (!vma || addr + len <= vma->vm_start))
7382 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7383 return addr;
7384 }
7385 if (mm->get_unmapped_area == arch_get_unmapped_area)
7386 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7387 index f4500c6..889656c 100644
7388 --- a/arch/tile/include/asm/atomic_64.h
7389 +++ b/arch/tile/include/asm/atomic_64.h
7390 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7391
7392 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7393
7394 +#define atomic64_read_unchecked(v) atomic64_read(v)
7395 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7396 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7397 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7398 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7399 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7400 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7401 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7402 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7403 +
7404 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7405 #define smp_mb__before_atomic_dec() smp_mb()
7406 #define smp_mb__after_atomic_dec() smp_mb()
7407 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7408 index a9a5299..0fce79e 100644
7409 --- a/arch/tile/include/asm/cache.h
7410 +++ b/arch/tile/include/asm/cache.h
7411 @@ -15,11 +15,12 @@
7412 #ifndef _ASM_TILE_CACHE_H
7413 #define _ASM_TILE_CACHE_H
7414
7415 +#include <linux/const.h>
7416 #include <arch/chip.h>
7417
7418 /* bytes per L1 data cache line */
7419 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7420 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7421 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7422
7423 /* bytes per L2 cache line */
7424 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7425 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7426 index 9ab078a..d6635c2 100644
7427 --- a/arch/tile/include/asm/uaccess.h
7428 +++ b/arch/tile/include/asm/uaccess.h
7429 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7430 const void __user *from,
7431 unsigned long n)
7432 {
7433 - int sz = __compiletime_object_size(to);
7434 + size_t sz = __compiletime_object_size(to);
7435
7436 - if (likely(sz == -1 || sz >= n))
7437 + if (likely(sz == (size_t)-1 || sz >= n))
7438 n = _copy_from_user(to, from, n);
7439 else
7440 copy_from_user_overflow();
7441 diff --git a/arch/um/Makefile b/arch/um/Makefile
7442 index 0970910..9f65c40 100644
7443 --- a/arch/um/Makefile
7444 +++ b/arch/um/Makefile
7445 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7446 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7447 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7448
7449 +ifdef CONSTIFY_PLUGIN
7450 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7451 +endif
7452 +
7453 #This will adjust *FLAGS accordingly to the platform.
7454 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7455
7456 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7457 index 19e1bdd..3665b77 100644
7458 --- a/arch/um/include/asm/cache.h
7459 +++ b/arch/um/include/asm/cache.h
7460 @@ -1,6 +1,7 @@
7461 #ifndef __UM_CACHE_H
7462 #define __UM_CACHE_H
7463
7464 +#include <linux/const.h>
7465
7466 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7467 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7468 @@ -12,6 +13,6 @@
7469 # define L1_CACHE_SHIFT 5
7470 #endif
7471
7472 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7473 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7474
7475 #endif
7476 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7477 index 2e0a6b1..a64d0f5 100644
7478 --- a/arch/um/include/asm/kmap_types.h
7479 +++ b/arch/um/include/asm/kmap_types.h
7480 @@ -8,6 +8,6 @@
7481
7482 /* No more #include "asm/arch/kmap_types.h" ! */
7483
7484 -#define KM_TYPE_NR 14
7485 +#define KM_TYPE_NR 15
7486
7487 #endif
7488 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7489 index 7cfc3ce..cbd1a58 100644
7490 --- a/arch/um/include/asm/page.h
7491 +++ b/arch/um/include/asm/page.h
7492 @@ -14,6 +14,9 @@
7493 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7494 #define PAGE_MASK (~(PAGE_SIZE-1))
7495
7496 +#define ktla_ktva(addr) (addr)
7497 +#define ktva_ktla(addr) (addr)
7498 +
7499 #ifndef __ASSEMBLY__
7500
7501 struct page;
7502 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7503 index 0032f92..cd151e0 100644
7504 --- a/arch/um/include/asm/pgtable-3level.h
7505 +++ b/arch/um/include/asm/pgtable-3level.h
7506 @@ -58,6 +58,7 @@
7507 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7508 #define pud_populate(mm, pud, pmd) \
7509 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7510 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7511
7512 #ifdef CONFIG_64BIT
7513 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7514 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7515 index c5f5afa..6abce4b 100644
7516 --- a/arch/um/kernel/process.c
7517 +++ b/arch/um/kernel/process.c
7518 @@ -402,22 +402,6 @@ int singlestepping(void * t)
7519 return 2;
7520 }
7521
7522 -/*
7523 - * Only x86 and x86_64 have an arch_align_stack().
7524 - * All other arches have "#define arch_align_stack(x) (x)"
7525 - * in their asm/system.h
7526 - * As this is included in UML from asm-um/system-generic.h,
7527 - * we can use it to behave as the subarch does.
7528 - */
7529 -#ifndef arch_align_stack
7530 -unsigned long arch_align_stack(unsigned long sp)
7531 -{
7532 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7533 - sp -= get_random_int() % 8192;
7534 - return sp & ~0xf;
7535 -}
7536 -#endif
7537 -
7538 unsigned long get_wchan(struct task_struct *p)
7539 {
7540 unsigned long stack_page, sp, ip;
7541 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7542 index ad8f795..2c7eec6 100644
7543 --- a/arch/unicore32/include/asm/cache.h
7544 +++ b/arch/unicore32/include/asm/cache.h
7545 @@ -12,8 +12,10 @@
7546 #ifndef __UNICORE_CACHE_H__
7547 #define __UNICORE_CACHE_H__
7548
7549 -#define L1_CACHE_SHIFT (5)
7550 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7551 +#include <linux/const.h>
7552 +
7553 +#define L1_CACHE_SHIFT 5
7554 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7555
7556 /*
7557 * Memory returned by kmalloc() may be used for DMA, so we must make
7558 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7559 index 50a1d1f..c26369f 100644
7560 --- a/arch/x86/Kconfig
7561 +++ b/arch/x86/Kconfig
7562 @@ -220,7 +220,7 @@ config X86_HT
7563
7564 config X86_32_LAZY_GS
7565 def_bool y
7566 - depends on X86_32 && !CC_STACKPROTECTOR
7567 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7568
7569 config ARCH_HWEIGHT_CFLAGS
7570 string
7571 @@ -1049,7 +1049,7 @@ choice
7572
7573 config NOHIGHMEM
7574 bool "off"
7575 - depends on !X86_NUMAQ
7576 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7577 ---help---
7578 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7579 However, the address space of 32-bit x86 processors is only 4
7580 @@ -1086,7 +1086,7 @@ config NOHIGHMEM
7581
7582 config HIGHMEM4G
7583 bool "4GB"
7584 - depends on !X86_NUMAQ
7585 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7586 ---help---
7587 Select this if you have a 32-bit processor and between 1 and 4
7588 gigabytes of physical RAM.
7589 @@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7590 hex
7591 default 0xB0000000 if VMSPLIT_3G_OPT
7592 default 0x80000000 if VMSPLIT_2G
7593 - default 0x78000000 if VMSPLIT_2G_OPT
7594 + default 0x70000000 if VMSPLIT_2G_OPT
7595 default 0x40000000 if VMSPLIT_1G
7596 default 0xC0000000
7597 depends on X86_32
7598 @@ -1528,6 +1528,7 @@ config SECCOMP
7599
7600 config CC_STACKPROTECTOR
7601 bool "Enable -fstack-protector buffer overflow detection"
7602 + depends on X86_64 || !PAX_MEMORY_UDEREF
7603 ---help---
7604 This option turns on the -fstack-protector GCC feature. This
7605 feature puts, at the beginning of functions, a canary value on
7606 @@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7607 config PHYSICAL_START
7608 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7609 default "0x1000000"
7610 + range 0x400000 0x40000000
7611 ---help---
7612 This gives the physical address where the kernel is loaded.
7613
7614 @@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7615 config PHYSICAL_ALIGN
7616 hex "Alignment value to which kernel should be aligned" if X86_32
7617 default "0x1000000"
7618 + range 0x400000 0x1000000 if PAX_KERNEXEC
7619 range 0x2000 0x1000000
7620 ---help---
7621 This value puts the alignment restrictions on physical address
7622 @@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7623 Say N if you want to disable CPU hotplug.
7624
7625 config COMPAT_VDSO
7626 - def_bool y
7627 + def_bool n
7628 prompt "Compat VDSO support"
7629 depends on X86_32 || IA32_EMULATION
7630 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7631 ---help---
7632 Map the 32-bit VDSO to the predictable old-style address too.
7633
7634 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7635 index 706e12e..62e4feb 100644
7636 --- a/arch/x86/Kconfig.cpu
7637 +++ b/arch/x86/Kconfig.cpu
7638 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7639
7640 config X86_F00F_BUG
7641 def_bool y
7642 - depends on M586MMX || M586TSC || M586 || M486 || M386
7643 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7644
7645 config X86_INVD_BUG
7646 def_bool y
7647 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7648
7649 config X86_ALIGNMENT_16
7650 def_bool y
7651 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7652 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7653
7654 config X86_INTEL_USERCOPY
7655 def_bool y
7656 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7657 # generates cmov.
7658 config X86_CMOV
7659 def_bool y
7660 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7661 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7662
7663 config X86_MINIMUM_CPU_FAMILY
7664 int
7665 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7666 index b322f12..652d0d9 100644
7667 --- a/arch/x86/Kconfig.debug
7668 +++ b/arch/x86/Kconfig.debug
7669 @@ -84,7 +84,7 @@ config X86_PTDUMP
7670 config DEBUG_RODATA
7671 bool "Write protect kernel read-only data structures"
7672 default y
7673 - depends on DEBUG_KERNEL
7674 + depends on DEBUG_KERNEL && BROKEN
7675 ---help---
7676 Mark the kernel read-only data as write-protected in the pagetables,
7677 in order to catch accidental (and incorrect) writes to such const
7678 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7679
7680 config DEBUG_SET_MODULE_RONX
7681 bool "Set loadable kernel module data as NX and text as RO"
7682 - depends on MODULES
7683 + depends on MODULES && BROKEN
7684 ---help---
7685 This option helps catch unintended modifications to loadable
7686 kernel module's text and read-only data. It also prevents execution
7687 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7688
7689 config DEBUG_STRICT_USER_COPY_CHECKS
7690 bool "Strict copy size checks"
7691 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7692 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7693 ---help---
7694 Enabling this option turns a certain set of sanity checks for user
7695 copy operations into compile time failures.
7696 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7697 index 05afcca..b6ecb51 100644
7698 --- a/arch/x86/Makefile
7699 +++ b/arch/x86/Makefile
7700 @@ -50,6 +50,7 @@ else
7701 UTS_MACHINE := x86_64
7702 CHECKFLAGS += -D__x86_64__ -m64
7703
7704 + biarch := $(call cc-option,-m64)
7705 KBUILD_AFLAGS += -m64
7706 KBUILD_CFLAGS += -m64
7707
7708 @@ -229,3 +230,12 @@ define archhelp
7709 echo ' FDARGS="..." arguments for the booted kernel'
7710 echo ' FDINITRD=file initrd for the booted kernel'
7711 endef
7712 +
7713 +define OLD_LD
7714 +
7715 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7716 +*** Please upgrade your binutils to 2.18 or newer
7717 +endef
7718 +
7719 +archprepare:
7720 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7721 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7722 index f7535be..37db2d1 100644
7723 --- a/arch/x86/boot/Makefile
7724 +++ b/arch/x86/boot/Makefile
7725 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7726 $(call cc-option, -fno-stack-protector) \
7727 $(call cc-option, -mpreferred-stack-boundary=2)
7728 KBUILD_CFLAGS += $(call cc-option, -m32)
7729 +ifdef CONSTIFY_PLUGIN
7730 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7731 +endif
7732 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7733 GCOV_PROFILE := n
7734
7735 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7736 index 878e4b9..20537ab 100644
7737 --- a/arch/x86/boot/bitops.h
7738 +++ b/arch/x86/boot/bitops.h
7739 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7740 u8 v;
7741 const u32 *p = (const u32 *)addr;
7742
7743 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7744 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7745 return v;
7746 }
7747
7748 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7749
7750 static inline void set_bit(int nr, void *addr)
7751 {
7752 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7753 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7754 }
7755
7756 #endif /* BOOT_BITOPS_H */
7757 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7758 index 18997e5..83d9c67 100644
7759 --- a/arch/x86/boot/boot.h
7760 +++ b/arch/x86/boot/boot.h
7761 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7762 static inline u16 ds(void)
7763 {
7764 u16 seg;
7765 - asm("movw %%ds,%0" : "=rm" (seg));
7766 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7767 return seg;
7768 }
7769
7770 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7771 static inline int memcmp(const void *s1, const void *s2, size_t len)
7772 {
7773 u8 diff;
7774 - asm("repe; cmpsb; setnz %0"
7775 + asm volatile("repe; cmpsb; setnz %0"
7776 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7777 return diff;
7778 }
7779 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7780 index 8a84501..b2d165f 100644
7781 --- a/arch/x86/boot/compressed/Makefile
7782 +++ b/arch/x86/boot/compressed/Makefile
7783 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7784 KBUILD_CFLAGS += $(cflags-y)
7785 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7786 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7787 +ifdef CONSTIFY_PLUGIN
7788 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7789 +endif
7790
7791 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7792 GCOV_PROFILE := n
7793 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7794 index 90201aa..be1de62 100644
7795 --- a/arch/x86/boot/compressed/eboot.c
7796 +++ b/arch/x86/boot/compressed/eboot.c
7797 @@ -144,7 +144,6 @@ again:
7798 *addr = max_addr;
7799 }
7800
7801 -free_pool:
7802 efi_call_phys1(sys_table->boottime->free_pool, map);
7803
7804 fail:
7805 @@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7806 if (i == map_size / desc_size)
7807 status = EFI_NOT_FOUND;
7808
7809 -free_pool:
7810 efi_call_phys1(sys_table->boottime->free_pool, map);
7811 fail:
7812 return status;
7813 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7814 index aa4aaf1..6656f2f 100644
7815 --- a/arch/x86/boot/compressed/head_32.S
7816 +++ b/arch/x86/boot/compressed/head_32.S
7817 @@ -116,7 +116,7 @@ preferred_addr:
7818 notl %eax
7819 andl %eax, %ebx
7820 #else
7821 - movl $LOAD_PHYSICAL_ADDR, %ebx
7822 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7823 #endif
7824
7825 /* Target address to relocate to for decompression */
7826 @@ -202,7 +202,7 @@ relocated:
7827 * and where it was actually loaded.
7828 */
7829 movl %ebp, %ebx
7830 - subl $LOAD_PHYSICAL_ADDR, %ebx
7831 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7832 jz 2f /* Nothing to be done if loaded at compiled addr. */
7833 /*
7834 * Process relocations.
7835 @@ -210,8 +210,7 @@ relocated:
7836
7837 1: subl $4, %edi
7838 movl (%edi), %ecx
7839 - testl %ecx, %ecx
7840 - jz 2f
7841 + jecxz 2f
7842 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7843 jmp 1b
7844 2:
7845 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7846 index 2c4b171..e1fa5b1 100644
7847 --- a/arch/x86/boot/compressed/head_64.S
7848 +++ b/arch/x86/boot/compressed/head_64.S
7849 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7850 notl %eax
7851 andl %eax, %ebx
7852 #else
7853 - movl $LOAD_PHYSICAL_ADDR, %ebx
7854 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7855 #endif
7856
7857 /* Target address to relocate to for decompression */
7858 @@ -273,7 +273,7 @@ preferred_addr:
7859 notq %rax
7860 andq %rax, %rbp
7861 #else
7862 - movq $LOAD_PHYSICAL_ADDR, %rbp
7863 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7864 #endif
7865
7866 /* Target address to relocate to for decompression */
7867 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7868 index 88f7ff6..ed695dd 100644
7869 --- a/arch/x86/boot/compressed/misc.c
7870 +++ b/arch/x86/boot/compressed/misc.c
7871 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
7872 case PT_LOAD:
7873 #ifdef CONFIG_RELOCATABLE
7874 dest = output;
7875 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7876 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7877 #else
7878 dest = (void *)(phdr->p_paddr);
7879 #endif
7880 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7881 error("Destination address too large");
7882 #endif
7883 #ifndef CONFIG_RELOCATABLE
7884 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7885 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7886 error("Wrong destination address");
7887 #endif
7888
7889 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7890 index 4d3ff03..e4972ff 100644
7891 --- a/arch/x86/boot/cpucheck.c
7892 +++ b/arch/x86/boot/cpucheck.c
7893 @@ -74,7 +74,7 @@ static int has_fpu(void)
7894 u16 fcw = -1, fsw = -1;
7895 u32 cr0;
7896
7897 - asm("movl %%cr0,%0" : "=r" (cr0));
7898 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7899 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7900 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7901 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7902 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7903 {
7904 u32 f0, f1;
7905
7906 - asm("pushfl ; "
7907 + asm volatile("pushfl ; "
7908 "pushfl ; "
7909 "popl %0 ; "
7910 "movl %0,%1 ; "
7911 @@ -115,7 +115,7 @@ static void get_flags(void)
7912 set_bit(X86_FEATURE_FPU, cpu.flags);
7913
7914 if (has_eflag(X86_EFLAGS_ID)) {
7915 - asm("cpuid"
7916 + asm volatile("cpuid"
7917 : "=a" (max_intel_level),
7918 "=b" (cpu_vendor[0]),
7919 "=d" (cpu_vendor[1]),
7920 @@ -124,7 +124,7 @@ static void get_flags(void)
7921
7922 if (max_intel_level >= 0x00000001 &&
7923 max_intel_level <= 0x0000ffff) {
7924 - asm("cpuid"
7925 + asm volatile("cpuid"
7926 : "=a" (tfms),
7927 "=c" (cpu.flags[4]),
7928 "=d" (cpu.flags[0])
7929 @@ -136,7 +136,7 @@ static void get_flags(void)
7930 cpu.model += ((tfms >> 16) & 0xf) << 4;
7931 }
7932
7933 - asm("cpuid"
7934 + asm volatile("cpuid"
7935 : "=a" (max_amd_level)
7936 : "a" (0x80000000)
7937 : "ebx", "ecx", "edx");
7938 @@ -144,7 +144,7 @@ static void get_flags(void)
7939 if (max_amd_level >= 0x80000001 &&
7940 max_amd_level <= 0x8000ffff) {
7941 u32 eax = 0x80000001;
7942 - asm("cpuid"
7943 + asm volatile("cpuid"
7944 : "+a" (eax),
7945 "=c" (cpu.flags[6]),
7946 "=d" (cpu.flags[1])
7947 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7948 u32 ecx = MSR_K7_HWCR;
7949 u32 eax, edx;
7950
7951 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7952 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7953 eax &= ~(1 << 15);
7954 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7955 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7956
7957 get_flags(); /* Make sure it really did something */
7958 err = check_flags();
7959 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7960 u32 ecx = MSR_VIA_FCR;
7961 u32 eax, edx;
7962
7963 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7964 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7965 eax |= (1<<1)|(1<<7);
7966 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7967 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7968
7969 set_bit(X86_FEATURE_CX8, cpu.flags);
7970 err = check_flags();
7971 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7972 u32 eax, edx;
7973 u32 level = 1;
7974
7975 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7976 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7977 - asm("cpuid"
7978 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7979 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7980 + asm volatile("cpuid"
7981 : "+a" (level), "=d" (cpu.flags[0])
7982 : : "ecx", "ebx");
7983 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7984 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7985
7986 err = check_flags();
7987 }
7988 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7989 index b4e15dd..8ac59ce 100644
7990 --- a/arch/x86/boot/header.S
7991 +++ b/arch/x86/boot/header.S
7992 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7993 # single linked list of
7994 # struct setup_data
7995
7996 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7997 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7998
7999 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8000 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8001 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8002 +#else
8003 #define VO_INIT_SIZE (VO__end - VO__text)
8004 +#endif
8005 #if ZO_INIT_SIZE > VO_INIT_SIZE
8006 #define INIT_SIZE ZO_INIT_SIZE
8007 #else
8008 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8009 index db75d07..8e6d0af 100644
8010 --- a/arch/x86/boot/memory.c
8011 +++ b/arch/x86/boot/memory.c
8012 @@ -19,7 +19,7 @@
8013
8014 static int detect_memory_e820(void)
8015 {
8016 - int count = 0;
8017 + unsigned int count = 0;
8018 struct biosregs ireg, oreg;
8019 struct e820entry *desc = boot_params.e820_map;
8020 static struct e820entry buf; /* static so it is zeroed */
8021 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8022 index 11e8c6e..fdbb1ed 100644
8023 --- a/arch/x86/boot/video-vesa.c
8024 +++ b/arch/x86/boot/video-vesa.c
8025 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8026
8027 boot_params.screen_info.vesapm_seg = oreg.es;
8028 boot_params.screen_info.vesapm_off = oreg.di;
8029 + boot_params.screen_info.vesapm_size = oreg.cx;
8030 }
8031
8032 /*
8033 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8034 index 43eda28..5ab5fdb 100644
8035 --- a/arch/x86/boot/video.c
8036 +++ b/arch/x86/boot/video.c
8037 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8038 static unsigned int get_entry(void)
8039 {
8040 char entry_buf[4];
8041 - int i, len = 0;
8042 + unsigned int i, len = 0;
8043 int key;
8044 unsigned int v;
8045
8046 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8047 index 5b577d5..3c1fed4 100644
8048 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8049 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8050 @@ -8,6 +8,8 @@
8051 * including this sentence is retained in full.
8052 */
8053
8054 +#include <asm/alternative-asm.h>
8055 +
8056 .extern crypto_ft_tab
8057 .extern crypto_it_tab
8058 .extern crypto_fl_tab
8059 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8060 je B192; \
8061 leaq 32(r9),r9;
8062
8063 +#define ret pax_force_retaddr 0, 1; ret
8064 +
8065 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8066 movq r1,r2; \
8067 movq r3,r4; \
8068 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8069 index 3470624..201259d 100644
8070 --- a/arch/x86/crypto/aesni-intel_asm.S
8071 +++ b/arch/x86/crypto/aesni-intel_asm.S
8072 @@ -31,6 +31,7 @@
8073
8074 #include <linux/linkage.h>
8075 #include <asm/inst.h>
8076 +#include <asm/alternative-asm.h>
8077
8078 #ifdef __x86_64__
8079 .data
8080 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8081 pop %r14
8082 pop %r13
8083 pop %r12
8084 + pax_force_retaddr 0, 1
8085 ret
8086 +ENDPROC(aesni_gcm_dec)
8087
8088
8089 /*****************************************************************************
8090 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8091 pop %r14
8092 pop %r13
8093 pop %r12
8094 + pax_force_retaddr 0, 1
8095 ret
8096 +ENDPROC(aesni_gcm_enc)
8097
8098 #endif
8099
8100 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8101 pxor %xmm1, %xmm0
8102 movaps %xmm0, (TKEYP)
8103 add $0x10, TKEYP
8104 + pax_force_retaddr_bts
8105 ret
8106
8107 .align 4
8108 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8109 shufps $0b01001110, %xmm2, %xmm1
8110 movaps %xmm1, 0x10(TKEYP)
8111 add $0x20, TKEYP
8112 + pax_force_retaddr_bts
8113 ret
8114
8115 .align 4
8116 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8117
8118 movaps %xmm0, (TKEYP)
8119 add $0x10, TKEYP
8120 + pax_force_retaddr_bts
8121 ret
8122
8123 .align 4
8124 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8125 pxor %xmm1, %xmm2
8126 movaps %xmm2, (TKEYP)
8127 add $0x10, TKEYP
8128 + pax_force_retaddr_bts
8129 ret
8130
8131 /*
8132 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8133 #ifndef __x86_64__
8134 popl KEYP
8135 #endif
8136 + pax_force_retaddr 0, 1
8137 ret
8138 +ENDPROC(aesni_set_key)
8139
8140 /*
8141 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8142 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8143 popl KLEN
8144 popl KEYP
8145 #endif
8146 + pax_force_retaddr 0, 1
8147 ret
8148 +ENDPROC(aesni_enc)
8149
8150 /*
8151 * _aesni_enc1: internal ABI
8152 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8153 AESENC KEY STATE
8154 movaps 0x70(TKEYP), KEY
8155 AESENCLAST KEY STATE
8156 + pax_force_retaddr_bts
8157 ret
8158
8159 /*
8160 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8161 AESENCLAST KEY STATE2
8162 AESENCLAST KEY STATE3
8163 AESENCLAST KEY STATE4
8164 + pax_force_retaddr_bts
8165 ret
8166
8167 /*
8168 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8169 popl KLEN
8170 popl KEYP
8171 #endif
8172 + pax_force_retaddr 0, 1
8173 ret
8174 +ENDPROC(aesni_dec)
8175
8176 /*
8177 * _aesni_dec1: internal ABI
8178 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8179 AESDEC KEY STATE
8180 movaps 0x70(TKEYP), KEY
8181 AESDECLAST KEY STATE
8182 + pax_force_retaddr_bts
8183 ret
8184
8185 /*
8186 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8187 AESDECLAST KEY STATE2
8188 AESDECLAST KEY STATE3
8189 AESDECLAST KEY STATE4
8190 + pax_force_retaddr_bts
8191 ret
8192
8193 /*
8194 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8195 popl KEYP
8196 popl LEN
8197 #endif
8198 + pax_force_retaddr 0, 1
8199 ret
8200 +ENDPROC(aesni_ecb_enc)
8201
8202 /*
8203 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8204 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8205 popl KEYP
8206 popl LEN
8207 #endif
8208 + pax_force_retaddr 0, 1
8209 ret
8210 +ENDPROC(aesni_ecb_dec)
8211
8212 /*
8213 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8214 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8215 popl LEN
8216 popl IVP
8217 #endif
8218 + pax_force_retaddr 0, 1
8219 ret
8220 +ENDPROC(aesni_cbc_enc)
8221
8222 /*
8223 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8224 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8225 popl LEN
8226 popl IVP
8227 #endif
8228 + pax_force_retaddr 0, 1
8229 ret
8230 +ENDPROC(aesni_cbc_dec)
8231
8232 #ifdef __x86_64__
8233 .align 16
8234 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8235 mov $1, TCTR_LOW
8236 MOVQ_R64_XMM TCTR_LOW INC
8237 MOVQ_R64_XMM CTR TCTR_LOW
8238 + pax_force_retaddr_bts
8239 ret
8240
8241 /*
8242 @@ -2554,6 +2582,7 @@ _aesni_inc:
8243 .Linc_low:
8244 movaps CTR, IV
8245 PSHUFB_XMM BSWAP_MASK IV
8246 + pax_force_retaddr_bts
8247 ret
8248
8249 /*
8250 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8251 .Lctr_enc_ret:
8252 movups IV, (IVP)
8253 .Lctr_enc_just_ret:
8254 + pax_force_retaddr 0, 1
8255 ret
8256 +ENDPROC(aesni_ctr_enc)
8257 #endif
8258 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8259 index 391d245..67f35c2 100644
8260 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8261 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8262 @@ -20,6 +20,8 @@
8263 *
8264 */
8265
8266 +#include <asm/alternative-asm.h>
8267 +
8268 .file "blowfish-x86_64-asm.S"
8269 .text
8270
8271 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8272 jnz __enc_xor;
8273
8274 write_block();
8275 + pax_force_retaddr 0, 1
8276 ret;
8277 __enc_xor:
8278 xor_block();
8279 + pax_force_retaddr 0, 1
8280 ret;
8281
8282 .align 8
8283 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8284
8285 movq %r11, %rbp;
8286
8287 + pax_force_retaddr 0, 1
8288 ret;
8289
8290 /**********************************************************************
8291 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8292
8293 popq %rbx;
8294 popq %rbp;
8295 + pax_force_retaddr 0, 1
8296 ret;
8297
8298 __enc_xor4:
8299 @@ -349,6 +355,7 @@ __enc_xor4:
8300
8301 popq %rbx;
8302 popq %rbp;
8303 + pax_force_retaddr 0, 1
8304 ret;
8305
8306 .align 8
8307 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8308 popq %rbx;
8309 popq %rbp;
8310
8311 + pax_force_retaddr 0, 1
8312 ret;
8313
8314 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8315 index 0b33743..7a56206 100644
8316 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8317 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8318 @@ -20,6 +20,8 @@
8319 *
8320 */
8321
8322 +#include <asm/alternative-asm.h>
8323 +
8324 .file "camellia-x86_64-asm_64.S"
8325 .text
8326
8327 @@ -229,12 +231,14 @@ __enc_done:
8328 enc_outunpack(mov, RT1);
8329
8330 movq RRBP, %rbp;
8331 + pax_force_retaddr 0, 1
8332 ret;
8333
8334 __enc_xor:
8335 enc_outunpack(xor, RT1);
8336
8337 movq RRBP, %rbp;
8338 + pax_force_retaddr 0, 1
8339 ret;
8340
8341 .global camellia_dec_blk;
8342 @@ -275,6 +279,7 @@ __dec_rounds16:
8343 dec_outunpack();
8344
8345 movq RRBP, %rbp;
8346 + pax_force_retaddr 0, 1
8347 ret;
8348
8349 /**********************************************************************
8350 @@ -468,6 +473,7 @@ __enc2_done:
8351
8352 movq RRBP, %rbp;
8353 popq %rbx;
8354 + pax_force_retaddr 0, 1
8355 ret;
8356
8357 __enc2_xor:
8358 @@ -475,6 +481,7 @@ __enc2_xor:
8359
8360 movq RRBP, %rbp;
8361 popq %rbx;
8362 + pax_force_retaddr 0, 1
8363 ret;
8364
8365 .global camellia_dec_blk_2way;
8366 @@ -517,4 +524,5 @@ __dec2_rounds16:
8367
8368 movq RRBP, %rbp;
8369 movq RXOR, %rbx;
8370 + pax_force_retaddr 0, 1
8371 ret;
8372 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8373 index 6214a9b..1f4fc9a 100644
8374 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8375 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8376 @@ -1,3 +1,5 @@
8377 +#include <asm/alternative-asm.h>
8378 +
8379 # enter ECRYPT_encrypt_bytes
8380 .text
8381 .p2align 5
8382 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8383 add %r11,%rsp
8384 mov %rdi,%rax
8385 mov %rsi,%rdx
8386 + pax_force_retaddr 0, 1
8387 ret
8388 # bytesatleast65:
8389 ._bytesatleast65:
8390 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8391 add %r11,%rsp
8392 mov %rdi,%rax
8393 mov %rsi,%rdx
8394 + pax_force_retaddr
8395 ret
8396 # enter ECRYPT_ivsetup
8397 .text
8398 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8399 add %r11,%rsp
8400 mov %rdi,%rax
8401 mov %rsi,%rdx
8402 + pax_force_retaddr
8403 ret
8404 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8405 index 504106b..4e50951 100644
8406 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8407 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8408 @@ -24,6 +24,8 @@
8409 *
8410 */
8411
8412 +#include <asm/alternative-asm.h>
8413 +
8414 .file "serpent-avx-x86_64-asm_64.S"
8415 .text
8416
8417 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8418 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8419 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8420
8421 + pax_force_retaddr
8422 ret;
8423
8424 __enc_xor8:
8425 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8426 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8427
8428 + pax_force_retaddr
8429 ret;
8430
8431 .align 8
8432 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8433 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8434 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8435
8436 + pax_force_retaddr
8437 ret;
8438 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8439 index 3ee1ff0..cbc568b 100644
8440 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8441 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8442 @@ -24,6 +24,8 @@
8443 *
8444 */
8445
8446 +#include <asm/alternative-asm.h>
8447 +
8448 .file "serpent-sse2-x86_64-asm_64.S"
8449 .text
8450
8451 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8452 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8453 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8454
8455 + pax_force_retaddr
8456 ret;
8457
8458 __enc_xor8:
8459 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8460 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8461
8462 + pax_force_retaddr
8463 ret;
8464
8465 .align 8
8466 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8467 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8468 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8469
8470 + pax_force_retaddr
8471 ret;
8472 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8473 index 49d6987..df66bd4 100644
8474 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8475 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8476 @@ -28,6 +28,8 @@
8477 * (at your option) any later version.
8478 */
8479
8480 +#include <asm/alternative-asm.h>
8481 +
8482 #define CTX %rdi // arg1
8483 #define BUF %rsi // arg2
8484 #define CNT %rdx // arg3
8485 @@ -104,6 +106,7 @@
8486 pop %r12
8487 pop %rbp
8488 pop %rbx
8489 + pax_force_retaddr 0, 1
8490 ret
8491
8492 .size \name, .-\name
8493 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8494 index 35f4557..16b379f 100644
8495 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8496 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8497 @@ -21,6 +21,8 @@
8498 *
8499 */
8500
8501 +#include <asm/alternative-asm.h>
8502 +
8503 .file "twofish-avx-x86_64-asm_64.S"
8504 .text
8505
8506 @@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8507 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8508 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8509
8510 + pax_force_retaddr
8511 ret;
8512
8513 __enc_xor8:
8514 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8515 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8516
8517 + pax_force_retaddr
8518 ret;
8519
8520 .align 8
8521 @@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8522 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8523 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8524
8525 + pax_force_retaddr
8526 ret;
8527 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8528 index 5b012a2..36d5364 100644
8529 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8530 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8531 @@ -20,6 +20,8 @@
8532 *
8533 */
8534
8535 +#include <asm/alternative-asm.h>
8536 +
8537 .file "twofish-x86_64-asm-3way.S"
8538 .text
8539
8540 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8541 popq %r13;
8542 popq %r14;
8543 popq %r15;
8544 + pax_force_retaddr 0, 1
8545 ret;
8546
8547 __enc_xor3:
8548 @@ -271,6 +274,7 @@ __enc_xor3:
8549 popq %r13;
8550 popq %r14;
8551 popq %r15;
8552 + pax_force_retaddr 0, 1
8553 ret;
8554
8555 .global twofish_dec_blk_3way
8556 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8557 popq %r13;
8558 popq %r14;
8559 popq %r15;
8560 + pax_force_retaddr 0, 1
8561 ret;
8562
8563 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8564 index 7bcf3fc..f53832f 100644
8565 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8566 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8567 @@ -21,6 +21,7 @@
8568 .text
8569
8570 #include <asm/asm-offsets.h>
8571 +#include <asm/alternative-asm.h>
8572
8573 #define a_offset 0
8574 #define b_offset 4
8575 @@ -268,6 +269,7 @@ twofish_enc_blk:
8576
8577 popq R1
8578 movq $1,%rax
8579 + pax_force_retaddr 0, 1
8580 ret
8581
8582 twofish_dec_blk:
8583 @@ -319,4 +321,5 @@ twofish_dec_blk:
8584
8585 popq R1
8586 movq $1,%rax
8587 + pax_force_retaddr 0, 1
8588 ret
8589 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8590 index 07b3a68..bd2a388 100644
8591 --- a/arch/x86/ia32/ia32_aout.c
8592 +++ b/arch/x86/ia32/ia32_aout.c
8593 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8594 unsigned long dump_start, dump_size;
8595 struct user32 dump;
8596
8597 + memset(&dump, 0, sizeof(dump));
8598 +
8599 fs = get_fs();
8600 set_fs(KERNEL_DS);
8601 has_dumped = 1;
8602 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8603 index 673ac9b..7a8c5df 100644
8604 --- a/arch/x86/ia32/ia32_signal.c
8605 +++ b/arch/x86/ia32/ia32_signal.c
8606 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8607 }
8608 seg = get_fs();
8609 set_fs(KERNEL_DS);
8610 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8611 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8612 set_fs(seg);
8613 if (ret >= 0 && uoss_ptr) {
8614 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8615 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8616 */
8617 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8618 size_t frame_size,
8619 - void **fpstate)
8620 + void __user **fpstate)
8621 {
8622 unsigned long sp;
8623
8624 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8625
8626 if (used_math()) {
8627 sp = sp - sig_xstate_ia32_size;
8628 - *fpstate = (struct _fpstate_ia32 *) sp;
8629 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8630 if (save_i387_xstate_ia32(*fpstate) < 0)
8631 return (void __user *) -1L;
8632 }
8633 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8634 sp -= frame_size;
8635 /* Align the stack pointer according to the i386 ABI,
8636 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8637 - sp = ((sp + 4) & -16ul) - 4;
8638 + sp = ((sp - 12) & -16ul) - 4;
8639 return (void __user *) sp;
8640 }
8641
8642 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8643 * These are actually not used anymore, but left because some
8644 * gdb versions depend on them as a marker.
8645 */
8646 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8647 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8648 } put_user_catch(err);
8649
8650 if (err)
8651 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8652 0xb8,
8653 __NR_ia32_rt_sigreturn,
8654 0x80cd,
8655 - 0,
8656 + 0
8657 };
8658
8659 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8660 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8661
8662 if (ka->sa.sa_flags & SA_RESTORER)
8663 restorer = ka->sa.sa_restorer;
8664 + else if (current->mm->context.vdso)
8665 + /* Return stub is in 32bit vsyscall page */
8666 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8667 else
8668 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8669 - rt_sigreturn);
8670 + restorer = &frame->retcode;
8671 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8672
8673 /*
8674 * Not actually used anymore, but left because some gdb
8675 * versions need it.
8676 */
8677 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8678 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8679 } put_user_catch(err);
8680
8681 if (err)
8682 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8683 index 20e5f7b..f33c779 100644
8684 --- a/arch/x86/ia32/ia32entry.S
8685 +++ b/arch/x86/ia32/ia32entry.S
8686 @@ -14,8 +14,10 @@
8687 #include <asm/segment.h>
8688 #include <asm/irqflags.h>
8689 #include <asm/asm.h>
8690 +#include <asm/pgtable.h>
8691 #include <linux/linkage.h>
8692 #include <linux/err.h>
8693 +#include <asm/alternative-asm.h>
8694
8695 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8696 #include <linux/elf-em.h>
8697 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8698 ENDPROC(native_irq_enable_sysexit)
8699 #endif
8700
8701 + .macro pax_enter_kernel_user
8702 + pax_set_fptr_mask
8703 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8704 + call pax_enter_kernel_user
8705 +#endif
8706 + .endm
8707 +
8708 + .macro pax_exit_kernel_user
8709 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8710 + call pax_exit_kernel_user
8711 +#endif
8712 +#ifdef CONFIG_PAX_RANDKSTACK
8713 + pushq %rax
8714 + pushq %r11
8715 + call pax_randomize_kstack
8716 + popq %r11
8717 + popq %rax
8718 +#endif
8719 + .endm
8720 +
8721 +.macro pax_erase_kstack
8722 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8723 + call pax_erase_kstack
8724 +#endif
8725 +.endm
8726 +
8727 /*
8728 * 32bit SYSENTER instruction entry.
8729 *
8730 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8731 CFI_REGISTER rsp,rbp
8732 SWAPGS_UNSAFE_STACK
8733 movq PER_CPU_VAR(kernel_stack), %rsp
8734 - addq $(KERNEL_STACK_OFFSET),%rsp
8735 - /*
8736 - * No need to follow this irqs on/off section: the syscall
8737 - * disabled irqs, here we enable it straight after entry:
8738 - */
8739 - ENABLE_INTERRUPTS(CLBR_NONE)
8740 movl %ebp,%ebp /* zero extension */
8741 pushq_cfi $__USER32_DS
8742 /*CFI_REL_OFFSET ss,0*/
8743 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8744 CFI_REL_OFFSET rsp,0
8745 pushfq_cfi
8746 /*CFI_REL_OFFSET rflags,0*/
8747 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8748 - CFI_REGISTER rip,r10
8749 + orl $X86_EFLAGS_IF,(%rsp)
8750 + GET_THREAD_INFO(%r11)
8751 + movl TI_sysenter_return(%r11), %r11d
8752 + CFI_REGISTER rip,r11
8753 pushq_cfi $__USER32_CS
8754 /*CFI_REL_OFFSET cs,0*/
8755 movl %eax, %eax
8756 - pushq_cfi %r10
8757 + pushq_cfi %r11
8758 CFI_REL_OFFSET rip,0
8759 pushq_cfi %rax
8760 cld
8761 SAVE_ARGS 0,1,0
8762 + pax_enter_kernel_user
8763 +
8764 +#ifdef CONFIG_PAX_RANDKSTACK
8765 + pax_erase_kstack
8766 +#endif
8767 +
8768 + /*
8769 + * No need to follow this irqs on/off section: the syscall
8770 + * disabled irqs, here we enable it straight after entry:
8771 + */
8772 + ENABLE_INTERRUPTS(CLBR_NONE)
8773 /* no need to do an access_ok check here because rbp has been
8774 32bit zero extended */
8775 +
8776 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8777 + mov $PAX_USER_SHADOW_BASE,%r11
8778 + add %r11,%rbp
8779 +#endif
8780 +
8781 1: movl (%rbp),%ebp
8782 _ASM_EXTABLE(1b,ia32_badarg)
8783 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8784 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8785 + GET_THREAD_INFO(%r11)
8786 + orl $TS_COMPAT,TI_status(%r11)
8787 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8788 CFI_REMEMBER_STATE
8789 jnz sysenter_tracesys
8790 cmpq $(IA32_NR_syscalls-1),%rax
8791 @@ -159,12 +201,15 @@ sysenter_do_call:
8792 sysenter_dispatch:
8793 call *ia32_sys_call_table(,%rax,8)
8794 movq %rax,RAX-ARGOFFSET(%rsp)
8795 + GET_THREAD_INFO(%r11)
8796 DISABLE_INTERRUPTS(CLBR_NONE)
8797 TRACE_IRQS_OFF
8798 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8799 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8800 jnz sysexit_audit
8801 sysexit_from_sys_call:
8802 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8803 + pax_exit_kernel_user
8804 + pax_erase_kstack
8805 + andl $~TS_COMPAT,TI_status(%r11)
8806 /* clear IF, that popfq doesn't enable interrupts early */
8807 andl $~0x200,EFLAGS-R11(%rsp)
8808 movl RIP-R11(%rsp),%edx /* User %eip */
8809 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8810 movl %eax,%esi /* 2nd arg: syscall number */
8811 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8812 call __audit_syscall_entry
8813 +
8814 + pax_erase_kstack
8815 +
8816 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8817 cmpq $(IA32_NR_syscalls-1),%rax
8818 ja ia32_badsys
8819 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8820 .endm
8821
8822 .macro auditsys_exit exit
8823 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8824 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8825 jnz ia32_ret_from_sys_call
8826 TRACE_IRQS_ON
8827 sti
8828 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8829 1: setbe %al /* 1 if error, 0 if not */
8830 movzbl %al,%edi /* zero-extend that into %edi */
8831 call __audit_syscall_exit
8832 + GET_THREAD_INFO(%r11)
8833 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8834 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8835 cli
8836 TRACE_IRQS_OFF
8837 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8838 + testl %edi,TI_flags(%r11)
8839 jz \exit
8840 CLEAR_RREGS -ARGOFFSET
8841 jmp int_with_check
8842 @@ -234,7 +283,7 @@ sysexit_audit:
8843
8844 sysenter_tracesys:
8845 #ifdef CONFIG_AUDITSYSCALL
8846 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8847 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8848 jz sysenter_auditsys
8849 #endif
8850 SAVE_REST
8851 @@ -246,6 +295,9 @@ sysenter_tracesys:
8852 RESTORE_REST
8853 cmpq $(IA32_NR_syscalls-1),%rax
8854 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8855 +
8856 + pax_erase_kstack
8857 +
8858 jmp sysenter_do_call
8859 CFI_ENDPROC
8860 ENDPROC(ia32_sysenter_target)
8861 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8862 ENTRY(ia32_cstar_target)
8863 CFI_STARTPROC32 simple
8864 CFI_SIGNAL_FRAME
8865 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8866 + CFI_DEF_CFA rsp,0
8867 CFI_REGISTER rip,rcx
8868 /*CFI_REGISTER rflags,r11*/
8869 SWAPGS_UNSAFE_STACK
8870 movl %esp,%r8d
8871 CFI_REGISTER rsp,r8
8872 movq PER_CPU_VAR(kernel_stack),%rsp
8873 + SAVE_ARGS 8*6,0,0
8874 + pax_enter_kernel_user
8875 +
8876 +#ifdef CONFIG_PAX_RANDKSTACK
8877 + pax_erase_kstack
8878 +#endif
8879 +
8880 /*
8881 * No need to follow this irqs on/off section: the syscall
8882 * disabled irqs and here we enable it straight after entry:
8883 */
8884 ENABLE_INTERRUPTS(CLBR_NONE)
8885 - SAVE_ARGS 8,0,0
8886 movl %eax,%eax /* zero extension */
8887 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8888 movq %rcx,RIP-ARGOFFSET(%rsp)
8889 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8890 /* no need to do an access_ok check here because r8 has been
8891 32bit zero extended */
8892 /* hardware stack frame is complete now */
8893 +
8894 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8895 + mov $PAX_USER_SHADOW_BASE,%r11
8896 + add %r11,%r8
8897 +#endif
8898 +
8899 1: movl (%r8),%r9d
8900 _ASM_EXTABLE(1b,ia32_badarg)
8901 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8902 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8903 + GET_THREAD_INFO(%r11)
8904 + orl $TS_COMPAT,TI_status(%r11)
8905 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8906 CFI_REMEMBER_STATE
8907 jnz cstar_tracesys
8908 cmpq $IA32_NR_syscalls-1,%rax
8909 @@ -314,12 +379,15 @@ cstar_do_call:
8910 cstar_dispatch:
8911 call *ia32_sys_call_table(,%rax,8)
8912 movq %rax,RAX-ARGOFFSET(%rsp)
8913 + GET_THREAD_INFO(%r11)
8914 DISABLE_INTERRUPTS(CLBR_NONE)
8915 TRACE_IRQS_OFF
8916 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8917 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8918 jnz sysretl_audit
8919 sysretl_from_sys_call:
8920 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8921 + pax_exit_kernel_user
8922 + pax_erase_kstack
8923 + andl $~TS_COMPAT,TI_status(%r11)
8924 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8925 movl RIP-ARGOFFSET(%rsp),%ecx
8926 CFI_REGISTER rip,rcx
8927 @@ -347,7 +415,7 @@ sysretl_audit:
8928
8929 cstar_tracesys:
8930 #ifdef CONFIG_AUDITSYSCALL
8931 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8932 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8933 jz cstar_auditsys
8934 #endif
8935 xchgl %r9d,%ebp
8936 @@ -361,6 +429,9 @@ cstar_tracesys:
8937 xchgl %ebp,%r9d
8938 cmpq $(IA32_NR_syscalls-1),%rax
8939 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8940 +
8941 + pax_erase_kstack
8942 +
8943 jmp cstar_do_call
8944 END(ia32_cstar_target)
8945
8946 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8947 CFI_REL_OFFSET rip,RIP-RIP
8948 PARAVIRT_ADJUST_EXCEPTION_FRAME
8949 SWAPGS
8950 - /*
8951 - * No need to follow this irqs on/off section: the syscall
8952 - * disabled irqs and here we enable it straight after entry:
8953 - */
8954 - ENABLE_INTERRUPTS(CLBR_NONE)
8955 movl %eax,%eax
8956 pushq_cfi %rax
8957 cld
8958 /* note the registers are not zero extended to the sf.
8959 this could be a problem. */
8960 SAVE_ARGS 0,1,0
8961 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8962 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8963 + pax_enter_kernel_user
8964 +
8965 +#ifdef CONFIG_PAX_RANDKSTACK
8966 + pax_erase_kstack
8967 +#endif
8968 +
8969 + /*
8970 + * No need to follow this irqs on/off section: the syscall
8971 + * disabled irqs and here we enable it straight after entry:
8972 + */
8973 + ENABLE_INTERRUPTS(CLBR_NONE)
8974 + GET_THREAD_INFO(%r11)
8975 + orl $TS_COMPAT,TI_status(%r11)
8976 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8977 jnz ia32_tracesys
8978 cmpq $(IA32_NR_syscalls-1),%rax
8979 ja ia32_badsys
8980 @@ -436,6 +514,9 @@ ia32_tracesys:
8981 RESTORE_REST
8982 cmpq $(IA32_NR_syscalls-1),%rax
8983 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8984 +
8985 + pax_erase_kstack
8986 +
8987 jmp ia32_do_call
8988 END(ia32_syscall)
8989
8990 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8991 index 4540bec..714d913 100644
8992 --- a/arch/x86/ia32/sys_ia32.c
8993 +++ b/arch/x86/ia32/sys_ia32.c
8994 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8995 */
8996 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8997 {
8998 - typeof(ubuf->st_uid) uid = 0;
8999 - typeof(ubuf->st_gid) gid = 0;
9000 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
9001 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
9002 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
9003 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
9004 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9005 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
9006 return ret;
9007 }
9008
9009 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
9010 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
9011 int options)
9012 {
9013 return compat_sys_wait4(pid, stat_addr, options, NULL);
9014 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9015 mm_segment_t old_fs = get_fs();
9016
9017 set_fs(KERNEL_DS);
9018 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9019 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9020 set_fs(old_fs);
9021 if (put_compat_timespec(&t, interval))
9022 return -EFAULT;
9023 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9024 mm_segment_t old_fs = get_fs();
9025
9026 set_fs(KERNEL_DS);
9027 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9028 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9029 set_fs(old_fs);
9030 if (!ret) {
9031 switch (_NSIG_WORDS) {
9032 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9033 if (copy_siginfo_from_user32(&info, uinfo))
9034 return -EFAULT;
9035 set_fs(KERNEL_DS);
9036 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9037 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9038 set_fs(old_fs);
9039 return ret;
9040 }
9041 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9042 return -EFAULT;
9043
9044 set_fs(KERNEL_DS);
9045 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9046 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9047 count);
9048 set_fs(old_fs);
9049
9050 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9051 index 952bd01..7692c6f 100644
9052 --- a/arch/x86/include/asm/alternative-asm.h
9053 +++ b/arch/x86/include/asm/alternative-asm.h
9054 @@ -15,6 +15,45 @@
9055 .endm
9056 #endif
9057
9058 +#ifdef KERNEXEC_PLUGIN
9059 + .macro pax_force_retaddr_bts rip=0
9060 + btsq $63,\rip(%rsp)
9061 + .endm
9062 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9063 + .macro pax_force_retaddr rip=0, reload=0
9064 + btsq $63,\rip(%rsp)
9065 + .endm
9066 + .macro pax_force_fptr ptr
9067 + btsq $63,\ptr
9068 + .endm
9069 + .macro pax_set_fptr_mask
9070 + .endm
9071 +#endif
9072 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9073 + .macro pax_force_retaddr rip=0, reload=0
9074 + .if \reload
9075 + pax_set_fptr_mask
9076 + .endif
9077 + orq %r10,\rip(%rsp)
9078 + .endm
9079 + .macro pax_force_fptr ptr
9080 + orq %r10,\ptr
9081 + .endm
9082 + .macro pax_set_fptr_mask
9083 + movabs $0x8000000000000000,%r10
9084 + .endm
9085 +#endif
9086 +#else
9087 + .macro pax_force_retaddr rip=0, reload=0
9088 + .endm
9089 + .macro pax_force_fptr ptr
9090 + .endm
9091 + .macro pax_force_retaddr_bts rip=0
9092 + .endm
9093 + .macro pax_set_fptr_mask
9094 + .endm
9095 +#endif
9096 +
9097 .macro altinstruction_entry orig alt feature orig_len alt_len
9098 .long \orig - .
9099 .long \alt - .
9100 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9101 index 7078068..f58bcda 100644
9102 --- a/arch/x86/include/asm/alternative.h
9103 +++ b/arch/x86/include/asm/alternative.h
9104 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9105 ".section .discard,\"aw\",@progbits\n" \
9106 DISCARD_ENTRY(1) \
9107 ".previous\n" \
9108 - ".section .altinstr_replacement, \"ax\"\n" \
9109 + ".section .altinstr_replacement, \"a\"\n" \
9110 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9111 ".previous"
9112
9113 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9114 DISCARD_ENTRY(1) \
9115 DISCARD_ENTRY(2) \
9116 ".previous\n" \
9117 - ".section .altinstr_replacement, \"ax\"\n" \
9118 + ".section .altinstr_replacement, \"a\"\n" \
9119 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9120 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9121 ".previous"
9122 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9123 index f342612..b3fe911 100644
9124 --- a/arch/x86/include/asm/apic.h
9125 +++ b/arch/x86/include/asm/apic.h
9126 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9127
9128 #ifdef CONFIG_X86_LOCAL_APIC
9129
9130 -extern unsigned int apic_verbosity;
9131 +extern int apic_verbosity;
9132 extern int local_apic_timer_c2_ok;
9133
9134 extern int disable_apic;
9135 @@ -391,7 +391,7 @@ struct apic {
9136 */
9137 int (*x86_32_numa_cpu_node)(int cpu);
9138 #endif
9139 -};
9140 +} __do_const;
9141
9142 /*
9143 * Pointer to the local APIC driver in use on this system (there's
9144 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9145 index 20370c6..a2eb9b0 100644
9146 --- a/arch/x86/include/asm/apm.h
9147 +++ b/arch/x86/include/asm/apm.h
9148 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9149 __asm__ __volatile__(APM_DO_ZERO_SEGS
9150 "pushl %%edi\n\t"
9151 "pushl %%ebp\n\t"
9152 - "lcall *%%cs:apm_bios_entry\n\t"
9153 + "lcall *%%ss:apm_bios_entry\n\t"
9154 "setc %%al\n\t"
9155 "popl %%ebp\n\t"
9156 "popl %%edi\n\t"
9157 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9158 __asm__ __volatile__(APM_DO_ZERO_SEGS
9159 "pushl %%edi\n\t"
9160 "pushl %%ebp\n\t"
9161 - "lcall *%%cs:apm_bios_entry\n\t"
9162 + "lcall *%%ss:apm_bios_entry\n\t"
9163 "setc %%bl\n\t"
9164 "popl %%ebp\n\t"
9165 "popl %%edi\n\t"
9166 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9167 index 58cb6d4..a4b806c 100644
9168 --- a/arch/x86/include/asm/atomic.h
9169 +++ b/arch/x86/include/asm/atomic.h
9170 @@ -22,7 +22,18 @@
9171 */
9172 static inline int atomic_read(const atomic_t *v)
9173 {
9174 - return (*(volatile int *)&(v)->counter);
9175 + return (*(volatile const int *)&(v)->counter);
9176 +}
9177 +
9178 +/**
9179 + * atomic_read_unchecked - read atomic variable
9180 + * @v: pointer of type atomic_unchecked_t
9181 + *
9182 + * Atomically reads the value of @v.
9183 + */
9184 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9185 +{
9186 + return (*(volatile const int *)&(v)->counter);
9187 }
9188
9189 /**
9190 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9191 }
9192
9193 /**
9194 + * atomic_set_unchecked - set atomic variable
9195 + * @v: pointer of type atomic_unchecked_t
9196 + * @i: required value
9197 + *
9198 + * Atomically sets the value of @v to @i.
9199 + */
9200 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9201 +{
9202 + v->counter = i;
9203 +}
9204 +
9205 +/**
9206 * atomic_add - add integer to atomic variable
9207 * @i: integer value to add
9208 * @v: pointer of type atomic_t
9209 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9210 */
9211 static inline void atomic_add(int i, atomic_t *v)
9212 {
9213 - asm volatile(LOCK_PREFIX "addl %1,%0"
9214 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9215 +
9216 +#ifdef CONFIG_PAX_REFCOUNT
9217 + "jno 0f\n"
9218 + LOCK_PREFIX "subl %1,%0\n"
9219 + "int $4\n0:\n"
9220 + _ASM_EXTABLE(0b, 0b)
9221 +#endif
9222 +
9223 + : "+m" (v->counter)
9224 + : "ir" (i));
9225 +}
9226 +
9227 +/**
9228 + * atomic_add_unchecked - add integer to atomic variable
9229 + * @i: integer value to add
9230 + * @v: pointer of type atomic_unchecked_t
9231 + *
9232 + * Atomically adds @i to @v.
9233 + */
9234 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9235 +{
9236 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9237 : "+m" (v->counter)
9238 : "ir" (i));
9239 }
9240 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9241 */
9242 static inline void atomic_sub(int i, atomic_t *v)
9243 {
9244 - asm volatile(LOCK_PREFIX "subl %1,%0"
9245 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9246 +
9247 +#ifdef CONFIG_PAX_REFCOUNT
9248 + "jno 0f\n"
9249 + LOCK_PREFIX "addl %1,%0\n"
9250 + "int $4\n0:\n"
9251 + _ASM_EXTABLE(0b, 0b)
9252 +#endif
9253 +
9254 + : "+m" (v->counter)
9255 + : "ir" (i));
9256 +}
9257 +
9258 +/**
9259 + * atomic_sub_unchecked - subtract integer from atomic variable
9260 + * @i: integer value to subtract
9261 + * @v: pointer of type atomic_unchecked_t
9262 + *
9263 + * Atomically subtracts @i from @v.
9264 + */
9265 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9266 +{
9267 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9268 : "+m" (v->counter)
9269 : "ir" (i));
9270 }
9271 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9272 {
9273 unsigned char c;
9274
9275 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9276 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9277 +
9278 +#ifdef CONFIG_PAX_REFCOUNT
9279 + "jno 0f\n"
9280 + LOCK_PREFIX "addl %2,%0\n"
9281 + "int $4\n0:\n"
9282 + _ASM_EXTABLE(0b, 0b)
9283 +#endif
9284 +
9285 + "sete %1\n"
9286 : "+m" (v->counter), "=qm" (c)
9287 : "ir" (i) : "memory");
9288 return c;
9289 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9290 */
9291 static inline void atomic_inc(atomic_t *v)
9292 {
9293 - asm volatile(LOCK_PREFIX "incl %0"
9294 + asm volatile(LOCK_PREFIX "incl %0\n"
9295 +
9296 +#ifdef CONFIG_PAX_REFCOUNT
9297 + "jno 0f\n"
9298 + LOCK_PREFIX "decl %0\n"
9299 + "int $4\n0:\n"
9300 + _ASM_EXTABLE(0b, 0b)
9301 +#endif
9302 +
9303 + : "+m" (v->counter));
9304 +}
9305 +
9306 +/**
9307 + * atomic_inc_unchecked - increment atomic variable
9308 + * @v: pointer of type atomic_unchecked_t
9309 + *
9310 + * Atomically increments @v by 1.
9311 + */
9312 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9313 +{
9314 + asm volatile(LOCK_PREFIX "incl %0\n"
9315 : "+m" (v->counter));
9316 }
9317
9318 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9319 */
9320 static inline void atomic_dec(atomic_t *v)
9321 {
9322 - asm volatile(LOCK_PREFIX "decl %0"
9323 + asm volatile(LOCK_PREFIX "decl %0\n"
9324 +
9325 +#ifdef CONFIG_PAX_REFCOUNT
9326 + "jno 0f\n"
9327 + LOCK_PREFIX "incl %0\n"
9328 + "int $4\n0:\n"
9329 + _ASM_EXTABLE(0b, 0b)
9330 +#endif
9331 +
9332 + : "+m" (v->counter));
9333 +}
9334 +
9335 +/**
9336 + * atomic_dec_unchecked - decrement atomic variable
9337 + * @v: pointer of type atomic_unchecked_t
9338 + *
9339 + * Atomically decrements @v by 1.
9340 + */
9341 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9342 +{
9343 + asm volatile(LOCK_PREFIX "decl %0\n"
9344 : "+m" (v->counter));
9345 }
9346
9347 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9348 {
9349 unsigned char c;
9350
9351 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9352 + asm volatile(LOCK_PREFIX "decl %0\n"
9353 +
9354 +#ifdef CONFIG_PAX_REFCOUNT
9355 + "jno 0f\n"
9356 + LOCK_PREFIX "incl %0\n"
9357 + "int $4\n0:\n"
9358 + _ASM_EXTABLE(0b, 0b)
9359 +#endif
9360 +
9361 + "sete %1\n"
9362 : "+m" (v->counter), "=qm" (c)
9363 : : "memory");
9364 return c != 0;
9365 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9366 {
9367 unsigned char c;
9368
9369 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9370 + asm volatile(LOCK_PREFIX "incl %0\n"
9371 +
9372 +#ifdef CONFIG_PAX_REFCOUNT
9373 + "jno 0f\n"
9374 + LOCK_PREFIX "decl %0\n"
9375 + "int $4\n0:\n"
9376 + _ASM_EXTABLE(0b, 0b)
9377 +#endif
9378 +
9379 + "sete %1\n"
9380 + : "+m" (v->counter), "=qm" (c)
9381 + : : "memory");
9382 + return c != 0;
9383 +}
9384 +
9385 +/**
9386 + * atomic_inc_and_test_unchecked - increment and test
9387 + * @v: pointer of type atomic_unchecked_t
9388 + *
9389 + * Atomically increments @v by 1
9390 + * and returns true if the result is zero, or false for all
9391 + * other cases.
9392 + */
9393 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9394 +{
9395 + unsigned char c;
9396 +
9397 + asm volatile(LOCK_PREFIX "incl %0\n"
9398 + "sete %1\n"
9399 : "+m" (v->counter), "=qm" (c)
9400 : : "memory");
9401 return c != 0;
9402 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9403 {
9404 unsigned char c;
9405
9406 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9407 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9408 +
9409 +#ifdef CONFIG_PAX_REFCOUNT
9410 + "jno 0f\n"
9411 + LOCK_PREFIX "subl %2,%0\n"
9412 + "int $4\n0:\n"
9413 + _ASM_EXTABLE(0b, 0b)
9414 +#endif
9415 +
9416 + "sets %1\n"
9417 : "+m" (v->counter), "=qm" (c)
9418 : "ir" (i) : "memory");
9419 return c;
9420 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9421 goto no_xadd;
9422 #endif
9423 /* Modern 486+ processor */
9424 - return i + xadd(&v->counter, i);
9425 + return i + xadd_check_overflow(&v->counter, i);
9426
9427 #ifdef CONFIG_M386
9428 no_xadd: /* Legacy 386 processor */
9429 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9430 }
9431
9432 /**
9433 + * atomic_add_return_unchecked - add integer and return
9434 + * @i: integer value to add
9435 + * @v: pointer of type atomic_unchecked_t
9436 + *
9437 + * Atomically adds @i to @v and returns @i + @v
9438 + */
9439 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9440 +{
9441 +#ifdef CONFIG_M386
9442 + int __i;
9443 + unsigned long flags;
9444 + if (unlikely(boot_cpu_data.x86 <= 3))
9445 + goto no_xadd;
9446 +#endif
9447 + /* Modern 486+ processor */
9448 + return i + xadd(&v->counter, i);
9449 +
9450 +#ifdef CONFIG_M386
9451 +no_xadd: /* Legacy 386 processor */
9452 + raw_local_irq_save(flags);
9453 + __i = atomic_read_unchecked(v);
9454 + atomic_set_unchecked(v, i + __i);
9455 + raw_local_irq_restore(flags);
9456 + return i + __i;
9457 +#endif
9458 +}
9459 +
9460 +/**
9461 * atomic_sub_return - subtract integer and return
9462 * @v: pointer of type atomic_t
9463 * @i: integer value to subtract
9464 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9465 }
9466
9467 #define atomic_inc_return(v) (atomic_add_return(1, v))
9468 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9469 +{
9470 + return atomic_add_return_unchecked(1, v);
9471 +}
9472 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9473
9474 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9475 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9476 return cmpxchg(&v->counter, old, new);
9477 }
9478
9479 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9480 +{
9481 + return cmpxchg(&v->counter, old, new);
9482 +}
9483 +
9484 static inline int atomic_xchg(atomic_t *v, int new)
9485 {
9486 return xchg(&v->counter, new);
9487 }
9488
9489 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9490 +{
9491 + return xchg(&v->counter, new);
9492 +}
9493 +
9494 /**
9495 * __atomic_add_unless - add unless the number is already a given value
9496 * @v: pointer of type atomic_t
9497 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9498 */
9499 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9500 {
9501 - int c, old;
9502 + int c, old, new;
9503 c = atomic_read(v);
9504 for (;;) {
9505 - if (unlikely(c == (u)))
9506 + if (unlikely(c == u))
9507 break;
9508 - old = atomic_cmpxchg((v), c, c + (a));
9509 +
9510 + asm volatile("addl %2,%0\n"
9511 +
9512 +#ifdef CONFIG_PAX_REFCOUNT
9513 + "jno 0f\n"
9514 + "subl %2,%0\n"
9515 + "int $4\n0:\n"
9516 + _ASM_EXTABLE(0b, 0b)
9517 +#endif
9518 +
9519 + : "=r" (new)
9520 + : "0" (c), "ir" (a));
9521 +
9522 + old = atomic_cmpxchg(v, c, new);
9523 if (likely(old == c))
9524 break;
9525 c = old;
9526 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9527 return c;
9528 }
9529
9530 +/**
9531 + * atomic_inc_not_zero_hint - increment if not null
9532 + * @v: pointer of type atomic_t
9533 + * @hint: probable value of the atomic before the increment
9534 + *
9535 + * This version of atomic_inc_not_zero() gives a hint of probable
9536 + * value of the atomic. This helps processor to not read the memory
9537 + * before doing the atomic read/modify/write cycle, lowering
9538 + * number of bus transactions on some arches.
9539 + *
9540 + * Returns: 0 if increment was not done, 1 otherwise.
9541 + */
9542 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9543 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9544 +{
9545 + int val, c = hint, new;
9546 +
9547 + /* sanity test, should be removed by compiler if hint is a constant */
9548 + if (!hint)
9549 + return __atomic_add_unless(v, 1, 0);
9550 +
9551 + do {
9552 + asm volatile("incl %0\n"
9553 +
9554 +#ifdef CONFIG_PAX_REFCOUNT
9555 + "jno 0f\n"
9556 + "decl %0\n"
9557 + "int $4\n0:\n"
9558 + _ASM_EXTABLE(0b, 0b)
9559 +#endif
9560 +
9561 + : "=r" (new)
9562 + : "0" (c));
9563 +
9564 + val = atomic_cmpxchg(v, c, new);
9565 + if (val == c)
9566 + return 1;
9567 + c = val;
9568 + } while (c);
9569 +
9570 + return 0;
9571 +}
9572
9573 /*
9574 * atomic_dec_if_positive - decrement by 1 if old value positive
9575 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9576 #endif
9577
9578 /* These are x86-specific, used by some header files */
9579 -#define atomic_clear_mask(mask, addr) \
9580 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9581 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9582 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9583 +{
9584 + asm volatile(LOCK_PREFIX "andl %1,%0"
9585 + : "+m" (v->counter)
9586 + : "r" (~(mask))
9587 + : "memory");
9588 +}
9589
9590 -#define atomic_set_mask(mask, addr) \
9591 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9592 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9593 - : "memory")
9594 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9595 +{
9596 + asm volatile(LOCK_PREFIX "andl %1,%0"
9597 + : "+m" (v->counter)
9598 + : "r" (~(mask))
9599 + : "memory");
9600 +}
9601 +
9602 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9603 +{
9604 + asm volatile(LOCK_PREFIX "orl %1,%0"
9605 + : "+m" (v->counter)
9606 + : "r" (mask)
9607 + : "memory");
9608 +}
9609 +
9610 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9611 +{
9612 + asm volatile(LOCK_PREFIX "orl %1,%0"
9613 + : "+m" (v->counter)
9614 + : "r" (mask)
9615 + : "memory");
9616 +}
9617
9618 /* Atomic operations are already serializing on x86 */
9619 #define smp_mb__before_atomic_dec() barrier()
9620 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9621 index b154de7..aadebd8 100644
9622 --- a/arch/x86/include/asm/atomic64_32.h
9623 +++ b/arch/x86/include/asm/atomic64_32.h
9624 @@ -12,6 +12,14 @@ typedef struct {
9625 u64 __aligned(8) counter;
9626 } atomic64_t;
9627
9628 +#ifdef CONFIG_PAX_REFCOUNT
9629 +typedef struct {
9630 + u64 __aligned(8) counter;
9631 +} atomic64_unchecked_t;
9632 +#else
9633 +typedef atomic64_t atomic64_unchecked_t;
9634 +#endif
9635 +
9636 #define ATOMIC64_INIT(val) { (val) }
9637
9638 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9639 @@ -37,21 +45,31 @@ typedef struct {
9640 ATOMIC64_DECL_ONE(sym##_386)
9641
9642 ATOMIC64_DECL_ONE(add_386);
9643 +ATOMIC64_DECL_ONE(add_unchecked_386);
9644 ATOMIC64_DECL_ONE(sub_386);
9645 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9646 ATOMIC64_DECL_ONE(inc_386);
9647 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9648 ATOMIC64_DECL_ONE(dec_386);
9649 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9650 #endif
9651
9652 #define alternative_atomic64(f, out, in...) \
9653 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9654
9655 ATOMIC64_DECL(read);
9656 +ATOMIC64_DECL(read_unchecked);
9657 ATOMIC64_DECL(set);
9658 +ATOMIC64_DECL(set_unchecked);
9659 ATOMIC64_DECL(xchg);
9660 ATOMIC64_DECL(add_return);
9661 +ATOMIC64_DECL(add_return_unchecked);
9662 ATOMIC64_DECL(sub_return);
9663 +ATOMIC64_DECL(sub_return_unchecked);
9664 ATOMIC64_DECL(inc_return);
9665 +ATOMIC64_DECL(inc_return_unchecked);
9666 ATOMIC64_DECL(dec_return);
9667 +ATOMIC64_DECL(dec_return_unchecked);
9668 ATOMIC64_DECL(dec_if_positive);
9669 ATOMIC64_DECL(inc_not_zero);
9670 ATOMIC64_DECL(add_unless);
9671 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9672 }
9673
9674 /**
9675 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9676 + * @p: pointer to type atomic64_unchecked_t
9677 + * @o: expected value
9678 + * @n: new value
9679 + *
9680 + * Atomically sets @v to @n if it was equal to @o and returns
9681 + * the old value.
9682 + */
9683 +
9684 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9685 +{
9686 + return cmpxchg64(&v->counter, o, n);
9687 +}
9688 +
9689 +/**
9690 * atomic64_xchg - xchg atomic64 variable
9691 * @v: pointer to type atomic64_t
9692 * @n: value to assign
9693 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9694 }
9695
9696 /**
9697 + * atomic64_set_unchecked - set atomic64 variable
9698 + * @v: pointer to type atomic64_unchecked_t
9699 + * @n: value to assign
9700 + *
9701 + * Atomically sets the value of @v to @n.
9702 + */
9703 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9704 +{
9705 + unsigned high = (unsigned)(i >> 32);
9706 + unsigned low = (unsigned)i;
9707 + alternative_atomic64(set, /* no output */,
9708 + "S" (v), "b" (low), "c" (high)
9709 + : "eax", "edx", "memory");
9710 +}
9711 +
9712 +/**
9713 * atomic64_read - read atomic64 variable
9714 * @v: pointer to type atomic64_t
9715 *
9716 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9717 }
9718
9719 /**
9720 + * atomic64_read_unchecked - read atomic64 variable
9721 + * @v: pointer to type atomic64_unchecked_t
9722 + *
9723 + * Atomically reads the value of @v and returns it.
9724 + */
9725 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9726 +{
9727 + long long r;
9728 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9729 + return r;
9730 + }
9731 +
9732 +/**
9733 * atomic64_add_return - add and return
9734 * @i: integer value to add
9735 * @v: pointer to type atomic64_t
9736 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9737 return i;
9738 }
9739
9740 +/**
9741 + * atomic64_add_return_unchecked - add and return
9742 + * @i: integer value to add
9743 + * @v: pointer to type atomic64_unchecked_t
9744 + *
9745 + * Atomically adds @i to @v and returns @i + *@v
9746 + */
9747 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9748 +{
9749 + alternative_atomic64(add_return_unchecked,
9750 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9751 + ASM_NO_INPUT_CLOBBER("memory"));
9752 + return i;
9753 +}
9754 +
9755 /*
9756 * Other variants with different arithmetic operators:
9757 */
9758 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9759 return a;
9760 }
9761
9762 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9763 +{
9764 + long long a;
9765 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9766 + "S" (v) : "memory", "ecx");
9767 + return a;
9768 +}
9769 +
9770 static inline long long atomic64_dec_return(atomic64_t *v)
9771 {
9772 long long a;
9773 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9774 }
9775
9776 /**
9777 + * atomic64_add_unchecked - add integer to atomic64 variable
9778 + * @i: integer value to add
9779 + * @v: pointer to type atomic64_unchecked_t
9780 + *
9781 + * Atomically adds @i to @v.
9782 + */
9783 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9784 +{
9785 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9786 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9787 + ASM_NO_INPUT_CLOBBER("memory"));
9788 + return i;
9789 +}
9790 +
9791 +/**
9792 * atomic64_sub - subtract the atomic64 variable
9793 * @i: integer value to subtract
9794 * @v: pointer to type atomic64_t
9795 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9796 index 0e1cbfc..5623683 100644
9797 --- a/arch/x86/include/asm/atomic64_64.h
9798 +++ b/arch/x86/include/asm/atomic64_64.h
9799 @@ -18,7 +18,19 @@
9800 */
9801 static inline long atomic64_read(const atomic64_t *v)
9802 {
9803 - return (*(volatile long *)&(v)->counter);
9804 + return (*(volatile const long *)&(v)->counter);
9805 +}
9806 +
9807 +/**
9808 + * atomic64_read_unchecked - read atomic64 variable
9809 + * @v: pointer of type atomic64_unchecked_t
9810 + *
9811 + * Atomically reads the value of @v.
9812 + * Doesn't imply a read memory barrier.
9813 + */
9814 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9815 +{
9816 + return (*(volatile const long *)&(v)->counter);
9817 }
9818
9819 /**
9820 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9821 }
9822
9823 /**
9824 + * atomic64_set_unchecked - set atomic64 variable
9825 + * @v: pointer to type atomic64_unchecked_t
9826 + * @i: required value
9827 + *
9828 + * Atomically sets the value of @v to @i.
9829 + */
9830 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9831 +{
9832 + v->counter = i;
9833 +}
9834 +
9835 +/**
9836 * atomic64_add - add integer to atomic64 variable
9837 * @i: integer value to add
9838 * @v: pointer to type atomic64_t
9839 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9840 */
9841 static inline void atomic64_add(long i, atomic64_t *v)
9842 {
9843 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9844 +
9845 +#ifdef CONFIG_PAX_REFCOUNT
9846 + "jno 0f\n"
9847 + LOCK_PREFIX "subq %1,%0\n"
9848 + "int $4\n0:\n"
9849 + _ASM_EXTABLE(0b, 0b)
9850 +#endif
9851 +
9852 + : "=m" (v->counter)
9853 + : "er" (i), "m" (v->counter));
9854 +}
9855 +
9856 +/**
9857 + * atomic64_add_unchecked - add integer to atomic64 variable
9858 + * @i: integer value to add
9859 + * @v: pointer to type atomic64_unchecked_t
9860 + *
9861 + * Atomically adds @i to @v.
9862 + */
9863 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9864 +{
9865 asm volatile(LOCK_PREFIX "addq %1,%0"
9866 : "=m" (v->counter)
9867 : "er" (i), "m" (v->counter));
9868 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9869 */
9870 static inline void atomic64_sub(long i, atomic64_t *v)
9871 {
9872 - asm volatile(LOCK_PREFIX "subq %1,%0"
9873 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9874 +
9875 +#ifdef CONFIG_PAX_REFCOUNT
9876 + "jno 0f\n"
9877 + LOCK_PREFIX "addq %1,%0\n"
9878 + "int $4\n0:\n"
9879 + _ASM_EXTABLE(0b, 0b)
9880 +#endif
9881 +
9882 + : "=m" (v->counter)
9883 + : "er" (i), "m" (v->counter));
9884 +}
9885 +
9886 +/**
9887 + * atomic64_sub_unchecked - subtract the atomic64 variable
9888 + * @i: integer value to subtract
9889 + * @v: pointer to type atomic64_unchecked_t
9890 + *
9891 + * Atomically subtracts @i from @v.
9892 + */
9893 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9894 +{
9895 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9896 : "=m" (v->counter)
9897 : "er" (i), "m" (v->counter));
9898 }
9899 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9900 {
9901 unsigned char c;
9902
9903 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9904 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9905 +
9906 +#ifdef CONFIG_PAX_REFCOUNT
9907 + "jno 0f\n"
9908 + LOCK_PREFIX "addq %2,%0\n"
9909 + "int $4\n0:\n"
9910 + _ASM_EXTABLE(0b, 0b)
9911 +#endif
9912 +
9913 + "sete %1\n"
9914 : "=m" (v->counter), "=qm" (c)
9915 : "er" (i), "m" (v->counter) : "memory");
9916 return c;
9917 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9918 */
9919 static inline void atomic64_inc(atomic64_t *v)
9920 {
9921 + asm volatile(LOCK_PREFIX "incq %0\n"
9922 +
9923 +#ifdef CONFIG_PAX_REFCOUNT
9924 + "jno 0f\n"
9925 + LOCK_PREFIX "decq %0\n"
9926 + "int $4\n0:\n"
9927 + _ASM_EXTABLE(0b, 0b)
9928 +#endif
9929 +
9930 + : "=m" (v->counter)
9931 + : "m" (v->counter));
9932 +}
9933 +
9934 +/**
9935 + * atomic64_inc_unchecked - increment atomic64 variable
9936 + * @v: pointer to type atomic64_unchecked_t
9937 + *
9938 + * Atomically increments @v by 1.
9939 + */
9940 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9941 +{
9942 asm volatile(LOCK_PREFIX "incq %0"
9943 : "=m" (v->counter)
9944 : "m" (v->counter));
9945 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9946 */
9947 static inline void atomic64_dec(atomic64_t *v)
9948 {
9949 - asm volatile(LOCK_PREFIX "decq %0"
9950 + asm volatile(LOCK_PREFIX "decq %0\n"
9951 +
9952 +#ifdef CONFIG_PAX_REFCOUNT
9953 + "jno 0f\n"
9954 + LOCK_PREFIX "incq %0\n"
9955 + "int $4\n0:\n"
9956 + _ASM_EXTABLE(0b, 0b)
9957 +#endif
9958 +
9959 + : "=m" (v->counter)
9960 + : "m" (v->counter));
9961 +}
9962 +
9963 +/**
9964 + * atomic64_dec_unchecked - decrement atomic64 variable
9965 + * @v: pointer to type atomic64_t
9966 + *
9967 + * Atomically decrements @v by 1.
9968 + */
9969 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9970 +{
9971 + asm volatile(LOCK_PREFIX "decq %0\n"
9972 : "=m" (v->counter)
9973 : "m" (v->counter));
9974 }
9975 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9976 {
9977 unsigned char c;
9978
9979 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9980 + asm volatile(LOCK_PREFIX "decq %0\n"
9981 +
9982 +#ifdef CONFIG_PAX_REFCOUNT
9983 + "jno 0f\n"
9984 + LOCK_PREFIX "incq %0\n"
9985 + "int $4\n0:\n"
9986 + _ASM_EXTABLE(0b, 0b)
9987 +#endif
9988 +
9989 + "sete %1\n"
9990 : "=m" (v->counter), "=qm" (c)
9991 : "m" (v->counter) : "memory");
9992 return c != 0;
9993 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9994 {
9995 unsigned char c;
9996
9997 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9998 + asm volatile(LOCK_PREFIX "incq %0\n"
9999 +
10000 +#ifdef CONFIG_PAX_REFCOUNT
10001 + "jno 0f\n"
10002 + LOCK_PREFIX "decq %0\n"
10003 + "int $4\n0:\n"
10004 + _ASM_EXTABLE(0b, 0b)
10005 +#endif
10006 +
10007 + "sete %1\n"
10008 : "=m" (v->counter), "=qm" (c)
10009 : "m" (v->counter) : "memory");
10010 return c != 0;
10011 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10012 {
10013 unsigned char c;
10014
10015 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10016 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
10017 +
10018 +#ifdef CONFIG_PAX_REFCOUNT
10019 + "jno 0f\n"
10020 + LOCK_PREFIX "subq %2,%0\n"
10021 + "int $4\n0:\n"
10022 + _ASM_EXTABLE(0b, 0b)
10023 +#endif
10024 +
10025 + "sets %1\n"
10026 : "=m" (v->counter), "=qm" (c)
10027 : "er" (i), "m" (v->counter) : "memory");
10028 return c;
10029 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10030 */
10031 static inline long atomic64_add_return(long i, atomic64_t *v)
10032 {
10033 + return i + xadd_check_overflow(&v->counter, i);
10034 +}
10035 +
10036 +/**
10037 + * atomic64_add_return_unchecked - add and return
10038 + * @i: integer value to add
10039 + * @v: pointer to type atomic64_unchecked_t
10040 + *
10041 + * Atomically adds @i to @v and returns @i + @v
10042 + */
10043 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10044 +{
10045 return i + xadd(&v->counter, i);
10046 }
10047
10048 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10049 }
10050
10051 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10052 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10053 +{
10054 + return atomic64_add_return_unchecked(1, v);
10055 +}
10056 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10057
10058 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10059 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10060 return cmpxchg(&v->counter, old, new);
10061 }
10062
10063 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10064 +{
10065 + return cmpxchg(&v->counter, old, new);
10066 +}
10067 +
10068 static inline long atomic64_xchg(atomic64_t *v, long new)
10069 {
10070 return xchg(&v->counter, new);
10071 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10072 */
10073 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10074 {
10075 - long c, old;
10076 + long c, old, new;
10077 c = atomic64_read(v);
10078 for (;;) {
10079 - if (unlikely(c == (u)))
10080 + if (unlikely(c == u))
10081 break;
10082 - old = atomic64_cmpxchg((v), c, c + (a));
10083 +
10084 + asm volatile("add %2,%0\n"
10085 +
10086 +#ifdef CONFIG_PAX_REFCOUNT
10087 + "jno 0f\n"
10088 + "sub %2,%0\n"
10089 + "int $4\n0:\n"
10090 + _ASM_EXTABLE(0b, 0b)
10091 +#endif
10092 +
10093 + : "=r" (new)
10094 + : "0" (c), "ir" (a));
10095 +
10096 + old = atomic64_cmpxchg(v, c, new);
10097 if (likely(old == c))
10098 break;
10099 c = old;
10100 }
10101 - return c != (u);
10102 + return c != u;
10103 }
10104
10105 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10106 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10107 index 72f5009..2f8b9a9 100644
10108 --- a/arch/x86/include/asm/bitops.h
10109 +++ b/arch/x86/include/asm/bitops.h
10110 @@ -40,7 +40,7 @@
10111 * a mask operation on a byte.
10112 */
10113 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10114 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10115 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10116 #define CONST_MASK(nr) (1 << ((nr) & 7))
10117
10118 /**
10119 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10120 index b13fe63..0dab13a 100644
10121 --- a/arch/x86/include/asm/boot.h
10122 +++ b/arch/x86/include/asm/boot.h
10123 @@ -11,10 +11,15 @@
10124 #include <asm/pgtable_types.h>
10125
10126 /* Physical address where kernel should be loaded. */
10127 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10128 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10129 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10130 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10131
10132 +#ifndef __ASSEMBLY__
10133 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10134 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10135 +#endif
10136 +
10137 /* Minimum kernel alignment, as a power of two */
10138 #ifdef CONFIG_X86_64
10139 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10140 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10141 index 48f99f1..d78ebf9 100644
10142 --- a/arch/x86/include/asm/cache.h
10143 +++ b/arch/x86/include/asm/cache.h
10144 @@ -5,12 +5,13 @@
10145
10146 /* L1 cache line size */
10147 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10148 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10149 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10150
10151 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10152 +#define __read_only __attribute__((__section__(".data..read_only")))
10153
10154 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10155 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10156 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10157
10158 #ifdef CONFIG_X86_VSMP
10159 #ifdef CONFIG_SMP
10160 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10161 index 9863ee3..4a1f8e1 100644
10162 --- a/arch/x86/include/asm/cacheflush.h
10163 +++ b/arch/x86/include/asm/cacheflush.h
10164 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10165 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10166
10167 if (pg_flags == _PGMT_DEFAULT)
10168 - return -1;
10169 + return ~0UL;
10170 else if (pg_flags == _PGMT_WC)
10171 return _PAGE_CACHE_WC;
10172 else if (pg_flags == _PGMT_UC_MINUS)
10173 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10174 index 46fc474..b02b0f9 100644
10175 --- a/arch/x86/include/asm/checksum_32.h
10176 +++ b/arch/x86/include/asm/checksum_32.h
10177 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10178 int len, __wsum sum,
10179 int *src_err_ptr, int *dst_err_ptr);
10180
10181 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10182 + int len, __wsum sum,
10183 + int *src_err_ptr, int *dst_err_ptr);
10184 +
10185 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10186 + int len, __wsum sum,
10187 + int *src_err_ptr, int *dst_err_ptr);
10188 +
10189 /*
10190 * Note: when you get a NULL pointer exception here this means someone
10191 * passed in an incorrect kernel address to one of these functions.
10192 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10193 int *err_ptr)
10194 {
10195 might_sleep();
10196 - return csum_partial_copy_generic((__force void *)src, dst,
10197 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10198 len, sum, err_ptr, NULL);
10199 }
10200
10201 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10202 {
10203 might_sleep();
10204 if (access_ok(VERIFY_WRITE, dst, len))
10205 - return csum_partial_copy_generic(src, (__force void *)dst,
10206 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10207 len, sum, NULL, err_ptr);
10208
10209 if (len)
10210 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10211 index 99480e5..d81165b 100644
10212 --- a/arch/x86/include/asm/cmpxchg.h
10213 +++ b/arch/x86/include/asm/cmpxchg.h
10214 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10215 __compiletime_error("Bad argument size for cmpxchg");
10216 extern void __xadd_wrong_size(void)
10217 __compiletime_error("Bad argument size for xadd");
10218 +extern void __xadd_check_overflow_wrong_size(void)
10219 + __compiletime_error("Bad argument size for xadd_check_overflow");
10220 extern void __add_wrong_size(void)
10221 __compiletime_error("Bad argument size for add");
10222 +extern void __add_check_overflow_wrong_size(void)
10223 + __compiletime_error("Bad argument size for add_check_overflow");
10224
10225 /*
10226 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10227 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10228 __ret; \
10229 })
10230
10231 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10232 + ({ \
10233 + __typeof__ (*(ptr)) __ret = (arg); \
10234 + switch (sizeof(*(ptr))) { \
10235 + case __X86_CASE_L: \
10236 + asm volatile (lock #op "l %0, %1\n" \
10237 + "jno 0f\n" \
10238 + "mov %0,%1\n" \
10239 + "int $4\n0:\n" \
10240 + _ASM_EXTABLE(0b, 0b) \
10241 + : "+r" (__ret), "+m" (*(ptr)) \
10242 + : : "memory", "cc"); \
10243 + break; \
10244 + case __X86_CASE_Q: \
10245 + asm volatile (lock #op "q %q0, %1\n" \
10246 + "jno 0f\n" \
10247 + "mov %0,%1\n" \
10248 + "int $4\n0:\n" \
10249 + _ASM_EXTABLE(0b, 0b) \
10250 + : "+r" (__ret), "+m" (*(ptr)) \
10251 + : : "memory", "cc"); \
10252 + break; \
10253 + default: \
10254 + __ ## op ## _check_overflow_wrong_size(); \
10255 + } \
10256 + __ret; \
10257 + })
10258 +
10259 /*
10260 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10261 * Since this is generally used to protect other memory information, we
10262 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10263 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10264 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10265
10266 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10267 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10268 +
10269 #define __add(ptr, inc, lock) \
10270 ({ \
10271 __typeof__ (*(ptr)) __ret = (inc); \
10272 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10273 index 6b7ee5f..9d664b3 100644
10274 --- a/arch/x86/include/asm/cpufeature.h
10275 +++ b/arch/x86/include/asm/cpufeature.h
10276 @@ -202,13 +202,14 @@
10277 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10278 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10279 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10280 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10281 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10282 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10283 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10284 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10285 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10286 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10287 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10288 +#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10289
10290 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10291
10292 @@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10293 ".section .discard,\"aw\",@progbits\n"
10294 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10295 ".previous\n"
10296 - ".section .altinstr_replacement,\"ax\"\n"
10297 + ".section .altinstr_replacement,\"a\"\n"
10298 "3: movb $1,%0\n"
10299 "4:\n"
10300 ".previous\n"
10301 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10302 index 8bf1c06..f723dfd 100644
10303 --- a/arch/x86/include/asm/desc.h
10304 +++ b/arch/x86/include/asm/desc.h
10305 @@ -4,6 +4,7 @@
10306 #include <asm/desc_defs.h>
10307 #include <asm/ldt.h>
10308 #include <asm/mmu.h>
10309 +#include <asm/pgtable.h>
10310
10311 #include <linux/smp.h>
10312 #include <linux/percpu.h>
10313 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10314
10315 desc->type = (info->read_exec_only ^ 1) << 1;
10316 desc->type |= info->contents << 2;
10317 + desc->type |= info->seg_not_present ^ 1;
10318
10319 desc->s = 1;
10320 desc->dpl = 0x3;
10321 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10322 }
10323
10324 extern struct desc_ptr idt_descr;
10325 -extern gate_desc idt_table[];
10326 extern struct desc_ptr nmi_idt_descr;
10327 -extern gate_desc nmi_idt_table[];
10328 -
10329 -struct gdt_page {
10330 - struct desc_struct gdt[GDT_ENTRIES];
10331 -} __attribute__((aligned(PAGE_SIZE)));
10332 -
10333 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10334 +extern gate_desc idt_table[256];
10335 +extern gate_desc nmi_idt_table[256];
10336
10337 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10338 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10339 {
10340 - return per_cpu(gdt_page, cpu).gdt;
10341 + return cpu_gdt_table[cpu];
10342 }
10343
10344 #ifdef CONFIG_X86_64
10345 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10346 unsigned long base, unsigned dpl, unsigned flags,
10347 unsigned short seg)
10348 {
10349 - gate->a = (seg << 16) | (base & 0xffff);
10350 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10351 + gate->gate.offset_low = base;
10352 + gate->gate.seg = seg;
10353 + gate->gate.reserved = 0;
10354 + gate->gate.type = type;
10355 + gate->gate.s = 0;
10356 + gate->gate.dpl = dpl;
10357 + gate->gate.p = 1;
10358 + gate->gate.offset_high = base >> 16;
10359 }
10360
10361 #endif
10362 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10363
10364 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10365 {
10366 + pax_open_kernel();
10367 memcpy(&idt[entry], gate, sizeof(*gate));
10368 + pax_close_kernel();
10369 }
10370
10371 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10372 {
10373 + pax_open_kernel();
10374 memcpy(&ldt[entry], desc, 8);
10375 + pax_close_kernel();
10376 }
10377
10378 static inline void
10379 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10380 default: size = sizeof(*gdt); break;
10381 }
10382
10383 + pax_open_kernel();
10384 memcpy(&gdt[entry], desc, size);
10385 + pax_close_kernel();
10386 }
10387
10388 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10389 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10390
10391 static inline void native_load_tr_desc(void)
10392 {
10393 + pax_open_kernel();
10394 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10395 + pax_close_kernel();
10396 }
10397
10398 static inline void native_load_gdt(const struct desc_ptr *dtr)
10399 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10400 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10401 unsigned int i;
10402
10403 + pax_open_kernel();
10404 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10405 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10406 + pax_close_kernel();
10407 }
10408
10409 #define _LDT_empty(info) \
10410 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10411 }
10412
10413 #ifdef CONFIG_X86_64
10414 -static inline void set_nmi_gate(int gate, void *addr)
10415 +static inline void set_nmi_gate(int gate, const void *addr)
10416 {
10417 gate_desc s;
10418
10419 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10420 }
10421 #endif
10422
10423 -static inline void _set_gate(int gate, unsigned type, void *addr,
10424 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10425 unsigned dpl, unsigned ist, unsigned seg)
10426 {
10427 gate_desc s;
10428 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10429 * Pentium F0 0F bugfix can have resulted in the mapped
10430 * IDT being write-protected.
10431 */
10432 -static inline void set_intr_gate(unsigned int n, void *addr)
10433 +static inline void set_intr_gate(unsigned int n, const void *addr)
10434 {
10435 BUG_ON((unsigned)n > 0xFF);
10436 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10437 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10438 /*
10439 * This routine sets up an interrupt gate at directory privilege level 3.
10440 */
10441 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10442 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10443 {
10444 BUG_ON((unsigned)n > 0xFF);
10445 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10446 }
10447
10448 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10449 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10450 {
10451 BUG_ON((unsigned)n > 0xFF);
10452 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10453 }
10454
10455 -static inline void set_trap_gate(unsigned int n, void *addr)
10456 +static inline void set_trap_gate(unsigned int n, const void *addr)
10457 {
10458 BUG_ON((unsigned)n > 0xFF);
10459 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10460 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10461 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10462 {
10463 BUG_ON((unsigned)n > 0xFF);
10464 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10465 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10466 }
10467
10468 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10469 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10470 {
10471 BUG_ON((unsigned)n > 0xFF);
10472 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10473 }
10474
10475 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10476 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10477 {
10478 BUG_ON((unsigned)n > 0xFF);
10479 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10480 }
10481
10482 +#ifdef CONFIG_X86_32
10483 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10484 +{
10485 + struct desc_struct d;
10486 +
10487 + if (likely(limit))
10488 + limit = (limit - 1UL) >> PAGE_SHIFT;
10489 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10490 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10491 +}
10492 +#endif
10493 +
10494 #endif /* _ASM_X86_DESC_H */
10495 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10496 index 278441f..b95a174 100644
10497 --- a/arch/x86/include/asm/desc_defs.h
10498 +++ b/arch/x86/include/asm/desc_defs.h
10499 @@ -31,6 +31,12 @@ struct desc_struct {
10500 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10501 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10502 };
10503 + struct {
10504 + u16 offset_low;
10505 + u16 seg;
10506 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10507 + unsigned offset_high: 16;
10508 + } gate;
10509 };
10510 } __attribute__((packed));
10511
10512 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10513 index 3778256..c5d4fce 100644
10514 --- a/arch/x86/include/asm/e820.h
10515 +++ b/arch/x86/include/asm/e820.h
10516 @@ -69,7 +69,7 @@ struct e820map {
10517 #define ISA_START_ADDRESS 0xa0000
10518 #define ISA_END_ADDRESS 0x100000
10519
10520 -#define BIOS_BEGIN 0x000a0000
10521 +#define BIOS_BEGIN 0x000c0000
10522 #define BIOS_END 0x00100000
10523
10524 #define BIOS_ROM_BASE 0xffe00000
10525 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10526 index 5939f44..f8845f6 100644
10527 --- a/arch/x86/include/asm/elf.h
10528 +++ b/arch/x86/include/asm/elf.h
10529 @@ -243,7 +243,25 @@ extern int force_personality32;
10530 the loader. We need to make sure that it is out of the way of the program
10531 that it will "exec", and that there is sufficient room for the brk. */
10532
10533 +#ifdef CONFIG_PAX_SEGMEXEC
10534 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10535 +#else
10536 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10537 +#endif
10538 +
10539 +#ifdef CONFIG_PAX_ASLR
10540 +#ifdef CONFIG_X86_32
10541 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10542 +
10543 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10544 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10545 +#else
10546 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10547 +
10548 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10549 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10550 +#endif
10551 +#endif
10552
10553 /* This yields a mask that user programs can use to figure out what
10554 instruction set this CPU supports. This could be done in user space,
10555 @@ -296,16 +314,12 @@ do { \
10556
10557 #define ARCH_DLINFO \
10558 do { \
10559 - if (vdso_enabled) \
10560 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10561 - (unsigned long)current->mm->context.vdso); \
10562 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10563 } while (0)
10564
10565 #define ARCH_DLINFO_X32 \
10566 do { \
10567 - if (vdso_enabled) \
10568 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10569 - (unsigned long)current->mm->context.vdso); \
10570 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10571 } while (0)
10572
10573 #define AT_SYSINFO 32
10574 @@ -320,7 +334,7 @@ else \
10575
10576 #endif /* !CONFIG_X86_32 */
10577
10578 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10579 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10580
10581 #define VDSO_ENTRY \
10582 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10583 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10584 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10585 #define compat_arch_setup_additional_pages syscall32_setup_pages
10586
10587 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10588 -#define arch_randomize_brk arch_randomize_brk
10589 -
10590 /*
10591 * True on X86_32 or when emulating IA32 on X86_64
10592 */
10593 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10594 index 75ce3f4..882e801 100644
10595 --- a/arch/x86/include/asm/emergency-restart.h
10596 +++ b/arch/x86/include/asm/emergency-restart.h
10597 @@ -13,6 +13,6 @@ enum reboot_type {
10598
10599 extern enum reboot_type reboot_type;
10600
10601 -extern void machine_emergency_restart(void);
10602 +extern void machine_emergency_restart(void) __noreturn;
10603
10604 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10605 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10606 index 04cb0f8..1da4bc9 100644
10607 --- a/arch/x86/include/asm/fpu-internal.h
10608 +++ b/arch/x86/include/asm/fpu-internal.h
10609 @@ -82,10 +82,12 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
10610 }
10611
10612 #ifdef CONFIG_X86_64
10613 -static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10614 +static inline int fxrstor_checking(struct i387_fxsave_struct __user *fx)
10615 {
10616 int err;
10617
10618 + fx = (struct i387_fxsave_struct __user *)____m(fx);
10619 +
10620 /* See comment in fxsave() below. */
10621 #ifdef CONFIG_AS_FXSAVEQ
10622 asm volatile("1: fxrstorq %[fx]\n\t"
10623 @@ -115,6 +117,8 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10624 {
10625 int err;
10626
10627 + fx = (struct i387_fxsave_struct __user *)____m(fx);
10628 +
10629 /*
10630 * Clear the bytes not touched by the fxsave and reserved
10631 * for the SW usage.
10632 @@ -183,15 +187,15 @@ static inline void fpu_fxsave(struct fpu *fpu)
10633 #else /* CONFIG_X86_32 */
10634
10635 /* perform fxrstor iff the processor has extended states, otherwise frstor */
10636 -static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10637 +static inline int fxrstor_checking(struct i387_fxsave_struct __user *fx)
10638 {
10639 /*
10640 * The "nop" is needed to make the instructions the same
10641 * length.
10642 */
10643 alternative_input(
10644 - "nop ; frstor %1",
10645 - "fxrstor %1",
10646 + __copyuser_seg" frstor %1; nop",
10647 + __copyuser_seg" fxrstor %1",
10648 X86_FEATURE_FXSR,
10649 "m" (*fx));
10650
10651 @@ -250,7 +254,14 @@ static inline int __save_init_fpu(struct task_struct *tsk)
10652
10653 static inline int fpu_fxrstor_checking(struct fpu *fpu)
10654 {
10655 - return fxrstor_checking(&fpu->state->fxsave);
10656 + int ret;
10657 + mm_segment_t fs;
10658 +
10659 + fs = get_fs();
10660 + set_fs(KERNEL_DS);
10661 + ret = fxrstor_checking(&fpu->state->fxsave);
10662 + set_fs(fs);
10663 + return ret;
10664 }
10665
10666 static inline int fpu_restore_checking(struct fpu *fpu)
10667 @@ -271,7 +282,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10668 "emms\n\t" /* clear stack tags */
10669 "fildl %P[addr]", /* set F?P to defined value */
10670 X86_FEATURE_FXSAVE_LEAK,
10671 - [addr] "m" (tsk->thread.fpu.has_fpu));
10672 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10673
10674 return fpu_restore_checking(&tsk->thread.fpu);
10675 }
10676 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10677 index 71ecbcb..11df950 100644
10678 --- a/arch/x86/include/asm/futex.h
10679 +++ b/arch/x86/include/asm/futex.h
10680 @@ -11,20 +11,22 @@
10681 #include <asm/processor.h>
10682
10683 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10684 + typecheck(u32 __user *, uaddr); \
10685 asm volatile("1:\t" insn "\n" \
10686 "2:\t.section .fixup,\"ax\"\n" \
10687 "3:\tmov\t%3, %1\n" \
10688 "\tjmp\t2b\n" \
10689 "\t.previous\n" \
10690 _ASM_EXTABLE(1b, 3b) \
10691 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10692 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10693 : "i" (-EFAULT), "0" (oparg), "1" (0))
10694
10695 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10696 + typecheck(u32 __user *, uaddr); \
10697 asm volatile("1:\tmovl %2, %0\n" \
10698 "\tmovl\t%0, %3\n" \
10699 "\t" insn "\n" \
10700 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
10701 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
10702 "\tjnz\t1b\n" \
10703 "3:\t.section .fixup,\"ax\"\n" \
10704 "4:\tmov\t%5, %1\n" \
10705 @@ -33,7 +35,7 @@
10706 _ASM_EXTABLE(1b, 4b) \
10707 _ASM_EXTABLE(2b, 4b) \
10708 : "=&a" (oldval), "=&r" (ret), \
10709 - "+m" (*uaddr), "=&r" (tem) \
10710 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10711 : "r" (oparg), "i" (-EFAULT), "1" (0))
10712
10713 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10714 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10715
10716 switch (op) {
10717 case FUTEX_OP_SET:
10718 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10719 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10720 break;
10721 case FUTEX_OP_ADD:
10722 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10723 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10724 uaddr, oparg);
10725 break;
10726 case FUTEX_OP_OR:
10727 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10728 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10729 return -EFAULT;
10730
10731 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10732 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10733 "2:\t.section .fixup, \"ax\"\n"
10734 "3:\tmov %3, %0\n"
10735 "\tjmp 2b\n"
10736 "\t.previous\n"
10737 _ASM_EXTABLE(1b, 3b)
10738 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10739 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10740 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10741 : "memory"
10742 );
10743 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10744 index eb92a6e..b98b2f4 100644
10745 --- a/arch/x86/include/asm/hw_irq.h
10746 +++ b/arch/x86/include/asm/hw_irq.h
10747 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10748 extern void enable_IO_APIC(void);
10749
10750 /* Statistics */
10751 -extern atomic_t irq_err_count;
10752 -extern atomic_t irq_mis_count;
10753 +extern atomic_unchecked_t irq_err_count;
10754 +extern atomic_unchecked_t irq_mis_count;
10755
10756 /* EISA */
10757 extern void eisa_set_level_irq(unsigned int irq);
10758 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10759 index d8e8eef..99f81ae 100644
10760 --- a/arch/x86/include/asm/io.h
10761 +++ b/arch/x86/include/asm/io.h
10762 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10763
10764 #include <linux/vmalloc.h>
10765
10766 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10767 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10768 +{
10769 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10770 +}
10771 +
10772 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10773 +{
10774 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10775 +}
10776 +
10777 /*
10778 * Convert a virtual cached pointer to an uncached pointer
10779 */
10780 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10781 index bba3cf8..06bc8da 100644
10782 --- a/arch/x86/include/asm/irqflags.h
10783 +++ b/arch/x86/include/asm/irqflags.h
10784 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10785 sti; \
10786 sysexit
10787
10788 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10789 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10790 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10791 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10792 +
10793 #else
10794 #define INTERRUPT_RETURN iret
10795 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10796 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10797 index 5478825..839e88c 100644
10798 --- a/arch/x86/include/asm/kprobes.h
10799 +++ b/arch/x86/include/asm/kprobes.h
10800 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10801 #define RELATIVEJUMP_SIZE 5
10802 #define RELATIVECALL_OPCODE 0xe8
10803 #define RELATIVE_ADDR_SIZE 4
10804 -#define MAX_STACK_SIZE 64
10805 -#define MIN_STACK_SIZE(ADDR) \
10806 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10807 - THREAD_SIZE - (unsigned long)(ADDR))) \
10808 - ? (MAX_STACK_SIZE) \
10809 - : (((unsigned long)current_thread_info()) + \
10810 - THREAD_SIZE - (unsigned long)(ADDR)))
10811 +#define MAX_STACK_SIZE 64UL
10812 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10813
10814 #define flush_insn_slot(p) do { } while (0)
10815
10816 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10817 index 09155d6..d2e6df9 100644
10818 --- a/arch/x86/include/asm/kvm_host.h
10819 +++ b/arch/x86/include/asm/kvm_host.h
10820 @@ -694,7 +694,7 @@ struct kvm_x86_ops {
10821 int (*check_intercept)(struct kvm_vcpu *vcpu,
10822 struct x86_instruction_info *info,
10823 enum x86_intercept_stage stage);
10824 -};
10825 +} __do_const;
10826
10827 struct kvm_arch_async_pf {
10828 u32 token;
10829 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10830 index c8bed0d..e5721fa 100644
10831 --- a/arch/x86/include/asm/local.h
10832 +++ b/arch/x86/include/asm/local.h
10833 @@ -17,26 +17,58 @@ typedef struct {
10834
10835 static inline void local_inc(local_t *l)
10836 {
10837 - asm volatile(_ASM_INC "%0"
10838 + asm volatile(_ASM_INC "%0\n"
10839 +
10840 +#ifdef CONFIG_PAX_REFCOUNT
10841 + "jno 0f\n"
10842 + _ASM_DEC "%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_dec(local_t *l)
10851 {
10852 - asm volatile(_ASM_DEC "%0"
10853 + asm volatile(_ASM_DEC "%0\n"
10854 +
10855 +#ifdef CONFIG_PAX_REFCOUNT
10856 + "jno 0f\n"
10857 + _ASM_INC "%0\n"
10858 + "int $4\n0:\n"
10859 + _ASM_EXTABLE(0b, 0b)
10860 +#endif
10861 +
10862 : "+m" (l->a.counter));
10863 }
10864
10865 static inline void local_add(long i, local_t *l)
10866 {
10867 - asm volatile(_ASM_ADD "%1,%0"
10868 + asm volatile(_ASM_ADD "%1,%0\n"
10869 +
10870 +#ifdef CONFIG_PAX_REFCOUNT
10871 + "jno 0f\n"
10872 + _ASM_SUB "%1,%0\n"
10873 + "int $4\n0:\n"
10874 + _ASM_EXTABLE(0b, 0b)
10875 +#endif
10876 +
10877 : "+m" (l->a.counter)
10878 : "ir" (i));
10879 }
10880
10881 static inline void local_sub(long i, local_t *l)
10882 {
10883 - asm volatile(_ASM_SUB "%1,%0"
10884 + asm volatile(_ASM_SUB "%1,%0\n"
10885 +
10886 +#ifdef CONFIG_PAX_REFCOUNT
10887 + "jno 0f\n"
10888 + _ASM_ADD "%1,%0\n"
10889 + "int $4\n0:\n"
10890 + _ASM_EXTABLE(0b, 0b)
10891 +#endif
10892 +
10893 : "+m" (l->a.counter)
10894 : "ir" (i));
10895 }
10896 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10897 {
10898 unsigned char c;
10899
10900 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10901 + asm volatile(_ASM_SUB "%2,%0\n"
10902 +
10903 +#ifdef CONFIG_PAX_REFCOUNT
10904 + "jno 0f\n"
10905 + _ASM_ADD "%2,%0\n"
10906 + "int $4\n0:\n"
10907 + _ASM_EXTABLE(0b, 0b)
10908 +#endif
10909 +
10910 + "sete %1\n"
10911 : "+m" (l->a.counter), "=qm" (c)
10912 : "ir" (i) : "memory");
10913 return c;
10914 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10915 {
10916 unsigned char c;
10917
10918 - asm volatile(_ASM_DEC "%0; sete %1"
10919 + asm volatile(_ASM_DEC "%0\n"
10920 +
10921 +#ifdef CONFIG_PAX_REFCOUNT
10922 + "jno 0f\n"
10923 + _ASM_INC "%0\n"
10924 + "int $4\n0:\n"
10925 + _ASM_EXTABLE(0b, 0b)
10926 +#endif
10927 +
10928 + "sete %1\n"
10929 : "+m" (l->a.counter), "=qm" (c)
10930 : : "memory");
10931 return c != 0;
10932 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10933 {
10934 unsigned char c;
10935
10936 - asm volatile(_ASM_INC "%0; sete %1"
10937 + asm volatile(_ASM_INC "%0\n"
10938 +
10939 +#ifdef CONFIG_PAX_REFCOUNT
10940 + "jno 0f\n"
10941 + _ASM_DEC "%0\n"
10942 + "int $4\n0:\n"
10943 + _ASM_EXTABLE(0b, 0b)
10944 +#endif
10945 +
10946 + "sete %1\n"
10947 : "+m" (l->a.counter), "=qm" (c)
10948 : : "memory");
10949 return c != 0;
10950 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10951 {
10952 unsigned char c;
10953
10954 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10955 + asm volatile(_ASM_ADD "%2,%0\n"
10956 +
10957 +#ifdef CONFIG_PAX_REFCOUNT
10958 + "jno 0f\n"
10959 + _ASM_SUB "%2,%0\n"
10960 + "int $4\n0:\n"
10961 + _ASM_EXTABLE(0b, 0b)
10962 +#endif
10963 +
10964 + "sets %1\n"
10965 : "+m" (l->a.counter), "=qm" (c)
10966 : "ir" (i) : "memory");
10967 return c;
10968 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10969 #endif
10970 /* Modern 486+ processor */
10971 __i = i;
10972 - asm volatile(_ASM_XADD "%0, %1;"
10973 + asm volatile(_ASM_XADD "%0, %1\n"
10974 +
10975 +#ifdef CONFIG_PAX_REFCOUNT
10976 + "jno 0f\n"
10977 + _ASM_MOV "%0,%1\n"
10978 + "int $4\n0:\n"
10979 + _ASM_EXTABLE(0b, 0b)
10980 +#endif
10981 +
10982 : "+r" (i), "+m" (l->a.counter)
10983 : : "memory");
10984 return i + __i;
10985 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10986 index 593e51d..fa69c9a 100644
10987 --- a/arch/x86/include/asm/mman.h
10988 +++ b/arch/x86/include/asm/mman.h
10989 @@ -5,4 +5,14 @@
10990
10991 #include <asm-generic/mman.h>
10992
10993 +#ifdef __KERNEL__
10994 +#ifndef __ASSEMBLY__
10995 +#ifdef CONFIG_X86_32
10996 +#define arch_mmap_check i386_mmap_check
10997 +int i386_mmap_check(unsigned long addr, unsigned long len,
10998 + unsigned long flags);
10999 +#endif
11000 +#endif
11001 +#endif
11002 +
11003 #endif /* _ASM_X86_MMAN_H */
11004 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
11005 index 5f55e69..e20bfb1 100644
11006 --- a/arch/x86/include/asm/mmu.h
11007 +++ b/arch/x86/include/asm/mmu.h
11008 @@ -9,7 +9,7 @@
11009 * we put the segment information here.
11010 */
11011 typedef struct {
11012 - void *ldt;
11013 + struct desc_struct *ldt;
11014 int size;
11015
11016 #ifdef CONFIG_X86_64
11017 @@ -18,7 +18,19 @@ typedef struct {
11018 #endif
11019
11020 struct mutex lock;
11021 - void *vdso;
11022 + unsigned long vdso;
11023 +
11024 +#ifdef CONFIG_X86_32
11025 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
11026 + unsigned long user_cs_base;
11027 + unsigned long user_cs_limit;
11028 +
11029 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11030 + cpumask_t cpu_user_cs_mask;
11031 +#endif
11032 +
11033 +#endif
11034 +#endif
11035 } mm_context_t;
11036
11037 #ifdef CONFIG_SMP
11038 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
11039 index cdbf367..adb37ac 100644
11040 --- a/arch/x86/include/asm/mmu_context.h
11041 +++ b/arch/x86/include/asm/mmu_context.h
11042 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11043
11044 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11045 {
11046 +
11047 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11048 + unsigned int i;
11049 + pgd_t *pgd;
11050 +
11051 + pax_open_kernel();
11052 + pgd = get_cpu_pgd(smp_processor_id());
11053 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11054 + set_pgd_batched(pgd+i, native_make_pgd(0));
11055 + pax_close_kernel();
11056 +#endif
11057 +
11058 #ifdef CONFIG_SMP
11059 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11060 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11061 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11062 struct task_struct *tsk)
11063 {
11064 unsigned cpu = smp_processor_id();
11065 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11066 + int tlbstate = TLBSTATE_OK;
11067 +#endif
11068
11069 if (likely(prev != next)) {
11070 #ifdef CONFIG_SMP
11071 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11072 + tlbstate = this_cpu_read(cpu_tlbstate.state);
11073 +#endif
11074 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11075 this_cpu_write(cpu_tlbstate.active_mm, next);
11076 #endif
11077 cpumask_set_cpu(cpu, mm_cpumask(next));
11078
11079 /* Re-load page tables */
11080 +#ifdef CONFIG_PAX_PER_CPU_PGD
11081 + pax_open_kernel();
11082 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11083 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11084 + pax_close_kernel();
11085 + load_cr3(get_cpu_pgd(cpu));
11086 +#else
11087 load_cr3(next->pgd);
11088 +#endif
11089
11090 /* stop flush ipis for the previous mm */
11091 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11092 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11093 */
11094 if (unlikely(prev->context.ldt != next->context.ldt))
11095 load_LDT_nolock(&next->context);
11096 - }
11097 +
11098 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11099 + if (!(__supported_pte_mask & _PAGE_NX)) {
11100 + smp_mb__before_clear_bit();
11101 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11102 + smp_mb__after_clear_bit();
11103 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11104 + }
11105 +#endif
11106 +
11107 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11108 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11109 + prev->context.user_cs_limit != next->context.user_cs_limit))
11110 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11111 #ifdef CONFIG_SMP
11112 + else if (unlikely(tlbstate != TLBSTATE_OK))
11113 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11114 +#endif
11115 +#endif
11116 +
11117 + }
11118 else {
11119 +
11120 +#ifdef CONFIG_PAX_PER_CPU_PGD
11121 + pax_open_kernel();
11122 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11123 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11124 + pax_close_kernel();
11125 + load_cr3(get_cpu_pgd(cpu));
11126 +#endif
11127 +
11128 +#ifdef CONFIG_SMP
11129 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11130 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11131
11132 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11133 * tlb flush IPI delivery. We must reload CR3
11134 * to make sure to use no freed page tables.
11135 */
11136 +
11137 +#ifndef CONFIG_PAX_PER_CPU_PGD
11138 load_cr3(next->pgd);
11139 +#endif
11140 +
11141 load_LDT_nolock(&next->context);
11142 +
11143 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11144 + if (!(__supported_pte_mask & _PAGE_NX))
11145 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11146 +#endif
11147 +
11148 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11149 +#ifdef CONFIG_PAX_PAGEEXEC
11150 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11151 +#endif
11152 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11153 +#endif
11154 +
11155 }
11156 +#endif
11157 }
11158 -#endif
11159 }
11160
11161 #define activate_mm(prev, next) \
11162 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11163 index 9eae775..c914fea 100644
11164 --- a/arch/x86/include/asm/module.h
11165 +++ b/arch/x86/include/asm/module.h
11166 @@ -5,6 +5,7 @@
11167
11168 #ifdef CONFIG_X86_64
11169 /* X86_64 does not define MODULE_PROC_FAMILY */
11170 +#define MODULE_PROC_FAMILY ""
11171 #elif defined CONFIG_M386
11172 #define MODULE_PROC_FAMILY "386 "
11173 #elif defined CONFIG_M486
11174 @@ -59,8 +60,20 @@
11175 #error unknown processor family
11176 #endif
11177
11178 -#ifdef CONFIG_X86_32
11179 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11180 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11181 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11182 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11183 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11184 +#else
11185 +#define MODULE_PAX_KERNEXEC ""
11186 #endif
11187
11188 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11189 +#define MODULE_PAX_UDEREF "UDEREF "
11190 +#else
11191 +#define MODULE_PAX_UDEREF ""
11192 +#endif
11193 +
11194 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11195 +
11196 #endif /* _ASM_X86_MODULE_H */
11197 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11198 index 320f7bb..e89f8f8 100644
11199 --- a/arch/x86/include/asm/page_64_types.h
11200 +++ b/arch/x86/include/asm/page_64_types.h
11201 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11202
11203 /* duplicated to the one in bootmem.h */
11204 extern unsigned long max_pfn;
11205 -extern unsigned long phys_base;
11206 +extern const unsigned long phys_base;
11207
11208 extern unsigned long __phys_addr(unsigned long);
11209 #define __phys_reloc_hide(x) (x)
11210 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11211 index a0facf3..c017b15 100644
11212 --- a/arch/x86/include/asm/paravirt.h
11213 +++ b/arch/x86/include/asm/paravirt.h
11214 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11215 val);
11216 }
11217
11218 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11219 +{
11220 + pgdval_t val = native_pgd_val(pgd);
11221 +
11222 + if (sizeof(pgdval_t) > sizeof(long))
11223 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11224 + val, (u64)val >> 32);
11225 + else
11226 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11227 + val);
11228 +}
11229 +
11230 static inline void pgd_clear(pgd_t *pgdp)
11231 {
11232 set_pgd(pgdp, __pgd(0));
11233 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11234 pv_mmu_ops.set_fixmap(idx, phys, flags);
11235 }
11236
11237 +#ifdef CONFIG_PAX_KERNEXEC
11238 +static inline unsigned long pax_open_kernel(void)
11239 +{
11240 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11241 +}
11242 +
11243 +static inline unsigned long pax_close_kernel(void)
11244 +{
11245 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11246 +}
11247 +#else
11248 +static inline unsigned long pax_open_kernel(void) { return 0; }
11249 +static inline unsigned long pax_close_kernel(void) { return 0; }
11250 +#endif
11251 +
11252 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11253
11254 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11255 @@ -929,7 +956,7 @@ extern void default_banner(void);
11256
11257 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11258 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11259 -#define PARA_INDIRECT(addr) *%cs:addr
11260 +#define PARA_INDIRECT(addr) *%ss:addr
11261 #endif
11262
11263 #define INTERRUPT_RETURN \
11264 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
11265 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11266 CLBR_NONE, \
11267 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11268 +
11269 +#define GET_CR0_INTO_RDI \
11270 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11271 + mov %rax,%rdi
11272 +
11273 +#define SET_RDI_INTO_CR0 \
11274 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11275 +
11276 +#define GET_CR3_INTO_RDI \
11277 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11278 + mov %rax,%rdi
11279 +
11280 +#define SET_RDI_INTO_CR3 \
11281 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11282 +
11283 #endif /* CONFIG_X86_32 */
11284
11285 #endif /* __ASSEMBLY__ */
11286 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11287 index 142236e..6a6b4a6 100644
11288 --- a/arch/x86/include/asm/paravirt_types.h
11289 +++ b/arch/x86/include/asm/paravirt_types.h
11290 @@ -84,20 +84,20 @@ struct pv_init_ops {
11291 */
11292 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11293 unsigned long addr, unsigned len);
11294 -};
11295 +} __no_const;
11296
11297
11298 struct pv_lazy_ops {
11299 /* Set deferred update mode, used for batching operations. */
11300 void (*enter)(void);
11301 void (*leave)(void);
11302 -};
11303 +} __no_const;
11304
11305 struct pv_time_ops {
11306 unsigned long long (*sched_clock)(void);
11307 unsigned long long (*steal_clock)(int cpu);
11308 unsigned long (*get_tsc_khz)(void);
11309 -};
11310 +} __no_const;
11311
11312 struct pv_cpu_ops {
11313 /* hooks for various privileged instructions */
11314 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
11315
11316 void (*start_context_switch)(struct task_struct *prev);
11317 void (*end_context_switch)(struct task_struct *next);
11318 -};
11319 +} __no_const;
11320
11321 struct pv_irq_ops {
11322 /*
11323 @@ -222,7 +222,7 @@ struct pv_apic_ops {
11324 unsigned long start_eip,
11325 unsigned long start_esp);
11326 #endif
11327 -};
11328 +} __no_const;
11329
11330 struct pv_mmu_ops {
11331 unsigned long (*read_cr2)(void);
11332 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
11333 struct paravirt_callee_save make_pud;
11334
11335 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11336 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11337 #endif /* PAGETABLE_LEVELS == 4 */
11338 #endif /* PAGETABLE_LEVELS >= 3 */
11339
11340 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
11341 an mfn. We can tell which is which from the index. */
11342 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11343 phys_addr_t phys, pgprot_t flags);
11344 +
11345 +#ifdef CONFIG_PAX_KERNEXEC
11346 + unsigned long (*pax_open_kernel)(void);
11347 + unsigned long (*pax_close_kernel)(void);
11348 +#endif
11349 +
11350 };
11351
11352 struct arch_spinlock;
11353 @@ -333,7 +340,7 @@ struct pv_lock_ops {
11354 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11355 int (*spin_trylock)(struct arch_spinlock *lock);
11356 void (*spin_unlock)(struct arch_spinlock *lock);
11357 -};
11358 +} __no_const;
11359
11360 /* This contains all the paravirt structures: we get a convenient
11361 * number for each function using the offset which we use to indicate
11362 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11363 index b4389a4..7024269 100644
11364 --- a/arch/x86/include/asm/pgalloc.h
11365 +++ b/arch/x86/include/asm/pgalloc.h
11366 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11367 pmd_t *pmd, pte_t *pte)
11368 {
11369 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11370 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11371 +}
11372 +
11373 +static inline void pmd_populate_user(struct mm_struct *mm,
11374 + pmd_t *pmd, pte_t *pte)
11375 +{
11376 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11377 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11378 }
11379
11380 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11381
11382 #ifdef CONFIG_X86_PAE
11383 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11384 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11385 +{
11386 + pud_populate(mm, pudp, pmd);
11387 +}
11388 #else /* !CONFIG_X86_PAE */
11389 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11390 {
11391 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11392 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11393 }
11394 +
11395 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11396 +{
11397 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11398 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11399 +}
11400 #endif /* CONFIG_X86_PAE */
11401
11402 #if PAGETABLE_LEVELS > 3
11403 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11404 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11405 }
11406
11407 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11408 +{
11409 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11410 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11411 +}
11412 +
11413 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11414 {
11415 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11416 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11417 index f2b489c..4f7e2e5 100644
11418 --- a/arch/x86/include/asm/pgtable-2level.h
11419 +++ b/arch/x86/include/asm/pgtable-2level.h
11420 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11421
11422 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11423 {
11424 + pax_open_kernel();
11425 *pmdp = pmd;
11426 + pax_close_kernel();
11427 }
11428
11429 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11430 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11431 index 4cc9f2b..5fd9226 100644
11432 --- a/arch/x86/include/asm/pgtable-3level.h
11433 +++ b/arch/x86/include/asm/pgtable-3level.h
11434 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11435
11436 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11437 {
11438 + pax_open_kernel();
11439 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11440 + pax_close_kernel();
11441 }
11442
11443 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11444 {
11445 + pax_open_kernel();
11446 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11447 + pax_close_kernel();
11448 }
11449
11450 /*
11451 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11452 index c3520d7..cf742ef 100644
11453 --- a/arch/x86/include/asm/pgtable.h
11454 +++ b/arch/x86/include/asm/pgtable.h
11455 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11456
11457 #ifndef __PAGETABLE_PUD_FOLDED
11458 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11459 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11460 #define pgd_clear(pgd) native_pgd_clear(pgd)
11461 #endif
11462
11463 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11464
11465 #define arch_end_context_switch(prev) do {} while(0)
11466
11467 +#define pax_open_kernel() native_pax_open_kernel()
11468 +#define pax_close_kernel() native_pax_close_kernel()
11469 #endif /* CONFIG_PARAVIRT */
11470
11471 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11472 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11473 +
11474 +#ifdef CONFIG_PAX_KERNEXEC
11475 +static inline unsigned long native_pax_open_kernel(void)
11476 +{
11477 + unsigned long cr0;
11478 +
11479 + preempt_disable();
11480 + barrier();
11481 + cr0 = read_cr0() ^ X86_CR0_WP;
11482 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11483 + write_cr0(cr0);
11484 + return cr0 ^ X86_CR0_WP;
11485 +}
11486 +
11487 +static inline unsigned long native_pax_close_kernel(void)
11488 +{
11489 + unsigned long cr0;
11490 +
11491 + cr0 = read_cr0() ^ X86_CR0_WP;
11492 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11493 + write_cr0(cr0);
11494 + barrier();
11495 + preempt_enable_no_resched();
11496 + return cr0 ^ X86_CR0_WP;
11497 +}
11498 +#else
11499 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11500 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11501 +#endif
11502 +
11503 /*
11504 * The following only work if pte_present() is true.
11505 * Undefined behaviour if not..
11506 */
11507 +static inline int pte_user(pte_t pte)
11508 +{
11509 + return pte_val(pte) & _PAGE_USER;
11510 +}
11511 +
11512 static inline int pte_dirty(pte_t pte)
11513 {
11514 return pte_flags(pte) & _PAGE_DIRTY;
11515 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11516 return pte_clear_flags(pte, _PAGE_RW);
11517 }
11518
11519 +static inline pte_t pte_mkread(pte_t pte)
11520 +{
11521 + return __pte(pte_val(pte) | _PAGE_USER);
11522 +}
11523 +
11524 static inline pte_t pte_mkexec(pte_t pte)
11525 {
11526 - return pte_clear_flags(pte, _PAGE_NX);
11527 +#ifdef CONFIG_X86_PAE
11528 + if (__supported_pte_mask & _PAGE_NX)
11529 + return pte_clear_flags(pte, _PAGE_NX);
11530 + else
11531 +#endif
11532 + return pte_set_flags(pte, _PAGE_USER);
11533 +}
11534 +
11535 +static inline pte_t pte_exprotect(pte_t pte)
11536 +{
11537 +#ifdef CONFIG_X86_PAE
11538 + if (__supported_pte_mask & _PAGE_NX)
11539 + return pte_set_flags(pte, _PAGE_NX);
11540 + else
11541 +#endif
11542 + return pte_clear_flags(pte, _PAGE_USER);
11543 }
11544
11545 static inline pte_t pte_mkdirty(pte_t pte)
11546 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11547 #endif
11548
11549 #ifndef __ASSEMBLY__
11550 +
11551 +#ifdef CONFIG_PAX_PER_CPU_PGD
11552 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11553 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11554 +{
11555 + return cpu_pgd[cpu];
11556 +}
11557 +#endif
11558 +
11559 #include <linux/mm_types.h>
11560
11561 static inline int pte_none(pte_t pte)
11562 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11563
11564 static inline int pgd_bad(pgd_t pgd)
11565 {
11566 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11567 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11568 }
11569
11570 static inline int pgd_none(pgd_t pgd)
11571 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11572 * pgd_offset() returns a (pgd_t *)
11573 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11574 */
11575 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11576 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11577 +
11578 +#ifdef CONFIG_PAX_PER_CPU_PGD
11579 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11580 +#endif
11581 +
11582 /*
11583 * a shortcut which implies the use of the kernel's pgd, instead
11584 * of a process's
11585 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11586 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11587 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11588
11589 +#ifdef CONFIG_X86_32
11590 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11591 +#else
11592 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11593 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11594 +
11595 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11596 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11597 +#else
11598 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11599 +#endif
11600 +
11601 +#endif
11602 +
11603 #ifndef __ASSEMBLY__
11604
11605 extern int direct_gbpages;
11606 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11607 * dst and src can be on the same page, but the range must not overlap,
11608 * and must not cross a page boundary.
11609 */
11610 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11611 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11612 {
11613 - memcpy(dst, src, count * sizeof(pgd_t));
11614 + pax_open_kernel();
11615 + while (count--)
11616 + *dst++ = *src++;
11617 + pax_close_kernel();
11618 }
11619
11620 +#ifdef CONFIG_PAX_PER_CPU_PGD
11621 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11622 +#endif
11623 +
11624 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11625 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11626 +#else
11627 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11628 +#endif
11629
11630 #include <asm-generic/pgtable.h>
11631 #endif /* __ASSEMBLY__ */
11632 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11633 index 0c92113..34a77c6 100644
11634 --- a/arch/x86/include/asm/pgtable_32.h
11635 +++ b/arch/x86/include/asm/pgtable_32.h
11636 @@ -25,9 +25,6 @@
11637 struct mm_struct;
11638 struct vm_area_struct;
11639
11640 -extern pgd_t swapper_pg_dir[1024];
11641 -extern pgd_t initial_page_table[1024];
11642 -
11643 static inline void pgtable_cache_init(void) { }
11644 static inline void check_pgt_cache(void) { }
11645 void paging_init(void);
11646 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11647 # include <asm/pgtable-2level.h>
11648 #endif
11649
11650 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11651 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11652 +#ifdef CONFIG_X86_PAE
11653 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11654 +#endif
11655 +
11656 #if defined(CONFIG_HIGHPTE)
11657 #define pte_offset_map(dir, address) \
11658 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11659 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11660 /* Clear a kernel PTE and flush it from the TLB */
11661 #define kpte_clear_flush(ptep, vaddr) \
11662 do { \
11663 + pax_open_kernel(); \
11664 pte_clear(&init_mm, (vaddr), (ptep)); \
11665 + pax_close_kernel(); \
11666 __flush_tlb_one((vaddr)); \
11667 } while (0)
11668
11669 @@ -74,6 +79,9 @@ do { \
11670
11671 #endif /* !__ASSEMBLY__ */
11672
11673 +#define HAVE_ARCH_UNMAPPED_AREA
11674 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11675 +
11676 /*
11677 * kern_addr_valid() is (1) for FLATMEM and (0) for
11678 * SPARSEMEM and DISCONTIGMEM
11679 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11680 index ed5903b..c7fe163 100644
11681 --- a/arch/x86/include/asm/pgtable_32_types.h
11682 +++ b/arch/x86/include/asm/pgtable_32_types.h
11683 @@ -8,7 +8,7 @@
11684 */
11685 #ifdef CONFIG_X86_PAE
11686 # include <asm/pgtable-3level_types.h>
11687 -# define PMD_SIZE (1UL << PMD_SHIFT)
11688 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11689 # define PMD_MASK (~(PMD_SIZE - 1))
11690 #else
11691 # include <asm/pgtable-2level_types.h>
11692 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11693 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11694 #endif
11695
11696 +#ifdef CONFIG_PAX_KERNEXEC
11697 +#ifndef __ASSEMBLY__
11698 +extern unsigned char MODULES_EXEC_VADDR[];
11699 +extern unsigned char MODULES_EXEC_END[];
11700 +#endif
11701 +#include <asm/boot.h>
11702 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11703 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11704 +#else
11705 +#define ktla_ktva(addr) (addr)
11706 +#define ktva_ktla(addr) (addr)
11707 +#endif
11708 +
11709 #define MODULES_VADDR VMALLOC_START
11710 #define MODULES_END VMALLOC_END
11711 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11712 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11713 index 8251be0..4ea8b46 100644
11714 --- a/arch/x86/include/asm/pgtable_64.h
11715 +++ b/arch/x86/include/asm/pgtable_64.h
11716 @@ -16,10 +16,14 @@
11717
11718 extern pud_t level3_kernel_pgt[512];
11719 extern pud_t level3_ident_pgt[512];
11720 +extern pud_t level3_vmalloc_start_pgt[512];
11721 +extern pud_t level3_vmalloc_end_pgt[512];
11722 +extern pud_t level3_vmemmap_pgt[512];
11723 +extern pud_t level2_vmemmap_pgt[512];
11724 extern pmd_t level2_kernel_pgt[512];
11725 extern pmd_t level2_fixmap_pgt[512];
11726 -extern pmd_t level2_ident_pgt[512];
11727 -extern pgd_t init_level4_pgt[];
11728 +extern pmd_t level2_ident_pgt[512*2];
11729 +extern pgd_t init_level4_pgt[512];
11730
11731 #define swapper_pg_dir init_level4_pgt
11732
11733 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11734
11735 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11736 {
11737 + pax_open_kernel();
11738 *pmdp = pmd;
11739 + pax_close_kernel();
11740 }
11741
11742 static inline void native_pmd_clear(pmd_t *pmd)
11743 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11744
11745 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11746 {
11747 + pax_open_kernel();
11748 *pudp = pud;
11749 + pax_close_kernel();
11750 }
11751
11752 static inline void native_pud_clear(pud_t *pud)
11753 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11754
11755 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11756 {
11757 + pax_open_kernel();
11758 + *pgdp = pgd;
11759 + pax_close_kernel();
11760 +}
11761 +
11762 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11763 +{
11764 *pgdp = pgd;
11765 }
11766
11767 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11768 index 766ea16..5b96cb3 100644
11769 --- a/arch/x86/include/asm/pgtable_64_types.h
11770 +++ b/arch/x86/include/asm/pgtable_64_types.h
11771 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11772 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11773 #define MODULES_END _AC(0xffffffffff000000, UL)
11774 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11775 +#define MODULES_EXEC_VADDR MODULES_VADDR
11776 +#define MODULES_EXEC_END MODULES_END
11777 +
11778 +#define ktla_ktva(addr) (addr)
11779 +#define ktva_ktla(addr) (addr)
11780
11781 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11782 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11783 index 013286a..8b42f4f 100644
11784 --- a/arch/x86/include/asm/pgtable_types.h
11785 +++ b/arch/x86/include/asm/pgtable_types.h
11786 @@ -16,13 +16,12 @@
11787 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11788 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11789 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11790 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11791 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11792 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11793 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11794 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11795 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11796 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11797 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11798 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11799 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11800 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11801
11802 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11803 @@ -40,7 +39,6 @@
11804 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11805 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11806 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11807 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11808 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11809 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11810 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11811 @@ -57,8 +55,10 @@
11812
11813 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11814 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11815 -#else
11816 +#elif defined(CONFIG_KMEMCHECK)
11817 #define _PAGE_NX (_AT(pteval_t, 0))
11818 +#else
11819 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11820 #endif
11821
11822 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11823 @@ -96,6 +96,9 @@
11824 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11825 _PAGE_ACCESSED)
11826
11827 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11828 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11829 +
11830 #define __PAGE_KERNEL_EXEC \
11831 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11832 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11833 @@ -106,7 +109,7 @@
11834 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11835 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11836 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11837 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11838 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11839 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11840 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11841 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11842 @@ -168,8 +171,8 @@
11843 * bits are combined, this will alow user to access the high address mapped
11844 * VDSO in the presence of CONFIG_COMPAT_VDSO
11845 */
11846 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11847 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11848 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11849 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11850 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11851 #endif
11852
11853 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11854 {
11855 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11856 }
11857 +#endif
11858
11859 +#if PAGETABLE_LEVELS == 3
11860 +#include <asm-generic/pgtable-nopud.h>
11861 +#endif
11862 +
11863 +#if PAGETABLE_LEVELS == 2
11864 +#include <asm-generic/pgtable-nopmd.h>
11865 +#endif
11866 +
11867 +#ifndef __ASSEMBLY__
11868 #if PAGETABLE_LEVELS > 3
11869 typedef struct { pudval_t pud; } pud_t;
11870
11871 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11872 return pud.pud;
11873 }
11874 #else
11875 -#include <asm-generic/pgtable-nopud.h>
11876 -
11877 static inline pudval_t native_pud_val(pud_t pud)
11878 {
11879 return native_pgd_val(pud.pgd);
11880 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11881 return pmd.pmd;
11882 }
11883 #else
11884 -#include <asm-generic/pgtable-nopmd.h>
11885 -
11886 static inline pmdval_t native_pmd_val(pmd_t pmd)
11887 {
11888 return native_pgd_val(pmd.pud.pgd);
11889 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11890
11891 extern pteval_t __supported_pte_mask;
11892 extern void set_nx(void);
11893 -extern int nx_enabled;
11894
11895 #define pgprot_writecombine pgprot_writecombine
11896 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11897 diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11898 index aea1d1d..680cf09 100644
11899 --- a/arch/x86/include/asm/processor-flags.h
11900 +++ b/arch/x86/include/asm/processor-flags.h
11901 @@ -65,6 +65,7 @@
11902 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11903 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11904 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11905 +#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11906
11907 /*
11908 * x86-64 Task Priority Register, CR8
11909 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11910 index d048cad..45e350f 100644
11911 --- a/arch/x86/include/asm/processor.h
11912 +++ b/arch/x86/include/asm/processor.h
11913 @@ -289,7 +289,7 @@ struct tss_struct {
11914
11915 } ____cacheline_aligned;
11916
11917 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11918 +extern struct tss_struct init_tss[NR_CPUS];
11919
11920 /*
11921 * Save the original ist values for checking stack pointers during debugging
11922 @@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11923 */
11924 #define TASK_SIZE PAGE_OFFSET
11925 #define TASK_SIZE_MAX TASK_SIZE
11926 +
11927 +#ifdef CONFIG_PAX_SEGMEXEC
11928 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11929 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11930 +#else
11931 #define STACK_TOP TASK_SIZE
11932 -#define STACK_TOP_MAX STACK_TOP
11933 +#endif
11934 +
11935 +#define STACK_TOP_MAX TASK_SIZE
11936
11937 #define INIT_THREAD { \
11938 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11939 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11940 .vm86_info = NULL, \
11941 .sysenter_cs = __KERNEL_CS, \
11942 .io_bitmap_ptr = NULL, \
11943 @@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11944 */
11945 #define INIT_TSS { \
11946 .x86_tss = { \
11947 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11948 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11949 .ss0 = __KERNEL_DS, \
11950 .ss1 = __KERNEL_CS, \
11951 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11952 @@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11953 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11954
11955 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11956 -#define KSTK_TOP(info) \
11957 -({ \
11958 - unsigned long *__ptr = (unsigned long *)(info); \
11959 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11960 -})
11961 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11962
11963 /*
11964 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11965 @@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11966 #define task_pt_regs(task) \
11967 ({ \
11968 struct pt_regs *__regs__; \
11969 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11970 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11971 __regs__ - 1; \
11972 })
11973
11974 @@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11975 /*
11976 * User space process size. 47bits minus one guard page.
11977 */
11978 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11979 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11980
11981 /* This decides where the kernel will search for a free chunk of vm
11982 * space during mmap's.
11983 */
11984 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11985 - 0xc0000000 : 0xFFFFe000)
11986 + 0xc0000000 : 0xFFFFf000)
11987
11988 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11989 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11990 @@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11991 #define STACK_TOP_MAX TASK_SIZE_MAX
11992
11993 #define INIT_THREAD { \
11994 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11995 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11996 }
11997
11998 #define INIT_TSS { \
11999 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12000 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12001 }
12002
12003 /*
12004 @@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
12005 */
12006 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
12007
12008 +#ifdef CONFIG_PAX_SEGMEXEC
12009 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
12010 +#endif
12011 +
12012 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
12013
12014 /* Get/set a process' ability to use the timestamp counter instruction */
12015 @@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
12016 #define cpu_has_amd_erratum(x) (false)
12017 #endif /* CONFIG_CPU_SUP_AMD */
12018
12019 -extern unsigned long arch_align_stack(unsigned long sp);
12020 +#define arch_align_stack(x) ((x) & ~0xfUL)
12021 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12022
12023 void default_idle(void);
12024 bool set_pm_idle_to_default(void);
12025
12026 -void stop_this_cpu(void *dummy);
12027 +void stop_this_cpu(void *dummy) __noreturn;
12028
12029 #endif /* _ASM_X86_PROCESSOR_H */
12030 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
12031 index 19f16eb..b50624b 100644
12032 --- a/arch/x86/include/asm/ptrace.h
12033 +++ b/arch/x86/include/asm/ptrace.h
12034 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
12035 }
12036
12037 /*
12038 - * user_mode_vm(regs) determines whether a register set came from user mode.
12039 + * user_mode(regs) determines whether a register set came from user mode.
12040 * This is true if V8086 mode was enabled OR if the register set was from
12041 * protected mode with RPL-3 CS value. This tricky test checks that with
12042 * one comparison. Many places in the kernel can bypass this full check
12043 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12044 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12045 + * be used.
12046 */
12047 -static inline int user_mode(struct pt_regs *regs)
12048 +static inline int user_mode_novm(struct pt_regs *regs)
12049 {
12050 #ifdef CONFIG_X86_32
12051 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12052 #else
12053 - return !!(regs->cs & 3);
12054 + return !!(regs->cs & SEGMENT_RPL_MASK);
12055 #endif
12056 }
12057
12058 -static inline int user_mode_vm(struct pt_regs *regs)
12059 +static inline int user_mode(struct pt_regs *regs)
12060 {
12061 #ifdef CONFIG_X86_32
12062 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12063 USER_RPL;
12064 #else
12065 - return user_mode(regs);
12066 + return user_mode_novm(regs);
12067 #endif
12068 }
12069
12070 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12071 #ifdef CONFIG_X86_64
12072 static inline bool user_64bit_mode(struct pt_regs *regs)
12073 {
12074 + unsigned long cs = regs->cs & 0xffff;
12075 #ifndef CONFIG_PARAVIRT
12076 /*
12077 * On non-paravirt systems, this is the only long mode CPL 3
12078 * selector. We do not allow long mode selectors in the LDT.
12079 */
12080 - return regs->cs == __USER_CS;
12081 + return cs == __USER_CS;
12082 #else
12083 /* Headers are too twisted for this to go in paravirt.h. */
12084 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12085 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12086 #endif
12087 }
12088 #endif
12089 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12090 index fe1ec5b..dc5c3fe 100644
12091 --- a/arch/x86/include/asm/realmode.h
12092 +++ b/arch/x86/include/asm/realmode.h
12093 @@ -22,16 +22,14 @@ struct real_mode_header {
12094 #endif
12095 /* APM/BIOS reboot */
12096 u32 machine_real_restart_asm;
12097 -#ifdef CONFIG_X86_64
12098 u32 machine_real_restart_seg;
12099 -#endif
12100 };
12101
12102 /* This must match data at trampoline_32/64.S */
12103 struct trampoline_header {
12104 #ifdef CONFIG_X86_32
12105 u32 start;
12106 - u16 gdt_pad;
12107 + u16 boot_cs;
12108 u16 gdt_limit;
12109 u32 gdt_base;
12110 #else
12111 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12112 index a82c4f1..ac45053 100644
12113 --- a/arch/x86/include/asm/reboot.h
12114 +++ b/arch/x86/include/asm/reboot.h
12115 @@ -6,13 +6,13 @@
12116 struct pt_regs;
12117
12118 struct machine_ops {
12119 - void (*restart)(char *cmd);
12120 - void (*halt)(void);
12121 - void (*power_off)(void);
12122 + void (* __noreturn restart)(char *cmd);
12123 + void (* __noreturn halt)(void);
12124 + void (* __noreturn power_off)(void);
12125 void (*shutdown)(void);
12126 void (*crash_shutdown)(struct pt_regs *);
12127 - void (*emergency_restart)(void);
12128 -};
12129 + void (* __noreturn emergency_restart)(void);
12130 +} __no_const;
12131
12132 extern struct machine_ops machine_ops;
12133
12134 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12135 index 2dbe4a7..ce1db00 100644
12136 --- a/arch/x86/include/asm/rwsem.h
12137 +++ b/arch/x86/include/asm/rwsem.h
12138 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12139 {
12140 asm volatile("# beginning down_read\n\t"
12141 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12142 +
12143 +#ifdef CONFIG_PAX_REFCOUNT
12144 + "jno 0f\n"
12145 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12146 + "int $4\n0:\n"
12147 + _ASM_EXTABLE(0b, 0b)
12148 +#endif
12149 +
12150 /* adds 0x00000001 */
12151 " jns 1f\n"
12152 " call call_rwsem_down_read_failed\n"
12153 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12154 "1:\n\t"
12155 " mov %1,%2\n\t"
12156 " add %3,%2\n\t"
12157 +
12158 +#ifdef CONFIG_PAX_REFCOUNT
12159 + "jno 0f\n"
12160 + "sub %3,%2\n"
12161 + "int $4\n0:\n"
12162 + _ASM_EXTABLE(0b, 0b)
12163 +#endif
12164 +
12165 " jle 2f\n\t"
12166 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12167 " jnz 1b\n\t"
12168 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12169 long tmp;
12170 asm volatile("# beginning down_write\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 /* adds 0xffff0001, returns the old value */
12181 " test %1,%1\n\t"
12182 /* was the count 0 before? */
12183 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12184 long tmp;
12185 asm volatile("# beginning __up_read\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 1, returns the old value */
12196 " jns 1f\n\t"
12197 " call call_rwsem_wake\n" /* expects old value in %edx */
12198 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12199 long tmp;
12200 asm volatile("# beginning __up_write\n\t"
12201 LOCK_PREFIX " xadd %1,(%2)\n\t"
12202 +
12203 +#ifdef CONFIG_PAX_REFCOUNT
12204 + "jno 0f\n"
12205 + "mov %1,(%2)\n"
12206 + "int $4\n0:\n"
12207 + _ASM_EXTABLE(0b, 0b)
12208 +#endif
12209 +
12210 /* subtracts 0xffff0001, returns the old value */
12211 " jns 1f\n\t"
12212 " call call_rwsem_wake\n" /* expects old value in %edx */
12213 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12214 {
12215 asm volatile("# beginning __downgrade_write\n\t"
12216 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12217 +
12218 +#ifdef CONFIG_PAX_REFCOUNT
12219 + "jno 0f\n"
12220 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12221 + "int $4\n0:\n"
12222 + _ASM_EXTABLE(0b, 0b)
12223 +#endif
12224 +
12225 /*
12226 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12227 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12228 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12229 */
12230 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12231 {
12232 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12233 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12234 +
12235 +#ifdef CONFIG_PAX_REFCOUNT
12236 + "jno 0f\n"
12237 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12238 + "int $4\n0:\n"
12239 + _ASM_EXTABLE(0b, 0b)
12240 +#endif
12241 +
12242 : "+m" (sem->count)
12243 : "er" (delta));
12244 }
12245 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12246 */
12247 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12248 {
12249 - return delta + xadd(&sem->count, delta);
12250 + return delta + xadd_check_overflow(&sem->count, delta);
12251 }
12252
12253 #endif /* __KERNEL__ */
12254 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12255 index c48a950..c6d7468 100644
12256 --- a/arch/x86/include/asm/segment.h
12257 +++ b/arch/x86/include/asm/segment.h
12258 @@ -64,10 +64,15 @@
12259 * 26 - ESPFIX small SS
12260 * 27 - per-cpu [ offset to per-cpu data area ]
12261 * 28 - stack_canary-20 [ for stack protector ]
12262 - * 29 - unused
12263 - * 30 - unused
12264 + * 29 - PCI BIOS CS
12265 + * 30 - PCI BIOS DS
12266 * 31 - TSS for double fault handler
12267 */
12268 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12269 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12270 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12271 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12272 +
12273 #define GDT_ENTRY_TLS_MIN 6
12274 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12275
12276 @@ -79,6 +84,8 @@
12277
12278 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12279
12280 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12281 +
12282 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12283
12284 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12285 @@ -104,6 +111,12 @@
12286 #define __KERNEL_STACK_CANARY 0
12287 #endif
12288
12289 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12290 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12291 +
12292 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12293 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12294 +
12295 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12296
12297 /*
12298 @@ -141,7 +154,7 @@
12299 */
12300
12301 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12302 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12303 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12304
12305
12306 #else
12307 @@ -165,6 +178,8 @@
12308 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12309 #define __USER32_DS __USER_DS
12310
12311 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12312 +
12313 #define GDT_ENTRY_TSS 8 /* needs two entries */
12314 #define GDT_ENTRY_LDT 10 /* needs two entries */
12315 #define GDT_ENTRY_TLS_MIN 12
12316 @@ -185,6 +200,7 @@
12317 #endif
12318
12319 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12320 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12321 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12322 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12323 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12324 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12325 {
12326 unsigned long __limit;
12327 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12328 - return __limit + 1;
12329 + return __limit;
12330 }
12331
12332 #endif /* !__ASSEMBLY__ */
12333 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12334 index 4f19a15..9e14f27 100644
12335 --- a/arch/x86/include/asm/smp.h
12336 +++ b/arch/x86/include/asm/smp.h
12337 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12338 /* cpus sharing the last level cache: */
12339 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12340 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12341 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12342 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12343
12344 static inline struct cpumask *cpu_sibling_mask(int cpu)
12345 {
12346 @@ -79,7 +79,7 @@ struct smp_ops {
12347
12348 void (*send_call_func_ipi)(const struct cpumask *mask);
12349 void (*send_call_func_single_ipi)(int cpu);
12350 -};
12351 +} __no_const;
12352
12353 /* Globals due to paravirt */
12354 extern void set_cpu_sibling_map(int cpu);
12355 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12356 extern int safe_smp_processor_id(void);
12357
12358 #elif defined(CONFIG_X86_64_SMP)
12359 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12360 -
12361 -#define stack_smp_processor_id() \
12362 -({ \
12363 - struct thread_info *ti; \
12364 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12365 - ti->cpu; \
12366 -})
12367 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12368 +#define stack_smp_processor_id() raw_smp_processor_id()
12369 #define safe_smp_processor_id() smp_processor_id()
12370
12371 #endif
12372 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12373 index 33692ea..350a534 100644
12374 --- a/arch/x86/include/asm/spinlock.h
12375 +++ b/arch/x86/include/asm/spinlock.h
12376 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12377 static inline void arch_read_lock(arch_rwlock_t *rw)
12378 {
12379 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12380 +
12381 +#ifdef CONFIG_PAX_REFCOUNT
12382 + "jno 0f\n"
12383 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12384 + "int $4\n0:\n"
12385 + _ASM_EXTABLE(0b, 0b)
12386 +#endif
12387 +
12388 "jns 1f\n"
12389 "call __read_lock_failed\n\t"
12390 "1:\n"
12391 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12392 static inline void arch_write_lock(arch_rwlock_t *rw)
12393 {
12394 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12395 +
12396 +#ifdef CONFIG_PAX_REFCOUNT
12397 + "jno 0f\n"
12398 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12399 + "int $4\n0:\n"
12400 + _ASM_EXTABLE(0b, 0b)
12401 +#endif
12402 +
12403 "jz 1f\n"
12404 "call __write_lock_failed\n\t"
12405 "1:\n"
12406 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12407
12408 static inline void arch_read_unlock(arch_rwlock_t *rw)
12409 {
12410 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12411 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12412 +
12413 +#ifdef CONFIG_PAX_REFCOUNT
12414 + "jno 0f\n"
12415 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12416 + "int $4\n0:\n"
12417 + _ASM_EXTABLE(0b, 0b)
12418 +#endif
12419 +
12420 :"+m" (rw->lock) : : "memory");
12421 }
12422
12423 static inline void arch_write_unlock(arch_rwlock_t *rw)
12424 {
12425 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12426 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12427 +
12428 +#ifdef CONFIG_PAX_REFCOUNT
12429 + "jno 0f\n"
12430 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12431 + "int $4\n0:\n"
12432 + _ASM_EXTABLE(0b, 0b)
12433 +#endif
12434 +
12435 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12436 }
12437
12438 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12439 index 6a99859..03cb807 100644
12440 --- a/arch/x86/include/asm/stackprotector.h
12441 +++ b/arch/x86/include/asm/stackprotector.h
12442 @@ -47,7 +47,7 @@
12443 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12444 */
12445 #define GDT_STACK_CANARY_INIT \
12446 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12447 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12448
12449 /*
12450 * Initialize the stackprotector canary value.
12451 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12452
12453 static inline void load_stack_canary_segment(void)
12454 {
12455 -#ifdef CONFIG_X86_32
12456 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12457 asm volatile ("mov %0, %%gs" : : "r" (0));
12458 #endif
12459 }
12460 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12461 index 70bbe39..4ae2bd4 100644
12462 --- a/arch/x86/include/asm/stacktrace.h
12463 +++ b/arch/x86/include/asm/stacktrace.h
12464 @@ -11,28 +11,20 @@
12465
12466 extern int kstack_depth_to_print;
12467
12468 -struct thread_info;
12469 +struct task_struct;
12470 struct stacktrace_ops;
12471
12472 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12473 - unsigned long *stack,
12474 - unsigned long bp,
12475 - const struct stacktrace_ops *ops,
12476 - void *data,
12477 - unsigned long *end,
12478 - int *graph);
12479 +typedef unsigned long walk_stack_t(struct task_struct *task,
12480 + void *stack_start,
12481 + unsigned long *stack,
12482 + unsigned long bp,
12483 + const struct stacktrace_ops *ops,
12484 + void *data,
12485 + unsigned long *end,
12486 + int *graph);
12487
12488 -extern unsigned long
12489 -print_context_stack(struct thread_info *tinfo,
12490 - unsigned long *stack, unsigned long bp,
12491 - const struct stacktrace_ops *ops, void *data,
12492 - unsigned long *end, int *graph);
12493 -
12494 -extern unsigned long
12495 -print_context_stack_bp(struct thread_info *tinfo,
12496 - unsigned long *stack, unsigned long bp,
12497 - const struct stacktrace_ops *ops, void *data,
12498 - unsigned long *end, int *graph);
12499 +extern walk_stack_t print_context_stack;
12500 +extern walk_stack_t print_context_stack_bp;
12501
12502 /* Generic stack tracer with callbacks */
12503
12504 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12505 void (*address)(void *data, unsigned long address, int reliable);
12506 /* On negative return stop dumping */
12507 int (*stack)(void *data, char *name);
12508 - walk_stack_t walk_stack;
12509 + walk_stack_t *walk_stack;
12510 };
12511
12512 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12513 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12514 index 4ec45b3..a4f0a8a 100644
12515 --- a/arch/x86/include/asm/switch_to.h
12516 +++ b/arch/x86/include/asm/switch_to.h
12517 @@ -108,7 +108,7 @@ do { \
12518 "call __switch_to\n\t" \
12519 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12520 __switch_canary \
12521 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12522 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12523 "movq %%rax,%%rdi\n\t" \
12524 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12525 "jnz ret_from_fork\n\t" \
12526 @@ -119,7 +119,7 @@ do { \
12527 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12528 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12529 [_tif_fork] "i" (_TIF_FORK), \
12530 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12531 + [thread_info] "m" (current_tinfo), \
12532 [current_task] "m" (current_task) \
12533 __switch_canary_iparam \
12534 : "memory", "cc" __EXTRA_CLOBBER)
12535 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12536 index 3fda9db4..4ca1c61 100644
12537 --- a/arch/x86/include/asm/sys_ia32.h
12538 +++ b/arch/x86/include/asm/sys_ia32.h
12539 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12540 struct old_sigaction32 __user *);
12541 asmlinkage long sys32_alarm(unsigned int);
12542
12543 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12544 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12545 asmlinkage long sys32_sysfs(int, u32, u32);
12546
12547 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12548 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12549 index 89f794f..1422765 100644
12550 --- a/arch/x86/include/asm/thread_info.h
12551 +++ b/arch/x86/include/asm/thread_info.h
12552 @@ -10,6 +10,7 @@
12553 #include <linux/compiler.h>
12554 #include <asm/page.h>
12555 #include <asm/types.h>
12556 +#include <asm/percpu.h>
12557
12558 /*
12559 * low level task data that entry.S needs immediate access to
12560 @@ -24,7 +25,6 @@ struct exec_domain;
12561 #include <linux/atomic.h>
12562
12563 struct thread_info {
12564 - struct task_struct *task; /* main task structure */
12565 struct exec_domain *exec_domain; /* execution domain */
12566 __u32 flags; /* low level flags */
12567 __u32 status; /* thread synchronous flags */
12568 @@ -34,19 +34,13 @@ struct thread_info {
12569 mm_segment_t addr_limit;
12570 struct restart_block restart_block;
12571 void __user *sysenter_return;
12572 -#ifdef CONFIG_X86_32
12573 - unsigned long previous_esp; /* ESP of the previous stack in
12574 - case of nested (IRQ) stacks
12575 - */
12576 - __u8 supervisor_stack[0];
12577 -#endif
12578 + unsigned long lowest_stack;
12579 unsigned int sig_on_uaccess_error:1;
12580 unsigned int uaccess_err:1; /* uaccess failed */
12581 };
12582
12583 -#define INIT_THREAD_INFO(tsk) \
12584 +#define INIT_THREAD_INFO \
12585 { \
12586 - .task = &tsk, \
12587 .exec_domain = &default_exec_domain, \
12588 .flags = 0, \
12589 .cpu = 0, \
12590 @@ -57,7 +51,7 @@ struct thread_info {
12591 }, \
12592 }
12593
12594 -#define init_thread_info (init_thread_union.thread_info)
12595 +#define init_thread_info (init_thread_union.stack)
12596 #define init_stack (init_thread_union.stack)
12597
12598 #else /* !__ASSEMBLY__ */
12599 @@ -98,6 +92,7 @@ struct thread_info {
12600 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12601 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12602 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12603 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12604
12605 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12606 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12607 @@ -122,16 +117,18 @@ struct thread_info {
12608 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12609 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12610 #define _TIF_X32 (1 << TIF_X32)
12611 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12612
12613 /* work to do in syscall_trace_enter() */
12614 #define _TIF_WORK_SYSCALL_ENTRY \
12615 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12616 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12617 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12618 + _TIF_GRSEC_SETXID)
12619
12620 /* work to do in syscall_trace_leave() */
12621 #define _TIF_WORK_SYSCALL_EXIT \
12622 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12623 - _TIF_SYSCALL_TRACEPOINT)
12624 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12625
12626 /* work to do on interrupt/exception return */
12627 #define _TIF_WORK_MASK \
12628 @@ -141,7 +138,8 @@ struct thread_info {
12629
12630 /* work to do on any return to user space */
12631 #define _TIF_ALLWORK_MASK \
12632 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12633 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12634 + _TIF_GRSEC_SETXID)
12635
12636 /* Only used for 64 bit */
12637 #define _TIF_DO_NOTIFY_MASK \
12638 @@ -157,45 +155,40 @@ struct thread_info {
12639
12640 #define PREEMPT_ACTIVE 0x10000000
12641
12642 -#ifdef CONFIG_X86_32
12643 -
12644 -#define STACK_WARN (THREAD_SIZE/8)
12645 -/*
12646 - * macros/functions for gaining access to the thread information structure
12647 - *
12648 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12649 - */
12650 -#ifndef __ASSEMBLY__
12651 -
12652 -
12653 -/* how to get the current stack pointer from C */
12654 -register unsigned long current_stack_pointer asm("esp") __used;
12655 -
12656 -/* how to get the thread information struct from C */
12657 -static inline struct thread_info *current_thread_info(void)
12658 -{
12659 - return (struct thread_info *)
12660 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12661 -}
12662 -
12663 -#else /* !__ASSEMBLY__ */
12664 -
12665 +#ifdef __ASSEMBLY__
12666 /* how to get the thread information struct from ASM */
12667 #define GET_THREAD_INFO(reg) \
12668 - movl $-THREAD_SIZE, reg; \
12669 - andl %esp, reg
12670 + mov PER_CPU_VAR(current_tinfo), reg
12671
12672 /* use this one if reg already contains %esp */
12673 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12674 - andl $-THREAD_SIZE, reg
12675 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12676 +#else
12677 +/* how to get the thread information struct from C */
12678 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12679 +
12680 +static __always_inline struct thread_info *current_thread_info(void)
12681 +{
12682 + return this_cpu_read_stable(current_tinfo);
12683 +}
12684 +#endif
12685 +
12686 +#ifdef CONFIG_X86_32
12687 +
12688 +#define STACK_WARN (THREAD_SIZE/8)
12689 +/*
12690 + * macros/functions for gaining access to the thread information structure
12691 + *
12692 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12693 + */
12694 +#ifndef __ASSEMBLY__
12695 +
12696 +/* how to get the current stack pointer from C */
12697 +register unsigned long current_stack_pointer asm("esp") __used;
12698
12699 #endif
12700
12701 #else /* X86_32 */
12702
12703 -#include <asm/percpu.h>
12704 -#define KERNEL_STACK_OFFSET (5*8)
12705 -
12706 /*
12707 * macros/functions for gaining access to the thread information structure
12708 * preempt_count needs to be 1 initially, until the scheduler is functional.
12709 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12710 #ifndef __ASSEMBLY__
12711 DECLARE_PER_CPU(unsigned long, kernel_stack);
12712
12713 -static inline struct thread_info *current_thread_info(void)
12714 -{
12715 - struct thread_info *ti;
12716 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12717 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12718 - return ti;
12719 -}
12720 -
12721 -#else /* !__ASSEMBLY__ */
12722 -
12723 -/* how to get the thread information struct from ASM */
12724 -#define GET_THREAD_INFO(reg) \
12725 - movq PER_CPU_VAR(kernel_stack),reg ; \
12726 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12727 -
12728 -/*
12729 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12730 - * a certain register (to be used in assembler memory operands).
12731 - */
12732 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12733 -
12734 +/* how to get the current stack pointer from C */
12735 +register unsigned long current_stack_pointer asm("rsp") __used;
12736 #endif
12737
12738 #endif /* !X86_32 */
12739 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12740 extern void arch_task_cache_init(void);
12741 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12742 extern void arch_release_task_struct(struct task_struct *tsk);
12743 +
12744 +#define __HAVE_THREAD_FUNCTIONS
12745 +#define task_thread_info(task) (&(task)->tinfo)
12746 +#define task_stack_page(task) ((task)->stack)
12747 +#define setup_thread_stack(p, org) do {} while (0)
12748 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12749 +
12750 #endif
12751 #endif /* _ASM_X86_THREAD_INFO_H */
12752 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12753 index e1f3a17..1ab364d 100644
12754 --- a/arch/x86/include/asm/uaccess.h
12755 +++ b/arch/x86/include/asm/uaccess.h
12756 @@ -7,12 +7,15 @@
12757 #include <linux/compiler.h>
12758 #include <linux/thread_info.h>
12759 #include <linux/string.h>
12760 +#include <linux/sched.h>
12761 #include <asm/asm.h>
12762 #include <asm/page.h>
12763
12764 #define VERIFY_READ 0
12765 #define VERIFY_WRITE 1
12766
12767 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12768 +
12769 /*
12770 * The fs value determines whether argument validity checking should be
12771 * performed or not. If get_fs() == USER_DS, checking is performed, with
12772 @@ -28,7 +31,12 @@
12773
12774 #define get_ds() (KERNEL_DS)
12775 #define get_fs() (current_thread_info()->addr_limit)
12776 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12777 +void __set_fs(mm_segment_t x);
12778 +void set_fs(mm_segment_t x);
12779 +#else
12780 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12781 +#endif
12782
12783 #define segment_eq(a, b) ((a).seg == (b).seg)
12784
12785 @@ -76,8 +84,33 @@
12786 * checks that the pointer is in the user space range - after calling
12787 * this function, memory access functions may still return -EFAULT.
12788 */
12789 -#define access_ok(type, addr, size) \
12790 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12791 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12792 +#define access_ok(type, addr, size) \
12793 +({ \
12794 + long __size = size; \
12795 + unsigned long __addr = (unsigned long)addr; \
12796 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12797 + unsigned long __end_ao = __addr + __size - 1; \
12798 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12799 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12800 + while(__addr_ao <= __end_ao) { \
12801 + char __c_ao; \
12802 + __addr_ao += PAGE_SIZE; \
12803 + if (__size > PAGE_SIZE) \
12804 + cond_resched(); \
12805 + if (__get_user(__c_ao, (char __user *)__addr)) \
12806 + break; \
12807 + if (type != VERIFY_WRITE) { \
12808 + __addr = __addr_ao; \
12809 + continue; \
12810 + } \
12811 + if (__put_user(__c_ao, (char __user *)__addr)) \
12812 + break; \
12813 + __addr = __addr_ao; \
12814 + } \
12815 + } \
12816 + __ret_ao; \
12817 +})
12818
12819 /*
12820 * The exception table consists of pairs of addresses relative to the
12821 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12822 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12823 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12824
12825 -
12826 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12827 +#define __copyuser_seg "gs;"
12828 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12829 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12830 +#else
12831 +#define __copyuser_seg
12832 +#define __COPYUSER_SET_ES
12833 +#define __COPYUSER_RESTORE_ES
12834 +#endif
12835
12836 #ifdef CONFIG_X86_32
12837 #define __put_user_asm_u64(x, addr, err, errret) \
12838 - asm volatile("1: movl %%eax,0(%2)\n" \
12839 - "2: movl %%edx,4(%2)\n" \
12840 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12841 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12842 "3:\n" \
12843 ".section .fixup,\"ax\"\n" \
12844 "4: movl %3,%0\n" \
12845 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12846 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12847
12848 #define __put_user_asm_ex_u64(x, addr) \
12849 - asm volatile("1: movl %%eax,0(%1)\n" \
12850 - "2: movl %%edx,4(%1)\n" \
12851 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12852 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12853 "3:\n" \
12854 _ASM_EXTABLE_EX(1b, 2b) \
12855 _ASM_EXTABLE_EX(2b, 3b) \
12856 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12857 __typeof__(*(ptr)) __pu_val; \
12858 __chk_user_ptr(ptr); \
12859 might_fault(); \
12860 - __pu_val = x; \
12861 + __pu_val = (x); \
12862 switch (sizeof(*(ptr))) { \
12863 case 1: \
12864 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12865 @@ -379,7 +420,7 @@ do { \
12866 } while (0)
12867
12868 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12869 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12870 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12871 "2:\n" \
12872 ".section .fixup,\"ax\"\n" \
12873 "3: mov %3,%0\n" \
12874 @@ -387,7 +428,7 @@ do { \
12875 " jmp 2b\n" \
12876 ".previous\n" \
12877 _ASM_EXTABLE(1b, 3b) \
12878 - : "=r" (err), ltype(x) \
12879 + : "=r" (err), ltype (x) \
12880 : "m" (__m(addr)), "i" (errret), "0" (err))
12881
12882 #define __get_user_size_ex(x, ptr, size) \
12883 @@ -412,7 +453,7 @@ do { \
12884 } while (0)
12885
12886 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12887 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12888 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12889 "2:\n" \
12890 _ASM_EXTABLE_EX(1b, 2b) \
12891 : ltype(x) : "m" (__m(addr)))
12892 @@ -429,13 +470,24 @@ do { \
12893 int __gu_err; \
12894 unsigned long __gu_val; \
12895 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12896 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12897 + (x) = (__typeof__(*(ptr)))__gu_val; \
12898 __gu_err; \
12899 })
12900
12901 /* FIXME: this hack is definitely wrong -AK */
12902 struct __large_struct { unsigned long buf[100]; };
12903 -#define __m(x) (*(struct __large_struct __user *)(x))
12904 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12905 +#define ____m(x) \
12906 +({ \
12907 + unsigned long ____x = (unsigned long)(x); \
12908 + if (____x < PAX_USER_SHADOW_BASE) \
12909 + ____x += PAX_USER_SHADOW_BASE; \
12910 + (void __user *)____x; \
12911 +})
12912 +#else
12913 +#define ____m(x) (x)
12914 +#endif
12915 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12916
12917 /*
12918 * Tell gcc we read from memory instead of writing: this is because
12919 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12920 * aliasing issues.
12921 */
12922 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12923 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12924 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12925 "2:\n" \
12926 ".section .fixup,\"ax\"\n" \
12927 "3: mov %3,%0\n" \
12928 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12929 ".previous\n" \
12930 _ASM_EXTABLE(1b, 3b) \
12931 : "=r"(err) \
12932 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12933 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12934
12935 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12936 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12937 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12938 "2:\n" \
12939 _ASM_EXTABLE_EX(1b, 2b) \
12940 : : ltype(x), "m" (__m(addr)))
12941 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12942 * On error, the variable @x is set to zero.
12943 */
12944
12945 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12946 +#define __get_user(x, ptr) get_user((x), (ptr))
12947 +#else
12948 #define __get_user(x, ptr) \
12949 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12950 +#endif
12951
12952 /**
12953 * __put_user: - Write a simple value into user space, with less checking.
12954 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12955 * Returns zero on success, or -EFAULT on error.
12956 */
12957
12958 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12959 +#define __put_user(x, ptr) put_user((x), (ptr))
12960 +#else
12961 #define __put_user(x, ptr) \
12962 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12963 +#endif
12964
12965 #define __get_user_unaligned __get_user
12966 #define __put_user_unaligned __put_user
12967 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12968 #define get_user_ex(x, ptr) do { \
12969 unsigned long __gue_val; \
12970 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12971 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12972 + (x) = (__typeof__(*(ptr)))__gue_val; \
12973 } while (0)
12974
12975 #ifdef CONFIG_X86_WP_WORKS_OK
12976 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12977 index 576e39b..ccd0a39 100644
12978 --- a/arch/x86/include/asm/uaccess_32.h
12979 +++ b/arch/x86/include/asm/uaccess_32.h
12980 @@ -11,15 +11,15 @@
12981 #include <asm/page.h>
12982
12983 unsigned long __must_check __copy_to_user_ll
12984 - (void __user *to, const void *from, unsigned long n);
12985 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12986 unsigned long __must_check __copy_from_user_ll
12987 - (void *to, const void __user *from, unsigned long n);
12988 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12989 unsigned long __must_check __copy_from_user_ll_nozero
12990 - (void *to, const void __user *from, unsigned long n);
12991 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12992 unsigned long __must_check __copy_from_user_ll_nocache
12993 - (void *to, const void __user *from, unsigned long n);
12994 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12995 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12996 - (void *to, const void __user *from, unsigned long n);
12997 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12998
12999 /**
13000 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
13001 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
13002 static __always_inline unsigned long __must_check
13003 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13004 {
13005 + if ((long)n < 0)
13006 + return n;
13007 +
13008 if (__builtin_constant_p(n)) {
13009 unsigned long ret;
13010
13011 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13012 return ret;
13013 }
13014 }
13015 + if (!__builtin_constant_p(n))
13016 + check_object_size(from, n, true);
13017 return __copy_to_user_ll(to, from, n);
13018 }
13019
13020 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
13021 __copy_to_user(void __user *to, const void *from, unsigned long n)
13022 {
13023 might_fault();
13024 +
13025 return __copy_to_user_inatomic(to, from, n);
13026 }
13027
13028 static __always_inline unsigned long
13029 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
13030 {
13031 + if ((long)n < 0)
13032 + return n;
13033 +
13034 /* Avoid zeroing the tail if the copy fails..
13035 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
13036 * but as the zeroing behaviour is only significant when n is not
13037 @@ -137,6 +146,10 @@ static __always_inline unsigned long
13038 __copy_from_user(void *to, const void __user *from, unsigned long n)
13039 {
13040 might_fault();
13041 +
13042 + if ((long)n < 0)
13043 + return n;
13044 +
13045 if (__builtin_constant_p(n)) {
13046 unsigned long ret;
13047
13048 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13049 return ret;
13050 }
13051 }
13052 + if (!__builtin_constant_p(n))
13053 + check_object_size(to, n, false);
13054 return __copy_from_user_ll(to, from, n);
13055 }
13056
13057 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13058 const void __user *from, unsigned long n)
13059 {
13060 might_fault();
13061 +
13062 + if ((long)n < 0)
13063 + return n;
13064 +
13065 if (__builtin_constant_p(n)) {
13066 unsigned long ret;
13067
13068 @@ -181,15 +200,19 @@ static __always_inline unsigned long
13069 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13070 unsigned long n)
13071 {
13072 - return __copy_from_user_ll_nocache_nozero(to, from, n);
13073 + if ((long)n < 0)
13074 + return n;
13075 +
13076 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13077 }
13078
13079 -unsigned long __must_check copy_to_user(void __user *to,
13080 - const void *from, unsigned long n);
13081 -unsigned long __must_check _copy_from_user(void *to,
13082 - const void __user *from,
13083 - unsigned long n);
13084 -
13085 +extern void copy_to_user_overflow(void)
13086 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13087 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13088 +#else
13089 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13090 +#endif
13091 +;
13092
13093 extern void copy_from_user_overflow(void)
13094 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13095 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13096 #endif
13097 ;
13098
13099 -static inline unsigned long __must_check copy_from_user(void *to,
13100 - const void __user *from,
13101 - unsigned long n)
13102 +/**
13103 + * copy_to_user: - Copy a block of data into user space.
13104 + * @to: Destination address, in user space.
13105 + * @from: Source address, in kernel space.
13106 + * @n: Number of bytes to copy.
13107 + *
13108 + * Context: User context only. This function may sleep.
13109 + *
13110 + * Copy data from kernel space to user space.
13111 + *
13112 + * Returns number of bytes that could not be copied.
13113 + * On success, this will be zero.
13114 + */
13115 +static inline unsigned long __must_check
13116 +copy_to_user(void __user *to, const void *from, unsigned long n)
13117 {
13118 - int sz = __compiletime_object_size(to);
13119 + size_t sz = __compiletime_object_size(from);
13120
13121 - if (likely(sz == -1 || sz >= n))
13122 - n = _copy_from_user(to, from, n);
13123 - else
13124 + if (unlikely(sz != (size_t)-1 && sz < n))
13125 + copy_to_user_overflow();
13126 + else if (access_ok(VERIFY_WRITE, to, n))
13127 + n = __copy_to_user(to, from, n);
13128 + return n;
13129 +}
13130 +
13131 +/**
13132 + * copy_from_user: - Copy a block of data from user space.
13133 + * @to: Destination address, in kernel space.
13134 + * @from: Source address, in user space.
13135 + * @n: Number of bytes to copy.
13136 + *
13137 + * Context: User context only. This function may sleep.
13138 + *
13139 + * Copy data from user space to kernel space.
13140 + *
13141 + * Returns number of bytes that could not be copied.
13142 + * On success, this will be zero.
13143 + *
13144 + * If some data could not be copied, this function will pad the copied
13145 + * data to the requested size using zero bytes.
13146 + */
13147 +static inline unsigned long __must_check
13148 +copy_from_user(void *to, const void __user *from, unsigned long n)
13149 +{
13150 + size_t sz = __compiletime_object_size(to);
13151 +
13152 + if (unlikely(sz != (size_t)-1 && sz < n))
13153 copy_from_user_overflow();
13154 -
13155 + else if (access_ok(VERIFY_READ, from, n))
13156 + n = __copy_from_user(to, from, n);
13157 + else if ((long)n > 0) {
13158 + if (!__builtin_constant_p(n))
13159 + check_object_size(to, n, false);
13160 + memset(to, 0, n);
13161 + }
13162 return n;
13163 }
13164
13165 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13166 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13167 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13168 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13169
13170 #endif /* _ASM_X86_UACCESS_32_H */
13171 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13172 index d8def8b..6052b20 100644
13173 --- a/arch/x86/include/asm/uaccess_64.h
13174 +++ b/arch/x86/include/asm/uaccess_64.h
13175 @@ -10,6 +10,9 @@
13176 #include <asm/alternative.h>
13177 #include <asm/cpufeature.h>
13178 #include <asm/page.h>
13179 +#include <asm/pgtable.h>
13180 +
13181 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13182
13183 /*
13184 * Copy To/From Userspace
13185 @@ -17,13 +20,13 @@
13186
13187 /* Handles exceptions in both to and from, but doesn't do access_ok */
13188 __must_check unsigned long
13189 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13190 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13191 __must_check unsigned long
13192 -copy_user_generic_string(void *to, const void *from, unsigned len);
13193 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13194 __must_check unsigned long
13195 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13196 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13197
13198 -static __always_inline __must_check unsigned long
13199 +static __always_inline __must_check __size_overflow(3) unsigned long
13200 copy_user_generic(void *to, const void *from, unsigned len)
13201 {
13202 unsigned ret;
13203 @@ -41,142 +44,205 @@ copy_user_generic(void *to, const void *from, unsigned len)
13204 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13205 "=d" (len)),
13206 "1" (to), "2" (from), "3" (len)
13207 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13208 + : "memory", "rcx", "r8", "r9", "r11");
13209 return ret;
13210 }
13211
13212 +static __always_inline __must_check unsigned long
13213 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13214 +static __always_inline __must_check unsigned long
13215 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13216 __must_check unsigned long
13217 -_copy_to_user(void __user *to, const void *from, unsigned len);
13218 -__must_check unsigned long
13219 -_copy_from_user(void *to, const void __user *from, unsigned len);
13220 -__must_check unsigned long
13221 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13222 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13223 +
13224 +extern void copy_to_user_overflow(void)
13225 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13226 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13227 +#else
13228 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13229 +#endif
13230 +;
13231 +
13232 +extern void copy_from_user_overflow(void)
13233 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13234 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13235 +#else
13236 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13237 +#endif
13238 +;
13239
13240 static inline unsigned long __must_check copy_from_user(void *to,
13241 const void __user *from,
13242 unsigned long n)
13243 {
13244 - int sz = __compiletime_object_size(to);
13245 -
13246 might_fault();
13247 - if (likely(sz == -1 || sz >= n))
13248 - n = _copy_from_user(to, from, n);
13249 -#ifdef CONFIG_DEBUG_VM
13250 - else
13251 - WARN(1, "Buffer overflow detected!\n");
13252 -#endif
13253 +
13254 + if (access_ok(VERIFY_READ, from, n))
13255 + n = __copy_from_user(to, from, n);
13256 + else if (n < INT_MAX) {
13257 + if (!__builtin_constant_p(n))
13258 + check_object_size(to, n, false);
13259 + memset(to, 0, n);
13260 + }
13261 return n;
13262 }
13263
13264 static __always_inline __must_check
13265 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13266 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13267 {
13268 might_fault();
13269
13270 - return _copy_to_user(dst, src, size);
13271 + if (access_ok(VERIFY_WRITE, dst, size))
13272 + size = __copy_to_user(dst, src, size);
13273 + return size;
13274 }
13275
13276 static __always_inline __must_check
13277 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13278 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13279 {
13280 - int ret = 0;
13281 + size_t sz = __compiletime_object_size(dst);
13282 + unsigned ret = 0;
13283
13284 might_fault();
13285 - if (!__builtin_constant_p(size))
13286 - return copy_user_generic(dst, (__force void *)src, size);
13287 +
13288 + if (size > INT_MAX)
13289 + return size;
13290 +
13291 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13292 + if (!__access_ok(VERIFY_READ, src, size))
13293 + return size;
13294 +#endif
13295 +
13296 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13297 + copy_from_user_overflow();
13298 + return size;
13299 + }
13300 +
13301 + if (!__builtin_constant_p(size)) {
13302 + check_object_size(dst, size, false);
13303 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13304 + }
13305 switch (size) {
13306 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13307 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13308 ret, "b", "b", "=q", 1);
13309 return ret;
13310 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13311 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13312 ret, "w", "w", "=r", 2);
13313 return ret;
13314 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13315 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13316 ret, "l", "k", "=r", 4);
13317 return ret;
13318 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13319 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13320 ret, "q", "", "=r", 8);
13321 return ret;
13322 case 10:
13323 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13324 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13325 ret, "q", "", "=r", 10);
13326 if (unlikely(ret))
13327 return ret;
13328 __get_user_asm(*(u16 *)(8 + (char *)dst),
13329 - (u16 __user *)(8 + (char __user *)src),
13330 + (const u16 __user *)(8 + (const char __user *)src),
13331 ret, "w", "w", "=r", 2);
13332 return ret;
13333 case 16:
13334 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13335 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13336 ret, "q", "", "=r", 16);
13337 if (unlikely(ret))
13338 return ret;
13339 __get_user_asm(*(u64 *)(8 + (char *)dst),
13340 - (u64 __user *)(8 + (char __user *)src),
13341 + (const u64 __user *)(8 + (const char __user *)src),
13342 ret, "q", "", "=r", 8);
13343 return ret;
13344 default:
13345 - return copy_user_generic(dst, (__force void *)src, size);
13346 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13347 }
13348 }
13349
13350 static __always_inline __must_check
13351 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13352 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13353 {
13354 - int ret = 0;
13355 + size_t sz = __compiletime_object_size(src);
13356 + unsigned ret = 0;
13357
13358 might_fault();
13359 - if (!__builtin_constant_p(size))
13360 - return copy_user_generic((__force void *)dst, src, size);
13361 +
13362 + if (size > INT_MAX)
13363 + return size;
13364 +
13365 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13366 + if (!__access_ok(VERIFY_WRITE, dst, size))
13367 + return size;
13368 +#endif
13369 +
13370 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13371 + copy_to_user_overflow();
13372 + return size;
13373 + }
13374 +
13375 + if (!__builtin_constant_p(size)) {
13376 + check_object_size(src, size, true);
13377 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13378 + }
13379 switch (size) {
13380 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13381 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13382 ret, "b", "b", "iq", 1);
13383 return ret;
13384 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13385 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13386 ret, "w", "w", "ir", 2);
13387 return ret;
13388 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13389 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13390 ret, "l", "k", "ir", 4);
13391 return ret;
13392 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13393 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13394 ret, "q", "", "er", 8);
13395 return ret;
13396 case 10:
13397 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13398 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13399 ret, "q", "", "er", 10);
13400 if (unlikely(ret))
13401 return ret;
13402 asm("":::"memory");
13403 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13404 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13405 ret, "w", "w", "ir", 2);
13406 return ret;
13407 case 16:
13408 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13409 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13410 ret, "q", "", "er", 16);
13411 if (unlikely(ret))
13412 return ret;
13413 asm("":::"memory");
13414 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13415 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13416 ret, "q", "", "er", 8);
13417 return ret;
13418 default:
13419 - return copy_user_generic((__force void *)dst, src, size);
13420 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13421 }
13422 }
13423
13424 static __always_inline __must_check
13425 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13426 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13427 {
13428 - int ret = 0;
13429 + unsigned ret = 0;
13430
13431 might_fault();
13432 +
13433 + if (size > INT_MAX)
13434 + return size;
13435 +
13436 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13437 + if (!__access_ok(VERIFY_READ, src, size))
13438 + return size;
13439 + if (!__access_ok(VERIFY_WRITE, dst, size))
13440 + return size;
13441 +#endif
13442 +
13443 if (!__builtin_constant_p(size))
13444 - return copy_user_generic((__force void *)dst,
13445 - (__force void *)src, size);
13446 + return copy_user_generic((__force_kernel void *)____m(dst),
13447 + (__force_kernel const void *)____m(src), size);
13448 switch (size) {
13449 case 1: {
13450 u8 tmp;
13451 - __get_user_asm(tmp, (u8 __user *)src,
13452 + __get_user_asm(tmp, (const u8 __user *)src,
13453 ret, "b", "b", "=q", 1);
13454 if (likely(!ret))
13455 __put_user_asm(tmp, (u8 __user *)dst,
13456 @@ -185,7 +251,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13457 }
13458 case 2: {
13459 u16 tmp;
13460 - __get_user_asm(tmp, (u16 __user *)src,
13461 + __get_user_asm(tmp, (const u16 __user *)src,
13462 ret, "w", "w", "=r", 2);
13463 if (likely(!ret))
13464 __put_user_asm(tmp, (u16 __user *)dst,
13465 @@ -195,7 +261,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13466
13467 case 4: {
13468 u32 tmp;
13469 - __get_user_asm(tmp, (u32 __user *)src,
13470 + __get_user_asm(tmp, (const u32 __user *)src,
13471 ret, "l", "k", "=r", 4);
13472 if (likely(!ret))
13473 __put_user_asm(tmp, (u32 __user *)dst,
13474 @@ -204,7 +270,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13475 }
13476 case 8: {
13477 u64 tmp;
13478 - __get_user_asm(tmp, (u64 __user *)src,
13479 + __get_user_asm(tmp, (const u64 __user *)src,
13480 ret, "q", "", "=r", 8);
13481 if (likely(!ret))
13482 __put_user_asm(tmp, (u64 __user *)dst,
13483 @@ -212,44 +278,65 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13484 return ret;
13485 }
13486 default:
13487 - return copy_user_generic((__force void *)dst,
13488 - (__force void *)src, size);
13489 + return copy_user_generic((__force_kernel void *)____m(dst),
13490 + (__force_kernel const void *)____m(src), size);
13491 }
13492 }
13493
13494 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13495 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13496 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13497 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13498
13499 static __must_check __always_inline int
13500 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13501 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13502 {
13503 - return copy_user_generic(dst, (__force const void *)src, size);
13504 + if (size > INT_MAX)
13505 + return size;
13506 +
13507 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13508 }
13509
13510 -static __must_check __always_inline int
13511 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13512 +static __must_check __always_inline unsigned long
13513 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13514 {
13515 - return copy_user_generic((__force void *)dst, src, size);
13516 + if (size > INT_MAX)
13517 + return size;
13518 +
13519 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13520 }
13521
13522 -extern long __copy_user_nocache(void *dst, const void __user *src,
13523 - unsigned size, int zerorest);
13524 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13525 + unsigned long size, int zerorest) __size_overflow(3);
13526
13527 -static inline int
13528 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13529 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13530 {
13531 might_sleep();
13532 +
13533 + if (size > INT_MAX)
13534 + return size;
13535 +
13536 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13537 + if (!__access_ok(VERIFY_READ, src, size))
13538 + return size;
13539 +#endif
13540 +
13541 return __copy_user_nocache(dst, src, size, 1);
13542 }
13543
13544 -static inline int
13545 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13546 - unsigned size)
13547 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13548 + unsigned long size)
13549 {
13550 + if (size > INT_MAX)
13551 + return size;
13552 +
13553 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13554 + if (!__access_ok(VERIFY_READ, src, size))
13555 + return size;
13556 +#endif
13557 +
13558 return __copy_user_nocache(dst, src, size, 0);
13559 }
13560
13561 -unsigned long
13562 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13563 +extern unsigned long
13564 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13565
13566 #endif /* _ASM_X86_UACCESS_64_H */
13567 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13568 index bb05228..d763d5b 100644
13569 --- a/arch/x86/include/asm/vdso.h
13570 +++ b/arch/x86/include/asm/vdso.h
13571 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13572 #define VDSO32_SYMBOL(base, name) \
13573 ({ \
13574 extern const char VDSO32_##name[]; \
13575 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13576 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13577 })
13578 #endif
13579
13580 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13581 index 5b238981..77fdd78 100644
13582 --- a/arch/x86/include/asm/word-at-a-time.h
13583 +++ b/arch/x86/include/asm/word-at-a-time.h
13584 @@ -11,7 +11,7 @@
13585 * and shift, for example.
13586 */
13587 struct word_at_a_time {
13588 - const unsigned long one_bits, high_bits;
13589 + unsigned long one_bits, high_bits;
13590 };
13591
13592 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13593 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13594 index 38155f6..e4184ba 100644
13595 --- a/arch/x86/include/asm/x86_init.h
13596 +++ b/arch/x86/include/asm/x86_init.h
13597 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13598 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13599 void (*find_smp_config)(void);
13600 void (*get_smp_config)(unsigned int early);
13601 -};
13602 +} __no_const;
13603
13604 /**
13605 * struct x86_init_resources - platform specific resource related ops
13606 @@ -43,7 +43,7 @@ struct x86_init_resources {
13607 void (*probe_roms)(void);
13608 void (*reserve_resources)(void);
13609 char *(*memory_setup)(void);
13610 -};
13611 +} __no_const;
13612
13613 /**
13614 * struct x86_init_irqs - platform specific interrupt setup
13615 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13616 void (*pre_vector_init)(void);
13617 void (*intr_init)(void);
13618 void (*trap_init)(void);
13619 -};
13620 +} __no_const;
13621
13622 /**
13623 * struct x86_init_oem - oem platform specific customizing functions
13624 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13625 struct x86_init_oem {
13626 void (*arch_setup)(void);
13627 void (*banner)(void);
13628 -};
13629 +} __no_const;
13630
13631 /**
13632 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13633 @@ -77,7 +77,7 @@ struct x86_init_oem {
13634 */
13635 struct x86_init_mapping {
13636 void (*pagetable_reserve)(u64 start, u64 end);
13637 -};
13638 +} __no_const;
13639
13640 /**
13641 * struct x86_init_paging - platform specific paging functions
13642 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13643 struct x86_init_paging {
13644 void (*pagetable_setup_start)(pgd_t *base);
13645 void (*pagetable_setup_done)(pgd_t *base);
13646 -};
13647 +} __no_const;
13648
13649 /**
13650 * struct x86_init_timers - platform specific timer setup
13651 @@ -102,7 +102,7 @@ struct x86_init_timers {
13652 void (*tsc_pre_init)(void);
13653 void (*timer_init)(void);
13654 void (*wallclock_init)(void);
13655 -};
13656 +} __no_const;
13657
13658 /**
13659 * struct x86_init_iommu - platform specific iommu setup
13660 @@ -110,7 +110,7 @@ struct x86_init_timers {
13661 */
13662 struct x86_init_iommu {
13663 int (*iommu_init)(void);
13664 -};
13665 +} __no_const;
13666
13667 /**
13668 * struct x86_init_pci - platform specific pci init functions
13669 @@ -124,7 +124,7 @@ struct x86_init_pci {
13670 int (*init)(void);
13671 void (*init_irq)(void);
13672 void (*fixup_irqs)(void);
13673 -};
13674 +} __no_const;
13675
13676 /**
13677 * struct x86_init_ops - functions for platform specific setup
13678 @@ -140,7 +140,7 @@ struct x86_init_ops {
13679 struct x86_init_timers timers;
13680 struct x86_init_iommu iommu;
13681 struct x86_init_pci pci;
13682 -};
13683 +} __no_const;
13684
13685 /**
13686 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13687 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13688 void (*setup_percpu_clockev)(void);
13689 void (*early_percpu_clock_init)(void);
13690 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13691 -};
13692 +} __no_const;
13693
13694 /**
13695 * struct x86_platform_ops - platform specific runtime functions
13696 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13697 void (*save_sched_clock_state)(void);
13698 void (*restore_sched_clock_state)(void);
13699 void (*apic_post_init)(void);
13700 -};
13701 +} __no_const;
13702
13703 struct pci_dev;
13704
13705 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13706 void (*teardown_msi_irq)(unsigned int irq);
13707 void (*teardown_msi_irqs)(struct pci_dev *dev);
13708 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13709 -};
13710 +} __no_const;
13711
13712 struct x86_io_apic_ops {
13713 void (*init) (void);
13714 unsigned int (*read) (unsigned int apic, unsigned int reg);
13715 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13716 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13717 -};
13718 +} __no_const;
13719
13720 extern struct x86_init_ops x86_init;
13721 extern struct x86_cpuinit_ops x86_cpuinit;
13722 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13723 index 8a1b6f9..d47ba6d 100644
13724 --- a/arch/x86/include/asm/xsave.h
13725 +++ b/arch/x86/include/asm/xsave.h
13726 @@ -65,6 +65,8 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13727 {
13728 int err;
13729
13730 + buf = (struct xsave_struct __user *)____m(buf);
13731 +
13732 /*
13733 * Clear the xsave header first, so that reserved fields are
13734 * initialized to zero.
13735 @@ -74,7 +76,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13736 if (unlikely(err))
13737 return -EFAULT;
13738
13739 - __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
13740 + __asm__ __volatile__("1:"
13741 + __copyuser_seg
13742 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
13743 "2:\n"
13744 ".section .fixup,\"ax\"\n"
13745 "3: movl $-1,%[err]\n"
13746 @@ -93,11 +97,13 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13747 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13748 {
13749 int err;
13750 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13751 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)____m(buf));
13752 u32 lmask = mask;
13753 u32 hmask = mask >> 32;
13754
13755 - __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13756 + __asm__ __volatile__("1:"
13757 + __copyuser_seg
13758 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13759 "2:\n"
13760 ".section .fixup,\"ax\"\n"
13761 "3: movl $-1,%[err]\n"
13762 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13763 index 1b8e5a0..354fd59 100644
13764 --- a/arch/x86/kernel/acpi/sleep.c
13765 +++ b/arch/x86/kernel/acpi/sleep.c
13766 @@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13767 #else /* CONFIG_64BIT */
13768 #ifdef CONFIG_SMP
13769 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13770 +
13771 + pax_open_kernel();
13772 early_gdt_descr.address =
13773 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13774 + pax_close_kernel();
13775 +
13776 initial_gs = per_cpu_offset(smp_processor_id());
13777 #endif
13778 initial_code = (unsigned long)wakeup_long64;
13779 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13780 index 13ab720..95d5442 100644
13781 --- a/arch/x86/kernel/acpi/wakeup_32.S
13782 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13783 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13784 # and restore the stack ... but you need gdt for this to work
13785 movl saved_context_esp, %esp
13786
13787 - movl %cs:saved_magic, %eax
13788 - cmpl $0x12345678, %eax
13789 + cmpl $0x12345678, saved_magic
13790 jne bogus_magic
13791
13792 # jump to place where we left off
13793 - movl saved_eip, %eax
13794 - jmp *%eax
13795 + jmp *(saved_eip)
13796
13797 bogus_magic:
13798 jmp bogus_magic
13799 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13800 index ced4534..3e75d69 100644
13801 --- a/arch/x86/kernel/alternative.c
13802 +++ b/arch/x86/kernel/alternative.c
13803 @@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13804 */
13805 for (a = start; a < end; a++) {
13806 instr = (u8 *)&a->instr_offset + a->instr_offset;
13807 +
13808 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13809 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13810 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13811 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13812 +#endif
13813 +
13814 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13815 BUG_ON(a->replacementlen > a->instrlen);
13816 BUG_ON(a->instrlen > sizeof(insnbuf));
13817 @@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13818 for (poff = start; poff < end; poff++) {
13819 u8 *ptr = (u8 *)poff + *poff;
13820
13821 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13822 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13823 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13824 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13825 +#endif
13826 +
13827 if (!*poff || ptr < text || ptr >= text_end)
13828 continue;
13829 /* turn DS segment override prefix into lock prefix */
13830 - if (*ptr == 0x3e)
13831 + if (*ktla_ktva(ptr) == 0x3e)
13832 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13833 };
13834 mutex_unlock(&text_mutex);
13835 @@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13836 for (poff = start; poff < end; poff++) {
13837 u8 *ptr = (u8 *)poff + *poff;
13838
13839 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13840 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13841 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13842 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13843 +#endif
13844 +
13845 if (!*poff || ptr < text || ptr >= text_end)
13846 continue;
13847 /* turn lock prefix into DS segment override prefix */
13848 - if (*ptr == 0xf0)
13849 + if (*ktla_ktva(ptr) == 0xf0)
13850 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13851 };
13852 mutex_unlock(&text_mutex);
13853 @@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13854
13855 BUG_ON(p->len > MAX_PATCH_LEN);
13856 /* prep the buffer with the original instructions */
13857 - memcpy(insnbuf, p->instr, p->len);
13858 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13859 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13860 (unsigned long)p->instr, p->len);
13861
13862 @@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13863 if (smp_alt_once)
13864 free_init_pages("SMP alternatives",
13865 (unsigned long)__smp_locks,
13866 - (unsigned long)__smp_locks_end);
13867 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13868
13869 restart_nmi();
13870 }
13871 @@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13872 * instructions. And on the local CPU you need to be protected again NMI or MCE
13873 * handlers seeing an inconsistent instruction while you patch.
13874 */
13875 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13876 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13877 size_t len)
13878 {
13879 unsigned long flags;
13880 local_irq_save(flags);
13881 - memcpy(addr, opcode, len);
13882 +
13883 + pax_open_kernel();
13884 + memcpy(ktla_ktva(addr), opcode, len);
13885 sync_core();
13886 + pax_close_kernel();
13887 +
13888 local_irq_restore(flags);
13889 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13890 that causes hangs on some VIA CPUs. */
13891 @@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13892 */
13893 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13894 {
13895 - unsigned long flags;
13896 - char *vaddr;
13897 + unsigned char *vaddr = ktla_ktva(addr);
13898 struct page *pages[2];
13899 - int i;
13900 + size_t i;
13901
13902 if (!core_kernel_text((unsigned long)addr)) {
13903 - pages[0] = vmalloc_to_page(addr);
13904 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13905 + pages[0] = vmalloc_to_page(vaddr);
13906 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13907 } else {
13908 - pages[0] = virt_to_page(addr);
13909 + pages[0] = virt_to_page(vaddr);
13910 WARN_ON(!PageReserved(pages[0]));
13911 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13912 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13913 }
13914 BUG_ON(!pages[0]);
13915 - local_irq_save(flags);
13916 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13917 - if (pages[1])
13918 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13919 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13920 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13921 - clear_fixmap(FIX_TEXT_POKE0);
13922 - if (pages[1])
13923 - clear_fixmap(FIX_TEXT_POKE1);
13924 - local_flush_tlb();
13925 - sync_core();
13926 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13927 - that causes hangs on some VIA CPUs. */
13928 + text_poke_early(addr, opcode, len);
13929 for (i = 0; i < len; i++)
13930 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13931 - local_irq_restore(flags);
13932 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13933 return addr;
13934 }
13935
13936 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13937 index 24deb30..94a3426 100644
13938 --- a/arch/x86/kernel/apic/apic.c
13939 +++ b/arch/x86/kernel/apic/apic.c
13940 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13941 /*
13942 * Debug level, exported for io_apic.c
13943 */
13944 -unsigned int apic_verbosity;
13945 +int apic_verbosity;
13946
13947 int pic_mode;
13948
13949 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13950 apic_write(APIC_ESR, 0);
13951 v1 = apic_read(APIC_ESR);
13952 ack_APIC_irq();
13953 - atomic_inc(&irq_err_count);
13954 + atomic_inc_unchecked(&irq_err_count);
13955
13956 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13957 smp_processor_id(), v0 , v1);
13958 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13959 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13960 /* Should happen once for each apic */
13961 WARN_ON((*drv)->eoi_write == eoi_write);
13962 - (*drv)->eoi_write = eoi_write;
13963 + pax_open_kernel();
13964 + *(void **)&(*drv)->eoi_write = eoi_write;
13965 + pax_close_kernel();
13966 }
13967 }
13968
13969 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13970 index c265593..137c4ac 100644
13971 --- a/arch/x86/kernel/apic/io_apic.c
13972 +++ b/arch/x86/kernel/apic/io_apic.c
13973 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13974 }
13975 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13976
13977 -void lock_vector_lock(void)
13978 +void lock_vector_lock(void) __acquires(vector_lock)
13979 {
13980 /* Used to the online set of cpus does not change
13981 * during assign_irq_vector.
13982 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13983 raw_spin_lock(&vector_lock);
13984 }
13985
13986 -void unlock_vector_lock(void)
13987 +void unlock_vector_lock(void) __releases(vector_lock)
13988 {
13989 raw_spin_unlock(&vector_lock);
13990 }
13991 @@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
13992 ack_APIC_irq();
13993 }
13994
13995 -atomic_t irq_mis_count;
13996 +atomic_unchecked_t irq_mis_count;
13997
13998 #ifdef CONFIG_GENERIC_PENDING_IRQ
13999 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
14000 @@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
14001 * at the cpu.
14002 */
14003 if (!(v & (1 << (i & 0x1f)))) {
14004 - atomic_inc(&irq_mis_count);
14005 + atomic_inc_unchecked(&irq_mis_count);
14006
14007 eoi_ioapic_irq(irq, cfg);
14008 }
14009 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14010 index d65464e..1035d31 100644
14011 --- a/arch/x86/kernel/apm_32.c
14012 +++ b/arch/x86/kernel/apm_32.c
14013 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
14014 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14015 * even though they are called in protected mode.
14016 */
14017 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14018 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14019 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14020
14021 static const char driver_version[] = "1.16ac"; /* no spaces */
14022 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14023 BUG_ON(cpu != 0);
14024 gdt = get_cpu_gdt_table(cpu);
14025 save_desc_40 = gdt[0x40 / 8];
14026 +
14027 + pax_open_kernel();
14028 gdt[0x40 / 8] = bad_bios_desc;
14029 + pax_close_kernel();
14030
14031 apm_irq_save(flags);
14032 APM_DO_SAVE_SEGS;
14033 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14034 &call->esi);
14035 APM_DO_RESTORE_SEGS;
14036 apm_irq_restore(flags);
14037 +
14038 + pax_open_kernel();
14039 gdt[0x40 / 8] = save_desc_40;
14040 + pax_close_kernel();
14041 +
14042 put_cpu();
14043
14044 return call->eax & 0xff;
14045 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14046 BUG_ON(cpu != 0);
14047 gdt = get_cpu_gdt_table(cpu);
14048 save_desc_40 = gdt[0x40 / 8];
14049 +
14050 + pax_open_kernel();
14051 gdt[0x40 / 8] = bad_bios_desc;
14052 + pax_close_kernel();
14053
14054 apm_irq_save(flags);
14055 APM_DO_SAVE_SEGS;
14056 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14057 &call->eax);
14058 APM_DO_RESTORE_SEGS;
14059 apm_irq_restore(flags);
14060 +
14061 + pax_open_kernel();
14062 gdt[0x40 / 8] = save_desc_40;
14063 + pax_close_kernel();
14064 +
14065 put_cpu();
14066 return error;
14067 }
14068 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14069 * code to that CPU.
14070 */
14071 gdt = get_cpu_gdt_table(0);
14072 +
14073 + pax_open_kernel();
14074 set_desc_base(&gdt[APM_CS >> 3],
14075 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14076 set_desc_base(&gdt[APM_CS_16 >> 3],
14077 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14078 set_desc_base(&gdt[APM_DS >> 3],
14079 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14080 + pax_close_kernel();
14081
14082 proc_create("apm", 0, NULL, &apm_file_ops);
14083
14084 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14085 index 68de2dc..1f3c720 100644
14086 --- a/arch/x86/kernel/asm-offsets.c
14087 +++ b/arch/x86/kernel/asm-offsets.c
14088 @@ -33,6 +33,8 @@ void common(void) {
14089 OFFSET(TI_status, thread_info, status);
14090 OFFSET(TI_addr_limit, thread_info, addr_limit);
14091 OFFSET(TI_preempt_count, thread_info, preempt_count);
14092 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14093 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14094
14095 BLANK();
14096 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14097 @@ -53,8 +55,26 @@ void common(void) {
14098 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14099 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14100 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14101 +
14102 +#ifdef CONFIG_PAX_KERNEXEC
14103 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14104 #endif
14105
14106 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14107 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14108 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14109 +#ifdef CONFIG_X86_64
14110 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14111 +#endif
14112 +#endif
14113 +
14114 +#endif
14115 +
14116 + BLANK();
14117 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14118 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14119 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14120 +
14121 #ifdef CONFIG_XEN
14122 BLANK();
14123 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14124 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14125 index 1b4754f..fbb4227 100644
14126 --- a/arch/x86/kernel/asm-offsets_64.c
14127 +++ b/arch/x86/kernel/asm-offsets_64.c
14128 @@ -76,6 +76,7 @@ int main(void)
14129 BLANK();
14130 #undef ENTRY
14131
14132 + DEFINE(TSS_size, sizeof(struct tss_struct));
14133 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14134 BLANK();
14135
14136 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14137 index d30a6a9..79becab 100644
14138 --- a/arch/x86/kernel/cpu/Makefile
14139 +++ b/arch/x86/kernel/cpu/Makefile
14140 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14141 CFLAGS_REMOVE_perf_event.o = -pg
14142 endif
14143
14144 -# Make sure load_percpu_segment has no stackprotector
14145 -nostackp := $(call cc-option, -fno-stack-protector)
14146 -CFLAGS_common.o := $(nostackp)
14147 -
14148 obj-y := intel_cacheinfo.o scattered.o topology.o
14149 obj-y += proc.o capflags.o powerflags.o common.o
14150 obj-y += vmware.o hypervisor.o mshyperv.o
14151 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14152 index e4da438..8b1c97c 100644
14153 --- a/arch/x86/kernel/cpu/amd.c
14154 +++ b/arch/x86/kernel/cpu/amd.c
14155 @@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14156 unsigned int size)
14157 {
14158 /* AMD errata T13 (order #21922) */
14159 - if ((c->x86 == 6)) {
14160 + if (c->x86 == 6) {
14161 /* Duron Rev A0 */
14162 if (c->x86_model == 3 && c->x86_mask == 0)
14163 size = 64;
14164 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14165 index a5fbc3c..2254849 100644
14166 --- a/arch/x86/kernel/cpu/common.c
14167 +++ b/arch/x86/kernel/cpu/common.c
14168 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14169
14170 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14171
14172 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14173 -#ifdef CONFIG_X86_64
14174 - /*
14175 - * We need valid kernel segments for data and code in long mode too
14176 - * IRET will check the segment types kkeil 2000/10/28
14177 - * Also sysret mandates a special GDT layout
14178 - *
14179 - * TLS descriptors are currently at a different place compared to i386.
14180 - * Hopefully nobody expects them at a fixed place (Wine?)
14181 - */
14182 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14183 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14184 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14185 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14186 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14187 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14188 -#else
14189 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14190 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14191 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14192 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14193 - /*
14194 - * Segments used for calling PnP BIOS have byte granularity.
14195 - * They code segments and data segments have fixed 64k limits,
14196 - * the transfer segment sizes are set at run time.
14197 - */
14198 - /* 32-bit code */
14199 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14200 - /* 16-bit code */
14201 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14202 - /* 16-bit data */
14203 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14204 - /* 16-bit data */
14205 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14206 - /* 16-bit data */
14207 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14208 - /*
14209 - * The APM segments have byte granularity and their bases
14210 - * are set at run time. All have 64k limits.
14211 - */
14212 - /* 32-bit code */
14213 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14214 - /* 16-bit code */
14215 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14216 - /* data */
14217 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14218 -
14219 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14220 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14221 - GDT_STACK_CANARY_INIT
14222 -#endif
14223 -} };
14224 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14225 -
14226 static int __init x86_xsave_setup(char *s)
14227 {
14228 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14229 @@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14230 {
14231 struct desc_ptr gdt_descr;
14232
14233 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14234 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14235 gdt_descr.size = GDT_SIZE - 1;
14236 load_gdt(&gdt_descr);
14237 /* Reload the per-cpu base */
14238 @@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14239 /* Filter out anything that depends on CPUID levels we don't have */
14240 filter_cpuid_features(c, true);
14241
14242 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14243 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14244 +#endif
14245 +
14246 /* If the model name is still unset, do table lookup. */
14247 if (!c->x86_model_id[0]) {
14248 const char *p;
14249 @@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14250 }
14251 __setup("clearcpuid=", setup_disablecpuid);
14252
14253 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14254 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14255 +
14256 #ifdef CONFIG_X86_64
14257 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14258 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14259 - (unsigned long) nmi_idt_table };
14260 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14261
14262 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14263 irq_stack_union) __aligned(PAGE_SIZE);
14264 @@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14265 EXPORT_PER_CPU_SYMBOL(current_task);
14266
14267 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14268 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14269 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14270 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14271
14272 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14273 @@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14274 {
14275 memset(regs, 0, sizeof(struct pt_regs));
14276 regs->fs = __KERNEL_PERCPU;
14277 - regs->gs = __KERNEL_STACK_CANARY;
14278 + savesegment(gs, regs->gs);
14279
14280 return regs;
14281 }
14282 @@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14283 int i;
14284
14285 cpu = stack_smp_processor_id();
14286 - t = &per_cpu(init_tss, cpu);
14287 + t = init_tss + cpu;
14288 oist = &per_cpu(orig_ist, cpu);
14289
14290 #ifdef CONFIG_NUMA
14291 @@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14292 switch_to_new_gdt(cpu);
14293 loadsegment(fs, 0);
14294
14295 - load_idt((const struct desc_ptr *)&idt_descr);
14296 + load_idt(&idt_descr);
14297
14298 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14299 syscall_init();
14300 @@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14301 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14302 barrier();
14303
14304 - x86_configure_nx();
14305 if (cpu != 0)
14306 enable_x2apic();
14307
14308 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14309 {
14310 int cpu = smp_processor_id();
14311 struct task_struct *curr = current;
14312 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14313 + struct tss_struct *t = init_tss + cpu;
14314 struct thread_struct *thread = &curr->thread;
14315
14316 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14317 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14318 index 0a4ce29..f211176 100644
14319 --- a/arch/x86/kernel/cpu/intel.c
14320 +++ b/arch/x86/kernel/cpu/intel.c
14321 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14322 * Update the IDT descriptor and reload the IDT so that
14323 * it uses the read-only mapped virtual address.
14324 */
14325 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14326 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14327 load_idt(&idt_descr);
14328 }
14329 #endif
14330 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14331 index 292d025..b520c94 100644
14332 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14333 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14334 @@ -45,6 +45,7 @@
14335 #include <asm/processor.h>
14336 #include <asm/mce.h>
14337 #include <asm/msr.h>
14338 +#include <asm/local.h>
14339
14340 #include "mce-internal.h"
14341
14342 @@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14343 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14344 m->cs, m->ip);
14345
14346 - if (m->cs == __KERNEL_CS)
14347 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14348 print_symbol("{%s}", m->ip);
14349 pr_cont("\n");
14350 }
14351 @@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14352
14353 #define PANIC_TIMEOUT 5 /* 5 seconds */
14354
14355 -static atomic_t mce_paniced;
14356 +static atomic_unchecked_t mce_paniced;
14357
14358 static int fake_panic;
14359 -static atomic_t mce_fake_paniced;
14360 +static atomic_unchecked_t mce_fake_paniced;
14361
14362 /* Panic in progress. Enable interrupts and wait for final IPI */
14363 static void wait_for_panic(void)
14364 @@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14365 /*
14366 * Make sure only one CPU runs in machine check panic
14367 */
14368 - if (atomic_inc_return(&mce_paniced) > 1)
14369 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14370 wait_for_panic();
14371 barrier();
14372
14373 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14374 console_verbose();
14375 } else {
14376 /* Don't log too much for fake panic */
14377 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14378 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14379 return;
14380 }
14381 /* First print corrected ones that are still unlogged */
14382 @@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14383 * might have been modified by someone else.
14384 */
14385 rmb();
14386 - if (atomic_read(&mce_paniced))
14387 + if (atomic_read_unchecked(&mce_paniced))
14388 wait_for_panic();
14389 if (!monarch_timeout)
14390 goto out;
14391 @@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14392 }
14393
14394 /* Call the installed machine check handler for this CPU setup. */
14395 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14396 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14397 unexpected_machine_check;
14398
14399 /*
14400 @@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14401 return;
14402 }
14403
14404 + pax_open_kernel();
14405 machine_check_vector = do_machine_check;
14406 + pax_close_kernel();
14407
14408 __mcheck_cpu_init_generic();
14409 __mcheck_cpu_init_vendor(c);
14410 @@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14411 */
14412
14413 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14414 -static int mce_chrdev_open_count; /* #times opened */
14415 +static local_t mce_chrdev_open_count; /* #times opened */
14416 static int mce_chrdev_open_exclu; /* already open exclusive? */
14417
14418 static int mce_chrdev_open(struct inode *inode, struct file *file)
14419 @@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14420 spin_lock(&mce_chrdev_state_lock);
14421
14422 if (mce_chrdev_open_exclu ||
14423 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14424 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14425 spin_unlock(&mce_chrdev_state_lock);
14426
14427 return -EBUSY;
14428 @@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14429
14430 if (file->f_flags & O_EXCL)
14431 mce_chrdev_open_exclu = 1;
14432 - mce_chrdev_open_count++;
14433 + local_inc(&mce_chrdev_open_count);
14434
14435 spin_unlock(&mce_chrdev_state_lock);
14436
14437 @@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14438 {
14439 spin_lock(&mce_chrdev_state_lock);
14440
14441 - mce_chrdev_open_count--;
14442 + local_dec(&mce_chrdev_open_count);
14443 mce_chrdev_open_exclu = 0;
14444
14445 spin_unlock(&mce_chrdev_state_lock);
14446 @@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14447 static void mce_reset(void)
14448 {
14449 cpu_missing = 0;
14450 - atomic_set(&mce_fake_paniced, 0);
14451 + atomic_set_unchecked(&mce_fake_paniced, 0);
14452 atomic_set(&mce_executing, 0);
14453 atomic_set(&mce_callin, 0);
14454 atomic_set(&global_nwo, 0);
14455 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14456 index 2d5454c..51987eb 100644
14457 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14458 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14459 @@ -11,6 +11,7 @@
14460 #include <asm/processor.h>
14461 #include <asm/mce.h>
14462 #include <asm/msr.h>
14463 +#include <asm/pgtable.h>
14464
14465 /* By default disabled */
14466 int mce_p5_enabled __read_mostly;
14467 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14468 if (!cpu_has(c, X86_FEATURE_MCE))
14469 return;
14470
14471 + pax_open_kernel();
14472 machine_check_vector = pentium_machine_check;
14473 + pax_close_kernel();
14474 /* Make sure the vector pointer is visible before we enable MCEs: */
14475 wmb();
14476
14477 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14478 index 2d7998f..17c9de1 100644
14479 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14480 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14481 @@ -10,6 +10,7 @@
14482 #include <asm/processor.h>
14483 #include <asm/mce.h>
14484 #include <asm/msr.h>
14485 +#include <asm/pgtable.h>
14486
14487 /* Machine check handler for WinChip C6: */
14488 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14489 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14490 {
14491 u32 lo, hi;
14492
14493 + pax_open_kernel();
14494 machine_check_vector = winchip_machine_check;
14495 + pax_close_kernel();
14496 /* Make sure the vector pointer is visible before we enable MCEs: */
14497 wmb();
14498
14499 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14500 index 6b96110..0da73eb 100644
14501 --- a/arch/x86/kernel/cpu/mtrr/main.c
14502 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14503 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14504 u64 size_or_mask, size_and_mask;
14505 static bool mtrr_aps_delayed_init;
14506
14507 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14508 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14509
14510 const struct mtrr_ops *mtrr_if;
14511
14512 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14513 index df5e41f..816c719 100644
14514 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14515 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14516 @@ -25,7 +25,7 @@ struct mtrr_ops {
14517 int (*validate_add_page)(unsigned long base, unsigned long size,
14518 unsigned int type);
14519 int (*have_wrcomb)(void);
14520 -};
14521 +} __do_const;
14522
14523 extern int generic_get_free_region(unsigned long base, unsigned long size,
14524 int replace_reg);
14525 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14526 index 915b876..171f845 100644
14527 --- a/arch/x86/kernel/cpu/perf_event.c
14528 +++ b/arch/x86/kernel/cpu/perf_event.c
14529 @@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14530 if (idx > GDT_ENTRIES)
14531 return 0;
14532
14533 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14534 + desc = get_cpu_gdt_table(smp_processor_id());
14535 }
14536
14537 return get_desc_base(desc + idx);
14538 @@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14539 break;
14540
14541 perf_callchain_store(entry, frame.return_address);
14542 - fp = frame.next_frame;
14543 + fp = (const void __force_user *)frame.next_frame;
14544 }
14545 }
14546
14547 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14548 index 6bca492..36e4496 100644
14549 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14550 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14551 @@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14552 * v2 and above have a perf capabilities MSR
14553 */
14554 if (version > 1) {
14555 - u64 capabilities;
14556 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14557
14558 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14559 - x86_pmu.intel_cap.capabilities = capabilities;
14560 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14561 + x86_pmu.intel_cap.capabilities = capabilities;
14562 }
14563
14564 intel_ds_init();
14565 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14566 index 13ad899..f642b9a 100644
14567 --- a/arch/x86/kernel/crash.c
14568 +++ b/arch/x86/kernel/crash.c
14569 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14570 {
14571 #ifdef CONFIG_X86_32
14572 struct pt_regs fixed_regs;
14573 -#endif
14574
14575 -#ifdef CONFIG_X86_32
14576 - if (!user_mode_vm(regs)) {
14577 + if (!user_mode(regs)) {
14578 crash_fixup_ss_esp(&fixed_regs, regs);
14579 regs = &fixed_regs;
14580 }
14581 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14582 index 37250fe..bf2ec74 100644
14583 --- a/arch/x86/kernel/doublefault_32.c
14584 +++ b/arch/x86/kernel/doublefault_32.c
14585 @@ -11,7 +11,7 @@
14586
14587 #define DOUBLEFAULT_STACKSIZE (1024)
14588 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14589 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14590 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14591
14592 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14593
14594 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14595 unsigned long gdt, tss;
14596
14597 store_gdt(&gdt_desc);
14598 - gdt = gdt_desc.address;
14599 + gdt = (unsigned long)gdt_desc.address;
14600
14601 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14602
14603 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14604 /* 0x2 bit is always set */
14605 .flags = X86_EFLAGS_SF | 0x2,
14606 .sp = STACK_START,
14607 - .es = __USER_DS,
14608 + .es = __KERNEL_DS,
14609 .cs = __KERNEL_CS,
14610 .ss = __KERNEL_DS,
14611 - .ds = __USER_DS,
14612 + .ds = __KERNEL_DS,
14613 .fs = __KERNEL_PERCPU,
14614
14615 .__cr3 = __pa_nodebug(swapper_pg_dir),
14616 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14617 index ae42418b..787c16b 100644
14618 --- a/arch/x86/kernel/dumpstack.c
14619 +++ b/arch/x86/kernel/dumpstack.c
14620 @@ -2,6 +2,9 @@
14621 * Copyright (C) 1991, 1992 Linus Torvalds
14622 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14623 */
14624 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14625 +#define __INCLUDED_BY_HIDESYM 1
14626 +#endif
14627 #include <linux/kallsyms.h>
14628 #include <linux/kprobes.h>
14629 #include <linux/uaccess.h>
14630 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14631 static void
14632 print_ftrace_graph_addr(unsigned long addr, void *data,
14633 const struct stacktrace_ops *ops,
14634 - struct thread_info *tinfo, int *graph)
14635 + struct task_struct *task, int *graph)
14636 {
14637 - struct task_struct *task;
14638 unsigned long ret_addr;
14639 int index;
14640
14641 if (addr != (unsigned long)return_to_handler)
14642 return;
14643
14644 - task = tinfo->task;
14645 index = task->curr_ret_stack;
14646
14647 if (!task->ret_stack || index < *graph)
14648 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14649 static inline void
14650 print_ftrace_graph_addr(unsigned long addr, void *data,
14651 const struct stacktrace_ops *ops,
14652 - struct thread_info *tinfo, int *graph)
14653 + struct task_struct *task, int *graph)
14654 { }
14655 #endif
14656
14657 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14658 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14659 */
14660
14661 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14662 - void *p, unsigned int size, void *end)
14663 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14664 {
14665 - void *t = tinfo;
14666 if (end) {
14667 if (p < end && p >= (end-THREAD_SIZE))
14668 return 1;
14669 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14670 }
14671
14672 unsigned long
14673 -print_context_stack(struct thread_info *tinfo,
14674 +print_context_stack(struct task_struct *task, void *stack_start,
14675 unsigned long *stack, unsigned long bp,
14676 const struct stacktrace_ops *ops, void *data,
14677 unsigned long *end, int *graph)
14678 {
14679 struct stack_frame *frame = (struct stack_frame *)bp;
14680
14681 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14682 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14683 unsigned long addr;
14684
14685 addr = *stack;
14686 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14687 } else {
14688 ops->address(data, addr, 0);
14689 }
14690 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14691 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14692 }
14693 stack++;
14694 }
14695 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14696 EXPORT_SYMBOL_GPL(print_context_stack);
14697
14698 unsigned long
14699 -print_context_stack_bp(struct thread_info *tinfo,
14700 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14701 unsigned long *stack, unsigned long bp,
14702 const struct stacktrace_ops *ops, void *data,
14703 unsigned long *end, int *graph)
14704 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14705 struct stack_frame *frame = (struct stack_frame *)bp;
14706 unsigned long *ret_addr = &frame->return_address;
14707
14708 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14709 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14710 unsigned long addr = *ret_addr;
14711
14712 if (!__kernel_text_address(addr))
14713 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14714 ops->address(data, addr, 1);
14715 frame = frame->next_frame;
14716 ret_addr = &frame->return_address;
14717 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14718 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14719 }
14720
14721 return (unsigned long)frame;
14722 @@ -189,7 +188,7 @@ void dump_stack(void)
14723
14724 bp = stack_frame(current, NULL);
14725 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14726 - current->pid, current->comm, print_tainted(),
14727 + task_pid_nr(current), current->comm, print_tainted(),
14728 init_utsname()->release,
14729 (int)strcspn(init_utsname()->version, " "),
14730 init_utsname()->version);
14731 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14732 }
14733 EXPORT_SYMBOL_GPL(oops_begin);
14734
14735 +extern void gr_handle_kernel_exploit(void);
14736 +
14737 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14738 {
14739 if (regs && kexec_should_crash(current))
14740 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14741 panic("Fatal exception in interrupt");
14742 if (panic_on_oops)
14743 panic("Fatal exception");
14744 - do_exit(signr);
14745 +
14746 + gr_handle_kernel_exploit();
14747 +
14748 + do_group_exit(signr);
14749 }
14750
14751 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14752 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14753 print_modules();
14754 show_regs(regs);
14755 #ifdef CONFIG_X86_32
14756 - if (user_mode_vm(regs)) {
14757 + if (user_mode(regs)) {
14758 sp = regs->sp;
14759 ss = regs->ss & 0xffff;
14760 } else {
14761 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14762 unsigned long flags = oops_begin();
14763 int sig = SIGSEGV;
14764
14765 - if (!user_mode_vm(regs))
14766 + if (!user_mode(regs))
14767 report_bug(regs->ip, regs);
14768
14769 if (__die(str, regs, err))
14770 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14771 index 1038a41..db2c12b 100644
14772 --- a/arch/x86/kernel/dumpstack_32.c
14773 +++ b/arch/x86/kernel/dumpstack_32.c
14774 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14775 bp = stack_frame(task, regs);
14776
14777 for (;;) {
14778 - struct thread_info *context;
14779 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14780
14781 - context = (struct thread_info *)
14782 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14783 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14784 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14785
14786 - stack = (unsigned long *)context->previous_esp;
14787 - if (!stack)
14788 + if (stack_start == task_stack_page(task))
14789 break;
14790 + stack = *(unsigned long **)stack_start;
14791 if (ops->stack(data, "IRQ") < 0)
14792 break;
14793 touch_nmi_watchdog();
14794 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14795 {
14796 int i;
14797
14798 - __show_regs(regs, !user_mode_vm(regs));
14799 + __show_regs(regs, !user_mode(regs));
14800
14801 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14802 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14803 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14804 * When in-kernel, we also print out the stack and code at the
14805 * time of the fault..
14806 */
14807 - if (!user_mode_vm(regs)) {
14808 + if (!user_mode(regs)) {
14809 unsigned int code_prologue = code_bytes * 43 / 64;
14810 unsigned int code_len = code_bytes;
14811 unsigned char c;
14812 u8 *ip;
14813 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
14814
14815 pr_emerg("Stack:\n");
14816 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14817
14818 pr_emerg("Code:");
14819
14820 - ip = (u8 *)regs->ip - code_prologue;
14821 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14822 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14823 /* try starting at IP */
14824 - ip = (u8 *)regs->ip;
14825 + ip = (u8 *)regs->ip + cs_base;
14826 code_len = code_len - code_prologue + 1;
14827 }
14828 for (i = 0; i < code_len; i++, ip++) {
14829 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14830 pr_cont(" Bad EIP value.");
14831 break;
14832 }
14833 - if (ip == (u8 *)regs->ip)
14834 + if (ip == (u8 *)regs->ip + cs_base)
14835 pr_cont(" <%02x>", c);
14836 else
14837 pr_cont(" %02x", c);
14838 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14839 {
14840 unsigned short ud2;
14841
14842 + ip = ktla_ktva(ip);
14843 if (ip < PAGE_OFFSET)
14844 return 0;
14845 if (probe_kernel_address((unsigned short *)ip, ud2))
14846 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14847
14848 return ud2 == 0x0b0f;
14849 }
14850 +
14851 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14852 +void pax_check_alloca(unsigned long size)
14853 +{
14854 + unsigned long sp = (unsigned long)&sp, stack_left;
14855 +
14856 + /* all kernel stacks are of the same size */
14857 + stack_left = sp & (THREAD_SIZE - 1);
14858 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14859 +}
14860 +EXPORT_SYMBOL(pax_check_alloca);
14861 +#endif
14862 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14863 index b653675..51cc8c0 100644
14864 --- a/arch/x86/kernel/dumpstack_64.c
14865 +++ b/arch/x86/kernel/dumpstack_64.c
14866 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14867 unsigned long *irq_stack_end =
14868 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14869 unsigned used = 0;
14870 - struct thread_info *tinfo;
14871 int graph = 0;
14872 unsigned long dummy;
14873 + void *stack_start;
14874
14875 if (!task)
14876 task = current;
14877 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14878 * current stack address. If the stacks consist of nested
14879 * exceptions
14880 */
14881 - tinfo = task_thread_info(task);
14882 for (;;) {
14883 char *id;
14884 unsigned long *estack_end;
14885 +
14886 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14887 &used, &id);
14888
14889 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14890 if (ops->stack(data, id) < 0)
14891 break;
14892
14893 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14894 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14895 data, estack_end, &graph);
14896 ops->stack(data, "<EOE>");
14897 /*
14898 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14899 * second-to-last pointer (index -2 to end) in the
14900 * exception stack:
14901 */
14902 + if ((u16)estack_end[-1] != __KERNEL_DS)
14903 + goto out;
14904 stack = (unsigned long *) estack_end[-2];
14905 continue;
14906 }
14907 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14908 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14909 if (ops->stack(data, "IRQ") < 0)
14910 break;
14911 - bp = ops->walk_stack(tinfo, stack, bp,
14912 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14913 ops, data, irq_stack_end, &graph);
14914 /*
14915 * We link to the next stack (which would be
14916 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14917 /*
14918 * This handles the process stack:
14919 */
14920 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14921 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14922 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14923 +out:
14924 put_cpu();
14925 }
14926 EXPORT_SYMBOL(dump_trace);
14927 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
14928 {
14929 int i;
14930 unsigned long sp;
14931 - const int cpu = smp_processor_id();
14932 + const int cpu = raw_smp_processor_id();
14933 struct task_struct *cur = current;
14934
14935 sp = regs->sp;
14936 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14937
14938 return ud2 == 0x0b0f;
14939 }
14940 +
14941 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14942 +void pax_check_alloca(unsigned long size)
14943 +{
14944 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14945 + unsigned cpu, used;
14946 + char *id;
14947 +
14948 + /* check the process stack first */
14949 + stack_start = (unsigned long)task_stack_page(current);
14950 + stack_end = stack_start + THREAD_SIZE;
14951 + if (likely(stack_start <= sp && sp < stack_end)) {
14952 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14953 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14954 + return;
14955 + }
14956 +
14957 + cpu = get_cpu();
14958 +
14959 + /* check the irq stacks */
14960 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14961 + stack_start = stack_end - IRQ_STACK_SIZE;
14962 + if (stack_start <= sp && sp < stack_end) {
14963 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14964 + put_cpu();
14965 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14966 + return;
14967 + }
14968 +
14969 + /* check the exception stacks */
14970 + used = 0;
14971 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14972 + stack_start = stack_end - EXCEPTION_STKSZ;
14973 + if (stack_end && stack_start <= sp && sp < stack_end) {
14974 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14975 + put_cpu();
14976 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14977 + return;
14978 + }
14979 +
14980 + put_cpu();
14981 +
14982 + /* unknown stack */
14983 + BUG();
14984 +}
14985 +EXPORT_SYMBOL(pax_check_alloca);
14986 +#endif
14987 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14988 index 9b9f18b..9fcaa04 100644
14989 --- a/arch/x86/kernel/early_printk.c
14990 +++ b/arch/x86/kernel/early_printk.c
14991 @@ -7,6 +7,7 @@
14992 #include <linux/pci_regs.h>
14993 #include <linux/pci_ids.h>
14994 #include <linux/errno.h>
14995 +#include <linux/sched.h>
14996 #include <asm/io.h>
14997 #include <asm/processor.h>
14998 #include <asm/fcntl.h>
14999 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
15000 index 8f8e8ee..3617d6e 100644
15001 --- a/arch/x86/kernel/entry_32.S
15002 +++ b/arch/x86/kernel/entry_32.S
15003 @@ -176,13 +176,153 @@
15004 /*CFI_REL_OFFSET gs, PT_GS*/
15005 .endm
15006 .macro SET_KERNEL_GS reg
15007 +
15008 +#ifdef CONFIG_CC_STACKPROTECTOR
15009 movl $(__KERNEL_STACK_CANARY), \reg
15010 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15011 + movl $(__USER_DS), \reg
15012 +#else
15013 + xorl \reg, \reg
15014 +#endif
15015 +
15016 movl \reg, %gs
15017 .endm
15018
15019 #endif /* CONFIG_X86_32_LAZY_GS */
15020
15021 -.macro SAVE_ALL
15022 +.macro pax_enter_kernel
15023 +#ifdef CONFIG_PAX_KERNEXEC
15024 + call pax_enter_kernel
15025 +#endif
15026 +.endm
15027 +
15028 +.macro pax_exit_kernel
15029 +#ifdef CONFIG_PAX_KERNEXEC
15030 + call pax_exit_kernel
15031 +#endif
15032 +.endm
15033 +
15034 +#ifdef CONFIG_PAX_KERNEXEC
15035 +ENTRY(pax_enter_kernel)
15036 +#ifdef CONFIG_PARAVIRT
15037 + pushl %eax
15038 + pushl %ecx
15039 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15040 + mov %eax, %esi
15041 +#else
15042 + mov %cr0, %esi
15043 +#endif
15044 + bts $16, %esi
15045 + jnc 1f
15046 + mov %cs, %esi
15047 + cmp $__KERNEL_CS, %esi
15048 + jz 3f
15049 + ljmp $__KERNEL_CS, $3f
15050 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15051 +2:
15052 +#ifdef CONFIG_PARAVIRT
15053 + mov %esi, %eax
15054 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15055 +#else
15056 + mov %esi, %cr0
15057 +#endif
15058 +3:
15059 +#ifdef CONFIG_PARAVIRT
15060 + popl %ecx
15061 + popl %eax
15062 +#endif
15063 + ret
15064 +ENDPROC(pax_enter_kernel)
15065 +
15066 +ENTRY(pax_exit_kernel)
15067 +#ifdef CONFIG_PARAVIRT
15068 + pushl %eax
15069 + pushl %ecx
15070 +#endif
15071 + mov %cs, %esi
15072 + cmp $__KERNEXEC_KERNEL_CS, %esi
15073 + jnz 2f
15074 +#ifdef CONFIG_PARAVIRT
15075 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15076 + mov %eax, %esi
15077 +#else
15078 + mov %cr0, %esi
15079 +#endif
15080 + btr $16, %esi
15081 + ljmp $__KERNEL_CS, $1f
15082 +1:
15083 +#ifdef CONFIG_PARAVIRT
15084 + mov %esi, %eax
15085 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15086 +#else
15087 + mov %esi, %cr0
15088 +#endif
15089 +2:
15090 +#ifdef CONFIG_PARAVIRT
15091 + popl %ecx
15092 + popl %eax
15093 +#endif
15094 + ret
15095 +ENDPROC(pax_exit_kernel)
15096 +#endif
15097 +
15098 +.macro pax_erase_kstack
15099 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15100 + call pax_erase_kstack
15101 +#endif
15102 +.endm
15103 +
15104 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15105 +/*
15106 + * ebp: thread_info
15107 + */
15108 +ENTRY(pax_erase_kstack)
15109 + pushl %edi
15110 + pushl %ecx
15111 + pushl %eax
15112 +
15113 + mov TI_lowest_stack(%ebp), %edi
15114 + mov $-0xBEEF, %eax
15115 + std
15116 +
15117 +1: mov %edi, %ecx
15118 + and $THREAD_SIZE_asm - 1, %ecx
15119 + shr $2, %ecx
15120 + repne scasl
15121 + jecxz 2f
15122 +
15123 + cmp $2*16, %ecx
15124 + jc 2f
15125 +
15126 + mov $2*16, %ecx
15127 + repe scasl
15128 + jecxz 2f
15129 + jne 1b
15130 +
15131 +2: cld
15132 + mov %esp, %ecx
15133 + sub %edi, %ecx
15134 +
15135 + cmp $THREAD_SIZE_asm, %ecx
15136 + jb 3f
15137 + ud2
15138 +3:
15139 +
15140 + shr $2, %ecx
15141 + rep stosl
15142 +
15143 + mov TI_task_thread_sp0(%ebp), %edi
15144 + sub $128, %edi
15145 + mov %edi, TI_lowest_stack(%ebp)
15146 +
15147 + popl %eax
15148 + popl %ecx
15149 + popl %edi
15150 + ret
15151 +ENDPROC(pax_erase_kstack)
15152 +#endif
15153 +
15154 +.macro __SAVE_ALL _DS
15155 cld
15156 PUSH_GS
15157 pushl_cfi %fs
15158 @@ -205,7 +345,7 @@
15159 CFI_REL_OFFSET ecx, 0
15160 pushl_cfi %ebx
15161 CFI_REL_OFFSET ebx, 0
15162 - movl $(__USER_DS), %edx
15163 + movl $\_DS, %edx
15164 movl %edx, %ds
15165 movl %edx, %es
15166 movl $(__KERNEL_PERCPU), %edx
15167 @@ -213,6 +353,15 @@
15168 SET_KERNEL_GS %edx
15169 .endm
15170
15171 +.macro SAVE_ALL
15172 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15173 + __SAVE_ALL __KERNEL_DS
15174 + pax_enter_kernel
15175 +#else
15176 + __SAVE_ALL __USER_DS
15177 +#endif
15178 +.endm
15179 +
15180 .macro RESTORE_INT_REGS
15181 popl_cfi %ebx
15182 CFI_RESTORE ebx
15183 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15184 popfl_cfi
15185 jmp syscall_exit
15186 CFI_ENDPROC
15187 -END(ret_from_fork)
15188 +ENDPROC(ret_from_fork)
15189
15190 /*
15191 * Interrupt exit functions should be protected against kprobes
15192 @@ -329,7 +478,15 @@ ret_from_intr:
15193 andl $SEGMENT_RPL_MASK, %eax
15194 #endif
15195 cmpl $USER_RPL, %eax
15196 +
15197 +#ifdef CONFIG_PAX_KERNEXEC
15198 + jae resume_userspace
15199 +
15200 + pax_exit_kernel
15201 + jmp resume_kernel
15202 +#else
15203 jb resume_kernel # not returning to v8086 or userspace
15204 +#endif
15205
15206 ENTRY(resume_userspace)
15207 LOCKDEP_SYS_EXIT
15208 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15209 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15210 # int/exception return?
15211 jne work_pending
15212 - jmp restore_all
15213 -END(ret_from_exception)
15214 + jmp restore_all_pax
15215 +ENDPROC(ret_from_exception)
15216
15217 #ifdef CONFIG_PREEMPT
15218 ENTRY(resume_kernel)
15219 @@ -357,7 +514,7 @@ need_resched:
15220 jz restore_all
15221 call preempt_schedule_irq
15222 jmp need_resched
15223 -END(resume_kernel)
15224 +ENDPROC(resume_kernel)
15225 #endif
15226 CFI_ENDPROC
15227 /*
15228 @@ -391,28 +548,43 @@ sysenter_past_esp:
15229 /*CFI_REL_OFFSET cs, 0*/
15230 /*
15231 * Push current_thread_info()->sysenter_return to the stack.
15232 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15233 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15234 */
15235 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15236 + pushl_cfi $0
15237 CFI_REL_OFFSET eip, 0
15238
15239 pushl_cfi %eax
15240 SAVE_ALL
15241 + GET_THREAD_INFO(%ebp)
15242 + movl TI_sysenter_return(%ebp),%ebp
15243 + movl %ebp,PT_EIP(%esp)
15244 ENABLE_INTERRUPTS(CLBR_NONE)
15245
15246 /*
15247 * Load the potential sixth argument from user stack.
15248 * Careful about security.
15249 */
15250 + movl PT_OLDESP(%esp),%ebp
15251 +
15252 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15253 + mov PT_OLDSS(%esp),%ds
15254 +1: movl %ds:(%ebp),%ebp
15255 + push %ss
15256 + pop %ds
15257 +#else
15258 cmpl $__PAGE_OFFSET-3,%ebp
15259 jae syscall_fault
15260 1: movl (%ebp),%ebp
15261 +#endif
15262 +
15263 movl %ebp,PT_EBP(%esp)
15264 _ASM_EXTABLE(1b,syscall_fault)
15265
15266 GET_THREAD_INFO(%ebp)
15267
15268 +#ifdef CONFIG_PAX_RANDKSTACK
15269 + pax_erase_kstack
15270 +#endif
15271 +
15272 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15273 jnz sysenter_audit
15274 sysenter_do_call:
15275 @@ -427,12 +599,24 @@ sysenter_do_call:
15276 testl $_TIF_ALLWORK_MASK, %ecx
15277 jne sysexit_audit
15278 sysenter_exit:
15279 +
15280 +#ifdef CONFIG_PAX_RANDKSTACK
15281 + pushl_cfi %eax
15282 + movl %esp, %eax
15283 + call pax_randomize_kstack
15284 + popl_cfi %eax
15285 +#endif
15286 +
15287 + pax_erase_kstack
15288 +
15289 /* if something modifies registers it must also disable sysexit */
15290 movl PT_EIP(%esp), %edx
15291 movl PT_OLDESP(%esp), %ecx
15292 xorl %ebp,%ebp
15293 TRACE_IRQS_ON
15294 1: mov PT_FS(%esp), %fs
15295 +2: mov PT_DS(%esp), %ds
15296 +3: mov PT_ES(%esp), %es
15297 PTGS_TO_GS
15298 ENABLE_INTERRUPTS_SYSEXIT
15299
15300 @@ -449,6 +633,9 @@ sysenter_audit:
15301 movl %eax,%edx /* 2nd arg: syscall number */
15302 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15303 call __audit_syscall_entry
15304 +
15305 + pax_erase_kstack
15306 +
15307 pushl_cfi %ebx
15308 movl PT_EAX(%esp),%eax /* reload syscall number */
15309 jmp sysenter_do_call
15310 @@ -474,10 +661,16 @@ sysexit_audit:
15311
15312 CFI_ENDPROC
15313 .pushsection .fixup,"ax"
15314 -2: movl $0,PT_FS(%esp)
15315 +4: movl $0,PT_FS(%esp)
15316 + jmp 1b
15317 +5: movl $0,PT_DS(%esp)
15318 + jmp 1b
15319 +6: movl $0,PT_ES(%esp)
15320 jmp 1b
15321 .popsection
15322 - _ASM_EXTABLE(1b,2b)
15323 + _ASM_EXTABLE(1b,4b)
15324 + _ASM_EXTABLE(2b,5b)
15325 + _ASM_EXTABLE(3b,6b)
15326 PTGS_TO_GS_EX
15327 ENDPROC(ia32_sysenter_target)
15328
15329 @@ -491,6 +684,11 @@ ENTRY(system_call)
15330 pushl_cfi %eax # save orig_eax
15331 SAVE_ALL
15332 GET_THREAD_INFO(%ebp)
15333 +
15334 +#ifdef CONFIG_PAX_RANDKSTACK
15335 + pax_erase_kstack
15336 +#endif
15337 +
15338 # system call tracing in operation / emulation
15339 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15340 jnz syscall_trace_entry
15341 @@ -509,6 +707,15 @@ syscall_exit:
15342 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15343 jne syscall_exit_work
15344
15345 +restore_all_pax:
15346 +
15347 +#ifdef CONFIG_PAX_RANDKSTACK
15348 + movl %esp, %eax
15349 + call pax_randomize_kstack
15350 +#endif
15351 +
15352 + pax_erase_kstack
15353 +
15354 restore_all:
15355 TRACE_IRQS_IRET
15356 restore_all_notrace:
15357 @@ -565,14 +772,34 @@ ldt_ss:
15358 * compensating for the offset by changing to the ESPFIX segment with
15359 * a base address that matches for the difference.
15360 */
15361 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15362 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15363 mov %esp, %edx /* load kernel esp */
15364 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15365 mov %dx, %ax /* eax: new kernel esp */
15366 sub %eax, %edx /* offset (low word is 0) */
15367 +#ifdef CONFIG_SMP
15368 + movl PER_CPU_VAR(cpu_number), %ebx
15369 + shll $PAGE_SHIFT_asm, %ebx
15370 + addl $cpu_gdt_table, %ebx
15371 +#else
15372 + movl $cpu_gdt_table, %ebx
15373 +#endif
15374 shr $16, %edx
15375 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15376 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15377 +
15378 +#ifdef CONFIG_PAX_KERNEXEC
15379 + mov %cr0, %esi
15380 + btr $16, %esi
15381 + mov %esi, %cr0
15382 +#endif
15383 +
15384 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15385 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15386 +
15387 +#ifdef CONFIG_PAX_KERNEXEC
15388 + bts $16, %esi
15389 + mov %esi, %cr0
15390 +#endif
15391 +
15392 pushl_cfi $__ESPFIX_SS
15393 pushl_cfi %eax /* new kernel esp */
15394 /* Disable interrupts, but do not irqtrace this section: we
15395 @@ -601,35 +828,23 @@ work_resched:
15396 movl TI_flags(%ebp), %ecx
15397 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15398 # than syscall tracing?
15399 - jz restore_all
15400 + jz restore_all_pax
15401 testb $_TIF_NEED_RESCHED, %cl
15402 jnz work_resched
15403
15404 work_notifysig: # deal with pending signals and
15405 # notify-resume requests
15406 + movl %esp, %eax
15407 #ifdef CONFIG_VM86
15408 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15409 - movl %esp, %eax
15410 - jne work_notifysig_v86 # returning to kernel-space or
15411 + jz 1f # returning to kernel-space or
15412 # vm86-space
15413 - TRACE_IRQS_ON
15414 - ENABLE_INTERRUPTS(CLBR_NONE)
15415 - movb PT_CS(%esp), %bl
15416 - andb $SEGMENT_RPL_MASK, %bl
15417 - cmpb $USER_RPL, %bl
15418 - jb resume_kernel
15419 - xorl %edx, %edx
15420 - call do_notify_resume
15421 - jmp resume_userspace
15422
15423 - ALIGN
15424 -work_notifysig_v86:
15425 pushl_cfi %ecx # save ti_flags for do_notify_resume
15426 call save_v86_state # %eax contains pt_regs pointer
15427 popl_cfi %ecx
15428 movl %eax, %esp
15429 -#else
15430 - movl %esp, %eax
15431 +1:
15432 #endif
15433 TRACE_IRQS_ON
15434 ENABLE_INTERRUPTS(CLBR_NONE)
15435 @@ -640,7 +855,7 @@ work_notifysig_v86:
15436 xorl %edx, %edx
15437 call do_notify_resume
15438 jmp resume_userspace
15439 -END(work_pending)
15440 +ENDPROC(work_pending)
15441
15442 # perform syscall exit tracing
15443 ALIGN
15444 @@ -648,11 +863,14 @@ syscall_trace_entry:
15445 movl $-ENOSYS,PT_EAX(%esp)
15446 movl %esp, %eax
15447 call syscall_trace_enter
15448 +
15449 + pax_erase_kstack
15450 +
15451 /* What it returned is what we'll actually use. */
15452 cmpl $(NR_syscalls), %eax
15453 jnae syscall_call
15454 jmp syscall_exit
15455 -END(syscall_trace_entry)
15456 +ENDPROC(syscall_trace_entry)
15457
15458 # perform syscall exit tracing
15459 ALIGN
15460 @@ -665,20 +883,24 @@ syscall_exit_work:
15461 movl %esp, %eax
15462 call syscall_trace_leave
15463 jmp resume_userspace
15464 -END(syscall_exit_work)
15465 +ENDPROC(syscall_exit_work)
15466 CFI_ENDPROC
15467
15468 RING0_INT_FRAME # can't unwind into user space anyway
15469 syscall_fault:
15470 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15471 + push %ss
15472 + pop %ds
15473 +#endif
15474 GET_THREAD_INFO(%ebp)
15475 movl $-EFAULT,PT_EAX(%esp)
15476 jmp resume_userspace
15477 -END(syscall_fault)
15478 +ENDPROC(syscall_fault)
15479
15480 syscall_badsys:
15481 movl $-ENOSYS,PT_EAX(%esp)
15482 jmp resume_userspace
15483 -END(syscall_badsys)
15484 +ENDPROC(syscall_badsys)
15485 CFI_ENDPROC
15486 /*
15487 * End of kprobes section
15488 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15489 CFI_ENDPROC
15490 ENDPROC(ptregs_clone)
15491
15492 + ALIGN;
15493 +ENTRY(kernel_execve)
15494 + CFI_STARTPROC
15495 + pushl_cfi %ebp
15496 + sub $PT_OLDSS+4,%esp
15497 + pushl_cfi %edi
15498 + pushl_cfi %ecx
15499 + pushl_cfi %eax
15500 + lea 3*4(%esp),%edi
15501 + mov $PT_OLDSS/4+1,%ecx
15502 + xorl %eax,%eax
15503 + rep stosl
15504 + popl_cfi %eax
15505 + popl_cfi %ecx
15506 + popl_cfi %edi
15507 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15508 + pushl_cfi %esp
15509 + call sys_execve
15510 + add $4,%esp
15511 + CFI_ADJUST_CFA_OFFSET -4
15512 + GET_THREAD_INFO(%ebp)
15513 + test %eax,%eax
15514 + jz syscall_exit
15515 + add $PT_OLDSS+4,%esp
15516 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15517 + popl_cfi %ebp
15518 + ret
15519 + CFI_ENDPROC
15520 +ENDPROC(kernel_execve)
15521 +
15522 .macro FIXUP_ESPFIX_STACK
15523 /*
15524 * Switch back for ESPFIX stack to the normal zerobased stack
15525 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15526 * normal stack and adjusts ESP with the matching offset.
15527 */
15528 /* fixup the stack */
15529 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15530 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15531 +#ifdef CONFIG_SMP
15532 + movl PER_CPU_VAR(cpu_number), %ebx
15533 + shll $PAGE_SHIFT_asm, %ebx
15534 + addl $cpu_gdt_table, %ebx
15535 +#else
15536 + movl $cpu_gdt_table, %ebx
15537 +#endif
15538 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15539 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15540 shl $16, %eax
15541 addl %esp, %eax /* the adjusted stack pointer */
15542 pushl_cfi $__KERNEL_DS
15543 @@ -813,7 +1072,7 @@ vector=vector+1
15544 .endr
15545 2: jmp common_interrupt
15546 .endr
15547 -END(irq_entries_start)
15548 +ENDPROC(irq_entries_start)
15549
15550 .previous
15551 END(interrupt)
15552 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15553 pushl_cfi $do_coprocessor_error
15554 jmp error_code
15555 CFI_ENDPROC
15556 -END(coprocessor_error)
15557 +ENDPROC(coprocessor_error)
15558
15559 ENTRY(simd_coprocessor_error)
15560 RING0_INT_FRAME
15561 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15562 #endif
15563 jmp error_code
15564 CFI_ENDPROC
15565 -END(simd_coprocessor_error)
15566 +ENDPROC(simd_coprocessor_error)
15567
15568 ENTRY(device_not_available)
15569 RING0_INT_FRAME
15570 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15571 pushl_cfi $do_device_not_available
15572 jmp error_code
15573 CFI_ENDPROC
15574 -END(device_not_available)
15575 +ENDPROC(device_not_available)
15576
15577 #ifdef CONFIG_PARAVIRT
15578 ENTRY(native_iret)
15579 iret
15580 _ASM_EXTABLE(native_iret, iret_exc)
15581 -END(native_iret)
15582 +ENDPROC(native_iret)
15583
15584 ENTRY(native_irq_enable_sysexit)
15585 sti
15586 sysexit
15587 -END(native_irq_enable_sysexit)
15588 +ENDPROC(native_irq_enable_sysexit)
15589 #endif
15590
15591 ENTRY(overflow)
15592 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15593 pushl_cfi $do_overflow
15594 jmp error_code
15595 CFI_ENDPROC
15596 -END(overflow)
15597 +ENDPROC(overflow)
15598
15599 ENTRY(bounds)
15600 RING0_INT_FRAME
15601 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15602 pushl_cfi $do_bounds
15603 jmp error_code
15604 CFI_ENDPROC
15605 -END(bounds)
15606 +ENDPROC(bounds)
15607
15608 ENTRY(invalid_op)
15609 RING0_INT_FRAME
15610 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15611 pushl_cfi $do_invalid_op
15612 jmp error_code
15613 CFI_ENDPROC
15614 -END(invalid_op)
15615 +ENDPROC(invalid_op)
15616
15617 ENTRY(coprocessor_segment_overrun)
15618 RING0_INT_FRAME
15619 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15620 pushl_cfi $do_coprocessor_segment_overrun
15621 jmp error_code
15622 CFI_ENDPROC
15623 -END(coprocessor_segment_overrun)
15624 +ENDPROC(coprocessor_segment_overrun)
15625
15626 ENTRY(invalid_TSS)
15627 RING0_EC_FRAME
15628 pushl_cfi $do_invalid_TSS
15629 jmp error_code
15630 CFI_ENDPROC
15631 -END(invalid_TSS)
15632 +ENDPROC(invalid_TSS)
15633
15634 ENTRY(segment_not_present)
15635 RING0_EC_FRAME
15636 pushl_cfi $do_segment_not_present
15637 jmp error_code
15638 CFI_ENDPROC
15639 -END(segment_not_present)
15640 +ENDPROC(segment_not_present)
15641
15642 ENTRY(stack_segment)
15643 RING0_EC_FRAME
15644 pushl_cfi $do_stack_segment
15645 jmp error_code
15646 CFI_ENDPROC
15647 -END(stack_segment)
15648 +ENDPROC(stack_segment)
15649
15650 ENTRY(alignment_check)
15651 RING0_EC_FRAME
15652 pushl_cfi $do_alignment_check
15653 jmp error_code
15654 CFI_ENDPROC
15655 -END(alignment_check)
15656 +ENDPROC(alignment_check)
15657
15658 ENTRY(divide_error)
15659 RING0_INT_FRAME
15660 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15661 pushl_cfi $do_divide_error
15662 jmp error_code
15663 CFI_ENDPROC
15664 -END(divide_error)
15665 +ENDPROC(divide_error)
15666
15667 #ifdef CONFIG_X86_MCE
15668 ENTRY(machine_check)
15669 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15670 pushl_cfi machine_check_vector
15671 jmp error_code
15672 CFI_ENDPROC
15673 -END(machine_check)
15674 +ENDPROC(machine_check)
15675 #endif
15676
15677 ENTRY(spurious_interrupt_bug)
15678 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15679 pushl_cfi $do_spurious_interrupt_bug
15680 jmp error_code
15681 CFI_ENDPROC
15682 -END(spurious_interrupt_bug)
15683 +ENDPROC(spurious_interrupt_bug)
15684 /*
15685 * End of kprobes section
15686 */
15687 @@ -1102,7 +1361,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15688
15689 ENTRY(mcount)
15690 ret
15691 -END(mcount)
15692 +ENDPROC(mcount)
15693
15694 ENTRY(ftrace_caller)
15695 cmpl $0, function_trace_stop
15696 @@ -1131,7 +1390,7 @@ ftrace_graph_call:
15697 .globl ftrace_stub
15698 ftrace_stub:
15699 ret
15700 -END(ftrace_caller)
15701 +ENDPROC(ftrace_caller)
15702
15703 #else /* ! CONFIG_DYNAMIC_FTRACE */
15704
15705 @@ -1167,7 +1426,7 @@ trace:
15706 popl %ecx
15707 popl %eax
15708 jmp ftrace_stub
15709 -END(mcount)
15710 +ENDPROC(mcount)
15711 #endif /* CONFIG_DYNAMIC_FTRACE */
15712 #endif /* CONFIG_FUNCTION_TRACER */
15713
15714 @@ -1188,7 +1447,7 @@ ENTRY(ftrace_graph_caller)
15715 popl %ecx
15716 popl %eax
15717 ret
15718 -END(ftrace_graph_caller)
15719 +ENDPROC(ftrace_graph_caller)
15720
15721 .globl return_to_handler
15722 return_to_handler:
15723 @@ -1243,15 +1502,18 @@ error_code:
15724 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15725 REG_TO_PTGS %ecx
15726 SET_KERNEL_GS %ecx
15727 - movl $(__USER_DS), %ecx
15728 + movl $(__KERNEL_DS), %ecx
15729 movl %ecx, %ds
15730 movl %ecx, %es
15731 +
15732 + pax_enter_kernel
15733 +
15734 TRACE_IRQS_OFF
15735 movl %esp,%eax # pt_regs pointer
15736 call *%edi
15737 jmp ret_from_exception
15738 CFI_ENDPROC
15739 -END(page_fault)
15740 +ENDPROC(page_fault)
15741
15742 /*
15743 * Debug traps and NMI can happen at the one SYSENTER instruction
15744 @@ -1293,7 +1555,7 @@ debug_stack_correct:
15745 call do_debug
15746 jmp ret_from_exception
15747 CFI_ENDPROC
15748 -END(debug)
15749 +ENDPROC(debug)
15750
15751 /*
15752 * NMI is doubly nasty. It can happen _while_ we're handling
15753 @@ -1330,6 +1592,9 @@ nmi_stack_correct:
15754 xorl %edx,%edx # zero error code
15755 movl %esp,%eax # pt_regs pointer
15756 call do_nmi
15757 +
15758 + pax_exit_kernel
15759 +
15760 jmp restore_all_notrace
15761 CFI_ENDPROC
15762
15763 @@ -1366,12 +1631,15 @@ nmi_espfix_stack:
15764 FIXUP_ESPFIX_STACK # %eax == %esp
15765 xorl %edx,%edx # zero error code
15766 call do_nmi
15767 +
15768 + pax_exit_kernel
15769 +
15770 RESTORE_REGS
15771 lss 12+4(%esp), %esp # back to espfix stack
15772 CFI_ADJUST_CFA_OFFSET -24
15773 jmp irq_return
15774 CFI_ENDPROC
15775 -END(nmi)
15776 +ENDPROC(nmi)
15777
15778 ENTRY(int3)
15779 RING0_INT_FRAME
15780 @@ -1383,14 +1651,14 @@ ENTRY(int3)
15781 call do_int3
15782 jmp ret_from_exception
15783 CFI_ENDPROC
15784 -END(int3)
15785 +ENDPROC(int3)
15786
15787 ENTRY(general_protection)
15788 RING0_EC_FRAME
15789 pushl_cfi $do_general_protection
15790 jmp error_code
15791 CFI_ENDPROC
15792 -END(general_protection)
15793 +ENDPROC(general_protection)
15794
15795 #ifdef CONFIG_KVM_GUEST
15796 ENTRY(async_page_fault)
15797 @@ -1398,7 +1666,7 @@ ENTRY(async_page_fault)
15798 pushl_cfi $do_async_page_fault
15799 jmp error_code
15800 CFI_ENDPROC
15801 -END(async_page_fault)
15802 +ENDPROC(async_page_fault)
15803 #endif
15804
15805 /*
15806 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15807 index dcdd0ea..a520f76 100644
15808 --- a/arch/x86/kernel/entry_64.S
15809 +++ b/arch/x86/kernel/entry_64.S
15810 @@ -57,6 +57,8 @@
15811 #include <asm/percpu.h>
15812 #include <asm/asm.h>
15813 #include <linux/err.h>
15814 +#include <asm/pgtable.h>
15815 +#include <asm/alternative-asm.h>
15816
15817 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15818 #include <linux/elf-em.h>
15819 @@ -70,8 +72,9 @@
15820 #ifdef CONFIG_FUNCTION_TRACER
15821 #ifdef CONFIG_DYNAMIC_FTRACE
15822 ENTRY(mcount)
15823 + pax_force_retaddr
15824 retq
15825 -END(mcount)
15826 +ENDPROC(mcount)
15827
15828 ENTRY(ftrace_caller)
15829 cmpl $0, function_trace_stop
15830 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15831 #endif
15832
15833 GLOBAL(ftrace_stub)
15834 + pax_force_retaddr
15835 retq
15836 -END(ftrace_caller)
15837 +ENDPROC(ftrace_caller)
15838
15839 #else /* ! CONFIG_DYNAMIC_FTRACE */
15840 ENTRY(mcount)
15841 @@ -114,6 +118,7 @@ ENTRY(mcount)
15842 #endif
15843
15844 GLOBAL(ftrace_stub)
15845 + pax_force_retaddr
15846 retq
15847
15848 trace:
15849 @@ -123,12 +128,13 @@ trace:
15850 movq 8(%rbp), %rsi
15851 subq $MCOUNT_INSN_SIZE, %rdi
15852
15853 + pax_force_fptr ftrace_trace_function
15854 call *ftrace_trace_function
15855
15856 MCOUNT_RESTORE_FRAME
15857
15858 jmp ftrace_stub
15859 -END(mcount)
15860 +ENDPROC(mcount)
15861 #endif /* CONFIG_DYNAMIC_FTRACE */
15862 #endif /* CONFIG_FUNCTION_TRACER */
15863
15864 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15865
15866 MCOUNT_RESTORE_FRAME
15867
15868 + pax_force_retaddr
15869 retq
15870 -END(ftrace_graph_caller)
15871 +ENDPROC(ftrace_graph_caller)
15872
15873 GLOBAL(return_to_handler)
15874 subq $24, %rsp
15875 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15876 movq 8(%rsp), %rdx
15877 movq (%rsp), %rax
15878 addq $24, %rsp
15879 + pax_force_fptr %rdi
15880 jmp *%rdi
15881 #endif
15882
15883 @@ -180,6 +188,273 @@ ENTRY(native_usergs_sysret64)
15884 ENDPROC(native_usergs_sysret64)
15885 #endif /* CONFIG_PARAVIRT */
15886
15887 + .macro ljmpq sel, off
15888 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15889 + .byte 0x48; ljmp *1234f(%rip)
15890 + .pushsection .rodata
15891 + .align 16
15892 + 1234: .quad \off; .word \sel
15893 + .popsection
15894 +#else
15895 + pushq $\sel
15896 + pushq $\off
15897 + lretq
15898 +#endif
15899 + .endm
15900 +
15901 + .macro pax_enter_kernel
15902 + pax_set_fptr_mask
15903 +#ifdef CONFIG_PAX_KERNEXEC
15904 + call pax_enter_kernel
15905 +#endif
15906 + .endm
15907 +
15908 + .macro pax_exit_kernel
15909 +#ifdef CONFIG_PAX_KERNEXEC
15910 + call pax_exit_kernel
15911 +#endif
15912 + .endm
15913 +
15914 +#ifdef CONFIG_PAX_KERNEXEC
15915 +ENTRY(pax_enter_kernel)
15916 + pushq %rdi
15917 +
15918 +#ifdef CONFIG_PARAVIRT
15919 + PV_SAVE_REGS(CLBR_RDI)
15920 +#endif
15921 +
15922 + GET_CR0_INTO_RDI
15923 + bts $16,%rdi
15924 + jnc 3f
15925 + mov %cs,%edi
15926 + cmp $__KERNEL_CS,%edi
15927 + jnz 2f
15928 +1:
15929 +
15930 +#ifdef CONFIG_PARAVIRT
15931 + PV_RESTORE_REGS(CLBR_RDI)
15932 +#endif
15933 +
15934 + popq %rdi
15935 + pax_force_retaddr
15936 + retq
15937 +
15938 +2: ljmpq __KERNEL_CS,1f
15939 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15940 +4: SET_RDI_INTO_CR0
15941 + jmp 1b
15942 +ENDPROC(pax_enter_kernel)
15943 +
15944 +ENTRY(pax_exit_kernel)
15945 + pushq %rdi
15946 +
15947 +#ifdef CONFIG_PARAVIRT
15948 + PV_SAVE_REGS(CLBR_RDI)
15949 +#endif
15950 +
15951 + mov %cs,%rdi
15952 + cmp $__KERNEXEC_KERNEL_CS,%edi
15953 + jz 2f
15954 +1:
15955 +
15956 +#ifdef CONFIG_PARAVIRT
15957 + PV_RESTORE_REGS(CLBR_RDI);
15958 +#endif
15959 +
15960 + popq %rdi
15961 + pax_force_retaddr
15962 + retq
15963 +
15964 +2: GET_CR0_INTO_RDI
15965 + btr $16,%rdi
15966 + ljmpq __KERNEL_CS,3f
15967 +3: SET_RDI_INTO_CR0
15968 + jmp 1b
15969 +ENDPROC(pax_exit_kernel)
15970 +#endif
15971 +
15972 + .macro pax_enter_kernel_user
15973 + pax_set_fptr_mask
15974 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15975 + call pax_enter_kernel_user
15976 +#endif
15977 + .endm
15978 +
15979 + .macro pax_exit_kernel_user
15980 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15981 + call pax_exit_kernel_user
15982 +#endif
15983 +#ifdef CONFIG_PAX_RANDKSTACK
15984 + pushq %rax
15985 + call pax_randomize_kstack
15986 + popq %rax
15987 +#endif
15988 + .endm
15989 +
15990 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15991 +ENTRY(pax_enter_kernel_user)
15992 + pushq %rdi
15993 + pushq %rbx
15994 +
15995 +#ifdef CONFIG_PARAVIRT
15996 + PV_SAVE_REGS(CLBR_RDI)
15997 +#endif
15998 +
15999 + GET_CR3_INTO_RDI
16000 + mov %rdi,%rbx
16001 + add $__START_KERNEL_map,%rbx
16002 + sub phys_base(%rip),%rbx
16003 +
16004 +#ifdef CONFIG_PARAVIRT
16005 + pushq %rdi
16006 + cmpl $0, pv_info+PARAVIRT_enabled
16007 + jz 1f
16008 + i = 0
16009 + .rept USER_PGD_PTRS
16010 + mov i*8(%rbx),%rsi
16011 + mov $0,%sil
16012 + lea i*8(%rbx),%rdi
16013 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16014 + i = i + 1
16015 + .endr
16016 + jmp 2f
16017 +1:
16018 +#endif
16019 +
16020 + i = 0
16021 + .rept USER_PGD_PTRS
16022 + movb $0,i*8(%rbx)
16023 + i = i + 1
16024 + .endr
16025 +
16026 +#ifdef CONFIG_PARAVIRT
16027 +2: popq %rdi
16028 +#endif
16029 + SET_RDI_INTO_CR3
16030 +
16031 +#ifdef CONFIG_PAX_KERNEXEC
16032 + GET_CR0_INTO_RDI
16033 + bts $16,%rdi
16034 + SET_RDI_INTO_CR0
16035 +#endif
16036 +
16037 +#ifdef CONFIG_PARAVIRT
16038 + PV_RESTORE_REGS(CLBR_RDI)
16039 +#endif
16040 +
16041 + popq %rbx
16042 + popq %rdi
16043 + pax_force_retaddr
16044 + retq
16045 +ENDPROC(pax_enter_kernel_user)
16046 +
16047 +ENTRY(pax_exit_kernel_user)
16048 + push %rdi
16049 +
16050 +#ifdef CONFIG_PARAVIRT
16051 + pushq %rbx
16052 + PV_SAVE_REGS(CLBR_RDI)
16053 +#endif
16054 +
16055 +#ifdef CONFIG_PAX_KERNEXEC
16056 + GET_CR0_INTO_RDI
16057 + btr $16,%rdi
16058 + SET_RDI_INTO_CR0
16059 +#endif
16060 +
16061 + GET_CR3_INTO_RDI
16062 + add $__START_KERNEL_map,%rdi
16063 + sub phys_base(%rip),%rdi
16064 +
16065 +#ifdef CONFIG_PARAVIRT
16066 + cmpl $0, pv_info+PARAVIRT_enabled
16067 + jz 1f
16068 + mov %rdi,%rbx
16069 + i = 0
16070 + .rept USER_PGD_PTRS
16071 + mov i*8(%rbx),%rsi
16072 + mov $0x67,%sil
16073 + lea i*8(%rbx),%rdi
16074 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16075 + i = i + 1
16076 + .endr
16077 + jmp 2f
16078 +1:
16079 +#endif
16080 +
16081 + i = 0
16082 + .rept USER_PGD_PTRS
16083 + movb $0x67,i*8(%rdi)
16084 + i = i + 1
16085 + .endr
16086 +
16087 +#ifdef CONFIG_PARAVIRT
16088 +2: PV_RESTORE_REGS(CLBR_RDI)
16089 + popq %rbx
16090 +#endif
16091 +
16092 + popq %rdi
16093 + pax_force_retaddr
16094 + retq
16095 +ENDPROC(pax_exit_kernel_user)
16096 +#endif
16097 +
16098 +.macro pax_erase_kstack
16099 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16100 + call pax_erase_kstack
16101 +#endif
16102 +.endm
16103 +
16104 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16105 +ENTRY(pax_erase_kstack)
16106 + pushq %rdi
16107 + pushq %rcx
16108 + pushq %rax
16109 + pushq %r11
16110 +
16111 + GET_THREAD_INFO(%r11)
16112 + mov TI_lowest_stack(%r11), %rdi
16113 + mov $-0xBEEF, %rax
16114 + std
16115 +
16116 +1: mov %edi, %ecx
16117 + and $THREAD_SIZE_asm - 1, %ecx
16118 + shr $3, %ecx
16119 + repne scasq
16120 + jecxz 2f
16121 +
16122 + cmp $2*8, %ecx
16123 + jc 2f
16124 +
16125 + mov $2*8, %ecx
16126 + repe scasq
16127 + jecxz 2f
16128 + jne 1b
16129 +
16130 +2: cld
16131 + mov %esp, %ecx
16132 + sub %edi, %ecx
16133 +
16134 + cmp $THREAD_SIZE_asm, %rcx
16135 + jb 3f
16136 + ud2
16137 +3:
16138 +
16139 + shr $3, %ecx
16140 + rep stosq
16141 +
16142 + mov TI_task_thread_sp0(%r11), %rdi
16143 + sub $256, %rdi
16144 + mov %rdi, TI_lowest_stack(%r11)
16145 +
16146 + popq %r11
16147 + popq %rax
16148 + popq %rcx
16149 + popq %rdi
16150 + pax_force_retaddr
16151 + ret
16152 +ENDPROC(pax_erase_kstack)
16153 +#endif
16154
16155 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16156 #ifdef CONFIG_TRACE_IRQFLAGS
16157 @@ -271,8 +546,8 @@ ENDPROC(native_usergs_sysret64)
16158 .endm
16159
16160 .macro UNFAKE_STACK_FRAME
16161 - addq $8*6, %rsp
16162 - CFI_ADJUST_CFA_OFFSET -(6*8)
16163 + addq $8*6 + ARG_SKIP, %rsp
16164 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16165 .endm
16166
16167 /*
16168 @@ -359,7 +634,7 @@ ENDPROC(native_usergs_sysret64)
16169 movq %rsp, %rsi
16170
16171 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16172 - testl $3, CS-RBP(%rsi)
16173 + testb $3, CS-RBP(%rsi)
16174 je 1f
16175 SWAPGS
16176 /*
16177 @@ -394,9 +669,10 @@ ENTRY(save_rest)
16178 movq_cfi r15, R15+16
16179 movq %r11, 8(%rsp) /* return address */
16180 FIXUP_TOP_OF_STACK %r11, 16
16181 + pax_force_retaddr
16182 ret
16183 CFI_ENDPROC
16184 -END(save_rest)
16185 +ENDPROC(save_rest)
16186
16187 /* save complete stack frame */
16188 .pushsection .kprobes.text, "ax"
16189 @@ -425,9 +701,10 @@ ENTRY(save_paranoid)
16190 js 1f /* negative -> in kernel */
16191 SWAPGS
16192 xorl %ebx,%ebx
16193 -1: ret
16194 +1: pax_force_retaddr_bts
16195 + ret
16196 CFI_ENDPROC
16197 -END(save_paranoid)
16198 +ENDPROC(save_paranoid)
16199 .popsection
16200
16201 /*
16202 @@ -449,7 +726,7 @@ ENTRY(ret_from_fork)
16203
16204 RESTORE_REST
16205
16206 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16207 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16208 jz retint_restore_args
16209
16210 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16211 @@ -459,7 +736,7 @@ ENTRY(ret_from_fork)
16212 jmp ret_from_sys_call # go to the SYSRET fastpath
16213
16214 CFI_ENDPROC
16215 -END(ret_from_fork)
16216 +ENDPROC(ret_from_fork)
16217
16218 /*
16219 * System call entry. Up to 6 arguments in registers are supported.
16220 @@ -495,7 +772,7 @@ END(ret_from_fork)
16221 ENTRY(system_call)
16222 CFI_STARTPROC simple
16223 CFI_SIGNAL_FRAME
16224 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16225 + CFI_DEF_CFA rsp,0
16226 CFI_REGISTER rip,rcx
16227 /*CFI_REGISTER rflags,r11*/
16228 SWAPGS_UNSAFE_STACK
16229 @@ -508,16 +785,23 @@ GLOBAL(system_call_after_swapgs)
16230
16231 movq %rsp,PER_CPU_VAR(old_rsp)
16232 movq PER_CPU_VAR(kernel_stack),%rsp
16233 + SAVE_ARGS 8*6,0
16234 + pax_enter_kernel_user
16235 +
16236 +#ifdef CONFIG_PAX_RANDKSTACK
16237 + pax_erase_kstack
16238 +#endif
16239 +
16240 /*
16241 * No need to follow this irqs off/on section - it's straight
16242 * and short:
16243 */
16244 ENABLE_INTERRUPTS(CLBR_NONE)
16245 - SAVE_ARGS 8,0
16246 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16247 movq %rcx,RIP-ARGOFFSET(%rsp)
16248 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16249 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16250 + GET_THREAD_INFO(%rcx)
16251 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16252 jnz tracesys
16253 system_call_fastpath:
16254 #if __SYSCALL_MASK == ~0
16255 @@ -527,7 +811,7 @@ system_call_fastpath:
16256 cmpl $__NR_syscall_max,%eax
16257 #endif
16258 ja badsys
16259 - movq %r10,%rcx
16260 + movq R10-ARGOFFSET(%rsp),%rcx
16261 call *sys_call_table(,%rax,8) # XXX: rip relative
16262 movq %rax,RAX-ARGOFFSET(%rsp)
16263 /*
16264 @@ -541,10 +825,13 @@ sysret_check:
16265 LOCKDEP_SYS_EXIT
16266 DISABLE_INTERRUPTS(CLBR_NONE)
16267 TRACE_IRQS_OFF
16268 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16269 + GET_THREAD_INFO(%rcx)
16270 + movl TI_flags(%rcx),%edx
16271 andl %edi,%edx
16272 jnz sysret_careful
16273 CFI_REMEMBER_STATE
16274 + pax_exit_kernel_user
16275 + pax_erase_kstack
16276 /*
16277 * sysretq will re-enable interrupts:
16278 */
16279 @@ -596,14 +883,18 @@ badsys:
16280 * jump back to the normal fast path.
16281 */
16282 auditsys:
16283 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16284 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16285 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16286 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16287 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16288 movq %rax,%rsi /* 2nd arg: syscall number */
16289 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16290 call __audit_syscall_entry
16291 +
16292 + pax_erase_kstack
16293 +
16294 LOAD_ARGS 0 /* reload call-clobbered registers */
16295 + pax_set_fptr_mask
16296 jmp system_call_fastpath
16297
16298 /*
16299 @@ -624,7 +915,7 @@ sysret_audit:
16300 /* Do syscall tracing */
16301 tracesys:
16302 #ifdef CONFIG_AUDITSYSCALL
16303 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16304 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16305 jz auditsys
16306 #endif
16307 SAVE_REST
16308 @@ -632,12 +923,16 @@ tracesys:
16309 FIXUP_TOP_OF_STACK %rdi
16310 movq %rsp,%rdi
16311 call syscall_trace_enter
16312 +
16313 + pax_erase_kstack
16314 +
16315 /*
16316 * Reload arg registers from stack in case ptrace changed them.
16317 * We don't reload %rax because syscall_trace_enter() returned
16318 * the value it wants us to use in the table lookup.
16319 */
16320 LOAD_ARGS ARGOFFSET, 1
16321 + pax_set_fptr_mask
16322 RESTORE_REST
16323 #if __SYSCALL_MASK == ~0
16324 cmpq $__NR_syscall_max,%rax
16325 @@ -646,7 +941,7 @@ tracesys:
16326 cmpl $__NR_syscall_max,%eax
16327 #endif
16328 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16329 - movq %r10,%rcx /* fixup for C */
16330 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16331 call *sys_call_table(,%rax,8)
16332 movq %rax,RAX-ARGOFFSET(%rsp)
16333 /* Use IRET because user could have changed frame */
16334 @@ -667,7 +962,9 @@ GLOBAL(int_with_check)
16335 andl %edi,%edx
16336 jnz int_careful
16337 andl $~TS_COMPAT,TI_status(%rcx)
16338 - jmp retint_swapgs
16339 + pax_exit_kernel_user
16340 + pax_erase_kstack
16341 + jmp retint_swapgs_pax
16342
16343 /* Either reschedule or signal or syscall exit tracking needed. */
16344 /* First do a reschedule test. */
16345 @@ -713,7 +1010,7 @@ int_restore_rest:
16346 TRACE_IRQS_OFF
16347 jmp int_with_check
16348 CFI_ENDPROC
16349 -END(system_call)
16350 +ENDPROC(system_call)
16351
16352 /*
16353 * Certain special system calls that need to save a complete full stack frame.
16354 @@ -729,7 +1026,7 @@ ENTRY(\label)
16355 call \func
16356 jmp ptregscall_common
16357 CFI_ENDPROC
16358 -END(\label)
16359 +ENDPROC(\label)
16360 .endm
16361
16362 PTREGSCALL stub_clone, sys_clone, %r8
16363 @@ -747,9 +1044,10 @@ ENTRY(ptregscall_common)
16364 movq_cfi_restore R12+8, r12
16365 movq_cfi_restore RBP+8, rbp
16366 movq_cfi_restore RBX+8, rbx
16367 + pax_force_retaddr
16368 ret $REST_SKIP /* pop extended registers */
16369 CFI_ENDPROC
16370 -END(ptregscall_common)
16371 +ENDPROC(ptregscall_common)
16372
16373 ENTRY(stub_execve)
16374 CFI_STARTPROC
16375 @@ -764,7 +1062,7 @@ ENTRY(stub_execve)
16376 RESTORE_REST
16377 jmp int_ret_from_sys_call
16378 CFI_ENDPROC
16379 -END(stub_execve)
16380 +ENDPROC(stub_execve)
16381
16382 /*
16383 * sigreturn is special because it needs to restore all registers on return.
16384 @@ -782,7 +1080,7 @@ ENTRY(stub_rt_sigreturn)
16385 RESTORE_REST
16386 jmp int_ret_from_sys_call
16387 CFI_ENDPROC
16388 -END(stub_rt_sigreturn)
16389 +ENDPROC(stub_rt_sigreturn)
16390
16391 #ifdef CONFIG_X86_X32_ABI
16392 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16393 @@ -851,7 +1149,7 @@ vector=vector+1
16394 2: jmp common_interrupt
16395 .endr
16396 CFI_ENDPROC
16397 -END(irq_entries_start)
16398 +ENDPROC(irq_entries_start)
16399
16400 .previous
16401 END(interrupt)
16402 @@ -871,6 +1169,16 @@ END(interrupt)
16403 subq $ORIG_RAX-RBP, %rsp
16404 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16405 SAVE_ARGS_IRQ
16406 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16407 + testb $3, CS(%rdi)
16408 + jnz 1f
16409 + pax_enter_kernel
16410 + jmp 2f
16411 +1: pax_enter_kernel_user
16412 +2:
16413 +#else
16414 + pax_enter_kernel
16415 +#endif
16416 call \func
16417 .endm
16418
16419 @@ -902,7 +1210,7 @@ ret_from_intr:
16420
16421 exit_intr:
16422 GET_THREAD_INFO(%rcx)
16423 - testl $3,CS-ARGOFFSET(%rsp)
16424 + testb $3,CS-ARGOFFSET(%rsp)
16425 je retint_kernel
16426
16427 /* Interrupt came from user space */
16428 @@ -924,12 +1232,16 @@ retint_swapgs: /* return to user-space */
16429 * The iretq could re-enable interrupts:
16430 */
16431 DISABLE_INTERRUPTS(CLBR_ANY)
16432 + pax_exit_kernel_user
16433 +retint_swapgs_pax:
16434 TRACE_IRQS_IRETQ
16435 SWAPGS
16436 jmp restore_args
16437
16438 retint_restore_args: /* return to kernel space */
16439 DISABLE_INTERRUPTS(CLBR_ANY)
16440 + pax_exit_kernel
16441 + pax_force_retaddr (RIP-ARGOFFSET)
16442 /*
16443 * The iretq could re-enable interrupts:
16444 */
16445 @@ -1012,7 +1324,7 @@ ENTRY(retint_kernel)
16446 #endif
16447
16448 CFI_ENDPROC
16449 -END(common_interrupt)
16450 +ENDPROC(common_interrupt)
16451 /*
16452 * End of kprobes section
16453 */
16454 @@ -1029,7 +1341,7 @@ ENTRY(\sym)
16455 interrupt \do_sym
16456 jmp ret_from_intr
16457 CFI_ENDPROC
16458 -END(\sym)
16459 +ENDPROC(\sym)
16460 .endm
16461
16462 #ifdef CONFIG_SMP
16463 @@ -1084,12 +1396,22 @@ ENTRY(\sym)
16464 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16465 call error_entry
16466 DEFAULT_FRAME 0
16467 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16468 + testb $3, CS(%rsp)
16469 + jnz 1f
16470 + pax_enter_kernel
16471 + jmp 2f
16472 +1: pax_enter_kernel_user
16473 +2:
16474 +#else
16475 + pax_enter_kernel
16476 +#endif
16477 movq %rsp,%rdi /* pt_regs pointer */
16478 xorl %esi,%esi /* no error code */
16479 call \do_sym
16480 jmp error_exit /* %ebx: no swapgs flag */
16481 CFI_ENDPROC
16482 -END(\sym)
16483 +ENDPROC(\sym)
16484 .endm
16485
16486 .macro paranoidzeroentry sym do_sym
16487 @@ -1101,15 +1423,25 @@ ENTRY(\sym)
16488 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16489 call save_paranoid
16490 TRACE_IRQS_OFF
16491 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16492 + testb $3, CS(%rsp)
16493 + jnz 1f
16494 + pax_enter_kernel
16495 + jmp 2f
16496 +1: pax_enter_kernel_user
16497 +2:
16498 +#else
16499 + pax_enter_kernel
16500 +#endif
16501 movq %rsp,%rdi /* pt_regs pointer */
16502 xorl %esi,%esi /* no error code */
16503 call \do_sym
16504 jmp paranoid_exit /* %ebx: no swapgs flag */
16505 CFI_ENDPROC
16506 -END(\sym)
16507 +ENDPROC(\sym)
16508 .endm
16509
16510 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16511 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16512 .macro paranoidzeroentry_ist sym do_sym ist
16513 ENTRY(\sym)
16514 INTR_FRAME
16515 @@ -1119,14 +1451,30 @@ ENTRY(\sym)
16516 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16517 call save_paranoid
16518 TRACE_IRQS_OFF_DEBUG
16519 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16520 + testb $3, CS(%rsp)
16521 + jnz 1f
16522 + pax_enter_kernel
16523 + jmp 2f
16524 +1: pax_enter_kernel_user
16525 +2:
16526 +#else
16527 + pax_enter_kernel
16528 +#endif
16529 movq %rsp,%rdi /* pt_regs pointer */
16530 xorl %esi,%esi /* no error code */
16531 +#ifdef CONFIG_SMP
16532 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16533 + lea init_tss(%r12), %r12
16534 +#else
16535 + lea init_tss(%rip), %r12
16536 +#endif
16537 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16538 call \do_sym
16539 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16540 jmp paranoid_exit /* %ebx: no swapgs flag */
16541 CFI_ENDPROC
16542 -END(\sym)
16543 +ENDPROC(\sym)
16544 .endm
16545
16546 .macro errorentry sym do_sym
16547 @@ -1137,13 +1485,23 @@ ENTRY(\sym)
16548 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16549 call error_entry
16550 DEFAULT_FRAME 0
16551 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16552 + testb $3, CS(%rsp)
16553 + jnz 1f
16554 + pax_enter_kernel
16555 + jmp 2f
16556 +1: pax_enter_kernel_user
16557 +2:
16558 +#else
16559 + pax_enter_kernel
16560 +#endif
16561 movq %rsp,%rdi /* pt_regs pointer */
16562 movq ORIG_RAX(%rsp),%rsi /* get error code */
16563 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16564 call \do_sym
16565 jmp error_exit /* %ebx: no swapgs flag */
16566 CFI_ENDPROC
16567 -END(\sym)
16568 +ENDPROC(\sym)
16569 .endm
16570
16571 /* error code is on the stack already */
16572 @@ -1156,13 +1514,23 @@ ENTRY(\sym)
16573 call save_paranoid
16574 DEFAULT_FRAME 0
16575 TRACE_IRQS_OFF
16576 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16577 + testb $3, CS(%rsp)
16578 + jnz 1f
16579 + pax_enter_kernel
16580 + jmp 2f
16581 +1: pax_enter_kernel_user
16582 +2:
16583 +#else
16584 + pax_enter_kernel
16585 +#endif
16586 movq %rsp,%rdi /* pt_regs pointer */
16587 movq ORIG_RAX(%rsp),%rsi /* get error code */
16588 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16589 call \do_sym
16590 jmp paranoid_exit /* %ebx: no swapgs flag */
16591 CFI_ENDPROC
16592 -END(\sym)
16593 +ENDPROC(\sym)
16594 .endm
16595
16596 zeroentry divide_error do_divide_error
16597 @@ -1192,9 +1560,10 @@ gs_change:
16598 2: mfence /* workaround */
16599 SWAPGS
16600 popfq_cfi
16601 + pax_force_retaddr
16602 ret
16603 CFI_ENDPROC
16604 -END(native_load_gs_index)
16605 +ENDPROC(native_load_gs_index)
16606
16607 _ASM_EXTABLE(gs_change,bad_gs)
16608 .section .fixup,"ax"
16609 @@ -1213,13 +1582,14 @@ ENTRY(kernel_thread_helper)
16610 * Here we are in the child and the registers are set as they were
16611 * at kernel_thread() invocation in the parent.
16612 */
16613 + pax_force_fptr %rsi
16614 call *%rsi
16615 # exit
16616 mov %eax, %edi
16617 call do_exit
16618 ud2 # padding for call trace
16619 CFI_ENDPROC
16620 -END(kernel_thread_helper)
16621 +ENDPROC(kernel_thread_helper)
16622
16623 /*
16624 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16625 @@ -1246,11 +1616,11 @@ ENTRY(kernel_execve)
16626 RESTORE_REST
16627 testq %rax,%rax
16628 je int_ret_from_sys_call
16629 - RESTORE_ARGS
16630 UNFAKE_STACK_FRAME
16631 + pax_force_retaddr
16632 ret
16633 CFI_ENDPROC
16634 -END(kernel_execve)
16635 +ENDPROC(kernel_execve)
16636
16637 /* Call softirq on interrupt stack. Interrupts are off. */
16638 ENTRY(call_softirq)
16639 @@ -1268,9 +1638,10 @@ ENTRY(call_softirq)
16640 CFI_DEF_CFA_REGISTER rsp
16641 CFI_ADJUST_CFA_OFFSET -8
16642 decl PER_CPU_VAR(irq_count)
16643 + pax_force_retaddr
16644 ret
16645 CFI_ENDPROC
16646 -END(call_softirq)
16647 +ENDPROC(call_softirq)
16648
16649 #ifdef CONFIG_XEN
16650 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16651 @@ -1308,7 +1679,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16652 decl PER_CPU_VAR(irq_count)
16653 jmp error_exit
16654 CFI_ENDPROC
16655 -END(xen_do_hypervisor_callback)
16656 +ENDPROC(xen_do_hypervisor_callback)
16657
16658 /*
16659 * Hypervisor uses this for application faults while it executes.
16660 @@ -1367,7 +1738,7 @@ ENTRY(xen_failsafe_callback)
16661 SAVE_ALL
16662 jmp error_exit
16663 CFI_ENDPROC
16664 -END(xen_failsafe_callback)
16665 +ENDPROC(xen_failsafe_callback)
16666
16667 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16668 xen_hvm_callback_vector xen_evtchn_do_upcall
16669 @@ -1416,16 +1787,31 @@ ENTRY(paranoid_exit)
16670 TRACE_IRQS_OFF_DEBUG
16671 testl %ebx,%ebx /* swapgs needed? */
16672 jnz paranoid_restore
16673 - testl $3,CS(%rsp)
16674 + testb $3,CS(%rsp)
16675 jnz paranoid_userspace
16676 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16677 + pax_exit_kernel
16678 + TRACE_IRQS_IRETQ 0
16679 + SWAPGS_UNSAFE_STACK
16680 + RESTORE_ALL 8
16681 + pax_force_retaddr_bts
16682 + jmp irq_return
16683 +#endif
16684 paranoid_swapgs:
16685 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16686 + pax_exit_kernel_user
16687 +#else
16688 + pax_exit_kernel
16689 +#endif
16690 TRACE_IRQS_IRETQ 0
16691 SWAPGS_UNSAFE_STACK
16692 RESTORE_ALL 8
16693 jmp irq_return
16694 paranoid_restore:
16695 + pax_exit_kernel
16696 TRACE_IRQS_IRETQ_DEBUG 0
16697 RESTORE_ALL 8
16698 + pax_force_retaddr_bts
16699 jmp irq_return
16700 paranoid_userspace:
16701 GET_THREAD_INFO(%rcx)
16702 @@ -1454,7 +1840,7 @@ paranoid_schedule:
16703 TRACE_IRQS_OFF
16704 jmp paranoid_userspace
16705 CFI_ENDPROC
16706 -END(paranoid_exit)
16707 +ENDPROC(paranoid_exit)
16708
16709 /*
16710 * Exception entry point. This expects an error code/orig_rax on the stack.
16711 @@ -1481,12 +1867,13 @@ ENTRY(error_entry)
16712 movq_cfi r14, R14+8
16713 movq_cfi r15, R15+8
16714 xorl %ebx,%ebx
16715 - testl $3,CS+8(%rsp)
16716 + testb $3,CS+8(%rsp)
16717 je error_kernelspace
16718 error_swapgs:
16719 SWAPGS
16720 error_sti:
16721 TRACE_IRQS_OFF
16722 + pax_force_retaddr_bts
16723 ret
16724
16725 /*
16726 @@ -1513,7 +1900,7 @@ bstep_iret:
16727 movq %rcx,RIP+8(%rsp)
16728 jmp error_swapgs
16729 CFI_ENDPROC
16730 -END(error_entry)
16731 +ENDPROC(error_entry)
16732
16733
16734 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16735 @@ -1533,7 +1920,7 @@ ENTRY(error_exit)
16736 jnz retint_careful
16737 jmp retint_swapgs
16738 CFI_ENDPROC
16739 -END(error_exit)
16740 +ENDPROC(error_exit)
16741
16742 /*
16743 * Test if a given stack is an NMI stack or not.
16744 @@ -1591,9 +1978,11 @@ ENTRY(nmi)
16745 * If %cs was not the kernel segment, then the NMI triggered in user
16746 * space, which means it is definitely not nested.
16747 */
16748 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16749 + je 1f
16750 cmpl $__KERNEL_CS, 16(%rsp)
16751 jne first_nmi
16752 -
16753 +1:
16754 /*
16755 * Check the special variable on the stack to see if NMIs are
16756 * executing.
16757 @@ -1752,6 +2141,17 @@ end_repeat_nmi:
16758 */
16759 movq %cr2, %r12
16760
16761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16762 + testb $3, CS(%rsp)
16763 + jnz 1f
16764 + pax_enter_kernel
16765 + jmp 2f
16766 +1: pax_enter_kernel_user
16767 +2:
16768 +#else
16769 + pax_enter_kernel
16770 +#endif
16771 +
16772 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16773 movq %rsp,%rdi
16774 movq $-1,%rsi
16775 @@ -1767,21 +2167,32 @@ end_repeat_nmi:
16776 testl %ebx,%ebx /* swapgs needed? */
16777 jnz nmi_restore
16778 nmi_swapgs:
16779 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16780 + pax_exit_kernel_user
16781 +#else
16782 + pax_exit_kernel
16783 +#endif
16784 SWAPGS_UNSAFE_STACK
16785 + RESTORE_ALL 8
16786 + /* Clear the NMI executing stack variable */
16787 + movq $0, 10*8(%rsp)
16788 + jmp irq_return
16789 nmi_restore:
16790 + pax_exit_kernel
16791 RESTORE_ALL 8
16792 + pax_force_retaddr_bts
16793 /* Clear the NMI executing stack variable */
16794 movq $0, 10*8(%rsp)
16795 jmp irq_return
16796 CFI_ENDPROC
16797 -END(nmi)
16798 +ENDPROC(nmi)
16799
16800 ENTRY(ignore_sysret)
16801 CFI_STARTPROC
16802 mov $-ENOSYS,%eax
16803 sysret
16804 CFI_ENDPROC
16805 -END(ignore_sysret)
16806 +ENDPROC(ignore_sysret)
16807
16808 /*
16809 * End of kprobes section
16810 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16811 index c3a7cb4..3ad00dc 100644
16812 --- a/arch/x86/kernel/ftrace.c
16813 +++ b/arch/x86/kernel/ftrace.c
16814 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16815 {
16816 unsigned char replaced[MCOUNT_INSN_SIZE];
16817
16818 + ip = ktla_ktva(ip);
16819 +
16820 /*
16821 * Note: Due to modules and __init, code can
16822 * disappear and change, we need to protect against faulting
16823 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16824 unsigned char old[MCOUNT_INSN_SIZE], *new;
16825 int ret;
16826
16827 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16828 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16829 new = ftrace_call_replace(ip, (unsigned long)func);
16830
16831 /* See comment above by declaration of modifying_ftrace_code */
16832 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16833 {
16834 unsigned char code[MCOUNT_INSN_SIZE];
16835
16836 + ip = ktla_ktva(ip);
16837 +
16838 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16839 return -EFAULT;
16840
16841 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16842 index c18f59d..9c0c9f6 100644
16843 --- a/arch/x86/kernel/head32.c
16844 +++ b/arch/x86/kernel/head32.c
16845 @@ -18,6 +18,7 @@
16846 #include <asm/io_apic.h>
16847 #include <asm/bios_ebda.h>
16848 #include <asm/tlbflush.h>
16849 +#include <asm/boot.h>
16850
16851 static void __init i386_default_early_setup(void)
16852 {
16853 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16854
16855 void __init i386_start_kernel(void)
16856 {
16857 - memblock_reserve(__pa_symbol(&_text),
16858 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16859 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16860
16861 #ifdef CONFIG_BLK_DEV_INITRD
16862 /* Reserve INITRD */
16863 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16864 index d42ab17..87b9555 100644
16865 --- a/arch/x86/kernel/head_32.S
16866 +++ b/arch/x86/kernel/head_32.S
16867 @@ -26,6 +26,12 @@
16868 /* Physical address */
16869 #define pa(X) ((X) - __PAGE_OFFSET)
16870
16871 +#ifdef CONFIG_PAX_KERNEXEC
16872 +#define ta(X) (X)
16873 +#else
16874 +#define ta(X) ((X) - __PAGE_OFFSET)
16875 +#endif
16876 +
16877 /*
16878 * References to members of the new_cpu_data structure.
16879 */
16880 @@ -55,11 +61,7 @@
16881 * and small than max_low_pfn, otherwise will waste some page table entries
16882 */
16883
16884 -#if PTRS_PER_PMD > 1
16885 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16886 -#else
16887 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16888 -#endif
16889 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16890
16891 /* Number of possible pages in the lowmem region */
16892 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16893 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16894 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16895
16896 /*
16897 + * Real beginning of normal "text" segment
16898 + */
16899 +ENTRY(stext)
16900 +ENTRY(_stext)
16901 +
16902 +/*
16903 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16904 * %esi points to the real-mode code as a 32-bit pointer.
16905 * CS and DS must be 4 GB flat segments, but we don't depend on
16906 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16907 * can.
16908 */
16909 __HEAD
16910 +
16911 +#ifdef CONFIG_PAX_KERNEXEC
16912 + jmp startup_32
16913 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16914 +.fill PAGE_SIZE-5,1,0xcc
16915 +#endif
16916 +
16917 ENTRY(startup_32)
16918 movl pa(stack_start),%ecx
16919
16920 @@ -106,6 +121,59 @@ ENTRY(startup_32)
16921 2:
16922 leal -__PAGE_OFFSET(%ecx),%esp
16923
16924 +#ifdef CONFIG_SMP
16925 + movl $pa(cpu_gdt_table),%edi
16926 + movl $__per_cpu_load,%eax
16927 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
16928 + rorl $16,%eax
16929 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
16930 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
16931 + movl $__per_cpu_end - 1,%eax
16932 + subl $__per_cpu_start,%eax
16933 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
16934 +#endif
16935 +
16936 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16937 + movl $NR_CPUS,%ecx
16938 + movl $pa(cpu_gdt_table),%edi
16939 +1:
16940 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16941 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16942 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16943 + addl $PAGE_SIZE_asm,%edi
16944 + loop 1b
16945 +#endif
16946 +
16947 +#ifdef CONFIG_PAX_KERNEXEC
16948 + movl $pa(boot_gdt),%edi
16949 + movl $__LOAD_PHYSICAL_ADDR,%eax
16950 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
16951 + rorl $16,%eax
16952 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
16953 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
16954 + rorl $16,%eax
16955 +
16956 + ljmp $(__BOOT_CS),$1f
16957 +1:
16958 +
16959 + movl $NR_CPUS,%ecx
16960 + movl $pa(cpu_gdt_table),%edi
16961 + addl $__PAGE_OFFSET,%eax
16962 +1:
16963 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
16964 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
16965 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
16966 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
16967 + rorl $16,%eax
16968 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
16969 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
16970 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
16971 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
16972 + rorl $16,%eax
16973 + addl $PAGE_SIZE_asm,%edi
16974 + loop 1b
16975 +#endif
16976 +
16977 /*
16978 * Clear BSS first so that there are no surprises...
16979 */
16980 @@ -196,8 +264,11 @@ ENTRY(startup_32)
16981 movl %eax, pa(max_pfn_mapped)
16982
16983 /* Do early initialization of the fixmap area */
16984 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16985 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16986 +#ifdef CONFIG_COMPAT_VDSO
16987 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16988 +#else
16989 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16990 +#endif
16991 #else /* Not PAE */
16992
16993 page_pde_offset = (__PAGE_OFFSET >> 20);
16994 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16995 movl %eax, pa(max_pfn_mapped)
16996
16997 /* Do early initialization of the fixmap area */
16998 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16999 - movl %eax,pa(initial_page_table+0xffc)
17000 +#ifdef CONFIG_COMPAT_VDSO
17001 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17002 +#else
17003 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17004 +#endif
17005 #endif
17006
17007 #ifdef CONFIG_PARAVIRT
17008 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17009 cmpl $num_subarch_entries, %eax
17010 jae bad_subarch
17011
17012 - movl pa(subarch_entries)(,%eax,4), %eax
17013 - subl $__PAGE_OFFSET, %eax
17014 - jmp *%eax
17015 + jmp *pa(subarch_entries)(,%eax,4)
17016
17017 bad_subarch:
17018 WEAK(lguest_entry)
17019 @@ -256,10 +328,10 @@ WEAK(xen_entry)
17020 __INITDATA
17021
17022 subarch_entries:
17023 - .long default_entry /* normal x86/PC */
17024 - .long lguest_entry /* lguest hypervisor */
17025 - .long xen_entry /* Xen hypervisor */
17026 - .long default_entry /* Moorestown MID */
17027 + .long ta(default_entry) /* normal x86/PC */
17028 + .long ta(lguest_entry) /* lguest hypervisor */
17029 + .long ta(xen_entry) /* Xen hypervisor */
17030 + .long ta(default_entry) /* Moorestown MID */
17031 num_subarch_entries = (. - subarch_entries) / 4
17032 .previous
17033 #else
17034 @@ -310,6 +382,7 @@ default_entry:
17035 orl %edx,%eax
17036 movl %eax,%cr4
17037
17038 +#ifdef CONFIG_X86_PAE
17039 testb $X86_CR4_PAE, %al # check if PAE is enabled
17040 jz 6f
17041
17042 @@ -338,6 +411,9 @@ default_entry:
17043 /* Make changes effective */
17044 wrmsr
17045
17046 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17047 +#endif
17048 +
17049 6:
17050
17051 /*
17052 @@ -436,14 +512,20 @@ is386: movl $2,%ecx # set MP
17053 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17054 movl %eax,%ss # after changing gdt.
17055
17056 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17057 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17058 movl %eax,%ds
17059 movl %eax,%es
17060
17061 movl $(__KERNEL_PERCPU), %eax
17062 movl %eax,%fs # set this cpu's percpu
17063
17064 +#ifdef CONFIG_CC_STACKPROTECTOR
17065 movl $(__KERNEL_STACK_CANARY),%eax
17066 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17067 + movl $(__USER_DS),%eax
17068 +#else
17069 + xorl %eax,%eax
17070 +#endif
17071 movl %eax,%gs
17072
17073 xorl %eax,%eax # Clear LDT
17074 @@ -520,8 +602,11 @@ setup_once:
17075 * relocation. Manually set base address in stack canary
17076 * segment descriptor.
17077 */
17078 - movl $gdt_page,%eax
17079 + movl $cpu_gdt_table,%eax
17080 movl $stack_canary,%ecx
17081 +#ifdef CONFIG_SMP
17082 + addl $__per_cpu_load,%ecx
17083 +#endif
17084 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17085 shrl $16, %ecx
17086 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17087 @@ -552,7 +637,7 @@ ENDPROC(early_idt_handlers)
17088 /* This is global to keep gas from relaxing the jumps */
17089 ENTRY(early_idt_handler)
17090 cld
17091 - cmpl $2,%ss:early_recursion_flag
17092 + cmpl $1,%ss:early_recursion_flag
17093 je hlt_loop
17094 incl %ss:early_recursion_flag
17095
17096 @@ -590,8 +675,8 @@ ENTRY(early_idt_handler)
17097 pushl (20+6*4)(%esp) /* trapno */
17098 pushl $fault_msg
17099 call printk
17100 -#endif
17101 call dump_stack
17102 +#endif
17103 hlt_loop:
17104 hlt
17105 jmp hlt_loop
17106 @@ -610,8 +695,11 @@ ENDPROC(early_idt_handler)
17107 /* This is the default interrupt "handler" :-) */
17108 ALIGN
17109 ignore_int:
17110 - cld
17111 #ifdef CONFIG_PRINTK
17112 + cmpl $2,%ss:early_recursion_flag
17113 + je hlt_loop
17114 + incl %ss:early_recursion_flag
17115 + cld
17116 pushl %eax
17117 pushl %ecx
17118 pushl %edx
17119 @@ -620,9 +708,6 @@ ignore_int:
17120 movl $(__KERNEL_DS),%eax
17121 movl %eax,%ds
17122 movl %eax,%es
17123 - cmpl $2,early_recursion_flag
17124 - je hlt_loop
17125 - incl early_recursion_flag
17126 pushl 16(%esp)
17127 pushl 24(%esp)
17128 pushl 32(%esp)
17129 @@ -656,29 +741,43 @@ ENTRY(setup_once_ref)
17130 /*
17131 * BSS section
17132 */
17133 -__PAGE_ALIGNED_BSS
17134 - .align PAGE_SIZE
17135 #ifdef CONFIG_X86_PAE
17136 +.section .initial_pg_pmd,"a",@progbits
17137 initial_pg_pmd:
17138 .fill 1024*KPMDS,4,0
17139 #else
17140 +.section .initial_page_table,"a",@progbits
17141 ENTRY(initial_page_table)
17142 .fill 1024,4,0
17143 #endif
17144 +.section .initial_pg_fixmap,"a",@progbits
17145 initial_pg_fixmap:
17146 .fill 1024,4,0
17147 +.section .empty_zero_page,"a",@progbits
17148 ENTRY(empty_zero_page)
17149 .fill 4096,1,0
17150 +.section .swapper_pg_dir,"a",@progbits
17151 ENTRY(swapper_pg_dir)
17152 +#ifdef CONFIG_X86_PAE
17153 + .fill 4,8,0
17154 +#else
17155 .fill 1024,4,0
17156 +#endif
17157 +
17158 +/*
17159 + * The IDT has to be page-aligned to simplify the Pentium
17160 + * F0 0F bug workaround.. We have a special link segment
17161 + * for this.
17162 + */
17163 +.section .idt,"a",@progbits
17164 +ENTRY(idt_table)
17165 + .fill 256,8,0
17166
17167 /*
17168 * This starts the data section.
17169 */
17170 #ifdef CONFIG_X86_PAE
17171 -__PAGE_ALIGNED_DATA
17172 - /* Page-aligned for the benefit of paravirt? */
17173 - .align PAGE_SIZE
17174 +.section .initial_page_table,"a",@progbits
17175 ENTRY(initial_page_table)
17176 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17177 # if KPMDS == 3
17178 @@ -697,12 +796,20 @@ ENTRY(initial_page_table)
17179 # error "Kernel PMDs should be 1, 2 or 3"
17180 # endif
17181 .align PAGE_SIZE /* needs to be page-sized too */
17182 +
17183 +#ifdef CONFIG_PAX_PER_CPU_PGD
17184 +ENTRY(cpu_pgd)
17185 + .rept NR_CPUS
17186 + .fill 4,8,0
17187 + .endr
17188 +#endif
17189 +
17190 #endif
17191
17192 .data
17193 .balign 4
17194 ENTRY(stack_start)
17195 - .long init_thread_union+THREAD_SIZE
17196 + .long init_thread_union+THREAD_SIZE-8
17197
17198 __INITRODATA
17199 int_msg:
17200 @@ -730,7 +837,7 @@ fault_msg:
17201 * segment size, and 32-bit linear address value:
17202 */
17203
17204 - .data
17205 +.section .rodata,"a",@progbits
17206 .globl boot_gdt_descr
17207 .globl idt_descr
17208
17209 @@ -739,7 +846,7 @@ fault_msg:
17210 .word 0 # 32 bit align gdt_desc.address
17211 boot_gdt_descr:
17212 .word __BOOT_DS+7
17213 - .long boot_gdt - __PAGE_OFFSET
17214 + .long pa(boot_gdt)
17215
17216 .word 0 # 32-bit align idt_desc.address
17217 idt_descr:
17218 @@ -750,7 +857,7 @@ idt_descr:
17219 .word 0 # 32 bit align gdt_desc.address
17220 ENTRY(early_gdt_descr)
17221 .word GDT_ENTRIES*8-1
17222 - .long gdt_page /* Overwritten for secondary CPUs */
17223 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17224
17225 /*
17226 * The boot_gdt must mirror the equivalent in setup.S and is
17227 @@ -759,5 +866,65 @@ ENTRY(early_gdt_descr)
17228 .align L1_CACHE_BYTES
17229 ENTRY(boot_gdt)
17230 .fill GDT_ENTRY_BOOT_CS,8,0
17231 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17232 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17233 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17234 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17235 +
17236 + .align PAGE_SIZE_asm
17237 +ENTRY(cpu_gdt_table)
17238 + .rept NR_CPUS
17239 + .quad 0x0000000000000000 /* NULL descriptor */
17240 + .quad 0x0000000000000000 /* 0x0b reserved */
17241 + .quad 0x0000000000000000 /* 0x13 reserved */
17242 + .quad 0x0000000000000000 /* 0x1b reserved */
17243 +
17244 +#ifdef CONFIG_PAX_KERNEXEC
17245 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17246 +#else
17247 + .quad 0x0000000000000000 /* 0x20 unused */
17248 +#endif
17249 +
17250 + .quad 0x0000000000000000 /* 0x28 unused */
17251 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17252 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17253 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17254 + .quad 0x0000000000000000 /* 0x4b reserved */
17255 + .quad 0x0000000000000000 /* 0x53 reserved */
17256 + .quad 0x0000000000000000 /* 0x5b reserved */
17257 +
17258 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17259 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17260 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17261 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17262 +
17263 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17264 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17265 +
17266 + /*
17267 + * Segments used for calling PnP BIOS have byte granularity.
17268 + * The code segments and data segments have fixed 64k limits,
17269 + * the transfer segment sizes are set at run time.
17270 + */
17271 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17272 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17273 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17274 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17275 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17276 +
17277 + /*
17278 + * The APM segments have byte granularity and their bases
17279 + * are set at run time. All have 64k limits.
17280 + */
17281 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17282 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17283 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17284 +
17285 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17286 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17287 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17288 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17289 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17290 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17291 +
17292 + /* Be sure this is zeroed to avoid false validations in Xen */
17293 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17294 + .endr
17295 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17296 index 94bf9cc..400455a 100644
17297 --- a/arch/x86/kernel/head_64.S
17298 +++ b/arch/x86/kernel/head_64.S
17299 @@ -20,6 +20,8 @@
17300 #include <asm/processor-flags.h>
17301 #include <asm/percpu.h>
17302 #include <asm/nops.h>
17303 +#include <asm/cpufeature.h>
17304 +#include <asm/alternative-asm.h>
17305
17306 #ifdef CONFIG_PARAVIRT
17307 #include <asm/asm-offsets.h>
17308 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17309 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17310 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17311 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17312 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17313 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17314 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17315 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17316 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17317 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17318
17319 .text
17320 __HEAD
17321 @@ -88,35 +96,23 @@ startup_64:
17322 */
17323 addq %rbp, init_level4_pgt + 0(%rip)
17324 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17325 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17326 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17327 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17328 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17329
17330 addq %rbp, level3_ident_pgt + 0(%rip)
17331 +#ifndef CONFIG_XEN
17332 + addq %rbp, level3_ident_pgt + 8(%rip)
17333 +#endif
17334
17335 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17336 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17337 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17338 +
17339 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17340 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17341
17342 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17343 -
17344 - /* Add an Identity mapping if I am above 1G */
17345 - leaq _text(%rip), %rdi
17346 - andq $PMD_PAGE_MASK, %rdi
17347 -
17348 - movq %rdi, %rax
17349 - shrq $PUD_SHIFT, %rax
17350 - andq $(PTRS_PER_PUD - 1), %rax
17351 - jz ident_complete
17352 -
17353 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17354 - leaq level3_ident_pgt(%rip), %rbx
17355 - movq %rdx, 0(%rbx, %rax, 8)
17356 -
17357 - movq %rdi, %rax
17358 - shrq $PMD_SHIFT, %rax
17359 - andq $(PTRS_PER_PMD - 1), %rax
17360 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17361 - leaq level2_spare_pgt(%rip), %rbx
17362 - movq %rdx, 0(%rbx, %rax, 8)
17363 -ident_complete:
17364 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17365
17366 /*
17367 * Fixup the kernel text+data virtual addresses. Note that
17368 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17369 * after the boot processor executes this code.
17370 */
17371
17372 - /* Enable PAE mode and PGE */
17373 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17374 + /* Enable PAE mode and PSE/PGE */
17375 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17376 movq %rax, %cr4
17377
17378 /* Setup early boot stage 4 level pagetables. */
17379 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17380 movl $MSR_EFER, %ecx
17381 rdmsr
17382 btsl $_EFER_SCE, %eax /* Enable System Call */
17383 - btl $20,%edi /* No Execute supported? */
17384 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17385 jnc 1f
17386 btsl $_EFER_NX, %eax
17387 + leaq init_level4_pgt(%rip), %rdi
17388 +#ifndef CONFIG_EFI
17389 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17390 +#endif
17391 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17392 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17393 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17394 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17395 1: wrmsr /* Make changes effective */
17396
17397 /* Setup cr0 */
17398 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17399 * jump. In addition we need to ensure %cs is set so we make this
17400 * a far return.
17401 */
17402 + pax_set_fptr_mask
17403 movq initial_code(%rip),%rax
17404 pushq $0 # fake return address to stop unwinder
17405 pushq $__KERNEL_CS # set correct cs
17406 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17407 bad_address:
17408 jmp bad_address
17409
17410 - .section ".init.text","ax"
17411 + __INIT
17412 .globl early_idt_handlers
17413 early_idt_handlers:
17414 # 104(%rsp) %rflags
17415 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17416 addq $16,%rsp # drop vector number and error code
17417 decl early_recursion_flag(%rip)
17418 INTERRUPT_RETURN
17419 + .previous
17420
17421 + __INITDATA
17422 .balign 4
17423 early_recursion_flag:
17424 .long 0
17425 + .previous
17426
17427 + .section .rodata,"a",@progbits
17428 #ifdef CONFIG_EARLY_PRINTK
17429 early_idt_msg:
17430 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17431 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17432 #endif /* CONFIG_EARLY_PRINTK */
17433 .previous
17434
17435 + .section .rodata,"a",@progbits
17436 #define NEXT_PAGE(name) \
17437 .balign PAGE_SIZE; \
17438 ENTRY(name)
17439 @@ -372,7 +382,6 @@ ENTRY(name)
17440 i = i + 1 ; \
17441 .endr
17442
17443 - .data
17444 /*
17445 * This default setting generates an ident mapping at address 0x100000
17446 * and a mapping for the kernel that precisely maps virtual address
17447 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17448 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17449 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17450 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17451 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17452 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17453 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17454 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17455 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17456 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17457 .org init_level4_pgt + L4_START_KERNEL*8, 0
17458 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17459 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17460
17461 +#ifdef CONFIG_PAX_PER_CPU_PGD
17462 +NEXT_PAGE(cpu_pgd)
17463 + .rept NR_CPUS
17464 + .fill 512,8,0
17465 + .endr
17466 +#endif
17467 +
17468 NEXT_PAGE(level3_ident_pgt)
17469 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17470 +#ifdef CONFIG_XEN
17471 .fill 511,8,0
17472 +#else
17473 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17474 + .fill 510,8,0
17475 +#endif
17476 +
17477 +NEXT_PAGE(level3_vmalloc_start_pgt)
17478 + .fill 512,8,0
17479 +
17480 +NEXT_PAGE(level3_vmalloc_end_pgt)
17481 + .fill 512,8,0
17482 +
17483 +NEXT_PAGE(level3_vmemmap_pgt)
17484 + .fill L3_VMEMMAP_START,8,0
17485 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17486
17487 NEXT_PAGE(level3_kernel_pgt)
17488 .fill L3_START_KERNEL,8,0
17489 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17490 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17491 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17492
17493 +NEXT_PAGE(level2_vmemmap_pgt)
17494 + .fill 512,8,0
17495 +
17496 NEXT_PAGE(level2_fixmap_pgt)
17497 - .fill 506,8,0
17498 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17499 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17500 - .fill 5,8,0
17501 + .fill 507,8,0
17502 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17503 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17504 + .fill 4,8,0
17505
17506 -NEXT_PAGE(level1_fixmap_pgt)
17507 +NEXT_PAGE(level1_vsyscall_pgt)
17508 .fill 512,8,0
17509
17510 -NEXT_PAGE(level2_ident_pgt)
17511 - /* Since I easily can, map the first 1G.
17512 + /* Since I easily can, map the first 2G.
17513 * Don't set NX because code runs from these pages.
17514 */
17515 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17516 +NEXT_PAGE(level2_ident_pgt)
17517 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17518
17519 NEXT_PAGE(level2_kernel_pgt)
17520 /*
17521 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17522 * If you want to increase this then increase MODULES_VADDR
17523 * too.)
17524 */
17525 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17526 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17527 -
17528 -NEXT_PAGE(level2_spare_pgt)
17529 - .fill 512, 8, 0
17530 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17531
17532 #undef PMDS
17533 #undef NEXT_PAGE
17534
17535 - .data
17536 + .align PAGE_SIZE
17537 +ENTRY(cpu_gdt_table)
17538 + .rept NR_CPUS
17539 + .quad 0x0000000000000000 /* NULL descriptor */
17540 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17541 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17542 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17543 + .quad 0x00cffb000000ffff /* __USER32_CS */
17544 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17545 + .quad 0x00affb000000ffff /* __USER_CS */
17546 +
17547 +#ifdef CONFIG_PAX_KERNEXEC
17548 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17549 +#else
17550 + .quad 0x0 /* unused */
17551 +#endif
17552 +
17553 + .quad 0,0 /* TSS */
17554 + .quad 0,0 /* LDT */
17555 + .quad 0,0,0 /* three TLS descriptors */
17556 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17557 + /* asm/segment.h:GDT_ENTRIES must match this */
17558 +
17559 + /* zero the remaining page */
17560 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17561 + .endr
17562 +
17563 .align 16
17564 .globl early_gdt_descr
17565 early_gdt_descr:
17566 .word GDT_ENTRIES*8-1
17567 early_gdt_descr_base:
17568 - .quad INIT_PER_CPU_VAR(gdt_page)
17569 + .quad cpu_gdt_table
17570
17571 ENTRY(phys_base)
17572 /* This must match the first entry in level2_kernel_pgt */
17573 .quad 0x0000000000000000
17574
17575 #include "../../x86/xen/xen-head.S"
17576 -
17577 - .section .bss, "aw", @nobits
17578 +
17579 + .section .rodata,"a",@progbits
17580 .align L1_CACHE_BYTES
17581 ENTRY(idt_table)
17582 - .skip IDT_ENTRIES * 16
17583 + .fill 512,8,0
17584
17585 .align L1_CACHE_BYTES
17586 ENTRY(nmi_idt_table)
17587 - .skip IDT_ENTRIES * 16
17588 + .fill 512,8,0
17589
17590 __PAGE_ALIGNED_BSS
17591 .align PAGE_SIZE
17592 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17593 index 9c3bd4a..e1d9b35 100644
17594 --- a/arch/x86/kernel/i386_ksyms_32.c
17595 +++ b/arch/x86/kernel/i386_ksyms_32.c
17596 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17597 EXPORT_SYMBOL(cmpxchg8b_emu);
17598 #endif
17599
17600 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17601 +
17602 /* Networking helper routines. */
17603 EXPORT_SYMBOL(csum_partial_copy_generic);
17604 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17605 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17606
17607 EXPORT_SYMBOL(__get_user_1);
17608 EXPORT_SYMBOL(__get_user_2);
17609 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17610
17611 EXPORT_SYMBOL(csum_partial);
17612 EXPORT_SYMBOL(empty_zero_page);
17613 +
17614 +#ifdef CONFIG_PAX_KERNEXEC
17615 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17616 +#endif
17617 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17618 index f250431..54097e7 100644
17619 --- a/arch/x86/kernel/i387.c
17620 +++ b/arch/x86/kernel/i387.c
17621 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17622 static inline bool interrupted_user_mode(void)
17623 {
17624 struct pt_regs *regs = get_irq_regs();
17625 - return regs && user_mode_vm(regs);
17626 + return regs && user_mode(regs);
17627 }
17628
17629 /*
17630 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17631 index 36d1853..bf25736 100644
17632 --- a/arch/x86/kernel/i8259.c
17633 +++ b/arch/x86/kernel/i8259.c
17634 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17635 "spurious 8259A interrupt: IRQ%d.\n", irq);
17636 spurious_irq_mask |= irqmask;
17637 }
17638 - atomic_inc(&irq_err_count);
17639 + atomic_inc_unchecked(&irq_err_count);
17640 /*
17641 * Theoretically we do not have to handle this IRQ,
17642 * but in Linux this does not cause problems and is
17643 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17644 index 8c96897..be66bfa 100644
17645 --- a/arch/x86/kernel/ioport.c
17646 +++ b/arch/x86/kernel/ioport.c
17647 @@ -6,6 +6,7 @@
17648 #include <linux/sched.h>
17649 #include <linux/kernel.h>
17650 #include <linux/capability.h>
17651 +#include <linux/security.h>
17652 #include <linux/errno.h>
17653 #include <linux/types.h>
17654 #include <linux/ioport.h>
17655 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17656
17657 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17658 return -EINVAL;
17659 +#ifdef CONFIG_GRKERNSEC_IO
17660 + if (turn_on && grsec_disable_privio) {
17661 + gr_handle_ioperm();
17662 + return -EPERM;
17663 + }
17664 +#endif
17665 if (turn_on && !capable(CAP_SYS_RAWIO))
17666 return -EPERM;
17667
17668 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17669 * because the ->io_bitmap_max value must match the bitmap
17670 * contents:
17671 */
17672 - tss = &per_cpu(init_tss, get_cpu());
17673 + tss = init_tss + get_cpu();
17674
17675 if (turn_on)
17676 bitmap_clear(t->io_bitmap_ptr, from, num);
17677 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17678 return -EINVAL;
17679 /* Trying to gain more privileges? */
17680 if (level > old) {
17681 +#ifdef CONFIG_GRKERNSEC_IO
17682 + if (grsec_disable_privio) {
17683 + gr_handle_iopl();
17684 + return -EPERM;
17685 + }
17686 +#endif
17687 if (!capable(CAP_SYS_RAWIO))
17688 return -EPERM;
17689 }
17690 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17691 index d44f782..31ab01e 100644
17692 --- a/arch/x86/kernel/irq.c
17693 +++ b/arch/x86/kernel/irq.c
17694 @@ -18,7 +18,7 @@
17695 #include <asm/mce.h>
17696 #include <asm/hw_irq.h>
17697
17698 -atomic_t irq_err_count;
17699 +atomic_unchecked_t irq_err_count;
17700
17701 /* Function pointer for generic interrupt vector handling */
17702 void (*x86_platform_ipi_callback)(void) = NULL;
17703 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17704 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17705 seq_printf(p, " Machine check polls\n");
17706 #endif
17707 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17708 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17709 #if defined(CONFIG_X86_IO_APIC)
17710 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17711 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17712 #endif
17713 return 0;
17714 }
17715 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17716
17717 u64 arch_irq_stat(void)
17718 {
17719 - u64 sum = atomic_read(&irq_err_count);
17720 + u64 sum = atomic_read_unchecked(&irq_err_count);
17721
17722 #ifdef CONFIG_X86_IO_APIC
17723 - sum += atomic_read(&irq_mis_count);
17724 + sum += atomic_read_unchecked(&irq_mis_count);
17725 #endif
17726 return sum;
17727 }
17728 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17729 index 344faf8..355f60d 100644
17730 --- a/arch/x86/kernel/irq_32.c
17731 +++ b/arch/x86/kernel/irq_32.c
17732 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17733 __asm__ __volatile__("andl %%esp,%0" :
17734 "=r" (sp) : "0" (THREAD_SIZE - 1));
17735
17736 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17737 + return sp < STACK_WARN;
17738 }
17739
17740 static void print_stack_overflow(void)
17741 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17742 * per-CPU IRQ handling contexts (thread information and stack)
17743 */
17744 union irq_ctx {
17745 - struct thread_info tinfo;
17746 - u32 stack[THREAD_SIZE/sizeof(u32)];
17747 + unsigned long previous_esp;
17748 + u32 stack[THREAD_SIZE/sizeof(u32)];
17749 } __attribute__((aligned(THREAD_SIZE)));
17750
17751 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17752 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17753 static inline int
17754 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17755 {
17756 - union irq_ctx *curctx, *irqctx;
17757 + union irq_ctx *irqctx;
17758 u32 *isp, arg1, arg2;
17759
17760 - curctx = (union irq_ctx *) current_thread_info();
17761 irqctx = __this_cpu_read(hardirq_ctx);
17762
17763 /*
17764 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17765 * handler) we can't do that and just have to keep using the
17766 * current stack (which is the irq stack already after all)
17767 */
17768 - if (unlikely(curctx == irqctx))
17769 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17770 return 0;
17771
17772 /* build the stack frame on the IRQ stack */
17773 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17774 - irqctx->tinfo.task = curctx->tinfo.task;
17775 - irqctx->tinfo.previous_esp = current_stack_pointer;
17776 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17777 + irqctx->previous_esp = current_stack_pointer;
17778
17779 - /* Copy the preempt_count so that the [soft]irq checks work. */
17780 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17781 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17782 + __set_fs(MAKE_MM_SEG(0));
17783 +#endif
17784
17785 if (unlikely(overflow))
17786 call_on_stack(print_stack_overflow, isp);
17787 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17788 : "0" (irq), "1" (desc), "2" (isp),
17789 "D" (desc->handle_irq)
17790 : "memory", "cc", "ecx");
17791 +
17792 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17793 + __set_fs(current_thread_info()->addr_limit);
17794 +#endif
17795 +
17796 return 1;
17797 }
17798
17799 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17800 */
17801 void __cpuinit irq_ctx_init(int cpu)
17802 {
17803 - union irq_ctx *irqctx;
17804 -
17805 if (per_cpu(hardirq_ctx, cpu))
17806 return;
17807
17808 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17809 - THREADINFO_GFP,
17810 - THREAD_SIZE_ORDER));
17811 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17812 - irqctx->tinfo.cpu = cpu;
17813 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17814 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17815 -
17816 - per_cpu(hardirq_ctx, cpu) = irqctx;
17817 -
17818 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17819 - THREADINFO_GFP,
17820 - THREAD_SIZE_ORDER));
17821 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17822 - irqctx->tinfo.cpu = cpu;
17823 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17824 -
17825 - per_cpu(softirq_ctx, cpu) = irqctx;
17826 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17827 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17828 +
17829 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17830 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17831
17832 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17833 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17834 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17835 asmlinkage void do_softirq(void)
17836 {
17837 unsigned long flags;
17838 - struct thread_info *curctx;
17839 union irq_ctx *irqctx;
17840 u32 *isp;
17841
17842 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17843 local_irq_save(flags);
17844
17845 if (local_softirq_pending()) {
17846 - curctx = current_thread_info();
17847 irqctx = __this_cpu_read(softirq_ctx);
17848 - irqctx->tinfo.task = curctx->task;
17849 - irqctx->tinfo.previous_esp = current_stack_pointer;
17850 + irqctx->previous_esp = current_stack_pointer;
17851
17852 /* build the stack frame on the softirq stack */
17853 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17854 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17855 +
17856 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17857 + __set_fs(MAKE_MM_SEG(0));
17858 +#endif
17859
17860 call_on_stack(__do_softirq, isp);
17861 +
17862 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17863 + __set_fs(current_thread_info()->addr_limit);
17864 +#endif
17865 +
17866 /*
17867 * Shouldn't happen, we returned above if in_interrupt():
17868 */
17869 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17870 if (unlikely(!desc))
17871 return false;
17872
17873 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17874 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17875 if (unlikely(overflow))
17876 print_stack_overflow();
17877 desc->handle_irq(irq, desc);
17878 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17879 index d04d3ec..ea4b374 100644
17880 --- a/arch/x86/kernel/irq_64.c
17881 +++ b/arch/x86/kernel/irq_64.c
17882 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17883 u64 estack_top, estack_bottom;
17884 u64 curbase = (u64)task_stack_page(current);
17885
17886 - if (user_mode_vm(regs))
17887 + if (user_mode(regs))
17888 return;
17889
17890 if (regs->sp >= curbase + sizeof(struct thread_info) +
17891 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17892 index dc1404b..bbc43e7 100644
17893 --- a/arch/x86/kernel/kdebugfs.c
17894 +++ b/arch/x86/kernel/kdebugfs.c
17895 @@ -27,7 +27,7 @@ struct setup_data_node {
17896 u32 len;
17897 };
17898
17899 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17900 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17901 size_t count, loff_t *ppos)
17902 {
17903 struct setup_data_node *node = file->private_data;
17904 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17905 index 3f61904..873cea9 100644
17906 --- a/arch/x86/kernel/kgdb.c
17907 +++ b/arch/x86/kernel/kgdb.c
17908 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17909 #ifdef CONFIG_X86_32
17910 switch (regno) {
17911 case GDB_SS:
17912 - if (!user_mode_vm(regs))
17913 + if (!user_mode(regs))
17914 *(unsigned long *)mem = __KERNEL_DS;
17915 break;
17916 case GDB_SP:
17917 - if (!user_mode_vm(regs))
17918 + if (!user_mode(regs))
17919 *(unsigned long *)mem = kernel_stack_pointer(regs);
17920 break;
17921 case GDB_GS:
17922 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17923 case 'k':
17924 /* clear the trace bit */
17925 linux_regs->flags &= ~X86_EFLAGS_TF;
17926 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17927 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17928
17929 /* set the trace bit if we're stepping */
17930 if (remcomInBuffer[0] == 's') {
17931 linux_regs->flags |= X86_EFLAGS_TF;
17932 - atomic_set(&kgdb_cpu_doing_single_step,
17933 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17934 raw_smp_processor_id());
17935 }
17936
17937 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17938
17939 switch (cmd) {
17940 case DIE_DEBUG:
17941 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17942 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17943 if (user_mode(regs))
17944 return single_step_cont(regs, args);
17945 break;
17946 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17947 index c5e410e..da6aaf9 100644
17948 --- a/arch/x86/kernel/kprobes-opt.c
17949 +++ b/arch/x86/kernel/kprobes-opt.c
17950 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17951 * Verify if the address gap is in 2GB range, because this uses
17952 * a relative jump.
17953 */
17954 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17955 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17956 if (abs(rel) > 0x7fffffff)
17957 return -ERANGE;
17958
17959 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17960 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17961
17962 /* Set probe function call */
17963 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17964 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17965
17966 /* Set returning jmp instruction at the tail of out-of-line buffer */
17967 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17968 - (u8 *)op->kp.addr + op->optinsn.size);
17969 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17970
17971 flush_icache_range((unsigned long) buf,
17972 (unsigned long) buf + TMPL_END_IDX +
17973 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17974 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17975
17976 /* Backup instructions which will be replaced by jump address */
17977 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17978 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17979 RELATIVE_ADDR_SIZE);
17980
17981 insn_buf[0] = RELATIVEJUMP_OPCODE;
17982 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17983 index e2f751e..dffa2a0 100644
17984 --- a/arch/x86/kernel/kprobes.c
17985 +++ b/arch/x86/kernel/kprobes.c
17986 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17987 } __attribute__((packed)) *insn;
17988
17989 insn = (struct __arch_relative_insn *)from;
17990 +
17991 + pax_open_kernel();
17992 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17993 insn->op = op;
17994 + pax_close_kernel();
17995 }
17996
17997 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17998 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17999 kprobe_opcode_t opcode;
18000 kprobe_opcode_t *orig_opcodes = opcodes;
18001
18002 - if (search_exception_tables((unsigned long)opcodes))
18003 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18004 return 0; /* Page fault may occur on this address. */
18005
18006 retry:
18007 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18008 /* Another subsystem puts a breakpoint, failed to recover */
18009 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
18010 return 0;
18011 + pax_open_kernel();
18012 memcpy(dest, insn.kaddr, insn.length);
18013 + pax_close_kernel();
18014
18015 #ifdef CONFIG_X86_64
18016 if (insn_rip_relative(&insn)) {
18017 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18018 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
18019 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18020 disp = (u8 *) dest + insn_offset_displacement(&insn);
18021 + pax_open_kernel();
18022 *(s32 *) disp = (s32) newdisp;
18023 + pax_close_kernel();
18024 }
18025 #endif
18026 return insn.length;
18027 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18028 * nor set current_kprobe, because it doesn't use single
18029 * stepping.
18030 */
18031 - regs->ip = (unsigned long)p->ainsn.insn;
18032 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18033 preempt_enable_no_resched();
18034 return;
18035 }
18036 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18037 if (p->opcode == BREAKPOINT_INSTRUCTION)
18038 regs->ip = (unsigned long)p->addr;
18039 else
18040 - regs->ip = (unsigned long)p->ainsn.insn;
18041 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18042 }
18043
18044 /*
18045 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18046 setup_singlestep(p, regs, kcb, 0);
18047 return 1;
18048 }
18049 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18050 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18051 /*
18052 * The breakpoint instruction was removed right
18053 * after we hit it. Another cpu has removed
18054 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18055 " movq %rax, 152(%rsp)\n"
18056 RESTORE_REGS_STRING
18057 " popfq\n"
18058 +#ifdef KERNEXEC_PLUGIN
18059 + " btsq $63,(%rsp)\n"
18060 +#endif
18061 #else
18062 " pushf\n"
18063 SAVE_REGS_STRING
18064 @@ -765,7 +775,7 @@ static void __kprobes
18065 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18066 {
18067 unsigned long *tos = stack_addr(regs);
18068 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18069 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18070 unsigned long orig_ip = (unsigned long)p->addr;
18071 kprobe_opcode_t *insn = p->ainsn.insn;
18072
18073 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18074 struct die_args *args = data;
18075 int ret = NOTIFY_DONE;
18076
18077 - if (args->regs && user_mode_vm(args->regs))
18078 + if (args->regs && user_mode(args->regs))
18079 return ret;
18080
18081 switch (val) {
18082 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18083 index ebc9873..1b9724b 100644
18084 --- a/arch/x86/kernel/ldt.c
18085 +++ b/arch/x86/kernel/ldt.c
18086 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18087 if (reload) {
18088 #ifdef CONFIG_SMP
18089 preempt_disable();
18090 - load_LDT(pc);
18091 + load_LDT_nolock(pc);
18092 if (!cpumask_equal(mm_cpumask(current->mm),
18093 cpumask_of(smp_processor_id())))
18094 smp_call_function(flush_ldt, current->mm, 1);
18095 preempt_enable();
18096 #else
18097 - load_LDT(pc);
18098 + load_LDT_nolock(pc);
18099 #endif
18100 }
18101 if (oldsize) {
18102 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18103 return err;
18104
18105 for (i = 0; i < old->size; i++)
18106 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18107 + write_ldt_entry(new->ldt, i, old->ldt + i);
18108 return 0;
18109 }
18110
18111 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18112 retval = copy_ldt(&mm->context, &old_mm->context);
18113 mutex_unlock(&old_mm->context.lock);
18114 }
18115 +
18116 + if (tsk == current) {
18117 + mm->context.vdso = 0;
18118 +
18119 +#ifdef CONFIG_X86_32
18120 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18121 + mm->context.user_cs_base = 0UL;
18122 + mm->context.user_cs_limit = ~0UL;
18123 +
18124 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18125 + cpus_clear(mm->context.cpu_user_cs_mask);
18126 +#endif
18127 +
18128 +#endif
18129 +#endif
18130 +
18131 + }
18132 +
18133 return retval;
18134 }
18135
18136 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18137 }
18138 }
18139
18140 +#ifdef CONFIG_PAX_SEGMEXEC
18141 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18142 + error = -EINVAL;
18143 + goto out_unlock;
18144 + }
18145 +#endif
18146 +
18147 fill_ldt(&ldt, &ldt_info);
18148 if (oldmode)
18149 ldt.avl = 0;
18150 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18151 index 5b19e4d..6476a76 100644
18152 --- a/arch/x86/kernel/machine_kexec_32.c
18153 +++ b/arch/x86/kernel/machine_kexec_32.c
18154 @@ -26,7 +26,7 @@
18155 #include <asm/cacheflush.h>
18156 #include <asm/debugreg.h>
18157
18158 -static void set_idt(void *newidt, __u16 limit)
18159 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18160 {
18161 struct desc_ptr curidt;
18162
18163 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18164 }
18165
18166
18167 -static void set_gdt(void *newgdt, __u16 limit)
18168 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18169 {
18170 struct desc_ptr curgdt;
18171
18172 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18173 }
18174
18175 control_page = page_address(image->control_code_page);
18176 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18177 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18178
18179 relocate_kernel_ptr = control_page;
18180 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18181 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18182 index 0327e2b..e43737b 100644
18183 --- a/arch/x86/kernel/microcode_intel.c
18184 +++ b/arch/x86/kernel/microcode_intel.c
18185 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18186
18187 static int get_ucode_user(void *to, const void *from, size_t n)
18188 {
18189 - return copy_from_user(to, from, n);
18190 + return copy_from_user(to, (const void __force_user *)from, n);
18191 }
18192
18193 static enum ucode_state
18194 request_microcode_user(int cpu, const void __user *buf, size_t size)
18195 {
18196 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18197 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18198 }
18199
18200 static void microcode_fini_cpu(int cpu)
18201 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18202 index 216a4d7..b328f09 100644
18203 --- a/arch/x86/kernel/module.c
18204 +++ b/arch/x86/kernel/module.c
18205 @@ -43,15 +43,60 @@ do { \
18206 } while (0)
18207 #endif
18208
18209 -void *module_alloc(unsigned long size)
18210 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18211 {
18212 - if (PAGE_ALIGN(size) > MODULES_LEN)
18213 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18214 return NULL;
18215 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18216 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18217 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18218 -1, __builtin_return_address(0));
18219 }
18220
18221 +void *module_alloc(unsigned long size)
18222 +{
18223 +
18224 +#ifdef CONFIG_PAX_KERNEXEC
18225 + return __module_alloc(size, PAGE_KERNEL);
18226 +#else
18227 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18228 +#endif
18229 +
18230 +}
18231 +
18232 +#ifdef CONFIG_PAX_KERNEXEC
18233 +#ifdef CONFIG_X86_32
18234 +void *module_alloc_exec(unsigned long size)
18235 +{
18236 + struct vm_struct *area;
18237 +
18238 + if (size == 0)
18239 + return NULL;
18240 +
18241 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18242 + return area ? area->addr : NULL;
18243 +}
18244 +EXPORT_SYMBOL(module_alloc_exec);
18245 +
18246 +void module_free_exec(struct module *mod, void *module_region)
18247 +{
18248 + vunmap(module_region);
18249 +}
18250 +EXPORT_SYMBOL(module_free_exec);
18251 +#else
18252 +void module_free_exec(struct module *mod, void *module_region)
18253 +{
18254 + module_free(mod, module_region);
18255 +}
18256 +EXPORT_SYMBOL(module_free_exec);
18257 +
18258 +void *module_alloc_exec(unsigned long size)
18259 +{
18260 + return __module_alloc(size, PAGE_KERNEL_RX);
18261 +}
18262 +EXPORT_SYMBOL(module_alloc_exec);
18263 +#endif
18264 +#endif
18265 +
18266 #ifdef CONFIG_X86_32
18267 int apply_relocate(Elf32_Shdr *sechdrs,
18268 const char *strtab,
18269 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18270 unsigned int i;
18271 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18272 Elf32_Sym *sym;
18273 - uint32_t *location;
18274 + uint32_t *plocation, location;
18275
18276 DEBUGP("Applying relocate section %u to %u\n",
18277 relsec, sechdrs[relsec].sh_info);
18278 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18279 /* This is where to make the change */
18280 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18281 - + rel[i].r_offset;
18282 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18283 + location = (uint32_t)plocation;
18284 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18285 + plocation = ktla_ktva((void *)plocation);
18286 /* This is the symbol it is referring to. Note that all
18287 undefined symbols have been resolved. */
18288 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18289 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18290 switch (ELF32_R_TYPE(rel[i].r_info)) {
18291 case R_386_32:
18292 /* We add the value into the location given */
18293 - *location += sym->st_value;
18294 + pax_open_kernel();
18295 + *plocation += sym->st_value;
18296 + pax_close_kernel();
18297 break;
18298 case R_386_PC32:
18299 /* Add the value, subtract its position */
18300 - *location += sym->st_value - (uint32_t)location;
18301 + pax_open_kernel();
18302 + *plocation += sym->st_value - location;
18303 + pax_close_kernel();
18304 break;
18305 default:
18306 pr_err("%s: Unknown relocation: %u\n",
18307 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18308 case R_X86_64_NONE:
18309 break;
18310 case R_X86_64_64:
18311 + pax_open_kernel();
18312 *(u64 *)loc = val;
18313 + pax_close_kernel();
18314 break;
18315 case R_X86_64_32:
18316 + pax_open_kernel();
18317 *(u32 *)loc = val;
18318 + pax_close_kernel();
18319 if (val != *(u32 *)loc)
18320 goto overflow;
18321 break;
18322 case R_X86_64_32S:
18323 + pax_open_kernel();
18324 *(s32 *)loc = val;
18325 + pax_close_kernel();
18326 if ((s64)val != *(s32 *)loc)
18327 goto overflow;
18328 break;
18329 case R_X86_64_PC32:
18330 val -= (u64)loc;
18331 + pax_open_kernel();
18332 *(u32 *)loc = val;
18333 + pax_close_kernel();
18334 +
18335 #if 0
18336 if ((s64)val != *(s32 *)loc)
18337 goto overflow;
18338 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18339 index f84f5c5..e27e54b 100644
18340 --- a/arch/x86/kernel/nmi.c
18341 +++ b/arch/x86/kernel/nmi.c
18342 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18343 dotraplinkage notrace __kprobes void
18344 do_nmi(struct pt_regs *regs, long error_code)
18345 {
18346 +
18347 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18348 + if (!user_mode(regs)) {
18349 + unsigned long cs = regs->cs & 0xFFFF;
18350 + unsigned long ip = ktva_ktla(regs->ip);
18351 +
18352 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18353 + regs->ip = ip;
18354 + }
18355 +#endif
18356 +
18357 nmi_nesting_preprocess(regs);
18358
18359 nmi_enter();
18360 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18361 index 676b8c7..870ba04 100644
18362 --- a/arch/x86/kernel/paravirt-spinlocks.c
18363 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18364 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18365 arch_spin_lock(lock);
18366 }
18367
18368 -struct pv_lock_ops pv_lock_ops = {
18369 +struct pv_lock_ops pv_lock_ops __read_only = {
18370 #ifdef CONFIG_SMP
18371 .spin_is_locked = __ticket_spin_is_locked,
18372 .spin_is_contended = __ticket_spin_is_contended,
18373 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18374 index 17fff18..7bb2088 100644
18375 --- a/arch/x86/kernel/paravirt.c
18376 +++ b/arch/x86/kernel/paravirt.c
18377 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18378 {
18379 return x;
18380 }
18381 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18382 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18383 +#endif
18384
18385 void __init default_banner(void)
18386 {
18387 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18388 if (opfunc == NULL)
18389 /* If there's no function, patch it with a ud2a (BUG) */
18390 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18391 - else if (opfunc == _paravirt_nop)
18392 + else if (opfunc == (void *)_paravirt_nop)
18393 /* If the operation is a nop, then nop the callsite */
18394 ret = paravirt_patch_nop();
18395
18396 /* identity functions just return their single argument */
18397 - else if (opfunc == _paravirt_ident_32)
18398 + else if (opfunc == (void *)_paravirt_ident_32)
18399 ret = paravirt_patch_ident_32(insnbuf, len);
18400 - else if (opfunc == _paravirt_ident_64)
18401 + else if (opfunc == (void *)_paravirt_ident_64)
18402 ret = paravirt_patch_ident_64(insnbuf, len);
18403 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18404 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18405 + ret = paravirt_patch_ident_64(insnbuf, len);
18406 +#endif
18407
18408 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18409 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18410 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18411 if (insn_len > len || start == NULL)
18412 insn_len = len;
18413 else
18414 - memcpy(insnbuf, start, insn_len);
18415 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18416
18417 return insn_len;
18418 }
18419 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18420 preempt_enable();
18421 }
18422
18423 -struct pv_info pv_info = {
18424 +struct pv_info pv_info __read_only = {
18425 .name = "bare hardware",
18426 .paravirt_enabled = 0,
18427 .kernel_rpl = 0,
18428 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18429 #endif
18430 };
18431
18432 -struct pv_init_ops pv_init_ops = {
18433 +struct pv_init_ops pv_init_ops __read_only = {
18434 .patch = native_patch,
18435 };
18436
18437 -struct pv_time_ops pv_time_ops = {
18438 +struct pv_time_ops pv_time_ops __read_only = {
18439 .sched_clock = native_sched_clock,
18440 .steal_clock = native_steal_clock,
18441 };
18442
18443 -struct pv_irq_ops pv_irq_ops = {
18444 +struct pv_irq_ops pv_irq_ops __read_only = {
18445 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18446 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18447 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18448 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18449 #endif
18450 };
18451
18452 -struct pv_cpu_ops pv_cpu_ops = {
18453 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18454 .cpuid = native_cpuid,
18455 .get_debugreg = native_get_debugreg,
18456 .set_debugreg = native_set_debugreg,
18457 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18458 .end_context_switch = paravirt_nop,
18459 };
18460
18461 -struct pv_apic_ops pv_apic_ops = {
18462 +struct pv_apic_ops pv_apic_ops __read_only = {
18463 #ifdef CONFIG_X86_LOCAL_APIC
18464 .startup_ipi_hook = paravirt_nop,
18465 #endif
18466 };
18467
18468 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18469 +#ifdef CONFIG_X86_32
18470 +#ifdef CONFIG_X86_PAE
18471 +/* 64-bit pagetable entries */
18472 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18473 +#else
18474 /* 32-bit pagetable entries */
18475 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18476 +#endif
18477 #else
18478 /* 64-bit pagetable entries */
18479 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18480 #endif
18481
18482 -struct pv_mmu_ops pv_mmu_ops = {
18483 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18484
18485 .read_cr2 = native_read_cr2,
18486 .write_cr2 = native_write_cr2,
18487 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18488 .make_pud = PTE_IDENT,
18489
18490 .set_pgd = native_set_pgd,
18491 + .set_pgd_batched = native_set_pgd_batched,
18492 #endif
18493 #endif /* PAGETABLE_LEVELS >= 3 */
18494
18495 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18496 },
18497
18498 .set_fixmap = native_set_fixmap,
18499 +
18500 +#ifdef CONFIG_PAX_KERNEXEC
18501 + .pax_open_kernel = native_pax_open_kernel,
18502 + .pax_close_kernel = native_pax_close_kernel,
18503 +#endif
18504 +
18505 };
18506
18507 EXPORT_SYMBOL_GPL(pv_time_ops);
18508 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18509 index 35ccf75..7a15747 100644
18510 --- a/arch/x86/kernel/pci-iommu_table.c
18511 +++ b/arch/x86/kernel/pci-iommu_table.c
18512 @@ -2,7 +2,7 @@
18513 #include <asm/iommu_table.h>
18514 #include <linux/string.h>
18515 #include <linux/kallsyms.h>
18516 -
18517 +#include <linux/sched.h>
18518
18519 #define DEBUG 1
18520
18521 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18522 index ef6a845..8028ed3 100644
18523 --- a/arch/x86/kernel/process.c
18524 +++ b/arch/x86/kernel/process.c
18525 @@ -36,7 +36,8 @@
18526 * section. Since TSS's are completely CPU-local, we want them
18527 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18528 */
18529 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18530 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18531 +EXPORT_SYMBOL(init_tss);
18532
18533 #ifdef CONFIG_X86_64
18534 static DEFINE_PER_CPU(unsigned char, is_idle);
18535 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18536 task_xstate_cachep =
18537 kmem_cache_create("task_xstate", xstate_size,
18538 __alignof__(union thread_xstate),
18539 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18540 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18541 }
18542
18543 static inline void drop_fpu(struct task_struct *tsk)
18544 @@ -117,7 +118,7 @@ void exit_thread(void)
18545 unsigned long *bp = t->io_bitmap_ptr;
18546
18547 if (bp) {
18548 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18549 + struct tss_struct *tss = init_tss + get_cpu();
18550
18551 t->io_bitmap_ptr = NULL;
18552 clear_thread_flag(TIF_IO_BITMAP);
18553 @@ -148,7 +149,7 @@ void show_regs_common(void)
18554 board = dmi_get_system_info(DMI_BOARD_NAME);
18555
18556 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18557 - current->pid, current->comm, print_tainted(),
18558 + task_pid_nr(current), current->comm, print_tainted(),
18559 init_utsname()->release,
18560 (int)strcspn(init_utsname()->version, " "),
18561 init_utsname()->version,
18562 @@ -161,6 +162,9 @@ void flush_thread(void)
18563 {
18564 struct task_struct *tsk = current;
18565
18566 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18567 + loadsegment(gs, 0);
18568 +#endif
18569 flush_ptrace_hw_breakpoint(tsk);
18570 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18571 drop_fpu(tsk);
18572 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18573 regs.di = (unsigned long) arg;
18574
18575 #ifdef CONFIG_X86_32
18576 - regs.ds = __USER_DS;
18577 - regs.es = __USER_DS;
18578 + regs.ds = __KERNEL_DS;
18579 + regs.es = __KERNEL_DS;
18580 regs.fs = __KERNEL_PERCPU;
18581 - regs.gs = __KERNEL_STACK_CANARY;
18582 + savesegment(gs, regs.gs);
18583 #else
18584 regs.ss = __KERNEL_DS;
18585 #endif
18586 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18587 void exit_idle(void)
18588 {
18589 /* idle loop has pid 0 */
18590 - if (current->pid)
18591 + if (task_pid_nr(current))
18592 return;
18593 __exit_idle();
18594 }
18595 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18596
18597 return ret;
18598 }
18599 -void stop_this_cpu(void *dummy)
18600 +__noreturn void stop_this_cpu(void *dummy)
18601 {
18602 local_irq_disable();
18603 /*
18604 @@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18605 }
18606 early_param("idle", idle_setup);
18607
18608 -unsigned long arch_align_stack(unsigned long sp)
18609 +#ifdef CONFIG_PAX_RANDKSTACK
18610 +void pax_randomize_kstack(struct pt_regs *regs)
18611 {
18612 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18613 - sp -= get_random_int() % 8192;
18614 - return sp & ~0xf;
18615 -}
18616 + struct thread_struct *thread = &current->thread;
18617 + unsigned long time;
18618
18619 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18620 -{
18621 - unsigned long range_end = mm->brk + 0x02000000;
18622 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18623 -}
18624 + if (!randomize_va_space)
18625 + return;
18626 +
18627 + if (v8086_mode(regs))
18628 + return;
18629
18630 + rdtscl(time);
18631 +
18632 + /* P4 seems to return a 0 LSB, ignore it */
18633 +#ifdef CONFIG_MPENTIUM4
18634 + time &= 0x3EUL;
18635 + time <<= 2;
18636 +#elif defined(CONFIG_X86_64)
18637 + time &= 0xFUL;
18638 + time <<= 4;
18639 +#else
18640 + time &= 0x1FUL;
18641 + time <<= 3;
18642 +#endif
18643 +
18644 + thread->sp0 ^= time;
18645 + load_sp0(init_tss + smp_processor_id(), thread);
18646 +
18647 +#ifdef CONFIG_X86_64
18648 + this_cpu_write(kernel_stack, thread->sp0);
18649 +#endif
18650 +}
18651 +#endif
18652 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18653 index 516fa18..d3a7099 100644
18654 --- a/arch/x86/kernel/process_32.c
18655 +++ b/arch/x86/kernel/process_32.c
18656 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18657 unsigned long thread_saved_pc(struct task_struct *tsk)
18658 {
18659 return ((unsigned long *)tsk->thread.sp)[3];
18660 +//XXX return tsk->thread.eip;
18661 }
18662
18663 void __show_regs(struct pt_regs *regs, int all)
18664 @@ -73,21 +74,20 @@ void __show_regs(struct pt_regs *regs, int all)
18665 unsigned long sp;
18666 unsigned short ss, gs;
18667
18668 - if (user_mode_vm(regs)) {
18669 + if (user_mode(regs)) {
18670 sp = regs->sp;
18671 ss = regs->ss & 0xffff;
18672 - gs = get_user_gs(regs);
18673 } else {
18674 sp = kernel_stack_pointer(regs);
18675 savesegment(ss, ss);
18676 - savesegment(gs, gs);
18677 }
18678 + gs = get_user_gs(regs);
18679
18680 show_regs_common();
18681
18682 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
18683 (u16)regs->cs, regs->ip, regs->flags,
18684 - smp_processor_id());
18685 + raw_smp_processor_id());
18686 print_symbol("EIP is at %s\n", regs->ip);
18687
18688 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
18689 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18690 struct task_struct *tsk;
18691 int err;
18692
18693 - childregs = task_pt_regs(p);
18694 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18695 *childregs = *regs;
18696 childregs->ax = 0;
18697 childregs->sp = sp;
18698
18699 p->thread.sp = (unsigned long) childregs;
18700 p->thread.sp0 = (unsigned long) (childregs+1);
18701 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18702
18703 p->thread.ip = (unsigned long) ret_from_fork;
18704
18705 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18706 struct thread_struct *prev = &prev_p->thread,
18707 *next = &next_p->thread;
18708 int cpu = smp_processor_id();
18709 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18710 + struct tss_struct *tss = init_tss + cpu;
18711 fpu_switch_t fpu;
18712
18713 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18714 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18715 */
18716 lazy_save_gs(prev->gs);
18717
18718 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18719 + __set_fs(task_thread_info(next_p)->addr_limit);
18720 +#endif
18721 +
18722 /*
18723 * Load the per-thread Thread-Local Storage descriptor.
18724 */
18725 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18726 */
18727 arch_end_context_switch(next_p);
18728
18729 + this_cpu_write(current_task, next_p);
18730 + this_cpu_write(current_tinfo, &next_p->tinfo);
18731 +
18732 /*
18733 * Restore %gs if needed (which is common)
18734 */
18735 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18736
18737 switch_fpu_finish(next_p, fpu);
18738
18739 - this_cpu_write(current_task, next_p);
18740 -
18741 return prev_p;
18742 }
18743
18744 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18745 } while (count++ < 16);
18746 return 0;
18747 }
18748 -
18749 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18750 index 0a980c9..1d0e689 100644
18751 --- a/arch/x86/kernel/process_64.c
18752 +++ b/arch/x86/kernel/process_64.c
18753 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18754 struct pt_regs *childregs;
18755 struct task_struct *me = current;
18756
18757 - childregs = ((struct pt_regs *)
18758 - (THREAD_SIZE + task_stack_page(p))) - 1;
18759 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18760 *childregs = *regs;
18761
18762 childregs->ax = 0;
18763 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18764 p->thread.sp = (unsigned long) childregs;
18765 p->thread.sp0 = (unsigned long) (childregs+1);
18766 p->thread.usersp = me->thread.usersp;
18767 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18768
18769 set_tsk_thread_flag(p, TIF_FORK);
18770
18771 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18772 struct thread_struct *prev = &prev_p->thread;
18773 struct thread_struct *next = &next_p->thread;
18774 int cpu = smp_processor_id();
18775 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18776 + struct tss_struct *tss = init_tss + cpu;
18777 unsigned fsindex, gsindex;
18778 fpu_switch_t fpu;
18779
18780 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18781 prev->usersp = this_cpu_read(old_rsp);
18782 this_cpu_write(old_rsp, next->usersp);
18783 this_cpu_write(current_task, next_p);
18784 + this_cpu_write(current_tinfo, &next_p->tinfo);
18785
18786 - this_cpu_write(kernel_stack,
18787 - (unsigned long)task_stack_page(next_p) +
18788 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18789 + this_cpu_write(kernel_stack, next->sp0);
18790
18791 /*
18792 * Now maybe reload the debug registers and handle I/O bitmaps
18793 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18794 if (!p || p == current || p->state == TASK_RUNNING)
18795 return 0;
18796 stack = (unsigned long)task_stack_page(p);
18797 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18798 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18799 return 0;
18800 fp = *(u64 *)(p->thread.sp);
18801 do {
18802 - if (fp < (unsigned long)stack ||
18803 - fp >= (unsigned long)stack+THREAD_SIZE)
18804 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18805 return 0;
18806 ip = *(u64 *)(fp+8);
18807 if (!in_sched_functions(ip))
18808 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18809 index 9ee1787..33228a7 100644
18810 --- a/arch/x86/kernel/ptrace.c
18811 +++ b/arch/x86/kernel/ptrace.c
18812 @@ -182,14 +182,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
18813 {
18814 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
18815 unsigned long sp = (unsigned long)&regs->sp;
18816 - struct thread_info *tinfo;
18817
18818 - if (context == (sp & ~(THREAD_SIZE - 1)))
18819 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
18820 return sp;
18821
18822 - tinfo = (struct thread_info *)context;
18823 - if (tinfo->previous_esp)
18824 - return tinfo->previous_esp;
18825 + sp = *(unsigned long *)context;
18826 + if (sp)
18827 + return sp;
18828
18829 return (unsigned long)regs;
18830 }
18831 @@ -854,7 +853,7 @@ long arch_ptrace(struct task_struct *child, long request,
18832 unsigned long addr, unsigned long data)
18833 {
18834 int ret;
18835 - unsigned long __user *datap = (unsigned long __user *)data;
18836 + unsigned long __user *datap = (__force unsigned long __user *)data;
18837
18838 switch (request) {
18839 /* read the word at location addr in the USER area. */
18840 @@ -939,14 +938,14 @@ long arch_ptrace(struct task_struct *child, long request,
18841 if ((int) addr < 0)
18842 return -EIO;
18843 ret = do_get_thread_area(child, addr,
18844 - (struct user_desc __user *)data);
18845 + (__force struct user_desc __user *) data);
18846 break;
18847
18848 case PTRACE_SET_THREAD_AREA:
18849 if ((int) addr < 0)
18850 return -EIO;
18851 ret = do_set_thread_area(child, addr,
18852 - (struct user_desc __user *)data, 0);
18853 + (__force struct user_desc __user *) data, 0);
18854 break;
18855 #endif
18856
18857 @@ -1456,7 +1455,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18858 memset(info, 0, sizeof(*info));
18859 info->si_signo = SIGTRAP;
18860 info->si_code = si_code;
18861 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18862 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18863 }
18864
18865 void user_single_step_siginfo(struct task_struct *tsk,
18866 @@ -1485,6 +1484,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18867 # define IS_IA32 0
18868 #endif
18869
18870 +#ifdef CONFIG_GRKERNSEC_SETXID
18871 +extern void gr_delayed_cred_worker(void);
18872 +#endif
18873 +
18874 /*
18875 * We must return the syscall number to actually look up in the table.
18876 * This can be -1L to skip running any syscall at all.
18877 @@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18878 {
18879 long ret = 0;
18880
18881 +#ifdef CONFIG_GRKERNSEC_SETXID
18882 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18883 + gr_delayed_cred_worker();
18884 +#endif
18885 +
18886 /*
18887 * If we stepped into a sysenter/syscall insn, it trapped in
18888 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18889 @@ -1541,6 +1549,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18890 {
18891 bool step;
18892
18893 +#ifdef CONFIG_GRKERNSEC_SETXID
18894 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18895 + gr_delayed_cred_worker();
18896 +#endif
18897 +
18898 audit_syscall_exit(regs);
18899
18900 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18901 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18902 index 42eb330..139955c 100644
18903 --- a/arch/x86/kernel/pvclock.c
18904 +++ b/arch/x86/kernel/pvclock.c
18905 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18906 return pv_tsc_khz;
18907 }
18908
18909 -static atomic64_t last_value = ATOMIC64_INIT(0);
18910 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18911
18912 void pvclock_resume(void)
18913 {
18914 - atomic64_set(&last_value, 0);
18915 + atomic64_set_unchecked(&last_value, 0);
18916 }
18917
18918 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18919 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18920 * updating at the same time, and one of them could be slightly behind,
18921 * making the assumption that last_value always go forward fail to hold.
18922 */
18923 - last = atomic64_read(&last_value);
18924 + last = atomic64_read_unchecked(&last_value);
18925 do {
18926 if (ret < last)
18927 return last;
18928 - last = atomic64_cmpxchg(&last_value, last, ret);
18929 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18930 } while (unlikely(last != ret));
18931
18932 return ret;
18933 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18934 index 52190a9..8074389 100644
18935 --- a/arch/x86/kernel/reboot.c
18936 +++ b/arch/x86/kernel/reboot.c
18937 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18938 EXPORT_SYMBOL(pm_power_off);
18939
18940 static const struct desc_ptr no_idt = {};
18941 -static int reboot_mode;
18942 +static unsigned short reboot_mode;
18943 enum reboot_type reboot_type = BOOT_ACPI;
18944 int reboot_force;
18945
18946 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18947
18948 void __noreturn machine_real_restart(unsigned int type)
18949 {
18950 +
18951 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18952 + struct desc_struct *gdt;
18953 +#endif
18954 +
18955 local_irq_disable();
18956
18957 /*
18958 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18959
18960 /* Jump to the identity-mapped low memory code */
18961 #ifdef CONFIG_X86_32
18962 - asm volatile("jmpl *%0" : :
18963 +
18964 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18965 + gdt = get_cpu_gdt_table(smp_processor_id());
18966 + pax_open_kernel();
18967 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18968 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18969 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18970 + loadsegment(ds, __KERNEL_DS);
18971 + loadsegment(es, __KERNEL_DS);
18972 + loadsegment(ss, __KERNEL_DS);
18973 +#endif
18974 +#ifdef CONFIG_PAX_KERNEXEC
18975 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18976 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18977 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18978 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18979 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18980 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18981 +#endif
18982 + pax_close_kernel();
18983 +#endif
18984 +
18985 + asm volatile("ljmpl *%0" : :
18986 "rm" (real_mode_header->machine_real_restart_asm),
18987 "a" (type));
18988 #else
18989 @@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18990 * try to force a triple fault and then cycle between hitting the keyboard
18991 * controller and doing that
18992 */
18993 -static void native_machine_emergency_restart(void)
18994 +static void __noreturn native_machine_emergency_restart(void)
18995 {
18996 int i;
18997 int attempt = 0;
18998 @@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18999 #endif
19000 }
19001
19002 -static void __machine_emergency_restart(int emergency)
19003 +static void __noreturn __machine_emergency_restart(int emergency)
19004 {
19005 reboot_emergency = emergency;
19006 machine_ops.emergency_restart();
19007 }
19008
19009 -static void native_machine_restart(char *__unused)
19010 +static void __noreturn native_machine_restart(char *__unused)
19011 {
19012 pr_notice("machine restart\n");
19013
19014 @@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
19015 __machine_emergency_restart(0);
19016 }
19017
19018 -static void native_machine_halt(void)
19019 +static void __noreturn native_machine_halt(void)
19020 {
19021 /* Stop other cpus and apics */
19022 machine_shutdown();
19023 @@ -687,7 +714,7 @@ static void native_machine_halt(void)
19024 stop_this_cpu(NULL);
19025 }
19026
19027 -static void native_machine_power_off(void)
19028 +static void __noreturn native_machine_power_off(void)
19029 {
19030 if (pm_power_off) {
19031 if (!reboot_force)
19032 @@ -696,6 +723,7 @@ static void native_machine_power_off(void)
19033 }
19034 /* A fallback in case there is no PM info available */
19035 tboot_shutdown(TB_SHUTDOWN_HALT);
19036 + unreachable();
19037 }
19038
19039 struct machine_ops machine_ops = {
19040 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19041 index 7a6f3b3..bed145d7 100644
19042 --- a/arch/x86/kernel/relocate_kernel_64.S
19043 +++ b/arch/x86/kernel/relocate_kernel_64.S
19044 @@ -11,6 +11,7 @@
19045 #include <asm/kexec.h>
19046 #include <asm/processor-flags.h>
19047 #include <asm/pgtable_types.h>
19048 +#include <asm/alternative-asm.h>
19049
19050 /*
19051 * Must be relocatable PIC code callable as a C function
19052 @@ -160,13 +161,14 @@ identity_mapped:
19053 xorq %rbp, %rbp
19054 xorq %r8, %r8
19055 xorq %r9, %r9
19056 - xorq %r10, %r9
19057 + xorq %r10, %r10
19058 xorq %r11, %r11
19059 xorq %r12, %r12
19060 xorq %r13, %r13
19061 xorq %r14, %r14
19062 xorq %r15, %r15
19063
19064 + pax_force_retaddr 0, 1
19065 ret
19066
19067 1:
19068 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19069 index 5cee802..bc22bc3 100644
19070 --- a/arch/x86/kernel/setup.c
19071 +++ b/arch/x86/kernel/setup.c
19072 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19073
19074 switch (data->type) {
19075 case SETUP_E820_EXT:
19076 - parse_e820_ext(data);
19077 + parse_e820_ext((struct setup_data __force_kernel *)data);
19078 break;
19079 case SETUP_DTB:
19080 add_dtb(pa_data);
19081 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19082 * area (640->1Mb) as ram even though it is not.
19083 * take them out.
19084 */
19085 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19086 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19087 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19088 }
19089
19090 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19091
19092 if (!boot_params.hdr.root_flags)
19093 root_mountflags &= ~MS_RDONLY;
19094 - init_mm.start_code = (unsigned long) _text;
19095 - init_mm.end_code = (unsigned long) _etext;
19096 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19097 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19098 init_mm.end_data = (unsigned long) _edata;
19099 init_mm.brk = _brk_end;
19100
19101 - code_resource.start = virt_to_phys(_text);
19102 - code_resource.end = virt_to_phys(_etext)-1;
19103 - data_resource.start = virt_to_phys(_etext);
19104 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19105 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19106 + data_resource.start = virt_to_phys(_sdata);
19107 data_resource.end = virt_to_phys(_edata)-1;
19108 bss_resource.start = virt_to_phys(&__bss_start);
19109 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19110 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19111 index 5cdff03..5810740 100644
19112 --- a/arch/x86/kernel/setup_percpu.c
19113 +++ b/arch/x86/kernel/setup_percpu.c
19114 @@ -21,19 +21,17 @@
19115 #include <asm/cpu.h>
19116 #include <asm/stackprotector.h>
19117
19118 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19119 +#ifdef CONFIG_SMP
19120 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19121 EXPORT_PER_CPU_SYMBOL(cpu_number);
19122 +#endif
19123
19124 -#ifdef CONFIG_X86_64
19125 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19126 -#else
19127 -#define BOOT_PERCPU_OFFSET 0
19128 -#endif
19129
19130 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19131 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19132
19133 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19134 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19135 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19136 };
19137 EXPORT_SYMBOL(__per_cpu_offset);
19138 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19139 {
19140 #ifdef CONFIG_X86_32
19141 struct desc_struct gdt;
19142 + unsigned long base = per_cpu_offset(cpu);
19143
19144 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19145 - 0x2 | DESCTYPE_S, 0x8);
19146 - gdt.s = 1;
19147 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19148 + 0x83 | DESCTYPE_S, 0xC);
19149 write_gdt_entry(get_cpu_gdt_table(cpu),
19150 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19151 #endif
19152 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19153 /* alrighty, percpu areas up and running */
19154 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19155 for_each_possible_cpu(cpu) {
19156 +#ifdef CONFIG_CC_STACKPROTECTOR
19157 +#ifdef CONFIG_X86_32
19158 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19159 +#endif
19160 +#endif
19161 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19162 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19163 per_cpu(cpu_number, cpu) = cpu;
19164 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19165 */
19166 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19167 #endif
19168 +#ifdef CONFIG_CC_STACKPROTECTOR
19169 +#ifdef CONFIG_X86_32
19170 + if (!cpu)
19171 + per_cpu(stack_canary.canary, cpu) = canary;
19172 +#endif
19173 +#endif
19174 /*
19175 * Up to this point, the boot CPU has been using .init.data
19176 * area. Reload any changed state for the boot CPU.
19177 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19178 index b280908..6de349e 100644
19179 --- a/arch/x86/kernel/signal.c
19180 +++ b/arch/x86/kernel/signal.c
19181 @@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19182 * Align the stack pointer according to the i386 ABI,
19183 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19184 */
19185 - sp = ((sp + 4) & -16ul) - 4;
19186 + sp = ((sp - 12) & -16ul) - 4;
19187 #else /* !CONFIG_X86_32 */
19188 sp = round_down(sp, 16) - 8;
19189 #endif
19190 @@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19191 * Return an always-bogus address instead so we will die with SIGSEGV.
19192 */
19193 if (onsigstack && !likely(on_sig_stack(sp)))
19194 - return (void __user *)-1L;
19195 + return (__force void __user *)-1L;
19196
19197 /* save i387 state */
19198 if (used_math() && save_i387_xstate(*fpstate) < 0)
19199 - return (void __user *)-1L;
19200 + return (__force void __user *)-1L;
19201
19202 return (void __user *)sp;
19203 }
19204 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19205 }
19206
19207 if (current->mm->context.vdso)
19208 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19209 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19210 else
19211 - restorer = &frame->retcode;
19212 + restorer = (void __user *)&frame->retcode;
19213 if (ka->sa.sa_flags & SA_RESTORER)
19214 restorer = ka->sa.sa_restorer;
19215
19216 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19217 * reasons and because gdb uses it as a signature to notice
19218 * signal handler stack frames.
19219 */
19220 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19221 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19222
19223 if (err)
19224 return -EFAULT;
19225 @@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19226 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19227
19228 /* Set up to return from userspace. */
19229 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19230 + if (current->mm->context.vdso)
19231 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19232 + else
19233 + restorer = (void __user *)&frame->retcode;
19234 if (ka->sa.sa_flags & SA_RESTORER)
19235 restorer = ka->sa.sa_restorer;
19236 put_user_ex(restorer, &frame->pretcode);
19237 @@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19238 * reasons and because gdb uses it as a signature to notice
19239 * signal handler stack frames.
19240 */
19241 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19242 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19243 } put_user_catch(err);
19244
19245 if (err)
19246 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19247 index 23c39cf..52ed8d9 100644
19248 --- a/arch/x86/kernel/smpboot.c
19249 +++ b/arch/x86/kernel/smpboot.c
19250 @@ -672,6 +672,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19251 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19252 (THREAD_SIZE + task_stack_page(idle))) - 1);
19253 per_cpu(current_task, cpu) = idle;
19254 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19255
19256 #ifdef CONFIG_X86_32
19257 /* Stack for startup_32 can be just as for start_secondary onwards */
19258 @@ -679,11 +680,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19259 #else
19260 clear_tsk_thread_flag(idle, TIF_FORK);
19261 initial_gs = per_cpu_offset(cpu);
19262 - per_cpu(kernel_stack, cpu) =
19263 - (unsigned long)task_stack_page(idle) -
19264 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19265 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19266 #endif
19267 +
19268 + pax_open_kernel();
19269 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19270 + pax_close_kernel();
19271 +
19272 initial_code = (unsigned long)start_secondary;
19273 stack_start = idle->thread.sp;
19274
19275 @@ -822,6 +825,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19276 /* the FPU context is blank, nobody can own it */
19277 __cpu_disable_lazy_restore(cpu);
19278
19279 +#ifdef CONFIG_PAX_PER_CPU_PGD
19280 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19281 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19282 + KERNEL_PGD_PTRS);
19283 +#endif
19284 +
19285 + /* the FPU context is blank, nobody can own it */
19286 + __cpu_disable_lazy_restore(cpu);
19287 +
19288 err = do_boot_cpu(apicid, cpu, tidle);
19289 if (err) {
19290 pr_debug("do_boot_cpu failed %d\n", err);
19291 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19292 index c346d11..d43b163 100644
19293 --- a/arch/x86/kernel/step.c
19294 +++ b/arch/x86/kernel/step.c
19295 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19296 struct desc_struct *desc;
19297 unsigned long base;
19298
19299 - seg &= ~7UL;
19300 + seg >>= 3;
19301
19302 mutex_lock(&child->mm->context.lock);
19303 - if (unlikely((seg >> 3) >= child->mm->context.size))
19304 + if (unlikely(seg >= child->mm->context.size))
19305 addr = -1L; /* bogus selector, access would fault */
19306 else {
19307 desc = child->mm->context.ldt + seg;
19308 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19309 addr += base;
19310 }
19311 mutex_unlock(&child->mm->context.lock);
19312 - }
19313 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19314 + addr = ktla_ktva(addr);
19315
19316 return addr;
19317 }
19318 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19319 unsigned char opcode[15];
19320 unsigned long addr = convert_ip_to_linear(child, regs);
19321
19322 + if (addr == -EINVAL)
19323 + return 0;
19324 +
19325 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19326 for (i = 0; i < copied; i++) {
19327 switch (opcode[i]) {
19328 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19329 index 0b0cb5f..db6b9ed 100644
19330 --- a/arch/x86/kernel/sys_i386_32.c
19331 +++ b/arch/x86/kernel/sys_i386_32.c
19332 @@ -24,17 +24,224 @@
19333
19334 #include <asm/syscalls.h>
19335
19336 -/*
19337 - * Do a system call from kernel instead of calling sys_execve so we
19338 - * end up with proper pt_regs.
19339 - */
19340 -int kernel_execve(const char *filename,
19341 - const char *const argv[],
19342 - const char *const envp[])
19343 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19344 {
19345 - long __res;
19346 - asm volatile ("int $0x80"
19347 - : "=a" (__res)
19348 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19349 - return __res;
19350 + unsigned long pax_task_size = TASK_SIZE;
19351 +
19352 +#ifdef CONFIG_PAX_SEGMEXEC
19353 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19354 + pax_task_size = SEGMEXEC_TASK_SIZE;
19355 +#endif
19356 +
19357 + if (len > pax_task_size || addr > pax_task_size - len)
19358 + return -EINVAL;
19359 +
19360 + return 0;
19361 +}
19362 +
19363 +unsigned long
19364 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19365 + unsigned long len, unsigned long pgoff, unsigned long flags)
19366 +{
19367 + struct mm_struct *mm = current->mm;
19368 + struct vm_area_struct *vma;
19369 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19370 +
19371 +#ifdef CONFIG_PAX_SEGMEXEC
19372 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19373 + pax_task_size = SEGMEXEC_TASK_SIZE;
19374 +#endif
19375 +
19376 + pax_task_size -= PAGE_SIZE;
19377 +
19378 + if (len > pax_task_size)
19379 + return -ENOMEM;
19380 +
19381 + if (flags & MAP_FIXED)
19382 + return addr;
19383 +
19384 +#ifdef CONFIG_PAX_RANDMMAP
19385 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19386 +#endif
19387 +
19388 + if (addr) {
19389 + addr = PAGE_ALIGN(addr);
19390 + if (pax_task_size - len >= addr) {
19391 + vma = find_vma(mm, addr);
19392 + if (check_heap_stack_gap(vma, addr, len))
19393 + return addr;
19394 + }
19395 + }
19396 + if (len > mm->cached_hole_size) {
19397 + start_addr = addr = mm->free_area_cache;
19398 + } else {
19399 + start_addr = addr = mm->mmap_base;
19400 + mm->cached_hole_size = 0;
19401 + }
19402 +
19403 +#ifdef CONFIG_PAX_PAGEEXEC
19404 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19405 + start_addr = 0x00110000UL;
19406 +
19407 +#ifdef CONFIG_PAX_RANDMMAP
19408 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19409 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19410 +#endif
19411 +
19412 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19413 + start_addr = addr = mm->mmap_base;
19414 + else
19415 + addr = start_addr;
19416 + }
19417 +#endif
19418 +
19419 +full_search:
19420 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19421 + /* At this point: (!vma || addr < vma->vm_end). */
19422 + if (pax_task_size - len < addr) {
19423 + /*
19424 + * Start a new search - just in case we missed
19425 + * some holes.
19426 + */
19427 + if (start_addr != mm->mmap_base) {
19428 + start_addr = addr = mm->mmap_base;
19429 + mm->cached_hole_size = 0;
19430 + goto full_search;
19431 + }
19432 + return -ENOMEM;
19433 + }
19434 + if (check_heap_stack_gap(vma, addr, len))
19435 + break;
19436 + if (addr + mm->cached_hole_size < vma->vm_start)
19437 + mm->cached_hole_size = vma->vm_start - addr;
19438 + addr = vma->vm_end;
19439 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19440 + start_addr = addr = mm->mmap_base;
19441 + mm->cached_hole_size = 0;
19442 + goto full_search;
19443 + }
19444 + }
19445 +
19446 + /*
19447 + * Remember the place where we stopped the search:
19448 + */
19449 + mm->free_area_cache = addr + len;
19450 + return addr;
19451 +}
19452 +
19453 +unsigned long
19454 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19455 + const unsigned long len, const unsigned long pgoff,
19456 + const unsigned long flags)
19457 +{
19458 + struct vm_area_struct *vma;
19459 + struct mm_struct *mm = current->mm;
19460 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19461 +
19462 +#ifdef CONFIG_PAX_SEGMEXEC
19463 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19464 + pax_task_size = SEGMEXEC_TASK_SIZE;
19465 +#endif
19466 +
19467 + pax_task_size -= PAGE_SIZE;
19468 +
19469 + /* requested length too big for entire address space */
19470 + if (len > pax_task_size)
19471 + return -ENOMEM;
19472 +
19473 + if (flags & MAP_FIXED)
19474 + return addr;
19475 +
19476 +#ifdef CONFIG_PAX_PAGEEXEC
19477 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19478 + goto bottomup;
19479 +#endif
19480 +
19481 +#ifdef CONFIG_PAX_RANDMMAP
19482 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19483 +#endif
19484 +
19485 + /* requesting a specific address */
19486 + if (addr) {
19487 + addr = PAGE_ALIGN(addr);
19488 + if (pax_task_size - len >= addr) {
19489 + vma = find_vma(mm, addr);
19490 + if (check_heap_stack_gap(vma, addr, len))
19491 + return addr;
19492 + }
19493 + }
19494 +
19495 + /* check if free_area_cache is useful for us */
19496 + if (len <= mm->cached_hole_size) {
19497 + mm->cached_hole_size = 0;
19498 + mm->free_area_cache = mm->mmap_base;
19499 + }
19500 +
19501 + /* either no address requested or can't fit in requested address hole */
19502 + addr = mm->free_area_cache;
19503 +
19504 + /* make sure it can fit in the remaining address space */
19505 + if (addr > len) {
19506 + vma = find_vma(mm, addr-len);
19507 + if (check_heap_stack_gap(vma, addr - len, len))
19508 + /* remember the address as a hint for next time */
19509 + return (mm->free_area_cache = addr-len);
19510 + }
19511 +
19512 + if (mm->mmap_base < len)
19513 + goto bottomup;
19514 +
19515 + addr = mm->mmap_base-len;
19516 +
19517 + do {
19518 + /*
19519 + * Lookup failure means no vma is above this address,
19520 + * else if new region fits below vma->vm_start,
19521 + * return with success:
19522 + */
19523 + vma = find_vma(mm, addr);
19524 + if (check_heap_stack_gap(vma, addr, len))
19525 + /* remember the address as a hint for next time */
19526 + return (mm->free_area_cache = addr);
19527 +
19528 + /* remember the largest hole we saw so far */
19529 + if (addr + mm->cached_hole_size < vma->vm_start)
19530 + mm->cached_hole_size = vma->vm_start - addr;
19531 +
19532 + /* try just below the current vma->vm_start */
19533 + addr = skip_heap_stack_gap(vma, len);
19534 + } while (!IS_ERR_VALUE(addr));
19535 +
19536 +bottomup:
19537 + /*
19538 + * A failed mmap() very likely causes application failure,
19539 + * so fall back to the bottom-up function here. This scenario
19540 + * can happen with large stack limits and large mmap()
19541 + * allocations.
19542 + */
19543 +
19544 +#ifdef CONFIG_PAX_SEGMEXEC
19545 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19546 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19547 + else
19548 +#endif
19549 +
19550 + mm->mmap_base = TASK_UNMAPPED_BASE;
19551 +
19552 +#ifdef CONFIG_PAX_RANDMMAP
19553 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19554 + mm->mmap_base += mm->delta_mmap;
19555 +#endif
19556 +
19557 + mm->free_area_cache = mm->mmap_base;
19558 + mm->cached_hole_size = ~0UL;
19559 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19560 + /*
19561 + * Restore the topdown base:
19562 + */
19563 + mm->mmap_base = base;
19564 + mm->free_area_cache = base;
19565 + mm->cached_hole_size = ~0UL;
19566 +
19567 + return addr;
19568 }
19569 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19570 index b4d3c39..82bb73b 100644
19571 --- a/arch/x86/kernel/sys_x86_64.c
19572 +++ b/arch/x86/kernel/sys_x86_64.c
19573 @@ -95,8 +95,8 @@ out:
19574 return error;
19575 }
19576
19577 -static void find_start_end(unsigned long flags, unsigned long *begin,
19578 - unsigned long *end)
19579 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19580 + unsigned long *begin, unsigned long *end)
19581 {
19582 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19583 unsigned long new_begin;
19584 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19585 *begin = new_begin;
19586 }
19587 } else {
19588 - *begin = TASK_UNMAPPED_BASE;
19589 + *begin = mm->mmap_base;
19590 *end = TASK_SIZE;
19591 }
19592 }
19593 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19594 if (flags & MAP_FIXED)
19595 return addr;
19596
19597 - find_start_end(flags, &begin, &end);
19598 + find_start_end(mm, flags, &begin, &end);
19599
19600 if (len > end)
19601 return -ENOMEM;
19602
19603 +#ifdef CONFIG_PAX_RANDMMAP
19604 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19605 +#endif
19606 +
19607 if (addr) {
19608 addr = PAGE_ALIGN(addr);
19609 vma = find_vma(mm, addr);
19610 - if (end - len >= addr &&
19611 - (!vma || addr + len <= vma->vm_start))
19612 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19613 return addr;
19614 }
19615 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19616 @@ -172,7 +175,7 @@ full_search:
19617 }
19618 return -ENOMEM;
19619 }
19620 - if (!vma || addr + len <= vma->vm_start) {
19621 + if (check_heap_stack_gap(vma, addr, len)) {
19622 /*
19623 * Remember the place where we stopped the search:
19624 */
19625 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19626 {
19627 struct vm_area_struct *vma;
19628 struct mm_struct *mm = current->mm;
19629 - unsigned long addr = addr0, start_addr;
19630 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19631
19632 /* requested length too big for entire address space */
19633 if (len > TASK_SIZE)
19634 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19635 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19636 goto bottomup;
19637
19638 +#ifdef CONFIG_PAX_RANDMMAP
19639 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19640 +#endif
19641 +
19642 /* requesting a specific address */
19643 if (addr) {
19644 addr = PAGE_ALIGN(addr);
19645 - vma = find_vma(mm, addr);
19646 - if (TASK_SIZE - len >= addr &&
19647 - (!vma || addr + len <= vma->vm_start))
19648 - return addr;
19649 + if (TASK_SIZE - len >= addr) {
19650 + vma = find_vma(mm, addr);
19651 + if (check_heap_stack_gap(vma, addr, len))
19652 + return addr;
19653 + }
19654 }
19655
19656 /* check if free_area_cache is useful for us */
19657 @@ -240,7 +248,7 @@ try_again:
19658 * return with success:
19659 */
19660 vma = find_vma(mm, addr);
19661 - if (!vma || addr+len <= vma->vm_start)
19662 + if (check_heap_stack_gap(vma, addr, len))
19663 /* remember the address as a hint for next time */
19664 return mm->free_area_cache = addr;
19665
19666 @@ -249,8 +257,8 @@ try_again:
19667 mm->cached_hole_size = vma->vm_start - addr;
19668
19669 /* try just below the current vma->vm_start */
19670 - addr = vma->vm_start-len;
19671 - } while (len < vma->vm_start);
19672 + addr = skip_heap_stack_gap(vma, len);
19673 + } while (!IS_ERR_VALUE(addr));
19674
19675 fail:
19676 /*
19677 @@ -270,13 +278,21 @@ bottomup:
19678 * can happen with large stack limits and large mmap()
19679 * allocations.
19680 */
19681 + mm->mmap_base = TASK_UNMAPPED_BASE;
19682 +
19683 +#ifdef CONFIG_PAX_RANDMMAP
19684 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19685 + mm->mmap_base += mm->delta_mmap;
19686 +#endif
19687 +
19688 + mm->free_area_cache = mm->mmap_base;
19689 mm->cached_hole_size = ~0UL;
19690 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19691 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19692 /*
19693 * Restore the topdown base:
19694 */
19695 - mm->free_area_cache = mm->mmap_base;
19696 + mm->mmap_base = base;
19697 + mm->free_area_cache = base;
19698 mm->cached_hole_size = ~0UL;
19699
19700 return addr;
19701 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19702 index f84fe00..93fe08f 100644
19703 --- a/arch/x86/kernel/tboot.c
19704 +++ b/arch/x86/kernel/tboot.c
19705 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19706
19707 void tboot_shutdown(u32 shutdown_type)
19708 {
19709 - void (*shutdown)(void);
19710 + void (* __noreturn shutdown)(void);
19711
19712 if (!tboot_enabled())
19713 return;
19714 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19715
19716 switch_to_tboot_pt();
19717
19718 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19719 + shutdown = (void *)tboot->shutdown_entry;
19720 shutdown();
19721
19722 /* should not reach here */
19723 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19724 return 0;
19725 }
19726
19727 -static atomic_t ap_wfs_count;
19728 +static atomic_unchecked_t ap_wfs_count;
19729
19730 static int tboot_wait_for_aps(int num_aps)
19731 {
19732 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19733 {
19734 switch (action) {
19735 case CPU_DYING:
19736 - atomic_inc(&ap_wfs_count);
19737 + atomic_inc_unchecked(&ap_wfs_count);
19738 if (num_online_cpus() == 1)
19739 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19740 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19741 return NOTIFY_BAD;
19742 break;
19743 }
19744 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19745
19746 tboot_create_trampoline();
19747
19748 - atomic_set(&ap_wfs_count, 0);
19749 + atomic_set_unchecked(&ap_wfs_count, 0);
19750 register_hotcpu_notifier(&tboot_cpu_notifier);
19751
19752 acpi_os_set_prepare_sleep(&tboot_sleep);
19753 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19754 index 24d3c91..d06b473 100644
19755 --- a/arch/x86/kernel/time.c
19756 +++ b/arch/x86/kernel/time.c
19757 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19758 {
19759 unsigned long pc = instruction_pointer(regs);
19760
19761 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19762 + if (!user_mode(regs) && in_lock_functions(pc)) {
19763 #ifdef CONFIG_FRAME_POINTER
19764 - return *(unsigned long *)(regs->bp + sizeof(long));
19765 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19766 #else
19767 unsigned long *sp =
19768 (unsigned long *)kernel_stack_pointer(regs);
19769 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19770 * or above a saved flags. Eflags has bits 22-31 zero,
19771 * kernel addresses don't.
19772 */
19773 +
19774 +#ifdef CONFIG_PAX_KERNEXEC
19775 + return ktla_ktva(sp[0]);
19776 +#else
19777 if (sp[0] >> 22)
19778 return sp[0];
19779 if (sp[1] >> 22)
19780 return sp[1];
19781 #endif
19782 +
19783 +#endif
19784 }
19785 return pc;
19786 }
19787 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19788 index 9d9d2f9..cad418a 100644
19789 --- a/arch/x86/kernel/tls.c
19790 +++ b/arch/x86/kernel/tls.c
19791 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19792 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19793 return -EINVAL;
19794
19795 +#ifdef CONFIG_PAX_SEGMEXEC
19796 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19797 + return -EINVAL;
19798 +#endif
19799 +
19800 set_tls_desc(p, idx, &info, 1);
19801
19802 return 0;
19803 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19804
19805 if (kbuf)
19806 info = kbuf;
19807 - else if (__copy_from_user(infobuf, ubuf, count))
19808 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19809 return -EFAULT;
19810 else
19811 info = infobuf;
19812 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19813 index b481341..5918bbe 100644
19814 --- a/arch/x86/kernel/traps.c
19815 +++ b/arch/x86/kernel/traps.c
19816 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19817
19818 /* Do we ignore FPU interrupts ? */
19819 char ignore_fpu_irq;
19820 -
19821 -/*
19822 - * The IDT has to be page-aligned to simplify the Pentium
19823 - * F0 0F bug workaround.
19824 - */
19825 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19826 #endif
19827
19828 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19829 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19830 }
19831
19832 static void __kprobes
19833 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19834 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19835 long error_code, siginfo_t *info)
19836 {
19837 struct task_struct *tsk = current;
19838
19839 #ifdef CONFIG_X86_32
19840 - if (regs->flags & X86_VM_MASK) {
19841 + if (v8086_mode(regs)) {
19842 /*
19843 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19844 * On nmi (interrupt 2), do_trap should not be called.
19845 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19846 }
19847 #endif
19848
19849 - if (!user_mode(regs))
19850 + if (!user_mode_novm(regs))
19851 goto kernel_trap;
19852
19853 #ifdef CONFIG_X86_32
19854 @@ -147,7 +141,7 @@ trap_signal:
19855 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19856 printk_ratelimit()) {
19857 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19858 - tsk->comm, tsk->pid, str,
19859 + tsk->comm, task_pid_nr(tsk), str,
19860 regs->ip, regs->sp, error_code);
19861 print_vma_addr(" in ", regs->ip);
19862 pr_cont("\n");
19863 @@ -164,8 +158,20 @@ kernel_trap:
19864 if (!fixup_exception(regs)) {
19865 tsk->thread.error_code = error_code;
19866 tsk->thread.trap_nr = trapnr;
19867 +
19868 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19869 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19870 + str = "PAX: suspicious stack segment fault";
19871 +#endif
19872 +
19873 die(str, regs, error_code);
19874 }
19875 +
19876 +#ifdef CONFIG_PAX_REFCOUNT
19877 + if (trapnr == 4)
19878 + pax_report_refcount_overflow(regs);
19879 +#endif
19880 +
19881 return;
19882
19883 #ifdef CONFIG_X86_32
19884 @@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19885 conditional_sti(regs);
19886
19887 #ifdef CONFIG_X86_32
19888 - if (regs->flags & X86_VM_MASK)
19889 + if (v8086_mode(regs))
19890 goto gp_in_vm86;
19891 #endif
19892
19893 tsk = current;
19894 - if (!user_mode(regs))
19895 + if (!user_mode_novm(regs))
19896 goto gp_in_kernel;
19897
19898 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19899 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19900 + struct mm_struct *mm = tsk->mm;
19901 + unsigned long limit;
19902 +
19903 + down_write(&mm->mmap_sem);
19904 + limit = mm->context.user_cs_limit;
19905 + if (limit < TASK_SIZE) {
19906 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19907 + up_write(&mm->mmap_sem);
19908 + return;
19909 + }
19910 + up_write(&mm->mmap_sem);
19911 + }
19912 +#endif
19913 +
19914 tsk->thread.error_code = error_code;
19915 tsk->thread.trap_nr = X86_TRAP_GP;
19916
19917 @@ -297,6 +319,13 @@ gp_in_kernel:
19918 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19919 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19920 return;
19921 +
19922 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19923 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19924 + die("PAX: suspicious general protection fault", regs, error_code);
19925 + else
19926 +#endif
19927 +
19928 die("general protection fault", regs, error_code);
19929 }
19930
19931 @@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19932 /* It's safe to allow irq's after DR6 has been saved */
19933 preempt_conditional_sti(regs);
19934
19935 - if (regs->flags & X86_VM_MASK) {
19936 + if (v8086_mode(regs)) {
19937 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19938 X86_TRAP_DB);
19939 preempt_conditional_cli(regs);
19940 @@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19941 * We already checked v86 mode above, so we can check for kernel mode
19942 * by just checking the CPL of CS.
19943 */
19944 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19945 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19946 tsk->thread.debugreg6 &= ~DR_STEP;
19947 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19948 regs->flags &= ~X86_EFLAGS_TF;
19949 @@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19950 return;
19951 conditional_sti(regs);
19952
19953 - if (!user_mode_vm(regs))
19954 + if (!user_mode(regs))
19955 {
19956 if (!fixup_exception(regs)) {
19957 task->thread.error_code = error_code;
19958 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19959 index 36fd420..7e5892d 100644
19960 --- a/arch/x86/kernel/uprobes.c
19961 +++ b/arch/x86/kernel/uprobes.c
19962 @@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19963 int ret = NOTIFY_DONE;
19964
19965 /* We are only interested in userspace traps */
19966 - if (regs && !user_mode_vm(regs))
19967 + if (regs && !user_mode(regs))
19968 return NOTIFY_DONE;
19969
19970 switch (val) {
19971 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19972 index b9242ba..50c5edd 100644
19973 --- a/arch/x86/kernel/verify_cpu.S
19974 +++ b/arch/x86/kernel/verify_cpu.S
19975 @@ -20,6 +20,7 @@
19976 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19977 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19978 * arch/x86/kernel/head_32.S: processor startup
19979 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19980 *
19981 * verify_cpu, returns the status of longmode and SSE in register %eax.
19982 * 0: Success 1: Failure
19983 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19984 index 54abcc0..eb6c848 100644
19985 --- a/arch/x86/kernel/vm86_32.c
19986 +++ b/arch/x86/kernel/vm86_32.c
19987 @@ -43,6 +43,7 @@
19988 #include <linux/ptrace.h>
19989 #include <linux/audit.h>
19990 #include <linux/stddef.h>
19991 +#include <linux/grsecurity.h>
19992
19993 #include <asm/uaccess.h>
19994 #include <asm/io.h>
19995 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19996 do_exit(SIGSEGV);
19997 }
19998
19999 - tss = &per_cpu(init_tss, get_cpu());
20000 + tss = init_tss + get_cpu();
20001 current->thread.sp0 = current->thread.saved_sp0;
20002 current->thread.sysenter_cs = __KERNEL_CS;
20003 load_sp0(tss, &current->thread);
20004 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
20005 struct task_struct *tsk;
20006 int tmp, ret = -EPERM;
20007
20008 +#ifdef CONFIG_GRKERNSEC_VM86
20009 + if (!capable(CAP_SYS_RAWIO)) {
20010 + gr_handle_vm86();
20011 + goto out;
20012 + }
20013 +#endif
20014 +
20015 tsk = current;
20016 if (tsk->thread.saved_sp0)
20017 goto out;
20018 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20019 int tmp, ret;
20020 struct vm86plus_struct __user *v86;
20021
20022 +#ifdef CONFIG_GRKERNSEC_VM86
20023 + if (!capable(CAP_SYS_RAWIO)) {
20024 + gr_handle_vm86();
20025 + ret = -EPERM;
20026 + goto out;
20027 + }
20028 +#endif
20029 +
20030 tsk = current;
20031 switch (cmd) {
20032 case VM86_REQUEST_IRQ:
20033 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20034 tsk->thread.saved_fs = info->regs32->fs;
20035 tsk->thread.saved_gs = get_user_gs(info->regs32);
20036
20037 - tss = &per_cpu(init_tss, get_cpu());
20038 + tss = init_tss + get_cpu();
20039 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20040 if (cpu_has_sep)
20041 tsk->thread.sysenter_cs = 0;
20042 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20043 goto cannot_handle;
20044 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20045 goto cannot_handle;
20046 - intr_ptr = (unsigned long __user *) (i << 2);
20047 + intr_ptr = (__force unsigned long __user *) (i << 2);
20048 if (get_user(segoffs, intr_ptr))
20049 goto cannot_handle;
20050 if ((segoffs >> 16) == BIOSSEG)
20051 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20052 index 22a1530..8fbaaad 100644
20053 --- a/arch/x86/kernel/vmlinux.lds.S
20054 +++ b/arch/x86/kernel/vmlinux.lds.S
20055 @@ -26,6 +26,13 @@
20056 #include <asm/page_types.h>
20057 #include <asm/cache.h>
20058 #include <asm/boot.h>
20059 +#include <asm/segment.h>
20060 +
20061 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20062 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20063 +#else
20064 +#define __KERNEL_TEXT_OFFSET 0
20065 +#endif
20066
20067 #undef i386 /* in case the preprocessor is a 32bit one */
20068
20069 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20070
20071 PHDRS {
20072 text PT_LOAD FLAGS(5); /* R_E */
20073 +#ifdef CONFIG_X86_32
20074 + module PT_LOAD FLAGS(5); /* R_E */
20075 +#endif
20076 +#ifdef CONFIG_XEN
20077 + rodata PT_LOAD FLAGS(5); /* R_E */
20078 +#else
20079 + rodata PT_LOAD FLAGS(4); /* R__ */
20080 +#endif
20081 data PT_LOAD FLAGS(6); /* RW_ */
20082 -#ifdef CONFIG_X86_64
20083 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20084 #ifdef CONFIG_SMP
20085 percpu PT_LOAD FLAGS(6); /* RW_ */
20086 #endif
20087 + text.init PT_LOAD FLAGS(5); /* R_E */
20088 + text.exit PT_LOAD FLAGS(5); /* R_E */
20089 init PT_LOAD FLAGS(7); /* RWE */
20090 -#endif
20091 note PT_NOTE FLAGS(0); /* ___ */
20092 }
20093
20094 SECTIONS
20095 {
20096 #ifdef CONFIG_X86_32
20097 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20098 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20099 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20100 #else
20101 - . = __START_KERNEL;
20102 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20103 + . = __START_KERNEL;
20104 #endif
20105
20106 /* Text and read-only data */
20107 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20108 - _text = .;
20109 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20110 /* bootstrapping code */
20111 +#ifdef CONFIG_X86_32
20112 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20113 +#else
20114 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20115 +#endif
20116 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20117 + _text = .;
20118 HEAD_TEXT
20119 #ifdef CONFIG_X86_32
20120 . = ALIGN(PAGE_SIZE);
20121 @@ -108,13 +128,48 @@ SECTIONS
20122 IRQENTRY_TEXT
20123 *(.fixup)
20124 *(.gnu.warning)
20125 - /* End of text section */
20126 - _etext = .;
20127 } :text = 0x9090
20128
20129 - NOTES :text :note
20130 + . += __KERNEL_TEXT_OFFSET;
20131
20132 - EXCEPTION_TABLE(16) :text = 0x9090
20133 +#ifdef CONFIG_X86_32
20134 + . = ALIGN(PAGE_SIZE);
20135 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20136 +
20137 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20138 + MODULES_EXEC_VADDR = .;
20139 + BYTE(0)
20140 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20141 + . = ALIGN(HPAGE_SIZE) - 1;
20142 + MODULES_EXEC_END = .;
20143 +#endif
20144 +
20145 + } :module
20146 +#endif
20147 +
20148 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20149 + /* End of text section */
20150 + BYTE(0)
20151 + _etext = . - __KERNEL_TEXT_OFFSET;
20152 + }
20153 +
20154 +#ifdef CONFIG_X86_32
20155 + . = ALIGN(PAGE_SIZE);
20156 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20157 + *(.idt)
20158 + . = ALIGN(PAGE_SIZE);
20159 + *(.empty_zero_page)
20160 + *(.initial_pg_fixmap)
20161 + *(.initial_pg_pmd)
20162 + *(.initial_page_table)
20163 + *(.swapper_pg_dir)
20164 + } :rodata
20165 +#endif
20166 +
20167 + . = ALIGN(PAGE_SIZE);
20168 + NOTES :rodata :note
20169 +
20170 + EXCEPTION_TABLE(16) :rodata
20171
20172 #if defined(CONFIG_DEBUG_RODATA)
20173 /* .text should occupy whole number of pages */
20174 @@ -126,16 +181,20 @@ SECTIONS
20175
20176 /* Data */
20177 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20178 +
20179 +#ifdef CONFIG_PAX_KERNEXEC
20180 + . = ALIGN(HPAGE_SIZE);
20181 +#else
20182 + . = ALIGN(PAGE_SIZE);
20183 +#endif
20184 +
20185 /* Start of data section */
20186 _sdata = .;
20187
20188 /* init_task */
20189 INIT_TASK_DATA(THREAD_SIZE)
20190
20191 -#ifdef CONFIG_X86_32
20192 - /* 32 bit has nosave before _edata */
20193 NOSAVE_DATA
20194 -#endif
20195
20196 PAGE_ALIGNED_DATA(PAGE_SIZE)
20197
20198 @@ -176,12 +235,19 @@ SECTIONS
20199 #endif /* CONFIG_X86_64 */
20200
20201 /* Init code and data - will be freed after init */
20202 - . = ALIGN(PAGE_SIZE);
20203 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20204 + BYTE(0)
20205 +
20206 +#ifdef CONFIG_PAX_KERNEXEC
20207 + . = ALIGN(HPAGE_SIZE);
20208 +#else
20209 + . = ALIGN(PAGE_SIZE);
20210 +#endif
20211 +
20212 __init_begin = .; /* paired with __init_end */
20213 - }
20214 + } :init.begin
20215
20216 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20217 +#ifdef CONFIG_SMP
20218 /*
20219 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20220 * output PHDR, so the next output section - .init.text - should
20221 @@ -190,12 +256,27 @@ SECTIONS
20222 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20223 #endif
20224
20225 - INIT_TEXT_SECTION(PAGE_SIZE)
20226 -#ifdef CONFIG_X86_64
20227 - :init
20228 -#endif
20229 + . = ALIGN(PAGE_SIZE);
20230 + init_begin = .;
20231 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20232 + VMLINUX_SYMBOL(_sinittext) = .;
20233 + INIT_TEXT
20234 + VMLINUX_SYMBOL(_einittext) = .;
20235 + . = ALIGN(PAGE_SIZE);
20236 + } :text.init
20237
20238 - INIT_DATA_SECTION(16)
20239 + /*
20240 + * .exit.text is discard at runtime, not link time, to deal with
20241 + * references from .altinstructions and .eh_frame
20242 + */
20243 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20244 + EXIT_TEXT
20245 + . = ALIGN(16);
20246 + } :text.exit
20247 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20248 +
20249 + . = ALIGN(PAGE_SIZE);
20250 + INIT_DATA_SECTION(16) :init
20251
20252 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20253 __x86_cpu_dev_start = .;
20254 @@ -257,19 +338,12 @@ SECTIONS
20255 }
20256
20257 . = ALIGN(8);
20258 - /*
20259 - * .exit.text is discard at runtime, not link time, to deal with
20260 - * references from .altinstructions and .eh_frame
20261 - */
20262 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20263 - EXIT_TEXT
20264 - }
20265
20266 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20267 EXIT_DATA
20268 }
20269
20270 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20271 +#ifndef CONFIG_SMP
20272 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20273 #endif
20274
20275 @@ -288,16 +362,10 @@ SECTIONS
20276 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20277 __smp_locks = .;
20278 *(.smp_locks)
20279 - . = ALIGN(PAGE_SIZE);
20280 __smp_locks_end = .;
20281 + . = ALIGN(PAGE_SIZE);
20282 }
20283
20284 -#ifdef CONFIG_X86_64
20285 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20286 - NOSAVE_DATA
20287 - }
20288 -#endif
20289 -
20290 /* BSS */
20291 . = ALIGN(PAGE_SIZE);
20292 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20293 @@ -313,6 +381,7 @@ SECTIONS
20294 __brk_base = .;
20295 . += 64 * 1024; /* 64k alignment slop space */
20296 *(.brk_reservation) /* areas brk users have reserved */
20297 + . = ALIGN(HPAGE_SIZE);
20298 __brk_limit = .;
20299 }
20300
20301 @@ -339,13 +408,12 @@ SECTIONS
20302 * for the boot processor.
20303 */
20304 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20305 -INIT_PER_CPU(gdt_page);
20306 INIT_PER_CPU(irq_stack_union);
20307
20308 /*
20309 * Build-time check on the image size:
20310 */
20311 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20312 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20313 "kernel image bigger than KERNEL_IMAGE_SIZE");
20314
20315 #ifdef CONFIG_SMP
20316 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20317 index 992f890..fc38904 100644
20318 --- a/arch/x86/kernel/vsmp_64.c
20319 +++ b/arch/x86/kernel/vsmp_64.c
20320 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20321 static void vsmp_apic_post_init(void)
20322 {
20323 /* need to update phys_pkg_id */
20324 - apic->phys_pkg_id = apicid_phys_pkg_id;
20325 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20326 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20327 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20328 }
20329
20330 void __init vsmp_init(void)
20331 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20332 index 8d141b3..40a0fe4 100644
20333 --- a/arch/x86/kernel/vsyscall_64.c
20334 +++ b/arch/x86/kernel/vsyscall_64.c
20335 @@ -56,15 +56,13 @@
20336 DEFINE_VVAR(int, vgetcpu_mode);
20337 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20338
20339 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20340 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20341
20342 static int __init vsyscall_setup(char *str)
20343 {
20344 if (str) {
20345 if (!strcmp("emulate", str))
20346 vsyscall_mode = EMULATE;
20347 - else if (!strcmp("native", str))
20348 - vsyscall_mode = NATIVE;
20349 else if (!strcmp("none", str))
20350 vsyscall_mode = NONE;
20351 else
20352 @@ -306,8 +304,7 @@ done:
20353 return true;
20354
20355 sigsegv:
20356 - force_sig(SIGSEGV, current);
20357 - return true;
20358 + do_group_exit(SIGKILL);
20359 }
20360
20361 /*
20362 @@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20363 extern char __vvar_page;
20364 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20365
20366 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20367 - vsyscall_mode == NATIVE
20368 - ? PAGE_KERNEL_VSYSCALL
20369 - : PAGE_KERNEL_VVAR);
20370 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20371 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20372 (unsigned long)VSYSCALL_START);
20373
20374 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20375 index 6020f6f..bedd6e3 100644
20376 --- a/arch/x86/kernel/x8664_ksyms_64.c
20377 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20378 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20379 EXPORT_SYMBOL(copy_user_generic_unrolled);
20380 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20381 EXPORT_SYMBOL(__copy_user_nocache);
20382 -EXPORT_SYMBOL(_copy_from_user);
20383 -EXPORT_SYMBOL(_copy_to_user);
20384
20385 EXPORT_SYMBOL(copy_page);
20386 EXPORT_SYMBOL(clear_page);
20387 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20388 index 3d3e207..316a7e0 100644
20389 --- a/arch/x86/kernel/xsave.c
20390 +++ b/arch/x86/kernel/xsave.c
20391 @@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20392 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20393 return -EINVAL;
20394
20395 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20396 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20397 fx_sw_user->extended_size -
20398 FP_XSTATE_MAGIC2_SIZE));
20399 if (err)
20400 @@ -268,7 +268,7 @@ fx_only:
20401 * the other extended state.
20402 */
20403 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20404 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20405 + return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
20406 }
20407
20408 /*
20409 @@ -297,8 +297,7 @@ int restore_i387_xstate(void __user *buf)
20410 if (use_xsave())
20411 err = restore_user_xstate(buf);
20412 else
20413 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20414 - buf);
20415 + err = fxrstor_checking((struct i387_fxsave_struct __user *)buf);
20416 if (unlikely(err)) {
20417 /*
20418 * Encountered an error while doing the restore from the
20419 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20420 index 0595f13..b544fa3 100644
20421 --- a/arch/x86/kvm/cpuid.c
20422 +++ b/arch/x86/kvm/cpuid.c
20423 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20424 struct kvm_cpuid2 *cpuid,
20425 struct kvm_cpuid_entry2 __user *entries)
20426 {
20427 - int r;
20428 + int r, i;
20429
20430 r = -E2BIG;
20431 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20432 goto out;
20433 r = -EFAULT;
20434 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20435 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20436 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20437 goto out;
20438 + for (i = 0; i < cpuid->nent; ++i) {
20439 + struct kvm_cpuid_entry2 cpuid_entry;
20440 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20441 + goto out;
20442 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20443 + }
20444 vcpu->arch.cpuid_nent = cpuid->nent;
20445 kvm_apic_set_version(vcpu);
20446 kvm_x86_ops->cpuid_update(vcpu);
20447 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20448 struct kvm_cpuid2 *cpuid,
20449 struct kvm_cpuid_entry2 __user *entries)
20450 {
20451 - int r;
20452 + int r, i;
20453
20454 r = -E2BIG;
20455 if (cpuid->nent < vcpu->arch.cpuid_nent)
20456 goto out;
20457 r = -EFAULT;
20458 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20459 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20460 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20461 goto out;
20462 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20463 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20464 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20465 + goto out;
20466 + }
20467 return 0;
20468
20469 out:
20470 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20471 index a3b57a2..e8f3324 100644
20472 --- a/arch/x86/kvm/emulate.c
20473 +++ b/arch/x86/kvm/emulate.c
20474 @@ -256,6 +256,7 @@ struct gprefix {
20475
20476 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20477 do { \
20478 + unsigned long _tmp; \
20479 __asm__ __volatile__ ( \
20480 _PRE_EFLAGS("0", "4", "2") \
20481 _op _suffix " %"_x"3,%1; " \
20482 @@ -270,8 +271,6 @@ struct gprefix {
20483 /* Raw emulation: instruction has two explicit operands. */
20484 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20485 do { \
20486 - unsigned long _tmp; \
20487 - \
20488 switch ((ctxt)->dst.bytes) { \
20489 case 2: \
20490 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20491 @@ -287,7 +286,6 @@ struct gprefix {
20492
20493 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20494 do { \
20495 - unsigned long _tmp; \
20496 switch ((ctxt)->dst.bytes) { \
20497 case 1: \
20498 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20499 @@ -390,8 +388,7 @@ struct gprefix {
20500 _ASM_EXTABLE(1b, 3b) \
20501 : "=m" ((ctxt)->eflags), "=&r" (_tmp), \
20502 "+a" (*rax), "+d" (*rdx), "+qm"(_ex) \
20503 - : "i" (EFLAGS_MASK), "m" ((ctxt)->src.val), \
20504 - "a" (*rax), "d" (*rdx)); \
20505 + : "i" (EFLAGS_MASK), "m" ((ctxt)->src.val)); \
20506 } while (0)
20507
20508 /* instruction has only one source operand, destination is implicit (e.g. mul, div, imul, idiv) */
20509 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20510 index ce87878..ab48aa3 100644
20511 --- a/arch/x86/kvm/lapic.c
20512 +++ b/arch/x86/kvm/lapic.c
20513 @@ -54,7 +54,7 @@
20514 #define APIC_BUS_CYCLE_NS 1
20515
20516 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20517 -#define apic_debug(fmt, arg...)
20518 +#define apic_debug(fmt, arg...) do {} while (0)
20519
20520 #define APIC_LVT_NUM 6
20521 /* 14 is the version for Xeon and Pentium 8.4.8*/
20522 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20523 index bb7cf01..0348a05 100644
20524 --- a/arch/x86/kvm/paging_tmpl.h
20525 +++ b/arch/x86/kvm/paging_tmpl.h
20526 @@ -196,7 +196,7 @@ retry_walk:
20527 if (unlikely(kvm_is_error_hva(host_addr)))
20528 goto error;
20529
20530 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20531 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20532 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20533 goto error;
20534
20535 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20536 index baead95..90feeb4 100644
20537 --- a/arch/x86/kvm/svm.c
20538 +++ b/arch/x86/kvm/svm.c
20539 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20540 int cpu = raw_smp_processor_id();
20541
20542 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20543 +
20544 + pax_open_kernel();
20545 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20546 + pax_close_kernel();
20547 +
20548 load_TR_desc();
20549 }
20550
20551 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20552 #endif
20553 #endif
20554
20555 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20556 + __set_fs(current_thread_info()->addr_limit);
20557 +#endif
20558 +
20559 reload_tss(vcpu);
20560
20561 local_irq_disable();
20562 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20563 index ff66a3b..48ad872 100644
20564 --- a/arch/x86/kvm/vmx.c
20565 +++ b/arch/x86/kvm/vmx.c
20566 @@ -1331,7 +1331,11 @@ static void reload_tss(void)
20567 struct desc_struct *descs;
20568
20569 descs = (void *)gdt->address;
20570 +
20571 + pax_open_kernel();
20572 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20573 + pax_close_kernel();
20574 +
20575 load_TR_desc();
20576 }
20577
20578 @@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20579 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20580 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20581
20582 +#ifdef CONFIG_PAX_PER_CPU_PGD
20583 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20584 +#endif
20585 +
20586 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20587 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20588 vmx->loaded_vmcs->cpu = cpu;
20589 @@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20590 if (!cpu_has_vmx_flexpriority())
20591 flexpriority_enabled = 0;
20592
20593 - if (!cpu_has_vmx_tpr_shadow())
20594 - kvm_x86_ops->update_cr8_intercept = NULL;
20595 + if (!cpu_has_vmx_tpr_shadow()) {
20596 + pax_open_kernel();
20597 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20598 + pax_close_kernel();
20599 + }
20600
20601 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20602 kvm_disable_largepages();
20603 @@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20604
20605 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20606 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20607 +
20608 +#ifndef CONFIG_PAX_PER_CPU_PGD
20609 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20610 +#endif
20611
20612 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20613 #ifdef CONFIG_X86_64
20614 @@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20615 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20616
20617 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20618 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20619 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20620
20621 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20622 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20623 @@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20624 "jmp .Lkvm_vmx_return \n\t"
20625 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20626 ".Lkvm_vmx_return: "
20627 +
20628 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20629 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20630 + ".Lkvm_vmx_return2: "
20631 +#endif
20632 +
20633 /* Save guest registers, load host registers, keep flags */
20634 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20635 "pop %0 \n\t"
20636 @@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20637 #endif
20638 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20639 [wordsize]"i"(sizeof(ulong))
20640 +
20641 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20642 + ,[cs]"i"(__KERNEL_CS)
20643 +#endif
20644 +
20645 : "cc", "memory"
20646 , R"ax", R"bx", R"di", R"si"
20647 #ifdef CONFIG_X86_64
20648 @@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20649 #endif
20650 );
20651
20652 -#ifndef CONFIG_X86_64
20653 +#ifdef CONFIG_X86_32
20654 /*
20655 * The sysexit path does not restore ds/es, so we must set them to
20656 * a reasonable value ourselves.
20657 @@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20658 * may be executed in interrupt context, which saves and restore segments
20659 * around it, nullifying its effect.
20660 */
20661 - loadsegment(ds, __USER_DS);
20662 - loadsegment(es, __USER_DS);
20663 + loadsegment(ds, __KERNEL_DS);
20664 + loadsegment(es, __KERNEL_DS);
20665 + loadsegment(ss, __KERNEL_DS);
20666 +
20667 +#ifdef CONFIG_PAX_KERNEXEC
20668 + loadsegment(fs, __KERNEL_PERCPU);
20669 +#endif
20670 +
20671 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20672 + __set_fs(current_thread_info()->addr_limit);
20673 +#endif
20674 +
20675 #endif
20676
20677 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20678 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20679 index a201790..9ac0c3c 100644
20680 --- a/arch/x86/kvm/x86.c
20681 +++ b/arch/x86/kvm/x86.c
20682 @@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20683 {
20684 struct kvm *kvm = vcpu->kvm;
20685 int lm = is_long_mode(vcpu);
20686 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20687 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20688 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20689 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20690 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20691 : kvm->arch.xen_hvm_config.blob_size_32;
20692 u32 page_num = data & ~PAGE_MASK;
20693 @@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20694 if (n < msr_list.nmsrs)
20695 goto out;
20696 r = -EFAULT;
20697 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20698 + goto out;
20699 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20700 num_msrs_to_save * sizeof(u32)))
20701 goto out;
20702 @@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20703 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20704 struct kvm_interrupt *irq)
20705 {
20706 - if (irq->irq < 0 || irq->irq >= 256)
20707 + if (irq->irq >= 256)
20708 return -EINVAL;
20709 if (irqchip_in_kernel(vcpu->kvm))
20710 return -ENXIO;
20711 @@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20712 kvm_mmu_set_mmio_spte_mask(mask);
20713 }
20714
20715 -int kvm_arch_init(void *opaque)
20716 +int kvm_arch_init(const void *opaque)
20717 {
20718 int r;
20719 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20720 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20721 index 642d880..cc9ebac 100644
20722 --- a/arch/x86/lguest/boot.c
20723 +++ b/arch/x86/lguest/boot.c
20724 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20725
20726 static void set_lguest_basic_apic_ops(void)
20727 {
20728 - apic->read = lguest_apic_read;
20729 - apic->write = lguest_apic_write;
20730 - apic->icr_read = lguest_apic_icr_read;
20731 - apic->icr_write = lguest_apic_icr_write;
20732 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20733 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20734 + *(void **)&apic->read = lguest_apic_read;
20735 + *(void **)&apic->write = lguest_apic_write;
20736 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20737 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20738 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20739 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20740 };
20741 #endif
20742
20743 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20744 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20745 * Launcher to reboot us.
20746 */
20747 -static void lguest_restart(char *reason)
20748 +static __noreturn void lguest_restart(char *reason)
20749 {
20750 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20751 + BUG();
20752 }
20753
20754 /*G:050
20755 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20756 index 00933d5..3a64af9 100644
20757 --- a/arch/x86/lib/atomic64_386_32.S
20758 +++ b/arch/x86/lib/atomic64_386_32.S
20759 @@ -48,6 +48,10 @@ BEGIN(read)
20760 movl (v), %eax
20761 movl 4(v), %edx
20762 RET_ENDP
20763 +BEGIN(read_unchecked)
20764 + movl (v), %eax
20765 + movl 4(v), %edx
20766 +RET_ENDP
20767 #undef v
20768
20769 #define v %esi
20770 @@ -55,6 +59,10 @@ BEGIN(set)
20771 movl %ebx, (v)
20772 movl %ecx, 4(v)
20773 RET_ENDP
20774 +BEGIN(set_unchecked)
20775 + movl %ebx, (v)
20776 + movl %ecx, 4(v)
20777 +RET_ENDP
20778 #undef v
20779
20780 #define v %esi
20781 @@ -70,6 +78,20 @@ RET_ENDP
20782 BEGIN(add)
20783 addl %eax, (v)
20784 adcl %edx, 4(v)
20785 +
20786 +#ifdef CONFIG_PAX_REFCOUNT
20787 + jno 0f
20788 + subl %eax, (v)
20789 + sbbl %edx, 4(v)
20790 + int $4
20791 +0:
20792 + _ASM_EXTABLE(0b, 0b)
20793 +#endif
20794 +
20795 +RET_ENDP
20796 +BEGIN(add_unchecked)
20797 + addl %eax, (v)
20798 + adcl %edx, 4(v)
20799 RET_ENDP
20800 #undef v
20801
20802 @@ -77,6 +99,24 @@ RET_ENDP
20803 BEGIN(add_return)
20804 addl (v), %eax
20805 adcl 4(v), %edx
20806 +
20807 +#ifdef CONFIG_PAX_REFCOUNT
20808 + into
20809 +1234:
20810 + _ASM_EXTABLE(1234b, 2f)
20811 +#endif
20812 +
20813 + movl %eax, (v)
20814 + movl %edx, 4(v)
20815 +
20816 +#ifdef CONFIG_PAX_REFCOUNT
20817 +2:
20818 +#endif
20819 +
20820 +RET_ENDP
20821 +BEGIN(add_return_unchecked)
20822 + addl (v), %eax
20823 + adcl 4(v), %edx
20824 movl %eax, (v)
20825 movl %edx, 4(v)
20826 RET_ENDP
20827 @@ -86,6 +126,20 @@ RET_ENDP
20828 BEGIN(sub)
20829 subl %eax, (v)
20830 sbbl %edx, 4(v)
20831 +
20832 +#ifdef CONFIG_PAX_REFCOUNT
20833 + jno 0f
20834 + addl %eax, (v)
20835 + adcl %edx, 4(v)
20836 + int $4
20837 +0:
20838 + _ASM_EXTABLE(0b, 0b)
20839 +#endif
20840 +
20841 +RET_ENDP
20842 +BEGIN(sub_unchecked)
20843 + subl %eax, (v)
20844 + sbbl %edx, 4(v)
20845 RET_ENDP
20846 #undef v
20847
20848 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20849 sbbl $0, %edx
20850 addl (v), %eax
20851 adcl 4(v), %edx
20852 +
20853 +#ifdef CONFIG_PAX_REFCOUNT
20854 + into
20855 +1234:
20856 + _ASM_EXTABLE(1234b, 2f)
20857 +#endif
20858 +
20859 + movl %eax, (v)
20860 + movl %edx, 4(v)
20861 +
20862 +#ifdef CONFIG_PAX_REFCOUNT
20863 +2:
20864 +#endif
20865 +
20866 +RET_ENDP
20867 +BEGIN(sub_return_unchecked)
20868 + negl %edx
20869 + negl %eax
20870 + sbbl $0, %edx
20871 + addl (v), %eax
20872 + adcl 4(v), %edx
20873 movl %eax, (v)
20874 movl %edx, 4(v)
20875 RET_ENDP
20876 @@ -105,6 +180,20 @@ RET_ENDP
20877 BEGIN(inc)
20878 addl $1, (v)
20879 adcl $0, 4(v)
20880 +
20881 +#ifdef CONFIG_PAX_REFCOUNT
20882 + jno 0f
20883 + subl $1, (v)
20884 + sbbl $0, 4(v)
20885 + int $4
20886 +0:
20887 + _ASM_EXTABLE(0b, 0b)
20888 +#endif
20889 +
20890 +RET_ENDP
20891 +BEGIN(inc_unchecked)
20892 + addl $1, (v)
20893 + adcl $0, 4(v)
20894 RET_ENDP
20895 #undef v
20896
20897 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20898 movl 4(v), %edx
20899 addl $1, %eax
20900 adcl $0, %edx
20901 +
20902 +#ifdef CONFIG_PAX_REFCOUNT
20903 + into
20904 +1234:
20905 + _ASM_EXTABLE(1234b, 2f)
20906 +#endif
20907 +
20908 + movl %eax, (v)
20909 + movl %edx, 4(v)
20910 +
20911 +#ifdef CONFIG_PAX_REFCOUNT
20912 +2:
20913 +#endif
20914 +
20915 +RET_ENDP
20916 +BEGIN(inc_return_unchecked)
20917 + movl (v), %eax
20918 + movl 4(v), %edx
20919 + addl $1, %eax
20920 + adcl $0, %edx
20921 movl %eax, (v)
20922 movl %edx, 4(v)
20923 RET_ENDP
20924 @@ -123,6 +232,20 @@ RET_ENDP
20925 BEGIN(dec)
20926 subl $1, (v)
20927 sbbl $0, 4(v)
20928 +
20929 +#ifdef CONFIG_PAX_REFCOUNT
20930 + jno 0f
20931 + addl $1, (v)
20932 + adcl $0, 4(v)
20933 + int $4
20934 +0:
20935 + _ASM_EXTABLE(0b, 0b)
20936 +#endif
20937 +
20938 +RET_ENDP
20939 +BEGIN(dec_unchecked)
20940 + subl $1, (v)
20941 + sbbl $0, 4(v)
20942 RET_ENDP
20943 #undef v
20944
20945 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20946 movl 4(v), %edx
20947 subl $1, %eax
20948 sbbl $0, %edx
20949 +
20950 +#ifdef CONFIG_PAX_REFCOUNT
20951 + into
20952 +1234:
20953 + _ASM_EXTABLE(1234b, 2f)
20954 +#endif
20955 +
20956 + movl %eax, (v)
20957 + movl %edx, 4(v)
20958 +
20959 +#ifdef CONFIG_PAX_REFCOUNT
20960 +2:
20961 +#endif
20962 +
20963 +RET_ENDP
20964 +BEGIN(dec_return_unchecked)
20965 + movl (v), %eax
20966 + movl 4(v), %edx
20967 + subl $1, %eax
20968 + sbbl $0, %edx
20969 movl %eax, (v)
20970 movl %edx, 4(v)
20971 RET_ENDP
20972 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20973 adcl %edx, %edi
20974 addl (v), %eax
20975 adcl 4(v), %edx
20976 +
20977 +#ifdef CONFIG_PAX_REFCOUNT
20978 + into
20979 +1234:
20980 + _ASM_EXTABLE(1234b, 2f)
20981 +#endif
20982 +
20983 cmpl %eax, %ecx
20984 je 3f
20985 1:
20986 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20987 1:
20988 addl $1, %eax
20989 adcl $0, %edx
20990 +
20991 +#ifdef CONFIG_PAX_REFCOUNT
20992 + into
20993 +1234:
20994 + _ASM_EXTABLE(1234b, 2f)
20995 +#endif
20996 +
20997 movl %eax, (v)
20998 movl %edx, 4(v)
20999 movl $1, %eax
21000 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
21001 movl 4(v), %edx
21002 subl $1, %eax
21003 sbbl $0, %edx
21004 +
21005 +#ifdef CONFIG_PAX_REFCOUNT
21006 + into
21007 +1234:
21008 + _ASM_EXTABLE(1234b, 1f)
21009 +#endif
21010 +
21011 js 1f
21012 movl %eax, (v)
21013 movl %edx, 4(v)
21014 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21015 index f5cc9eb..51fa319 100644
21016 --- a/arch/x86/lib/atomic64_cx8_32.S
21017 +++ b/arch/x86/lib/atomic64_cx8_32.S
21018 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21019 CFI_STARTPROC
21020
21021 read64 %ecx
21022 + pax_force_retaddr
21023 ret
21024 CFI_ENDPROC
21025 ENDPROC(atomic64_read_cx8)
21026
21027 +ENTRY(atomic64_read_unchecked_cx8)
21028 + CFI_STARTPROC
21029 +
21030 + read64 %ecx
21031 + pax_force_retaddr
21032 + ret
21033 + CFI_ENDPROC
21034 +ENDPROC(atomic64_read_unchecked_cx8)
21035 +
21036 ENTRY(atomic64_set_cx8)
21037 CFI_STARTPROC
21038
21039 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21040 cmpxchg8b (%esi)
21041 jne 1b
21042
21043 + pax_force_retaddr
21044 ret
21045 CFI_ENDPROC
21046 ENDPROC(atomic64_set_cx8)
21047
21048 +ENTRY(atomic64_set_unchecked_cx8)
21049 + CFI_STARTPROC
21050 +
21051 +1:
21052 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
21053 + * are atomic on 586 and newer */
21054 + cmpxchg8b (%esi)
21055 + jne 1b
21056 +
21057 + pax_force_retaddr
21058 + ret
21059 + CFI_ENDPROC
21060 +ENDPROC(atomic64_set_unchecked_cx8)
21061 +
21062 ENTRY(atomic64_xchg_cx8)
21063 CFI_STARTPROC
21064
21065 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21066 cmpxchg8b (%esi)
21067 jne 1b
21068
21069 + pax_force_retaddr
21070 ret
21071 CFI_ENDPROC
21072 ENDPROC(atomic64_xchg_cx8)
21073
21074 -.macro addsub_return func ins insc
21075 -ENTRY(atomic64_\func\()_return_cx8)
21076 +.macro addsub_return func ins insc unchecked=""
21077 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21078 CFI_STARTPROC
21079 SAVE ebp
21080 SAVE ebx
21081 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21082 movl %edx, %ecx
21083 \ins\()l %esi, %ebx
21084 \insc\()l %edi, %ecx
21085 +
21086 +.ifb \unchecked
21087 +#ifdef CONFIG_PAX_REFCOUNT
21088 + into
21089 +2:
21090 + _ASM_EXTABLE(2b, 3f)
21091 +#endif
21092 +.endif
21093 +
21094 LOCK_PREFIX
21095 cmpxchg8b (%ebp)
21096 jne 1b
21097 -
21098 -10:
21099 movl %ebx, %eax
21100 movl %ecx, %edx
21101 +
21102 +.ifb \unchecked
21103 +#ifdef CONFIG_PAX_REFCOUNT
21104 +3:
21105 +#endif
21106 +.endif
21107 +
21108 RESTORE edi
21109 RESTORE esi
21110 RESTORE ebx
21111 RESTORE ebp
21112 + pax_force_retaddr
21113 ret
21114 CFI_ENDPROC
21115 -ENDPROC(atomic64_\func\()_return_cx8)
21116 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21117 .endm
21118
21119 addsub_return add add adc
21120 addsub_return sub sub sbb
21121 +addsub_return add add adc _unchecked
21122 +addsub_return sub sub sbb _unchecked
21123
21124 -.macro incdec_return func ins insc
21125 -ENTRY(atomic64_\func\()_return_cx8)
21126 +.macro incdec_return func ins insc unchecked=""
21127 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21128 CFI_STARTPROC
21129 SAVE ebx
21130
21131 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21132 movl %edx, %ecx
21133 \ins\()l $1, %ebx
21134 \insc\()l $0, %ecx
21135 +
21136 +.ifb \unchecked
21137 +#ifdef CONFIG_PAX_REFCOUNT
21138 + into
21139 +2:
21140 + _ASM_EXTABLE(2b, 3f)
21141 +#endif
21142 +.endif
21143 +
21144 LOCK_PREFIX
21145 cmpxchg8b (%esi)
21146 jne 1b
21147
21148 -10:
21149 movl %ebx, %eax
21150 movl %ecx, %edx
21151 +
21152 +.ifb \unchecked
21153 +#ifdef CONFIG_PAX_REFCOUNT
21154 +3:
21155 +#endif
21156 +.endif
21157 +
21158 RESTORE ebx
21159 + pax_force_retaddr
21160 ret
21161 CFI_ENDPROC
21162 -ENDPROC(atomic64_\func\()_return_cx8)
21163 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21164 .endm
21165
21166 incdec_return inc add adc
21167 incdec_return dec sub sbb
21168 +incdec_return inc add adc _unchecked
21169 +incdec_return dec sub sbb _unchecked
21170
21171 ENTRY(atomic64_dec_if_positive_cx8)
21172 CFI_STARTPROC
21173 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21174 movl %edx, %ecx
21175 subl $1, %ebx
21176 sbb $0, %ecx
21177 +
21178 +#ifdef CONFIG_PAX_REFCOUNT
21179 + into
21180 +1234:
21181 + _ASM_EXTABLE(1234b, 2f)
21182 +#endif
21183 +
21184 js 2f
21185 LOCK_PREFIX
21186 cmpxchg8b (%esi)
21187 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21188 movl %ebx, %eax
21189 movl %ecx, %edx
21190 RESTORE ebx
21191 + pax_force_retaddr
21192 ret
21193 CFI_ENDPROC
21194 ENDPROC(atomic64_dec_if_positive_cx8)
21195 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21196 movl %edx, %ecx
21197 addl %ebp, %ebx
21198 adcl %edi, %ecx
21199 +
21200 +#ifdef CONFIG_PAX_REFCOUNT
21201 + into
21202 +1234:
21203 + _ASM_EXTABLE(1234b, 3f)
21204 +#endif
21205 +
21206 LOCK_PREFIX
21207 cmpxchg8b (%esi)
21208 jne 1b
21209 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21210 CFI_ADJUST_CFA_OFFSET -8
21211 RESTORE ebx
21212 RESTORE ebp
21213 + pax_force_retaddr
21214 ret
21215 4:
21216 cmpl %edx, 4(%esp)
21217 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21218 xorl %ecx, %ecx
21219 addl $1, %ebx
21220 adcl %edx, %ecx
21221 +
21222 +#ifdef CONFIG_PAX_REFCOUNT
21223 + into
21224 +1234:
21225 + _ASM_EXTABLE(1234b, 3f)
21226 +#endif
21227 +
21228 LOCK_PREFIX
21229 cmpxchg8b (%esi)
21230 jne 1b
21231 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21232 movl $1, %eax
21233 3:
21234 RESTORE ebx
21235 + pax_force_retaddr
21236 ret
21237 CFI_ENDPROC
21238 ENDPROC(atomic64_inc_not_zero_cx8)
21239 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21240 index 2af5df3..62b1a5a 100644
21241 --- a/arch/x86/lib/checksum_32.S
21242 +++ b/arch/x86/lib/checksum_32.S
21243 @@ -29,7 +29,8 @@
21244 #include <asm/dwarf2.h>
21245 #include <asm/errno.h>
21246 #include <asm/asm.h>
21247 -
21248 +#include <asm/segment.h>
21249 +
21250 /*
21251 * computes a partial checksum, e.g. for TCP/UDP fragments
21252 */
21253 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21254
21255 #define ARGBASE 16
21256 #define FP 12
21257 -
21258 -ENTRY(csum_partial_copy_generic)
21259 +
21260 +ENTRY(csum_partial_copy_generic_to_user)
21261 CFI_STARTPROC
21262 +
21263 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21264 + pushl_cfi %gs
21265 + popl_cfi %es
21266 + jmp csum_partial_copy_generic
21267 +#endif
21268 +
21269 +ENTRY(csum_partial_copy_generic_from_user)
21270 +
21271 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21272 + pushl_cfi %gs
21273 + popl_cfi %ds
21274 +#endif
21275 +
21276 +ENTRY(csum_partial_copy_generic)
21277 subl $4,%esp
21278 CFI_ADJUST_CFA_OFFSET 4
21279 pushl_cfi %edi
21280 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21281 jmp 4f
21282 SRC(1: movw (%esi), %bx )
21283 addl $2, %esi
21284 -DST( movw %bx, (%edi) )
21285 +DST( movw %bx, %es:(%edi) )
21286 addl $2, %edi
21287 addw %bx, %ax
21288 adcl $0, %eax
21289 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21290 SRC(1: movl (%esi), %ebx )
21291 SRC( movl 4(%esi), %edx )
21292 adcl %ebx, %eax
21293 -DST( movl %ebx, (%edi) )
21294 +DST( movl %ebx, %es:(%edi) )
21295 adcl %edx, %eax
21296 -DST( movl %edx, 4(%edi) )
21297 +DST( movl %edx, %es:4(%edi) )
21298
21299 SRC( movl 8(%esi), %ebx )
21300 SRC( movl 12(%esi), %edx )
21301 adcl %ebx, %eax
21302 -DST( movl %ebx, 8(%edi) )
21303 +DST( movl %ebx, %es:8(%edi) )
21304 adcl %edx, %eax
21305 -DST( movl %edx, 12(%edi) )
21306 +DST( movl %edx, %es:12(%edi) )
21307
21308 SRC( movl 16(%esi), %ebx )
21309 SRC( movl 20(%esi), %edx )
21310 adcl %ebx, %eax
21311 -DST( movl %ebx, 16(%edi) )
21312 +DST( movl %ebx, %es:16(%edi) )
21313 adcl %edx, %eax
21314 -DST( movl %edx, 20(%edi) )
21315 +DST( movl %edx, %es:20(%edi) )
21316
21317 SRC( movl 24(%esi), %ebx )
21318 SRC( movl 28(%esi), %edx )
21319 adcl %ebx, %eax
21320 -DST( movl %ebx, 24(%edi) )
21321 +DST( movl %ebx, %es:24(%edi) )
21322 adcl %edx, %eax
21323 -DST( movl %edx, 28(%edi) )
21324 +DST( movl %edx, %es:28(%edi) )
21325
21326 lea 32(%esi), %esi
21327 lea 32(%edi), %edi
21328 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21329 shrl $2, %edx # This clears CF
21330 SRC(3: movl (%esi), %ebx )
21331 adcl %ebx, %eax
21332 -DST( movl %ebx, (%edi) )
21333 +DST( movl %ebx, %es:(%edi) )
21334 lea 4(%esi), %esi
21335 lea 4(%edi), %edi
21336 dec %edx
21337 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21338 jb 5f
21339 SRC( movw (%esi), %cx )
21340 leal 2(%esi), %esi
21341 -DST( movw %cx, (%edi) )
21342 +DST( movw %cx, %es:(%edi) )
21343 leal 2(%edi), %edi
21344 je 6f
21345 shll $16,%ecx
21346 SRC(5: movb (%esi), %cl )
21347 -DST( movb %cl, (%edi) )
21348 +DST( movb %cl, %es:(%edi) )
21349 6: addl %ecx, %eax
21350 adcl $0, %eax
21351 7:
21352 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21353
21354 6001:
21355 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21356 - movl $-EFAULT, (%ebx)
21357 + movl $-EFAULT, %ss:(%ebx)
21358
21359 # zero the complete destination - computing the rest
21360 # is too much work
21361 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21362
21363 6002:
21364 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21365 - movl $-EFAULT,(%ebx)
21366 + movl $-EFAULT,%ss:(%ebx)
21367 jmp 5000b
21368
21369 .previous
21370
21371 + pushl_cfi %ss
21372 + popl_cfi %ds
21373 + pushl_cfi %ss
21374 + popl_cfi %es
21375 popl_cfi %ebx
21376 CFI_RESTORE ebx
21377 popl_cfi %esi
21378 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21379 popl_cfi %ecx # equivalent to addl $4,%esp
21380 ret
21381 CFI_ENDPROC
21382 -ENDPROC(csum_partial_copy_generic)
21383 +ENDPROC(csum_partial_copy_generic_to_user)
21384
21385 #else
21386
21387 /* Version for PentiumII/PPro */
21388
21389 #define ROUND1(x) \
21390 + nop; nop; nop; \
21391 SRC(movl x(%esi), %ebx ) ; \
21392 addl %ebx, %eax ; \
21393 - DST(movl %ebx, x(%edi) ) ;
21394 + DST(movl %ebx, %es:x(%edi)) ;
21395
21396 #define ROUND(x) \
21397 + nop; nop; nop; \
21398 SRC(movl x(%esi), %ebx ) ; \
21399 adcl %ebx, %eax ; \
21400 - DST(movl %ebx, x(%edi) ) ;
21401 + DST(movl %ebx, %es:x(%edi)) ;
21402
21403 #define ARGBASE 12
21404 -
21405 -ENTRY(csum_partial_copy_generic)
21406 +
21407 +ENTRY(csum_partial_copy_generic_to_user)
21408 CFI_STARTPROC
21409 +
21410 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21411 + pushl_cfi %gs
21412 + popl_cfi %es
21413 + jmp csum_partial_copy_generic
21414 +#endif
21415 +
21416 +ENTRY(csum_partial_copy_generic_from_user)
21417 +
21418 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21419 + pushl_cfi %gs
21420 + popl_cfi %ds
21421 +#endif
21422 +
21423 +ENTRY(csum_partial_copy_generic)
21424 pushl_cfi %ebx
21425 CFI_REL_OFFSET ebx, 0
21426 pushl_cfi %edi
21427 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21428 subl %ebx, %edi
21429 lea -1(%esi),%edx
21430 andl $-32,%edx
21431 - lea 3f(%ebx,%ebx), %ebx
21432 + lea 3f(%ebx,%ebx,2), %ebx
21433 testl %esi, %esi
21434 jmp *%ebx
21435 1: addl $64,%esi
21436 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21437 jb 5f
21438 SRC( movw (%esi), %dx )
21439 leal 2(%esi), %esi
21440 -DST( movw %dx, (%edi) )
21441 +DST( movw %dx, %es:(%edi) )
21442 leal 2(%edi), %edi
21443 je 6f
21444 shll $16,%edx
21445 5:
21446 SRC( movb (%esi), %dl )
21447 -DST( movb %dl, (%edi) )
21448 +DST( movb %dl, %es:(%edi) )
21449 6: addl %edx, %eax
21450 adcl $0, %eax
21451 7:
21452 .section .fixup, "ax"
21453 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21454 - movl $-EFAULT, (%ebx)
21455 + movl $-EFAULT, %ss:(%ebx)
21456 # zero the complete destination (computing the rest is too much work)
21457 movl ARGBASE+8(%esp),%edi # dst
21458 movl ARGBASE+12(%esp),%ecx # len
21459 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21460 rep; stosb
21461 jmp 7b
21462 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21463 - movl $-EFAULT, (%ebx)
21464 + movl $-EFAULT, %ss:(%ebx)
21465 jmp 7b
21466 .previous
21467
21468 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21469 + pushl_cfi %ss
21470 + popl_cfi %ds
21471 + pushl_cfi %ss
21472 + popl_cfi %es
21473 +#endif
21474 +
21475 popl_cfi %esi
21476 CFI_RESTORE esi
21477 popl_cfi %edi
21478 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21479 CFI_RESTORE ebx
21480 ret
21481 CFI_ENDPROC
21482 -ENDPROC(csum_partial_copy_generic)
21483 +ENDPROC(csum_partial_copy_generic_to_user)
21484
21485 #undef ROUND
21486 #undef ROUND1
21487 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21488 index f2145cf..cea889d 100644
21489 --- a/arch/x86/lib/clear_page_64.S
21490 +++ b/arch/x86/lib/clear_page_64.S
21491 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21492 movl $4096/8,%ecx
21493 xorl %eax,%eax
21494 rep stosq
21495 + pax_force_retaddr
21496 ret
21497 CFI_ENDPROC
21498 ENDPROC(clear_page_c)
21499 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21500 movl $4096,%ecx
21501 xorl %eax,%eax
21502 rep stosb
21503 + pax_force_retaddr
21504 ret
21505 CFI_ENDPROC
21506 ENDPROC(clear_page_c_e)
21507 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21508 leaq 64(%rdi),%rdi
21509 jnz .Lloop
21510 nop
21511 + pax_force_retaddr
21512 ret
21513 CFI_ENDPROC
21514 .Lclear_page_end:
21515 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21516
21517 #include <asm/cpufeature.h>
21518
21519 - .section .altinstr_replacement,"ax"
21520 + .section .altinstr_replacement,"a"
21521 1: .byte 0xeb /* jmp <disp8> */
21522 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21523 2: .byte 0xeb /* jmp <disp8> */
21524 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21525 index 1e572c5..2a162cd 100644
21526 --- a/arch/x86/lib/cmpxchg16b_emu.S
21527 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21528 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21529
21530 popf
21531 mov $1, %al
21532 + pax_force_retaddr
21533 ret
21534
21535 not_same:
21536 popf
21537 xor %al,%al
21538 + pax_force_retaddr
21539 ret
21540
21541 CFI_ENDPROC
21542 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21543 index 6b34d04..dccb07f 100644
21544 --- a/arch/x86/lib/copy_page_64.S
21545 +++ b/arch/x86/lib/copy_page_64.S
21546 @@ -9,6 +9,7 @@ copy_page_c:
21547 CFI_STARTPROC
21548 movl $4096/8,%ecx
21549 rep movsq
21550 + pax_force_retaddr
21551 ret
21552 CFI_ENDPROC
21553 ENDPROC(copy_page_c)
21554 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21555
21556 ENTRY(copy_page)
21557 CFI_STARTPROC
21558 - subq $2*8,%rsp
21559 - CFI_ADJUST_CFA_OFFSET 2*8
21560 + subq $3*8,%rsp
21561 + CFI_ADJUST_CFA_OFFSET 3*8
21562 movq %rbx,(%rsp)
21563 CFI_REL_OFFSET rbx, 0
21564 movq %r12,1*8(%rsp)
21565 CFI_REL_OFFSET r12, 1*8
21566 + movq %r13,2*8(%rsp)
21567 + CFI_REL_OFFSET r13, 2*8
21568
21569 movl $(4096/64)-5,%ecx
21570 .p2align 4
21571 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21572 movq 16 (%rsi), %rdx
21573 movq 24 (%rsi), %r8
21574 movq 32 (%rsi), %r9
21575 - movq 40 (%rsi), %r10
21576 + movq 40 (%rsi), %r13
21577 movq 48 (%rsi), %r11
21578 movq 56 (%rsi), %r12
21579
21580 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21581 movq %rdx, 16 (%rdi)
21582 movq %r8, 24 (%rdi)
21583 movq %r9, 32 (%rdi)
21584 - movq %r10, 40 (%rdi)
21585 + movq %r13, 40 (%rdi)
21586 movq %r11, 48 (%rdi)
21587 movq %r12, 56 (%rdi)
21588
21589 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21590 movq 16 (%rsi), %rdx
21591 movq 24 (%rsi), %r8
21592 movq 32 (%rsi), %r9
21593 - movq 40 (%rsi), %r10
21594 + movq 40 (%rsi), %r13
21595 movq 48 (%rsi), %r11
21596 movq 56 (%rsi), %r12
21597
21598 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21599 movq %rdx, 16 (%rdi)
21600 movq %r8, 24 (%rdi)
21601 movq %r9, 32 (%rdi)
21602 - movq %r10, 40 (%rdi)
21603 + movq %r13, 40 (%rdi)
21604 movq %r11, 48 (%rdi)
21605 movq %r12, 56 (%rdi)
21606
21607 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21608 CFI_RESTORE rbx
21609 movq 1*8(%rsp),%r12
21610 CFI_RESTORE r12
21611 - addq $2*8,%rsp
21612 - CFI_ADJUST_CFA_OFFSET -2*8
21613 + movq 2*8(%rsp),%r13
21614 + CFI_RESTORE r13
21615 + addq $3*8,%rsp
21616 + CFI_ADJUST_CFA_OFFSET -3*8
21617 + pax_force_retaddr
21618 ret
21619 .Lcopy_page_end:
21620 CFI_ENDPROC
21621 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21622
21623 #include <asm/cpufeature.h>
21624
21625 - .section .altinstr_replacement,"ax"
21626 + .section .altinstr_replacement,"a"
21627 1: .byte 0xeb /* jmp <disp8> */
21628 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21629 2:
21630 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21631 index 5b2995f..78e7644 100644
21632 --- a/arch/x86/lib/copy_user_64.S
21633 +++ b/arch/x86/lib/copy_user_64.S
21634 @@ -17,6 +17,7 @@
21635 #include <asm/cpufeature.h>
21636 #include <asm/alternative-asm.h>
21637 #include <asm/asm.h>
21638 +#include <asm/pgtable.h>
21639
21640 /*
21641 * By placing feature2 after feature1 in altinstructions section, we logically
21642 @@ -30,7 +31,7 @@
21643 .byte 0xe9 /* 32bit jump */
21644 .long \orig-1f /* by default jump to orig */
21645 1:
21646 - .section .altinstr_replacement,"ax"
21647 + .section .altinstr_replacement,"a"
21648 2: .byte 0xe9 /* near jump with 32bit immediate */
21649 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21650 3: .byte 0xe9 /* near jump with 32bit immediate */
21651 @@ -69,47 +70,20 @@
21652 #endif
21653 .endm
21654
21655 -/* Standard copy_to_user with segment limit checking */
21656 -ENTRY(_copy_to_user)
21657 - CFI_STARTPROC
21658 - GET_THREAD_INFO(%rax)
21659 - movq %rdi,%rcx
21660 - addq %rdx,%rcx
21661 - jc bad_to_user
21662 - cmpq TI_addr_limit(%rax),%rcx
21663 - ja bad_to_user
21664 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21665 - copy_user_generic_unrolled,copy_user_generic_string, \
21666 - copy_user_enhanced_fast_string
21667 - CFI_ENDPROC
21668 -ENDPROC(_copy_to_user)
21669 -
21670 -/* Standard copy_from_user with segment limit checking */
21671 -ENTRY(_copy_from_user)
21672 - CFI_STARTPROC
21673 - GET_THREAD_INFO(%rax)
21674 - movq %rsi,%rcx
21675 - addq %rdx,%rcx
21676 - jc bad_from_user
21677 - cmpq TI_addr_limit(%rax),%rcx
21678 - ja bad_from_user
21679 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21680 - copy_user_generic_unrolled,copy_user_generic_string, \
21681 - copy_user_enhanced_fast_string
21682 - CFI_ENDPROC
21683 -ENDPROC(_copy_from_user)
21684 -
21685 .section .fixup,"ax"
21686 /* must zero dest */
21687 ENTRY(bad_from_user)
21688 bad_from_user:
21689 CFI_STARTPROC
21690 + testl %edx,%edx
21691 + js bad_to_user
21692 movl %edx,%ecx
21693 xorl %eax,%eax
21694 rep
21695 stosb
21696 bad_to_user:
21697 movl %edx,%eax
21698 + pax_force_retaddr
21699 ret
21700 CFI_ENDPROC
21701 ENDPROC(bad_from_user)
21702 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21703 jz 17f
21704 1: movq (%rsi),%r8
21705 2: movq 1*8(%rsi),%r9
21706 -3: movq 2*8(%rsi),%r10
21707 +3: movq 2*8(%rsi),%rax
21708 4: movq 3*8(%rsi),%r11
21709 5: movq %r8,(%rdi)
21710 6: movq %r9,1*8(%rdi)
21711 -7: movq %r10,2*8(%rdi)
21712 +7: movq %rax,2*8(%rdi)
21713 8: movq %r11,3*8(%rdi)
21714 9: movq 4*8(%rsi),%r8
21715 10: movq 5*8(%rsi),%r9
21716 -11: movq 6*8(%rsi),%r10
21717 +11: movq 6*8(%rsi),%rax
21718 12: movq 7*8(%rsi),%r11
21719 13: movq %r8,4*8(%rdi)
21720 14: movq %r9,5*8(%rdi)
21721 -15: movq %r10,6*8(%rdi)
21722 +15: movq %rax,6*8(%rdi)
21723 16: movq %r11,7*8(%rdi)
21724 leaq 64(%rsi),%rsi
21725 leaq 64(%rdi),%rdi
21726 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21727 decl %ecx
21728 jnz 21b
21729 23: xor %eax,%eax
21730 + pax_force_retaddr
21731 ret
21732
21733 .section .fixup,"ax"
21734 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21735 3: rep
21736 movsb
21737 4: xorl %eax,%eax
21738 + pax_force_retaddr
21739 ret
21740
21741 .section .fixup,"ax"
21742 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21743 1: rep
21744 movsb
21745 2: xorl %eax,%eax
21746 + pax_force_retaddr
21747 ret
21748
21749 .section .fixup,"ax"
21750 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21751 index cacddc7..09d49e4 100644
21752 --- a/arch/x86/lib/copy_user_nocache_64.S
21753 +++ b/arch/x86/lib/copy_user_nocache_64.S
21754 @@ -8,6 +8,7 @@
21755
21756 #include <linux/linkage.h>
21757 #include <asm/dwarf2.h>
21758 +#include <asm/alternative-asm.h>
21759
21760 #define FIX_ALIGNMENT 1
21761
21762 @@ -15,6 +16,7 @@
21763 #include <asm/asm-offsets.h>
21764 #include <asm/thread_info.h>
21765 #include <asm/asm.h>
21766 +#include <asm/pgtable.h>
21767
21768 .macro ALIGN_DESTINATION
21769 #ifdef FIX_ALIGNMENT
21770 @@ -48,6 +50,15 @@
21771 */
21772 ENTRY(__copy_user_nocache)
21773 CFI_STARTPROC
21774 +
21775 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21776 + mov $PAX_USER_SHADOW_BASE,%rcx
21777 + cmp %rcx,%rsi
21778 + jae 1f
21779 + add %rcx,%rsi
21780 +1:
21781 +#endif
21782 +
21783 cmpl $8,%edx
21784 jb 20f /* less then 8 bytes, go to byte copy loop */
21785 ALIGN_DESTINATION
21786 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21787 jz 17f
21788 1: movq (%rsi),%r8
21789 2: movq 1*8(%rsi),%r9
21790 -3: movq 2*8(%rsi),%r10
21791 +3: movq 2*8(%rsi),%rax
21792 4: movq 3*8(%rsi),%r11
21793 5: movnti %r8,(%rdi)
21794 6: movnti %r9,1*8(%rdi)
21795 -7: movnti %r10,2*8(%rdi)
21796 +7: movnti %rax,2*8(%rdi)
21797 8: movnti %r11,3*8(%rdi)
21798 9: movq 4*8(%rsi),%r8
21799 10: movq 5*8(%rsi),%r9
21800 -11: movq 6*8(%rsi),%r10
21801 +11: movq 6*8(%rsi),%rax
21802 12: movq 7*8(%rsi),%r11
21803 13: movnti %r8,4*8(%rdi)
21804 14: movnti %r9,5*8(%rdi)
21805 -15: movnti %r10,6*8(%rdi)
21806 +15: movnti %rax,6*8(%rdi)
21807 16: movnti %r11,7*8(%rdi)
21808 leaq 64(%rsi),%rsi
21809 leaq 64(%rdi),%rdi
21810 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21811 jnz 21b
21812 23: xorl %eax,%eax
21813 sfence
21814 + pax_force_retaddr
21815 ret
21816
21817 .section .fixup,"ax"
21818 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21819 index 2419d5f..953ee51 100644
21820 --- a/arch/x86/lib/csum-copy_64.S
21821 +++ b/arch/x86/lib/csum-copy_64.S
21822 @@ -9,6 +9,7 @@
21823 #include <asm/dwarf2.h>
21824 #include <asm/errno.h>
21825 #include <asm/asm.h>
21826 +#include <asm/alternative-asm.h>
21827
21828 /*
21829 * Checksum copy with exception handling.
21830 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21831 CFI_RESTORE rbp
21832 addq $7*8, %rsp
21833 CFI_ADJUST_CFA_OFFSET -7*8
21834 + pax_force_retaddr 0, 1
21835 ret
21836 CFI_RESTORE_STATE
21837
21838 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21839 index 25b7ae8..169fafc 100644
21840 --- a/arch/x86/lib/csum-wrappers_64.c
21841 +++ b/arch/x86/lib/csum-wrappers_64.c
21842 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21843 len -= 2;
21844 }
21845 }
21846 - isum = csum_partial_copy_generic((__force const void *)src,
21847 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
21848 dst, len, isum, errp, NULL);
21849 if (unlikely(*errp))
21850 goto out_err;
21851 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21852 }
21853
21854 *errp = 0;
21855 - return csum_partial_copy_generic(src, (void __force *)dst,
21856 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
21857 len, isum, NULL, errp);
21858 }
21859 EXPORT_SYMBOL(csum_partial_copy_to_user);
21860 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21861 index b33b1fb..219f389 100644
21862 --- a/arch/x86/lib/getuser.S
21863 +++ b/arch/x86/lib/getuser.S
21864 @@ -33,15 +33,38 @@
21865 #include <asm/asm-offsets.h>
21866 #include <asm/thread_info.h>
21867 #include <asm/asm.h>
21868 +#include <asm/segment.h>
21869 +#include <asm/pgtable.h>
21870 +#include <asm/alternative-asm.h>
21871 +
21872 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21873 +#define __copyuser_seg gs;
21874 +#else
21875 +#define __copyuser_seg
21876 +#endif
21877
21878 .text
21879 ENTRY(__get_user_1)
21880 CFI_STARTPROC
21881 +
21882 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21883 GET_THREAD_INFO(%_ASM_DX)
21884 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21885 jae bad_get_user
21886 -1: movzb (%_ASM_AX),%edx
21887 +
21888 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21889 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21890 + cmp %_ASM_DX,%_ASM_AX
21891 + jae 1234f
21892 + add %_ASM_DX,%_ASM_AX
21893 +1234:
21894 +#endif
21895 +
21896 +#endif
21897 +
21898 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21899 xor %eax,%eax
21900 + pax_force_retaddr
21901 ret
21902 CFI_ENDPROC
21903 ENDPROC(__get_user_1)
21904 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21905 ENTRY(__get_user_2)
21906 CFI_STARTPROC
21907 add $1,%_ASM_AX
21908 +
21909 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21910 jc bad_get_user
21911 GET_THREAD_INFO(%_ASM_DX)
21912 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21913 jae bad_get_user
21914 -2: movzwl -1(%_ASM_AX),%edx
21915 +
21916 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21917 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21918 + cmp %_ASM_DX,%_ASM_AX
21919 + jae 1234f
21920 + add %_ASM_DX,%_ASM_AX
21921 +1234:
21922 +#endif
21923 +
21924 +#endif
21925 +
21926 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21927 xor %eax,%eax
21928 + pax_force_retaddr
21929 ret
21930 CFI_ENDPROC
21931 ENDPROC(__get_user_2)
21932 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21933 ENTRY(__get_user_4)
21934 CFI_STARTPROC
21935 add $3,%_ASM_AX
21936 +
21937 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21938 jc bad_get_user
21939 GET_THREAD_INFO(%_ASM_DX)
21940 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21941 jae bad_get_user
21942 -3: mov -3(%_ASM_AX),%edx
21943 +
21944 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21945 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21946 + cmp %_ASM_DX,%_ASM_AX
21947 + jae 1234f
21948 + add %_ASM_DX,%_ASM_AX
21949 +1234:
21950 +#endif
21951 +
21952 +#endif
21953 +
21954 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21955 xor %eax,%eax
21956 + pax_force_retaddr
21957 ret
21958 CFI_ENDPROC
21959 ENDPROC(__get_user_4)
21960 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21961 GET_THREAD_INFO(%_ASM_DX)
21962 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21963 jae bad_get_user
21964 +
21965 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21966 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21967 + cmp %_ASM_DX,%_ASM_AX
21968 + jae 1234f
21969 + add %_ASM_DX,%_ASM_AX
21970 +1234:
21971 +#endif
21972 +
21973 4: movq -7(%_ASM_AX),%_ASM_DX
21974 xor %eax,%eax
21975 + pax_force_retaddr
21976 ret
21977 CFI_ENDPROC
21978 ENDPROC(__get_user_8)
21979 @@ -91,6 +152,7 @@ bad_get_user:
21980 CFI_STARTPROC
21981 xor %edx,%edx
21982 mov $(-EFAULT),%_ASM_AX
21983 + pax_force_retaddr
21984 ret
21985 CFI_ENDPROC
21986 END(bad_get_user)
21987 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21988 index b1e6c4b..21ae8fc 100644
21989 --- a/arch/x86/lib/insn.c
21990 +++ b/arch/x86/lib/insn.c
21991 @@ -21,6 +21,11 @@
21992 #include <linux/string.h>
21993 #include <asm/inat.h>
21994 #include <asm/insn.h>
21995 +#ifdef __KERNEL__
21996 +#include <asm/pgtable_types.h>
21997 +#else
21998 +#define ktla_ktva(addr) addr
21999 +#endif
22000
22001 /* Verify next sizeof(t) bytes can be on the same instruction */
22002 #define validate_next(t, insn, n) \
22003 @@ -49,8 +54,8 @@
22004 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22005 {
22006 memset(insn, 0, sizeof(*insn));
22007 - insn->kaddr = kaddr;
22008 - insn->next_byte = kaddr;
22009 + insn->kaddr = ktla_ktva(kaddr);
22010 + insn->next_byte = ktla_ktva(kaddr);
22011 insn->x86_64 = x86_64 ? 1 : 0;
22012 insn->opnd_bytes = 4;
22013 if (x86_64)
22014 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22015 index 05a95e7..326f2fa 100644
22016 --- a/arch/x86/lib/iomap_copy_64.S
22017 +++ b/arch/x86/lib/iomap_copy_64.S
22018 @@ -17,6 +17,7 @@
22019
22020 #include <linux/linkage.h>
22021 #include <asm/dwarf2.h>
22022 +#include <asm/alternative-asm.h>
22023
22024 /*
22025 * override generic version in lib/iomap_copy.c
22026 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22027 CFI_STARTPROC
22028 movl %edx,%ecx
22029 rep movsd
22030 + pax_force_retaddr
22031 ret
22032 CFI_ENDPROC
22033 ENDPROC(__iowrite32_copy)
22034 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22035 index 1c273be..da9cc0e 100644
22036 --- a/arch/x86/lib/memcpy_64.S
22037 +++ b/arch/x86/lib/memcpy_64.S
22038 @@ -33,6 +33,7 @@
22039 rep movsq
22040 movl %edx, %ecx
22041 rep movsb
22042 + pax_force_retaddr
22043 ret
22044 .Lmemcpy_e:
22045 .previous
22046 @@ -49,6 +50,7 @@
22047 movq %rdi, %rax
22048 movq %rdx, %rcx
22049 rep movsb
22050 + pax_force_retaddr
22051 ret
22052 .Lmemcpy_e_e:
22053 .previous
22054 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22055 */
22056 movq 0*8(%rsi), %r8
22057 movq 1*8(%rsi), %r9
22058 - movq 2*8(%rsi), %r10
22059 + movq 2*8(%rsi), %rcx
22060 movq 3*8(%rsi), %r11
22061 leaq 4*8(%rsi), %rsi
22062
22063 movq %r8, 0*8(%rdi)
22064 movq %r9, 1*8(%rdi)
22065 - movq %r10, 2*8(%rdi)
22066 + movq %rcx, 2*8(%rdi)
22067 movq %r11, 3*8(%rdi)
22068 leaq 4*8(%rdi), %rdi
22069 jae .Lcopy_forward_loop
22070 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22071 subq $0x20, %rdx
22072 movq -1*8(%rsi), %r8
22073 movq -2*8(%rsi), %r9
22074 - movq -3*8(%rsi), %r10
22075 + movq -3*8(%rsi), %rcx
22076 movq -4*8(%rsi), %r11
22077 leaq -4*8(%rsi), %rsi
22078 movq %r8, -1*8(%rdi)
22079 movq %r9, -2*8(%rdi)
22080 - movq %r10, -3*8(%rdi)
22081 + movq %rcx, -3*8(%rdi)
22082 movq %r11, -4*8(%rdi)
22083 leaq -4*8(%rdi), %rdi
22084 jae .Lcopy_backward_loop
22085 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22086 */
22087 movq 0*8(%rsi), %r8
22088 movq 1*8(%rsi), %r9
22089 - movq -2*8(%rsi, %rdx), %r10
22090 + movq -2*8(%rsi, %rdx), %rcx
22091 movq -1*8(%rsi, %rdx), %r11
22092 movq %r8, 0*8(%rdi)
22093 movq %r9, 1*8(%rdi)
22094 - movq %r10, -2*8(%rdi, %rdx)
22095 + movq %rcx, -2*8(%rdi, %rdx)
22096 movq %r11, -1*8(%rdi, %rdx)
22097 + pax_force_retaddr
22098 retq
22099 .p2align 4
22100 .Lless_16bytes:
22101 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22102 movq -1*8(%rsi, %rdx), %r9
22103 movq %r8, 0*8(%rdi)
22104 movq %r9, -1*8(%rdi, %rdx)
22105 + pax_force_retaddr
22106 retq
22107 .p2align 4
22108 .Lless_8bytes:
22109 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22110 movl -4(%rsi, %rdx), %r8d
22111 movl %ecx, (%rdi)
22112 movl %r8d, -4(%rdi, %rdx)
22113 + pax_force_retaddr
22114 retq
22115 .p2align 4
22116 .Lless_3bytes:
22117 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22118 movb %cl, (%rdi)
22119
22120 .Lend:
22121 + pax_force_retaddr
22122 retq
22123 CFI_ENDPROC
22124 ENDPROC(memcpy)
22125 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22126 index ee16461..c39c199 100644
22127 --- a/arch/x86/lib/memmove_64.S
22128 +++ b/arch/x86/lib/memmove_64.S
22129 @@ -61,13 +61,13 @@ ENTRY(memmove)
22130 5:
22131 sub $0x20, %rdx
22132 movq 0*8(%rsi), %r11
22133 - movq 1*8(%rsi), %r10
22134 + movq 1*8(%rsi), %rcx
22135 movq 2*8(%rsi), %r9
22136 movq 3*8(%rsi), %r8
22137 leaq 4*8(%rsi), %rsi
22138
22139 movq %r11, 0*8(%rdi)
22140 - movq %r10, 1*8(%rdi)
22141 + movq %rcx, 1*8(%rdi)
22142 movq %r9, 2*8(%rdi)
22143 movq %r8, 3*8(%rdi)
22144 leaq 4*8(%rdi), %rdi
22145 @@ -81,10 +81,10 @@ ENTRY(memmove)
22146 4:
22147 movq %rdx, %rcx
22148 movq -8(%rsi, %rdx), %r11
22149 - lea -8(%rdi, %rdx), %r10
22150 + lea -8(%rdi, %rdx), %r9
22151 shrq $3, %rcx
22152 rep movsq
22153 - movq %r11, (%r10)
22154 + movq %r11, (%r9)
22155 jmp 13f
22156 .Lmemmove_end_forward:
22157
22158 @@ -95,14 +95,14 @@ ENTRY(memmove)
22159 7:
22160 movq %rdx, %rcx
22161 movq (%rsi), %r11
22162 - movq %rdi, %r10
22163 + movq %rdi, %r9
22164 leaq -8(%rsi, %rdx), %rsi
22165 leaq -8(%rdi, %rdx), %rdi
22166 shrq $3, %rcx
22167 std
22168 rep movsq
22169 cld
22170 - movq %r11, (%r10)
22171 + movq %r11, (%r9)
22172 jmp 13f
22173
22174 /*
22175 @@ -127,13 +127,13 @@ ENTRY(memmove)
22176 8:
22177 subq $0x20, %rdx
22178 movq -1*8(%rsi), %r11
22179 - movq -2*8(%rsi), %r10
22180 + movq -2*8(%rsi), %rcx
22181 movq -3*8(%rsi), %r9
22182 movq -4*8(%rsi), %r8
22183 leaq -4*8(%rsi), %rsi
22184
22185 movq %r11, -1*8(%rdi)
22186 - movq %r10, -2*8(%rdi)
22187 + movq %rcx, -2*8(%rdi)
22188 movq %r9, -3*8(%rdi)
22189 movq %r8, -4*8(%rdi)
22190 leaq -4*8(%rdi), %rdi
22191 @@ -151,11 +151,11 @@ ENTRY(memmove)
22192 * Move data from 16 bytes to 31 bytes.
22193 */
22194 movq 0*8(%rsi), %r11
22195 - movq 1*8(%rsi), %r10
22196 + movq 1*8(%rsi), %rcx
22197 movq -2*8(%rsi, %rdx), %r9
22198 movq -1*8(%rsi, %rdx), %r8
22199 movq %r11, 0*8(%rdi)
22200 - movq %r10, 1*8(%rdi)
22201 + movq %rcx, 1*8(%rdi)
22202 movq %r9, -2*8(%rdi, %rdx)
22203 movq %r8, -1*8(%rdi, %rdx)
22204 jmp 13f
22205 @@ -167,9 +167,9 @@ ENTRY(memmove)
22206 * Move data from 8 bytes to 15 bytes.
22207 */
22208 movq 0*8(%rsi), %r11
22209 - movq -1*8(%rsi, %rdx), %r10
22210 + movq -1*8(%rsi, %rdx), %r9
22211 movq %r11, 0*8(%rdi)
22212 - movq %r10, -1*8(%rdi, %rdx)
22213 + movq %r9, -1*8(%rdi, %rdx)
22214 jmp 13f
22215 10:
22216 cmpq $4, %rdx
22217 @@ -178,9 +178,9 @@ ENTRY(memmove)
22218 * Move data from 4 bytes to 7 bytes.
22219 */
22220 movl (%rsi), %r11d
22221 - movl -4(%rsi, %rdx), %r10d
22222 + movl -4(%rsi, %rdx), %r9d
22223 movl %r11d, (%rdi)
22224 - movl %r10d, -4(%rdi, %rdx)
22225 + movl %r9d, -4(%rdi, %rdx)
22226 jmp 13f
22227 11:
22228 cmp $2, %rdx
22229 @@ -189,9 +189,9 @@ ENTRY(memmove)
22230 * Move data from 2 bytes to 3 bytes.
22231 */
22232 movw (%rsi), %r11w
22233 - movw -2(%rsi, %rdx), %r10w
22234 + movw -2(%rsi, %rdx), %r9w
22235 movw %r11w, (%rdi)
22236 - movw %r10w, -2(%rdi, %rdx)
22237 + movw %r9w, -2(%rdi, %rdx)
22238 jmp 13f
22239 12:
22240 cmp $1, %rdx
22241 @@ -202,6 +202,7 @@ ENTRY(memmove)
22242 movb (%rsi), %r11b
22243 movb %r11b, (%rdi)
22244 13:
22245 + pax_force_retaddr
22246 retq
22247 CFI_ENDPROC
22248
22249 @@ -210,6 +211,7 @@ ENTRY(memmove)
22250 /* Forward moving data. */
22251 movq %rdx, %rcx
22252 rep movsb
22253 + pax_force_retaddr
22254 retq
22255 .Lmemmove_end_forward_efs:
22256 .previous
22257 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22258 index 2dcb380..963660a 100644
22259 --- a/arch/x86/lib/memset_64.S
22260 +++ b/arch/x86/lib/memset_64.S
22261 @@ -30,6 +30,7 @@
22262 movl %edx,%ecx
22263 rep stosb
22264 movq %r9,%rax
22265 + pax_force_retaddr
22266 ret
22267 .Lmemset_e:
22268 .previous
22269 @@ -52,6 +53,7 @@
22270 movq %rdx,%rcx
22271 rep stosb
22272 movq %r9,%rax
22273 + pax_force_retaddr
22274 ret
22275 .Lmemset_e_e:
22276 .previous
22277 @@ -59,7 +61,7 @@
22278 ENTRY(memset)
22279 ENTRY(__memset)
22280 CFI_STARTPROC
22281 - movq %rdi,%r10
22282 + movq %rdi,%r11
22283
22284 /* expand byte value */
22285 movzbl %sil,%ecx
22286 @@ -117,7 +119,8 @@ ENTRY(__memset)
22287 jnz .Lloop_1
22288
22289 .Lende:
22290 - movq %r10,%rax
22291 + movq %r11,%rax
22292 + pax_force_retaddr
22293 ret
22294
22295 CFI_RESTORE_STATE
22296 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22297 index c9f2d9b..e7fd2c0 100644
22298 --- a/arch/x86/lib/mmx_32.c
22299 +++ b/arch/x86/lib/mmx_32.c
22300 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22301 {
22302 void *p;
22303 int i;
22304 + unsigned long cr0;
22305
22306 if (unlikely(in_interrupt()))
22307 return __memcpy(to, from, len);
22308 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22309 kernel_fpu_begin();
22310
22311 __asm__ __volatile__ (
22312 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22313 - " prefetch 64(%0)\n"
22314 - " prefetch 128(%0)\n"
22315 - " prefetch 192(%0)\n"
22316 - " prefetch 256(%0)\n"
22317 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22318 + " prefetch 64(%1)\n"
22319 + " prefetch 128(%1)\n"
22320 + " prefetch 192(%1)\n"
22321 + " prefetch 256(%1)\n"
22322 "2: \n"
22323 ".section .fixup, \"ax\"\n"
22324 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22325 + "3: \n"
22326 +
22327 +#ifdef CONFIG_PAX_KERNEXEC
22328 + " movl %%cr0, %0\n"
22329 + " movl %0, %%eax\n"
22330 + " andl $0xFFFEFFFF, %%eax\n"
22331 + " movl %%eax, %%cr0\n"
22332 +#endif
22333 +
22334 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22335 +
22336 +#ifdef CONFIG_PAX_KERNEXEC
22337 + " movl %0, %%cr0\n"
22338 +#endif
22339 +
22340 " jmp 2b\n"
22341 ".previous\n"
22342 _ASM_EXTABLE(1b, 3b)
22343 - : : "r" (from));
22344 + : "=&r" (cr0) : "r" (from) : "ax");
22345
22346 for ( ; i > 5; i--) {
22347 __asm__ __volatile__ (
22348 - "1: prefetch 320(%0)\n"
22349 - "2: movq (%0), %%mm0\n"
22350 - " movq 8(%0), %%mm1\n"
22351 - " movq 16(%0), %%mm2\n"
22352 - " movq 24(%0), %%mm3\n"
22353 - " movq %%mm0, (%1)\n"
22354 - " movq %%mm1, 8(%1)\n"
22355 - " movq %%mm2, 16(%1)\n"
22356 - " movq %%mm3, 24(%1)\n"
22357 - " movq 32(%0), %%mm0\n"
22358 - " movq 40(%0), %%mm1\n"
22359 - " movq 48(%0), %%mm2\n"
22360 - " movq 56(%0), %%mm3\n"
22361 - " movq %%mm0, 32(%1)\n"
22362 - " movq %%mm1, 40(%1)\n"
22363 - " movq %%mm2, 48(%1)\n"
22364 - " movq %%mm3, 56(%1)\n"
22365 + "1: prefetch 320(%1)\n"
22366 + "2: movq (%1), %%mm0\n"
22367 + " movq 8(%1), %%mm1\n"
22368 + " movq 16(%1), %%mm2\n"
22369 + " movq 24(%1), %%mm3\n"
22370 + " movq %%mm0, (%2)\n"
22371 + " movq %%mm1, 8(%2)\n"
22372 + " movq %%mm2, 16(%2)\n"
22373 + " movq %%mm3, 24(%2)\n"
22374 + " movq 32(%1), %%mm0\n"
22375 + " movq 40(%1), %%mm1\n"
22376 + " movq 48(%1), %%mm2\n"
22377 + " movq 56(%1), %%mm3\n"
22378 + " movq %%mm0, 32(%2)\n"
22379 + " movq %%mm1, 40(%2)\n"
22380 + " movq %%mm2, 48(%2)\n"
22381 + " movq %%mm3, 56(%2)\n"
22382 ".section .fixup, \"ax\"\n"
22383 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22384 + "3:\n"
22385 +
22386 +#ifdef CONFIG_PAX_KERNEXEC
22387 + " movl %%cr0, %0\n"
22388 + " movl %0, %%eax\n"
22389 + " andl $0xFFFEFFFF, %%eax\n"
22390 + " movl %%eax, %%cr0\n"
22391 +#endif
22392 +
22393 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22394 +
22395 +#ifdef CONFIG_PAX_KERNEXEC
22396 + " movl %0, %%cr0\n"
22397 +#endif
22398 +
22399 " jmp 2b\n"
22400 ".previous\n"
22401 _ASM_EXTABLE(1b, 3b)
22402 - : : "r" (from), "r" (to) : "memory");
22403 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22404
22405 from += 64;
22406 to += 64;
22407 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22408 static void fast_copy_page(void *to, void *from)
22409 {
22410 int i;
22411 + unsigned long cr0;
22412
22413 kernel_fpu_begin();
22414
22415 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22416 * but that is for later. -AV
22417 */
22418 __asm__ __volatile__(
22419 - "1: prefetch (%0)\n"
22420 - " prefetch 64(%0)\n"
22421 - " prefetch 128(%0)\n"
22422 - " prefetch 192(%0)\n"
22423 - " prefetch 256(%0)\n"
22424 + "1: prefetch (%1)\n"
22425 + " prefetch 64(%1)\n"
22426 + " prefetch 128(%1)\n"
22427 + " prefetch 192(%1)\n"
22428 + " prefetch 256(%1)\n"
22429 "2: \n"
22430 ".section .fixup, \"ax\"\n"
22431 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22432 + "3: \n"
22433 +
22434 +#ifdef CONFIG_PAX_KERNEXEC
22435 + " movl %%cr0, %0\n"
22436 + " movl %0, %%eax\n"
22437 + " andl $0xFFFEFFFF, %%eax\n"
22438 + " movl %%eax, %%cr0\n"
22439 +#endif
22440 +
22441 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22442 +
22443 +#ifdef CONFIG_PAX_KERNEXEC
22444 + " movl %0, %%cr0\n"
22445 +#endif
22446 +
22447 " jmp 2b\n"
22448 ".previous\n"
22449 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22450 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22451
22452 for (i = 0; i < (4096-320)/64; i++) {
22453 __asm__ __volatile__ (
22454 - "1: prefetch 320(%0)\n"
22455 - "2: movq (%0), %%mm0\n"
22456 - " movntq %%mm0, (%1)\n"
22457 - " movq 8(%0), %%mm1\n"
22458 - " movntq %%mm1, 8(%1)\n"
22459 - " movq 16(%0), %%mm2\n"
22460 - " movntq %%mm2, 16(%1)\n"
22461 - " movq 24(%0), %%mm3\n"
22462 - " movntq %%mm3, 24(%1)\n"
22463 - " movq 32(%0), %%mm4\n"
22464 - " movntq %%mm4, 32(%1)\n"
22465 - " movq 40(%0), %%mm5\n"
22466 - " movntq %%mm5, 40(%1)\n"
22467 - " movq 48(%0), %%mm6\n"
22468 - " movntq %%mm6, 48(%1)\n"
22469 - " movq 56(%0), %%mm7\n"
22470 - " movntq %%mm7, 56(%1)\n"
22471 + "1: prefetch 320(%1)\n"
22472 + "2: movq (%1), %%mm0\n"
22473 + " movntq %%mm0, (%2)\n"
22474 + " movq 8(%1), %%mm1\n"
22475 + " movntq %%mm1, 8(%2)\n"
22476 + " movq 16(%1), %%mm2\n"
22477 + " movntq %%mm2, 16(%2)\n"
22478 + " movq 24(%1), %%mm3\n"
22479 + " movntq %%mm3, 24(%2)\n"
22480 + " movq 32(%1), %%mm4\n"
22481 + " movntq %%mm4, 32(%2)\n"
22482 + " movq 40(%1), %%mm5\n"
22483 + " movntq %%mm5, 40(%2)\n"
22484 + " movq 48(%1), %%mm6\n"
22485 + " movntq %%mm6, 48(%2)\n"
22486 + " movq 56(%1), %%mm7\n"
22487 + " movntq %%mm7, 56(%2)\n"
22488 ".section .fixup, \"ax\"\n"
22489 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22490 + "3:\n"
22491 +
22492 +#ifdef CONFIG_PAX_KERNEXEC
22493 + " movl %%cr0, %0\n"
22494 + " movl %0, %%eax\n"
22495 + " andl $0xFFFEFFFF, %%eax\n"
22496 + " movl %%eax, %%cr0\n"
22497 +#endif
22498 +
22499 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22500 +
22501 +#ifdef CONFIG_PAX_KERNEXEC
22502 + " movl %0, %%cr0\n"
22503 +#endif
22504 +
22505 " jmp 2b\n"
22506 ".previous\n"
22507 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22508 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22509
22510 from += 64;
22511 to += 64;
22512 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22513 static void fast_copy_page(void *to, void *from)
22514 {
22515 int i;
22516 + unsigned long cr0;
22517
22518 kernel_fpu_begin();
22519
22520 __asm__ __volatile__ (
22521 - "1: prefetch (%0)\n"
22522 - " prefetch 64(%0)\n"
22523 - " prefetch 128(%0)\n"
22524 - " prefetch 192(%0)\n"
22525 - " prefetch 256(%0)\n"
22526 + "1: prefetch (%1)\n"
22527 + " prefetch 64(%1)\n"
22528 + " prefetch 128(%1)\n"
22529 + " prefetch 192(%1)\n"
22530 + " prefetch 256(%1)\n"
22531 "2: \n"
22532 ".section .fixup, \"ax\"\n"
22533 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22534 + "3: \n"
22535 +
22536 +#ifdef CONFIG_PAX_KERNEXEC
22537 + " movl %%cr0, %0\n"
22538 + " movl %0, %%eax\n"
22539 + " andl $0xFFFEFFFF, %%eax\n"
22540 + " movl %%eax, %%cr0\n"
22541 +#endif
22542 +
22543 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22544 +
22545 +#ifdef CONFIG_PAX_KERNEXEC
22546 + " movl %0, %%cr0\n"
22547 +#endif
22548 +
22549 " jmp 2b\n"
22550 ".previous\n"
22551 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22552 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22553
22554 for (i = 0; i < 4096/64; i++) {
22555 __asm__ __volatile__ (
22556 - "1: prefetch 320(%0)\n"
22557 - "2: movq (%0), %%mm0\n"
22558 - " movq 8(%0), %%mm1\n"
22559 - " movq 16(%0), %%mm2\n"
22560 - " movq 24(%0), %%mm3\n"
22561 - " movq %%mm0, (%1)\n"
22562 - " movq %%mm1, 8(%1)\n"
22563 - " movq %%mm2, 16(%1)\n"
22564 - " movq %%mm3, 24(%1)\n"
22565 - " movq 32(%0), %%mm0\n"
22566 - " movq 40(%0), %%mm1\n"
22567 - " movq 48(%0), %%mm2\n"
22568 - " movq 56(%0), %%mm3\n"
22569 - " movq %%mm0, 32(%1)\n"
22570 - " movq %%mm1, 40(%1)\n"
22571 - " movq %%mm2, 48(%1)\n"
22572 - " movq %%mm3, 56(%1)\n"
22573 + "1: prefetch 320(%1)\n"
22574 + "2: movq (%1), %%mm0\n"
22575 + " movq 8(%1), %%mm1\n"
22576 + " movq 16(%1), %%mm2\n"
22577 + " movq 24(%1), %%mm3\n"
22578 + " movq %%mm0, (%2)\n"
22579 + " movq %%mm1, 8(%2)\n"
22580 + " movq %%mm2, 16(%2)\n"
22581 + " movq %%mm3, 24(%2)\n"
22582 + " movq 32(%1), %%mm0\n"
22583 + " movq 40(%1), %%mm1\n"
22584 + " movq 48(%1), %%mm2\n"
22585 + " movq 56(%1), %%mm3\n"
22586 + " movq %%mm0, 32(%2)\n"
22587 + " movq %%mm1, 40(%2)\n"
22588 + " movq %%mm2, 48(%2)\n"
22589 + " movq %%mm3, 56(%2)\n"
22590 ".section .fixup, \"ax\"\n"
22591 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22592 + "3:\n"
22593 +
22594 +#ifdef CONFIG_PAX_KERNEXEC
22595 + " movl %%cr0, %0\n"
22596 + " movl %0, %%eax\n"
22597 + " andl $0xFFFEFFFF, %%eax\n"
22598 + " movl %%eax, %%cr0\n"
22599 +#endif
22600 +
22601 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22602 +
22603 +#ifdef CONFIG_PAX_KERNEXEC
22604 + " movl %0, %%cr0\n"
22605 +#endif
22606 +
22607 " jmp 2b\n"
22608 ".previous\n"
22609 _ASM_EXTABLE(1b, 3b)
22610 - : : "r" (from), "r" (to) : "memory");
22611 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22612
22613 from += 64;
22614 to += 64;
22615 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22616 index f6d13ee..aca5f0b 100644
22617 --- a/arch/x86/lib/msr-reg.S
22618 +++ b/arch/x86/lib/msr-reg.S
22619 @@ -3,6 +3,7 @@
22620 #include <asm/dwarf2.h>
22621 #include <asm/asm.h>
22622 #include <asm/msr.h>
22623 +#include <asm/alternative-asm.h>
22624
22625 #ifdef CONFIG_X86_64
22626 /*
22627 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22628 CFI_STARTPROC
22629 pushq_cfi %rbx
22630 pushq_cfi %rbp
22631 - movq %rdi, %r10 /* Save pointer */
22632 + movq %rdi, %r9 /* Save pointer */
22633 xorl %r11d, %r11d /* Return value */
22634 movl (%rdi), %eax
22635 movl 4(%rdi), %ecx
22636 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22637 movl 28(%rdi), %edi
22638 CFI_REMEMBER_STATE
22639 1: \op
22640 -2: movl %eax, (%r10)
22641 +2: movl %eax, (%r9)
22642 movl %r11d, %eax /* Return value */
22643 - movl %ecx, 4(%r10)
22644 - movl %edx, 8(%r10)
22645 - movl %ebx, 12(%r10)
22646 - movl %ebp, 20(%r10)
22647 - movl %esi, 24(%r10)
22648 - movl %edi, 28(%r10)
22649 + movl %ecx, 4(%r9)
22650 + movl %edx, 8(%r9)
22651 + movl %ebx, 12(%r9)
22652 + movl %ebp, 20(%r9)
22653 + movl %esi, 24(%r9)
22654 + movl %edi, 28(%r9)
22655 popq_cfi %rbp
22656 popq_cfi %rbx
22657 + pax_force_retaddr
22658 ret
22659 3:
22660 CFI_RESTORE_STATE
22661 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22662 index 7f951c8..ebd573a 100644
22663 --- a/arch/x86/lib/putuser.S
22664 +++ b/arch/x86/lib/putuser.S
22665 @@ -15,7 +15,9 @@
22666 #include <asm/thread_info.h>
22667 #include <asm/errno.h>
22668 #include <asm/asm.h>
22669 -
22670 +#include <asm/segment.h>
22671 +#include <asm/pgtable.h>
22672 +#include <asm/alternative-asm.h>
22673
22674 /*
22675 * __put_user_X
22676 @@ -29,52 +31,119 @@
22677 * as they get called from within inline assembly.
22678 */
22679
22680 -#define ENTER CFI_STARTPROC ; \
22681 - GET_THREAD_INFO(%_ASM_BX)
22682 -#define EXIT ret ; \
22683 +#define ENTER CFI_STARTPROC
22684 +#define EXIT pax_force_retaddr; ret ; \
22685 CFI_ENDPROC
22686
22687 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22688 +#define _DEST %_ASM_CX,%_ASM_BX
22689 +#else
22690 +#define _DEST %_ASM_CX
22691 +#endif
22692 +
22693 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22694 +#define __copyuser_seg gs;
22695 +#else
22696 +#define __copyuser_seg
22697 +#endif
22698 +
22699 .text
22700 ENTRY(__put_user_1)
22701 ENTER
22702 +
22703 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22704 + GET_THREAD_INFO(%_ASM_BX)
22705 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22706 jae bad_put_user
22707 -1: movb %al,(%_ASM_CX)
22708 +
22709 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22710 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22711 + cmp %_ASM_BX,%_ASM_CX
22712 + jb 1234f
22713 + xor %ebx,%ebx
22714 +1234:
22715 +#endif
22716 +
22717 +#endif
22718 +
22719 +1: __copyuser_seg movb %al,(_DEST)
22720 xor %eax,%eax
22721 EXIT
22722 ENDPROC(__put_user_1)
22723
22724 ENTRY(__put_user_2)
22725 ENTER
22726 +
22727 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22728 + GET_THREAD_INFO(%_ASM_BX)
22729 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22730 sub $1,%_ASM_BX
22731 cmp %_ASM_BX,%_ASM_CX
22732 jae bad_put_user
22733 -2: movw %ax,(%_ASM_CX)
22734 +
22735 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22736 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22737 + cmp %_ASM_BX,%_ASM_CX
22738 + jb 1234f
22739 + xor %ebx,%ebx
22740 +1234:
22741 +#endif
22742 +
22743 +#endif
22744 +
22745 +2: __copyuser_seg movw %ax,(_DEST)
22746 xor %eax,%eax
22747 EXIT
22748 ENDPROC(__put_user_2)
22749
22750 ENTRY(__put_user_4)
22751 ENTER
22752 +
22753 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22754 + GET_THREAD_INFO(%_ASM_BX)
22755 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22756 sub $3,%_ASM_BX
22757 cmp %_ASM_BX,%_ASM_CX
22758 jae bad_put_user
22759 -3: movl %eax,(%_ASM_CX)
22760 +
22761 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22762 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22763 + cmp %_ASM_BX,%_ASM_CX
22764 + jb 1234f
22765 + xor %ebx,%ebx
22766 +1234:
22767 +#endif
22768 +
22769 +#endif
22770 +
22771 +3: __copyuser_seg movl %eax,(_DEST)
22772 xor %eax,%eax
22773 EXIT
22774 ENDPROC(__put_user_4)
22775
22776 ENTRY(__put_user_8)
22777 ENTER
22778 +
22779 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22780 + GET_THREAD_INFO(%_ASM_BX)
22781 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22782 sub $7,%_ASM_BX
22783 cmp %_ASM_BX,%_ASM_CX
22784 jae bad_put_user
22785 -4: mov %_ASM_AX,(%_ASM_CX)
22786 +
22787 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22788 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22789 + cmp %_ASM_BX,%_ASM_CX
22790 + jb 1234f
22791 + xor %ebx,%ebx
22792 +1234:
22793 +#endif
22794 +
22795 +#endif
22796 +
22797 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22798 #ifdef CONFIG_X86_32
22799 -5: movl %edx,4(%_ASM_CX)
22800 +5: __copyuser_seg movl %edx,4(_DEST)
22801 #endif
22802 xor %eax,%eax
22803 EXIT
22804 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22805 index 1cad221..de671ee 100644
22806 --- a/arch/x86/lib/rwlock.S
22807 +++ b/arch/x86/lib/rwlock.S
22808 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22809 FRAME
22810 0: LOCK_PREFIX
22811 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22812 +
22813 +#ifdef CONFIG_PAX_REFCOUNT
22814 + jno 1234f
22815 + LOCK_PREFIX
22816 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22817 + int $4
22818 +1234:
22819 + _ASM_EXTABLE(1234b, 1234b)
22820 +#endif
22821 +
22822 1: rep; nop
22823 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22824 jne 1b
22825 LOCK_PREFIX
22826 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22827 +
22828 +#ifdef CONFIG_PAX_REFCOUNT
22829 + jno 1234f
22830 + LOCK_PREFIX
22831 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22832 + int $4
22833 +1234:
22834 + _ASM_EXTABLE(1234b, 1234b)
22835 +#endif
22836 +
22837 jnz 0b
22838 ENDFRAME
22839 + pax_force_retaddr
22840 ret
22841 CFI_ENDPROC
22842 END(__write_lock_failed)
22843 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22844 FRAME
22845 0: LOCK_PREFIX
22846 READ_LOCK_SIZE(inc) (%__lock_ptr)
22847 +
22848 +#ifdef CONFIG_PAX_REFCOUNT
22849 + jno 1234f
22850 + LOCK_PREFIX
22851 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22852 + int $4
22853 +1234:
22854 + _ASM_EXTABLE(1234b, 1234b)
22855 +#endif
22856 +
22857 1: rep; nop
22858 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22859 js 1b
22860 LOCK_PREFIX
22861 READ_LOCK_SIZE(dec) (%__lock_ptr)
22862 +
22863 +#ifdef CONFIG_PAX_REFCOUNT
22864 + jno 1234f
22865 + LOCK_PREFIX
22866 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22867 + int $4
22868 +1234:
22869 + _ASM_EXTABLE(1234b, 1234b)
22870 +#endif
22871 +
22872 js 0b
22873 ENDFRAME
22874 + pax_force_retaddr
22875 ret
22876 CFI_ENDPROC
22877 END(__read_lock_failed)
22878 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22879 index 5dff5f0..cadebf4 100644
22880 --- a/arch/x86/lib/rwsem.S
22881 +++ b/arch/x86/lib/rwsem.S
22882 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22883 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22884 CFI_RESTORE __ASM_REG(dx)
22885 restore_common_regs
22886 + pax_force_retaddr
22887 ret
22888 CFI_ENDPROC
22889 ENDPROC(call_rwsem_down_read_failed)
22890 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22891 movq %rax,%rdi
22892 call rwsem_down_write_failed
22893 restore_common_regs
22894 + pax_force_retaddr
22895 ret
22896 CFI_ENDPROC
22897 ENDPROC(call_rwsem_down_write_failed)
22898 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22899 movq %rax,%rdi
22900 call rwsem_wake
22901 restore_common_regs
22902 -1: ret
22903 +1: pax_force_retaddr
22904 + ret
22905 CFI_ENDPROC
22906 ENDPROC(call_rwsem_wake)
22907
22908 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22909 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22910 CFI_RESTORE __ASM_REG(dx)
22911 restore_common_regs
22912 + pax_force_retaddr
22913 ret
22914 CFI_ENDPROC
22915 ENDPROC(call_rwsem_downgrade_wake)
22916 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22917 index a63efd6..ccecad8 100644
22918 --- a/arch/x86/lib/thunk_64.S
22919 +++ b/arch/x86/lib/thunk_64.S
22920 @@ -8,6 +8,7 @@
22921 #include <linux/linkage.h>
22922 #include <asm/dwarf2.h>
22923 #include <asm/calling.h>
22924 +#include <asm/alternative-asm.h>
22925
22926 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22927 .macro THUNK name, func, put_ret_addr_in_rdi=0
22928 @@ -41,5 +42,6 @@
22929 SAVE_ARGS
22930 restore:
22931 RESTORE_ARGS
22932 + pax_force_retaddr
22933 ret
22934 CFI_ENDPROC
22935 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22936 index 1781b2f..90368dd 100644
22937 --- a/arch/x86/lib/usercopy_32.c
22938 +++ b/arch/x86/lib/usercopy_32.c
22939 @@ -42,10 +42,12 @@ do { \
22940 int __d0; \
22941 might_fault(); \
22942 __asm__ __volatile__( \
22943 + __COPYUSER_SET_ES \
22944 "0: rep; stosl\n" \
22945 " movl %2,%0\n" \
22946 "1: rep; stosb\n" \
22947 "2:\n" \
22948 + __COPYUSER_RESTORE_ES \
22949 ".section .fixup,\"ax\"\n" \
22950 "3: lea 0(%2,%0,4),%0\n" \
22951 " jmp 2b\n" \
22952 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22953
22954 #ifdef CONFIG_X86_INTEL_USERCOPY
22955 static unsigned long
22956 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22957 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22958 {
22959 int d0, d1;
22960 __asm__ __volatile__(
22961 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22962 " .align 2,0x90\n"
22963 "3: movl 0(%4), %%eax\n"
22964 "4: movl 4(%4), %%edx\n"
22965 - "5: movl %%eax, 0(%3)\n"
22966 - "6: movl %%edx, 4(%3)\n"
22967 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22968 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22969 "7: movl 8(%4), %%eax\n"
22970 "8: movl 12(%4),%%edx\n"
22971 - "9: movl %%eax, 8(%3)\n"
22972 - "10: movl %%edx, 12(%3)\n"
22973 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22974 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22975 "11: movl 16(%4), %%eax\n"
22976 "12: movl 20(%4), %%edx\n"
22977 - "13: movl %%eax, 16(%3)\n"
22978 - "14: movl %%edx, 20(%3)\n"
22979 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22980 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22981 "15: movl 24(%4), %%eax\n"
22982 "16: movl 28(%4), %%edx\n"
22983 - "17: movl %%eax, 24(%3)\n"
22984 - "18: movl %%edx, 28(%3)\n"
22985 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22986 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22987 "19: movl 32(%4), %%eax\n"
22988 "20: movl 36(%4), %%edx\n"
22989 - "21: movl %%eax, 32(%3)\n"
22990 - "22: movl %%edx, 36(%3)\n"
22991 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22992 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22993 "23: movl 40(%4), %%eax\n"
22994 "24: movl 44(%4), %%edx\n"
22995 - "25: movl %%eax, 40(%3)\n"
22996 - "26: movl %%edx, 44(%3)\n"
22997 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22998 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22999 "27: movl 48(%4), %%eax\n"
23000 "28: movl 52(%4), %%edx\n"
23001 - "29: movl %%eax, 48(%3)\n"
23002 - "30: movl %%edx, 52(%3)\n"
23003 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23004 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23005 "31: movl 56(%4), %%eax\n"
23006 "32: movl 60(%4), %%edx\n"
23007 - "33: movl %%eax, 56(%3)\n"
23008 - "34: movl %%edx, 60(%3)\n"
23009 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23010 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23011 " addl $-64, %0\n"
23012 " addl $64, %4\n"
23013 " addl $64, %3\n"
23014 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23015 " shrl $2, %0\n"
23016 " andl $3, %%eax\n"
23017 " cld\n"
23018 + __COPYUSER_SET_ES
23019 "99: rep; movsl\n"
23020 "36: movl %%eax, %0\n"
23021 "37: rep; movsb\n"
23022 "100:\n"
23023 + __COPYUSER_RESTORE_ES
23024 ".section .fixup,\"ax\"\n"
23025 "101: lea 0(%%eax,%0,4),%0\n"
23026 " jmp 100b\n"
23027 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23028 }
23029
23030 static unsigned long
23031 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23032 +{
23033 + int d0, d1;
23034 + __asm__ __volatile__(
23035 + " .align 2,0x90\n"
23036 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23037 + " cmpl $67, %0\n"
23038 + " jbe 3f\n"
23039 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23040 + " .align 2,0x90\n"
23041 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23042 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23043 + "5: movl %%eax, 0(%3)\n"
23044 + "6: movl %%edx, 4(%3)\n"
23045 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23046 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23047 + "9: movl %%eax, 8(%3)\n"
23048 + "10: movl %%edx, 12(%3)\n"
23049 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23050 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23051 + "13: movl %%eax, 16(%3)\n"
23052 + "14: movl %%edx, 20(%3)\n"
23053 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23054 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23055 + "17: movl %%eax, 24(%3)\n"
23056 + "18: movl %%edx, 28(%3)\n"
23057 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23058 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23059 + "21: movl %%eax, 32(%3)\n"
23060 + "22: movl %%edx, 36(%3)\n"
23061 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23062 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23063 + "25: movl %%eax, 40(%3)\n"
23064 + "26: movl %%edx, 44(%3)\n"
23065 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23066 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23067 + "29: movl %%eax, 48(%3)\n"
23068 + "30: movl %%edx, 52(%3)\n"
23069 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23070 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23071 + "33: movl %%eax, 56(%3)\n"
23072 + "34: movl %%edx, 60(%3)\n"
23073 + " addl $-64, %0\n"
23074 + " addl $64, %4\n"
23075 + " addl $64, %3\n"
23076 + " cmpl $63, %0\n"
23077 + " ja 1b\n"
23078 + "35: movl %0, %%eax\n"
23079 + " shrl $2, %0\n"
23080 + " andl $3, %%eax\n"
23081 + " cld\n"
23082 + "99: rep; "__copyuser_seg" movsl\n"
23083 + "36: movl %%eax, %0\n"
23084 + "37: rep; "__copyuser_seg" movsb\n"
23085 + "100:\n"
23086 + ".section .fixup,\"ax\"\n"
23087 + "101: lea 0(%%eax,%0,4),%0\n"
23088 + " jmp 100b\n"
23089 + ".previous\n"
23090 + _ASM_EXTABLE(1b,100b)
23091 + _ASM_EXTABLE(2b,100b)
23092 + _ASM_EXTABLE(3b,100b)
23093 + _ASM_EXTABLE(4b,100b)
23094 + _ASM_EXTABLE(5b,100b)
23095 + _ASM_EXTABLE(6b,100b)
23096 + _ASM_EXTABLE(7b,100b)
23097 + _ASM_EXTABLE(8b,100b)
23098 + _ASM_EXTABLE(9b,100b)
23099 + _ASM_EXTABLE(10b,100b)
23100 + _ASM_EXTABLE(11b,100b)
23101 + _ASM_EXTABLE(12b,100b)
23102 + _ASM_EXTABLE(13b,100b)
23103 + _ASM_EXTABLE(14b,100b)
23104 + _ASM_EXTABLE(15b,100b)
23105 + _ASM_EXTABLE(16b,100b)
23106 + _ASM_EXTABLE(17b,100b)
23107 + _ASM_EXTABLE(18b,100b)
23108 + _ASM_EXTABLE(19b,100b)
23109 + _ASM_EXTABLE(20b,100b)
23110 + _ASM_EXTABLE(21b,100b)
23111 + _ASM_EXTABLE(22b,100b)
23112 + _ASM_EXTABLE(23b,100b)
23113 + _ASM_EXTABLE(24b,100b)
23114 + _ASM_EXTABLE(25b,100b)
23115 + _ASM_EXTABLE(26b,100b)
23116 + _ASM_EXTABLE(27b,100b)
23117 + _ASM_EXTABLE(28b,100b)
23118 + _ASM_EXTABLE(29b,100b)
23119 + _ASM_EXTABLE(30b,100b)
23120 + _ASM_EXTABLE(31b,100b)
23121 + _ASM_EXTABLE(32b,100b)
23122 + _ASM_EXTABLE(33b,100b)
23123 + _ASM_EXTABLE(34b,100b)
23124 + _ASM_EXTABLE(35b,100b)
23125 + _ASM_EXTABLE(36b,100b)
23126 + _ASM_EXTABLE(37b,100b)
23127 + _ASM_EXTABLE(99b,101b)
23128 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23129 + : "1"(to), "2"(from), "0"(size)
23130 + : "eax", "edx", "memory");
23131 + return size;
23132 +}
23133 +
23134 +static unsigned long __size_overflow(3)
23135 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23136 {
23137 int d0, d1;
23138 __asm__ __volatile__(
23139 " .align 2,0x90\n"
23140 - "0: movl 32(%4), %%eax\n"
23141 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23142 " cmpl $67, %0\n"
23143 " jbe 2f\n"
23144 - "1: movl 64(%4), %%eax\n"
23145 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23146 " .align 2,0x90\n"
23147 - "2: movl 0(%4), %%eax\n"
23148 - "21: movl 4(%4), %%edx\n"
23149 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23150 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23151 " movl %%eax, 0(%3)\n"
23152 " movl %%edx, 4(%3)\n"
23153 - "3: movl 8(%4), %%eax\n"
23154 - "31: movl 12(%4),%%edx\n"
23155 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23156 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23157 " movl %%eax, 8(%3)\n"
23158 " movl %%edx, 12(%3)\n"
23159 - "4: movl 16(%4), %%eax\n"
23160 - "41: movl 20(%4), %%edx\n"
23161 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23162 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23163 " movl %%eax, 16(%3)\n"
23164 " movl %%edx, 20(%3)\n"
23165 - "10: movl 24(%4), %%eax\n"
23166 - "51: movl 28(%4), %%edx\n"
23167 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23168 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23169 " movl %%eax, 24(%3)\n"
23170 " movl %%edx, 28(%3)\n"
23171 - "11: movl 32(%4), %%eax\n"
23172 - "61: movl 36(%4), %%edx\n"
23173 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23174 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23175 " movl %%eax, 32(%3)\n"
23176 " movl %%edx, 36(%3)\n"
23177 - "12: movl 40(%4), %%eax\n"
23178 - "71: movl 44(%4), %%edx\n"
23179 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23180 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23181 " movl %%eax, 40(%3)\n"
23182 " movl %%edx, 44(%3)\n"
23183 - "13: movl 48(%4), %%eax\n"
23184 - "81: movl 52(%4), %%edx\n"
23185 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23186 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23187 " movl %%eax, 48(%3)\n"
23188 " movl %%edx, 52(%3)\n"
23189 - "14: movl 56(%4), %%eax\n"
23190 - "91: movl 60(%4), %%edx\n"
23191 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23192 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23193 " movl %%eax, 56(%3)\n"
23194 " movl %%edx, 60(%3)\n"
23195 " addl $-64, %0\n"
23196 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23197 " shrl $2, %0\n"
23198 " andl $3, %%eax\n"
23199 " cld\n"
23200 - "6: rep; movsl\n"
23201 + "6: rep; "__copyuser_seg" movsl\n"
23202 " movl %%eax,%0\n"
23203 - "7: rep; movsb\n"
23204 + "7: rep; "__copyuser_seg" movsb\n"
23205 "8:\n"
23206 ".section .fixup,\"ax\"\n"
23207 "9: lea 0(%%eax,%0,4),%0\n"
23208 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23209 * hyoshiok@miraclelinux.com
23210 */
23211
23212 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23213 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23214 const void __user *from, unsigned long size)
23215 {
23216 int d0, d1;
23217
23218 __asm__ __volatile__(
23219 " .align 2,0x90\n"
23220 - "0: movl 32(%4), %%eax\n"
23221 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23222 " cmpl $67, %0\n"
23223 " jbe 2f\n"
23224 - "1: movl 64(%4), %%eax\n"
23225 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23226 " .align 2,0x90\n"
23227 - "2: movl 0(%4), %%eax\n"
23228 - "21: movl 4(%4), %%edx\n"
23229 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23230 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23231 " movnti %%eax, 0(%3)\n"
23232 " movnti %%edx, 4(%3)\n"
23233 - "3: movl 8(%4), %%eax\n"
23234 - "31: movl 12(%4),%%edx\n"
23235 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23236 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23237 " movnti %%eax, 8(%3)\n"
23238 " movnti %%edx, 12(%3)\n"
23239 - "4: movl 16(%4), %%eax\n"
23240 - "41: movl 20(%4), %%edx\n"
23241 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23242 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23243 " movnti %%eax, 16(%3)\n"
23244 " movnti %%edx, 20(%3)\n"
23245 - "10: movl 24(%4), %%eax\n"
23246 - "51: movl 28(%4), %%edx\n"
23247 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23248 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23249 " movnti %%eax, 24(%3)\n"
23250 " movnti %%edx, 28(%3)\n"
23251 - "11: movl 32(%4), %%eax\n"
23252 - "61: movl 36(%4), %%edx\n"
23253 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23254 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23255 " movnti %%eax, 32(%3)\n"
23256 " movnti %%edx, 36(%3)\n"
23257 - "12: movl 40(%4), %%eax\n"
23258 - "71: movl 44(%4), %%edx\n"
23259 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23260 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23261 " movnti %%eax, 40(%3)\n"
23262 " movnti %%edx, 44(%3)\n"
23263 - "13: movl 48(%4), %%eax\n"
23264 - "81: movl 52(%4), %%edx\n"
23265 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23266 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23267 " movnti %%eax, 48(%3)\n"
23268 " movnti %%edx, 52(%3)\n"
23269 - "14: movl 56(%4), %%eax\n"
23270 - "91: movl 60(%4), %%edx\n"
23271 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23272 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23273 " movnti %%eax, 56(%3)\n"
23274 " movnti %%edx, 60(%3)\n"
23275 " addl $-64, %0\n"
23276 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23277 " shrl $2, %0\n"
23278 " andl $3, %%eax\n"
23279 " cld\n"
23280 - "6: rep; movsl\n"
23281 + "6: rep; "__copyuser_seg" movsl\n"
23282 " movl %%eax,%0\n"
23283 - "7: rep; movsb\n"
23284 + "7: rep; "__copyuser_seg" movsb\n"
23285 "8:\n"
23286 ".section .fixup,\"ax\"\n"
23287 "9: lea 0(%%eax,%0,4),%0\n"
23288 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23289 return size;
23290 }
23291
23292 -static unsigned long __copy_user_intel_nocache(void *to,
23293 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23294 const void __user *from, unsigned long size)
23295 {
23296 int d0, d1;
23297
23298 __asm__ __volatile__(
23299 " .align 2,0x90\n"
23300 - "0: movl 32(%4), %%eax\n"
23301 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23302 " cmpl $67, %0\n"
23303 " jbe 2f\n"
23304 - "1: movl 64(%4), %%eax\n"
23305 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23306 " .align 2,0x90\n"
23307 - "2: movl 0(%4), %%eax\n"
23308 - "21: movl 4(%4), %%edx\n"
23309 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23310 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23311 " movnti %%eax, 0(%3)\n"
23312 " movnti %%edx, 4(%3)\n"
23313 - "3: movl 8(%4), %%eax\n"
23314 - "31: movl 12(%4),%%edx\n"
23315 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23316 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23317 " movnti %%eax, 8(%3)\n"
23318 " movnti %%edx, 12(%3)\n"
23319 - "4: movl 16(%4), %%eax\n"
23320 - "41: movl 20(%4), %%edx\n"
23321 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23322 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23323 " movnti %%eax, 16(%3)\n"
23324 " movnti %%edx, 20(%3)\n"
23325 - "10: movl 24(%4), %%eax\n"
23326 - "51: movl 28(%4), %%edx\n"
23327 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23328 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23329 " movnti %%eax, 24(%3)\n"
23330 " movnti %%edx, 28(%3)\n"
23331 - "11: movl 32(%4), %%eax\n"
23332 - "61: movl 36(%4), %%edx\n"
23333 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23334 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23335 " movnti %%eax, 32(%3)\n"
23336 " movnti %%edx, 36(%3)\n"
23337 - "12: movl 40(%4), %%eax\n"
23338 - "71: movl 44(%4), %%edx\n"
23339 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23340 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23341 " movnti %%eax, 40(%3)\n"
23342 " movnti %%edx, 44(%3)\n"
23343 - "13: movl 48(%4), %%eax\n"
23344 - "81: movl 52(%4), %%edx\n"
23345 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23346 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23347 " movnti %%eax, 48(%3)\n"
23348 " movnti %%edx, 52(%3)\n"
23349 - "14: movl 56(%4), %%eax\n"
23350 - "91: movl 60(%4), %%edx\n"
23351 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23352 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23353 " movnti %%eax, 56(%3)\n"
23354 " movnti %%edx, 60(%3)\n"
23355 " addl $-64, %0\n"
23356 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23357 " shrl $2, %0\n"
23358 " andl $3, %%eax\n"
23359 " cld\n"
23360 - "6: rep; movsl\n"
23361 + "6: rep; "__copyuser_seg" movsl\n"
23362 " movl %%eax,%0\n"
23363 - "7: rep; movsb\n"
23364 + "7: rep; "__copyuser_seg" movsb\n"
23365 "8:\n"
23366 ".section .fixup,\"ax\"\n"
23367 "9: lea 0(%%eax,%0,4),%0\n"
23368 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23369 */
23370 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23371 unsigned long size);
23372 -unsigned long __copy_user_intel(void __user *to, const void *from,
23373 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23374 + unsigned long size);
23375 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23376 unsigned long size);
23377 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23378 const void __user *from, unsigned long size);
23379 #endif /* CONFIG_X86_INTEL_USERCOPY */
23380
23381 /* Generic arbitrary sized copy. */
23382 -#define __copy_user(to, from, size) \
23383 +#define __copy_user(to, from, size, prefix, set, restore) \
23384 do { \
23385 int __d0, __d1, __d2; \
23386 __asm__ __volatile__( \
23387 + set \
23388 " cmp $7,%0\n" \
23389 " jbe 1f\n" \
23390 " movl %1,%0\n" \
23391 " negl %0\n" \
23392 " andl $7,%0\n" \
23393 " subl %0,%3\n" \
23394 - "4: rep; movsb\n" \
23395 + "4: rep; "prefix"movsb\n" \
23396 " movl %3,%0\n" \
23397 " shrl $2,%0\n" \
23398 " andl $3,%3\n" \
23399 " .align 2,0x90\n" \
23400 - "0: rep; movsl\n" \
23401 + "0: rep; "prefix"movsl\n" \
23402 " movl %3,%0\n" \
23403 - "1: rep; movsb\n" \
23404 + "1: rep; "prefix"movsb\n" \
23405 "2:\n" \
23406 + restore \
23407 ".section .fixup,\"ax\"\n" \
23408 "5: addl %3,%0\n" \
23409 " jmp 2b\n" \
23410 @@ -537,14 +649,14 @@ do { \
23411 " negl %0\n" \
23412 " andl $7,%0\n" \
23413 " subl %0,%3\n" \
23414 - "4: rep; movsb\n" \
23415 + "4: rep; "__copyuser_seg"movsb\n" \
23416 " movl %3,%0\n" \
23417 " shrl $2,%0\n" \
23418 " andl $3,%3\n" \
23419 " .align 2,0x90\n" \
23420 - "0: rep; movsl\n" \
23421 + "0: rep; "__copyuser_seg"movsl\n" \
23422 " movl %3,%0\n" \
23423 - "1: rep; movsb\n" \
23424 + "1: rep; "__copyuser_seg"movsb\n" \
23425 "2:\n" \
23426 ".section .fixup,\"ax\"\n" \
23427 "5: addl %3,%0\n" \
23428 @@ -627,9 +739,9 @@ survive:
23429 }
23430 #endif
23431 if (movsl_is_ok(to, from, n))
23432 - __copy_user(to, from, n);
23433 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23434 else
23435 - n = __copy_user_intel(to, from, n);
23436 + n = __generic_copy_to_user_intel(to, from, n);
23437 return n;
23438 }
23439 EXPORT_SYMBOL(__copy_to_user_ll);
23440 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23441 unsigned long n)
23442 {
23443 if (movsl_is_ok(to, from, n))
23444 - __copy_user(to, from, n);
23445 + __copy_user(to, from, n, __copyuser_seg, "", "");
23446 else
23447 - n = __copy_user_intel((void __user *)to,
23448 - (const void *)from, n);
23449 + n = __generic_copy_from_user_intel(to, from, n);
23450 return n;
23451 }
23452 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23453 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23454 if (n > 64 && cpu_has_xmm2)
23455 n = __copy_user_intel_nocache(to, from, n);
23456 else
23457 - __copy_user(to, from, n);
23458 + __copy_user(to, from, n, __copyuser_seg, "", "");
23459 #else
23460 - __copy_user(to, from, n);
23461 + __copy_user(to, from, n, __copyuser_seg, "", "");
23462 #endif
23463 return n;
23464 }
23465 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23466
23467 -/**
23468 - * copy_to_user: - Copy a block of data into user space.
23469 - * @to: Destination address, in user space.
23470 - * @from: Source address, in kernel space.
23471 - * @n: Number of bytes to copy.
23472 - *
23473 - * Context: User context only. This function may sleep.
23474 - *
23475 - * Copy data from kernel space to user space.
23476 - *
23477 - * Returns number of bytes that could not be copied.
23478 - * On success, this will be zero.
23479 - */
23480 -unsigned long
23481 -copy_to_user(void __user *to, const void *from, unsigned long n)
23482 -{
23483 - if (access_ok(VERIFY_WRITE, to, n))
23484 - n = __copy_to_user(to, from, n);
23485 - return n;
23486 -}
23487 -EXPORT_SYMBOL(copy_to_user);
23488 -
23489 -/**
23490 - * copy_from_user: - Copy a block of data from user space.
23491 - * @to: Destination address, in kernel space.
23492 - * @from: Source address, in user space.
23493 - * @n: Number of bytes to copy.
23494 - *
23495 - * Context: User context only. This function may sleep.
23496 - *
23497 - * Copy data from user space to kernel space.
23498 - *
23499 - * Returns number of bytes that could not be copied.
23500 - * On success, this will be zero.
23501 - *
23502 - * If some data could not be copied, this function will pad the copied
23503 - * data to the requested size using zero bytes.
23504 - */
23505 -unsigned long
23506 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23507 -{
23508 - if (access_ok(VERIFY_READ, from, n))
23509 - n = __copy_from_user(to, from, n);
23510 - else
23511 - memset(to, 0, n);
23512 - return n;
23513 -}
23514 -EXPORT_SYMBOL(_copy_from_user);
23515 -
23516 void copy_from_user_overflow(void)
23517 {
23518 WARN(1, "Buffer overflow detected!\n");
23519 }
23520 EXPORT_SYMBOL(copy_from_user_overflow);
23521 +
23522 +void copy_to_user_overflow(void)
23523 +{
23524 + WARN(1, "Buffer overflow detected!\n");
23525 +}
23526 +EXPORT_SYMBOL(copy_to_user_overflow);
23527 +
23528 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23529 +void __set_fs(mm_segment_t x)
23530 +{
23531 + switch (x.seg) {
23532 + case 0:
23533 + loadsegment(gs, 0);
23534 + break;
23535 + case TASK_SIZE_MAX:
23536 + loadsegment(gs, __USER_DS);
23537 + break;
23538 + case -1UL:
23539 + loadsegment(gs, __KERNEL_DS);
23540 + break;
23541 + default:
23542 + BUG();
23543 + }
23544 + return;
23545 +}
23546 +EXPORT_SYMBOL(__set_fs);
23547 +
23548 +void set_fs(mm_segment_t x)
23549 +{
23550 + current_thread_info()->addr_limit = x;
23551 + __set_fs(x);
23552 +}
23553 +EXPORT_SYMBOL(set_fs);
23554 +#endif
23555 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23556 index e5b130b..7d33980 100644
23557 --- a/arch/x86/lib/usercopy_64.c
23558 +++ b/arch/x86/lib/usercopy_64.c
23559 @@ -38,7 +38,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23560 _ASM_EXTABLE(0b,3b)
23561 _ASM_EXTABLE(1b,2b)
23562 : [size8] "=&c"(size), [dst] "=&D" (__d0)
23563 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
23564 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
23565 [zero] "r" (0UL), [eight] "r" (8UL));
23566 return size;
23567 }
23568 @@ -52,12 +52,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
23569 }
23570 EXPORT_SYMBOL(clear_user);
23571
23572 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23573 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23574 {
23575 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23576 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23577 - }
23578 - return len;
23579 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
23580 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
23581 + return len;
23582 }
23583 EXPORT_SYMBOL(copy_in_user);
23584
23585 @@ -67,7 +66,7 @@ EXPORT_SYMBOL(copy_in_user);
23586 * it is not necessary to optimize tail handling.
23587 */
23588 unsigned long
23589 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23590 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23591 {
23592 char c;
23593 unsigned zero_len;
23594 @@ -84,3 +83,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23595 break;
23596 return len;
23597 }
23598 +
23599 +void copy_from_user_overflow(void)
23600 +{
23601 + WARN(1, "Buffer overflow detected!\n");
23602 +}
23603 +EXPORT_SYMBOL(copy_from_user_overflow);
23604 +
23605 +void copy_to_user_overflow(void)
23606 +{
23607 + WARN(1, "Buffer overflow detected!\n");
23608 +}
23609 +EXPORT_SYMBOL(copy_to_user_overflow);
23610 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23611 index 903ec1e..c4166b2 100644
23612 --- a/arch/x86/mm/extable.c
23613 +++ b/arch/x86/mm/extable.c
23614 @@ -6,12 +6,24 @@
23615 static inline unsigned long
23616 ex_insn_addr(const struct exception_table_entry *x)
23617 {
23618 - return (unsigned long)&x->insn + x->insn;
23619 + unsigned long reloc = 0;
23620 +
23621 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23622 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23623 +#endif
23624 +
23625 + return (unsigned long)&x->insn + x->insn + reloc;
23626 }
23627 static inline unsigned long
23628 ex_fixup_addr(const struct exception_table_entry *x)
23629 {
23630 - return (unsigned long)&x->fixup + x->fixup;
23631 + unsigned long reloc = 0;
23632 +
23633 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23634 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23635 +#endif
23636 +
23637 + return (unsigned long)&x->fixup + x->fixup + reloc;
23638 }
23639
23640 int fixup_exception(struct pt_regs *regs)
23641 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23642 unsigned long new_ip;
23643
23644 #ifdef CONFIG_PNPBIOS
23645 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23646 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23647 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23648 extern u32 pnp_bios_is_utter_crap;
23649 pnp_bios_is_utter_crap = 1;
23650 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23651 i += 4;
23652 p->fixup -= i;
23653 i += 4;
23654 +
23655 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23656 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23657 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23658 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23659 +#endif
23660 +
23661 }
23662 }
23663
23664 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23665 index 76dcd9d..e9dffde 100644
23666 --- a/arch/x86/mm/fault.c
23667 +++ b/arch/x86/mm/fault.c
23668 @@ -13,11 +13,18 @@
23669 #include <linux/perf_event.h> /* perf_sw_event */
23670 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23671 #include <linux/prefetch.h> /* prefetchw */
23672 +#include <linux/unistd.h>
23673 +#include <linux/compiler.h>
23674
23675 #include <asm/traps.h> /* dotraplinkage, ... */
23676 #include <asm/pgalloc.h> /* pgd_*(), ... */
23677 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23678 #include <asm/fixmap.h> /* VSYSCALL_START */
23679 +#include <asm/tlbflush.h>
23680 +
23681 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23682 +#include <asm/stacktrace.h>
23683 +#endif
23684
23685 /*
23686 * Page fault error code bits:
23687 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23688 int ret = 0;
23689
23690 /* kprobe_running() needs smp_processor_id() */
23691 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23692 + if (kprobes_built_in() && !user_mode(regs)) {
23693 preempt_disable();
23694 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23695 ret = 1;
23696 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23697 return !instr_lo || (instr_lo>>1) == 1;
23698 case 0x00:
23699 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23700 - if (probe_kernel_address(instr, opcode))
23701 + if (user_mode(regs)) {
23702 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23703 + return 0;
23704 + } else if (probe_kernel_address(instr, opcode))
23705 return 0;
23706
23707 *prefetch = (instr_lo == 0xF) &&
23708 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23709 while (instr < max_instr) {
23710 unsigned char opcode;
23711
23712 - if (probe_kernel_address(instr, opcode))
23713 + if (user_mode(regs)) {
23714 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23715 + break;
23716 + } else if (probe_kernel_address(instr, opcode))
23717 break;
23718
23719 instr++;
23720 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23721 force_sig_info(si_signo, &info, tsk);
23722 }
23723
23724 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23725 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23726 +#endif
23727 +
23728 +#ifdef CONFIG_PAX_EMUTRAMP
23729 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23730 +#endif
23731 +
23732 +#ifdef CONFIG_PAX_PAGEEXEC
23733 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23734 +{
23735 + pgd_t *pgd;
23736 + pud_t *pud;
23737 + pmd_t *pmd;
23738 +
23739 + pgd = pgd_offset(mm, address);
23740 + if (!pgd_present(*pgd))
23741 + return NULL;
23742 + pud = pud_offset(pgd, address);
23743 + if (!pud_present(*pud))
23744 + return NULL;
23745 + pmd = pmd_offset(pud, address);
23746 + if (!pmd_present(*pmd))
23747 + return NULL;
23748 + return pmd;
23749 +}
23750 +#endif
23751 +
23752 DEFINE_SPINLOCK(pgd_lock);
23753 LIST_HEAD(pgd_list);
23754
23755 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23756 for (address = VMALLOC_START & PMD_MASK;
23757 address >= TASK_SIZE && address < FIXADDR_TOP;
23758 address += PMD_SIZE) {
23759 +
23760 +#ifdef CONFIG_PAX_PER_CPU_PGD
23761 + unsigned long cpu;
23762 +#else
23763 struct page *page;
23764 +#endif
23765
23766 spin_lock(&pgd_lock);
23767 +
23768 +#ifdef CONFIG_PAX_PER_CPU_PGD
23769 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23770 + pgd_t *pgd = get_cpu_pgd(cpu);
23771 + pmd_t *ret;
23772 +#else
23773 list_for_each_entry(page, &pgd_list, lru) {
23774 + pgd_t *pgd = page_address(page);
23775 spinlock_t *pgt_lock;
23776 pmd_t *ret;
23777
23778 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23779 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23780
23781 spin_lock(pgt_lock);
23782 - ret = vmalloc_sync_one(page_address(page), address);
23783 +#endif
23784 +
23785 + ret = vmalloc_sync_one(pgd, address);
23786 +
23787 +#ifndef CONFIG_PAX_PER_CPU_PGD
23788 spin_unlock(pgt_lock);
23789 +#endif
23790
23791 if (!ret)
23792 break;
23793 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23794 * an interrupt in the middle of a task switch..
23795 */
23796 pgd_paddr = read_cr3();
23797 +
23798 +#ifdef CONFIG_PAX_PER_CPU_PGD
23799 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23800 +#endif
23801 +
23802 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23803 if (!pmd_k)
23804 return -1;
23805 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23806 * happen within a race in page table update. In the later
23807 * case just flush:
23808 */
23809 +
23810 +#ifdef CONFIG_PAX_PER_CPU_PGD
23811 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23812 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23813 +#else
23814 pgd = pgd_offset(current->active_mm, address);
23815 +#endif
23816 +
23817 pgd_ref = pgd_offset_k(address);
23818 if (pgd_none(*pgd_ref))
23819 return -1;
23820 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23821 static int is_errata100(struct pt_regs *regs, unsigned long address)
23822 {
23823 #ifdef CONFIG_X86_64
23824 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23825 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23826 return 1;
23827 #endif
23828 return 0;
23829 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23830 }
23831
23832 static const char nx_warning[] = KERN_CRIT
23833 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23834 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23835
23836 static void
23837 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23838 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23839 if (!oops_may_print())
23840 return;
23841
23842 - if (error_code & PF_INSTR) {
23843 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23844 unsigned int level;
23845
23846 pte_t *pte = lookup_address(address, &level);
23847
23848 if (pte && pte_present(*pte) && !pte_exec(*pte))
23849 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23850 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23851 }
23852
23853 +#ifdef CONFIG_PAX_KERNEXEC
23854 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23855 + if (current->signal->curr_ip)
23856 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23857 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23858 + else
23859 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23860 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23861 + }
23862 +#endif
23863 +
23864 printk(KERN_ALERT "BUG: unable to handle kernel ");
23865 if (address < PAGE_SIZE)
23866 printk(KERN_CONT "NULL pointer dereference");
23867 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23868 }
23869 #endif
23870
23871 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23872 + if (pax_is_fetch_fault(regs, error_code, address)) {
23873 +
23874 +#ifdef CONFIG_PAX_EMUTRAMP
23875 + switch (pax_handle_fetch_fault(regs)) {
23876 + case 2:
23877 + return;
23878 + }
23879 +#endif
23880 +
23881 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23882 + do_group_exit(SIGKILL);
23883 + }
23884 +#endif
23885 +
23886 if (unlikely(show_unhandled_signals))
23887 show_signal_msg(regs, error_code, address, tsk);
23888
23889 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23890 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23891 printk(KERN_ERR
23892 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23893 - tsk->comm, tsk->pid, address);
23894 + tsk->comm, task_pid_nr(tsk), address);
23895 code = BUS_MCEERR_AR;
23896 }
23897 #endif
23898 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23899 return 1;
23900 }
23901
23902 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23903 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23904 +{
23905 + pte_t *pte;
23906 + pmd_t *pmd;
23907 + spinlock_t *ptl;
23908 + unsigned char pte_mask;
23909 +
23910 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23911 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23912 + return 0;
23913 +
23914 + /* PaX: it's our fault, let's handle it if we can */
23915 +
23916 + /* PaX: take a look at read faults before acquiring any locks */
23917 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23918 + /* instruction fetch attempt from a protected page in user mode */
23919 + up_read(&mm->mmap_sem);
23920 +
23921 +#ifdef CONFIG_PAX_EMUTRAMP
23922 + switch (pax_handle_fetch_fault(regs)) {
23923 + case 2:
23924 + return 1;
23925 + }
23926 +#endif
23927 +
23928 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23929 + do_group_exit(SIGKILL);
23930 + }
23931 +
23932 + pmd = pax_get_pmd(mm, address);
23933 + if (unlikely(!pmd))
23934 + return 0;
23935 +
23936 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23937 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23938 + pte_unmap_unlock(pte, ptl);
23939 + return 0;
23940 + }
23941 +
23942 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23943 + /* write attempt to a protected page in user mode */
23944 + pte_unmap_unlock(pte, ptl);
23945 + return 0;
23946 + }
23947 +
23948 +#ifdef CONFIG_SMP
23949 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23950 +#else
23951 + if (likely(address > get_limit(regs->cs)))
23952 +#endif
23953 + {
23954 + set_pte(pte, pte_mkread(*pte));
23955 + __flush_tlb_one(address);
23956 + pte_unmap_unlock(pte, ptl);
23957 + up_read(&mm->mmap_sem);
23958 + return 1;
23959 + }
23960 +
23961 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23962 +
23963 + /*
23964 + * PaX: fill DTLB with user rights and retry
23965 + */
23966 + __asm__ __volatile__ (
23967 + "orb %2,(%1)\n"
23968 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23969 +/*
23970 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23971 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23972 + * page fault when examined during a TLB load attempt. this is true not only
23973 + * for PTEs holding a non-present entry but also present entries that will
23974 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23975 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23976 + * for our target pages since their PTEs are simply not in the TLBs at all.
23977 +
23978 + * the best thing in omitting it is that we gain around 15-20% speed in the
23979 + * fast path of the page fault handler and can get rid of tracing since we
23980 + * can no longer flush unintended entries.
23981 + */
23982 + "invlpg (%0)\n"
23983 +#endif
23984 + __copyuser_seg"testb $0,(%0)\n"
23985 + "xorb %3,(%1)\n"
23986 + :
23987 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23988 + : "memory", "cc");
23989 + pte_unmap_unlock(pte, ptl);
23990 + up_read(&mm->mmap_sem);
23991 + return 1;
23992 +}
23993 +#endif
23994 +
23995 /*
23996 * Handle a spurious fault caused by a stale TLB entry.
23997 *
23998 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23999 static inline int
24000 access_error(unsigned long error_code, struct vm_area_struct *vma)
24001 {
24002 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24003 + return 1;
24004 +
24005 if (error_code & PF_WRITE) {
24006 /* write, present and write, not present: */
24007 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24008 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24009 {
24010 struct vm_area_struct *vma;
24011 struct task_struct *tsk;
24012 - unsigned long address;
24013 struct mm_struct *mm;
24014 int fault;
24015 int write = error_code & PF_WRITE;
24016 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24017 (write ? FAULT_FLAG_WRITE : 0);
24018
24019 - tsk = current;
24020 - mm = tsk->mm;
24021 -
24022 /* Get the faulting address: */
24023 - address = read_cr2();
24024 + unsigned long address = read_cr2();
24025 +
24026 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24027 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24028 + if (!search_exception_tables(regs->ip)) {
24029 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24030 + bad_area_nosemaphore(regs, error_code, address);
24031 + return;
24032 + }
24033 + if (address < PAX_USER_SHADOW_BASE) {
24034 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24035 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24036 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24037 + } else
24038 + address -= PAX_USER_SHADOW_BASE;
24039 + }
24040 +#endif
24041 +
24042 + tsk = current;
24043 + mm = tsk->mm;
24044
24045 /*
24046 * Detect and handle instructions that would cause a page fault for
24047 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24048 * User-mode registers count as a user access even for any
24049 * potential system fault or CPU buglet:
24050 */
24051 - if (user_mode_vm(regs)) {
24052 + if (user_mode(regs)) {
24053 local_irq_enable();
24054 error_code |= PF_USER;
24055 } else {
24056 @@ -1132,6 +1339,11 @@ retry:
24057 might_sleep();
24058 }
24059
24060 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24061 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24062 + return;
24063 +#endif
24064 +
24065 vma = find_vma(mm, address);
24066 if (unlikely(!vma)) {
24067 bad_area(regs, error_code, address);
24068 @@ -1143,18 +1355,24 @@ retry:
24069 bad_area(regs, error_code, address);
24070 return;
24071 }
24072 - if (error_code & PF_USER) {
24073 - /*
24074 - * Accessing the stack below %sp is always a bug.
24075 - * The large cushion allows instructions like enter
24076 - * and pusha to work. ("enter $65535, $31" pushes
24077 - * 32 pointers and then decrements %sp by 65535.)
24078 - */
24079 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24080 - bad_area(regs, error_code, address);
24081 - return;
24082 - }
24083 + /*
24084 + * Accessing the stack below %sp is always a bug.
24085 + * The large cushion allows instructions like enter
24086 + * and pusha to work. ("enter $65535, $31" pushes
24087 + * 32 pointers and then decrements %sp by 65535.)
24088 + */
24089 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24090 + bad_area(regs, error_code, address);
24091 + return;
24092 }
24093 +
24094 +#ifdef CONFIG_PAX_SEGMEXEC
24095 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24096 + bad_area(regs, error_code, address);
24097 + return;
24098 + }
24099 +#endif
24100 +
24101 if (unlikely(expand_stack(vma, address))) {
24102 bad_area(regs, error_code, address);
24103 return;
24104 @@ -1209,3 +1427,292 @@ good_area:
24105
24106 up_read(&mm->mmap_sem);
24107 }
24108 +
24109 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24110 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24111 +{
24112 + struct mm_struct *mm = current->mm;
24113 + unsigned long ip = regs->ip;
24114 +
24115 + if (v8086_mode(regs))
24116 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24117 +
24118 +#ifdef CONFIG_PAX_PAGEEXEC
24119 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24120 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24121 + return true;
24122 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24123 + return true;
24124 + return false;
24125 + }
24126 +#endif
24127 +
24128 +#ifdef CONFIG_PAX_SEGMEXEC
24129 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24130 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24131 + return true;
24132 + return false;
24133 + }
24134 +#endif
24135 +
24136 + return false;
24137 +}
24138 +#endif
24139 +
24140 +#ifdef CONFIG_PAX_EMUTRAMP
24141 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24142 +{
24143 + int err;
24144 +
24145 + do { /* PaX: libffi trampoline emulation */
24146 + unsigned char mov, jmp;
24147 + unsigned int addr1, addr2;
24148 +
24149 +#ifdef CONFIG_X86_64
24150 + if ((regs->ip + 9) >> 32)
24151 + break;
24152 +#endif
24153 +
24154 + err = get_user(mov, (unsigned char __user *)regs->ip);
24155 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24156 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24157 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24158 +
24159 + if (err)
24160 + break;
24161 +
24162 + if (mov == 0xB8 && jmp == 0xE9) {
24163 + regs->ax = addr1;
24164 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24165 + return 2;
24166 + }
24167 + } while (0);
24168 +
24169 + do { /* PaX: gcc trampoline emulation #1 */
24170 + unsigned char mov1, mov2;
24171 + unsigned short jmp;
24172 + unsigned int addr1, addr2;
24173 +
24174 +#ifdef CONFIG_X86_64
24175 + if ((regs->ip + 11) >> 32)
24176 + break;
24177 +#endif
24178 +
24179 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24180 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24181 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24182 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24183 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24184 +
24185 + if (err)
24186 + break;
24187 +
24188 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24189 + regs->cx = addr1;
24190 + regs->ax = addr2;
24191 + regs->ip = addr2;
24192 + return 2;
24193 + }
24194 + } while (0);
24195 +
24196 + do { /* PaX: gcc trampoline emulation #2 */
24197 + unsigned char mov, jmp;
24198 + unsigned int addr1, addr2;
24199 +
24200 +#ifdef CONFIG_X86_64
24201 + if ((regs->ip + 9) >> 32)
24202 + break;
24203 +#endif
24204 +
24205 + err = get_user(mov, (unsigned char __user *)regs->ip);
24206 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24207 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24208 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24209 +
24210 + if (err)
24211 + break;
24212 +
24213 + if (mov == 0xB9 && jmp == 0xE9) {
24214 + regs->cx = addr1;
24215 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24216 + return 2;
24217 + }
24218 + } while (0);
24219 +
24220 + return 1; /* PaX in action */
24221 +}
24222 +
24223 +#ifdef CONFIG_X86_64
24224 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24225 +{
24226 + int err;
24227 +
24228 + do { /* PaX: libffi trampoline emulation */
24229 + unsigned short mov1, mov2, jmp1;
24230 + unsigned char stcclc, jmp2;
24231 + unsigned long addr1, addr2;
24232 +
24233 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24234 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24235 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24236 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24237 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24238 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24239 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24240 +
24241 + if (err)
24242 + break;
24243 +
24244 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24245 + regs->r11 = addr1;
24246 + regs->r10 = addr2;
24247 + if (stcclc == 0xF8)
24248 + regs->flags &= ~X86_EFLAGS_CF;
24249 + else
24250 + regs->flags |= X86_EFLAGS_CF;
24251 + regs->ip = addr1;
24252 + return 2;
24253 + }
24254 + } while (0);
24255 +
24256 + do { /* PaX: gcc trampoline emulation #1 */
24257 + unsigned short mov1, mov2, jmp1;
24258 + unsigned char jmp2;
24259 + unsigned int addr1;
24260 + unsigned long addr2;
24261 +
24262 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24263 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24264 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24265 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24266 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24267 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24268 +
24269 + if (err)
24270 + break;
24271 +
24272 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24273 + regs->r11 = addr1;
24274 + regs->r10 = addr2;
24275 + regs->ip = addr1;
24276 + return 2;
24277 + }
24278 + } while (0);
24279 +
24280 + do { /* PaX: gcc trampoline emulation #2 */
24281 + unsigned short mov1, mov2, jmp1;
24282 + unsigned char jmp2;
24283 + unsigned long addr1, addr2;
24284 +
24285 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24286 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24287 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24288 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24289 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24290 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24291 +
24292 + if (err)
24293 + break;
24294 +
24295 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24296 + regs->r11 = addr1;
24297 + regs->r10 = addr2;
24298 + regs->ip = addr1;
24299 + return 2;
24300 + }
24301 + } while (0);
24302 +
24303 + return 1; /* PaX in action */
24304 +}
24305 +#endif
24306 +
24307 +/*
24308 + * PaX: decide what to do with offenders (regs->ip = fault address)
24309 + *
24310 + * returns 1 when task should be killed
24311 + * 2 when gcc trampoline was detected
24312 + */
24313 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24314 +{
24315 + if (v8086_mode(regs))
24316 + return 1;
24317 +
24318 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24319 + return 1;
24320 +
24321 +#ifdef CONFIG_X86_32
24322 + return pax_handle_fetch_fault_32(regs);
24323 +#else
24324 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24325 + return pax_handle_fetch_fault_32(regs);
24326 + else
24327 + return pax_handle_fetch_fault_64(regs);
24328 +#endif
24329 +}
24330 +#endif
24331 +
24332 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24333 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24334 +{
24335 + long i;
24336 +
24337 + printk(KERN_ERR "PAX: bytes at PC: ");
24338 + for (i = 0; i < 20; i++) {
24339 + unsigned char c;
24340 + if (get_user(c, (unsigned char __force_user *)pc+i))
24341 + printk(KERN_CONT "?? ");
24342 + else
24343 + printk(KERN_CONT "%02x ", c);
24344 + }
24345 + printk("\n");
24346 +
24347 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24348 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24349 + unsigned long c;
24350 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24351 +#ifdef CONFIG_X86_32
24352 + printk(KERN_CONT "???????? ");
24353 +#else
24354 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24355 + printk(KERN_CONT "???????? ???????? ");
24356 + else
24357 + printk(KERN_CONT "???????????????? ");
24358 +#endif
24359 + } else {
24360 +#ifdef CONFIG_X86_64
24361 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24362 + printk(KERN_CONT "%08x ", (unsigned int)c);
24363 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24364 + } else
24365 +#endif
24366 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24367 + }
24368 + }
24369 + printk("\n");
24370 +}
24371 +#endif
24372 +
24373 +/**
24374 + * probe_kernel_write(): safely attempt to write to a location
24375 + * @dst: address to write to
24376 + * @src: pointer to the data that shall be written
24377 + * @size: size of the data chunk
24378 + *
24379 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24380 + * happens, handle that and return -EFAULT.
24381 + */
24382 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24383 +{
24384 + long ret;
24385 + mm_segment_t old_fs = get_fs();
24386 +
24387 + set_fs(KERNEL_DS);
24388 + pagefault_disable();
24389 + pax_open_kernel();
24390 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24391 + pax_close_kernel();
24392 + pagefault_enable();
24393 + set_fs(old_fs);
24394 +
24395 + return ret ? -EFAULT : 0;
24396 +}
24397 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24398 index dd74e46..7d26398 100644
24399 --- a/arch/x86/mm/gup.c
24400 +++ b/arch/x86/mm/gup.c
24401 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24402 addr = start;
24403 len = (unsigned long) nr_pages << PAGE_SHIFT;
24404 end = start + len;
24405 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24406 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24407 (void __user *)start, len)))
24408 return 0;
24409
24410 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24411 index 6f31ee5..8ee4164 100644
24412 --- a/arch/x86/mm/highmem_32.c
24413 +++ b/arch/x86/mm/highmem_32.c
24414 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24415 idx = type + KM_TYPE_NR*smp_processor_id();
24416 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24417 BUG_ON(!pte_none(*(kmap_pte-idx)));
24418 +
24419 + pax_open_kernel();
24420 set_pte(kmap_pte-idx, mk_pte(page, prot));
24421 + pax_close_kernel();
24422 +
24423 arch_flush_lazy_mmu_mode();
24424
24425 return (void *)vaddr;
24426 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24427 index b91e485..d00e7c9 100644
24428 --- a/arch/x86/mm/hugetlbpage.c
24429 +++ b/arch/x86/mm/hugetlbpage.c
24430 @@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24431 struct hstate *h = hstate_file(file);
24432 struct mm_struct *mm = current->mm;
24433 struct vm_area_struct *vma;
24434 - unsigned long start_addr;
24435 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24436 +
24437 +#ifdef CONFIG_PAX_SEGMEXEC
24438 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24439 + pax_task_size = SEGMEXEC_TASK_SIZE;
24440 +#endif
24441 +
24442 + pax_task_size -= PAGE_SIZE;
24443
24444 if (len > mm->cached_hole_size) {
24445 - start_addr = mm->free_area_cache;
24446 + start_addr = mm->free_area_cache;
24447 } else {
24448 - start_addr = TASK_UNMAPPED_BASE;
24449 - mm->cached_hole_size = 0;
24450 + start_addr = mm->mmap_base;
24451 + mm->cached_hole_size = 0;
24452 }
24453
24454 full_search:
24455 @@ -291,26 +298,27 @@ full_search:
24456
24457 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24458 /* At this point: (!vma || addr < vma->vm_end). */
24459 - if (TASK_SIZE - len < addr) {
24460 + if (pax_task_size - len < addr) {
24461 /*
24462 * Start a new search - just in case we missed
24463 * some holes.
24464 */
24465 - if (start_addr != TASK_UNMAPPED_BASE) {
24466 - start_addr = TASK_UNMAPPED_BASE;
24467 + if (start_addr != mm->mmap_base) {
24468 + start_addr = mm->mmap_base;
24469 mm->cached_hole_size = 0;
24470 goto full_search;
24471 }
24472 return -ENOMEM;
24473 }
24474 - if (!vma || addr + len <= vma->vm_start) {
24475 - mm->free_area_cache = addr + len;
24476 - return addr;
24477 - }
24478 + if (check_heap_stack_gap(vma, addr, len))
24479 + break;
24480 if (addr + mm->cached_hole_size < vma->vm_start)
24481 mm->cached_hole_size = vma->vm_start - addr;
24482 addr = ALIGN(vma->vm_end, huge_page_size(h));
24483 }
24484 +
24485 + mm->free_area_cache = addr + len;
24486 + return addr;
24487 }
24488
24489 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24490 @@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24491 struct mm_struct *mm = current->mm;
24492 struct vm_area_struct *vma;
24493 unsigned long base = mm->mmap_base;
24494 - unsigned long addr = addr0;
24495 + unsigned long addr;
24496 unsigned long largest_hole = mm->cached_hole_size;
24497 - unsigned long start_addr;
24498
24499 /* don't allow allocations above current base */
24500 if (mm->free_area_cache > base)
24501 @@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24502 largest_hole = 0;
24503 mm->free_area_cache = base;
24504 }
24505 -try_again:
24506 - start_addr = mm->free_area_cache;
24507
24508 /* make sure it can fit in the remaining address space */
24509 if (mm->free_area_cache < len)
24510 goto fail;
24511
24512 /* either no address requested or can't fit in requested address hole */
24513 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24514 + addr = mm->free_area_cache - len;
24515 do {
24516 + addr &= huge_page_mask(h);
24517 /*
24518 * Lookup failure means no vma is above this address,
24519 * i.e. return with success:
24520 @@ -351,10 +357,10 @@ try_again:
24521 if (!vma)
24522 return addr;
24523
24524 - if (addr + len <= vma->vm_start) {
24525 + if (check_heap_stack_gap(vma, addr, len)) {
24526 /* remember the address as a hint for next time */
24527 - mm->cached_hole_size = largest_hole;
24528 - return (mm->free_area_cache = addr);
24529 + mm->cached_hole_size = largest_hole;
24530 + return (mm->free_area_cache = addr);
24531 } else if (mm->free_area_cache == vma->vm_end) {
24532 /* pull free_area_cache down to the first hole */
24533 mm->free_area_cache = vma->vm_start;
24534 @@ -363,29 +369,34 @@ try_again:
24535
24536 /* remember the largest hole we saw so far */
24537 if (addr + largest_hole < vma->vm_start)
24538 - largest_hole = vma->vm_start - addr;
24539 + largest_hole = vma->vm_start - addr;
24540
24541 /* try just below the current vma->vm_start */
24542 - addr = (vma->vm_start - len) & huge_page_mask(h);
24543 - } while (len <= vma->vm_start);
24544 + addr = skip_heap_stack_gap(vma, len);
24545 + } while (!IS_ERR_VALUE(addr));
24546
24547 fail:
24548 /*
24549 - * if hint left us with no space for the requested
24550 - * mapping then try again:
24551 - */
24552 - if (start_addr != base) {
24553 - mm->free_area_cache = base;
24554 - largest_hole = 0;
24555 - goto try_again;
24556 - }
24557 - /*
24558 * A failed mmap() very likely causes application failure,
24559 * so fall back to the bottom-up function here. This scenario
24560 * can happen with large stack limits and large mmap()
24561 * allocations.
24562 */
24563 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24564 +
24565 +#ifdef CONFIG_PAX_SEGMEXEC
24566 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24567 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24568 + else
24569 +#endif
24570 +
24571 + mm->mmap_base = TASK_UNMAPPED_BASE;
24572 +
24573 +#ifdef CONFIG_PAX_RANDMMAP
24574 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24575 + mm->mmap_base += mm->delta_mmap;
24576 +#endif
24577 +
24578 + mm->free_area_cache = mm->mmap_base;
24579 mm->cached_hole_size = ~0UL;
24580 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24581 len, pgoff, flags);
24582 @@ -393,6 +404,7 @@ fail:
24583 /*
24584 * Restore the topdown base:
24585 */
24586 + mm->mmap_base = base;
24587 mm->free_area_cache = base;
24588 mm->cached_hole_size = ~0UL;
24589
24590 @@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24591 struct hstate *h = hstate_file(file);
24592 struct mm_struct *mm = current->mm;
24593 struct vm_area_struct *vma;
24594 + unsigned long pax_task_size = TASK_SIZE;
24595
24596 if (len & ~huge_page_mask(h))
24597 return -EINVAL;
24598 - if (len > TASK_SIZE)
24599 +
24600 +#ifdef CONFIG_PAX_SEGMEXEC
24601 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24602 + pax_task_size = SEGMEXEC_TASK_SIZE;
24603 +#endif
24604 +
24605 + pax_task_size -= PAGE_SIZE;
24606 +
24607 + if (len > pax_task_size)
24608 return -ENOMEM;
24609
24610 if (flags & MAP_FIXED) {
24611 @@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24612 if (addr) {
24613 addr = ALIGN(addr, huge_page_size(h));
24614 vma = find_vma(mm, addr);
24615 - if (TASK_SIZE - len >= addr &&
24616 - (!vma || addr + len <= vma->vm_start))
24617 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24618 return addr;
24619 }
24620 if (mm->get_unmapped_area == arch_get_unmapped_area)
24621 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24622 index d7aea41..0fc945b 100644
24623 --- a/arch/x86/mm/init.c
24624 +++ b/arch/x86/mm/init.c
24625 @@ -4,6 +4,7 @@
24626 #include <linux/swap.h>
24627 #include <linux/memblock.h>
24628 #include <linux/bootmem.h> /* for max_low_pfn */
24629 +#include <linux/tboot.h>
24630
24631 #include <asm/cacheflush.h>
24632 #include <asm/e820.h>
24633 @@ -16,6 +17,8 @@
24634 #include <asm/tlb.h>
24635 #include <asm/proto.h>
24636 #include <asm/dma.h> /* for MAX_DMA_PFN */
24637 +#include <asm/desc.h>
24638 +#include <asm/bios_ebda.h>
24639
24640 unsigned long __initdata pgt_buf_start;
24641 unsigned long __meminitdata pgt_buf_end;
24642 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24643 {
24644 int i;
24645 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24646 - unsigned long start = 0, good_end;
24647 + unsigned long start = 0x100000, good_end;
24648 phys_addr_t base;
24649
24650 for (i = 0; i < nr_range; i++) {
24651 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24652 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24653 * mmio resources as well as potential bios/acpi data regions.
24654 */
24655 +
24656 +#ifdef CONFIG_GRKERNSEC_KMEM
24657 +static unsigned int ebda_start __read_only;
24658 +static unsigned int ebda_end __read_only;
24659 +#endif
24660 +
24661 int devmem_is_allowed(unsigned long pagenr)
24662 {
24663 - if (pagenr < 256)
24664 +#ifdef CONFIG_GRKERNSEC_KMEM
24665 + /* allow BDA */
24666 + if (!pagenr)
24667 return 1;
24668 + /* allow EBDA */
24669 + if (pagenr >= ebda_start && pagenr < ebda_end)
24670 + return 1;
24671 + /* if tboot is in use, allow access to its hardcoded serial log range */
24672 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
24673 + return 1;
24674 +#else
24675 + if (!pagenr)
24676 + return 1;
24677 +#ifdef CONFIG_VM86
24678 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24679 + return 1;
24680 +#endif
24681 +#endif
24682 +
24683 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24684 + return 1;
24685 +#ifdef CONFIG_GRKERNSEC_KMEM
24686 + /* throw out everything else below 1MB */
24687 + if (pagenr <= 256)
24688 + return 0;
24689 +#endif
24690 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24691 return 0;
24692 if (!page_is_ram(pagenr))
24693 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24694 #endif
24695 }
24696
24697 +#ifdef CONFIG_GRKERNSEC_KMEM
24698 +static inline void gr_init_ebda(void)
24699 +{
24700 + unsigned int ebda_addr;
24701 + unsigned int ebda_size = 0;
24702 +
24703 + ebda_addr = get_bios_ebda();
24704 + if (ebda_addr) {
24705 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24706 + ebda_size <<= 10;
24707 + }
24708 + if (ebda_addr && ebda_size) {
24709 + ebda_start = ebda_addr >> PAGE_SHIFT;
24710 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24711 + } else {
24712 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24713 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24714 + }
24715 +}
24716 +#else
24717 +static inline void gr_init_ebda(void) { }
24718 +#endif
24719 +
24720 void free_initmem(void)
24721 {
24722 +#ifdef CONFIG_PAX_KERNEXEC
24723 +#ifdef CONFIG_X86_32
24724 + /* PaX: limit KERNEL_CS to actual size */
24725 + unsigned long addr, limit;
24726 + struct desc_struct d;
24727 + int cpu;
24728 +#else
24729 + pgd_t *pgd;
24730 + pud_t *pud;
24731 + pmd_t *pmd;
24732 + unsigned long addr, end;
24733 +#endif
24734 +#endif
24735 +
24736 + gr_init_ebda();
24737 +
24738 +#ifdef CONFIG_PAX_KERNEXEC
24739 +#ifdef CONFIG_X86_32
24740 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24741 + limit = (limit - 1UL) >> PAGE_SHIFT;
24742 +
24743 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24744 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24745 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24746 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24747 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24748 + }
24749 +
24750 + /* PaX: make KERNEL_CS read-only */
24751 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24752 + if (!paravirt_enabled())
24753 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24754 +/*
24755 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24756 + pgd = pgd_offset_k(addr);
24757 + pud = pud_offset(pgd, addr);
24758 + pmd = pmd_offset(pud, addr);
24759 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24760 + }
24761 +*/
24762 +#ifdef CONFIG_X86_PAE
24763 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24764 +/*
24765 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24766 + pgd = pgd_offset_k(addr);
24767 + pud = pud_offset(pgd, addr);
24768 + pmd = pmd_offset(pud, addr);
24769 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24770 + }
24771 +*/
24772 +#endif
24773 +
24774 +#ifdef CONFIG_MODULES
24775 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24776 +#endif
24777 +
24778 +#else
24779 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24780 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24781 + pgd = pgd_offset_k(addr);
24782 + pud = pud_offset(pgd, addr);
24783 + pmd = pmd_offset(pud, addr);
24784 + if (!pmd_present(*pmd))
24785 + continue;
24786 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24787 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24788 + else
24789 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24790 + }
24791 +
24792 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24793 + end = addr + KERNEL_IMAGE_SIZE;
24794 + for (; addr < end; addr += PMD_SIZE) {
24795 + pgd = pgd_offset_k(addr);
24796 + pud = pud_offset(pgd, addr);
24797 + pmd = pmd_offset(pud, addr);
24798 + if (!pmd_present(*pmd))
24799 + continue;
24800 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24801 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24802 + }
24803 +#endif
24804 +
24805 + flush_tlb_all();
24806 +#endif
24807 +
24808 free_init_pages("unused kernel memory",
24809 (unsigned long)(&__init_begin),
24810 (unsigned long)(&__init_end));
24811 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24812 index 575d86f..4987469 100644
24813 --- a/arch/x86/mm/init_32.c
24814 +++ b/arch/x86/mm/init_32.c
24815 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24816 }
24817
24818 /*
24819 - * Creates a middle page table and puts a pointer to it in the
24820 - * given global directory entry. This only returns the gd entry
24821 - * in non-PAE compilation mode, since the middle layer is folded.
24822 - */
24823 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24824 -{
24825 - pud_t *pud;
24826 - pmd_t *pmd_table;
24827 -
24828 -#ifdef CONFIG_X86_PAE
24829 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24830 - if (after_bootmem)
24831 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24832 - else
24833 - pmd_table = (pmd_t *)alloc_low_page();
24834 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24835 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24836 - pud = pud_offset(pgd, 0);
24837 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24838 -
24839 - return pmd_table;
24840 - }
24841 -#endif
24842 - pud = pud_offset(pgd, 0);
24843 - pmd_table = pmd_offset(pud, 0);
24844 -
24845 - return pmd_table;
24846 -}
24847 -
24848 -/*
24849 * Create a page table and place a pointer to it in a middle page
24850 * directory entry:
24851 */
24852 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24853 page_table = (pte_t *)alloc_low_page();
24854
24855 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24856 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24857 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24858 +#else
24859 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24860 +#endif
24861 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24862 }
24863
24864 return pte_offset_kernel(pmd, 0);
24865 }
24866
24867 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24868 +{
24869 + pud_t *pud;
24870 + pmd_t *pmd_table;
24871 +
24872 + pud = pud_offset(pgd, 0);
24873 + pmd_table = pmd_offset(pud, 0);
24874 +
24875 + return pmd_table;
24876 +}
24877 +
24878 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24879 {
24880 int pgd_idx = pgd_index(vaddr);
24881 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24882 int pgd_idx, pmd_idx;
24883 unsigned long vaddr;
24884 pgd_t *pgd;
24885 + pud_t *pud;
24886 pmd_t *pmd;
24887 pte_t *pte = NULL;
24888
24889 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24890 pgd = pgd_base + pgd_idx;
24891
24892 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24893 - pmd = one_md_table_init(pgd);
24894 - pmd = pmd + pmd_index(vaddr);
24895 + pud = pud_offset(pgd, vaddr);
24896 + pmd = pmd_offset(pud, vaddr);
24897 +
24898 +#ifdef CONFIG_X86_PAE
24899 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24900 +#endif
24901 +
24902 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24903 pmd++, pmd_idx++) {
24904 pte = page_table_kmap_check(one_page_table_init(pmd),
24905 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24906 }
24907 }
24908
24909 -static inline int is_kernel_text(unsigned long addr)
24910 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24911 {
24912 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24913 - return 1;
24914 - return 0;
24915 + if ((start > ktla_ktva((unsigned long)_etext) ||
24916 + end <= ktla_ktva((unsigned long)_stext)) &&
24917 + (start > ktla_ktva((unsigned long)_einittext) ||
24918 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24919 +
24920 +#ifdef CONFIG_ACPI_SLEEP
24921 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24922 +#endif
24923 +
24924 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24925 + return 0;
24926 + return 1;
24927 }
24928
24929 /*
24930 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24931 unsigned long last_map_addr = end;
24932 unsigned long start_pfn, end_pfn;
24933 pgd_t *pgd_base = swapper_pg_dir;
24934 - int pgd_idx, pmd_idx, pte_ofs;
24935 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24936 unsigned long pfn;
24937 pgd_t *pgd;
24938 + pud_t *pud;
24939 pmd_t *pmd;
24940 pte_t *pte;
24941 unsigned pages_2m, pages_4k;
24942 @@ -280,8 +281,13 @@ repeat:
24943 pfn = start_pfn;
24944 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24945 pgd = pgd_base + pgd_idx;
24946 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24947 - pmd = one_md_table_init(pgd);
24948 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24949 + pud = pud_offset(pgd, 0);
24950 + pmd = pmd_offset(pud, 0);
24951 +
24952 +#ifdef CONFIG_X86_PAE
24953 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24954 +#endif
24955
24956 if (pfn >= end_pfn)
24957 continue;
24958 @@ -293,14 +299,13 @@ repeat:
24959 #endif
24960 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24961 pmd++, pmd_idx++) {
24962 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24963 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24964
24965 /*
24966 * Map with big pages if possible, otherwise
24967 * create normal page tables:
24968 */
24969 if (use_pse) {
24970 - unsigned int addr2;
24971 pgprot_t prot = PAGE_KERNEL_LARGE;
24972 /*
24973 * first pass will use the same initial
24974 @@ -310,11 +315,7 @@ repeat:
24975 __pgprot(PTE_IDENT_ATTR |
24976 _PAGE_PSE);
24977
24978 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24979 - PAGE_OFFSET + PAGE_SIZE-1;
24980 -
24981 - if (is_kernel_text(addr) ||
24982 - is_kernel_text(addr2))
24983 + if (is_kernel_text(address, address + PMD_SIZE))
24984 prot = PAGE_KERNEL_LARGE_EXEC;
24985
24986 pages_2m++;
24987 @@ -331,7 +332,7 @@ repeat:
24988 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24989 pte += pte_ofs;
24990 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24991 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24992 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24993 pgprot_t prot = PAGE_KERNEL;
24994 /*
24995 * first pass will use the same initial
24996 @@ -339,7 +340,7 @@ repeat:
24997 */
24998 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24999
25000 - if (is_kernel_text(addr))
25001 + if (is_kernel_text(address, address + PAGE_SIZE))
25002 prot = PAGE_KERNEL_EXEC;
25003
25004 pages_4k++;
25005 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25006
25007 pud = pud_offset(pgd, va);
25008 pmd = pmd_offset(pud, va);
25009 - if (!pmd_present(*pmd))
25010 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
25011 break;
25012
25013 pte = pte_offset_kernel(pmd, va);
25014 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
25015
25016 static void __init pagetable_init(void)
25017 {
25018 - pgd_t *pgd_base = swapper_pg_dir;
25019 -
25020 - permanent_kmaps_init(pgd_base);
25021 + permanent_kmaps_init(swapper_pg_dir);
25022 }
25023
25024 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25025 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25026 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25027
25028 /* user-defined highmem size */
25029 @@ -734,6 +733,12 @@ void __init mem_init(void)
25030
25031 pci_iommu_alloc();
25032
25033 +#ifdef CONFIG_PAX_PER_CPU_PGD
25034 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25035 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25036 + KERNEL_PGD_PTRS);
25037 +#endif
25038 +
25039 #ifdef CONFIG_FLATMEM
25040 BUG_ON(!mem_map);
25041 #endif
25042 @@ -760,7 +765,7 @@ void __init mem_init(void)
25043 reservedpages++;
25044
25045 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25046 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25047 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25048 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25049
25050 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25051 @@ -801,10 +806,10 @@ void __init mem_init(void)
25052 ((unsigned long)&__init_end -
25053 (unsigned long)&__init_begin) >> 10,
25054
25055 - (unsigned long)&_etext, (unsigned long)&_edata,
25056 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25057 + (unsigned long)&_sdata, (unsigned long)&_edata,
25058 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25059
25060 - (unsigned long)&_text, (unsigned long)&_etext,
25061 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25062 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25063
25064 /*
25065 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25066 if (!kernel_set_to_readonly)
25067 return;
25068
25069 + start = ktla_ktva(start);
25070 pr_debug("Set kernel text: %lx - %lx for read write\n",
25071 start, start+size);
25072
25073 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25074 if (!kernel_set_to_readonly)
25075 return;
25076
25077 + start = ktla_ktva(start);
25078 pr_debug("Set kernel text: %lx - %lx for read only\n",
25079 start, start+size);
25080
25081 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25082 unsigned long start = PFN_ALIGN(_text);
25083 unsigned long size = PFN_ALIGN(_etext) - start;
25084
25085 + start = ktla_ktva(start);
25086 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25087 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25088 size >> 10);
25089 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25090 index 3baff25..8b37564 100644
25091 --- a/arch/x86/mm/init_64.c
25092 +++ b/arch/x86/mm/init_64.c
25093 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25094 * around without checking the pgd every time.
25095 */
25096
25097 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25098 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25099 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25100
25101 int force_personality32;
25102 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25103
25104 for (address = start; address <= end; address += PGDIR_SIZE) {
25105 const pgd_t *pgd_ref = pgd_offset_k(address);
25106 +
25107 +#ifdef CONFIG_PAX_PER_CPU_PGD
25108 + unsigned long cpu;
25109 +#else
25110 struct page *page;
25111 +#endif
25112
25113 if (pgd_none(*pgd_ref))
25114 continue;
25115
25116 spin_lock(&pgd_lock);
25117 +
25118 +#ifdef CONFIG_PAX_PER_CPU_PGD
25119 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25120 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25121 +#else
25122 list_for_each_entry(page, &pgd_list, lru) {
25123 pgd_t *pgd;
25124 spinlock_t *pgt_lock;
25125 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25126 /* the pgt_lock only for Xen */
25127 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25128 spin_lock(pgt_lock);
25129 +#endif
25130
25131 if (pgd_none(*pgd))
25132 set_pgd(pgd, *pgd_ref);
25133 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25134 BUG_ON(pgd_page_vaddr(*pgd)
25135 != pgd_page_vaddr(*pgd_ref));
25136
25137 +#ifndef CONFIG_PAX_PER_CPU_PGD
25138 spin_unlock(pgt_lock);
25139 +#endif
25140 +
25141 }
25142 spin_unlock(&pgd_lock);
25143 }
25144 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25145 {
25146 if (pgd_none(*pgd)) {
25147 pud_t *pud = (pud_t *)spp_getpage();
25148 - pgd_populate(&init_mm, pgd, pud);
25149 + pgd_populate_kernel(&init_mm, pgd, pud);
25150 if (pud != pud_offset(pgd, 0))
25151 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25152 pud, pud_offset(pgd, 0));
25153 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25154 {
25155 if (pud_none(*pud)) {
25156 pmd_t *pmd = (pmd_t *) spp_getpage();
25157 - pud_populate(&init_mm, pud, pmd);
25158 + pud_populate_kernel(&init_mm, pud, pmd);
25159 if (pmd != pmd_offset(pud, 0))
25160 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25161 pmd, pmd_offset(pud, 0));
25162 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25163 pmd = fill_pmd(pud, vaddr);
25164 pte = fill_pte(pmd, vaddr);
25165
25166 + pax_open_kernel();
25167 set_pte(pte, new_pte);
25168 + pax_close_kernel();
25169
25170 /*
25171 * It's enough to flush this one mapping.
25172 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25173 pgd = pgd_offset_k((unsigned long)__va(phys));
25174 if (pgd_none(*pgd)) {
25175 pud = (pud_t *) spp_getpage();
25176 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25177 - _PAGE_USER));
25178 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25179 }
25180 pud = pud_offset(pgd, (unsigned long)__va(phys));
25181 if (pud_none(*pud)) {
25182 pmd = (pmd_t *) spp_getpage();
25183 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25184 - _PAGE_USER));
25185 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25186 }
25187 pmd = pmd_offset(pud, phys);
25188 BUG_ON(!pmd_none(*pmd));
25189 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25190 if (pfn >= pgt_buf_top)
25191 panic("alloc_low_page: ran out of memory");
25192
25193 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25194 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25195 clear_page(adr);
25196 *phys = pfn * PAGE_SIZE;
25197 return adr;
25198 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25199
25200 phys = __pa(virt);
25201 left = phys & (PAGE_SIZE - 1);
25202 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25203 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25204 adr = (void *)(((unsigned long)adr) | left);
25205
25206 return adr;
25207 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25208 unmap_low_page(pmd);
25209
25210 spin_lock(&init_mm.page_table_lock);
25211 - pud_populate(&init_mm, pud, __va(pmd_phys));
25212 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25213 spin_unlock(&init_mm.page_table_lock);
25214 }
25215 __flush_tlb_all();
25216 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25217 unmap_low_page(pud);
25218
25219 spin_lock(&init_mm.page_table_lock);
25220 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25221 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25222 spin_unlock(&init_mm.page_table_lock);
25223 pgd_changed = true;
25224 }
25225 @@ -691,6 +705,12 @@ void __init mem_init(void)
25226
25227 pci_iommu_alloc();
25228
25229 +#ifdef CONFIG_PAX_PER_CPU_PGD
25230 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25231 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25232 + KERNEL_PGD_PTRS);
25233 +#endif
25234 +
25235 /* clear_bss() already clear the empty_zero_page */
25236
25237 reservedpages = 0;
25238 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25239 static struct vm_area_struct gate_vma = {
25240 .vm_start = VSYSCALL_START,
25241 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25242 - .vm_page_prot = PAGE_READONLY_EXEC,
25243 - .vm_flags = VM_READ | VM_EXEC
25244 + .vm_page_prot = PAGE_READONLY,
25245 + .vm_flags = VM_READ
25246 };
25247
25248 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25249 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25250
25251 const char *arch_vma_name(struct vm_area_struct *vma)
25252 {
25253 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25254 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25255 return "[vdso]";
25256 if (vma == &gate_vma)
25257 return "[vsyscall]";
25258 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25259 index 7b179b4..6bd1777 100644
25260 --- a/arch/x86/mm/iomap_32.c
25261 +++ b/arch/x86/mm/iomap_32.c
25262 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25263 type = kmap_atomic_idx_push();
25264 idx = type + KM_TYPE_NR * smp_processor_id();
25265 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25266 +
25267 + pax_open_kernel();
25268 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25269 + pax_close_kernel();
25270 +
25271 arch_flush_lazy_mmu_mode();
25272
25273 return (void *)vaddr;
25274 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25275 index 78fe3f1..8293b6f 100644
25276 --- a/arch/x86/mm/ioremap.c
25277 +++ b/arch/x86/mm/ioremap.c
25278 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25279 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25280 int is_ram = page_is_ram(pfn);
25281
25282 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25283 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25284 return NULL;
25285 WARN_ON_ONCE(is_ram);
25286 }
25287 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25288
25289 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25290 if (page_is_ram(start >> PAGE_SHIFT))
25291 +#ifdef CONFIG_HIGHMEM
25292 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25293 +#endif
25294 return __va(phys);
25295
25296 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25297 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25298 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25299
25300 static __initdata int after_paging_init;
25301 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25302 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25303
25304 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25305 {
25306 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25307 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25308
25309 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25310 - memset(bm_pte, 0, sizeof(bm_pte));
25311 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25312 + pmd_populate_user(&init_mm, pmd, bm_pte);
25313
25314 /*
25315 * The boot-ioremap range spans multiple pmds, for which
25316 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25317 index d87dd6d..bf3fa66 100644
25318 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25319 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25320 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25321 * memory (e.g. tracked pages)? For now, we need this to avoid
25322 * invoking kmemcheck for PnP BIOS calls.
25323 */
25324 - if (regs->flags & X86_VM_MASK)
25325 + if (v8086_mode(regs))
25326 return false;
25327 - if (regs->cs != __KERNEL_CS)
25328 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25329 return false;
25330
25331 pte = kmemcheck_pte_lookup(address);
25332 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25333 index 845df68..1d8d29f 100644
25334 --- a/arch/x86/mm/mmap.c
25335 +++ b/arch/x86/mm/mmap.c
25336 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25337 * Leave an at least ~128 MB hole with possible stack randomization.
25338 */
25339 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25340 -#define MAX_GAP (TASK_SIZE/6*5)
25341 +#define MAX_GAP (pax_task_size/6*5)
25342
25343 static int mmap_is_legacy(void)
25344 {
25345 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25346 return rnd << PAGE_SHIFT;
25347 }
25348
25349 -static unsigned long mmap_base(void)
25350 +static unsigned long mmap_base(struct mm_struct *mm)
25351 {
25352 unsigned long gap = rlimit(RLIMIT_STACK);
25353 + unsigned long pax_task_size = TASK_SIZE;
25354 +
25355 +#ifdef CONFIG_PAX_SEGMEXEC
25356 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25357 + pax_task_size = SEGMEXEC_TASK_SIZE;
25358 +#endif
25359
25360 if (gap < MIN_GAP)
25361 gap = MIN_GAP;
25362 else if (gap > MAX_GAP)
25363 gap = MAX_GAP;
25364
25365 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25366 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25367 }
25368
25369 /*
25370 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25371 * does, but not when emulating X86_32
25372 */
25373 -static unsigned long mmap_legacy_base(void)
25374 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25375 {
25376 - if (mmap_is_ia32())
25377 + if (mmap_is_ia32()) {
25378 +
25379 +#ifdef CONFIG_PAX_SEGMEXEC
25380 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25381 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25382 + else
25383 +#endif
25384 +
25385 return TASK_UNMAPPED_BASE;
25386 - else
25387 + } else
25388 return TASK_UNMAPPED_BASE + mmap_rnd();
25389 }
25390
25391 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25392 void arch_pick_mmap_layout(struct mm_struct *mm)
25393 {
25394 if (mmap_is_legacy()) {
25395 - mm->mmap_base = mmap_legacy_base();
25396 + mm->mmap_base = mmap_legacy_base(mm);
25397 +
25398 +#ifdef CONFIG_PAX_RANDMMAP
25399 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25400 + mm->mmap_base += mm->delta_mmap;
25401 +#endif
25402 +
25403 mm->get_unmapped_area = arch_get_unmapped_area;
25404 mm->unmap_area = arch_unmap_area;
25405 } else {
25406 - mm->mmap_base = mmap_base();
25407 + mm->mmap_base = mmap_base(mm);
25408 +
25409 +#ifdef CONFIG_PAX_RANDMMAP
25410 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25411 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25412 +#endif
25413 +
25414 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25415 mm->unmap_area = arch_unmap_area_topdown;
25416 }
25417 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25418 index dc0b727..dc9d71a 100644
25419 --- a/arch/x86/mm/mmio-mod.c
25420 +++ b/arch/x86/mm/mmio-mod.c
25421 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25422 break;
25423 default:
25424 {
25425 - unsigned char *ip = (unsigned char *)instptr;
25426 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25427 my_trace->opcode = MMIO_UNKNOWN_OP;
25428 my_trace->width = 0;
25429 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25430 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25431 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25432 void __iomem *addr)
25433 {
25434 - static atomic_t next_id;
25435 + static atomic_unchecked_t next_id;
25436 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25437 /* These are page-unaligned. */
25438 struct mmiotrace_map map = {
25439 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25440 .private = trace
25441 },
25442 .phys = offset,
25443 - .id = atomic_inc_return(&next_id)
25444 + .id = atomic_inc_return_unchecked(&next_id)
25445 };
25446 map.map_id = trace->id;
25447
25448 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25449 index b008656..773eac2 100644
25450 --- a/arch/x86/mm/pageattr-test.c
25451 +++ b/arch/x86/mm/pageattr-test.c
25452 @@ -36,7 +36,7 @@ enum {
25453
25454 static int pte_testbit(pte_t pte)
25455 {
25456 - return pte_flags(pte) & _PAGE_UNUSED1;
25457 + return pte_flags(pte) & _PAGE_CPA_TEST;
25458 }
25459
25460 struct split_state {
25461 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25462 index a718e0d..45efc32 100644
25463 --- a/arch/x86/mm/pageattr.c
25464 +++ b/arch/x86/mm/pageattr.c
25465 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25466 */
25467 #ifdef CONFIG_PCI_BIOS
25468 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25469 - pgprot_val(forbidden) |= _PAGE_NX;
25470 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25471 #endif
25472
25473 /*
25474 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25475 * Does not cover __inittext since that is gone later on. On
25476 * 64bit we do not enforce !NX on the low mapping
25477 */
25478 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25479 - pgprot_val(forbidden) |= _PAGE_NX;
25480 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25481 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25482
25483 +#ifdef CONFIG_DEBUG_RODATA
25484 /*
25485 * The .rodata section needs to be read-only. Using the pfn
25486 * catches all aliases.
25487 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25488 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25489 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25490 pgprot_val(forbidden) |= _PAGE_RW;
25491 +#endif
25492
25493 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25494 /*
25495 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25496 }
25497 #endif
25498
25499 +#ifdef CONFIG_PAX_KERNEXEC
25500 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25501 + pgprot_val(forbidden) |= _PAGE_RW;
25502 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25503 + }
25504 +#endif
25505 +
25506 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25507
25508 return prot;
25509 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25510 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25511 {
25512 /* change init_mm */
25513 + pax_open_kernel();
25514 set_pte_atomic(kpte, pte);
25515 +
25516 #ifdef CONFIG_X86_32
25517 if (!SHARED_KERNEL_PMD) {
25518 +
25519 +#ifdef CONFIG_PAX_PER_CPU_PGD
25520 + unsigned long cpu;
25521 +#else
25522 struct page *page;
25523 +#endif
25524
25525 +#ifdef CONFIG_PAX_PER_CPU_PGD
25526 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25527 + pgd_t *pgd = get_cpu_pgd(cpu);
25528 +#else
25529 list_for_each_entry(page, &pgd_list, lru) {
25530 - pgd_t *pgd;
25531 + pgd_t *pgd = (pgd_t *)page_address(page);
25532 +#endif
25533 +
25534 pud_t *pud;
25535 pmd_t *pmd;
25536
25537 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25538 + pgd += pgd_index(address);
25539 pud = pud_offset(pgd, address);
25540 pmd = pmd_offset(pud, address);
25541 set_pte_atomic((pte_t *)pmd, pte);
25542 }
25543 }
25544 #endif
25545 + pax_close_kernel();
25546 }
25547
25548 static int
25549 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25550 index 3d68ef6..7f69136 100644
25551 --- a/arch/x86/mm/pat.c
25552 +++ b/arch/x86/mm/pat.c
25553 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25554
25555 if (!entry) {
25556 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25557 - current->comm, current->pid, start, end - 1);
25558 + current->comm, task_pid_nr(current), start, end - 1);
25559 return -EINVAL;
25560 }
25561
25562 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25563
25564 while (cursor < to) {
25565 if (!devmem_is_allowed(pfn)) {
25566 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25567 - current->comm, from, to - 1);
25568 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25569 + current->comm, from, to - 1, cursor);
25570 return 0;
25571 }
25572 cursor += PAGE_SIZE;
25573 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25574 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25575 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25576 "for [mem %#010Lx-%#010Lx]\n",
25577 - current->comm, current->pid,
25578 + current->comm, task_pid_nr(current),
25579 cattr_name(flags),
25580 base, (unsigned long long)(base + size-1));
25581 return -EINVAL;
25582 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25583 flags = lookup_memtype(paddr);
25584 if (want_flags != flags) {
25585 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25586 - current->comm, current->pid,
25587 + current->comm, task_pid_nr(current),
25588 cattr_name(want_flags),
25589 (unsigned long long)paddr,
25590 (unsigned long long)(paddr + size - 1),
25591 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25592 free_memtype(paddr, paddr + size);
25593 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25594 " for [mem %#010Lx-%#010Lx], got %s\n",
25595 - current->comm, current->pid,
25596 + current->comm, task_pid_nr(current),
25597 cattr_name(want_flags),
25598 (unsigned long long)paddr,
25599 (unsigned long long)(paddr + size - 1),
25600 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25601 index 9f0614d..92ae64a 100644
25602 --- a/arch/x86/mm/pf_in.c
25603 +++ b/arch/x86/mm/pf_in.c
25604 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25605 int i;
25606 enum reason_type rv = OTHERS;
25607
25608 - p = (unsigned char *)ins_addr;
25609 + p = (unsigned char *)ktla_ktva(ins_addr);
25610 p += skip_prefix(p, &prf);
25611 p += get_opcode(p, &opcode);
25612
25613 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25614 struct prefix_bits prf;
25615 int i;
25616
25617 - p = (unsigned char *)ins_addr;
25618 + p = (unsigned char *)ktla_ktva(ins_addr);
25619 p += skip_prefix(p, &prf);
25620 p += get_opcode(p, &opcode);
25621
25622 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25623 struct prefix_bits prf;
25624 int i;
25625
25626 - p = (unsigned char *)ins_addr;
25627 + p = (unsigned char *)ktla_ktva(ins_addr);
25628 p += skip_prefix(p, &prf);
25629 p += get_opcode(p, &opcode);
25630
25631 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25632 struct prefix_bits prf;
25633 int i;
25634
25635 - p = (unsigned char *)ins_addr;
25636 + p = (unsigned char *)ktla_ktva(ins_addr);
25637 p += skip_prefix(p, &prf);
25638 p += get_opcode(p, &opcode);
25639 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25640 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25641 struct prefix_bits prf;
25642 int i;
25643
25644 - p = (unsigned char *)ins_addr;
25645 + p = (unsigned char *)ktla_ktva(ins_addr);
25646 p += skip_prefix(p, &prf);
25647 p += get_opcode(p, &opcode);
25648 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25649 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25650 index 8573b83..4f3ed7e 100644
25651 --- a/arch/x86/mm/pgtable.c
25652 +++ b/arch/x86/mm/pgtable.c
25653 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25654 list_del(&page->lru);
25655 }
25656
25657 -#define UNSHARED_PTRS_PER_PGD \
25658 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25659 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25660 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25661
25662 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25663 +{
25664 + unsigned int count = USER_PGD_PTRS;
25665
25666 + while (count--)
25667 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25668 +}
25669 +#endif
25670 +
25671 +#ifdef CONFIG_PAX_PER_CPU_PGD
25672 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25673 +{
25674 + unsigned int count = USER_PGD_PTRS;
25675 +
25676 + while (count--) {
25677 + pgd_t pgd;
25678 +
25679 +#ifdef CONFIG_X86_64
25680 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25681 +#else
25682 + pgd = *src++;
25683 +#endif
25684 +
25685 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25686 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25687 +#endif
25688 +
25689 + *dst++ = pgd;
25690 + }
25691 +
25692 +}
25693 +#endif
25694 +
25695 +#ifdef CONFIG_X86_64
25696 +#define pxd_t pud_t
25697 +#define pyd_t pgd_t
25698 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25699 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25700 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25701 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25702 +#define PYD_SIZE PGDIR_SIZE
25703 +#else
25704 +#define pxd_t pmd_t
25705 +#define pyd_t pud_t
25706 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25707 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25708 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25709 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25710 +#define PYD_SIZE PUD_SIZE
25711 +#endif
25712 +
25713 +#ifdef CONFIG_PAX_PER_CPU_PGD
25714 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25715 +static inline void pgd_dtor(pgd_t *pgd) {}
25716 +#else
25717 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25718 {
25719 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25720 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25721 pgd_list_del(pgd);
25722 spin_unlock(&pgd_lock);
25723 }
25724 +#endif
25725
25726 /*
25727 * List of all pgd's needed for non-PAE so it can invalidate entries
25728 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25729 * -- wli
25730 */
25731
25732 -#ifdef CONFIG_X86_PAE
25733 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25734 /*
25735 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25736 * updating the top-level pagetable entries to guarantee the
25737 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25738 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25739 * and initialize the kernel pmds here.
25740 */
25741 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25742 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25743
25744 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25745 {
25746 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25747 */
25748 flush_tlb_mm(mm);
25749 }
25750 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25751 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25752 #else /* !CONFIG_X86_PAE */
25753
25754 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25755 -#define PREALLOCATED_PMDS 0
25756 +#define PREALLOCATED_PXDS 0
25757
25758 #endif /* CONFIG_X86_PAE */
25759
25760 -static void free_pmds(pmd_t *pmds[])
25761 +static void free_pxds(pxd_t *pxds[])
25762 {
25763 int i;
25764
25765 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25766 - if (pmds[i])
25767 - free_page((unsigned long)pmds[i]);
25768 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25769 + if (pxds[i])
25770 + free_page((unsigned long)pxds[i]);
25771 }
25772
25773 -static int preallocate_pmds(pmd_t *pmds[])
25774 +static int preallocate_pxds(pxd_t *pxds[])
25775 {
25776 int i;
25777 bool failed = false;
25778
25779 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25780 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25781 - if (pmd == NULL)
25782 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25783 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25784 + if (pxd == NULL)
25785 failed = true;
25786 - pmds[i] = pmd;
25787 + pxds[i] = pxd;
25788 }
25789
25790 if (failed) {
25791 - free_pmds(pmds);
25792 + free_pxds(pxds);
25793 return -ENOMEM;
25794 }
25795
25796 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25797 * preallocate which never got a corresponding vma will need to be
25798 * freed manually.
25799 */
25800 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25801 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25802 {
25803 int i;
25804
25805 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25806 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25807 pgd_t pgd = pgdp[i];
25808
25809 if (pgd_val(pgd) != 0) {
25810 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25811 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25812
25813 - pgdp[i] = native_make_pgd(0);
25814 + set_pgd(pgdp + i, native_make_pgd(0));
25815
25816 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25817 - pmd_free(mm, pmd);
25818 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25819 + pxd_free(mm, pxd);
25820 }
25821 }
25822 }
25823
25824 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25825 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25826 {
25827 - pud_t *pud;
25828 + pyd_t *pyd;
25829 unsigned long addr;
25830 int i;
25831
25832 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25833 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25834 return;
25835
25836 - pud = pud_offset(pgd, 0);
25837 +#ifdef CONFIG_X86_64
25838 + pyd = pyd_offset(mm, 0L);
25839 +#else
25840 + pyd = pyd_offset(pgd, 0L);
25841 +#endif
25842
25843 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25844 - i++, pud++, addr += PUD_SIZE) {
25845 - pmd_t *pmd = pmds[i];
25846 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25847 + i++, pyd++, addr += PYD_SIZE) {
25848 + pxd_t *pxd = pxds[i];
25849
25850 if (i >= KERNEL_PGD_BOUNDARY)
25851 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25852 - sizeof(pmd_t) * PTRS_PER_PMD);
25853 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25854 + sizeof(pxd_t) * PTRS_PER_PMD);
25855
25856 - pud_populate(mm, pud, pmd);
25857 + pyd_populate(mm, pyd, pxd);
25858 }
25859 }
25860
25861 pgd_t *pgd_alloc(struct mm_struct *mm)
25862 {
25863 pgd_t *pgd;
25864 - pmd_t *pmds[PREALLOCATED_PMDS];
25865 + pxd_t *pxds[PREALLOCATED_PXDS];
25866
25867 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25868
25869 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25870
25871 mm->pgd = pgd;
25872
25873 - if (preallocate_pmds(pmds) != 0)
25874 + if (preallocate_pxds(pxds) != 0)
25875 goto out_free_pgd;
25876
25877 if (paravirt_pgd_alloc(mm) != 0)
25878 - goto out_free_pmds;
25879 + goto out_free_pxds;
25880
25881 /*
25882 * Make sure that pre-populating the pmds is atomic with
25883 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25884 spin_lock(&pgd_lock);
25885
25886 pgd_ctor(mm, pgd);
25887 - pgd_prepopulate_pmd(mm, pgd, pmds);
25888 + pgd_prepopulate_pxd(mm, pgd, pxds);
25889
25890 spin_unlock(&pgd_lock);
25891
25892 return pgd;
25893
25894 -out_free_pmds:
25895 - free_pmds(pmds);
25896 +out_free_pxds:
25897 + free_pxds(pxds);
25898 out_free_pgd:
25899 free_page((unsigned long)pgd);
25900 out:
25901 @@ -295,7 +356,7 @@ out:
25902
25903 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25904 {
25905 - pgd_mop_up_pmds(mm, pgd);
25906 + pgd_mop_up_pxds(mm, pgd);
25907 pgd_dtor(pgd);
25908 paravirt_pgd_free(mm, pgd);
25909 free_page((unsigned long)pgd);
25910 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25911 index a69bcb8..19068ab 100644
25912 --- a/arch/x86/mm/pgtable_32.c
25913 +++ b/arch/x86/mm/pgtable_32.c
25914 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25915 return;
25916 }
25917 pte = pte_offset_kernel(pmd, vaddr);
25918 +
25919 + pax_open_kernel();
25920 if (pte_val(pteval))
25921 set_pte_at(&init_mm, vaddr, pte, pteval);
25922 else
25923 pte_clear(&init_mm, vaddr, pte);
25924 + pax_close_kernel();
25925
25926 /*
25927 * It's enough to flush this one mapping.
25928 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25929 index 410531d..0f16030 100644
25930 --- a/arch/x86/mm/setup_nx.c
25931 +++ b/arch/x86/mm/setup_nx.c
25932 @@ -5,8 +5,10 @@
25933 #include <asm/pgtable.h>
25934 #include <asm/proto.h>
25935
25936 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25937 static int disable_nx __cpuinitdata;
25938
25939 +#ifndef CONFIG_PAX_PAGEEXEC
25940 /*
25941 * noexec = on|off
25942 *
25943 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25944 return 0;
25945 }
25946 early_param("noexec", noexec_setup);
25947 +#endif
25948 +
25949 +#endif
25950
25951 void __cpuinit x86_configure_nx(void)
25952 {
25953 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25954 if (cpu_has_nx && !disable_nx)
25955 __supported_pte_mask |= _PAGE_NX;
25956 else
25957 +#endif
25958 __supported_pte_mask &= ~_PAGE_NX;
25959 }
25960
25961 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25962 index 613cd83..3a21f1c 100644
25963 --- a/arch/x86/mm/tlb.c
25964 +++ b/arch/x86/mm/tlb.c
25965 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
25966 BUG();
25967 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25968 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25969 +
25970 +#ifndef CONFIG_PAX_PER_CPU_PGD
25971 load_cr3(swapper_pg_dir);
25972 +#endif
25973 +
25974 }
25975 }
25976 EXPORT_SYMBOL_GPL(leave_mm);
25977 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25978 index 877b9a1..a8ecf42 100644
25979 --- a/arch/x86/net/bpf_jit.S
25980 +++ b/arch/x86/net/bpf_jit.S
25981 @@ -9,6 +9,7 @@
25982 */
25983 #include <linux/linkage.h>
25984 #include <asm/dwarf2.h>
25985 +#include <asm/alternative-asm.h>
25986
25987 /*
25988 * Calling convention :
25989 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25990 jle bpf_slow_path_word
25991 mov (SKBDATA,%rsi),%eax
25992 bswap %eax /* ntohl() */
25993 + pax_force_retaddr
25994 ret
25995
25996 sk_load_half:
25997 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25998 jle bpf_slow_path_half
25999 movzwl (SKBDATA,%rsi),%eax
26000 rol $8,%ax # ntohs()
26001 + pax_force_retaddr
26002 ret
26003
26004 sk_load_byte:
26005 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
26006 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26007 jle bpf_slow_path_byte
26008 movzbl (SKBDATA,%rsi),%eax
26009 + pax_force_retaddr
26010 ret
26011
26012 /**
26013 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
26014 movzbl (SKBDATA,%rsi),%ebx
26015 and $15,%bl
26016 shl $2,%bl
26017 + pax_force_retaddr
26018 ret
26019
26020 /* rsi contains offset and can be scratched */
26021 @@ -109,6 +114,7 @@ bpf_slow_path_word:
26022 js bpf_error
26023 mov -12(%rbp),%eax
26024 bswap %eax
26025 + pax_force_retaddr
26026 ret
26027
26028 bpf_slow_path_half:
26029 @@ -117,12 +123,14 @@ bpf_slow_path_half:
26030 mov -12(%rbp),%ax
26031 rol $8,%ax
26032 movzwl %ax,%eax
26033 + pax_force_retaddr
26034 ret
26035
26036 bpf_slow_path_byte:
26037 bpf_slow_path_common(1)
26038 js bpf_error
26039 movzbl -12(%rbp),%eax
26040 + pax_force_retaddr
26041 ret
26042
26043 bpf_slow_path_byte_msh:
26044 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26045 and $15,%al
26046 shl $2,%al
26047 xchg %eax,%ebx
26048 + pax_force_retaddr
26049 ret
26050
26051 #define sk_negative_common(SIZE) \
26052 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26053 sk_negative_common(4)
26054 mov (%rax), %eax
26055 bswap %eax
26056 + pax_force_retaddr
26057 ret
26058
26059 bpf_slow_path_half_neg:
26060 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26061 mov (%rax),%ax
26062 rol $8,%ax
26063 movzwl %ax,%eax
26064 + pax_force_retaddr
26065 ret
26066
26067 bpf_slow_path_byte_neg:
26068 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26069 .globl sk_load_byte_negative_offset
26070 sk_negative_common(1)
26071 movzbl (%rax), %eax
26072 + pax_force_retaddr
26073 ret
26074
26075 bpf_slow_path_byte_msh_neg:
26076 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26077 and $15,%al
26078 shl $2,%al
26079 xchg %eax,%ebx
26080 + pax_force_retaddr
26081 ret
26082
26083 bpf_error:
26084 @@ -197,4 +210,5 @@ bpf_error:
26085 xor %eax,%eax
26086 mov -8(%rbp),%rbx
26087 leaveq
26088 + pax_force_retaddr
26089 ret
26090 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26091 index 33643a8..f6211a0 100644
26092 --- a/arch/x86/net/bpf_jit_comp.c
26093 +++ b/arch/x86/net/bpf_jit_comp.c
26094 @@ -11,6 +11,7 @@
26095 #include <asm/cacheflush.h>
26096 #include <linux/netdevice.h>
26097 #include <linux/filter.h>
26098 +#include <linux/random.h>
26099
26100 /*
26101 * Conventions :
26102 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
26103 return ptr + len;
26104 }
26105
26106 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26107 +#define MAX_INSTR_CODE_SIZE 96
26108 +#else
26109 +#define MAX_INSTR_CODE_SIZE 64
26110 +#endif
26111 +
26112 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
26113
26114 #define EMIT1(b1) EMIT(b1, 1)
26115 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
26116 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
26117 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
26118 +
26119 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26120 +/* original constant will appear in ecx */
26121 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
26122 +do { \
26123 + /* mov ecx, randkey */ \
26124 + EMIT1(0xb9); \
26125 + EMIT(_key, 4); \
26126 + /* xor ecx, randkey ^ off */ \
26127 + EMIT2(0x81, 0xf1); \
26128 + EMIT((_key) ^ (_off), 4); \
26129 +} while (0)
26130 +
26131 +#define EMIT1_off32(b1, _off) \
26132 +do { \
26133 + switch (b1) { \
26134 + case 0x05: /* add eax, imm32 */ \
26135 + case 0x2d: /* sub eax, imm32 */ \
26136 + case 0x25: /* and eax, imm32 */ \
26137 + case 0x0d: /* or eax, imm32 */ \
26138 + case 0xb8: /* mov eax, imm32 */ \
26139 + case 0x3d: /* cmp eax, imm32 */ \
26140 + case 0xa9: /* test eax, imm32 */ \
26141 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26142 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
26143 + break; \
26144 + case 0xbb: /* mov ebx, imm32 */ \
26145 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26146 + /* mov ebx, ecx */ \
26147 + EMIT2(0x89, 0xcb); \
26148 + break; \
26149 + case 0xbe: /* mov esi, imm32 */ \
26150 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26151 + /* mov esi, ecx */ \
26152 + EMIT2(0x89, 0xce); \
26153 + break; \
26154 + case 0xe9: /* jmp rel imm32 */ \
26155 + EMIT1(b1); \
26156 + EMIT(_off, 4); \
26157 + /* prevent fall-through, we're not called if off = 0 */ \
26158 + EMIT(0xcccccccc, 4); \
26159 + EMIT(0xcccccccc, 4); \
26160 + break; \
26161 + default: \
26162 + EMIT1(b1); \
26163 + EMIT(_off, 4); \
26164 + } \
26165 +} while (0)
26166 +
26167 +#define EMIT2_off32(b1, b2, _off) \
26168 +do { \
26169 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
26170 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
26171 + EMIT(randkey, 4); \
26172 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
26173 + EMIT((_off) - randkey, 4); \
26174 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
26175 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26176 + /* imul eax, ecx */ \
26177 + EMIT3(0x0f, 0xaf, 0xc1); \
26178 + } else { \
26179 + EMIT2(b1, b2); \
26180 + EMIT(_off, 4); \
26181 + } \
26182 +} while (0)
26183 +#else
26184 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
26185 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
26186 +#endif
26187
26188 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
26189 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
26190 @@ -89,6 +164,24 @@ do { \
26191 #define X86_JBE 0x76
26192 #define X86_JA 0x77
26193
26194 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26195 +#define APPEND_FLOW_VERIFY() \
26196 +do { \
26197 + /* mov ecx, randkey */ \
26198 + EMIT1(0xb9); \
26199 + EMIT(randkey, 4); \
26200 + /* cmp ecx, randkey */ \
26201 + EMIT2(0x81, 0xf9); \
26202 + EMIT(randkey, 4); \
26203 + /* jz after 8 int 3s */ \
26204 + EMIT2(0x74, 0x08); \
26205 + EMIT(0xcccccccc, 4); \
26206 + EMIT(0xcccccccc, 4); \
26207 +} while (0)
26208 +#else
26209 +#define APPEND_FLOW_VERIFY() do { } while (0)
26210 +#endif
26211 +
26212 #define EMIT_COND_JMP(op, offset) \
26213 do { \
26214 if (is_near(offset)) \
26215 @@ -96,6 +189,7 @@ do { \
26216 else { \
26217 EMIT2(0x0f, op + 0x10); \
26218 EMIT(offset, 4); /* jxx .+off32 */ \
26219 + APPEND_FLOW_VERIFY(); \
26220 } \
26221 } while (0)
26222
26223 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
26224 set_fs(old_fs);
26225 }
26226
26227 +struct bpf_jit_work {
26228 + struct work_struct work;
26229 + void *image;
26230 +};
26231 +
26232 #define CHOOSE_LOAD_FUNC(K, func) \
26233 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26234
26235 void bpf_jit_compile(struct sk_filter *fp)
26236 {
26237 - u8 temp[64];
26238 + u8 temp[MAX_INSTR_CODE_SIZE];
26239 u8 *prog;
26240 unsigned int proglen, oldproglen = 0;
26241 int ilen, i;
26242 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
26243 unsigned int *addrs;
26244 const struct sock_filter *filter = fp->insns;
26245 int flen = fp->len;
26246 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26247 + unsigned int randkey;
26248 +#endif
26249
26250 if (!bpf_jit_enable)
26251 return;
26252 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
26253 if (addrs == NULL)
26254 return;
26255
26256 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26257 + if (!fp->work)
26258 + goto out;
26259 +
26260 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26261 + randkey = get_random_int();
26262 +#endif
26263 +
26264 /* Before first pass, make a rough estimation of addrs[]
26265 - * each bpf instruction is translated to less than 64 bytes
26266 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
26267 */
26268 for (proglen = 0, i = 0; i < flen; i++) {
26269 - proglen += 64;
26270 + proglen += MAX_INSTR_CODE_SIZE;
26271 addrs[i] = proglen;
26272 }
26273 cleanup_addr = proglen; /* epilogue address */
26274 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
26275 case BPF_S_ALU_MUL_K: /* A *= K */
26276 if (is_imm8(K))
26277 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
26278 - else {
26279 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
26280 - EMIT(K, 4);
26281 - }
26282 + else
26283 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
26284 break;
26285 case BPF_S_ALU_DIV_X: /* A /= X; */
26286 seen |= SEEN_XREG;
26287 @@ -281,8 +389,14 @@ void bpf_jit_compile(struct sk_filter *fp)
26288 EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */
26289 break;
26290 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
26291 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26292 + DILUTE_CONST_SEQUENCE(K, randkey);
26293 + // imul rax, rcx
26294 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
26295 +#else
26296 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
26297 EMIT(K, 4);
26298 +#endif
26299 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
26300 break;
26301 case BPF_S_ALU_AND_X:
26302 @@ -509,8 +623,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
26303 if (is_imm8(K)) {
26304 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
26305 } else {
26306 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
26307 - EMIT(K, 4);
26308 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
26309 }
26310 } else {
26311 EMIT2(0x89,0xde); /* mov %ebx,%esi */
26312 @@ -593,17 +706,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26313 break;
26314 default:
26315 /* hmm, too complex filter, give up with jit compiler */
26316 - goto out;
26317 + goto error;
26318 }
26319 ilen = prog - temp;
26320 if (image) {
26321 if (unlikely(proglen + ilen > oldproglen)) {
26322 pr_err("bpb_jit_compile fatal error\n");
26323 - kfree(addrs);
26324 - module_free(NULL, image);
26325 - return;
26326 + module_free_exec(NULL, image);
26327 + goto error;
26328 }
26329 + pax_open_kernel();
26330 memcpy(image + proglen, temp, ilen);
26331 + pax_close_kernel();
26332 }
26333 proglen += ilen;
26334 addrs[i] = proglen;
26335 @@ -624,11 +738,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26336 break;
26337 }
26338 if (proglen == oldproglen) {
26339 - image = module_alloc(max_t(unsigned int,
26340 - proglen,
26341 - sizeof(struct work_struct)));
26342 + image = module_alloc_exec(proglen);
26343 if (!image)
26344 - goto out;
26345 + goto error;
26346 }
26347 oldproglen = proglen;
26348 }
26349 @@ -644,7 +756,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26350 bpf_flush_icache(image, image + proglen);
26351
26352 fp->bpf_func = (void *)image;
26353 - }
26354 + } else
26355 +error:
26356 + kfree(fp->work);
26357 +
26358 out:
26359 kfree(addrs);
26360 return;
26361 @@ -652,18 +767,20 @@ out:
26362
26363 static void jit_free_defer(struct work_struct *arg)
26364 {
26365 - module_free(NULL, arg);
26366 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26367 + kfree(arg);
26368 }
26369
26370 /* run from softirq, we must use a work_struct to call
26371 - * module_free() from process context
26372 + * module_free_exec() from process context
26373 */
26374 void bpf_jit_free(struct sk_filter *fp)
26375 {
26376 if (fp->bpf_func != sk_run_filter) {
26377 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26378 + struct work_struct *work = &fp->work->work;
26379
26380 INIT_WORK(work, jit_free_defer);
26381 + fp->work->image = fp->bpf_func;
26382 schedule_work(work);
26383 }
26384 }
26385 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26386 index d6aa6e8..266395a 100644
26387 --- a/arch/x86/oprofile/backtrace.c
26388 +++ b/arch/x86/oprofile/backtrace.c
26389 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26390 struct stack_frame_ia32 *fp;
26391 unsigned long bytes;
26392
26393 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26394 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26395 if (bytes != sizeof(bufhead))
26396 return NULL;
26397
26398 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26399 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26400
26401 oprofile_add_trace(bufhead[0].return_address);
26402
26403 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26404 struct stack_frame bufhead[2];
26405 unsigned long bytes;
26406
26407 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26408 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26409 if (bytes != sizeof(bufhead))
26410 return NULL;
26411
26412 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26413 {
26414 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26415
26416 - if (!user_mode_vm(regs)) {
26417 + if (!user_mode(regs)) {
26418 unsigned long stack = kernel_stack_pointer(regs);
26419 if (depth)
26420 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26421 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26422 index e14a2ff..3fd6b58 100644
26423 --- a/arch/x86/pci/mrst.c
26424 +++ b/arch/x86/pci/mrst.c
26425 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26426 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26427 pci_mmcfg_late_init();
26428 pcibios_enable_irq = mrst_pci_irq_enable;
26429 - pci_root_ops = pci_mrst_ops;
26430 + pax_open_kernel();
26431 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26432 + pax_close_kernel();
26433 pci_soc_mode = 1;
26434 /* Continue with standard init */
26435 return 1;
26436 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26437 index da8fe05..7ee6704 100644
26438 --- a/arch/x86/pci/pcbios.c
26439 +++ b/arch/x86/pci/pcbios.c
26440 @@ -79,50 +79,93 @@ union bios32 {
26441 static struct {
26442 unsigned long address;
26443 unsigned short segment;
26444 -} bios32_indirect = { 0, __KERNEL_CS };
26445 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26446
26447 /*
26448 * Returns the entry point for the given service, NULL on error
26449 */
26450
26451 -static unsigned long bios32_service(unsigned long service)
26452 +static unsigned long __devinit bios32_service(unsigned long service)
26453 {
26454 unsigned char return_code; /* %al */
26455 unsigned long address; /* %ebx */
26456 unsigned long length; /* %ecx */
26457 unsigned long entry; /* %edx */
26458 unsigned long flags;
26459 + struct desc_struct d, *gdt;
26460
26461 local_irq_save(flags);
26462 - __asm__("lcall *(%%edi); cld"
26463 +
26464 + gdt = get_cpu_gdt_table(smp_processor_id());
26465 +
26466 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26467 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26468 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26469 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26470 +
26471 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26472 : "=a" (return_code),
26473 "=b" (address),
26474 "=c" (length),
26475 "=d" (entry)
26476 : "0" (service),
26477 "1" (0),
26478 - "D" (&bios32_indirect));
26479 + "D" (&bios32_indirect),
26480 + "r"(__PCIBIOS_DS)
26481 + : "memory");
26482 +
26483 + pax_open_kernel();
26484 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26485 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26486 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26487 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26488 + pax_close_kernel();
26489 +
26490 local_irq_restore(flags);
26491
26492 switch (return_code) {
26493 - case 0:
26494 - return address + entry;
26495 - case 0x80: /* Not present */
26496 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26497 - return 0;
26498 - default: /* Shouldn't happen */
26499 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26500 - service, return_code);
26501 + case 0: {
26502 + int cpu;
26503 + unsigned char flags;
26504 +
26505 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26506 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26507 + printk(KERN_WARNING "bios32_service: not valid\n");
26508 return 0;
26509 + }
26510 + address = address + PAGE_OFFSET;
26511 + length += 16UL; /* some BIOSs underreport this... */
26512 + flags = 4;
26513 + if (length >= 64*1024*1024) {
26514 + length >>= PAGE_SHIFT;
26515 + flags |= 8;
26516 + }
26517 +
26518 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26519 + gdt = get_cpu_gdt_table(cpu);
26520 + pack_descriptor(&d, address, length, 0x9b, flags);
26521 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26522 + pack_descriptor(&d, address, length, 0x93, flags);
26523 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26524 + }
26525 + return entry;
26526 + }
26527 + case 0x80: /* Not present */
26528 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26529 + return 0;
26530 + default: /* Shouldn't happen */
26531 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26532 + service, return_code);
26533 + return 0;
26534 }
26535 }
26536
26537 static struct {
26538 unsigned long address;
26539 unsigned short segment;
26540 -} pci_indirect = { 0, __KERNEL_CS };
26541 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26542
26543 -static int pci_bios_present;
26544 +static int pci_bios_present __read_only;
26545
26546 static int __devinit check_pcibios(void)
26547 {
26548 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26549 unsigned long flags, pcibios_entry;
26550
26551 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26552 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26553 + pci_indirect.address = pcibios_entry;
26554
26555 local_irq_save(flags);
26556 - __asm__(
26557 - "lcall *(%%edi); cld\n\t"
26558 + __asm__("movw %w6, %%ds\n\t"
26559 + "lcall *%%ss:(%%edi); cld\n\t"
26560 + "push %%ss\n\t"
26561 + "pop %%ds\n\t"
26562 "jc 1f\n\t"
26563 "xor %%ah, %%ah\n"
26564 "1:"
26565 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26566 "=b" (ebx),
26567 "=c" (ecx)
26568 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26569 - "D" (&pci_indirect)
26570 + "D" (&pci_indirect),
26571 + "r" (__PCIBIOS_DS)
26572 : "memory");
26573 local_irq_restore(flags);
26574
26575 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26576
26577 switch (len) {
26578 case 1:
26579 - __asm__("lcall *(%%esi); cld\n\t"
26580 + __asm__("movw %w6, %%ds\n\t"
26581 + "lcall *%%ss:(%%esi); cld\n\t"
26582 + "push %%ss\n\t"
26583 + "pop %%ds\n\t"
26584 "jc 1f\n\t"
26585 "xor %%ah, %%ah\n"
26586 "1:"
26587 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26588 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26589 "b" (bx),
26590 "D" ((long)reg),
26591 - "S" (&pci_indirect));
26592 + "S" (&pci_indirect),
26593 + "r" (__PCIBIOS_DS));
26594 /*
26595 * Zero-extend the result beyond 8 bits, do not trust the
26596 * BIOS having done it:
26597 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26598 *value &= 0xff;
26599 break;
26600 case 2:
26601 - __asm__("lcall *(%%esi); cld\n\t"
26602 + __asm__("movw %w6, %%ds\n\t"
26603 + "lcall *%%ss:(%%esi); cld\n\t"
26604 + "push %%ss\n\t"
26605 + "pop %%ds\n\t"
26606 "jc 1f\n\t"
26607 "xor %%ah, %%ah\n"
26608 "1:"
26609 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26610 : "1" (PCIBIOS_READ_CONFIG_WORD),
26611 "b" (bx),
26612 "D" ((long)reg),
26613 - "S" (&pci_indirect));
26614 + "S" (&pci_indirect),
26615 + "r" (__PCIBIOS_DS));
26616 /*
26617 * Zero-extend the result beyond 16 bits, do not trust the
26618 * BIOS having done it:
26619 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26620 *value &= 0xffff;
26621 break;
26622 case 4:
26623 - __asm__("lcall *(%%esi); cld\n\t"
26624 + __asm__("movw %w6, %%ds\n\t"
26625 + "lcall *%%ss:(%%esi); cld\n\t"
26626 + "push %%ss\n\t"
26627 + "pop %%ds\n\t"
26628 "jc 1f\n\t"
26629 "xor %%ah, %%ah\n"
26630 "1:"
26631 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26632 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26633 "b" (bx),
26634 "D" ((long)reg),
26635 - "S" (&pci_indirect));
26636 + "S" (&pci_indirect),
26637 + "r" (__PCIBIOS_DS));
26638 break;
26639 }
26640
26641 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26642
26643 switch (len) {
26644 case 1:
26645 - __asm__("lcall *(%%esi); cld\n\t"
26646 + __asm__("movw %w6, %%ds\n\t"
26647 + "lcall *%%ss:(%%esi); cld\n\t"
26648 + "push %%ss\n\t"
26649 + "pop %%ds\n\t"
26650 "jc 1f\n\t"
26651 "xor %%ah, %%ah\n"
26652 "1:"
26653 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26654 "c" (value),
26655 "b" (bx),
26656 "D" ((long)reg),
26657 - "S" (&pci_indirect));
26658 + "S" (&pci_indirect),
26659 + "r" (__PCIBIOS_DS));
26660 break;
26661 case 2:
26662 - __asm__("lcall *(%%esi); cld\n\t"
26663 + __asm__("movw %w6, %%ds\n\t"
26664 + "lcall *%%ss:(%%esi); cld\n\t"
26665 + "push %%ss\n\t"
26666 + "pop %%ds\n\t"
26667 "jc 1f\n\t"
26668 "xor %%ah, %%ah\n"
26669 "1:"
26670 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26671 "c" (value),
26672 "b" (bx),
26673 "D" ((long)reg),
26674 - "S" (&pci_indirect));
26675 + "S" (&pci_indirect),
26676 + "r" (__PCIBIOS_DS));
26677 break;
26678 case 4:
26679 - __asm__("lcall *(%%esi); cld\n\t"
26680 + __asm__("movw %w6, %%ds\n\t"
26681 + "lcall *%%ss:(%%esi); cld\n\t"
26682 + "push %%ss\n\t"
26683 + "pop %%ds\n\t"
26684 "jc 1f\n\t"
26685 "xor %%ah, %%ah\n"
26686 "1:"
26687 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26688 "c" (value),
26689 "b" (bx),
26690 "D" ((long)reg),
26691 - "S" (&pci_indirect));
26692 + "S" (&pci_indirect),
26693 + "r" (__PCIBIOS_DS));
26694 break;
26695 }
26696
26697 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26698
26699 DBG("PCI: Fetching IRQ routing table... ");
26700 __asm__("push %%es\n\t"
26701 + "movw %w8, %%ds\n\t"
26702 "push %%ds\n\t"
26703 "pop %%es\n\t"
26704 - "lcall *(%%esi); cld\n\t"
26705 + "lcall *%%ss:(%%esi); cld\n\t"
26706 "pop %%es\n\t"
26707 + "push %%ss\n\t"
26708 + "pop %%ds\n"
26709 "jc 1f\n\t"
26710 "xor %%ah, %%ah\n"
26711 "1:"
26712 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26713 "1" (0),
26714 "D" ((long) &opt),
26715 "S" (&pci_indirect),
26716 - "m" (opt)
26717 + "m" (opt),
26718 + "r" (__PCIBIOS_DS)
26719 : "memory");
26720 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26721 if (ret & 0xff00)
26722 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26723 {
26724 int ret;
26725
26726 - __asm__("lcall *(%%esi); cld\n\t"
26727 + __asm__("movw %w5, %%ds\n\t"
26728 + "lcall *%%ss:(%%esi); cld\n\t"
26729 + "push %%ss\n\t"
26730 + "pop %%ds\n"
26731 "jc 1f\n\t"
26732 "xor %%ah, %%ah\n"
26733 "1:"
26734 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26735 : "0" (PCIBIOS_SET_PCI_HW_INT),
26736 "b" ((dev->bus->number << 8) | dev->devfn),
26737 "c" ((irq << 8) | (pin + 10)),
26738 - "S" (&pci_indirect));
26739 + "S" (&pci_indirect),
26740 + "r" (__PCIBIOS_DS));
26741 return !(ret & 0xff00);
26742 }
26743 EXPORT_SYMBOL(pcibios_set_irq_routing);
26744 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26745 index 40e4469..1ab536e 100644
26746 --- a/arch/x86/platform/efi/efi_32.c
26747 +++ b/arch/x86/platform/efi/efi_32.c
26748 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26749 {
26750 struct desc_ptr gdt_descr;
26751
26752 +#ifdef CONFIG_PAX_KERNEXEC
26753 + struct desc_struct d;
26754 +#endif
26755 +
26756 local_irq_save(efi_rt_eflags);
26757
26758 load_cr3(initial_page_table);
26759 __flush_tlb_all();
26760
26761 +#ifdef CONFIG_PAX_KERNEXEC
26762 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26763 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26764 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26765 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26766 +#endif
26767 +
26768 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26769 gdt_descr.size = GDT_SIZE - 1;
26770 load_gdt(&gdt_descr);
26771 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26772 {
26773 struct desc_ptr gdt_descr;
26774
26775 +#ifdef CONFIG_PAX_KERNEXEC
26776 + struct desc_struct d;
26777 +
26778 + memset(&d, 0, sizeof d);
26779 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26780 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26781 +#endif
26782 +
26783 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26784 gdt_descr.size = GDT_SIZE - 1;
26785 load_gdt(&gdt_descr);
26786 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26787 index fbe66e6..eae5e38 100644
26788 --- a/arch/x86/platform/efi/efi_stub_32.S
26789 +++ b/arch/x86/platform/efi/efi_stub_32.S
26790 @@ -6,7 +6,9 @@
26791 */
26792
26793 #include <linux/linkage.h>
26794 +#include <linux/init.h>
26795 #include <asm/page_types.h>
26796 +#include <asm/segment.h>
26797
26798 /*
26799 * efi_call_phys(void *, ...) is a function with variable parameters.
26800 @@ -20,7 +22,7 @@
26801 * service functions will comply with gcc calling convention, too.
26802 */
26803
26804 -.text
26805 +__INIT
26806 ENTRY(efi_call_phys)
26807 /*
26808 * 0. The function can only be called in Linux kernel. So CS has been
26809 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26810 * The mapping of lower virtual memory has been created in prelog and
26811 * epilog.
26812 */
26813 - movl $1f, %edx
26814 - subl $__PAGE_OFFSET, %edx
26815 - jmp *%edx
26816 +#ifdef CONFIG_PAX_KERNEXEC
26817 + movl $(__KERNEXEC_EFI_DS), %edx
26818 + mov %edx, %ds
26819 + mov %edx, %es
26820 + mov %edx, %ss
26821 + addl $2f,(1f)
26822 + ljmp *(1f)
26823 +
26824 +__INITDATA
26825 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26826 +.previous
26827 +
26828 +2:
26829 + subl $2b,(1b)
26830 +#else
26831 + jmp 1f-__PAGE_OFFSET
26832 1:
26833 +#endif
26834
26835 /*
26836 * 2. Now on the top of stack is the return
26837 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26838 * parameter 2, ..., param n. To make things easy, we save the return
26839 * address of efi_call_phys in a global variable.
26840 */
26841 - popl %edx
26842 - movl %edx, saved_return_addr
26843 - /* get the function pointer into ECX*/
26844 - popl %ecx
26845 - movl %ecx, efi_rt_function_ptr
26846 - movl $2f, %edx
26847 - subl $__PAGE_OFFSET, %edx
26848 - pushl %edx
26849 + popl (saved_return_addr)
26850 + popl (efi_rt_function_ptr)
26851
26852 /*
26853 * 3. Clear PG bit in %CR0.
26854 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26855 /*
26856 * 5. Call the physical function.
26857 */
26858 - jmp *%ecx
26859 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26860
26861 -2:
26862 /*
26863 * 6. After EFI runtime service returns, control will return to
26864 * following instruction. We'd better readjust stack pointer first.
26865 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26866 movl %cr0, %edx
26867 orl $0x80000000, %edx
26868 movl %edx, %cr0
26869 - jmp 1f
26870 -1:
26871 +
26872 /*
26873 * 8. Now restore the virtual mode from flat mode by
26874 * adding EIP with PAGE_OFFSET.
26875 */
26876 - movl $1f, %edx
26877 - jmp *%edx
26878 +#ifdef CONFIG_PAX_KERNEXEC
26879 + movl $(__KERNEL_DS), %edx
26880 + mov %edx, %ds
26881 + mov %edx, %es
26882 + mov %edx, %ss
26883 + ljmp $(__KERNEL_CS),$1f
26884 +#else
26885 + jmp 1f+__PAGE_OFFSET
26886 +#endif
26887 1:
26888
26889 /*
26890 * 9. Balance the stack. And because EAX contain the return value,
26891 * we'd better not clobber it.
26892 */
26893 - leal efi_rt_function_ptr, %edx
26894 - movl (%edx), %ecx
26895 - pushl %ecx
26896 + pushl (efi_rt_function_ptr)
26897
26898 /*
26899 - * 10. Push the saved return address onto the stack and return.
26900 + * 10. Return to the saved return address.
26901 */
26902 - leal saved_return_addr, %edx
26903 - movl (%edx), %ecx
26904 - pushl %ecx
26905 - ret
26906 + jmpl *(saved_return_addr)
26907 ENDPROC(efi_call_phys)
26908 .previous
26909
26910 -.data
26911 +__INITDATA
26912 saved_return_addr:
26913 .long 0
26914 efi_rt_function_ptr:
26915 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26916 index 4c07cca..2c8427d 100644
26917 --- a/arch/x86/platform/efi/efi_stub_64.S
26918 +++ b/arch/x86/platform/efi/efi_stub_64.S
26919 @@ -7,6 +7,7 @@
26920 */
26921
26922 #include <linux/linkage.h>
26923 +#include <asm/alternative-asm.h>
26924
26925 #define SAVE_XMM \
26926 mov %rsp, %rax; \
26927 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26928 call *%rdi
26929 addq $32, %rsp
26930 RESTORE_XMM
26931 + pax_force_retaddr 0, 1
26932 ret
26933 ENDPROC(efi_call0)
26934
26935 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26936 call *%rdi
26937 addq $32, %rsp
26938 RESTORE_XMM
26939 + pax_force_retaddr 0, 1
26940 ret
26941 ENDPROC(efi_call1)
26942
26943 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26944 call *%rdi
26945 addq $32, %rsp
26946 RESTORE_XMM
26947 + pax_force_retaddr 0, 1
26948 ret
26949 ENDPROC(efi_call2)
26950
26951 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26952 call *%rdi
26953 addq $32, %rsp
26954 RESTORE_XMM
26955 + pax_force_retaddr 0, 1
26956 ret
26957 ENDPROC(efi_call3)
26958
26959 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26960 call *%rdi
26961 addq $32, %rsp
26962 RESTORE_XMM
26963 + pax_force_retaddr 0, 1
26964 ret
26965 ENDPROC(efi_call4)
26966
26967 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26968 call *%rdi
26969 addq $48, %rsp
26970 RESTORE_XMM
26971 + pax_force_retaddr 0, 1
26972 ret
26973 ENDPROC(efi_call5)
26974
26975 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26976 call *%rdi
26977 addq $48, %rsp
26978 RESTORE_XMM
26979 + pax_force_retaddr 0, 1
26980 ret
26981 ENDPROC(efi_call6)
26982 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26983 index fd41a92..9c33628 100644
26984 --- a/arch/x86/platform/mrst/mrst.c
26985 +++ b/arch/x86/platform/mrst/mrst.c
26986 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26987 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26988 int sfi_mrtc_num;
26989
26990 -static void mrst_power_off(void)
26991 +static __noreturn void mrst_power_off(void)
26992 {
26993 + BUG();
26994 }
26995
26996 -static void mrst_reboot(void)
26997 +static __noreturn void mrst_reboot(void)
26998 {
26999 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
27000 + BUG();
27001 }
27002
27003 /* parse all the mtimer info to a static mtimer array */
27004 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
27005 index 218cdb1..c1178eb 100644
27006 --- a/arch/x86/power/cpu.c
27007 +++ b/arch/x86/power/cpu.c
27008 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
27009 static void fix_processor_context(void)
27010 {
27011 int cpu = smp_processor_id();
27012 - struct tss_struct *t = &per_cpu(init_tss, cpu);
27013 + struct tss_struct *t = init_tss + cpu;
27014
27015 set_tss_desc(cpu, t); /*
27016 * This just modifies memory; should not be
27017 @@ -142,8 +142,6 @@ static void fix_processor_context(void)
27018 */
27019
27020 #ifdef CONFIG_X86_64
27021 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
27022 -
27023 syscall_init(); /* This sets MSR_*STAR and related */
27024 #endif
27025 load_TR_desc(); /* This does ltr */
27026 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
27027 index cbca565..bae7133 100644
27028 --- a/arch/x86/realmode/init.c
27029 +++ b/arch/x86/realmode/init.c
27030 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
27031 __va(real_mode_header->trampoline_header);
27032
27033 #ifdef CONFIG_X86_32
27034 - trampoline_header->start = __pa(startup_32_smp);
27035 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
27036 +
27037 +#ifdef CONFIG_PAX_KERNEXEC
27038 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
27039 +#endif
27040 +
27041 + trampoline_header->boot_cs = __BOOT_CS;
27042 trampoline_header->gdt_limit = __BOOT_DS + 7;
27043 trampoline_header->gdt_base = __pa(boot_gdt);
27044 #else
27045 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
27046 index 8869287..d577672 100644
27047 --- a/arch/x86/realmode/rm/Makefile
27048 +++ b/arch/x86/realmode/rm/Makefile
27049 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
27050 $(call cc-option, -fno-unit-at-a-time)) \
27051 $(call cc-option, -fno-stack-protector) \
27052 $(call cc-option, -mpreferred-stack-boundary=2)
27053 +ifdef CONSTIFY_PLUGIN
27054 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
27055 +endif
27056 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
27057 GCOV_PROFILE := n
27058 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
27059 index a28221d..93c40f1 100644
27060 --- a/arch/x86/realmode/rm/header.S
27061 +++ b/arch/x86/realmode/rm/header.S
27062 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
27063 #endif
27064 /* APM/BIOS reboot */
27065 .long pa_machine_real_restart_asm
27066 -#ifdef CONFIG_X86_64
27067 +#ifdef CONFIG_X86_32
27068 + .long __KERNEL_CS
27069 +#else
27070 .long __KERNEL32_CS
27071 #endif
27072 END(real_mode_header)
27073 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
27074 index c1b2791..f9e31c7 100644
27075 --- a/arch/x86/realmode/rm/trampoline_32.S
27076 +++ b/arch/x86/realmode/rm/trampoline_32.S
27077 @@ -25,6 +25,12 @@
27078 #include <asm/page_types.h>
27079 #include "realmode.h"
27080
27081 +#ifdef CONFIG_PAX_KERNEXEC
27082 +#define ta(X) (X)
27083 +#else
27084 +#define ta(X) (pa_ ## X)
27085 +#endif
27086 +
27087 .text
27088 .code16
27089
27090 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
27091
27092 cli # We should be safe anyway
27093
27094 - movl tr_start, %eax # where we need to go
27095 -
27096 movl $0xA5A5A5A5, trampoline_status
27097 # write marker for master knows we're running
27098
27099 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
27100 movw $1, %dx # protected mode (PE) bit
27101 lmsw %dx # into protected mode
27102
27103 - ljmpl $__BOOT_CS, $pa_startup_32
27104 + ljmpl *(trampoline_header)
27105
27106 .section ".text32","ax"
27107 .code32
27108 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
27109 .balign 8
27110 GLOBAL(trampoline_header)
27111 tr_start: .space 4
27112 - tr_gdt_pad: .space 2
27113 + tr_boot_cs: .space 2
27114 tr_gdt: .space 6
27115 END(trampoline_header)
27116
27117 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
27118 index bb360dc..3e5945f 100644
27119 --- a/arch/x86/realmode/rm/trampoline_64.S
27120 +++ b/arch/x86/realmode/rm/trampoline_64.S
27121 @@ -107,7 +107,7 @@ ENTRY(startup_32)
27122 wrmsr
27123
27124 # Enable paging and in turn activate Long Mode
27125 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
27126 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
27127 movl %eax, %cr0
27128
27129 /*
27130 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
27131 index 5a1847d..deccb30 100644
27132 --- a/arch/x86/tools/relocs.c
27133 +++ b/arch/x86/tools/relocs.c
27134 @@ -12,10 +12,13 @@
27135 #include <regex.h>
27136 #include <tools/le_byteshift.h>
27137
27138 +#include "../../../include/generated/autoconf.h"
27139 +
27140 static void die(char *fmt, ...);
27141
27142 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
27143 static Elf32_Ehdr ehdr;
27144 +static Elf32_Phdr *phdr;
27145 static unsigned long reloc_count, reloc_idx;
27146 static unsigned long *relocs;
27147 static unsigned long reloc16_count, reloc16_idx;
27148 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
27149 }
27150 }
27151
27152 +static void read_phdrs(FILE *fp)
27153 +{
27154 + unsigned int i;
27155 +
27156 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
27157 + if (!phdr) {
27158 + die("Unable to allocate %d program headers\n",
27159 + ehdr.e_phnum);
27160 + }
27161 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
27162 + die("Seek to %d failed: %s\n",
27163 + ehdr.e_phoff, strerror(errno));
27164 + }
27165 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
27166 + die("Cannot read ELF program headers: %s\n",
27167 + strerror(errno));
27168 + }
27169 + for(i = 0; i < ehdr.e_phnum; i++) {
27170 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
27171 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
27172 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
27173 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
27174 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
27175 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
27176 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
27177 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
27178 + }
27179 +
27180 +}
27181 +
27182 static void read_shdrs(FILE *fp)
27183 {
27184 - int i;
27185 + unsigned int i;
27186 Elf32_Shdr shdr;
27187
27188 secs = calloc(ehdr.e_shnum, sizeof(struct section));
27189 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
27190
27191 static void read_strtabs(FILE *fp)
27192 {
27193 - int i;
27194 + unsigned int i;
27195 for (i = 0; i < ehdr.e_shnum; i++) {
27196 struct section *sec = &secs[i];
27197 if (sec->shdr.sh_type != SHT_STRTAB) {
27198 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
27199
27200 static void read_symtabs(FILE *fp)
27201 {
27202 - int i,j;
27203 + unsigned int i,j;
27204 for (i = 0; i < ehdr.e_shnum; i++) {
27205 struct section *sec = &secs[i];
27206 if (sec->shdr.sh_type != SHT_SYMTAB) {
27207 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
27208 }
27209
27210
27211 -static void read_relocs(FILE *fp)
27212 +static void read_relocs(FILE *fp, int use_real_mode)
27213 {
27214 - int i,j;
27215 + unsigned int i,j;
27216 + uint32_t base;
27217 +
27218 for (i = 0; i < ehdr.e_shnum; i++) {
27219 struct section *sec = &secs[i];
27220 if (sec->shdr.sh_type != SHT_REL) {
27221 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
27222 die("Cannot read symbol table: %s\n",
27223 strerror(errno));
27224 }
27225 + base = 0;
27226 +
27227 +#ifdef CONFIG_X86_32
27228 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
27229 + if (phdr[j].p_type != PT_LOAD )
27230 + continue;
27231 + 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)
27232 + continue;
27233 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
27234 + break;
27235 + }
27236 +#endif
27237 +
27238 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
27239 Elf32_Rel *rel = &sec->reltab[j];
27240 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27241 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27242 rel->r_info = elf32_to_cpu(rel->r_info);
27243 }
27244 }
27245 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27246
27247 static void print_absolute_symbols(void)
27248 {
27249 - int i;
27250 + unsigned int i;
27251 printf("Absolute symbols\n");
27252 printf(" Num: Value Size Type Bind Visibility Name\n");
27253 for (i = 0; i < ehdr.e_shnum; i++) {
27254 struct section *sec = &secs[i];
27255 char *sym_strtab;
27256 - int j;
27257 + unsigned int j;
27258
27259 if (sec->shdr.sh_type != SHT_SYMTAB) {
27260 continue;
27261 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27262
27263 static void print_absolute_relocs(void)
27264 {
27265 - int i, printed = 0;
27266 + unsigned int i, printed = 0;
27267
27268 for (i = 0; i < ehdr.e_shnum; i++) {
27269 struct section *sec = &secs[i];
27270 struct section *sec_applies, *sec_symtab;
27271 char *sym_strtab;
27272 Elf32_Sym *sh_symtab;
27273 - int j;
27274 + unsigned int j;
27275 if (sec->shdr.sh_type != SHT_REL) {
27276 continue;
27277 }
27278 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27279 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27280 int use_real_mode)
27281 {
27282 - int i;
27283 + unsigned int i;
27284 /* Walk through the relocations */
27285 for (i = 0; i < ehdr.e_shnum; i++) {
27286 char *sym_strtab;
27287 Elf32_Sym *sh_symtab;
27288 struct section *sec_applies, *sec_symtab;
27289 - int j;
27290 + unsigned int j;
27291 struct section *sec = &secs[i];
27292
27293 if (sec->shdr.sh_type != SHT_REL) {
27294 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27295 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27296 r_type = ELF32_R_TYPE(rel->r_info);
27297
27298 + if (!use_real_mode) {
27299 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27300 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27301 + continue;
27302 +
27303 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27304 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27305 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27306 + continue;
27307 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27308 + continue;
27309 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27310 + continue;
27311 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27312 + continue;
27313 +#endif
27314 + }
27315 +
27316 shn_abs = sym->st_shndx == SHN_ABS;
27317
27318 switch (r_type) {
27319 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27320
27321 static void emit_relocs(int as_text, int use_real_mode)
27322 {
27323 - int i;
27324 + unsigned int i;
27325 /* Count how many relocations I have and allocate space for them. */
27326 reloc_count = 0;
27327 walk_relocs(count_reloc, use_real_mode);
27328 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27329 fname, strerror(errno));
27330 }
27331 read_ehdr(fp);
27332 + read_phdrs(fp);
27333 read_shdrs(fp);
27334 read_strtabs(fp);
27335 read_symtabs(fp);
27336 - read_relocs(fp);
27337 + read_relocs(fp, use_real_mode);
27338 if (show_absolute_syms) {
27339 print_absolute_symbols();
27340 return 0;
27341 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27342 index fd14be1..e3c79c0 100644
27343 --- a/arch/x86/vdso/Makefile
27344 +++ b/arch/x86/vdso/Makefile
27345 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27346 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27347 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27348
27349 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27350 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27351 GCOV_PROFILE := n
27352
27353 #
27354 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27355 index 0faad64..39ef157 100644
27356 --- a/arch/x86/vdso/vdso32-setup.c
27357 +++ b/arch/x86/vdso/vdso32-setup.c
27358 @@ -25,6 +25,7 @@
27359 #include <asm/tlbflush.h>
27360 #include <asm/vdso.h>
27361 #include <asm/proto.h>
27362 +#include <asm/mman.h>
27363
27364 enum {
27365 VDSO_DISABLED = 0,
27366 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27367 void enable_sep_cpu(void)
27368 {
27369 int cpu = get_cpu();
27370 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27371 + struct tss_struct *tss = init_tss + cpu;
27372
27373 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27374 put_cpu();
27375 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27376 gate_vma.vm_start = FIXADDR_USER_START;
27377 gate_vma.vm_end = FIXADDR_USER_END;
27378 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27379 - gate_vma.vm_page_prot = __P101;
27380 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27381
27382 return 0;
27383 }
27384 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27385 if (compat)
27386 addr = VDSO_HIGH_BASE;
27387 else {
27388 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27389 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27390 if (IS_ERR_VALUE(addr)) {
27391 ret = addr;
27392 goto up_fail;
27393 }
27394 }
27395
27396 - current->mm->context.vdso = (void *)addr;
27397 + current->mm->context.vdso = addr;
27398
27399 if (compat_uses_vma || !compat) {
27400 /*
27401 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27402 }
27403
27404 current_thread_info()->sysenter_return =
27405 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27406 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27407
27408 up_fail:
27409 if (ret)
27410 - current->mm->context.vdso = NULL;
27411 + current->mm->context.vdso = 0;
27412
27413 up_write(&mm->mmap_sem);
27414
27415 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27416
27417 const char *arch_vma_name(struct vm_area_struct *vma)
27418 {
27419 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27420 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27421 return "[vdso]";
27422 +
27423 +#ifdef CONFIG_PAX_SEGMEXEC
27424 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27425 + return "[vdso]";
27426 +#endif
27427 +
27428 return NULL;
27429 }
27430
27431 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27432 * Check to see if the corresponding task was created in compat vdso
27433 * mode.
27434 */
27435 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27436 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27437 return &gate_vma;
27438 return NULL;
27439 }
27440 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27441 index 00aaf04..4a26505 100644
27442 --- a/arch/x86/vdso/vma.c
27443 +++ b/arch/x86/vdso/vma.c
27444 @@ -16,8 +16,6 @@
27445 #include <asm/vdso.h>
27446 #include <asm/page.h>
27447
27448 -unsigned int __read_mostly vdso_enabled = 1;
27449 -
27450 extern char vdso_start[], vdso_end[];
27451 extern unsigned short vdso_sync_cpuid;
27452
27453 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27454 * unaligned here as a result of stack start randomization.
27455 */
27456 addr = PAGE_ALIGN(addr);
27457 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27458
27459 return addr;
27460 }
27461 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27462 unsigned size)
27463 {
27464 struct mm_struct *mm = current->mm;
27465 - unsigned long addr;
27466 + unsigned long addr = 0;
27467 int ret;
27468
27469 - if (!vdso_enabled)
27470 - return 0;
27471 -
27472 down_write(&mm->mmap_sem);
27473 +
27474 +#ifdef CONFIG_PAX_RANDMMAP
27475 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27476 +#endif
27477 +
27478 addr = vdso_addr(mm->start_stack, size);
27479 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27480 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27481 if (IS_ERR_VALUE(addr)) {
27482 ret = addr;
27483 goto up_fail;
27484 }
27485
27486 - current->mm->context.vdso = (void *)addr;
27487 + mm->context.vdso = addr;
27488
27489 ret = install_special_mapping(mm, addr, size,
27490 VM_READ|VM_EXEC|
27491 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27492 pages);
27493 - if (ret) {
27494 - current->mm->context.vdso = NULL;
27495 - goto up_fail;
27496 - }
27497 + if (ret)
27498 + mm->context.vdso = 0;
27499
27500 up_fail:
27501 up_write(&mm->mmap_sem);
27502 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27503 vdsox32_size);
27504 }
27505 #endif
27506 -
27507 -static __init int vdso_setup(char *s)
27508 -{
27509 - vdso_enabled = simple_strtoul(s, NULL, 0);
27510 - return 0;
27511 -}
27512 -__setup("vdso=", vdso_setup);
27513 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27514 index c1461de..355f120 100644
27515 --- a/arch/x86/xen/enlighten.c
27516 +++ b/arch/x86/xen/enlighten.c
27517 @@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27518
27519 struct shared_info xen_dummy_shared_info;
27520
27521 -void *xen_initial_gdt;
27522 -
27523 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27524 __read_mostly int xen_have_vector_callback;
27525 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27526 @@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27527
27528 static void set_xen_basic_apic_ops(void)
27529 {
27530 - apic->read = xen_apic_read;
27531 - apic->write = xen_apic_write;
27532 - apic->icr_read = xen_apic_icr_read;
27533 - apic->icr_write = xen_apic_icr_write;
27534 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27535 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27536 - apic->set_apic_id = xen_set_apic_id;
27537 - apic->get_apic_id = xen_get_apic_id;
27538 + *(void **)&apic->read = xen_apic_read;
27539 + *(void **)&apic->write = xen_apic_write;
27540 + *(void **)&apic->icr_read = xen_apic_icr_read;
27541 + *(void **)&apic->icr_write = xen_apic_icr_write;
27542 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27543 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27544 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27545 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27546
27547 #ifdef CONFIG_SMP
27548 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27549 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27550 - apic->send_IPI_mask = xen_send_IPI_mask;
27551 - apic->send_IPI_all = xen_send_IPI_all;
27552 - apic->send_IPI_self = xen_send_IPI_self;
27553 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27554 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27555 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27556 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27557 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27558 #endif
27559 }
27560
27561 @@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27562 #endif
27563 };
27564
27565 -static void xen_reboot(int reason)
27566 +static __noreturn void xen_reboot(int reason)
27567 {
27568 struct sched_shutdown r = { .reason = reason };
27569
27570 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27571 - BUG();
27572 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27573 + BUG();
27574 }
27575
27576 -static void xen_restart(char *msg)
27577 +static __noreturn void xen_restart(char *msg)
27578 {
27579 xen_reboot(SHUTDOWN_reboot);
27580 }
27581
27582 -static void xen_emergency_restart(void)
27583 +static __noreturn void xen_emergency_restart(void)
27584 {
27585 xen_reboot(SHUTDOWN_reboot);
27586 }
27587
27588 -static void xen_machine_halt(void)
27589 +static __noreturn void xen_machine_halt(void)
27590 {
27591 xen_reboot(SHUTDOWN_poweroff);
27592 }
27593
27594 -static void xen_machine_power_off(void)
27595 +static __noreturn void xen_machine_power_off(void)
27596 {
27597 if (pm_power_off)
27598 pm_power_off();
27599 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27600 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27601
27602 /* Work out if we support NX */
27603 - x86_configure_nx();
27604 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27605 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27606 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27607 + unsigned l, h;
27608 +
27609 + __supported_pte_mask |= _PAGE_NX;
27610 + rdmsr(MSR_EFER, l, h);
27611 + l |= EFER_NX;
27612 + wrmsr(MSR_EFER, l, h);
27613 + }
27614 +#endif
27615
27616 xen_setup_features();
27617
27618 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27619
27620 machine_ops = xen_machine_ops;
27621
27622 - /*
27623 - * The only reliable way to retain the initial address of the
27624 - * percpu gdt_page is to remember it here, so we can go and
27625 - * mark it RW later, when the initial percpu area is freed.
27626 - */
27627 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27628 -
27629 xen_smp_init();
27630
27631 #ifdef CONFIG_ACPI_NUMA
27632 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27633 index dde1a3f..6b663e6 100644
27634 --- a/arch/x86/xen/mmu.c
27635 +++ b/arch/x86/xen/mmu.c
27636 @@ -1784,6 +1784,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27637 convert_pfn_mfn(init_level4_pgt);
27638 convert_pfn_mfn(level3_ident_pgt);
27639 convert_pfn_mfn(level3_kernel_pgt);
27640 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27641 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27642 + convert_pfn_mfn(level3_vmemmap_pgt);
27643
27644 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27645 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27646 @@ -1802,7 +1805,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27647 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27648 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27649 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27650 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27651 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27652 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27653 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27654 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27655 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27656 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27657
27658 @@ -1986,6 +1993,7 @@ static void __init xen_post_allocator_init(void)
27659 pv_mmu_ops.set_pud = xen_set_pud;
27660 #if PAGETABLE_LEVELS == 4
27661 pv_mmu_ops.set_pgd = xen_set_pgd;
27662 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27663 #endif
27664
27665 /* This will work as long as patching hasn't happened yet
27666 @@ -2067,6 +2075,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27667 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27668 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27669 .set_pgd = xen_set_pgd_hyper,
27670 + .set_pgd_batched = xen_set_pgd_hyper,
27671
27672 .alloc_pud = xen_alloc_pmd_init,
27673 .release_pud = xen_release_pmd_init,
27674 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27675 index f58dca7..ad21f52 100644
27676 --- a/arch/x86/xen/smp.c
27677 +++ b/arch/x86/xen/smp.c
27678 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27679 {
27680 BUG_ON(smp_processor_id() != 0);
27681 native_smp_prepare_boot_cpu();
27682 -
27683 - /* We've switched to the "real" per-cpu gdt, so make sure the
27684 - old memory can be recycled */
27685 - make_lowmem_page_readwrite(xen_initial_gdt);
27686 -
27687 xen_filter_cpu_maps();
27688 xen_setup_vcpu_info_placement();
27689 }
27690 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27691 gdt = get_cpu_gdt_table(cpu);
27692
27693 ctxt->flags = VGCF_IN_KERNEL;
27694 - ctxt->user_regs.ds = __USER_DS;
27695 - ctxt->user_regs.es = __USER_DS;
27696 + ctxt->user_regs.ds = __KERNEL_DS;
27697 + ctxt->user_regs.es = __KERNEL_DS;
27698 ctxt->user_regs.ss = __KERNEL_DS;
27699 #ifdef CONFIG_X86_32
27700 ctxt->user_regs.fs = __KERNEL_PERCPU;
27701 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27702 + savesegment(gs, ctxt->user_regs.gs);
27703 #else
27704 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27705 #endif
27706 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27707 int rc;
27708
27709 per_cpu(current_task, cpu) = idle;
27710 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27711 #ifdef CONFIG_X86_32
27712 irq_ctx_init(cpu);
27713 #else
27714 clear_tsk_thread_flag(idle, TIF_FORK);
27715 - per_cpu(kernel_stack, cpu) =
27716 - (unsigned long)task_stack_page(idle) -
27717 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27718 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27719 #endif
27720 xen_setup_runstate_info(cpu);
27721 xen_setup_timer(cpu);
27722 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27723 index f9643fc..602e8af 100644
27724 --- a/arch/x86/xen/xen-asm_32.S
27725 +++ b/arch/x86/xen/xen-asm_32.S
27726 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27727 ESP_OFFSET=4 # bytes pushed onto stack
27728
27729 /*
27730 - * Store vcpu_info pointer for easy access. Do it this way to
27731 - * avoid having to reload %fs
27732 + * Store vcpu_info pointer for easy access.
27733 */
27734 #ifdef CONFIG_SMP
27735 - GET_THREAD_INFO(%eax)
27736 - movl TI_cpu(%eax), %eax
27737 - movl __per_cpu_offset(,%eax,4), %eax
27738 - mov xen_vcpu(%eax), %eax
27739 + push %fs
27740 + mov $(__KERNEL_PERCPU), %eax
27741 + mov %eax, %fs
27742 + mov PER_CPU_VAR(xen_vcpu), %eax
27743 + pop %fs
27744 #else
27745 movl xen_vcpu, %eax
27746 #endif
27747 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27748 index aaa7291..3f77960 100644
27749 --- a/arch/x86/xen/xen-head.S
27750 +++ b/arch/x86/xen/xen-head.S
27751 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27752 #ifdef CONFIG_X86_32
27753 mov %esi,xen_start_info
27754 mov $init_thread_union+THREAD_SIZE,%esp
27755 +#ifdef CONFIG_SMP
27756 + movl $cpu_gdt_table,%edi
27757 + movl $__per_cpu_load,%eax
27758 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27759 + rorl $16,%eax
27760 + movb %al,__KERNEL_PERCPU + 4(%edi)
27761 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27762 + movl $__per_cpu_end - 1,%eax
27763 + subl $__per_cpu_start,%eax
27764 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27765 +#endif
27766 #else
27767 mov %rsi,xen_start_info
27768 mov $init_thread_union+THREAD_SIZE,%rsp
27769 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27770 index 202d4c1..99b072a 100644
27771 --- a/arch/x86/xen/xen-ops.h
27772 +++ b/arch/x86/xen/xen-ops.h
27773 @@ -10,8 +10,6 @@
27774 extern const char xen_hypervisor_callback[];
27775 extern const char xen_failsafe_callback[];
27776
27777 -extern void *xen_initial_gdt;
27778 -
27779 struct trap_info;
27780 void xen_copy_trap_info(struct trap_info *traps);
27781
27782 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27783 index 525bd3d..ef888b1 100644
27784 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27785 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27786 @@ -119,9 +119,9 @@
27787 ----------------------------------------------------------------------*/
27788
27789 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27790 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27791 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27792 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27793 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27794
27795 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27796 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27797 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27798 index 2f33760..835e50a 100644
27799 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27800 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27801 @@ -11,6 +11,7 @@
27802 #ifndef _XTENSA_CORE_H
27803 #define _XTENSA_CORE_H
27804
27805 +#include <linux/const.h>
27806
27807 /****************************************************************************
27808 Parameters Useful for Any Code, USER or PRIVILEGED
27809 @@ -112,9 +113,9 @@
27810 ----------------------------------------------------------------------*/
27811
27812 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27813 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27814 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27815 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27816 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27817
27818 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27819 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27820 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27821 index af00795..2bb8105 100644
27822 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27823 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27824 @@ -11,6 +11,7 @@
27825 #ifndef _XTENSA_CORE_CONFIGURATION_H
27826 #define _XTENSA_CORE_CONFIGURATION_H
27827
27828 +#include <linux/const.h>
27829
27830 /****************************************************************************
27831 Parameters Useful for Any Code, USER or PRIVILEGED
27832 @@ -118,9 +119,9 @@
27833 ----------------------------------------------------------------------*/
27834
27835 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27836 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27837 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27838 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27839 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27840
27841 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27842 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27843 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27844 index 58916af..9cb880b 100644
27845 --- a/block/blk-iopoll.c
27846 +++ b/block/blk-iopoll.c
27847 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27848 }
27849 EXPORT_SYMBOL(blk_iopoll_complete);
27850
27851 -static void blk_iopoll_softirq(struct softirq_action *h)
27852 +static void blk_iopoll_softirq(void)
27853 {
27854 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27855 int rearm = 0, budget = blk_iopoll_budget;
27856 diff --git a/block/blk-map.c b/block/blk-map.c
27857 index 623e1cd..ca1e109 100644
27858 --- a/block/blk-map.c
27859 +++ b/block/blk-map.c
27860 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27861 if (!len || !kbuf)
27862 return -EINVAL;
27863
27864 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27865 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27866 if (do_copy)
27867 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27868 else
27869 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27870 index 467c8de..4bddc6d 100644
27871 --- a/block/blk-softirq.c
27872 +++ b/block/blk-softirq.c
27873 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27874 * Softirq action handler - move entries to local list and loop over them
27875 * while passing them to the queue registered handler.
27876 */
27877 -static void blk_done_softirq(struct softirq_action *h)
27878 +static void blk_done_softirq(void)
27879 {
27880 struct list_head *cpu_list, local_list;
27881
27882 diff --git a/block/bsg.c b/block/bsg.c
27883 index ff64ae3..593560c 100644
27884 --- a/block/bsg.c
27885 +++ b/block/bsg.c
27886 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27887 struct sg_io_v4 *hdr, struct bsg_device *bd,
27888 fmode_t has_write_perm)
27889 {
27890 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27891 + unsigned char *cmdptr;
27892 +
27893 if (hdr->request_len > BLK_MAX_CDB) {
27894 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27895 if (!rq->cmd)
27896 return -ENOMEM;
27897 - }
27898 + cmdptr = rq->cmd;
27899 + } else
27900 + cmdptr = tmpcmd;
27901
27902 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27903 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27904 hdr->request_len))
27905 return -EFAULT;
27906
27907 + if (cmdptr != rq->cmd)
27908 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27909 +
27910 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27911 if (blk_verify_command(rq->cmd, has_write_perm))
27912 return -EPERM;
27913 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27914 index 7c668c8..db3521c 100644
27915 --- a/block/compat_ioctl.c
27916 +++ b/block/compat_ioctl.c
27917 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27918 err |= __get_user(f->spec1, &uf->spec1);
27919 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27920 err |= __get_user(name, &uf->name);
27921 - f->name = compat_ptr(name);
27922 + f->name = (void __force_kernel *)compat_ptr(name);
27923 if (err) {
27924 err = -EFAULT;
27925 goto out;
27926 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27927 index 6296b40..417c00f 100644
27928 --- a/block/partitions/efi.c
27929 +++ b/block/partitions/efi.c
27930 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27931 if (!gpt)
27932 return NULL;
27933
27934 + if (!le32_to_cpu(gpt->num_partition_entries))
27935 + return NULL;
27936 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27937 + if (!pte)
27938 + return NULL;
27939 +
27940 count = le32_to_cpu(gpt->num_partition_entries) *
27941 le32_to_cpu(gpt->sizeof_partition_entry);
27942 - if (!count)
27943 - return NULL;
27944 - pte = kzalloc(count, GFP_KERNEL);
27945 - if (!pte)
27946 - return NULL;
27947 -
27948 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27949 (u8 *) pte,
27950 count) < count) {
27951 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27952 index 9a87daa..fb17486 100644
27953 --- a/block/scsi_ioctl.c
27954 +++ b/block/scsi_ioctl.c
27955 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27956 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27957 struct sg_io_hdr *hdr, fmode_t mode)
27958 {
27959 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27960 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27961 + unsigned char *cmdptr;
27962 +
27963 + if (rq->cmd != rq->__cmd)
27964 + cmdptr = rq->cmd;
27965 + else
27966 + cmdptr = tmpcmd;
27967 +
27968 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27969 return -EFAULT;
27970 +
27971 + if (cmdptr != rq->cmd)
27972 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27973 +
27974 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27975 return -EPERM;
27976
27977 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27978 int err;
27979 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27980 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27981 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27982 + unsigned char *cmdptr;
27983
27984 if (!sic)
27985 return -EINVAL;
27986 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27987 */
27988 err = -EFAULT;
27989 rq->cmd_len = cmdlen;
27990 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27991 +
27992 + if (rq->cmd != rq->__cmd)
27993 + cmdptr = rq->cmd;
27994 + else
27995 + cmdptr = tmpcmd;
27996 +
27997 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27998 goto error;
27999
28000 + if (rq->cmd != cmdptr)
28001 + memcpy(rq->cmd, cmdptr, cmdlen);
28002 +
28003 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
28004 goto error;
28005
28006 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
28007 index 7bdd61b..afec999 100644
28008 --- a/crypto/cryptd.c
28009 +++ b/crypto/cryptd.c
28010 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
28011
28012 struct cryptd_blkcipher_request_ctx {
28013 crypto_completion_t complete;
28014 -};
28015 +} __no_const;
28016
28017 struct cryptd_hash_ctx {
28018 struct crypto_shash *child;
28019 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
28020
28021 struct cryptd_aead_request_ctx {
28022 crypto_completion_t complete;
28023 -};
28024 +} __no_const;
28025
28026 static void cryptd_queue_worker(struct work_struct *work);
28027
28028 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
28029 index e6defd8..c26a225 100644
28030 --- a/drivers/acpi/apei/cper.c
28031 +++ b/drivers/acpi/apei/cper.c
28032 @@ -38,12 +38,12 @@
28033 */
28034 u64 cper_next_record_id(void)
28035 {
28036 - static atomic64_t seq;
28037 + static atomic64_unchecked_t seq;
28038
28039 - if (!atomic64_read(&seq))
28040 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
28041 + if (!atomic64_read_unchecked(&seq))
28042 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
28043
28044 - return atomic64_inc_return(&seq);
28045 + return atomic64_inc_return_unchecked(&seq);
28046 }
28047 EXPORT_SYMBOL_GPL(cper_next_record_id);
28048
28049 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
28050 index 7586544..636a2f0 100644
28051 --- a/drivers/acpi/ec_sys.c
28052 +++ b/drivers/acpi/ec_sys.c
28053 @@ -12,6 +12,7 @@
28054 #include <linux/acpi.h>
28055 #include <linux/debugfs.h>
28056 #include <linux/module.h>
28057 +#include <linux/uaccess.h>
28058 #include "internal.h"
28059
28060 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
28061 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28062 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
28063 */
28064 unsigned int size = EC_SPACE_SIZE;
28065 - u8 *data = (u8 *) buf;
28066 + u8 data;
28067 loff_t init_off = *off;
28068 int err = 0;
28069
28070 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28071 size = count;
28072
28073 while (size) {
28074 - err = ec_read(*off, &data[*off - init_off]);
28075 + err = ec_read(*off, &data);
28076 if (err)
28077 return err;
28078 + if (put_user(data, &buf[*off - init_off]))
28079 + return -EFAULT;
28080 *off += 1;
28081 size--;
28082 }
28083 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28084
28085 unsigned int size = count;
28086 loff_t init_off = *off;
28087 - u8 *data = (u8 *) buf;
28088 int err = 0;
28089
28090 if (*off >= EC_SPACE_SIZE)
28091 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28092 }
28093
28094 while (size) {
28095 - u8 byte_write = data[*off - init_off];
28096 + u8 byte_write;
28097 + if (get_user(byte_write, &buf[*off - init_off]))
28098 + return -EFAULT;
28099 err = ec_write(*off, byte_write);
28100 if (err)
28101 return err;
28102 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
28103 index 251c7b62..000462d 100644
28104 --- a/drivers/acpi/proc.c
28105 +++ b/drivers/acpi/proc.c
28106 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
28107 size_t count, loff_t * ppos)
28108 {
28109 struct list_head *node, *next;
28110 - char strbuf[5];
28111 - char str[5] = "";
28112 - unsigned int len = count;
28113 + char strbuf[5] = {0};
28114
28115 - if (len > 4)
28116 - len = 4;
28117 - if (len < 0)
28118 + if (count > 4)
28119 + count = 4;
28120 + if (copy_from_user(strbuf, buffer, count))
28121 return -EFAULT;
28122 -
28123 - if (copy_from_user(strbuf, buffer, len))
28124 - return -EFAULT;
28125 - strbuf[len] = '\0';
28126 - sscanf(strbuf, "%s", str);
28127 + strbuf[count] = '\0';
28128
28129 mutex_lock(&acpi_device_lock);
28130 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
28131 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
28132 if (!dev->wakeup.flags.valid)
28133 continue;
28134
28135 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
28136 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
28137 if (device_can_wakeup(&dev->dev)) {
28138 bool enable = !device_may_wakeup(&dev->dev);
28139 device_set_wakeup_enable(&dev->dev, enable);
28140 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
28141 index bebe17f..3d0c1d8 100644
28142 --- a/drivers/acpi/processor_driver.c
28143 +++ b/drivers/acpi/processor_driver.c
28144 @@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
28145 return 0;
28146 #endif
28147
28148 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
28149 + BUG_ON(pr->id >= nr_cpu_ids);
28150
28151 /*
28152 * Buggy BIOS check
28153 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
28154 index 8e1039c..ea9cbd4 100644
28155 --- a/drivers/ata/libata-core.c
28156 +++ b/drivers/ata/libata-core.c
28157 @@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
28158 struct ata_port *ap;
28159 unsigned int tag;
28160
28161 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28162 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28163 ap = qc->ap;
28164
28165 qc->flags = 0;
28166 @@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
28167 struct ata_port *ap;
28168 struct ata_link *link;
28169
28170 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28171 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28172 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
28173 ap = qc->ap;
28174 link = qc->dev->link;
28175 @@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28176 return;
28177
28178 spin_lock(&lock);
28179 + pax_open_kernel();
28180
28181 for (cur = ops->inherits; cur; cur = cur->inherits) {
28182 void **inherit = (void **)cur;
28183 @@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28184 if (IS_ERR(*pp))
28185 *pp = NULL;
28186
28187 - ops->inherits = NULL;
28188 + *(struct ata_port_operations **)&ops->inherits = NULL;
28189
28190 + pax_close_kernel();
28191 spin_unlock(&lock);
28192 }
28193
28194 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
28195 index bfaa5cb..3ba1cc3 100644
28196 --- a/drivers/ata/pata_arasan_cf.c
28197 +++ b/drivers/ata/pata_arasan_cf.c
28198 @@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
28199 /* Handle platform specific quirks */
28200 if (pdata->quirk) {
28201 if (pdata->quirk & CF_BROKEN_PIO) {
28202 - ap->ops->set_piomode = NULL;
28203 + pax_open_kernel();
28204 + *(void **)&ap->ops->set_piomode = NULL;
28205 + pax_close_kernel();
28206 ap->pio_mask = 0;
28207 }
28208 if (pdata->quirk & CF_BROKEN_MWDMA)
28209 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
28210 index f9b983a..887b9d8 100644
28211 --- a/drivers/atm/adummy.c
28212 +++ b/drivers/atm/adummy.c
28213 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
28214 vcc->pop(vcc, skb);
28215 else
28216 dev_kfree_skb_any(skb);
28217 - atomic_inc(&vcc->stats->tx);
28218 + atomic_inc_unchecked(&vcc->stats->tx);
28219
28220 return 0;
28221 }
28222 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
28223 index 89b30f3..7964211d4 100644
28224 --- a/drivers/atm/ambassador.c
28225 +++ b/drivers/atm/ambassador.c
28226 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
28227 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
28228
28229 // VC layer stats
28230 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28231 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28232
28233 // free the descriptor
28234 kfree (tx_descr);
28235 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28236 dump_skb ("<<<", vc, skb);
28237
28238 // VC layer stats
28239 - atomic_inc(&atm_vcc->stats->rx);
28240 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28241 __net_timestamp(skb);
28242 // end of our responsibility
28243 atm_vcc->push (atm_vcc, skb);
28244 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28245 } else {
28246 PRINTK (KERN_INFO, "dropped over-size frame");
28247 // should we count this?
28248 - atomic_inc(&atm_vcc->stats->rx_drop);
28249 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28250 }
28251
28252 } else {
28253 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28254 }
28255
28256 if (check_area (skb->data, skb->len)) {
28257 - atomic_inc(&atm_vcc->stats->tx_err);
28258 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28259 return -ENOMEM; // ?
28260 }
28261
28262 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28263 index b22d71c..d6e1049 100644
28264 --- a/drivers/atm/atmtcp.c
28265 +++ b/drivers/atm/atmtcp.c
28266 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28267 if (vcc->pop) vcc->pop(vcc,skb);
28268 else dev_kfree_skb(skb);
28269 if (dev_data) return 0;
28270 - atomic_inc(&vcc->stats->tx_err);
28271 + atomic_inc_unchecked(&vcc->stats->tx_err);
28272 return -ENOLINK;
28273 }
28274 size = skb->len+sizeof(struct atmtcp_hdr);
28275 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28276 if (!new_skb) {
28277 if (vcc->pop) vcc->pop(vcc,skb);
28278 else dev_kfree_skb(skb);
28279 - atomic_inc(&vcc->stats->tx_err);
28280 + atomic_inc_unchecked(&vcc->stats->tx_err);
28281 return -ENOBUFS;
28282 }
28283 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28284 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28285 if (vcc->pop) vcc->pop(vcc,skb);
28286 else dev_kfree_skb(skb);
28287 out_vcc->push(out_vcc,new_skb);
28288 - atomic_inc(&vcc->stats->tx);
28289 - atomic_inc(&out_vcc->stats->rx);
28290 + atomic_inc_unchecked(&vcc->stats->tx);
28291 + atomic_inc_unchecked(&out_vcc->stats->rx);
28292 return 0;
28293 }
28294
28295 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28296 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28297 read_unlock(&vcc_sklist_lock);
28298 if (!out_vcc) {
28299 - atomic_inc(&vcc->stats->tx_err);
28300 + atomic_inc_unchecked(&vcc->stats->tx_err);
28301 goto done;
28302 }
28303 skb_pull(skb,sizeof(struct atmtcp_hdr));
28304 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28305 __net_timestamp(new_skb);
28306 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28307 out_vcc->push(out_vcc,new_skb);
28308 - atomic_inc(&vcc->stats->tx);
28309 - atomic_inc(&out_vcc->stats->rx);
28310 + atomic_inc_unchecked(&vcc->stats->tx);
28311 + atomic_inc_unchecked(&out_vcc->stats->rx);
28312 done:
28313 if (vcc->pop) vcc->pop(vcc,skb);
28314 else dev_kfree_skb(skb);
28315 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28316 index 2059ee4..faf51c7 100644
28317 --- a/drivers/atm/eni.c
28318 +++ b/drivers/atm/eni.c
28319 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28320 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28321 vcc->dev->number);
28322 length = 0;
28323 - atomic_inc(&vcc->stats->rx_err);
28324 + atomic_inc_unchecked(&vcc->stats->rx_err);
28325 }
28326 else {
28327 length = ATM_CELL_SIZE-1; /* no HEC */
28328 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28329 size);
28330 }
28331 eff = length = 0;
28332 - atomic_inc(&vcc->stats->rx_err);
28333 + atomic_inc_unchecked(&vcc->stats->rx_err);
28334 }
28335 else {
28336 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28337 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28338 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28339 vcc->dev->number,vcc->vci,length,size << 2,descr);
28340 length = eff = 0;
28341 - atomic_inc(&vcc->stats->rx_err);
28342 + atomic_inc_unchecked(&vcc->stats->rx_err);
28343 }
28344 }
28345 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28346 @@ -767,7 +767,7 @@ rx_dequeued++;
28347 vcc->push(vcc,skb);
28348 pushed++;
28349 }
28350 - atomic_inc(&vcc->stats->rx);
28351 + atomic_inc_unchecked(&vcc->stats->rx);
28352 }
28353 wake_up(&eni_dev->rx_wait);
28354 }
28355 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28356 PCI_DMA_TODEVICE);
28357 if (vcc->pop) vcc->pop(vcc,skb);
28358 else dev_kfree_skb_irq(skb);
28359 - atomic_inc(&vcc->stats->tx);
28360 + atomic_inc_unchecked(&vcc->stats->tx);
28361 wake_up(&eni_dev->tx_wait);
28362 dma_complete++;
28363 }
28364 @@ -1567,7 +1567,7 @@ tx_complete++;
28365 /*--------------------------------- entries ---------------------------------*/
28366
28367
28368 -static const char *media_name[] __devinitdata = {
28369 +static const char *media_name[] __devinitconst = {
28370 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28371 "UTP", "05?", "06?", "07?", /* 4- 7 */
28372 "TAXI","09?", "10?", "11?", /* 8-11 */
28373 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28374 index 86fed1b..6dc4721 100644
28375 --- a/drivers/atm/firestream.c
28376 +++ b/drivers/atm/firestream.c
28377 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28378 }
28379 }
28380
28381 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28382 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28383
28384 fs_dprintk (FS_DEBUG_TXMEM, "i");
28385 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28386 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28387 #endif
28388 skb_put (skb, qe->p1 & 0xffff);
28389 ATM_SKB(skb)->vcc = atm_vcc;
28390 - atomic_inc(&atm_vcc->stats->rx);
28391 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28392 __net_timestamp(skb);
28393 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28394 atm_vcc->push (atm_vcc, skb);
28395 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28396 kfree (pe);
28397 }
28398 if (atm_vcc)
28399 - atomic_inc(&atm_vcc->stats->rx_drop);
28400 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28401 break;
28402 case 0x1f: /* Reassembly abort: no buffers. */
28403 /* Silently increment error counter. */
28404 if (atm_vcc)
28405 - atomic_inc(&atm_vcc->stats->rx_drop);
28406 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28407 break;
28408 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28409 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28410 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28411 index 361f5ae..7fc552d 100644
28412 --- a/drivers/atm/fore200e.c
28413 +++ b/drivers/atm/fore200e.c
28414 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28415 #endif
28416 /* check error condition */
28417 if (*entry->status & STATUS_ERROR)
28418 - atomic_inc(&vcc->stats->tx_err);
28419 + atomic_inc_unchecked(&vcc->stats->tx_err);
28420 else
28421 - atomic_inc(&vcc->stats->tx);
28422 + atomic_inc_unchecked(&vcc->stats->tx);
28423 }
28424 }
28425
28426 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28427 if (skb == NULL) {
28428 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28429
28430 - atomic_inc(&vcc->stats->rx_drop);
28431 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28432 return -ENOMEM;
28433 }
28434
28435 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28436
28437 dev_kfree_skb_any(skb);
28438
28439 - atomic_inc(&vcc->stats->rx_drop);
28440 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28441 return -ENOMEM;
28442 }
28443
28444 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28445
28446 vcc->push(vcc, skb);
28447 - atomic_inc(&vcc->stats->rx);
28448 + atomic_inc_unchecked(&vcc->stats->rx);
28449
28450 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28451
28452 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28453 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28454 fore200e->atm_dev->number,
28455 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28456 - atomic_inc(&vcc->stats->rx_err);
28457 + atomic_inc_unchecked(&vcc->stats->rx_err);
28458 }
28459 }
28460
28461 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28462 goto retry_here;
28463 }
28464
28465 - atomic_inc(&vcc->stats->tx_err);
28466 + atomic_inc_unchecked(&vcc->stats->tx_err);
28467
28468 fore200e->tx_sat++;
28469 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28470 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28471 index b182c2f..1c6fa8a 100644
28472 --- a/drivers/atm/he.c
28473 +++ b/drivers/atm/he.c
28474 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28475
28476 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28477 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28478 - atomic_inc(&vcc->stats->rx_drop);
28479 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28480 goto return_host_buffers;
28481 }
28482
28483 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28484 RBRQ_LEN_ERR(he_dev->rbrq_head)
28485 ? "LEN_ERR" : "",
28486 vcc->vpi, vcc->vci);
28487 - atomic_inc(&vcc->stats->rx_err);
28488 + atomic_inc_unchecked(&vcc->stats->rx_err);
28489 goto return_host_buffers;
28490 }
28491
28492 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28493 vcc->push(vcc, skb);
28494 spin_lock(&he_dev->global_lock);
28495
28496 - atomic_inc(&vcc->stats->rx);
28497 + atomic_inc_unchecked(&vcc->stats->rx);
28498
28499 return_host_buffers:
28500 ++pdus_assembled;
28501 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28502 tpd->vcc->pop(tpd->vcc, tpd->skb);
28503 else
28504 dev_kfree_skb_any(tpd->skb);
28505 - atomic_inc(&tpd->vcc->stats->tx_err);
28506 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28507 }
28508 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28509 return;
28510 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28511 vcc->pop(vcc, skb);
28512 else
28513 dev_kfree_skb_any(skb);
28514 - atomic_inc(&vcc->stats->tx_err);
28515 + atomic_inc_unchecked(&vcc->stats->tx_err);
28516 return -EINVAL;
28517 }
28518
28519 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28520 vcc->pop(vcc, skb);
28521 else
28522 dev_kfree_skb_any(skb);
28523 - atomic_inc(&vcc->stats->tx_err);
28524 + atomic_inc_unchecked(&vcc->stats->tx_err);
28525 return -EINVAL;
28526 }
28527 #endif
28528 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28529 vcc->pop(vcc, skb);
28530 else
28531 dev_kfree_skb_any(skb);
28532 - atomic_inc(&vcc->stats->tx_err);
28533 + atomic_inc_unchecked(&vcc->stats->tx_err);
28534 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28535 return -ENOMEM;
28536 }
28537 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28538 vcc->pop(vcc, skb);
28539 else
28540 dev_kfree_skb_any(skb);
28541 - atomic_inc(&vcc->stats->tx_err);
28542 + atomic_inc_unchecked(&vcc->stats->tx_err);
28543 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28544 return -ENOMEM;
28545 }
28546 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28547 __enqueue_tpd(he_dev, tpd, cid);
28548 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28549
28550 - atomic_inc(&vcc->stats->tx);
28551 + atomic_inc_unchecked(&vcc->stats->tx);
28552
28553 return 0;
28554 }
28555 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28556 index 7d01c2a..4e3ac01 100644
28557 --- a/drivers/atm/horizon.c
28558 +++ b/drivers/atm/horizon.c
28559 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28560 {
28561 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28562 // VC layer stats
28563 - atomic_inc(&vcc->stats->rx);
28564 + atomic_inc_unchecked(&vcc->stats->rx);
28565 __net_timestamp(skb);
28566 // end of our responsibility
28567 vcc->push (vcc, skb);
28568 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28569 dev->tx_iovec = NULL;
28570
28571 // VC layer stats
28572 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28573 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28574
28575 // free the skb
28576 hrz_kfree_skb (skb);
28577 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28578 index 8974bd2..b856f85 100644
28579 --- a/drivers/atm/idt77252.c
28580 +++ b/drivers/atm/idt77252.c
28581 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28582 else
28583 dev_kfree_skb(skb);
28584
28585 - atomic_inc(&vcc->stats->tx);
28586 + atomic_inc_unchecked(&vcc->stats->tx);
28587 }
28588
28589 atomic_dec(&scq->used);
28590 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28591 if ((sb = dev_alloc_skb(64)) == NULL) {
28592 printk("%s: Can't allocate buffers for aal0.\n",
28593 card->name);
28594 - atomic_add(i, &vcc->stats->rx_drop);
28595 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28596 break;
28597 }
28598 if (!atm_charge(vcc, sb->truesize)) {
28599 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28600 card->name);
28601 - atomic_add(i - 1, &vcc->stats->rx_drop);
28602 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28603 dev_kfree_skb(sb);
28604 break;
28605 }
28606 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28607 ATM_SKB(sb)->vcc = vcc;
28608 __net_timestamp(sb);
28609 vcc->push(vcc, sb);
28610 - atomic_inc(&vcc->stats->rx);
28611 + atomic_inc_unchecked(&vcc->stats->rx);
28612
28613 cell += ATM_CELL_PAYLOAD;
28614 }
28615 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28616 "(CDC: %08x)\n",
28617 card->name, len, rpp->len, readl(SAR_REG_CDC));
28618 recycle_rx_pool_skb(card, rpp);
28619 - atomic_inc(&vcc->stats->rx_err);
28620 + atomic_inc_unchecked(&vcc->stats->rx_err);
28621 return;
28622 }
28623 if (stat & SAR_RSQE_CRC) {
28624 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28625 recycle_rx_pool_skb(card, rpp);
28626 - atomic_inc(&vcc->stats->rx_err);
28627 + atomic_inc_unchecked(&vcc->stats->rx_err);
28628 return;
28629 }
28630 if (skb_queue_len(&rpp->queue) > 1) {
28631 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28632 RXPRINTK("%s: Can't alloc RX skb.\n",
28633 card->name);
28634 recycle_rx_pool_skb(card, rpp);
28635 - atomic_inc(&vcc->stats->rx_err);
28636 + atomic_inc_unchecked(&vcc->stats->rx_err);
28637 return;
28638 }
28639 if (!atm_charge(vcc, skb->truesize)) {
28640 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28641 __net_timestamp(skb);
28642
28643 vcc->push(vcc, skb);
28644 - atomic_inc(&vcc->stats->rx);
28645 + atomic_inc_unchecked(&vcc->stats->rx);
28646
28647 return;
28648 }
28649 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28650 __net_timestamp(skb);
28651
28652 vcc->push(vcc, skb);
28653 - atomic_inc(&vcc->stats->rx);
28654 + atomic_inc_unchecked(&vcc->stats->rx);
28655
28656 if (skb->truesize > SAR_FB_SIZE_3)
28657 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28658 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28659 if (vcc->qos.aal != ATM_AAL0) {
28660 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28661 card->name, vpi, vci);
28662 - atomic_inc(&vcc->stats->rx_drop);
28663 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28664 goto drop;
28665 }
28666
28667 if ((sb = dev_alloc_skb(64)) == NULL) {
28668 printk("%s: Can't allocate buffers for AAL0.\n",
28669 card->name);
28670 - atomic_inc(&vcc->stats->rx_err);
28671 + atomic_inc_unchecked(&vcc->stats->rx_err);
28672 goto drop;
28673 }
28674
28675 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28676 ATM_SKB(sb)->vcc = vcc;
28677 __net_timestamp(sb);
28678 vcc->push(vcc, sb);
28679 - atomic_inc(&vcc->stats->rx);
28680 + atomic_inc_unchecked(&vcc->stats->rx);
28681
28682 drop:
28683 skb_pull(queue, 64);
28684 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28685
28686 if (vc == NULL) {
28687 printk("%s: NULL connection in send().\n", card->name);
28688 - atomic_inc(&vcc->stats->tx_err);
28689 + atomic_inc_unchecked(&vcc->stats->tx_err);
28690 dev_kfree_skb(skb);
28691 return -EINVAL;
28692 }
28693 if (!test_bit(VCF_TX, &vc->flags)) {
28694 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28695 - atomic_inc(&vcc->stats->tx_err);
28696 + atomic_inc_unchecked(&vcc->stats->tx_err);
28697 dev_kfree_skb(skb);
28698 return -EINVAL;
28699 }
28700 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28701 break;
28702 default:
28703 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28704 - atomic_inc(&vcc->stats->tx_err);
28705 + atomic_inc_unchecked(&vcc->stats->tx_err);
28706 dev_kfree_skb(skb);
28707 return -EINVAL;
28708 }
28709
28710 if (skb_shinfo(skb)->nr_frags != 0) {
28711 printk("%s: No scatter-gather yet.\n", card->name);
28712 - atomic_inc(&vcc->stats->tx_err);
28713 + atomic_inc_unchecked(&vcc->stats->tx_err);
28714 dev_kfree_skb(skb);
28715 return -EINVAL;
28716 }
28717 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28718
28719 err = queue_skb(card, vc, skb, oam);
28720 if (err) {
28721 - atomic_inc(&vcc->stats->tx_err);
28722 + atomic_inc_unchecked(&vcc->stats->tx_err);
28723 dev_kfree_skb(skb);
28724 return err;
28725 }
28726 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28727 skb = dev_alloc_skb(64);
28728 if (!skb) {
28729 printk("%s: Out of memory in send_oam().\n", card->name);
28730 - atomic_inc(&vcc->stats->tx_err);
28731 + atomic_inc_unchecked(&vcc->stats->tx_err);
28732 return -ENOMEM;
28733 }
28734 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28735 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28736 index 96cce6d..62c3ec5 100644
28737 --- a/drivers/atm/iphase.c
28738 +++ b/drivers/atm/iphase.c
28739 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28740 status = (u_short) (buf_desc_ptr->desc_mode);
28741 if (status & (RX_CER | RX_PTE | RX_OFL))
28742 {
28743 - atomic_inc(&vcc->stats->rx_err);
28744 + atomic_inc_unchecked(&vcc->stats->rx_err);
28745 IF_ERR(printk("IA: bad packet, dropping it");)
28746 if (status & RX_CER) {
28747 IF_ERR(printk(" cause: packet CRC error\n");)
28748 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28749 len = dma_addr - buf_addr;
28750 if (len > iadev->rx_buf_sz) {
28751 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28752 - atomic_inc(&vcc->stats->rx_err);
28753 + atomic_inc_unchecked(&vcc->stats->rx_err);
28754 goto out_free_desc;
28755 }
28756
28757 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28758 ia_vcc = INPH_IA_VCC(vcc);
28759 if (ia_vcc == NULL)
28760 {
28761 - atomic_inc(&vcc->stats->rx_err);
28762 + atomic_inc_unchecked(&vcc->stats->rx_err);
28763 atm_return(vcc, skb->truesize);
28764 dev_kfree_skb_any(skb);
28765 goto INCR_DLE;
28766 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28767 if ((length > iadev->rx_buf_sz) || (length >
28768 (skb->len - sizeof(struct cpcs_trailer))))
28769 {
28770 - atomic_inc(&vcc->stats->rx_err);
28771 + atomic_inc_unchecked(&vcc->stats->rx_err);
28772 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28773 length, skb->len);)
28774 atm_return(vcc, skb->truesize);
28775 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28776
28777 IF_RX(printk("rx_dle_intr: skb push");)
28778 vcc->push(vcc,skb);
28779 - atomic_inc(&vcc->stats->rx);
28780 + atomic_inc_unchecked(&vcc->stats->rx);
28781 iadev->rx_pkt_cnt++;
28782 }
28783 INCR_DLE:
28784 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28785 {
28786 struct k_sonet_stats *stats;
28787 stats = &PRIV(_ia_dev[board])->sonet_stats;
28788 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28789 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28790 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28791 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28792 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28793 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28794 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28795 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28796 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28797 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28798 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28799 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28800 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28801 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28802 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28803 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28804 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28805 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28806 }
28807 ia_cmds.status = 0;
28808 break;
28809 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28810 if ((desc == 0) || (desc > iadev->num_tx_desc))
28811 {
28812 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28813 - atomic_inc(&vcc->stats->tx);
28814 + atomic_inc_unchecked(&vcc->stats->tx);
28815 if (vcc->pop)
28816 vcc->pop(vcc, skb);
28817 else
28818 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28819 ATM_DESC(skb) = vcc->vci;
28820 skb_queue_tail(&iadev->tx_dma_q, skb);
28821
28822 - atomic_inc(&vcc->stats->tx);
28823 + atomic_inc_unchecked(&vcc->stats->tx);
28824 iadev->tx_pkt_cnt++;
28825 /* Increment transaction counter */
28826 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28827
28828 #if 0
28829 /* add flow control logic */
28830 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28831 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28832 if (iavcc->vc_desc_cnt > 10) {
28833 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28834 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28835 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28836 index 68c7588..7036683 100644
28837 --- a/drivers/atm/lanai.c
28838 +++ b/drivers/atm/lanai.c
28839 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28840 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28841 lanai_endtx(lanai, lvcc);
28842 lanai_free_skb(lvcc->tx.atmvcc, skb);
28843 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28844 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28845 }
28846
28847 /* Try to fill the buffer - don't call unless there is backlog */
28848 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28849 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28850 __net_timestamp(skb);
28851 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28852 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28853 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28854 out:
28855 lvcc->rx.buf.ptr = end;
28856 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28857 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28858 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28859 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28860 lanai->stats.service_rxnotaal5++;
28861 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28862 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28863 return 0;
28864 }
28865 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28866 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28867 int bytes;
28868 read_unlock(&vcc_sklist_lock);
28869 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28870 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28871 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28872 lvcc->stats.x.aal5.service_trash++;
28873 bytes = (SERVICE_GET_END(s) * 16) -
28874 (((unsigned long) lvcc->rx.buf.ptr) -
28875 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28876 }
28877 if (s & SERVICE_STREAM) {
28878 read_unlock(&vcc_sklist_lock);
28879 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28880 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28881 lvcc->stats.x.aal5.service_stream++;
28882 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28883 "PDU on VCI %d!\n", lanai->number, vci);
28884 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28885 return 0;
28886 }
28887 DPRINTK("got rx crc error on vci %d\n", vci);
28888 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28889 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28890 lvcc->stats.x.aal5.service_rxcrc++;
28891 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28892 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28893 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28894 index 1c70c45..300718d 100644
28895 --- a/drivers/atm/nicstar.c
28896 +++ b/drivers/atm/nicstar.c
28897 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28898 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28899 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28900 card->index);
28901 - atomic_inc(&vcc->stats->tx_err);
28902 + atomic_inc_unchecked(&vcc->stats->tx_err);
28903 dev_kfree_skb_any(skb);
28904 return -EINVAL;
28905 }
28906 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28907 if (!vc->tx) {
28908 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28909 card->index);
28910 - atomic_inc(&vcc->stats->tx_err);
28911 + atomic_inc_unchecked(&vcc->stats->tx_err);
28912 dev_kfree_skb_any(skb);
28913 return -EINVAL;
28914 }
28915 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28916 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28917 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28918 card->index);
28919 - atomic_inc(&vcc->stats->tx_err);
28920 + atomic_inc_unchecked(&vcc->stats->tx_err);
28921 dev_kfree_skb_any(skb);
28922 return -EINVAL;
28923 }
28924
28925 if (skb_shinfo(skb)->nr_frags != 0) {
28926 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28927 - atomic_inc(&vcc->stats->tx_err);
28928 + atomic_inc_unchecked(&vcc->stats->tx_err);
28929 dev_kfree_skb_any(skb);
28930 return -EINVAL;
28931 }
28932 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28933 }
28934
28935 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28936 - atomic_inc(&vcc->stats->tx_err);
28937 + atomic_inc_unchecked(&vcc->stats->tx_err);
28938 dev_kfree_skb_any(skb);
28939 return -EIO;
28940 }
28941 - atomic_inc(&vcc->stats->tx);
28942 + atomic_inc_unchecked(&vcc->stats->tx);
28943
28944 return 0;
28945 }
28946 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28947 printk
28948 ("nicstar%d: Can't allocate buffers for aal0.\n",
28949 card->index);
28950 - atomic_add(i, &vcc->stats->rx_drop);
28951 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28952 break;
28953 }
28954 if (!atm_charge(vcc, sb->truesize)) {
28955 RXPRINTK
28956 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28957 card->index);
28958 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28959 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28960 dev_kfree_skb_any(sb);
28961 break;
28962 }
28963 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28964 ATM_SKB(sb)->vcc = vcc;
28965 __net_timestamp(sb);
28966 vcc->push(vcc, sb);
28967 - atomic_inc(&vcc->stats->rx);
28968 + atomic_inc_unchecked(&vcc->stats->rx);
28969 cell += ATM_CELL_PAYLOAD;
28970 }
28971
28972 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28973 if (iovb == NULL) {
28974 printk("nicstar%d: Out of iovec buffers.\n",
28975 card->index);
28976 - atomic_inc(&vcc->stats->rx_drop);
28977 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28978 recycle_rx_buf(card, skb);
28979 return;
28980 }
28981 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28982 small or large buffer itself. */
28983 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28984 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28985 - atomic_inc(&vcc->stats->rx_err);
28986 + atomic_inc_unchecked(&vcc->stats->rx_err);
28987 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28988 NS_MAX_IOVECS);
28989 NS_PRV_IOVCNT(iovb) = 0;
28990 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28991 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28992 card->index);
28993 which_list(card, skb);
28994 - atomic_inc(&vcc->stats->rx_err);
28995 + atomic_inc_unchecked(&vcc->stats->rx_err);
28996 recycle_rx_buf(card, skb);
28997 vc->rx_iov = NULL;
28998 recycle_iov_buf(card, iovb);
28999 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29000 ("nicstar%d: Expected a large buffer, and this is not one.\n",
29001 card->index);
29002 which_list(card, skb);
29003 - atomic_inc(&vcc->stats->rx_err);
29004 + atomic_inc_unchecked(&vcc->stats->rx_err);
29005 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29006 NS_PRV_IOVCNT(iovb));
29007 vc->rx_iov = NULL;
29008 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29009 printk(" - PDU size mismatch.\n");
29010 else
29011 printk(".\n");
29012 - atomic_inc(&vcc->stats->rx_err);
29013 + atomic_inc_unchecked(&vcc->stats->rx_err);
29014 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29015 NS_PRV_IOVCNT(iovb));
29016 vc->rx_iov = NULL;
29017 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29018 /* skb points to a small buffer */
29019 if (!atm_charge(vcc, skb->truesize)) {
29020 push_rxbufs(card, skb);
29021 - atomic_inc(&vcc->stats->rx_drop);
29022 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29023 } else {
29024 skb_put(skb, len);
29025 dequeue_sm_buf(card, skb);
29026 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29027 ATM_SKB(skb)->vcc = vcc;
29028 __net_timestamp(skb);
29029 vcc->push(vcc, skb);
29030 - atomic_inc(&vcc->stats->rx);
29031 + atomic_inc_unchecked(&vcc->stats->rx);
29032 }
29033 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
29034 struct sk_buff *sb;
29035 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29036 if (len <= NS_SMBUFSIZE) {
29037 if (!atm_charge(vcc, sb->truesize)) {
29038 push_rxbufs(card, sb);
29039 - atomic_inc(&vcc->stats->rx_drop);
29040 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29041 } else {
29042 skb_put(sb, len);
29043 dequeue_sm_buf(card, sb);
29044 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29045 ATM_SKB(sb)->vcc = vcc;
29046 __net_timestamp(sb);
29047 vcc->push(vcc, sb);
29048 - atomic_inc(&vcc->stats->rx);
29049 + atomic_inc_unchecked(&vcc->stats->rx);
29050 }
29051
29052 push_rxbufs(card, skb);
29053 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29054
29055 if (!atm_charge(vcc, skb->truesize)) {
29056 push_rxbufs(card, skb);
29057 - atomic_inc(&vcc->stats->rx_drop);
29058 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29059 } else {
29060 dequeue_lg_buf(card, skb);
29061 #ifdef NS_USE_DESTRUCTORS
29062 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29063 ATM_SKB(skb)->vcc = vcc;
29064 __net_timestamp(skb);
29065 vcc->push(vcc, skb);
29066 - atomic_inc(&vcc->stats->rx);
29067 + atomic_inc_unchecked(&vcc->stats->rx);
29068 }
29069
29070 push_rxbufs(card, sb);
29071 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29072 printk
29073 ("nicstar%d: Out of huge buffers.\n",
29074 card->index);
29075 - atomic_inc(&vcc->stats->rx_drop);
29076 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29077 recycle_iovec_rx_bufs(card,
29078 (struct iovec *)
29079 iovb->data,
29080 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29081 card->hbpool.count++;
29082 } else
29083 dev_kfree_skb_any(hb);
29084 - atomic_inc(&vcc->stats->rx_drop);
29085 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29086 } else {
29087 /* Copy the small buffer to the huge buffer */
29088 sb = (struct sk_buff *)iov->iov_base;
29089 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29090 #endif /* NS_USE_DESTRUCTORS */
29091 __net_timestamp(hb);
29092 vcc->push(vcc, hb);
29093 - atomic_inc(&vcc->stats->rx);
29094 + atomic_inc_unchecked(&vcc->stats->rx);
29095 }
29096 }
29097
29098 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
29099 index 9851093..adb2b1e 100644
29100 --- a/drivers/atm/solos-pci.c
29101 +++ b/drivers/atm/solos-pci.c
29102 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
29103 }
29104 atm_charge(vcc, skb->truesize);
29105 vcc->push(vcc, skb);
29106 - atomic_inc(&vcc->stats->rx);
29107 + atomic_inc_unchecked(&vcc->stats->rx);
29108 break;
29109
29110 case PKT_STATUS:
29111 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
29112 vcc = SKB_CB(oldskb)->vcc;
29113
29114 if (vcc) {
29115 - atomic_inc(&vcc->stats->tx);
29116 + atomic_inc_unchecked(&vcc->stats->tx);
29117 solos_pop(vcc, oldskb);
29118 } else
29119 dev_kfree_skb_irq(oldskb);
29120 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
29121 index 0215934..ce9f5b1 100644
29122 --- a/drivers/atm/suni.c
29123 +++ b/drivers/atm/suni.c
29124 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
29125
29126
29127 #define ADD_LIMITED(s,v) \
29128 - atomic_add((v),&stats->s); \
29129 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
29130 + atomic_add_unchecked((v),&stats->s); \
29131 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
29132
29133
29134 static void suni_hz(unsigned long from_timer)
29135 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
29136 index 5120a96..e2572bd 100644
29137 --- a/drivers/atm/uPD98402.c
29138 +++ b/drivers/atm/uPD98402.c
29139 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
29140 struct sonet_stats tmp;
29141 int error = 0;
29142
29143 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29144 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29145 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
29146 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
29147 if (zero && !error) {
29148 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
29149
29150
29151 #define ADD_LIMITED(s,v) \
29152 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
29153 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
29154 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29155 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
29156 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
29157 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29158
29159
29160 static void stat_event(struct atm_dev *dev)
29161 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
29162 if (reason & uPD98402_INT_PFM) stat_event(dev);
29163 if (reason & uPD98402_INT_PCO) {
29164 (void) GET(PCOCR); /* clear interrupt cause */
29165 - atomic_add(GET(HECCT),
29166 + atomic_add_unchecked(GET(HECCT),
29167 &PRIV(dev)->sonet_stats.uncorr_hcs);
29168 }
29169 if ((reason & uPD98402_INT_RFO) &&
29170 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
29171 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
29172 uPD98402_INT_LOS),PIMR); /* enable them */
29173 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
29174 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29175 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
29176 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
29177 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29178 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
29179 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
29180 return 0;
29181 }
29182
29183 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
29184 index abe4e20..83c4727 100644
29185 --- a/drivers/atm/zatm.c
29186 +++ b/drivers/atm/zatm.c
29187 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29188 }
29189 if (!size) {
29190 dev_kfree_skb_irq(skb);
29191 - if (vcc) atomic_inc(&vcc->stats->rx_err);
29192 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
29193 continue;
29194 }
29195 if (!atm_charge(vcc,skb->truesize)) {
29196 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29197 skb->len = size;
29198 ATM_SKB(skb)->vcc = vcc;
29199 vcc->push(vcc,skb);
29200 - atomic_inc(&vcc->stats->rx);
29201 + atomic_inc_unchecked(&vcc->stats->rx);
29202 }
29203 zout(pos & 0xffff,MTA(mbx));
29204 #if 0 /* probably a stupid idea */
29205 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
29206 skb_queue_head(&zatm_vcc->backlog,skb);
29207 break;
29208 }
29209 - atomic_inc(&vcc->stats->tx);
29210 + atomic_inc_unchecked(&vcc->stats->tx);
29211 wake_up(&zatm_vcc->tx_wait);
29212 }
29213
29214 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
29215 index deb4a45..211eff2 100644
29216 --- a/drivers/base/devtmpfs.c
29217 +++ b/drivers/base/devtmpfs.c
29218 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
29219 if (!thread)
29220 return 0;
29221
29222 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
29223 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
29224 if (err)
29225 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
29226 else
29227 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
29228 index cbb463b..babe2cf 100644
29229 --- a/drivers/base/power/wakeup.c
29230 +++ b/drivers/base/power/wakeup.c
29231 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
29232 * They need to be modified together atomically, so it's better to use one
29233 * atomic variable to hold them both.
29234 */
29235 -static atomic_t combined_event_count = ATOMIC_INIT(0);
29236 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29237
29238 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29239 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29240
29241 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29242 {
29243 - unsigned int comb = atomic_read(&combined_event_count);
29244 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29245
29246 *cnt = (comb >> IN_PROGRESS_BITS);
29247 *inpr = comb & MAX_IN_PROGRESS;
29248 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29249 ws->start_prevent_time = ws->last_time;
29250
29251 /* Increment the counter of events in progress. */
29252 - cec = atomic_inc_return(&combined_event_count);
29253 + cec = atomic_inc_return_unchecked(&combined_event_count);
29254
29255 trace_wakeup_source_activate(ws->name, cec);
29256 }
29257 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29258 * Increment the counter of registered wakeup events and decrement the
29259 * couter of wakeup events in progress simultaneously.
29260 */
29261 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29262 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29263 trace_wakeup_source_deactivate(ws->name, cec);
29264
29265 split_counters(&cnt, &inpr);
29266 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29267 index b0f553b..77b928b 100644
29268 --- a/drivers/block/cciss.c
29269 +++ b/drivers/block/cciss.c
29270 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29271 int err;
29272 u32 cp;
29273
29274 + memset(&arg64, 0, sizeof(arg64));
29275 +
29276 err = 0;
29277 err |=
29278 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29279 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29280 while (!list_empty(&h->reqQ)) {
29281 c = list_entry(h->reqQ.next, CommandList_struct, list);
29282 /* can't do anything if fifo is full */
29283 - if ((h->access.fifo_full(h))) {
29284 + if ((h->access->fifo_full(h))) {
29285 dev_warn(&h->pdev->dev, "fifo full\n");
29286 break;
29287 }
29288 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29289 h->Qdepth--;
29290
29291 /* Tell the controller execute command */
29292 - h->access.submit_command(h, c);
29293 + h->access->submit_command(h, c);
29294
29295 /* Put job onto the completed Q */
29296 addQ(&h->cmpQ, c);
29297 @@ -3443,17 +3445,17 @@ startio:
29298
29299 static inline unsigned long get_next_completion(ctlr_info_t *h)
29300 {
29301 - return h->access.command_completed(h);
29302 + return h->access->command_completed(h);
29303 }
29304
29305 static inline int interrupt_pending(ctlr_info_t *h)
29306 {
29307 - return h->access.intr_pending(h);
29308 + return h->access->intr_pending(h);
29309 }
29310
29311 static inline long interrupt_not_for_us(ctlr_info_t *h)
29312 {
29313 - return ((h->access.intr_pending(h) == 0) ||
29314 + return ((h->access->intr_pending(h) == 0) ||
29315 (h->interrupts_enabled == 0));
29316 }
29317
29318 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29319 u32 a;
29320
29321 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29322 - return h->access.command_completed(h);
29323 + return h->access->command_completed(h);
29324
29325 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29326 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29327 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29328 trans_support & CFGTBL_Trans_use_short_tags);
29329
29330 /* Change the access methods to the performant access methods */
29331 - h->access = SA5_performant_access;
29332 + h->access = &SA5_performant_access;
29333 h->transMethod = CFGTBL_Trans_Performant;
29334
29335 return;
29336 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29337 if (prod_index < 0)
29338 return -ENODEV;
29339 h->product_name = products[prod_index].product_name;
29340 - h->access = *(products[prod_index].access);
29341 + h->access = products[prod_index].access;
29342
29343 if (cciss_board_disabled(h)) {
29344 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29345 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29346 }
29347
29348 /* make sure the board interrupts are off */
29349 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29350 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29351 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29352 if (rc)
29353 goto clean2;
29354 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29355 * fake ones to scoop up any residual completions.
29356 */
29357 spin_lock_irqsave(&h->lock, flags);
29358 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29359 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29360 spin_unlock_irqrestore(&h->lock, flags);
29361 free_irq(h->intr[h->intr_mode], h);
29362 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29363 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29364 dev_info(&h->pdev->dev, "Board READY.\n");
29365 dev_info(&h->pdev->dev,
29366 "Waiting for stale completions to drain.\n");
29367 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29368 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29369 msleep(10000);
29370 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29371 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29372
29373 rc = controller_reset_failed(h->cfgtable);
29374 if (rc)
29375 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29376 cciss_scsi_setup(h);
29377
29378 /* Turn the interrupts on so we can service requests */
29379 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29380 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29381
29382 /* Get the firmware version */
29383 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29384 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29385 kfree(flush_buf);
29386 if (return_code != IO_OK)
29387 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29388 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29389 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29390 free_irq(h->intr[h->intr_mode], h);
29391 }
29392
29393 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29394 index 7fda30e..eb5dfe0 100644
29395 --- a/drivers/block/cciss.h
29396 +++ b/drivers/block/cciss.h
29397 @@ -101,7 +101,7 @@ struct ctlr_info
29398 /* information about each logical volume */
29399 drive_info_struct *drv[CISS_MAX_LUN];
29400
29401 - struct access_method access;
29402 + struct access_method *access;
29403
29404 /* queue and queue Info */
29405 struct list_head reqQ;
29406 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29407 index 9125bbe..eede5c8 100644
29408 --- a/drivers/block/cpqarray.c
29409 +++ b/drivers/block/cpqarray.c
29410 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29411 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29412 goto Enomem4;
29413 }
29414 - hba[i]->access.set_intr_mask(hba[i], 0);
29415 + hba[i]->access->set_intr_mask(hba[i], 0);
29416 if (request_irq(hba[i]->intr, do_ida_intr,
29417 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29418 {
29419 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29420 add_timer(&hba[i]->timer);
29421
29422 /* Enable IRQ now that spinlock and rate limit timer are set up */
29423 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29424 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29425
29426 for(j=0; j<NWD; j++) {
29427 struct gendisk *disk = ida_gendisk[i][j];
29428 @@ -694,7 +694,7 @@ DBGINFO(
29429 for(i=0; i<NR_PRODUCTS; i++) {
29430 if (board_id == products[i].board_id) {
29431 c->product_name = products[i].product_name;
29432 - c->access = *(products[i].access);
29433 + c->access = products[i].access;
29434 break;
29435 }
29436 }
29437 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29438 hba[ctlr]->intr = intr;
29439 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29440 hba[ctlr]->product_name = products[j].product_name;
29441 - hba[ctlr]->access = *(products[j].access);
29442 + hba[ctlr]->access = products[j].access;
29443 hba[ctlr]->ctlr = ctlr;
29444 hba[ctlr]->board_id = board_id;
29445 hba[ctlr]->pci_dev = NULL; /* not PCI */
29446 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29447
29448 while((c = h->reqQ) != NULL) {
29449 /* Can't do anything if we're busy */
29450 - if (h->access.fifo_full(h) == 0)
29451 + if (h->access->fifo_full(h) == 0)
29452 return;
29453
29454 /* Get the first entry from the request Q */
29455 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29456 h->Qdepth--;
29457
29458 /* Tell the controller to do our bidding */
29459 - h->access.submit_command(h, c);
29460 + h->access->submit_command(h, c);
29461
29462 /* Get onto the completion Q */
29463 addQ(&h->cmpQ, c);
29464 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29465 unsigned long flags;
29466 __u32 a,a1;
29467
29468 - istat = h->access.intr_pending(h);
29469 + istat = h->access->intr_pending(h);
29470 /* Is this interrupt for us? */
29471 if (istat == 0)
29472 return IRQ_NONE;
29473 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29474 */
29475 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29476 if (istat & FIFO_NOT_EMPTY) {
29477 - while((a = h->access.command_completed(h))) {
29478 + while((a = h->access->command_completed(h))) {
29479 a1 = a; a &= ~3;
29480 if ((c = h->cmpQ) == NULL)
29481 {
29482 @@ -1449,11 +1449,11 @@ static int sendcmd(
29483 /*
29484 * Disable interrupt
29485 */
29486 - info_p->access.set_intr_mask(info_p, 0);
29487 + info_p->access->set_intr_mask(info_p, 0);
29488 /* Make sure there is room in the command FIFO */
29489 /* Actually it should be completely empty at this time. */
29490 for (i = 200000; i > 0; i--) {
29491 - temp = info_p->access.fifo_full(info_p);
29492 + temp = info_p->access->fifo_full(info_p);
29493 if (temp != 0) {
29494 break;
29495 }
29496 @@ -1466,7 +1466,7 @@ DBG(
29497 /*
29498 * Send the cmd
29499 */
29500 - info_p->access.submit_command(info_p, c);
29501 + info_p->access->submit_command(info_p, c);
29502 complete = pollcomplete(ctlr);
29503
29504 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29505 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29506 * we check the new geometry. Then turn interrupts back on when
29507 * we're done.
29508 */
29509 - host->access.set_intr_mask(host, 0);
29510 + host->access->set_intr_mask(host, 0);
29511 getgeometry(ctlr);
29512 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29513 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29514
29515 for(i=0; i<NWD; i++) {
29516 struct gendisk *disk = ida_gendisk[ctlr][i];
29517 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29518 /* Wait (up to 2 seconds) for a command to complete */
29519
29520 for (i = 200000; i > 0; i--) {
29521 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29522 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29523 if (done == 0) {
29524 udelay(10); /* a short fixed delay */
29525 } else
29526 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29527 index be73e9d..7fbf140 100644
29528 --- a/drivers/block/cpqarray.h
29529 +++ b/drivers/block/cpqarray.h
29530 @@ -99,7 +99,7 @@ struct ctlr_info {
29531 drv_info_t drv[NWD];
29532 struct proc_dir_entry *proc;
29533
29534 - struct access_method access;
29535 + struct access_method *access;
29536
29537 cmdlist_t *reqQ;
29538 cmdlist_t *cmpQ;
29539 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29540 index b953cc7..e3dc580 100644
29541 --- a/drivers/block/drbd/drbd_int.h
29542 +++ b/drivers/block/drbd/drbd_int.h
29543 @@ -735,7 +735,7 @@ struct drbd_request;
29544 struct drbd_epoch {
29545 struct list_head list;
29546 unsigned int barrier_nr;
29547 - atomic_t epoch_size; /* increased on every request added. */
29548 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29549 atomic_t active; /* increased on every req. added, and dec on every finished. */
29550 unsigned long flags;
29551 };
29552 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29553 void *int_dig_in;
29554 void *int_dig_vv;
29555 wait_queue_head_t seq_wait;
29556 - atomic_t packet_seq;
29557 + atomic_unchecked_t packet_seq;
29558 unsigned int peer_seq;
29559 spinlock_t peer_seq_lock;
29560 unsigned int minor;
29561 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29562
29563 static inline void drbd_tcp_cork(struct socket *sock)
29564 {
29565 - int __user val = 1;
29566 + int val = 1;
29567 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29568 - (char __user *)&val, sizeof(val));
29569 + (char __force_user *)&val, sizeof(val));
29570 }
29571
29572 static inline void drbd_tcp_uncork(struct socket *sock)
29573 {
29574 - int __user val = 0;
29575 + int val = 0;
29576 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29577 - (char __user *)&val, sizeof(val));
29578 + (char __force_user *)&val, sizeof(val));
29579 }
29580
29581 static inline void drbd_tcp_nodelay(struct socket *sock)
29582 {
29583 - int __user val = 1;
29584 + int val = 1;
29585 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29586 - (char __user *)&val, sizeof(val));
29587 + (char __force_user *)&val, sizeof(val));
29588 }
29589
29590 static inline void drbd_tcp_quickack(struct socket *sock)
29591 {
29592 - int __user val = 2;
29593 + int val = 2;
29594 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29595 - (char __user *)&val, sizeof(val));
29596 + (char __force_user *)&val, sizeof(val));
29597 }
29598
29599 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29600 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29601 index f93a032..71c87bf 100644
29602 --- a/drivers/block/drbd/drbd_main.c
29603 +++ b/drivers/block/drbd/drbd_main.c
29604 @@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29605 p.sector = sector;
29606 p.block_id = block_id;
29607 p.blksize = blksize;
29608 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29609 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29610
29611 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29612 return false;
29613 @@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29614
29615 p.sector = cpu_to_be64(req->sector);
29616 p.block_id = (unsigned long)req;
29617 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29618 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29619
29620 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29621
29622 @@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29623 atomic_set(&mdev->unacked_cnt, 0);
29624 atomic_set(&mdev->local_cnt, 0);
29625 atomic_set(&mdev->net_cnt, 0);
29626 - atomic_set(&mdev->packet_seq, 0);
29627 + atomic_set_unchecked(&mdev->packet_seq, 0);
29628 atomic_set(&mdev->pp_in_use, 0);
29629 atomic_set(&mdev->pp_in_use_by_net, 0);
29630 atomic_set(&mdev->rs_sect_in, 0);
29631 @@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29632 mdev->receiver.t_state);
29633
29634 /* no need to lock it, I'm the only thread alive */
29635 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29636 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29637 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29638 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29639 mdev->al_writ_cnt =
29640 mdev->bm_writ_cnt =
29641 mdev->read_cnt =
29642 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29643 index edb490a..ecd69da 100644
29644 --- a/drivers/block/drbd/drbd_nl.c
29645 +++ b/drivers/block/drbd/drbd_nl.c
29646 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29647 module_put(THIS_MODULE);
29648 }
29649
29650 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29651 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29652
29653 static unsigned short *
29654 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29655 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29656 cn_reply->id.idx = CN_IDX_DRBD;
29657 cn_reply->id.val = CN_VAL_DRBD;
29658
29659 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29660 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29661 cn_reply->ack = 0; /* not used here. */
29662 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29663 (int)((char *)tl - (char *)reply->tag_list);
29664 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29665 cn_reply->id.idx = CN_IDX_DRBD;
29666 cn_reply->id.val = CN_VAL_DRBD;
29667
29668 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29669 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29670 cn_reply->ack = 0; /* not used here. */
29671 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29672 (int)((char *)tl - (char *)reply->tag_list);
29673 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29674 cn_reply->id.idx = CN_IDX_DRBD;
29675 cn_reply->id.val = CN_VAL_DRBD;
29676
29677 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29678 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29679 cn_reply->ack = 0; // not used here.
29680 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29681 (int)((char*)tl - (char*)reply->tag_list);
29682 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29683 cn_reply->id.idx = CN_IDX_DRBD;
29684 cn_reply->id.val = CN_VAL_DRBD;
29685
29686 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29687 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29688 cn_reply->ack = 0; /* not used here. */
29689 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29690 (int)((char *)tl - (char *)reply->tag_list);
29691 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29692 index c74ca2d..860c819 100644
29693 --- a/drivers/block/drbd/drbd_receiver.c
29694 +++ b/drivers/block/drbd/drbd_receiver.c
29695 @@ -898,7 +898,7 @@ retry:
29696 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29697 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29698
29699 - atomic_set(&mdev->packet_seq, 0);
29700 + atomic_set_unchecked(&mdev->packet_seq, 0);
29701 mdev->peer_seq = 0;
29702
29703 if (drbd_send_protocol(mdev) == -1)
29704 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29705 do {
29706 next_epoch = NULL;
29707
29708 - epoch_size = atomic_read(&epoch->epoch_size);
29709 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29710
29711 switch (ev & ~EV_CLEANUP) {
29712 case EV_PUT:
29713 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29714 rv = FE_DESTROYED;
29715 } else {
29716 epoch->flags = 0;
29717 - atomic_set(&epoch->epoch_size, 0);
29718 + atomic_set_unchecked(&epoch->epoch_size, 0);
29719 /* atomic_set(&epoch->active, 0); is already zero */
29720 if (rv == FE_STILL_LIVE)
29721 rv = FE_RECYCLED;
29722 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29723 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29724 drbd_flush(mdev);
29725
29726 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29727 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29728 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29729 if (epoch)
29730 break;
29731 }
29732
29733 epoch = mdev->current_epoch;
29734 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29735 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29736
29737 D_ASSERT(atomic_read(&epoch->active) == 0);
29738 D_ASSERT(epoch->flags == 0);
29739 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29740 }
29741
29742 epoch->flags = 0;
29743 - atomic_set(&epoch->epoch_size, 0);
29744 + atomic_set_unchecked(&epoch->epoch_size, 0);
29745 atomic_set(&epoch->active, 0);
29746
29747 spin_lock(&mdev->epoch_lock);
29748 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29749 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29750 list_add(&epoch->list, &mdev->current_epoch->list);
29751 mdev->current_epoch = epoch;
29752 mdev->epochs++;
29753 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29754 spin_unlock(&mdev->peer_seq_lock);
29755
29756 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29757 - atomic_inc(&mdev->current_epoch->epoch_size);
29758 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29759 return drbd_drain_block(mdev, data_size);
29760 }
29761
29762 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29763
29764 spin_lock(&mdev->epoch_lock);
29765 e->epoch = mdev->current_epoch;
29766 - atomic_inc(&e->epoch->epoch_size);
29767 + atomic_inc_unchecked(&e->epoch->epoch_size);
29768 atomic_inc(&e->epoch->active);
29769 spin_unlock(&mdev->epoch_lock);
29770
29771 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29772 D_ASSERT(list_empty(&mdev->done_ee));
29773
29774 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29775 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29776 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29777 D_ASSERT(list_empty(&mdev->current_epoch->list));
29778 }
29779
29780 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29781 index 3bba655..6151b66 100644
29782 --- a/drivers/block/loop.c
29783 +++ b/drivers/block/loop.c
29784 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29785 mm_segment_t old_fs = get_fs();
29786
29787 set_fs(get_ds());
29788 - bw = file->f_op->write(file, buf, len, &pos);
29789 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29790 set_fs(old_fs);
29791 if (likely(bw == len))
29792 return 0;
29793 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29794 index ea6f632..eafb192 100644
29795 --- a/drivers/char/Kconfig
29796 +++ b/drivers/char/Kconfig
29797 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29798
29799 config DEVKMEM
29800 bool "/dev/kmem virtual device support"
29801 - default y
29802 + default n
29803 + depends on !GRKERNSEC_KMEM
29804 help
29805 Say Y here if you want to support the /dev/kmem device. The
29806 /dev/kmem device is rarely used, but can be used for certain
29807 @@ -581,6 +582,7 @@ config DEVPORT
29808 bool
29809 depends on !M68K
29810 depends on ISA || PCI
29811 + depends on !GRKERNSEC_KMEM
29812 default y
29813
29814 source "drivers/s390/char/Kconfig"
29815 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29816 index 2e04433..22afc64 100644
29817 --- a/drivers/char/agp/frontend.c
29818 +++ b/drivers/char/agp/frontend.c
29819 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29820 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29821 return -EFAULT;
29822
29823 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29824 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29825 return -EFAULT;
29826
29827 client = agp_find_client_by_pid(reserve.pid);
29828 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29829 index 21cb980..f15107c 100644
29830 --- a/drivers/char/genrtc.c
29831 +++ b/drivers/char/genrtc.c
29832 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29833 switch (cmd) {
29834
29835 case RTC_PLL_GET:
29836 + memset(&pll, 0, sizeof(pll));
29837 if (get_rtc_pll(&pll))
29838 return -EINVAL;
29839 else
29840 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29841 index dfd7876..c0b0885 100644
29842 --- a/drivers/char/hpet.c
29843 +++ b/drivers/char/hpet.c
29844 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29845 }
29846
29847 static int
29848 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29849 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29850 struct hpet_info *info)
29851 {
29852 struct hpet_timer __iomem *timer;
29853 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29854 index 2c29942..604c5ba 100644
29855 --- a/drivers/char/ipmi/ipmi_msghandler.c
29856 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29857 @@ -420,7 +420,7 @@ struct ipmi_smi {
29858 struct proc_dir_entry *proc_dir;
29859 char proc_dir_name[10];
29860
29861 - atomic_t stats[IPMI_NUM_STATS];
29862 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29863
29864 /*
29865 * run_to_completion duplicate of smb_info, smi_info
29866 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29867
29868
29869 #define ipmi_inc_stat(intf, stat) \
29870 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29871 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29872 #define ipmi_get_stat(intf, stat) \
29873 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29874 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29875
29876 static int is_lan_addr(struct ipmi_addr *addr)
29877 {
29878 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29879 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29880 init_waitqueue_head(&intf->waitq);
29881 for (i = 0; i < IPMI_NUM_STATS; i++)
29882 - atomic_set(&intf->stats[i], 0);
29883 + atomic_set_unchecked(&intf->stats[i], 0);
29884
29885 intf->proc_dir = NULL;
29886
29887 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29888 index 83f85cf..279e63f 100644
29889 --- a/drivers/char/ipmi/ipmi_si_intf.c
29890 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29891 @@ -275,7 +275,7 @@ struct smi_info {
29892 unsigned char slave_addr;
29893
29894 /* Counters and things for the proc filesystem. */
29895 - atomic_t stats[SI_NUM_STATS];
29896 + atomic_unchecked_t stats[SI_NUM_STATS];
29897
29898 struct task_struct *thread;
29899
29900 @@ -284,9 +284,9 @@ struct smi_info {
29901 };
29902
29903 #define smi_inc_stat(smi, stat) \
29904 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29905 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29906 #define smi_get_stat(smi, stat) \
29907 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29908 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29909
29910 #define SI_MAX_PARMS 4
29911
29912 @@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29913 atomic_set(&new_smi->req_events, 0);
29914 new_smi->run_to_completion = 0;
29915 for (i = 0; i < SI_NUM_STATS; i++)
29916 - atomic_set(&new_smi->stats[i], 0);
29917 + atomic_set_unchecked(&new_smi->stats[i], 0);
29918
29919 new_smi->interrupt_disabled = 1;
29920 atomic_set(&new_smi->stop_operation, 0);
29921 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29922 index 47ff7e4..0c7d340 100644
29923 --- a/drivers/char/mbcs.c
29924 +++ b/drivers/char/mbcs.c
29925 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29926 return 0;
29927 }
29928
29929 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29930 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29931 {
29932 .part_num = MBCS_PART_NUM,
29933 .mfg_num = MBCS_MFG_NUM,
29934 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29935 index e5eedfa..fcab50ea 100644
29936 --- a/drivers/char/mem.c
29937 +++ b/drivers/char/mem.c
29938 @@ -18,6 +18,7 @@
29939 #include <linux/raw.h>
29940 #include <linux/tty.h>
29941 #include <linux/capability.h>
29942 +#include <linux/security.h>
29943 #include <linux/ptrace.h>
29944 #include <linux/device.h>
29945 #include <linux/highmem.h>
29946 @@ -37,6 +38,10 @@
29947
29948 #define DEVPORT_MINOR 4
29949
29950 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29951 +extern const struct file_operations grsec_fops;
29952 +#endif
29953 +
29954 static inline unsigned long size_inside_page(unsigned long start,
29955 unsigned long size)
29956 {
29957 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29958
29959 while (cursor < to) {
29960 if (!devmem_is_allowed(pfn)) {
29961 +#ifdef CONFIG_GRKERNSEC_KMEM
29962 + gr_handle_mem_readwrite(from, to);
29963 +#else
29964 printk(KERN_INFO
29965 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29966 current->comm, from, to);
29967 +#endif
29968 return 0;
29969 }
29970 cursor += PAGE_SIZE;
29971 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29972 }
29973 return 1;
29974 }
29975 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29976 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29977 +{
29978 + return 0;
29979 +}
29980 #else
29981 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29982 {
29983 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29984
29985 while (count > 0) {
29986 unsigned long remaining;
29987 + char *temp;
29988
29989 sz = size_inside_page(p, count);
29990
29991 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29992 if (!ptr)
29993 return -EFAULT;
29994
29995 - remaining = copy_to_user(buf, ptr, sz);
29996 +#ifdef CONFIG_PAX_USERCOPY
29997 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29998 + if (!temp) {
29999 + unxlate_dev_mem_ptr(p, ptr);
30000 + return -ENOMEM;
30001 + }
30002 + memcpy(temp, ptr, sz);
30003 +#else
30004 + temp = ptr;
30005 +#endif
30006 +
30007 + remaining = copy_to_user(buf, temp, sz);
30008 +
30009 +#ifdef CONFIG_PAX_USERCOPY
30010 + kfree(temp);
30011 +#endif
30012 +
30013 unxlate_dev_mem_ptr(p, ptr);
30014 if (remaining)
30015 return -EFAULT;
30016 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30017 size_t count, loff_t *ppos)
30018 {
30019 unsigned long p = *ppos;
30020 - ssize_t low_count, read, sz;
30021 + ssize_t low_count, read, sz, err = 0;
30022 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
30023 - int err = 0;
30024
30025 read = 0;
30026 if (p < (unsigned long) high_memory) {
30027 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30028 }
30029 #endif
30030 while (low_count > 0) {
30031 + char *temp;
30032 +
30033 sz = size_inside_page(p, low_count);
30034
30035 /*
30036 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30037 */
30038 kbuf = xlate_dev_kmem_ptr((char *)p);
30039
30040 - if (copy_to_user(buf, kbuf, sz))
30041 +#ifdef CONFIG_PAX_USERCOPY
30042 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30043 + if (!temp)
30044 + return -ENOMEM;
30045 + memcpy(temp, kbuf, sz);
30046 +#else
30047 + temp = kbuf;
30048 +#endif
30049 +
30050 + err = copy_to_user(buf, temp, sz);
30051 +
30052 +#ifdef CONFIG_PAX_USERCOPY
30053 + kfree(temp);
30054 +#endif
30055 +
30056 + if (err)
30057 return -EFAULT;
30058 buf += sz;
30059 p += sz;
30060 @@ -833,6 +880,9 @@ static const struct memdev {
30061 #ifdef CONFIG_CRASH_DUMP
30062 [12] = { "oldmem", 0, &oldmem_fops, NULL },
30063 #endif
30064 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30065 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
30066 +#endif
30067 };
30068
30069 static int memory_open(struct inode *inode, struct file *filp)
30070 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
30071 index 9df78e2..01ba9ae 100644
30072 --- a/drivers/char/nvram.c
30073 +++ b/drivers/char/nvram.c
30074 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
30075
30076 spin_unlock_irq(&rtc_lock);
30077
30078 - if (copy_to_user(buf, contents, tmp - contents))
30079 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
30080 return -EFAULT;
30081
30082 *ppos = i;
30083 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
30084 index 0a484b4..f48ccd1 100644
30085 --- a/drivers/char/pcmcia/synclink_cs.c
30086 +++ b/drivers/char/pcmcia/synclink_cs.c
30087 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30088
30089 if (debug_level >= DEBUG_LEVEL_INFO)
30090 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
30091 - __FILE__,__LINE__, info->device_name, port->count);
30092 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
30093
30094 - WARN_ON(!port->count);
30095 + WARN_ON(!atomic_read(&port->count));
30096
30097 if (tty_port_close_start(port, tty, filp) == 0)
30098 goto cleanup;
30099 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30100 cleanup:
30101 if (debug_level >= DEBUG_LEVEL_INFO)
30102 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
30103 - tty->driver->name, port->count);
30104 + tty->driver->name, atomic_read(&port->count));
30105 }
30106
30107 /* Wait until the transmitter is empty.
30108 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30109
30110 if (debug_level >= DEBUG_LEVEL_INFO)
30111 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
30112 - __FILE__,__LINE__,tty->driver->name, port->count);
30113 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
30114
30115 /* If port is closing, signal caller to try again */
30116 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
30117 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30118 goto cleanup;
30119 }
30120 spin_lock(&port->lock);
30121 - port->count++;
30122 + atomic_inc(&port->count);
30123 spin_unlock(&port->lock);
30124 spin_unlock_irqrestore(&info->netlock, flags);
30125
30126 - if (port->count == 1) {
30127 + if (atomic_read(&port->count) == 1) {
30128 /* 1st open on this device, init hardware */
30129 retval = startup(info, tty);
30130 if (retval < 0)
30131 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
30132 unsigned short new_crctype;
30133
30134 /* return error if TTY interface open */
30135 - if (info->port.count)
30136 + if (atomic_read(&info->port.count))
30137 return -EBUSY;
30138
30139 switch (encoding)
30140 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
30141
30142 /* arbitrate between network and tty opens */
30143 spin_lock_irqsave(&info->netlock, flags);
30144 - if (info->port.count != 0 || info->netcount != 0) {
30145 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
30146 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
30147 spin_unlock_irqrestore(&info->netlock, flags);
30148 return -EBUSY;
30149 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
30150 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
30151
30152 /* return error if TTY interface open */
30153 - if (info->port.count)
30154 + if (atomic_read(&info->port.count))
30155 return -EBUSY;
30156
30157 if (cmd != SIOCWANDEV)
30158 diff --git a/drivers/char/random.c b/drivers/char/random.c
30159 index b86eae9..4192a7a 100644
30160 --- a/drivers/char/random.c
30161 +++ b/drivers/char/random.c
30162 @@ -272,8 +272,13 @@
30163 /*
30164 * Configuration information
30165 */
30166 +#ifdef CONFIG_GRKERNSEC_RANDNET
30167 +#define INPUT_POOL_WORDS 512
30168 +#define OUTPUT_POOL_WORDS 128
30169 +#else
30170 #define INPUT_POOL_WORDS 128
30171 #define OUTPUT_POOL_WORDS 32
30172 +#endif
30173 #define SEC_XFER_SIZE 512
30174 #define EXTRACT_SIZE 10
30175
30176 @@ -313,10 +318,17 @@ static struct poolinfo {
30177 int poolwords;
30178 int tap1, tap2, tap3, tap4, tap5;
30179 } poolinfo_table[] = {
30180 +#ifdef CONFIG_GRKERNSEC_RANDNET
30181 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
30182 + { 512, 411, 308, 208, 104, 1 },
30183 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
30184 + { 128, 103, 76, 51, 25, 1 },
30185 +#else
30186 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
30187 { 128, 103, 76, 51, 25, 1 },
30188 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
30189 { 32, 26, 20, 14, 7, 1 },
30190 +#endif
30191 #if 0
30192 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
30193 { 2048, 1638, 1231, 819, 411, 1 },
30194 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
30195 input_rotate += i ? 7 : 14;
30196 }
30197
30198 - ACCESS_ONCE(r->input_rotate) = input_rotate;
30199 - ACCESS_ONCE(r->add_ptr) = i;
30200 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
30201 + ACCESS_ONCE_RW(r->add_ptr) = i;
30202 smp_wmb();
30203
30204 if (out)
30205 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
30206 }
30207 #endif
30208
30209 +#ifdef CONFIG_PAX_LATENT_ENTROPY
30210 +u64 latent_entropy;
30211 +
30212 +__init void transfer_latent_entropy(void)
30213 +{
30214 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30215 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30216 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
30217 +}
30218 +#endif
30219 +
30220 /*********************************************************************
30221 *
30222 * Entropy extraction routines
30223 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
30224
30225 extract_buf(r, tmp);
30226 i = min_t(int, nbytes, EXTRACT_SIZE);
30227 - if (copy_to_user(buf, tmp, i)) {
30228 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
30229 ret = -EFAULT;
30230 break;
30231 }
30232 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30233 #include <linux/sysctl.h>
30234
30235 static int min_read_thresh = 8, min_write_thresh;
30236 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
30237 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30238 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30239 static char sysctl_bootid[16];
30240
30241 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30242 index f877805..403375a 100644
30243 --- a/drivers/char/sonypi.c
30244 +++ b/drivers/char/sonypi.c
30245 @@ -54,6 +54,7 @@
30246
30247 #include <asm/uaccess.h>
30248 #include <asm/io.h>
30249 +#include <asm/local.h>
30250
30251 #include <linux/sonypi.h>
30252
30253 @@ -490,7 +491,7 @@ static struct sonypi_device {
30254 spinlock_t fifo_lock;
30255 wait_queue_head_t fifo_proc_list;
30256 struct fasync_struct *fifo_async;
30257 - int open_count;
30258 + local_t open_count;
30259 int model;
30260 struct input_dev *input_jog_dev;
30261 struct input_dev *input_key_dev;
30262 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30263 static int sonypi_misc_release(struct inode *inode, struct file *file)
30264 {
30265 mutex_lock(&sonypi_device.lock);
30266 - sonypi_device.open_count--;
30267 + local_dec(&sonypi_device.open_count);
30268 mutex_unlock(&sonypi_device.lock);
30269 return 0;
30270 }
30271 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30272 {
30273 mutex_lock(&sonypi_device.lock);
30274 /* Flush input queue on first open */
30275 - if (!sonypi_device.open_count)
30276 + if (!local_read(&sonypi_device.open_count))
30277 kfifo_reset(&sonypi_device.fifo);
30278 - sonypi_device.open_count++;
30279 + local_inc(&sonypi_device.open_count);
30280 mutex_unlock(&sonypi_device.lock);
30281
30282 return 0;
30283 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30284 index 4dc8024..90108d1 100644
30285 --- a/drivers/char/tpm/tpm.c
30286 +++ b/drivers/char/tpm/tpm.c
30287 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30288 chip->vendor.req_complete_val)
30289 goto out_recv;
30290
30291 - if ((status == chip->vendor.req_canceled)) {
30292 + if (status == chip->vendor.req_canceled) {
30293 dev_err(chip->dev, "Operation Canceled\n");
30294 rc = -ECANCELED;
30295 goto out;
30296 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30297 index 0636520..169c1d0 100644
30298 --- a/drivers/char/tpm/tpm_bios.c
30299 +++ b/drivers/char/tpm/tpm_bios.c
30300 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30301 event = addr;
30302
30303 if ((event->event_type == 0 && event->event_size == 0) ||
30304 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30305 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30306 return NULL;
30307
30308 return addr;
30309 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30310 return NULL;
30311
30312 if ((event->event_type == 0 && event->event_size == 0) ||
30313 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30314 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30315 return NULL;
30316
30317 (*pos)++;
30318 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30319 int i;
30320
30321 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30322 - seq_putc(m, data[i]);
30323 + if (!seq_putc(m, data[i]))
30324 + return -EFAULT;
30325
30326 return 0;
30327 }
30328 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30329 log->bios_event_log_end = log->bios_event_log + len;
30330
30331 virt = acpi_os_map_memory(start, len);
30332 + if (!virt) {
30333 + kfree(log->bios_event_log);
30334 + log->bios_event_log = NULL;
30335 + return -EFAULT;
30336 + }
30337
30338 - memcpy(log->bios_event_log, virt, len);
30339 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30340
30341 acpi_os_unmap_memory(virt, len);
30342 return 0;
30343 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30344 index cdf2f54..e55c197 100644
30345 --- a/drivers/char/virtio_console.c
30346 +++ b/drivers/char/virtio_console.c
30347 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30348 if (to_user) {
30349 ssize_t ret;
30350
30351 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30352 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30353 if (ret)
30354 return -EFAULT;
30355 } else {
30356 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30357 if (!port_has_data(port) && !port->host_connected)
30358 return 0;
30359
30360 - return fill_readbuf(port, ubuf, count, true);
30361 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30362 }
30363
30364 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30365 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30366 index e164c55..3aabb50 100644
30367 --- a/drivers/edac/edac_pci_sysfs.c
30368 +++ b/drivers/edac/edac_pci_sysfs.c
30369 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30370 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30371 static int edac_pci_poll_msec = 1000; /* one second workq period */
30372
30373 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30374 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30375 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30376 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30377
30378 static struct kobject *edac_pci_top_main_kobj;
30379 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30380 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30381 edac_printk(KERN_CRIT, EDAC_PCI,
30382 "Signaled System Error on %s\n",
30383 pci_name(dev));
30384 - atomic_inc(&pci_nonparity_count);
30385 + atomic_inc_unchecked(&pci_nonparity_count);
30386 }
30387
30388 if (status & (PCI_STATUS_PARITY)) {
30389 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30390 "Master Data Parity Error on %s\n",
30391 pci_name(dev));
30392
30393 - atomic_inc(&pci_parity_count);
30394 + atomic_inc_unchecked(&pci_parity_count);
30395 }
30396
30397 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30398 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30399 "Detected Parity Error on %s\n",
30400 pci_name(dev));
30401
30402 - atomic_inc(&pci_parity_count);
30403 + atomic_inc_unchecked(&pci_parity_count);
30404 }
30405 }
30406
30407 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30408 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30409 "Signaled System Error on %s\n",
30410 pci_name(dev));
30411 - atomic_inc(&pci_nonparity_count);
30412 + atomic_inc_unchecked(&pci_nonparity_count);
30413 }
30414
30415 if (status & (PCI_STATUS_PARITY)) {
30416 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30417 "Master Data Parity Error on "
30418 "%s\n", pci_name(dev));
30419
30420 - atomic_inc(&pci_parity_count);
30421 + atomic_inc_unchecked(&pci_parity_count);
30422 }
30423
30424 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30425 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30426 "Detected Parity Error on %s\n",
30427 pci_name(dev));
30428
30429 - atomic_inc(&pci_parity_count);
30430 + atomic_inc_unchecked(&pci_parity_count);
30431 }
30432 }
30433 }
30434 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30435 if (!check_pci_errors)
30436 return;
30437
30438 - before_count = atomic_read(&pci_parity_count);
30439 + before_count = atomic_read_unchecked(&pci_parity_count);
30440
30441 /* scan all PCI devices looking for a Parity Error on devices and
30442 * bridges.
30443 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30444 /* Only if operator has selected panic on PCI Error */
30445 if (edac_pci_get_panic_on_pe()) {
30446 /* If the count is different 'after' from 'before' */
30447 - if (before_count != atomic_read(&pci_parity_count))
30448 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30449 panic("EDAC: PCI Parity Error");
30450 }
30451 }
30452 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30453 index 8c87a5e..a19cbd7 100644
30454 --- a/drivers/edac/mce_amd.h
30455 +++ b/drivers/edac/mce_amd.h
30456 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30457 struct amd_decoder_ops {
30458 bool (*dc_mce)(u16, u8);
30459 bool (*ic_mce)(u16, u8);
30460 -};
30461 +} __no_const;
30462
30463 void amd_report_gart_errors(bool);
30464 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30465 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30466 index 57ea7f4..789e3c3 100644
30467 --- a/drivers/firewire/core-card.c
30468 +++ b/drivers/firewire/core-card.c
30469 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30470
30471 void fw_core_remove_card(struct fw_card *card)
30472 {
30473 - struct fw_card_driver dummy_driver = dummy_driver_template;
30474 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30475
30476 card->driver->update_phy_reg(card, 4,
30477 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30478 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30479 index f8d2287..5aaf4db 100644
30480 --- a/drivers/firewire/core-cdev.c
30481 +++ b/drivers/firewire/core-cdev.c
30482 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30483 int ret;
30484
30485 if ((request->channels == 0 && request->bandwidth == 0) ||
30486 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30487 - request->bandwidth < 0)
30488 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30489 return -EINVAL;
30490
30491 r = kmalloc(sizeof(*r), GFP_KERNEL);
30492 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30493 index 87d6f2d..5bf9d90 100644
30494 --- a/drivers/firewire/core-transaction.c
30495 +++ b/drivers/firewire/core-transaction.c
30496 @@ -37,6 +37,7 @@
30497 #include <linux/timer.h>
30498 #include <linux/types.h>
30499 #include <linux/workqueue.h>
30500 +#include <linux/sched.h>
30501
30502 #include <asm/byteorder.h>
30503
30504 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30505 index 515a42c..5ecf3ba 100644
30506 --- a/drivers/firewire/core.h
30507 +++ b/drivers/firewire/core.h
30508 @@ -111,6 +111,7 @@ struct fw_card_driver {
30509
30510 int (*stop_iso)(struct fw_iso_context *ctx);
30511 };
30512 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30513
30514 void fw_card_initialize(struct fw_card *card,
30515 const struct fw_card_driver *driver, struct device *device);
30516 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30517 index b298158..7ed8432 100644
30518 --- a/drivers/firmware/dmi_scan.c
30519 +++ b/drivers/firmware/dmi_scan.c
30520 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30521 }
30522 }
30523 else {
30524 - /*
30525 - * no iounmap() for that ioremap(); it would be a no-op, but
30526 - * it's so early in setup that sucker gets confused into doing
30527 - * what it shouldn't if we actually call it.
30528 - */
30529 p = dmi_ioremap(0xF0000, 0x10000);
30530 if (p == NULL)
30531 goto error;
30532 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30533 if (buf == NULL)
30534 return -1;
30535
30536 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30537 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30538
30539 iounmap(buf);
30540 return 0;
30541 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30542 index 82d5c20..44a7177 100644
30543 --- a/drivers/gpio/gpio-vr41xx.c
30544 +++ b/drivers/gpio/gpio-vr41xx.c
30545 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30546 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30547 maskl, pendl, maskh, pendh);
30548
30549 - atomic_inc(&irq_err_count);
30550 + atomic_inc_unchecked(&irq_err_count);
30551
30552 return -EINVAL;
30553 }
30554 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30555 index 3252e70..b5314ace 100644
30556 --- a/drivers/gpu/drm/drm_crtc_helper.c
30557 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30558 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30559 struct drm_crtc *tmp;
30560 int crtc_mask = 1;
30561
30562 - WARN(!crtc, "checking null crtc?\n");
30563 + BUG_ON(!crtc);
30564
30565 dev = crtc->dev;
30566
30567 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30568 index 9238de4..a27c72a 100644
30569 --- a/drivers/gpu/drm/drm_drv.c
30570 +++ b/drivers/gpu/drm/drm_drv.c
30571 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30572 /**
30573 * Copy and IOCTL return string to user space
30574 */
30575 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30576 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30577 {
30578 int len;
30579
30580 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30581 return -ENODEV;
30582
30583 atomic_inc(&dev->ioctl_count);
30584 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30585 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30586 ++file_priv->ioctl_count;
30587
30588 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30589 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30590 index 7aff5c7..bee6c27 100644
30591 --- a/drivers/gpu/drm/drm_fops.c
30592 +++ b/drivers/gpu/drm/drm_fops.c
30593 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30594 }
30595
30596 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30597 - atomic_set(&dev->counts[i], 0);
30598 + atomic_set_unchecked(&dev->counts[i], 0);
30599
30600 dev->sigdata.lock = NULL;
30601
30602 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
30603 if (drm_device_is_unplugged(dev))
30604 return -ENODEV;
30605
30606 - if (!dev->open_count++)
30607 + if (local_inc_return(&dev->open_count) == 1)
30608 need_setup = 1;
30609 mutex_lock(&dev->struct_mutex);
30610 old_mapping = dev->dev_mapping;
30611 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
30612 retcode = drm_open_helper(inode, filp, dev);
30613 if (retcode)
30614 goto err_undo;
30615 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30616 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30617 if (need_setup) {
30618 retcode = drm_setup(dev);
30619 if (retcode)
30620 @@ -164,7 +164,7 @@ err_undo:
30621 iput(container_of(dev->dev_mapping, struct inode, i_data));
30622 dev->dev_mapping = old_mapping;
30623 mutex_unlock(&dev->struct_mutex);
30624 - dev->open_count--;
30625 + local_dec(&dev->open_count);
30626 return retcode;
30627 }
30628 EXPORT_SYMBOL(drm_open);
30629 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
30630
30631 mutex_lock(&drm_global_mutex);
30632
30633 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30634 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30635
30636 if (dev->driver->preclose)
30637 dev->driver->preclose(dev, file_priv);
30638 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
30639 * Begin inline drm_release
30640 */
30641
30642 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30643 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30644 task_pid_nr(current),
30645 (long)old_encode_dev(file_priv->minor->device),
30646 - dev->open_count);
30647 + local_read(&dev->open_count));
30648
30649 /* Release any auth tokens that might point to this file_priv,
30650 (do that under the drm_global_mutex) */
30651 @@ -546,8 +546,8 @@ int drm_release(struct inode *inode, struct file *filp)
30652 * End inline drm_release
30653 */
30654
30655 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30656 - if (!--dev->open_count) {
30657 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30658 + if (local_dec_and_test(&dev->open_count)) {
30659 if (atomic_read(&dev->ioctl_count)) {
30660 DRM_ERROR("Device busy: %d\n",
30661 atomic_read(&dev->ioctl_count));
30662 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30663 index c87dc96..326055d 100644
30664 --- a/drivers/gpu/drm/drm_global.c
30665 +++ b/drivers/gpu/drm/drm_global.c
30666 @@ -36,7 +36,7 @@
30667 struct drm_global_item {
30668 struct mutex mutex;
30669 void *object;
30670 - int refcount;
30671 + atomic_t refcount;
30672 };
30673
30674 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30675 @@ -49,7 +49,7 @@ void drm_global_init(void)
30676 struct drm_global_item *item = &glob[i];
30677 mutex_init(&item->mutex);
30678 item->object = NULL;
30679 - item->refcount = 0;
30680 + atomic_set(&item->refcount, 0);
30681 }
30682 }
30683
30684 @@ -59,7 +59,7 @@ void drm_global_release(void)
30685 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30686 struct drm_global_item *item = &glob[i];
30687 BUG_ON(item->object != NULL);
30688 - BUG_ON(item->refcount != 0);
30689 + BUG_ON(atomic_read(&item->refcount) != 0);
30690 }
30691 }
30692
30693 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30694 void *object;
30695
30696 mutex_lock(&item->mutex);
30697 - if (item->refcount == 0) {
30698 + if (atomic_read(&item->refcount) == 0) {
30699 item->object = kzalloc(ref->size, GFP_KERNEL);
30700 if (unlikely(item->object == NULL)) {
30701 ret = -ENOMEM;
30702 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30703 goto out_err;
30704
30705 }
30706 - ++item->refcount;
30707 + atomic_inc(&item->refcount);
30708 ref->object = item->object;
30709 object = item->object;
30710 mutex_unlock(&item->mutex);
30711 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30712 struct drm_global_item *item = &glob[ref->global_type];
30713
30714 mutex_lock(&item->mutex);
30715 - BUG_ON(item->refcount == 0);
30716 + BUG_ON(atomic_read(&item->refcount) == 0);
30717 BUG_ON(ref->object != item->object);
30718 - if (--item->refcount == 0) {
30719 + if (atomic_dec_and_test(&item->refcount)) {
30720 ref->release(ref);
30721 item->object = NULL;
30722 }
30723 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30724 index 8928edb..0c79258 100644
30725 --- a/drivers/gpu/drm/drm_info.c
30726 +++ b/drivers/gpu/drm/drm_info.c
30727 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30728 struct drm_local_map *map;
30729 struct drm_map_list *r_list;
30730
30731 - /* Hardcoded from _DRM_FRAME_BUFFER,
30732 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30733 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30734 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30735 + static const char * const types[] = {
30736 + [_DRM_FRAME_BUFFER] = "FB",
30737 + [_DRM_REGISTERS] = "REG",
30738 + [_DRM_SHM] = "SHM",
30739 + [_DRM_AGP] = "AGP",
30740 + [_DRM_SCATTER_GATHER] = "SG",
30741 + [_DRM_CONSISTENT] = "PCI",
30742 + [_DRM_GEM] = "GEM" };
30743 const char *type;
30744 int i;
30745
30746 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30747 map = r_list->map;
30748 if (!map)
30749 continue;
30750 - if (map->type < 0 || map->type > 5)
30751 + if (map->type >= ARRAY_SIZE(types))
30752 type = "??";
30753 else
30754 type = types[map->type];
30755 @@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30756 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30757 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30758 vma->vm_flags & VM_IO ? 'i' : '-',
30759 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30760 + 0);
30761 +#else
30762 vma->vm_pgoff);
30763 +#endif
30764
30765 #if defined(__i386__)
30766 pgprot = pgprot_val(vma->vm_page_prot);
30767 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30768 index 637fcc3..e890b33 100644
30769 --- a/drivers/gpu/drm/drm_ioc32.c
30770 +++ b/drivers/gpu/drm/drm_ioc32.c
30771 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30772 request = compat_alloc_user_space(nbytes);
30773 if (!access_ok(VERIFY_WRITE, request, nbytes))
30774 return -EFAULT;
30775 - list = (struct drm_buf_desc *) (request + 1);
30776 + list = (struct drm_buf_desc __user *) (request + 1);
30777
30778 if (__put_user(count, &request->count)
30779 || __put_user(list, &request->list))
30780 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30781 request = compat_alloc_user_space(nbytes);
30782 if (!access_ok(VERIFY_WRITE, request, nbytes))
30783 return -EFAULT;
30784 - list = (struct drm_buf_pub *) (request + 1);
30785 + list = (struct drm_buf_pub __user *) (request + 1);
30786
30787 if (__put_user(count, &request->count)
30788 || __put_user(list, &request->list))
30789 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30790 index 64a62c6..ceab35e 100644
30791 --- a/drivers/gpu/drm/drm_ioctl.c
30792 +++ b/drivers/gpu/drm/drm_ioctl.c
30793 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30794 stats->data[i].value =
30795 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30796 else
30797 - stats->data[i].value = atomic_read(&dev->counts[i]);
30798 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30799 stats->data[i].type = dev->types[i];
30800 }
30801
30802 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30803 index 3203955..c8090af 100644
30804 --- a/drivers/gpu/drm/drm_lock.c
30805 +++ b/drivers/gpu/drm/drm_lock.c
30806 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30807 if (drm_lock_take(&master->lock, lock->context)) {
30808 master->lock.file_priv = file_priv;
30809 master->lock.lock_time = jiffies;
30810 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30811 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30812 break; /* Got lock */
30813 }
30814
30815 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30816 return -EINVAL;
30817 }
30818
30819 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30820 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30821
30822 if (drm_lock_free(&master->lock, lock->context)) {
30823 /* FIXME: Should really bail out here. */
30824 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30825 index 21bcd4a..8e074e0 100644
30826 --- a/drivers/gpu/drm/drm_stub.c
30827 +++ b/drivers/gpu/drm/drm_stub.c
30828 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30829
30830 drm_device_set_unplugged(dev);
30831
30832 - if (dev->open_count == 0) {
30833 + if (local_read(&dev->open_count) == 0) {
30834 drm_put_dev(dev);
30835 }
30836 mutex_unlock(&drm_global_mutex);
30837 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30838 index 463ec68..f5bd2b5 100644
30839 --- a/drivers/gpu/drm/i810/i810_dma.c
30840 +++ b/drivers/gpu/drm/i810/i810_dma.c
30841 @@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30842 dma->buflist[vertex->idx],
30843 vertex->discard, vertex->used);
30844
30845 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30846 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30847 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30848 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30849 sarea_priv->last_enqueue = dev_priv->counter - 1;
30850 sarea_priv->last_dispatch = (int)hw_status[5];
30851
30852 @@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30853 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30854 mc->last_render);
30855
30856 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30857 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30858 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30859 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30860 sarea_priv->last_enqueue = dev_priv->counter - 1;
30861 sarea_priv->last_dispatch = (int)hw_status[5];
30862
30863 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30864 index 6e0acad..93c8289 100644
30865 --- a/drivers/gpu/drm/i810/i810_drv.h
30866 +++ b/drivers/gpu/drm/i810/i810_drv.h
30867 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30868 int page_flipping;
30869
30870 wait_queue_head_t irq_queue;
30871 - atomic_t irq_received;
30872 - atomic_t irq_emitted;
30873 + atomic_unchecked_t irq_received;
30874 + atomic_unchecked_t irq_emitted;
30875
30876 int front_offset;
30877 } drm_i810_private_t;
30878 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30879 index 359f6e8..ada68fd 100644
30880 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30881 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30882 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30883 I915_READ(GTIMR));
30884 }
30885 seq_printf(m, "Interrupts received: %d\n",
30886 - atomic_read(&dev_priv->irq_received));
30887 + atomic_read_unchecked(&dev_priv->irq_received));
30888 for (i = 0; i < I915_NUM_RINGS; i++) {
30889 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30890 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30891 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30892 index 0969a7c..b9ffa45 100644
30893 --- a/drivers/gpu/drm/i915/i915_dma.c
30894 +++ b/drivers/gpu/drm/i915/i915_dma.c
30895 @@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30896 bool can_switch;
30897
30898 spin_lock(&dev->count_lock);
30899 - can_switch = (dev->open_count == 0);
30900 + can_switch = (local_read(&dev->open_count) == 0);
30901 spin_unlock(&dev->count_lock);
30902 return can_switch;
30903 }
30904 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30905 index 627fe35..c9a7346 100644
30906 --- a/drivers/gpu/drm/i915/i915_drv.h
30907 +++ b/drivers/gpu/drm/i915/i915_drv.h
30908 @@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30909 /* render clock increase/decrease */
30910 /* display clock increase/decrease */
30911 /* pll clock increase/decrease */
30912 -};
30913 +} __no_const;
30914
30915 struct drm_i915_gt_funcs {
30916 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30917 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30918 -};
30919 +} __no_const;
30920
30921 struct intel_device_info {
30922 u8 gen;
30923 @@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30924 int current_page;
30925 int page_flipping;
30926
30927 - atomic_t irq_received;
30928 + atomic_unchecked_t irq_received;
30929
30930 /* protects the irq masks */
30931 spinlock_t irq_lock;
30932 @@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30933 * will be page flipped away on the next vblank. When it
30934 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30935 */
30936 - atomic_t pending_flip;
30937 + atomic_unchecked_t pending_flip;
30938 };
30939
30940 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30941 @@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30942 struct drm_i915_private *dev_priv, unsigned port);
30943 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30944 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30945 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30946 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30947 {
30948 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30949 }
30950 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30951 index cdf46b5..e785624 100644
30952 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30953 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30954 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30955 i915_gem_clflush_object(obj);
30956
30957 if (obj->base.pending_write_domain)
30958 - cd->flips |= atomic_read(&obj->pending_flip);
30959 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30960
30961 /* The actual obj->write_domain will be updated with
30962 * pending_write_domain after we emit the accumulated flush for all
30963 @@ -907,9 +907,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30964
30965 static int
30966 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30967 - int count)
30968 + unsigned int count)
30969 {
30970 - int i;
30971 + unsigned int i;
30972
30973 for (i = 0; i < count; i++) {
30974 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30975 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30976 index 73fa3e1..ab2e9b9 100644
30977 --- a/drivers/gpu/drm/i915/i915_irq.c
30978 +++ b/drivers/gpu/drm/i915/i915_irq.c
30979 @@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30980 u32 pipe_stats[I915_MAX_PIPES];
30981 bool blc_event;
30982
30983 - atomic_inc(&dev_priv->irq_received);
30984 + atomic_inc_unchecked(&dev_priv->irq_received);
30985
30986 while (true) {
30987 iir = I915_READ(VLV_IIR);
30988 @@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30989 irqreturn_t ret = IRQ_NONE;
30990 int i;
30991
30992 - atomic_inc(&dev_priv->irq_received);
30993 + atomic_inc_unchecked(&dev_priv->irq_received);
30994
30995 /* disable master interrupt before clearing iir */
30996 de_ier = I915_READ(DEIER);
30997 @@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30998 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30999 u32 hotplug_mask;
31000
31001 - atomic_inc(&dev_priv->irq_received);
31002 + atomic_inc_unchecked(&dev_priv->irq_received);
31003
31004 /* disable master interrupt before clearing iir */
31005 de_ier = I915_READ(DEIER);
31006 @@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
31007 {
31008 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31009
31010 - atomic_set(&dev_priv->irq_received, 0);
31011 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31012
31013 I915_WRITE(HWSTAM, 0xeffe);
31014
31015 @@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
31016 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31017 int pipe;
31018
31019 - atomic_set(&dev_priv->irq_received, 0);
31020 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31021
31022 /* VLV magic */
31023 I915_WRITE(VLV_IMR, 0);
31024 @@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
31025 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31026 int pipe;
31027
31028 - atomic_set(&dev_priv->irq_received, 0);
31029 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31030
31031 for_each_pipe(pipe)
31032 I915_WRITE(PIPESTAT(pipe), 0);
31033 @@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
31034 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
31035 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
31036
31037 - atomic_inc(&dev_priv->irq_received);
31038 + atomic_inc_unchecked(&dev_priv->irq_received);
31039
31040 iir = I915_READ16(IIR);
31041 if (iir == 0)
31042 @@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
31043 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31044 int pipe;
31045
31046 - atomic_set(&dev_priv->irq_received, 0);
31047 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31048
31049 if (I915_HAS_HOTPLUG(dev)) {
31050 I915_WRITE(PORT_HOTPLUG_EN, 0);
31051 @@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
31052 };
31053 int pipe, ret = IRQ_NONE;
31054
31055 - atomic_inc(&dev_priv->irq_received);
31056 + atomic_inc_unchecked(&dev_priv->irq_received);
31057
31058 iir = I915_READ(IIR);
31059 do {
31060 @@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
31061 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31062 int pipe;
31063
31064 - atomic_set(&dev_priv->irq_received, 0);
31065 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31066
31067 I915_WRITE(PORT_HOTPLUG_EN, 0);
31068 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
31069 @@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
31070 int irq_received;
31071 int ret = IRQ_NONE, pipe;
31072
31073 - atomic_inc(&dev_priv->irq_received);
31074 + atomic_inc_unchecked(&dev_priv->irq_received);
31075
31076 iir = I915_READ(IIR);
31077
31078 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
31079 index b634f6f..43c62f5 100644
31080 --- a/drivers/gpu/drm/i915/intel_display.c
31081 +++ b/drivers/gpu/drm/i915/intel_display.c
31082 @@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
31083
31084 wait_event(dev_priv->pending_flip_queue,
31085 atomic_read(&dev_priv->mm.wedged) ||
31086 - atomic_read(&obj->pending_flip) == 0);
31087 + atomic_read_unchecked(&obj->pending_flip) == 0);
31088
31089 /* Big Hammer, we also need to ensure that any pending
31090 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
31091 @@ -6168,8 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
31092
31093 obj = work->old_fb_obj;
31094
31095 - atomic_clear_mask(1 << intel_crtc->plane,
31096 - &obj->pending_flip.counter);
31097 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
31098
31099 wake_up(&dev_priv->pending_flip_queue);
31100 schedule_work(&work->work);
31101 @@ -6515,7 +6514,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31102 /* Block clients from rendering to the new back buffer until
31103 * the flip occurs and the object is no longer visible.
31104 */
31105 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31106 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31107
31108 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
31109 if (ret)
31110 @@ -6530,7 +6529,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31111 return 0;
31112
31113 cleanup_pending:
31114 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31115 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31116 drm_gem_object_unreference(&work->old_fb_obj->base);
31117 drm_gem_object_unreference(&obj->base);
31118 mutex_unlock(&dev->struct_mutex);
31119 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
31120 index 54558a0..2d97005 100644
31121 --- a/drivers/gpu/drm/mga/mga_drv.h
31122 +++ b/drivers/gpu/drm/mga/mga_drv.h
31123 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
31124 u32 clear_cmd;
31125 u32 maccess;
31126
31127 - atomic_t vbl_received; /**< Number of vblanks received. */
31128 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
31129 wait_queue_head_t fence_queue;
31130 - atomic_t last_fence_retired;
31131 + atomic_unchecked_t last_fence_retired;
31132 u32 next_fence_to_post;
31133
31134 unsigned int fb_cpp;
31135 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
31136 index 2581202..f230a8d9 100644
31137 --- a/drivers/gpu/drm/mga/mga_irq.c
31138 +++ b/drivers/gpu/drm/mga/mga_irq.c
31139 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
31140 if (crtc != 0)
31141 return 0;
31142
31143 - return atomic_read(&dev_priv->vbl_received);
31144 + return atomic_read_unchecked(&dev_priv->vbl_received);
31145 }
31146
31147
31148 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31149 /* VBLANK interrupt */
31150 if (status & MGA_VLINEPEN) {
31151 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
31152 - atomic_inc(&dev_priv->vbl_received);
31153 + atomic_inc_unchecked(&dev_priv->vbl_received);
31154 drm_handle_vblank(dev, 0);
31155 handled = 1;
31156 }
31157 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31158 if ((prim_start & ~0x03) != (prim_end & ~0x03))
31159 MGA_WRITE(MGA_PRIMEND, prim_end);
31160
31161 - atomic_inc(&dev_priv->last_fence_retired);
31162 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
31163 DRM_WAKEUP(&dev_priv->fence_queue);
31164 handled = 1;
31165 }
31166 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
31167 * using fences.
31168 */
31169 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
31170 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
31171 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
31172 - *sequence) <= (1 << 23)));
31173
31174 *sequence = cur_fence;
31175 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
31176 index a0a3fe3..209bf10 100644
31177 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
31178 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
31179 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
31180 struct bit_table {
31181 const char id;
31182 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
31183 -};
31184 +} __no_const;
31185
31186 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
31187
31188 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
31189 index 4f2cc95..9c6c510 100644
31190 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
31191 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
31192 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
31193 u32 handle, u16 class);
31194 void (*set_tile_region)(struct drm_device *dev, int i);
31195 void (*tlb_flush)(struct drm_device *, int engine);
31196 -};
31197 +} __no_const;
31198
31199 struct nouveau_instmem_engine {
31200 void *priv;
31201 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
31202 struct nouveau_mc_engine {
31203 int (*init)(struct drm_device *dev);
31204 void (*takedown)(struct drm_device *dev);
31205 -};
31206 +} __no_const;
31207
31208 struct nouveau_timer_engine {
31209 int (*init)(struct drm_device *dev);
31210 void (*takedown)(struct drm_device *dev);
31211 uint64_t (*read)(struct drm_device *dev);
31212 -};
31213 +} __no_const;
31214
31215 struct nouveau_fb_engine {
31216 int num_tiles;
31217 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
31218 void (*put)(struct drm_device *, struct nouveau_mem **);
31219
31220 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
31221 -};
31222 +} __no_const;
31223
31224 struct nouveau_engine {
31225 struct nouveau_instmem_engine instmem;
31226 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
31227 struct drm_global_reference mem_global_ref;
31228 struct ttm_bo_global_ref bo_global_ref;
31229 struct ttm_bo_device bdev;
31230 - atomic_t validate_sequence;
31231 + atomic_unchecked_t validate_sequence;
31232 int (*move)(struct nouveau_channel *,
31233 struct ttm_buffer_object *,
31234 struct ttm_mem_reg *, struct ttm_mem_reg *);
31235 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
31236 index af7cfb8..aadc2a3 100644
31237 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
31238 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
31239 @@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
31240 int trycnt = 0;
31241 int ret, i;
31242
31243 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
31244 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
31245 retry:
31246 if (++trycnt > 100000) {
31247 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
31248 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
31249 index f5e9584..05934ba 100644
31250 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
31251 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
31252 @@ -492,7 +492,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31253 bool can_switch;
31254
31255 spin_lock(&dev->count_lock);
31256 - can_switch = (dev->open_count == 0);
31257 + can_switch = (local_read(&dev->open_count) == 0);
31258 spin_unlock(&dev->count_lock);
31259 return can_switch;
31260 }
31261 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31262 index 93240bd..c490f60 100644
31263 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31264 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31265 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31266 }
31267
31268 if (nv_encoder->dcb->type == OUTPUT_DP) {
31269 - struct dp_train_func func = {
31270 + static struct dp_train_func func = {
31271 .link_set = nv50_sor_dp_link_set,
31272 .train_set = nv50_sor_dp_train_set,
31273 .train_adj = nv50_sor_dp_train_adj
31274 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31275 index 8a2fc89..3a5cf40 100644
31276 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31277 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31278 @@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31279 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31280
31281 if (nv_encoder->dcb->type == OUTPUT_DP) {
31282 - struct dp_train_func func = {
31283 + static struct dp_train_func func = {
31284 .link_set = nvd0_sor_dp_link_set,
31285 .train_set = nvd0_sor_dp_train_set,
31286 .train_adj = nvd0_sor_dp_train_adj
31287 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31288 index bcac90b..53bfc76 100644
31289 --- a/drivers/gpu/drm/r128/r128_cce.c
31290 +++ b/drivers/gpu/drm/r128/r128_cce.c
31291 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31292
31293 /* GH: Simple idle check.
31294 */
31295 - atomic_set(&dev_priv->idle_count, 0);
31296 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31297
31298 /* We don't support anything other than bus-mastering ring mode,
31299 * but the ring can be in either AGP or PCI space for the ring
31300 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31301 index 930c71b..499aded 100644
31302 --- a/drivers/gpu/drm/r128/r128_drv.h
31303 +++ b/drivers/gpu/drm/r128/r128_drv.h
31304 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31305 int is_pci;
31306 unsigned long cce_buffers_offset;
31307
31308 - atomic_t idle_count;
31309 + atomic_unchecked_t idle_count;
31310
31311 int page_flipping;
31312 int current_page;
31313 u32 crtc_offset;
31314 u32 crtc_offset_cntl;
31315
31316 - atomic_t vbl_received;
31317 + atomic_unchecked_t vbl_received;
31318
31319 u32 color_fmt;
31320 unsigned int front_offset;
31321 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31322 index 429d5a0..7e899ed 100644
31323 --- a/drivers/gpu/drm/r128/r128_irq.c
31324 +++ b/drivers/gpu/drm/r128/r128_irq.c
31325 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31326 if (crtc != 0)
31327 return 0;
31328
31329 - return atomic_read(&dev_priv->vbl_received);
31330 + return atomic_read_unchecked(&dev_priv->vbl_received);
31331 }
31332
31333 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31334 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31335 /* VBLANK interrupt */
31336 if (status & R128_CRTC_VBLANK_INT) {
31337 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31338 - atomic_inc(&dev_priv->vbl_received);
31339 + atomic_inc_unchecked(&dev_priv->vbl_received);
31340 drm_handle_vblank(dev, 0);
31341 return IRQ_HANDLED;
31342 }
31343 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31344 index a9e33ce..09edd4b 100644
31345 --- a/drivers/gpu/drm/r128/r128_state.c
31346 +++ b/drivers/gpu/drm/r128/r128_state.c
31347 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31348
31349 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31350 {
31351 - if (atomic_read(&dev_priv->idle_count) == 0)
31352 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31353 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31354 else
31355 - atomic_set(&dev_priv->idle_count, 0);
31356 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31357 }
31358
31359 #endif
31360 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31361 index 5a82b6b..9e69c73 100644
31362 --- a/drivers/gpu/drm/radeon/mkregtable.c
31363 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31364 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31365 regex_t mask_rex;
31366 regmatch_t match[4];
31367 char buf[1024];
31368 - size_t end;
31369 + long end;
31370 int len;
31371 int done = 0;
31372 int r;
31373 unsigned o;
31374 struct offset *offset;
31375 char last_reg_s[10];
31376 - int last_reg;
31377 + unsigned long last_reg;
31378
31379 if (regcomp
31380 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31381 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31382 index 59a1531..3bab49b 100644
31383 --- a/drivers/gpu/drm/radeon/radeon.h
31384 +++ b/drivers/gpu/drm/radeon/radeon.h
31385 @@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31386 int x2, int y2);
31387 void (*draw_auto)(struct radeon_device *rdev);
31388 void (*set_default_state)(struct radeon_device *rdev);
31389 -};
31390 +} __no_const;
31391
31392 struct r600_blit {
31393 struct radeon_bo *shader_obj;
31394 @@ -1216,7 +1216,7 @@ struct radeon_asic {
31395 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31396 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31397 } pflip;
31398 -};
31399 +} __no_const;
31400
31401 /*
31402 * Asic structures
31403 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31404 index 7a3daeb..5016171 100644
31405 --- a/drivers/gpu/drm/radeon/radeon_device.c
31406 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31407 @@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31408 bool can_switch;
31409
31410 spin_lock(&dev->count_lock);
31411 - can_switch = (dev->open_count == 0);
31412 + can_switch = (local_read(&dev->open_count) == 0);
31413 spin_unlock(&dev->count_lock);
31414 return can_switch;
31415 }
31416 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31417 index a1b59ca..86f2d44 100644
31418 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31419 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31420 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31421
31422 /* SW interrupt */
31423 wait_queue_head_t swi_queue;
31424 - atomic_t swi_emitted;
31425 + atomic_unchecked_t swi_emitted;
31426 int vblank_crtc;
31427 uint32_t irq_enable_reg;
31428 uint32_t r500_disp_irq_reg;
31429 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31430 index 48b7cea..342236f 100644
31431 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31432 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31433 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31434 request = compat_alloc_user_space(sizeof(*request));
31435 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31436 || __put_user(req32.param, &request->param)
31437 - || __put_user((void __user *)(unsigned long)req32.value,
31438 + || __put_user((unsigned long)req32.value,
31439 &request->value))
31440 return -EFAULT;
31441
31442 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31443 index 00da384..32f972d 100644
31444 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31445 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31446 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31447 unsigned int ret;
31448 RING_LOCALS;
31449
31450 - atomic_inc(&dev_priv->swi_emitted);
31451 - ret = atomic_read(&dev_priv->swi_emitted);
31452 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31453 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31454
31455 BEGIN_RING(4);
31456 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31457 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31458 drm_radeon_private_t *dev_priv =
31459 (drm_radeon_private_t *) dev->dev_private;
31460
31461 - atomic_set(&dev_priv->swi_emitted, 0);
31462 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31463 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31464
31465 dev->max_vblank_count = 0x001fffff;
31466 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31467 index e8422ae..d22d4a8 100644
31468 --- a/drivers/gpu/drm/radeon/radeon_state.c
31469 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31470 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31471 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31472 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31473
31474 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31475 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31476 sarea_priv->nbox * sizeof(depth_boxes[0])))
31477 return -EFAULT;
31478
31479 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31480 {
31481 drm_radeon_private_t *dev_priv = dev->dev_private;
31482 drm_radeon_getparam_t *param = data;
31483 - int value;
31484 + int value = 0;
31485
31486 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31487
31488 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31489 index 5b71c71..650f9e4 100644
31490 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31491 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31492 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31493 }
31494 if (unlikely(ttm_vm_ops == NULL)) {
31495 ttm_vm_ops = vma->vm_ops;
31496 - radeon_ttm_vm_ops = *ttm_vm_ops;
31497 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31498 + pax_open_kernel();
31499 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31500 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31501 + pax_close_kernel();
31502 }
31503 vma->vm_ops = &radeon_ttm_vm_ops;
31504 return 0;
31505 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31506 index 3b663fc..57850f4 100644
31507 --- a/drivers/gpu/drm/radeon/rs690.c
31508 +++ b/drivers/gpu/drm/radeon/rs690.c
31509 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31510 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31511 rdev->pm.sideport_bandwidth.full)
31512 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31513 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31514 + read_delay_latency.full = dfixed_const(800 * 1000);
31515 read_delay_latency.full = dfixed_div(read_delay_latency,
31516 rdev->pm.igp_sideport_mclk);
31517 + a.full = dfixed_const(370);
31518 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31519 } else {
31520 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31521 rdev->pm.k8_bandwidth.full)
31522 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31523 index 578207e..1073f25 100644
31524 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31525 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31526 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31527 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31528 struct shrink_control *sc)
31529 {
31530 - static atomic_t start_pool = ATOMIC_INIT(0);
31531 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31532 unsigned i;
31533 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31534 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31535 struct ttm_page_pool *pool;
31536 int shrink_pages = sc->nr_to_scan;
31537
31538 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31539 index 88edacc..1e5412b 100644
31540 --- a/drivers/gpu/drm/via/via_drv.h
31541 +++ b/drivers/gpu/drm/via/via_drv.h
31542 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31543 typedef uint32_t maskarray_t[5];
31544
31545 typedef struct drm_via_irq {
31546 - atomic_t irq_received;
31547 + atomic_unchecked_t irq_received;
31548 uint32_t pending_mask;
31549 uint32_t enable_mask;
31550 wait_queue_head_t irq_queue;
31551 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31552 struct timeval last_vblank;
31553 int last_vblank_valid;
31554 unsigned usec_per_vblank;
31555 - atomic_t vbl_received;
31556 + atomic_unchecked_t vbl_received;
31557 drm_via_state_t hc_state;
31558 char pci_buf[VIA_PCI_BUF_SIZE];
31559 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31560 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31561 index d391f48..10c8ca3 100644
31562 --- a/drivers/gpu/drm/via/via_irq.c
31563 +++ b/drivers/gpu/drm/via/via_irq.c
31564 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31565 if (crtc != 0)
31566 return 0;
31567
31568 - return atomic_read(&dev_priv->vbl_received);
31569 + return atomic_read_unchecked(&dev_priv->vbl_received);
31570 }
31571
31572 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31573 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31574
31575 status = VIA_READ(VIA_REG_INTERRUPT);
31576 if (status & VIA_IRQ_VBLANK_PENDING) {
31577 - atomic_inc(&dev_priv->vbl_received);
31578 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31579 + atomic_inc_unchecked(&dev_priv->vbl_received);
31580 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31581 do_gettimeofday(&cur_vblank);
31582 if (dev_priv->last_vblank_valid) {
31583 dev_priv->usec_per_vblank =
31584 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31585 dev_priv->last_vblank = cur_vblank;
31586 dev_priv->last_vblank_valid = 1;
31587 }
31588 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31589 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31590 DRM_DEBUG("US per vblank is: %u\n",
31591 dev_priv->usec_per_vblank);
31592 }
31593 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31594
31595 for (i = 0; i < dev_priv->num_irqs; ++i) {
31596 if (status & cur_irq->pending_mask) {
31597 - atomic_inc(&cur_irq->irq_received);
31598 + atomic_inc_unchecked(&cur_irq->irq_received);
31599 DRM_WAKEUP(&cur_irq->irq_queue);
31600 handled = 1;
31601 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31602 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31603 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31604 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31605 masks[irq][4]));
31606 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31607 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31608 } else {
31609 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31610 (((cur_irq_sequence =
31611 - atomic_read(&cur_irq->irq_received)) -
31612 + atomic_read_unchecked(&cur_irq->irq_received)) -
31613 *sequence) <= (1 << 23)));
31614 }
31615 *sequence = cur_irq_sequence;
31616 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31617 }
31618
31619 for (i = 0; i < dev_priv->num_irqs; ++i) {
31620 - atomic_set(&cur_irq->irq_received, 0);
31621 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31622 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31623 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31624 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31625 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31626 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31627 case VIA_IRQ_RELATIVE:
31628 irqwait->request.sequence +=
31629 - atomic_read(&cur_irq->irq_received);
31630 + atomic_read_unchecked(&cur_irq->irq_received);
31631 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31632 case VIA_IRQ_ABSOLUTE:
31633 break;
31634 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31635 index 29c984f..4084f1a 100644
31636 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31637 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31638 @@ -263,7 +263,7 @@ struct vmw_private {
31639 * Fencing and IRQs.
31640 */
31641
31642 - atomic_t marker_seq;
31643 + atomic_unchecked_t marker_seq;
31644 wait_queue_head_t fence_queue;
31645 wait_queue_head_t fifo_queue;
31646 int fence_queue_waiters; /* Protected by hw_mutex */
31647 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31648 index a0c2f12..68ae6cb 100644
31649 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31650 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31651 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31652 (unsigned int) min,
31653 (unsigned int) fifo->capabilities);
31654
31655 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31656 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31657 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31658 vmw_marker_queue_init(&fifo->marker_queue);
31659 return vmw_fifo_send_fence(dev_priv, &dummy);
31660 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31661 if (reserveable)
31662 iowrite32(bytes, fifo_mem +
31663 SVGA_FIFO_RESERVED);
31664 - return fifo_mem + (next_cmd >> 2);
31665 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31666 } else {
31667 need_bounce = true;
31668 }
31669 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31670
31671 fm = vmw_fifo_reserve(dev_priv, bytes);
31672 if (unlikely(fm == NULL)) {
31673 - *seqno = atomic_read(&dev_priv->marker_seq);
31674 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31675 ret = -ENOMEM;
31676 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31677 false, 3*HZ);
31678 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31679 }
31680
31681 do {
31682 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31683 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31684 } while (*seqno == 0);
31685
31686 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31687 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31688 index cabc95f..14b3d77 100644
31689 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31690 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31691 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31692 * emitted. Then the fence is stale and signaled.
31693 */
31694
31695 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31696 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31697 > VMW_FENCE_WRAP);
31698
31699 return ret;
31700 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31701
31702 if (fifo_idle)
31703 down_read(&fifo_state->rwsem);
31704 - signal_seq = atomic_read(&dev_priv->marker_seq);
31705 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31706 ret = 0;
31707
31708 for (;;) {
31709 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31710 index 8a8725c..afed796 100644
31711 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31712 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31713 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31714 while (!vmw_lag_lt(queue, us)) {
31715 spin_lock(&queue->lock);
31716 if (list_empty(&queue->head))
31717 - seqno = atomic_read(&dev_priv->marker_seq);
31718 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31719 else {
31720 marker = list_first_entry(&queue->head,
31721 struct vmw_marker, head);
31722 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31723 index 5de3bb3..08e5063 100644
31724 --- a/drivers/hid/hid-core.c
31725 +++ b/drivers/hid/hid-core.c
31726 @@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31727
31728 int hid_add_device(struct hid_device *hdev)
31729 {
31730 - static atomic_t id = ATOMIC_INIT(0);
31731 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31732 int ret;
31733
31734 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31735 @@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31736 /* XXX hack, any other cleaner solution after the driver core
31737 * is converted to allow more than 20 bytes as the device name? */
31738 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31739 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31740 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31741
31742 hid_debug_register(hdev, dev_name(&hdev->dev));
31743 ret = device_add(&hdev->dev);
31744 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31745 index eec3291..8ed706b 100644
31746 --- a/drivers/hid/hid-wiimote-debug.c
31747 +++ b/drivers/hid/hid-wiimote-debug.c
31748 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31749 else if (size == 0)
31750 return -EIO;
31751
31752 - if (copy_to_user(u, buf, size))
31753 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31754 return -EFAULT;
31755
31756 *off += size;
31757 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31758 index 14599e2..711c965 100644
31759 --- a/drivers/hid/usbhid/hiddev.c
31760 +++ b/drivers/hid/usbhid/hiddev.c
31761 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31762 break;
31763
31764 case HIDIOCAPPLICATION:
31765 - if (arg < 0 || arg >= hid->maxapplication)
31766 + if (arg >= hid->maxapplication)
31767 break;
31768
31769 for (i = 0; i < hid->maxcollection; i++)
31770 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31771 index f4c3d28..82f45a9 100644
31772 --- a/drivers/hv/channel.c
31773 +++ b/drivers/hv/channel.c
31774 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31775 int ret = 0;
31776 int t;
31777
31778 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31779 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31780 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31781 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31782
31783 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31784 if (ret)
31785 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31786 index 86f8885..ab9cb2b 100644
31787 --- a/drivers/hv/hv.c
31788 +++ b/drivers/hv/hv.c
31789 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31790 u64 output_address = (output) ? virt_to_phys(output) : 0;
31791 u32 output_address_hi = output_address >> 32;
31792 u32 output_address_lo = output_address & 0xFFFFFFFF;
31793 - void *hypercall_page = hv_context.hypercall_page;
31794 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31795
31796 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31797 "=a"(hv_status_lo) : "d" (control_hi),
31798 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31799 index 0614ff3..f0b2b5c 100644
31800 --- a/drivers/hv/hyperv_vmbus.h
31801 +++ b/drivers/hv/hyperv_vmbus.h
31802 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31803 struct vmbus_connection {
31804 enum vmbus_connect_state conn_state;
31805
31806 - atomic_t next_gpadl_handle;
31807 + atomic_unchecked_t next_gpadl_handle;
31808
31809 /*
31810 * Represents channel interrupts. Each bit position represents a
31811 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31812 index 4748086..3abf845 100644
31813 --- a/drivers/hv/vmbus_drv.c
31814 +++ b/drivers/hv/vmbus_drv.c
31815 @@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31816 {
31817 int ret = 0;
31818
31819 - static atomic_t device_num = ATOMIC_INIT(0);
31820 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31821
31822 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31823 - atomic_inc_return(&device_num));
31824 + atomic_inc_return_unchecked(&device_num));
31825
31826 child_device_obj->device.bus = &hv_bus;
31827 child_device_obj->device.parent = &hv_acpi_dev->dev;
31828 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31829 index 8b011d0..3de24a1 100644
31830 --- a/drivers/hwmon/sht15.c
31831 +++ b/drivers/hwmon/sht15.c
31832 @@ -166,7 +166,7 @@ struct sht15_data {
31833 int supply_uV;
31834 bool supply_uV_valid;
31835 struct work_struct update_supply_work;
31836 - atomic_t interrupt_handled;
31837 + atomic_unchecked_t interrupt_handled;
31838 };
31839
31840 /**
31841 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31842 return ret;
31843
31844 gpio_direction_input(data->pdata->gpio_data);
31845 - atomic_set(&data->interrupt_handled, 0);
31846 + atomic_set_unchecked(&data->interrupt_handled, 0);
31847
31848 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31849 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31850 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31851 /* Only relevant if the interrupt hasn't occurred. */
31852 - if (!atomic_read(&data->interrupt_handled))
31853 + if (!atomic_read_unchecked(&data->interrupt_handled))
31854 schedule_work(&data->read_work);
31855 }
31856 ret = wait_event_timeout(data->wait_queue,
31857 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31858
31859 /* First disable the interrupt */
31860 disable_irq_nosync(irq);
31861 - atomic_inc(&data->interrupt_handled);
31862 + atomic_inc_unchecked(&data->interrupt_handled);
31863 /* Then schedule a reading work struct */
31864 if (data->state != SHT15_READING_NOTHING)
31865 schedule_work(&data->read_work);
31866 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31867 * If not, then start the interrupt again - care here as could
31868 * have gone low in meantime so verify it hasn't!
31869 */
31870 - atomic_set(&data->interrupt_handled, 0);
31871 + atomic_set_unchecked(&data->interrupt_handled, 0);
31872 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31873 /* If still not occurred or another handler was scheduled */
31874 if (gpio_get_value(data->pdata->gpio_data)
31875 - || atomic_read(&data->interrupt_handled))
31876 + || atomic_read_unchecked(&data->interrupt_handled))
31877 return;
31878 }
31879
31880 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31881 index 378fcb5..5e91fa8 100644
31882 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31883 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31884 @@ -43,7 +43,7 @@
31885 extern struct i2c_adapter amd756_smbus;
31886
31887 static struct i2c_adapter *s4882_adapter;
31888 -static struct i2c_algorithm *s4882_algo;
31889 +static i2c_algorithm_no_const *s4882_algo;
31890
31891 /* Wrapper access functions for multiplexed SMBus */
31892 static DEFINE_MUTEX(amd756_lock);
31893 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31894 index 29015eb..af2d8e9 100644
31895 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31896 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31897 @@ -41,7 +41,7 @@
31898 extern struct i2c_adapter *nforce2_smbus;
31899
31900 static struct i2c_adapter *s4985_adapter;
31901 -static struct i2c_algorithm *s4985_algo;
31902 +static i2c_algorithm_no_const *s4985_algo;
31903
31904 /* Wrapper access functions for multiplexed SMBus */
31905 static DEFINE_MUTEX(nforce2_lock);
31906 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31907 index 1038c38..eb92f51 100644
31908 --- a/drivers/i2c/i2c-mux.c
31909 +++ b/drivers/i2c/i2c-mux.c
31910 @@ -30,7 +30,7 @@
31911 /* multiplexer per channel data */
31912 struct i2c_mux_priv {
31913 struct i2c_adapter adap;
31914 - struct i2c_algorithm algo;
31915 + i2c_algorithm_no_const algo;
31916
31917 struct i2c_adapter *parent;
31918 void *mux_priv; /* the mux chip/device */
31919 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31920 index 57d00ca..0145194 100644
31921 --- a/drivers/ide/aec62xx.c
31922 +++ b/drivers/ide/aec62xx.c
31923 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31924 .cable_detect = atp86x_cable_detect,
31925 };
31926
31927 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31928 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31929 { /* 0: AEC6210 */
31930 .name = DRV_NAME,
31931 .init_chipset = init_chipset_aec62xx,
31932 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31933 index 2c8016a..911a27c 100644
31934 --- a/drivers/ide/alim15x3.c
31935 +++ b/drivers/ide/alim15x3.c
31936 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31937 .dma_sff_read_status = ide_dma_sff_read_status,
31938 };
31939
31940 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31941 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31942 .name = DRV_NAME,
31943 .init_chipset = init_chipset_ali15x3,
31944 .init_hwif = init_hwif_ali15x3,
31945 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31946 index 3747b25..56fc995 100644
31947 --- a/drivers/ide/amd74xx.c
31948 +++ b/drivers/ide/amd74xx.c
31949 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31950 .udma_mask = udma, \
31951 }
31952
31953 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31954 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31955 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31956 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31957 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31958 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31959 index 15f0ead..cb43480 100644
31960 --- a/drivers/ide/atiixp.c
31961 +++ b/drivers/ide/atiixp.c
31962 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31963 .cable_detect = atiixp_cable_detect,
31964 };
31965
31966 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31967 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31968 { /* 0: IXP200/300/400/700 */
31969 .name = DRV_NAME,
31970 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31971 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31972 index 5f80312..d1fc438 100644
31973 --- a/drivers/ide/cmd64x.c
31974 +++ b/drivers/ide/cmd64x.c
31975 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31976 .dma_sff_read_status = ide_dma_sff_read_status,
31977 };
31978
31979 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31980 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31981 { /* 0: CMD643 */
31982 .name = DRV_NAME,
31983 .init_chipset = init_chipset_cmd64x,
31984 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31985 index 2c1e5f7..1444762 100644
31986 --- a/drivers/ide/cs5520.c
31987 +++ b/drivers/ide/cs5520.c
31988 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31989 .set_dma_mode = cs5520_set_dma_mode,
31990 };
31991
31992 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31993 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31994 .name = DRV_NAME,
31995 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31996 .port_ops = &cs5520_port_ops,
31997 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31998 index 4dc4eb9..49b40ad 100644
31999 --- a/drivers/ide/cs5530.c
32000 +++ b/drivers/ide/cs5530.c
32001 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
32002 .udma_filter = cs5530_udma_filter,
32003 };
32004
32005 -static const struct ide_port_info cs5530_chipset __devinitdata = {
32006 +static const struct ide_port_info cs5530_chipset __devinitconst = {
32007 .name = DRV_NAME,
32008 .init_chipset = init_chipset_cs5530,
32009 .init_hwif = init_hwif_cs5530,
32010 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
32011 index 5059faf..18d4c85 100644
32012 --- a/drivers/ide/cs5535.c
32013 +++ b/drivers/ide/cs5535.c
32014 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
32015 .cable_detect = cs5535_cable_detect,
32016 };
32017
32018 -static const struct ide_port_info cs5535_chipset __devinitdata = {
32019 +static const struct ide_port_info cs5535_chipset __devinitconst = {
32020 .name = DRV_NAME,
32021 .port_ops = &cs5535_port_ops,
32022 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
32023 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
32024 index 847553f..3ffb49d 100644
32025 --- a/drivers/ide/cy82c693.c
32026 +++ b/drivers/ide/cy82c693.c
32027 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
32028 .set_dma_mode = cy82c693_set_dma_mode,
32029 };
32030
32031 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
32032 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
32033 .name = DRV_NAME,
32034 .init_iops = init_iops_cy82c693,
32035 .port_ops = &cy82c693_port_ops,
32036 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
32037 index 58c51cd..4aec3b8 100644
32038 --- a/drivers/ide/hpt366.c
32039 +++ b/drivers/ide/hpt366.c
32040 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
32041 }
32042 };
32043
32044 -static const struct hpt_info hpt36x __devinitdata = {
32045 +static const struct hpt_info hpt36x __devinitconst = {
32046 .chip_name = "HPT36x",
32047 .chip_type = HPT36x,
32048 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
32049 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
32050 .timings = &hpt36x_timings
32051 };
32052
32053 -static const struct hpt_info hpt370 __devinitdata = {
32054 +static const struct hpt_info hpt370 __devinitconst = {
32055 .chip_name = "HPT370",
32056 .chip_type = HPT370,
32057 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
32058 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
32059 .timings = &hpt37x_timings
32060 };
32061
32062 -static const struct hpt_info hpt370a __devinitdata = {
32063 +static const struct hpt_info hpt370a __devinitconst = {
32064 .chip_name = "HPT370A",
32065 .chip_type = HPT370A,
32066 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
32067 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
32068 .timings = &hpt37x_timings
32069 };
32070
32071 -static const struct hpt_info hpt374 __devinitdata = {
32072 +static const struct hpt_info hpt374 __devinitconst = {
32073 .chip_name = "HPT374",
32074 .chip_type = HPT374,
32075 .udma_mask = ATA_UDMA5,
32076 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
32077 .timings = &hpt37x_timings
32078 };
32079
32080 -static const struct hpt_info hpt372 __devinitdata = {
32081 +static const struct hpt_info hpt372 __devinitconst = {
32082 .chip_name = "HPT372",
32083 .chip_type = HPT372,
32084 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32085 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
32086 .timings = &hpt37x_timings
32087 };
32088
32089 -static const struct hpt_info hpt372a __devinitdata = {
32090 +static const struct hpt_info hpt372a __devinitconst = {
32091 .chip_name = "HPT372A",
32092 .chip_type = HPT372A,
32093 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32094 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
32095 .timings = &hpt37x_timings
32096 };
32097
32098 -static const struct hpt_info hpt302 __devinitdata = {
32099 +static const struct hpt_info hpt302 __devinitconst = {
32100 .chip_name = "HPT302",
32101 .chip_type = HPT302,
32102 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32103 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
32104 .timings = &hpt37x_timings
32105 };
32106
32107 -static const struct hpt_info hpt371 __devinitdata = {
32108 +static const struct hpt_info hpt371 __devinitconst = {
32109 .chip_name = "HPT371",
32110 .chip_type = HPT371,
32111 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32112 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
32113 .timings = &hpt37x_timings
32114 };
32115
32116 -static const struct hpt_info hpt372n __devinitdata = {
32117 +static const struct hpt_info hpt372n __devinitconst = {
32118 .chip_name = "HPT372N",
32119 .chip_type = HPT372N,
32120 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32121 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
32122 .timings = &hpt37x_timings
32123 };
32124
32125 -static const struct hpt_info hpt302n __devinitdata = {
32126 +static const struct hpt_info hpt302n __devinitconst = {
32127 .chip_name = "HPT302N",
32128 .chip_type = HPT302N,
32129 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32130 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
32131 .timings = &hpt37x_timings
32132 };
32133
32134 -static const struct hpt_info hpt371n __devinitdata = {
32135 +static const struct hpt_info hpt371n __devinitconst = {
32136 .chip_name = "HPT371N",
32137 .chip_type = HPT371N,
32138 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32139 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
32140 .dma_sff_read_status = ide_dma_sff_read_status,
32141 };
32142
32143 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
32144 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
32145 { /* 0: HPT36x */
32146 .name = DRV_NAME,
32147 .init_chipset = init_chipset_hpt366,
32148 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
32149 index 8126824..55a2798 100644
32150 --- a/drivers/ide/ide-cd.c
32151 +++ b/drivers/ide/ide-cd.c
32152 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
32153 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
32154 if ((unsigned long)buf & alignment
32155 || blk_rq_bytes(rq) & q->dma_pad_mask
32156 - || object_is_on_stack(buf))
32157 + || object_starts_on_stack(buf))
32158 drive->dma = 0;
32159 }
32160 }
32161 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
32162 index 7f56b73..dab5b67 100644
32163 --- a/drivers/ide/ide-pci-generic.c
32164 +++ b/drivers/ide/ide-pci-generic.c
32165 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
32166 .udma_mask = ATA_UDMA6, \
32167 }
32168
32169 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
32170 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
32171 /* 0: Unknown */
32172 DECLARE_GENERIC_PCI_DEV(0),
32173
32174 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
32175 index 560e66d..d5dd180 100644
32176 --- a/drivers/ide/it8172.c
32177 +++ b/drivers/ide/it8172.c
32178 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
32179 .set_dma_mode = it8172_set_dma_mode,
32180 };
32181
32182 -static const struct ide_port_info it8172_port_info __devinitdata = {
32183 +static const struct ide_port_info it8172_port_info __devinitconst = {
32184 .name = DRV_NAME,
32185 .port_ops = &it8172_port_ops,
32186 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
32187 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
32188 index 46816ba..1847aeb 100644
32189 --- a/drivers/ide/it8213.c
32190 +++ b/drivers/ide/it8213.c
32191 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
32192 .cable_detect = it8213_cable_detect,
32193 };
32194
32195 -static const struct ide_port_info it8213_chipset __devinitdata = {
32196 +static const struct ide_port_info it8213_chipset __devinitconst = {
32197 .name = DRV_NAME,
32198 .enablebits = { {0x41, 0x80, 0x80} },
32199 .port_ops = &it8213_port_ops,
32200 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
32201 index 2e3169f..c5611db 100644
32202 --- a/drivers/ide/it821x.c
32203 +++ b/drivers/ide/it821x.c
32204 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
32205 .cable_detect = it821x_cable_detect,
32206 };
32207
32208 -static const struct ide_port_info it821x_chipset __devinitdata = {
32209 +static const struct ide_port_info it821x_chipset __devinitconst = {
32210 .name = DRV_NAME,
32211 .init_chipset = init_chipset_it821x,
32212 .init_hwif = init_hwif_it821x,
32213 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
32214 index 74c2c4a..efddd7d 100644
32215 --- a/drivers/ide/jmicron.c
32216 +++ b/drivers/ide/jmicron.c
32217 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
32218 .cable_detect = jmicron_cable_detect,
32219 };
32220
32221 -static const struct ide_port_info jmicron_chipset __devinitdata = {
32222 +static const struct ide_port_info jmicron_chipset __devinitconst = {
32223 .name = DRV_NAME,
32224 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
32225 .port_ops = &jmicron_port_ops,
32226 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
32227 index 95327a2..73f78d8 100644
32228 --- a/drivers/ide/ns87415.c
32229 +++ b/drivers/ide/ns87415.c
32230 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
32231 .dma_sff_read_status = superio_dma_sff_read_status,
32232 };
32233
32234 -static const struct ide_port_info ns87415_chipset __devinitdata = {
32235 +static const struct ide_port_info ns87415_chipset __devinitconst = {
32236 .name = DRV_NAME,
32237 .init_hwif = init_hwif_ns87415,
32238 .tp_ops = &ns87415_tp_ops,
32239 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
32240 index 1a53a4c..39edc66 100644
32241 --- a/drivers/ide/opti621.c
32242 +++ b/drivers/ide/opti621.c
32243 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
32244 .set_pio_mode = opti621_set_pio_mode,
32245 };
32246
32247 -static const struct ide_port_info opti621_chipset __devinitdata = {
32248 +static const struct ide_port_info opti621_chipset __devinitconst = {
32249 .name = DRV_NAME,
32250 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
32251 .port_ops = &opti621_port_ops,
32252 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
32253 index 9546fe2..2e5ceb6 100644
32254 --- a/drivers/ide/pdc202xx_new.c
32255 +++ b/drivers/ide/pdc202xx_new.c
32256 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
32257 .udma_mask = udma, \
32258 }
32259
32260 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32261 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32262 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32263 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32264 };
32265 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32266 index 3a35ec6..5634510 100644
32267 --- a/drivers/ide/pdc202xx_old.c
32268 +++ b/drivers/ide/pdc202xx_old.c
32269 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32270 .max_sectors = sectors, \
32271 }
32272
32273 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32274 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32275 { /* 0: PDC20246 */
32276 .name = DRV_NAME,
32277 .init_chipset = init_chipset_pdc202xx,
32278 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32279 index 1892e81..fe0fd60 100644
32280 --- a/drivers/ide/piix.c
32281 +++ b/drivers/ide/piix.c
32282 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32283 .udma_mask = udma, \
32284 }
32285
32286 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32287 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32288 /* 0: MPIIX */
32289 { /*
32290 * MPIIX actually has only a single IDE channel mapped to
32291 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32292 index a6414a8..c04173e 100644
32293 --- a/drivers/ide/rz1000.c
32294 +++ b/drivers/ide/rz1000.c
32295 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32296 }
32297 }
32298
32299 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32300 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32301 .name = DRV_NAME,
32302 .host_flags = IDE_HFLAG_NO_DMA,
32303 };
32304 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32305 index 356b9b5..d4758eb 100644
32306 --- a/drivers/ide/sc1200.c
32307 +++ b/drivers/ide/sc1200.c
32308 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32309 .dma_sff_read_status = ide_dma_sff_read_status,
32310 };
32311
32312 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32313 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32314 .name = DRV_NAME,
32315 .port_ops = &sc1200_port_ops,
32316 .dma_ops = &sc1200_dma_ops,
32317 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32318 index b7f5b0c..9701038 100644
32319 --- a/drivers/ide/scc_pata.c
32320 +++ b/drivers/ide/scc_pata.c
32321 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32322 .dma_sff_read_status = scc_dma_sff_read_status,
32323 };
32324
32325 -static const struct ide_port_info scc_chipset __devinitdata = {
32326 +static const struct ide_port_info scc_chipset __devinitconst = {
32327 .name = "sccIDE",
32328 .init_iops = init_iops_scc,
32329 .init_dma = scc_init_dma,
32330 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32331 index 35fb8da..24d72ef 100644
32332 --- a/drivers/ide/serverworks.c
32333 +++ b/drivers/ide/serverworks.c
32334 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32335 .cable_detect = svwks_cable_detect,
32336 };
32337
32338 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32339 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32340 { /* 0: OSB4 */
32341 .name = DRV_NAME,
32342 .init_chipset = init_chipset_svwks,
32343 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32344 index ddeda44..46f7e30 100644
32345 --- a/drivers/ide/siimage.c
32346 +++ b/drivers/ide/siimage.c
32347 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32348 .udma_mask = ATA_UDMA6, \
32349 }
32350
32351 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32352 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32353 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32354 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32355 };
32356 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32357 index 4a00225..09e61b4 100644
32358 --- a/drivers/ide/sis5513.c
32359 +++ b/drivers/ide/sis5513.c
32360 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32361 .cable_detect = sis_cable_detect,
32362 };
32363
32364 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32365 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32366 .name = DRV_NAME,
32367 .init_chipset = init_chipset_sis5513,
32368 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32369 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32370 index f21dc2a..d051cd2 100644
32371 --- a/drivers/ide/sl82c105.c
32372 +++ b/drivers/ide/sl82c105.c
32373 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32374 .dma_sff_read_status = ide_dma_sff_read_status,
32375 };
32376
32377 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32378 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32379 .name = DRV_NAME,
32380 .init_chipset = init_chipset_sl82c105,
32381 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32382 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32383 index 864ffe0..863a5e9 100644
32384 --- a/drivers/ide/slc90e66.c
32385 +++ b/drivers/ide/slc90e66.c
32386 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32387 .cable_detect = slc90e66_cable_detect,
32388 };
32389
32390 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32391 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32392 .name = DRV_NAME,
32393 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32394 .port_ops = &slc90e66_port_ops,
32395 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32396 index 4799d5c..1794678 100644
32397 --- a/drivers/ide/tc86c001.c
32398 +++ b/drivers/ide/tc86c001.c
32399 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32400 .dma_sff_read_status = ide_dma_sff_read_status,
32401 };
32402
32403 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32404 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32405 .name = DRV_NAME,
32406 .init_hwif = init_hwif_tc86c001,
32407 .port_ops = &tc86c001_port_ops,
32408 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32409 index 281c914..55ce1b8 100644
32410 --- a/drivers/ide/triflex.c
32411 +++ b/drivers/ide/triflex.c
32412 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32413 .set_dma_mode = triflex_set_mode,
32414 };
32415
32416 -static const struct ide_port_info triflex_device __devinitdata = {
32417 +static const struct ide_port_info triflex_device __devinitconst = {
32418 .name = DRV_NAME,
32419 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32420 .port_ops = &triflex_port_ops,
32421 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32422 index 4b42ca0..e494a98 100644
32423 --- a/drivers/ide/trm290.c
32424 +++ b/drivers/ide/trm290.c
32425 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32426 .dma_check = trm290_dma_check,
32427 };
32428
32429 -static const struct ide_port_info trm290_chipset __devinitdata = {
32430 +static const struct ide_port_info trm290_chipset __devinitconst = {
32431 .name = DRV_NAME,
32432 .init_hwif = init_hwif_trm290,
32433 .tp_ops = &trm290_tp_ops,
32434 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32435 index f46f49c..eb77678 100644
32436 --- a/drivers/ide/via82cxxx.c
32437 +++ b/drivers/ide/via82cxxx.c
32438 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32439 .cable_detect = via82cxxx_cable_detect,
32440 };
32441
32442 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32443 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32444 .name = DRV_NAME,
32445 .init_chipset = init_chipset_via82cxxx,
32446 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32447 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32448 index 73d4531..c90cd2d 100644
32449 --- a/drivers/ieee802154/fakehard.c
32450 +++ b/drivers/ieee802154/fakehard.c
32451 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32452 phy->transmit_power = 0xbf;
32453
32454 dev->netdev_ops = &fake_ops;
32455 - dev->ml_priv = &fake_mlme;
32456 + dev->ml_priv = (void *)&fake_mlme;
32457
32458 priv = netdev_priv(dev);
32459 priv->phy = phy;
32460 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32461 index d67999f..4c5d083 100644
32462 --- a/drivers/infiniband/core/cm.c
32463 +++ b/drivers/infiniband/core/cm.c
32464 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32465
32466 struct cm_counter_group {
32467 struct kobject obj;
32468 - atomic_long_t counter[CM_ATTR_COUNT];
32469 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32470 };
32471
32472 struct cm_counter_attribute {
32473 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32474 struct ib_mad_send_buf *msg = NULL;
32475 int ret;
32476
32477 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32478 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32479 counter[CM_REQ_COUNTER]);
32480
32481 /* Quick state check to discard duplicate REQs. */
32482 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32483 if (!cm_id_priv)
32484 return;
32485
32486 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32487 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32488 counter[CM_REP_COUNTER]);
32489 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32490 if (ret)
32491 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32492 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32493 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32494 spin_unlock_irq(&cm_id_priv->lock);
32495 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32496 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32497 counter[CM_RTU_COUNTER]);
32498 goto out;
32499 }
32500 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32501 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32502 dreq_msg->local_comm_id);
32503 if (!cm_id_priv) {
32504 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32505 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32506 counter[CM_DREQ_COUNTER]);
32507 cm_issue_drep(work->port, work->mad_recv_wc);
32508 return -EINVAL;
32509 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32510 case IB_CM_MRA_REP_RCVD:
32511 break;
32512 case IB_CM_TIMEWAIT:
32513 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32514 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32515 counter[CM_DREQ_COUNTER]);
32516 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32517 goto unlock;
32518 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32519 cm_free_msg(msg);
32520 goto deref;
32521 case IB_CM_DREQ_RCVD:
32522 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32523 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32524 counter[CM_DREQ_COUNTER]);
32525 goto unlock;
32526 default:
32527 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32528 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32529 cm_id_priv->msg, timeout)) {
32530 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32531 - atomic_long_inc(&work->port->
32532 + atomic_long_inc_unchecked(&work->port->
32533 counter_group[CM_RECV_DUPLICATES].
32534 counter[CM_MRA_COUNTER]);
32535 goto out;
32536 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32537 break;
32538 case IB_CM_MRA_REQ_RCVD:
32539 case IB_CM_MRA_REP_RCVD:
32540 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32541 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32542 counter[CM_MRA_COUNTER]);
32543 /* fall through */
32544 default:
32545 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32546 case IB_CM_LAP_IDLE:
32547 break;
32548 case IB_CM_MRA_LAP_SENT:
32549 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32550 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32551 counter[CM_LAP_COUNTER]);
32552 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32553 goto unlock;
32554 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32555 cm_free_msg(msg);
32556 goto deref;
32557 case IB_CM_LAP_RCVD:
32558 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32559 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32560 counter[CM_LAP_COUNTER]);
32561 goto unlock;
32562 default:
32563 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32564 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32565 if (cur_cm_id_priv) {
32566 spin_unlock_irq(&cm.lock);
32567 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32568 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32569 counter[CM_SIDR_REQ_COUNTER]);
32570 goto out; /* Duplicate message. */
32571 }
32572 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32573 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32574 msg->retries = 1;
32575
32576 - atomic_long_add(1 + msg->retries,
32577 + atomic_long_add_unchecked(1 + msg->retries,
32578 &port->counter_group[CM_XMIT].counter[attr_index]);
32579 if (msg->retries)
32580 - atomic_long_add(msg->retries,
32581 + atomic_long_add_unchecked(msg->retries,
32582 &port->counter_group[CM_XMIT_RETRIES].
32583 counter[attr_index]);
32584
32585 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32586 }
32587
32588 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32589 - atomic_long_inc(&port->counter_group[CM_RECV].
32590 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32591 counter[attr_id - CM_ATTR_ID_OFFSET]);
32592
32593 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32594 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32595 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32596
32597 return sprintf(buf, "%ld\n",
32598 - atomic_long_read(&group->counter[cm_attr->index]));
32599 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32600 }
32601
32602 static const struct sysfs_ops cm_counter_ops = {
32603 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32604 index 176c8f9..2627b62 100644
32605 --- a/drivers/infiniband/core/fmr_pool.c
32606 +++ b/drivers/infiniband/core/fmr_pool.c
32607 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32608
32609 struct task_struct *thread;
32610
32611 - atomic_t req_ser;
32612 - atomic_t flush_ser;
32613 + atomic_unchecked_t req_ser;
32614 + atomic_unchecked_t flush_ser;
32615
32616 wait_queue_head_t force_wait;
32617 };
32618 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32619 struct ib_fmr_pool *pool = pool_ptr;
32620
32621 do {
32622 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32623 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32624 ib_fmr_batch_release(pool);
32625
32626 - atomic_inc(&pool->flush_ser);
32627 + atomic_inc_unchecked(&pool->flush_ser);
32628 wake_up_interruptible(&pool->force_wait);
32629
32630 if (pool->flush_function)
32631 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32632 }
32633
32634 set_current_state(TASK_INTERRUPTIBLE);
32635 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32636 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32637 !kthread_should_stop())
32638 schedule();
32639 __set_current_state(TASK_RUNNING);
32640 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32641 pool->dirty_watermark = params->dirty_watermark;
32642 pool->dirty_len = 0;
32643 spin_lock_init(&pool->pool_lock);
32644 - atomic_set(&pool->req_ser, 0);
32645 - atomic_set(&pool->flush_ser, 0);
32646 + atomic_set_unchecked(&pool->req_ser, 0);
32647 + atomic_set_unchecked(&pool->flush_ser, 0);
32648 init_waitqueue_head(&pool->force_wait);
32649
32650 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32651 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32652 }
32653 spin_unlock_irq(&pool->pool_lock);
32654
32655 - serial = atomic_inc_return(&pool->req_ser);
32656 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32657 wake_up_process(pool->thread);
32658
32659 if (wait_event_interruptible(pool->force_wait,
32660 - atomic_read(&pool->flush_ser) - serial >= 0))
32661 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32662 return -EINTR;
32663
32664 return 0;
32665 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32666 } else {
32667 list_add_tail(&fmr->list, &pool->dirty_list);
32668 if (++pool->dirty_len >= pool->dirty_watermark) {
32669 - atomic_inc(&pool->req_ser);
32670 + atomic_inc_unchecked(&pool->req_ser);
32671 wake_up_process(pool->thread);
32672 }
32673 }
32674 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32675 index 57e07c6..56d09d4 100644
32676 --- a/drivers/infiniband/hw/cxgb4/mem.c
32677 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32678 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32679 int err;
32680 struct fw_ri_tpte tpt;
32681 u32 stag_idx;
32682 - static atomic_t key;
32683 + static atomic_unchecked_t key;
32684
32685 if (c4iw_fatal_error(rdev))
32686 return -EIO;
32687 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32688 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32689 rdev->stats.stag.max = rdev->stats.stag.cur;
32690 mutex_unlock(&rdev->stats.lock);
32691 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32692 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32693 }
32694 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32695 __func__, stag_state, type, pdid, stag_idx);
32696 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32697 index 79b3dbc..96e5fcc 100644
32698 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32699 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32700 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32701 struct ib_atomic_eth *ateth;
32702 struct ipath_ack_entry *e;
32703 u64 vaddr;
32704 - atomic64_t *maddr;
32705 + atomic64_unchecked_t *maddr;
32706 u64 sdata;
32707 u32 rkey;
32708 u8 next;
32709 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32710 IB_ACCESS_REMOTE_ATOMIC)))
32711 goto nack_acc_unlck;
32712 /* Perform atomic OP and save result. */
32713 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32714 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32715 sdata = be64_to_cpu(ateth->swap_data);
32716 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32717 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32718 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32719 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32720 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32721 be64_to_cpu(ateth->compare_data),
32722 sdata);
32723 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32724 index 1f95bba..9530f87 100644
32725 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32726 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32727 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32728 unsigned long flags;
32729 struct ib_wc wc;
32730 u64 sdata;
32731 - atomic64_t *maddr;
32732 + atomic64_unchecked_t *maddr;
32733 enum ib_wc_status send_status;
32734
32735 /*
32736 @@ -382,11 +382,11 @@ again:
32737 IB_ACCESS_REMOTE_ATOMIC)))
32738 goto acc_err;
32739 /* Perform atomic OP and save result. */
32740 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32741 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32742 sdata = wqe->wr.wr.atomic.compare_add;
32743 *(u64 *) sqp->s_sge.sge.vaddr =
32744 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32745 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32746 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32747 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32748 sdata, wqe->wr.wr.atomic.swap);
32749 goto send_comp;
32750 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32751 index 7140199..da60063 100644
32752 --- a/drivers/infiniband/hw/nes/nes.c
32753 +++ b/drivers/infiniband/hw/nes/nes.c
32754 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32755 LIST_HEAD(nes_adapter_list);
32756 static LIST_HEAD(nes_dev_list);
32757
32758 -atomic_t qps_destroyed;
32759 +atomic_unchecked_t qps_destroyed;
32760
32761 static unsigned int ee_flsh_adapter;
32762 static unsigned int sysfs_nonidx_addr;
32763 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32764 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32765 struct nes_adapter *nesadapter = nesdev->nesadapter;
32766
32767 - atomic_inc(&qps_destroyed);
32768 + atomic_inc_unchecked(&qps_destroyed);
32769
32770 /* Free the control structures */
32771
32772 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32773 index c438e46..ca30356 100644
32774 --- a/drivers/infiniband/hw/nes/nes.h
32775 +++ b/drivers/infiniband/hw/nes/nes.h
32776 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32777 extern unsigned int wqm_quanta;
32778 extern struct list_head nes_adapter_list;
32779
32780 -extern atomic_t cm_connects;
32781 -extern atomic_t cm_accepts;
32782 -extern atomic_t cm_disconnects;
32783 -extern atomic_t cm_closes;
32784 -extern atomic_t cm_connecteds;
32785 -extern atomic_t cm_connect_reqs;
32786 -extern atomic_t cm_rejects;
32787 -extern atomic_t mod_qp_timouts;
32788 -extern atomic_t qps_created;
32789 -extern atomic_t qps_destroyed;
32790 -extern atomic_t sw_qps_destroyed;
32791 +extern atomic_unchecked_t cm_connects;
32792 +extern atomic_unchecked_t cm_accepts;
32793 +extern atomic_unchecked_t cm_disconnects;
32794 +extern atomic_unchecked_t cm_closes;
32795 +extern atomic_unchecked_t cm_connecteds;
32796 +extern atomic_unchecked_t cm_connect_reqs;
32797 +extern atomic_unchecked_t cm_rejects;
32798 +extern atomic_unchecked_t mod_qp_timouts;
32799 +extern atomic_unchecked_t qps_created;
32800 +extern atomic_unchecked_t qps_destroyed;
32801 +extern atomic_unchecked_t sw_qps_destroyed;
32802 extern u32 mh_detected;
32803 extern u32 mh_pauses_sent;
32804 extern u32 cm_packets_sent;
32805 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32806 extern u32 cm_packets_received;
32807 extern u32 cm_packets_dropped;
32808 extern u32 cm_packets_retrans;
32809 -extern atomic_t cm_listens_created;
32810 -extern atomic_t cm_listens_destroyed;
32811 +extern atomic_unchecked_t cm_listens_created;
32812 +extern atomic_unchecked_t cm_listens_destroyed;
32813 extern u32 cm_backlog_drops;
32814 -extern atomic_t cm_loopbacks;
32815 -extern atomic_t cm_nodes_created;
32816 -extern atomic_t cm_nodes_destroyed;
32817 -extern atomic_t cm_accel_dropped_pkts;
32818 -extern atomic_t cm_resets_recvd;
32819 -extern atomic_t pau_qps_created;
32820 -extern atomic_t pau_qps_destroyed;
32821 +extern atomic_unchecked_t cm_loopbacks;
32822 +extern atomic_unchecked_t cm_nodes_created;
32823 +extern atomic_unchecked_t cm_nodes_destroyed;
32824 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32825 +extern atomic_unchecked_t cm_resets_recvd;
32826 +extern atomic_unchecked_t pau_qps_created;
32827 +extern atomic_unchecked_t pau_qps_destroyed;
32828
32829 extern u32 int_mod_timer_init;
32830 extern u32 int_mod_cq_depth_256;
32831 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32832 index 020e95c..fbb3450 100644
32833 --- a/drivers/infiniband/hw/nes/nes_cm.c
32834 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32835 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32836 u32 cm_packets_retrans;
32837 u32 cm_packets_created;
32838 u32 cm_packets_received;
32839 -atomic_t cm_listens_created;
32840 -atomic_t cm_listens_destroyed;
32841 +atomic_unchecked_t cm_listens_created;
32842 +atomic_unchecked_t cm_listens_destroyed;
32843 u32 cm_backlog_drops;
32844 -atomic_t cm_loopbacks;
32845 -atomic_t cm_nodes_created;
32846 -atomic_t cm_nodes_destroyed;
32847 -atomic_t cm_accel_dropped_pkts;
32848 -atomic_t cm_resets_recvd;
32849 +atomic_unchecked_t cm_loopbacks;
32850 +atomic_unchecked_t cm_nodes_created;
32851 +atomic_unchecked_t cm_nodes_destroyed;
32852 +atomic_unchecked_t cm_accel_dropped_pkts;
32853 +atomic_unchecked_t cm_resets_recvd;
32854
32855 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32856 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32857 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32858
32859 static struct nes_cm_core *g_cm_core;
32860
32861 -atomic_t cm_connects;
32862 -atomic_t cm_accepts;
32863 -atomic_t cm_disconnects;
32864 -atomic_t cm_closes;
32865 -atomic_t cm_connecteds;
32866 -atomic_t cm_connect_reqs;
32867 -atomic_t cm_rejects;
32868 +atomic_unchecked_t cm_connects;
32869 +atomic_unchecked_t cm_accepts;
32870 +atomic_unchecked_t cm_disconnects;
32871 +atomic_unchecked_t cm_closes;
32872 +atomic_unchecked_t cm_connecteds;
32873 +atomic_unchecked_t cm_connect_reqs;
32874 +atomic_unchecked_t cm_rejects;
32875
32876 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32877 {
32878 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32879 kfree(listener);
32880 listener = NULL;
32881 ret = 0;
32882 - atomic_inc(&cm_listens_destroyed);
32883 + atomic_inc_unchecked(&cm_listens_destroyed);
32884 } else {
32885 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32886 }
32887 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32888 cm_node->rem_mac);
32889
32890 add_hte_node(cm_core, cm_node);
32891 - atomic_inc(&cm_nodes_created);
32892 + atomic_inc_unchecked(&cm_nodes_created);
32893
32894 return cm_node;
32895 }
32896 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32897 }
32898
32899 atomic_dec(&cm_core->node_cnt);
32900 - atomic_inc(&cm_nodes_destroyed);
32901 + atomic_inc_unchecked(&cm_nodes_destroyed);
32902 nesqp = cm_node->nesqp;
32903 if (nesqp) {
32904 nesqp->cm_node = NULL;
32905 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32906
32907 static void drop_packet(struct sk_buff *skb)
32908 {
32909 - atomic_inc(&cm_accel_dropped_pkts);
32910 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32911 dev_kfree_skb_any(skb);
32912 }
32913
32914 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32915 {
32916
32917 int reset = 0; /* whether to send reset in case of err.. */
32918 - atomic_inc(&cm_resets_recvd);
32919 + atomic_inc_unchecked(&cm_resets_recvd);
32920 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32921 " refcnt=%d\n", cm_node, cm_node->state,
32922 atomic_read(&cm_node->ref_count));
32923 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32924 rem_ref_cm_node(cm_node->cm_core, cm_node);
32925 return NULL;
32926 }
32927 - atomic_inc(&cm_loopbacks);
32928 + atomic_inc_unchecked(&cm_loopbacks);
32929 loopbackremotenode->loopbackpartner = cm_node;
32930 loopbackremotenode->tcp_cntxt.rcv_wscale =
32931 NES_CM_DEFAULT_RCV_WND_SCALE;
32932 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32933 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32934 else {
32935 rem_ref_cm_node(cm_core, cm_node);
32936 - atomic_inc(&cm_accel_dropped_pkts);
32937 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32938 dev_kfree_skb_any(skb);
32939 }
32940 break;
32941 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32942
32943 if ((cm_id) && (cm_id->event_handler)) {
32944 if (issue_disconn) {
32945 - atomic_inc(&cm_disconnects);
32946 + atomic_inc_unchecked(&cm_disconnects);
32947 cm_event.event = IW_CM_EVENT_DISCONNECT;
32948 cm_event.status = disconn_status;
32949 cm_event.local_addr = cm_id->local_addr;
32950 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32951 }
32952
32953 if (issue_close) {
32954 - atomic_inc(&cm_closes);
32955 + atomic_inc_unchecked(&cm_closes);
32956 nes_disconnect(nesqp, 1);
32957
32958 cm_id->provider_data = nesqp;
32959 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32960
32961 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32962 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32963 - atomic_inc(&cm_accepts);
32964 + atomic_inc_unchecked(&cm_accepts);
32965
32966 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32967 netdev_refcnt_read(nesvnic->netdev));
32968 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32969 struct nes_cm_core *cm_core;
32970 u8 *start_buff;
32971
32972 - atomic_inc(&cm_rejects);
32973 + atomic_inc_unchecked(&cm_rejects);
32974 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32975 loopback = cm_node->loopbackpartner;
32976 cm_core = cm_node->cm_core;
32977 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32978 ntohl(cm_id->local_addr.sin_addr.s_addr),
32979 ntohs(cm_id->local_addr.sin_port));
32980
32981 - atomic_inc(&cm_connects);
32982 + atomic_inc_unchecked(&cm_connects);
32983 nesqp->active_conn = 1;
32984
32985 /* cache the cm_id in the qp */
32986 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32987 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32988 return err;
32989 }
32990 - atomic_inc(&cm_listens_created);
32991 + atomic_inc_unchecked(&cm_listens_created);
32992 }
32993
32994 cm_id->add_ref(cm_id);
32995 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32996
32997 if (nesqp->destroyed)
32998 return;
32999 - atomic_inc(&cm_connecteds);
33000 + atomic_inc_unchecked(&cm_connecteds);
33001 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
33002 " local port 0x%04X. jiffies = %lu.\n",
33003 nesqp->hwqp.qp_id,
33004 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
33005
33006 cm_id->add_ref(cm_id);
33007 ret = cm_id->event_handler(cm_id, &cm_event);
33008 - atomic_inc(&cm_closes);
33009 + atomic_inc_unchecked(&cm_closes);
33010 cm_event.event = IW_CM_EVENT_CLOSE;
33011 cm_event.status = 0;
33012 cm_event.provider_data = cm_id->provider_data;
33013 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
33014 return;
33015 cm_id = cm_node->cm_id;
33016
33017 - atomic_inc(&cm_connect_reqs);
33018 + atomic_inc_unchecked(&cm_connect_reqs);
33019 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33020 cm_node, cm_id, jiffies);
33021
33022 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
33023 return;
33024 cm_id = cm_node->cm_id;
33025
33026 - atomic_inc(&cm_connect_reqs);
33027 + atomic_inc_unchecked(&cm_connect_reqs);
33028 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33029 cm_node, cm_id, jiffies);
33030
33031 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
33032 index 3ba7be3..c81f6ff 100644
33033 --- a/drivers/infiniband/hw/nes/nes_mgt.c
33034 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
33035 @@ -40,8 +40,8 @@
33036 #include "nes.h"
33037 #include "nes_mgt.h"
33038
33039 -atomic_t pau_qps_created;
33040 -atomic_t pau_qps_destroyed;
33041 +atomic_unchecked_t pau_qps_created;
33042 +atomic_unchecked_t pau_qps_destroyed;
33043
33044 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
33045 {
33046 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
33047 {
33048 struct sk_buff *skb;
33049 unsigned long flags;
33050 - atomic_inc(&pau_qps_destroyed);
33051 + atomic_inc_unchecked(&pau_qps_destroyed);
33052
33053 /* Free packets that have not yet been forwarded */
33054 /* Lock is acquired by skb_dequeue when removing the skb */
33055 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
33056 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
33057 skb_queue_head_init(&nesqp->pau_list);
33058 spin_lock_init(&nesqp->pau_lock);
33059 - atomic_inc(&pau_qps_created);
33060 + atomic_inc_unchecked(&pau_qps_created);
33061 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
33062 }
33063
33064 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
33065 index f3a3ecf..57d311d 100644
33066 --- a/drivers/infiniband/hw/nes/nes_nic.c
33067 +++ b/drivers/infiniband/hw/nes/nes_nic.c
33068 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
33069 target_stat_values[++index] = mh_detected;
33070 target_stat_values[++index] = mh_pauses_sent;
33071 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
33072 - target_stat_values[++index] = atomic_read(&cm_connects);
33073 - target_stat_values[++index] = atomic_read(&cm_accepts);
33074 - target_stat_values[++index] = atomic_read(&cm_disconnects);
33075 - target_stat_values[++index] = atomic_read(&cm_connecteds);
33076 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
33077 - target_stat_values[++index] = atomic_read(&cm_rejects);
33078 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
33079 - target_stat_values[++index] = atomic_read(&qps_created);
33080 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
33081 - target_stat_values[++index] = atomic_read(&qps_destroyed);
33082 - target_stat_values[++index] = atomic_read(&cm_closes);
33083 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
33084 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
33085 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
33086 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
33087 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
33088 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
33089 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
33090 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
33091 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
33092 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
33093 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
33094 target_stat_values[++index] = cm_packets_sent;
33095 target_stat_values[++index] = cm_packets_bounced;
33096 target_stat_values[++index] = cm_packets_created;
33097 target_stat_values[++index] = cm_packets_received;
33098 target_stat_values[++index] = cm_packets_dropped;
33099 target_stat_values[++index] = cm_packets_retrans;
33100 - target_stat_values[++index] = atomic_read(&cm_listens_created);
33101 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
33102 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
33103 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
33104 target_stat_values[++index] = cm_backlog_drops;
33105 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
33106 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
33107 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
33108 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
33109 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
33110 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
33111 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
33112 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
33113 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
33114 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
33115 target_stat_values[++index] = nesadapter->free_4kpbl;
33116 target_stat_values[++index] = nesadapter->free_256pbl;
33117 target_stat_values[++index] = int_mod_timer_init;
33118 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
33119 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
33120 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
33121 - target_stat_values[++index] = atomic_read(&pau_qps_created);
33122 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
33123 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
33124 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
33125 }
33126
33127 /**
33128 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
33129 index 8b8812d..a5e1133 100644
33130 --- a/drivers/infiniband/hw/nes/nes_verbs.c
33131 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
33132 @@ -46,9 +46,9 @@
33133
33134 #include <rdma/ib_umem.h>
33135
33136 -atomic_t mod_qp_timouts;
33137 -atomic_t qps_created;
33138 -atomic_t sw_qps_destroyed;
33139 +atomic_unchecked_t mod_qp_timouts;
33140 +atomic_unchecked_t qps_created;
33141 +atomic_unchecked_t sw_qps_destroyed;
33142
33143 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
33144
33145 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
33146 if (init_attr->create_flags)
33147 return ERR_PTR(-EINVAL);
33148
33149 - atomic_inc(&qps_created);
33150 + atomic_inc_unchecked(&qps_created);
33151 switch (init_attr->qp_type) {
33152 case IB_QPT_RC:
33153 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
33154 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
33155 struct iw_cm_event cm_event;
33156 int ret = 0;
33157
33158 - atomic_inc(&sw_qps_destroyed);
33159 + atomic_inc_unchecked(&sw_qps_destroyed);
33160 nesqp->destroyed = 1;
33161
33162 /* Blow away the connection if it exists. */
33163 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
33164 index 7b1b8669..4b69f85 100644
33165 --- a/drivers/infiniband/hw/qib/qib.h
33166 +++ b/drivers/infiniband/hw/qib/qib.h
33167 @@ -51,6 +51,7 @@
33168 #include <linux/completion.h>
33169 #include <linux/kref.h>
33170 #include <linux/sched.h>
33171 +#include <linux/slab.h>
33172
33173 #include "qib_common.h"
33174 #include "qib_verbs.h"
33175 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
33176 index da739d9..da1c7f4 100644
33177 --- a/drivers/input/gameport/gameport.c
33178 +++ b/drivers/input/gameport/gameport.c
33179 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
33180 */
33181 static void gameport_init_port(struct gameport *gameport)
33182 {
33183 - static atomic_t gameport_no = ATOMIC_INIT(0);
33184 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
33185
33186 __module_get(THIS_MODULE);
33187
33188 mutex_init(&gameport->drv_mutex);
33189 device_initialize(&gameport->dev);
33190 dev_set_name(&gameport->dev, "gameport%lu",
33191 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
33192 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
33193 gameport->dev.bus = &gameport_bus;
33194 gameport->dev.release = gameport_release_port;
33195 if (gameport->parent)
33196 diff --git a/drivers/input/input.c b/drivers/input/input.c
33197 index 8921c61..f5cd63d 100644
33198 --- a/drivers/input/input.c
33199 +++ b/drivers/input/input.c
33200 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
33201 */
33202 int input_register_device(struct input_dev *dev)
33203 {
33204 - static atomic_t input_no = ATOMIC_INIT(0);
33205 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
33206 struct input_handler *handler;
33207 const char *path;
33208 int error;
33209 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
33210 dev->setkeycode = input_default_setkeycode;
33211
33212 dev_set_name(&dev->dev, "input%ld",
33213 - (unsigned long) atomic_inc_return(&input_no) - 1);
33214 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
33215
33216 error = device_add(&dev->dev);
33217 if (error)
33218 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
33219 index 04c69af..5f92d00 100644
33220 --- a/drivers/input/joystick/sidewinder.c
33221 +++ b/drivers/input/joystick/sidewinder.c
33222 @@ -30,6 +30,7 @@
33223 #include <linux/kernel.h>
33224 #include <linux/module.h>
33225 #include <linux/slab.h>
33226 +#include <linux/sched.h>
33227 #include <linux/init.h>
33228 #include <linux/input.h>
33229 #include <linux/gameport.h>
33230 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
33231 index 83811e4..0822b90 100644
33232 --- a/drivers/input/joystick/xpad.c
33233 +++ b/drivers/input/joystick/xpad.c
33234 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
33235
33236 static int xpad_led_probe(struct usb_xpad *xpad)
33237 {
33238 - static atomic_t led_seq = ATOMIC_INIT(0);
33239 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
33240 long led_no;
33241 struct xpad_led *led;
33242 struct led_classdev *led_cdev;
33243 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
33244 if (!led)
33245 return -ENOMEM;
33246
33247 - led_no = (long)atomic_inc_return(&led_seq) - 1;
33248 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
33249
33250 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
33251 led->xpad = xpad;
33252 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
33253 index 0110b5a..d3ad144 100644
33254 --- a/drivers/input/mousedev.c
33255 +++ b/drivers/input/mousedev.c
33256 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33257
33258 spin_unlock_irq(&client->packet_lock);
33259
33260 - if (copy_to_user(buffer, data, count))
33261 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
33262 return -EFAULT;
33263
33264 return count;
33265 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33266 index d0f7533..fb8215b 100644
33267 --- a/drivers/input/serio/serio.c
33268 +++ b/drivers/input/serio/serio.c
33269 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33270 */
33271 static void serio_init_port(struct serio *serio)
33272 {
33273 - static atomic_t serio_no = ATOMIC_INIT(0);
33274 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33275
33276 __module_get(THIS_MODULE);
33277
33278 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33279 mutex_init(&serio->drv_mutex);
33280 device_initialize(&serio->dev);
33281 dev_set_name(&serio->dev, "serio%ld",
33282 - (long)atomic_inc_return(&serio_no) - 1);
33283 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33284 serio->dev.bus = &serio_bus;
33285 serio->dev.release = serio_release_port;
33286 serio->dev.groups = serio_device_attr_groups;
33287 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33288 index 38c4bd8..58965d9 100644
33289 --- a/drivers/isdn/capi/capi.c
33290 +++ b/drivers/isdn/capi/capi.c
33291 @@ -83,8 +83,8 @@ struct capiminor {
33292
33293 struct capi20_appl *ap;
33294 u32 ncci;
33295 - atomic_t datahandle;
33296 - atomic_t msgid;
33297 + atomic_unchecked_t datahandle;
33298 + atomic_unchecked_t msgid;
33299
33300 struct tty_port port;
33301 int ttyinstop;
33302 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33303 capimsg_setu16(s, 2, mp->ap->applid);
33304 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33305 capimsg_setu8 (s, 5, CAPI_RESP);
33306 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33307 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33308 capimsg_setu32(s, 8, mp->ncci);
33309 capimsg_setu16(s, 12, datahandle);
33310 }
33311 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33312 mp->outbytes -= len;
33313 spin_unlock_bh(&mp->outlock);
33314
33315 - datahandle = atomic_inc_return(&mp->datahandle);
33316 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33317 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33318 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33319 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33320 capimsg_setu16(skb->data, 2, mp->ap->applid);
33321 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33322 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33323 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33324 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33325 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33326 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33327 capimsg_setu16(skb->data, 16, len); /* Data length */
33328 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33329 index a6d9fd2..afdb8a3 100644
33330 --- a/drivers/isdn/gigaset/interface.c
33331 +++ b/drivers/isdn/gigaset/interface.c
33332 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33333 }
33334 tty->driver_data = cs;
33335
33336 - ++cs->port.count;
33337 + atomic_inc(&cs->port.count);
33338
33339 - if (cs->port.count == 1) {
33340 + if (atomic_read(&cs->port.count) == 1) {
33341 tty_port_tty_set(&cs->port, tty);
33342 tty->low_latency = 1;
33343 }
33344 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33345
33346 if (!cs->connected)
33347 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33348 - else if (!cs->port.count)
33349 + else if (!atomic_read(&cs->port.count))
33350 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33351 - else if (!--cs->port.count)
33352 + else if (!atomic_dec_return(&cs->port.count))
33353 tty_port_tty_set(&cs->port, NULL);
33354
33355 mutex_unlock(&cs->mutex);
33356 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33357 index 821f7ac..28d4030 100644
33358 --- a/drivers/isdn/hardware/avm/b1.c
33359 +++ b/drivers/isdn/hardware/avm/b1.c
33360 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33361 }
33362 if (left) {
33363 if (t4file->user) {
33364 - if (copy_from_user(buf, dp, left))
33365 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33366 return -EFAULT;
33367 } else {
33368 memcpy(buf, dp, left);
33369 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33370 }
33371 if (left) {
33372 if (config->user) {
33373 - if (copy_from_user(buf, dp, left))
33374 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33375 return -EFAULT;
33376 } else {
33377 memcpy(buf, dp, left);
33378 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33379 index dd6b53a..19d9ee6 100644
33380 --- a/drivers/isdn/hardware/eicon/divasync.h
33381 +++ b/drivers/isdn/hardware/eicon/divasync.h
33382 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33383 } diva_didd_add_adapter_t;
33384 typedef struct _diva_didd_remove_adapter {
33385 IDI_CALL p_request;
33386 -} diva_didd_remove_adapter_t;
33387 +} __no_const diva_didd_remove_adapter_t;
33388 typedef struct _diva_didd_read_adapter_array {
33389 void *buffer;
33390 dword length;
33391 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33392 index d303e65..28bcb7b 100644
33393 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33394 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33395 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33396 typedef struct _diva_os_idi_adapter_interface {
33397 diva_init_card_proc_t cleanup_adapter_proc;
33398 diva_cmd_card_proc_t cmd_proc;
33399 -} diva_os_idi_adapter_interface_t;
33400 +} __no_const diva_os_idi_adapter_interface_t;
33401
33402 typedef struct _diva_os_xdi_adapter {
33403 struct list_head link;
33404 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33405 index 7bc5067..fd36232 100644
33406 --- a/drivers/isdn/i4l/isdn_tty.c
33407 +++ b/drivers/isdn/i4l/isdn_tty.c
33408 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33409 port = &info->port;
33410 #ifdef ISDN_DEBUG_MODEM_OPEN
33411 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33412 - port->count);
33413 + atomic_read(&port->count))
33414 #endif
33415 - port->count++;
33416 + atomic_inc(&port->count);
33417 tty->driver_data = info;
33418 port->tty = tty;
33419 tty->port = port;
33420 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33421 #endif
33422 return;
33423 }
33424 - if ((tty->count == 1) && (port->count != 1)) {
33425 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33426 /*
33427 * Uh, oh. tty->count is 1, which means that the tty
33428 * structure will be freed. Info->count should always
33429 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33430 * serial port won't be shutdown.
33431 */
33432 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33433 - "info->count is %d\n", port->count);
33434 - port->count = 1;
33435 + "info->count is %d\n", atomic_read(&port->count));
33436 + atomic_set(&port->count, 1);
33437 }
33438 - if (--port->count < 0) {
33439 + if (atomic_dec_return(&port->count) < 0) {
33440 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33441 - info->line, port->count);
33442 - port->count = 0;
33443 + info->line, atomic_read(&port->count));
33444 + atomic_set(&port->count, 0);
33445 }
33446 - if (port->count) {
33447 + if (atomic_read(&port->count)) {
33448 #ifdef ISDN_DEBUG_MODEM_OPEN
33449 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33450 #endif
33451 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33452 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33453 return;
33454 isdn_tty_shutdown(info);
33455 - port->count = 0;
33456 + atomic_set(&port->count, 0);
33457 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33458 port->tty = NULL;
33459 wake_up_interruptible(&port->open_wait);
33460 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33461 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33462 modem_info *info = &dev->mdm.info[i];
33463
33464 - if (info->port.count == 0)
33465 + if (atomic_read(&info->port.count) == 0)
33466 continue;
33467 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33468 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33469 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33470 index e74df7c..03a03ba 100644
33471 --- a/drivers/isdn/icn/icn.c
33472 +++ b/drivers/isdn/icn/icn.c
33473 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33474 if (count > len)
33475 count = len;
33476 if (user) {
33477 - if (copy_from_user(msg, buf, count))
33478 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33479 return -EFAULT;
33480 } else
33481 memcpy(msg, buf, count);
33482 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33483 index b5fdcb7..5b6c59f 100644
33484 --- a/drivers/lguest/core.c
33485 +++ b/drivers/lguest/core.c
33486 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33487 * it's worked so far. The end address needs +1 because __get_vm_area
33488 * allocates an extra guard page, so we need space for that.
33489 */
33490 +
33491 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33492 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33493 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33494 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33495 +#else
33496 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33497 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33498 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33499 +#endif
33500 +
33501 if (!switcher_vma) {
33502 err = -ENOMEM;
33503 printk("lguest: could not map switcher pages high\n");
33504 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33505 * Now the Switcher is mapped at the right address, we can't fail!
33506 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33507 */
33508 - memcpy(switcher_vma->addr, start_switcher_text,
33509 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33510 end_switcher_text - start_switcher_text);
33511
33512 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33513 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33514 index 39809035..ce25c5e 100644
33515 --- a/drivers/lguest/x86/core.c
33516 +++ b/drivers/lguest/x86/core.c
33517 @@ -59,7 +59,7 @@ static struct {
33518 /* Offset from where switcher.S was compiled to where we've copied it */
33519 static unsigned long switcher_offset(void)
33520 {
33521 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33522 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33523 }
33524
33525 /* This cpu's struct lguest_pages. */
33526 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33527 * These copies are pretty cheap, so we do them unconditionally: */
33528 /* Save the current Host top-level page directory.
33529 */
33530 +
33531 +#ifdef CONFIG_PAX_PER_CPU_PGD
33532 + pages->state.host_cr3 = read_cr3();
33533 +#else
33534 pages->state.host_cr3 = __pa(current->mm->pgd);
33535 +#endif
33536 +
33537 /*
33538 * Set up the Guest's page tables to see this CPU's pages (and no
33539 * other CPU's pages).
33540 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33541 * compiled-in switcher code and the high-mapped copy we just made.
33542 */
33543 for (i = 0; i < IDT_ENTRIES; i++)
33544 - default_idt_entries[i] += switcher_offset();
33545 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33546
33547 /*
33548 * Set up the Switcher's per-cpu areas.
33549 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33550 * it will be undisturbed when we switch. To change %cs and jump we
33551 * need this structure to feed to Intel's "lcall" instruction.
33552 */
33553 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33554 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33555 lguest_entry.segment = LGUEST_CS;
33556
33557 /*
33558 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33559 index 40634b0..4f5855e 100644
33560 --- a/drivers/lguest/x86/switcher_32.S
33561 +++ b/drivers/lguest/x86/switcher_32.S
33562 @@ -87,6 +87,7 @@
33563 #include <asm/page.h>
33564 #include <asm/segment.h>
33565 #include <asm/lguest.h>
33566 +#include <asm/processor-flags.h>
33567
33568 // We mark the start of the code to copy
33569 // It's placed in .text tho it's never run here
33570 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33571 // Changes type when we load it: damn Intel!
33572 // For after we switch over our page tables
33573 // That entry will be read-only: we'd crash.
33574 +
33575 +#ifdef CONFIG_PAX_KERNEXEC
33576 + mov %cr0, %edx
33577 + xor $X86_CR0_WP, %edx
33578 + mov %edx, %cr0
33579 +#endif
33580 +
33581 movl $(GDT_ENTRY_TSS*8), %edx
33582 ltr %dx
33583
33584 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33585 // Let's clear it again for our return.
33586 // The GDT descriptor of the Host
33587 // Points to the table after two "size" bytes
33588 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33589 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33590 // Clear "used" from type field (byte 5, bit 2)
33591 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33592 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33593 +
33594 +#ifdef CONFIG_PAX_KERNEXEC
33595 + mov %cr0, %eax
33596 + xor $X86_CR0_WP, %eax
33597 + mov %eax, %cr0
33598 +#endif
33599
33600 // Once our page table's switched, the Guest is live!
33601 // The Host fades as we run this final step.
33602 @@ -295,13 +309,12 @@ deliver_to_host:
33603 // I consulted gcc, and it gave
33604 // These instructions, which I gladly credit:
33605 leal (%edx,%ebx,8), %eax
33606 - movzwl (%eax),%edx
33607 - movl 4(%eax), %eax
33608 - xorw %ax, %ax
33609 - orl %eax, %edx
33610 + movl 4(%eax), %edx
33611 + movw (%eax), %dx
33612 // Now the address of the handler's in %edx
33613 // We call it now: its "iret" drops us home.
33614 - jmp *%edx
33615 + ljmp $__KERNEL_CS, $1f
33616 +1: jmp *%edx
33617
33618 // Every interrupt can come to us here
33619 // But we must truly tell each apart.
33620 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33621 index 20e5c2c..9e849a9 100644
33622 --- a/drivers/macintosh/macio_asic.c
33623 +++ b/drivers/macintosh/macio_asic.c
33624 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33625 * MacIO is matched against any Apple ID, it's probe() function
33626 * will then decide wether it applies or not
33627 */
33628 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33629 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33630 .vendor = PCI_VENDOR_ID_APPLE,
33631 .device = PCI_ANY_ID,
33632 .subvendor = PCI_ANY_ID,
33633 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33634 index 94e7f6b..2f4a0d8 100644
33635 --- a/drivers/md/bitmap.c
33636 +++ b/drivers/md/bitmap.c
33637 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33638 chunk_kb ? "KB" : "B");
33639 if (bitmap->storage.file) {
33640 seq_printf(seq, ", file: ");
33641 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33642 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33643 }
33644
33645 seq_printf(seq, "\n");
33646 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33647 index afd9598..528d8f9 100644
33648 --- a/drivers/md/dm-ioctl.c
33649 +++ b/drivers/md/dm-ioctl.c
33650 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33651 cmd == DM_LIST_VERSIONS_CMD)
33652 return 0;
33653
33654 - if ((cmd == DM_DEV_CREATE_CMD)) {
33655 + if (cmd == DM_DEV_CREATE_CMD) {
33656 if (!*param->name) {
33657 DMWARN("name not supplied when creating device");
33658 return -EINVAL;
33659 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33660 index bc5ddba8..b961159 100644
33661 --- a/drivers/md/dm-raid1.c
33662 +++ b/drivers/md/dm-raid1.c
33663 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33664
33665 struct mirror {
33666 struct mirror_set *ms;
33667 - atomic_t error_count;
33668 + atomic_unchecked_t error_count;
33669 unsigned long error_type;
33670 struct dm_dev *dev;
33671 sector_t offset;
33672 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33673 struct mirror *m;
33674
33675 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33676 - if (!atomic_read(&m->error_count))
33677 + if (!atomic_read_unchecked(&m->error_count))
33678 return m;
33679
33680 return NULL;
33681 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33682 * simple way to tell if a device has encountered
33683 * errors.
33684 */
33685 - atomic_inc(&m->error_count);
33686 + atomic_inc_unchecked(&m->error_count);
33687
33688 if (test_and_set_bit(error_type, &m->error_type))
33689 return;
33690 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33691 struct mirror *m = get_default_mirror(ms);
33692
33693 do {
33694 - if (likely(!atomic_read(&m->error_count)))
33695 + if (likely(!atomic_read_unchecked(&m->error_count)))
33696 return m;
33697
33698 if (m-- == ms->mirror)
33699 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33700 {
33701 struct mirror *default_mirror = get_default_mirror(m->ms);
33702
33703 - return !atomic_read(&default_mirror->error_count);
33704 + return !atomic_read_unchecked(&default_mirror->error_count);
33705 }
33706
33707 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33708 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33709 */
33710 if (likely(region_in_sync(ms, region, 1)))
33711 m = choose_mirror(ms, bio->bi_sector);
33712 - else if (m && atomic_read(&m->error_count))
33713 + else if (m && atomic_read_unchecked(&m->error_count))
33714 m = NULL;
33715
33716 if (likely(m))
33717 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33718 }
33719
33720 ms->mirror[mirror].ms = ms;
33721 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33722 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33723 ms->mirror[mirror].error_type = 0;
33724 ms->mirror[mirror].offset = offset;
33725
33726 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33727 */
33728 static char device_status_char(struct mirror *m)
33729 {
33730 - if (!atomic_read(&(m->error_count)))
33731 + if (!atomic_read_unchecked(&(m->error_count)))
33732 return 'A';
33733
33734 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33735 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33736 index a087bf2..4c94786 100644
33737 --- a/drivers/md/dm-stripe.c
33738 +++ b/drivers/md/dm-stripe.c
33739 @@ -20,7 +20,7 @@ struct stripe {
33740 struct dm_dev *dev;
33741 sector_t physical_start;
33742
33743 - atomic_t error_count;
33744 + atomic_unchecked_t error_count;
33745 };
33746
33747 struct stripe_c {
33748 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33749 kfree(sc);
33750 return r;
33751 }
33752 - atomic_set(&(sc->stripe[i].error_count), 0);
33753 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33754 }
33755
33756 ti->private = sc;
33757 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33758 DMEMIT("%d ", sc->stripes);
33759 for (i = 0; i < sc->stripes; i++) {
33760 DMEMIT("%s ", sc->stripe[i].dev->name);
33761 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33762 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33763 'D' : 'A';
33764 }
33765 buffer[i] = '\0';
33766 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33767 */
33768 for (i = 0; i < sc->stripes; i++)
33769 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33770 - atomic_inc(&(sc->stripe[i].error_count));
33771 - if (atomic_read(&(sc->stripe[i].error_count)) <
33772 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33773 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33774 DM_IO_ERROR_THRESHOLD)
33775 schedule_work(&sc->trigger_event);
33776 }
33777 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33778 index 100368e..64262ce 100644
33779 --- a/drivers/md/dm-table.c
33780 +++ b/drivers/md/dm-table.c
33781 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33782 if (!dev_size)
33783 return 0;
33784
33785 - if ((start >= dev_size) || (start + len > dev_size)) {
33786 + if ((start >= dev_size) || (len > dev_size - start)) {
33787 DMWARN("%s: %s too small for target: "
33788 "start=%llu, len=%llu, dev_size=%llu",
33789 dm_device_name(ti->table->md), bdevname(bdev, b),
33790 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33791 index 693e149..b7e0fde 100644
33792 --- a/drivers/md/dm-thin-metadata.c
33793 +++ b/drivers/md/dm-thin-metadata.c
33794 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33795 {
33796 pmd->info.tm = pmd->tm;
33797 pmd->info.levels = 2;
33798 - pmd->info.value_type.context = pmd->data_sm;
33799 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33800 pmd->info.value_type.size = sizeof(__le64);
33801 pmd->info.value_type.inc = data_block_inc;
33802 pmd->info.value_type.dec = data_block_dec;
33803 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33804
33805 pmd->bl_info.tm = pmd->tm;
33806 pmd->bl_info.levels = 1;
33807 - pmd->bl_info.value_type.context = pmd->data_sm;
33808 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33809 pmd->bl_info.value_type.size = sizeof(__le64);
33810 pmd->bl_info.value_type.inc = data_block_inc;
33811 pmd->bl_info.value_type.dec = data_block_dec;
33812 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33813 index 4256200..154b975 100644
33814 --- a/drivers/md/dm.c
33815 +++ b/drivers/md/dm.c
33816 @@ -176,9 +176,9 @@ struct mapped_device {
33817 /*
33818 * Event handling.
33819 */
33820 - atomic_t event_nr;
33821 + atomic_unchecked_t event_nr;
33822 wait_queue_head_t eventq;
33823 - atomic_t uevent_seq;
33824 + atomic_unchecked_t uevent_seq;
33825 struct list_head uevent_list;
33826 spinlock_t uevent_lock; /* Protect access to uevent_list */
33827
33828 @@ -1893,8 +1893,8 @@ static struct mapped_device *alloc_dev(int minor)
33829 rwlock_init(&md->map_lock);
33830 atomic_set(&md->holders, 1);
33831 atomic_set(&md->open_count, 0);
33832 - atomic_set(&md->event_nr, 0);
33833 - atomic_set(&md->uevent_seq, 0);
33834 + atomic_set_unchecked(&md->event_nr, 0);
33835 + atomic_set_unchecked(&md->uevent_seq, 0);
33836 INIT_LIST_HEAD(&md->uevent_list);
33837 spin_lock_init(&md->uevent_lock);
33838
33839 @@ -2028,7 +2028,7 @@ static void event_callback(void *context)
33840
33841 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33842
33843 - atomic_inc(&md->event_nr);
33844 + atomic_inc_unchecked(&md->event_nr);
33845 wake_up(&md->eventq);
33846 }
33847
33848 @@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33849
33850 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33851 {
33852 - return atomic_add_return(1, &md->uevent_seq);
33853 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33854 }
33855
33856 uint32_t dm_get_event_nr(struct mapped_device *md)
33857 {
33858 - return atomic_read(&md->event_nr);
33859 + return atomic_read_unchecked(&md->event_nr);
33860 }
33861
33862 int dm_wait_event(struct mapped_device *md, int event_nr)
33863 {
33864 return wait_event_interruptible(md->eventq,
33865 - (event_nr != atomic_read(&md->event_nr)));
33866 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33867 }
33868
33869 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33870 diff --git a/drivers/md/md.c b/drivers/md/md.c
33871 index c7b000f..15a8b22 100644
33872 --- a/drivers/md/md.c
33873 +++ b/drivers/md/md.c
33874 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33875 * start build, activate spare
33876 */
33877 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33878 -static atomic_t md_event_count;
33879 +static atomic_unchecked_t md_event_count;
33880 void md_new_event(struct mddev *mddev)
33881 {
33882 - atomic_inc(&md_event_count);
33883 + atomic_inc_unchecked(&md_event_count);
33884 wake_up(&md_event_waiters);
33885 }
33886 EXPORT_SYMBOL_GPL(md_new_event);
33887 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33888 */
33889 static void md_new_event_inintr(struct mddev *mddev)
33890 {
33891 - atomic_inc(&md_event_count);
33892 + atomic_inc_unchecked(&md_event_count);
33893 wake_up(&md_event_waiters);
33894 }
33895
33896 @@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33897 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33898 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33899 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33900 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33901 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33902
33903 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33904 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33905 @@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33906 else
33907 sb->resync_offset = cpu_to_le64(0);
33908
33909 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33910 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33911
33912 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33913 sb->size = cpu_to_le64(mddev->dev_sectors);
33914 @@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33915 static ssize_t
33916 errors_show(struct md_rdev *rdev, char *page)
33917 {
33918 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33919 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33920 }
33921
33922 static ssize_t
33923 @@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33924 char *e;
33925 unsigned long n = simple_strtoul(buf, &e, 10);
33926 if (*buf && (*e == 0 || *e == '\n')) {
33927 - atomic_set(&rdev->corrected_errors, n);
33928 + atomic_set_unchecked(&rdev->corrected_errors, n);
33929 return len;
33930 }
33931 return -EINVAL;
33932 @@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33933 rdev->sb_loaded = 0;
33934 rdev->bb_page = NULL;
33935 atomic_set(&rdev->nr_pending, 0);
33936 - atomic_set(&rdev->read_errors, 0);
33937 - atomic_set(&rdev->corrected_errors, 0);
33938 + atomic_set_unchecked(&rdev->read_errors, 0);
33939 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33940
33941 INIT_LIST_HEAD(&rdev->same_set);
33942 init_waitqueue_head(&rdev->blocked_wait);
33943 @@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33944
33945 spin_unlock(&pers_lock);
33946 seq_printf(seq, "\n");
33947 - seq->poll_event = atomic_read(&md_event_count);
33948 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33949 return 0;
33950 }
33951 if (v == (void*)2) {
33952 @@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33953 return error;
33954
33955 seq = file->private_data;
33956 - seq->poll_event = atomic_read(&md_event_count);
33957 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33958 return error;
33959 }
33960
33961 @@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33962 /* always allow read */
33963 mask = POLLIN | POLLRDNORM;
33964
33965 - if (seq->poll_event != atomic_read(&md_event_count))
33966 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33967 mask |= POLLERR | POLLPRI;
33968 return mask;
33969 }
33970 @@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33971 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33972 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33973 (int)part_stat_read(&disk->part0, sectors[1]) -
33974 - atomic_read(&disk->sync_io);
33975 + atomic_read_unchecked(&disk->sync_io);
33976 /* sync IO will cause sync_io to increase before the disk_stats
33977 * as sync_io is counted when a request starts, and
33978 * disk_stats is counted when it completes.
33979 diff --git a/drivers/md/md.h b/drivers/md/md.h
33980 index f385b03..b600be8 100644
33981 --- a/drivers/md/md.h
33982 +++ b/drivers/md/md.h
33983 @@ -94,13 +94,13 @@ struct md_rdev {
33984 * only maintained for arrays that
33985 * support hot removal
33986 */
33987 - atomic_t read_errors; /* number of consecutive read errors that
33988 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33989 * we have tried to ignore.
33990 */
33991 struct timespec last_read_error; /* monotonic time since our
33992 * last read error
33993 */
33994 - atomic_t corrected_errors; /* number of corrected read errors,
33995 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33996 * for reporting to userspace and storing
33997 * in superblock.
33998 */
33999 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
34000
34001 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
34002 {
34003 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34004 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34005 }
34006
34007 struct md_personality
34008 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
34009 index f6d29e6..7917f5e 100644
34010 --- a/drivers/md/persistent-data/dm-space-map-disk.c
34011 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
34012 @@ -22,7 +22,7 @@
34013 * Space map interface.
34014 */
34015 struct sm_disk {
34016 - struct dm_space_map sm;
34017 + dm_space_map_no_const sm;
34018
34019 struct ll_disk ll;
34020 struct ll_disk old_ll;
34021 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
34022 index e89ae5e..062e4c2 100644
34023 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
34024 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
34025 @@ -43,7 +43,7 @@ struct block_op {
34026 };
34027
34028 struct sm_metadata {
34029 - struct dm_space_map sm;
34030 + dm_space_map_no_const sm;
34031
34032 struct ll_disk ll;
34033 struct ll_disk old_ll;
34034 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
34035 index 1cbfc6b..56e1dbb 100644
34036 --- a/drivers/md/persistent-data/dm-space-map.h
34037 +++ b/drivers/md/persistent-data/dm-space-map.h
34038 @@ -60,6 +60,7 @@ struct dm_space_map {
34039 int (*root_size)(struct dm_space_map *sm, size_t *result);
34040 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
34041 };
34042 +typedef struct dm_space_map __no_const dm_space_map_no_const;
34043
34044 /*----------------------------------------------------------------*/
34045
34046 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
34047 index 7077dcf..facc1e9 100644
34048 --- a/drivers/md/raid1.c
34049 +++ b/drivers/md/raid1.c
34050 @@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
34051 if (r1_sync_page_io(rdev, sect, s,
34052 bio->bi_io_vec[idx].bv_page,
34053 READ) != 0)
34054 - atomic_add(s, &rdev->corrected_errors);
34055 + atomic_add_unchecked(s, &rdev->corrected_errors);
34056 }
34057 sectors -= s;
34058 sect += s;
34059 @@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
34060 test_bit(In_sync, &rdev->flags)) {
34061 if (r1_sync_page_io(rdev, sect, s,
34062 conf->tmppage, READ)) {
34063 - atomic_add(s, &rdev->corrected_errors);
34064 + atomic_add_unchecked(s, &rdev->corrected_errors);
34065 printk(KERN_INFO
34066 "md/raid1:%s: read error corrected "
34067 "(%d sectors at %llu on %s)\n",
34068 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
34069 index c52d893..69c5d80 100644
34070 --- a/drivers/md/raid10.c
34071 +++ b/drivers/md/raid10.c
34072 @@ -1814,7 +1814,7 @@ static void end_sync_read(struct bio *bio, int error)
34073 /* The write handler will notice the lack of
34074 * R10BIO_Uptodate and record any errors etc
34075 */
34076 - atomic_add(r10_bio->sectors,
34077 + atomic_add_unchecked(r10_bio->sectors,
34078 &conf->mirrors[d].rdev->corrected_errors);
34079
34080 /* for reconstruct, we always reschedule after a read.
34081 @@ -2163,7 +2163,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34082 {
34083 struct timespec cur_time_mon;
34084 unsigned long hours_since_last;
34085 - unsigned int read_errors = atomic_read(&rdev->read_errors);
34086 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
34087
34088 ktime_get_ts(&cur_time_mon);
34089
34090 @@ -2185,9 +2185,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34091 * overflowing the shift of read_errors by hours_since_last.
34092 */
34093 if (hours_since_last >= 8 * sizeof(read_errors))
34094 - atomic_set(&rdev->read_errors, 0);
34095 + atomic_set_unchecked(&rdev->read_errors, 0);
34096 else
34097 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
34098 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
34099 }
34100
34101 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
34102 @@ -2241,8 +2241,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34103 return;
34104
34105 check_decay_read_errors(mddev, rdev);
34106 - atomic_inc(&rdev->read_errors);
34107 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
34108 + atomic_inc_unchecked(&rdev->read_errors);
34109 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
34110 char b[BDEVNAME_SIZE];
34111 bdevname(rdev->bdev, b);
34112
34113 @@ -2250,7 +2250,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34114 "md/raid10:%s: %s: Raid device exceeded "
34115 "read_error threshold [cur %d:max %d]\n",
34116 mdname(mddev), b,
34117 - atomic_read(&rdev->read_errors), max_read_errors);
34118 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
34119 printk(KERN_NOTICE
34120 "md/raid10:%s: %s: Failing raid device\n",
34121 mdname(mddev), b);
34122 @@ -2405,7 +2405,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34123 sect +
34124 choose_data_offset(r10_bio, rdev)),
34125 bdevname(rdev->bdev, b));
34126 - atomic_add(s, &rdev->corrected_errors);
34127 + atomic_add_unchecked(s, &rdev->corrected_errors);
34128 }
34129
34130 rdev_dec_pending(rdev, mddev);
34131 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
34132 index 0689173..35df76c 100644
34133 --- a/drivers/md/raid5.c
34134 +++ b/drivers/md/raid5.c
34135 @@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
34136 mdname(conf->mddev), STRIPE_SECTORS,
34137 (unsigned long long)s,
34138 bdevname(rdev->bdev, b));
34139 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
34140 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
34141 clear_bit(R5_ReadError, &sh->dev[i].flags);
34142 clear_bit(R5_ReWrite, &sh->dev[i].flags);
34143 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
34144 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
34145
34146 - if (atomic_read(&rdev->read_errors))
34147 - atomic_set(&rdev->read_errors, 0);
34148 + if (atomic_read_unchecked(&rdev->read_errors))
34149 + atomic_set_unchecked(&rdev->read_errors, 0);
34150 } else {
34151 const char *bdn = bdevname(rdev->bdev, b);
34152 int retry = 0;
34153 int set_bad = 0;
34154
34155 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
34156 - atomic_inc(&rdev->read_errors);
34157 + atomic_inc_unchecked(&rdev->read_errors);
34158 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
34159 printk_ratelimited(
34160 KERN_WARNING
34161 @@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
34162 mdname(conf->mddev),
34163 (unsigned long long)s,
34164 bdn);
34165 - } else if (atomic_read(&rdev->read_errors)
34166 + } else if (atomic_read_unchecked(&rdev->read_errors)
34167 > conf->max_nr_stripes)
34168 printk(KERN_WARNING
34169 "md/raid:%s: Too many read errors, failing device %s.\n",
34170 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
34171 index ebf3f05..b1f3e77 100644
34172 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
34173 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
34174 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
34175 .subvendor = _subvend, .subdevice = _subdev, \
34176 .driver_data = (unsigned long)&_driverdata }
34177
34178 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
34179 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
34180 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
34181 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
34182 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
34183 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
34184 index fa7188a..04a045e 100644
34185 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
34186 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
34187 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
34188 union {
34189 dmx_ts_cb ts;
34190 dmx_section_cb sec;
34191 - } cb;
34192 + } __no_const cb;
34193
34194 struct dvb_demux *demux;
34195 void *priv;
34196 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
34197 index 39eab73..60033e7 100644
34198 --- a/drivers/media/dvb/dvb-core/dvbdev.c
34199 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
34200 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
34201 const struct dvb_device *template, void *priv, int type)
34202 {
34203 struct dvb_device *dvbdev;
34204 - struct file_operations *dvbdevfops;
34205 + file_operations_no_const *dvbdevfops;
34206 struct device *clsdev;
34207 int minor;
34208 int id;
34209 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
34210 index 3940bb0..fb3952a 100644
34211 --- a/drivers/media/dvb/dvb-usb/cxusb.c
34212 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
34213 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
34214
34215 struct dib0700_adapter_state {
34216 int (*set_param_save) (struct dvb_frontend *);
34217 -};
34218 +} __no_const;
34219
34220 static int dib7070_set_param_override(struct dvb_frontend *fe)
34221 {
34222 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
34223 index 9382895..ac8093c 100644
34224 --- a/drivers/media/dvb/dvb-usb/dw2102.c
34225 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
34226 @@ -95,7 +95,7 @@ struct su3000_state {
34227
34228 struct s6x0_state {
34229 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
34230 -};
34231 +} __no_const;
34232
34233 /* debug */
34234 static int dvb_usb_dw2102_debug;
34235 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
34236 index 404f63a..4796533 100644
34237 --- a/drivers/media/dvb/frontends/dib3000.h
34238 +++ b/drivers/media/dvb/frontends/dib3000.h
34239 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34240 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34241 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34242 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34243 -};
34244 +} __no_const;
34245
34246 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34247 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34248 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34249 index 72ee8de..eae0c80 100644
34250 --- a/drivers/media/dvb/ngene/ngene-cards.c
34251 +++ b/drivers/media/dvb/ngene/ngene-cards.c
34252 @@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
34253
34254 /****************************************************************************/
34255
34256 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34257 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34258 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34259 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34260 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34261 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34262 index 697a421..16c5a5f 100644
34263 --- a/drivers/media/radio/radio-cadet.c
34264 +++ b/drivers/media/radio/radio-cadet.c
34265 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34266 unsigned char readbuf[RDS_BUFFER];
34267 int i = 0;
34268
34269 + if (count > RDS_BUFFER)
34270 + return -EFAULT;
34271 mutex_lock(&dev->lock);
34272 if (dev->rdsstat == 0)
34273 cadet_start_rds(dev);
34274 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34275 while (i < count && dev->rdsin != dev->rdsout)
34276 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34277
34278 - if (i && copy_to_user(data, readbuf, i))
34279 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34280 i = -EFAULT;
34281 unlock:
34282 mutex_unlock(&dev->lock);
34283 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34284 index 55cbd78..428b0da 100644
34285 --- a/drivers/media/radio/radio-tea5777.h
34286 +++ b/drivers/media/radio/radio-tea5777.h
34287 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34288
34289 struct radio_tea5777 {
34290 struct v4l2_device *v4l2_dev;
34291 - struct v4l2_file_operations fops;
34292 + v4l2_file_operations_no_const fops;
34293 struct video_device vd; /* video device */
34294 bool has_am; /* Device can tune to AM freqs */
34295 bool write_before_read; /* must write before read quirk */
34296 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34297 index 9cde353..8c6a1c3 100644
34298 --- a/drivers/media/video/au0828/au0828.h
34299 +++ b/drivers/media/video/au0828/au0828.h
34300 @@ -191,7 +191,7 @@ struct au0828_dev {
34301
34302 /* I2C */
34303 struct i2c_adapter i2c_adap;
34304 - struct i2c_algorithm i2c_algo;
34305 + i2c_algorithm_no_const i2c_algo;
34306 struct i2c_client i2c_client;
34307 u32 i2c_rc;
34308
34309 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34310 index dfac6e3..c26de31 100644
34311 --- a/drivers/media/video/cx88/cx88-alsa.c
34312 +++ b/drivers/media/video/cx88/cx88-alsa.c
34313 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34314 * Only boards with eeprom and byte 1 at eeprom=1 have it
34315 */
34316
34317 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34318 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34319 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34320 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34321 {0, }
34322 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34323 index 88cf9d9..bbc4b2c 100644
34324 --- a/drivers/media/video/omap/omap_vout.c
34325 +++ b/drivers/media/video/omap/omap_vout.c
34326 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34327 OMAP_VIDEO2,
34328 };
34329
34330 -static struct videobuf_queue_ops video_vbq_ops;
34331 /* Variables configurable through module params*/
34332 static u32 video1_numbuffers = 3;
34333 static u32 video2_numbuffers = 3;
34334 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34335 {
34336 struct videobuf_queue *q;
34337 struct omap_vout_device *vout = NULL;
34338 + static struct videobuf_queue_ops video_vbq_ops = {
34339 + .buf_setup = omap_vout_buffer_setup,
34340 + .buf_prepare = omap_vout_buffer_prepare,
34341 + .buf_release = omap_vout_buffer_release,
34342 + .buf_queue = omap_vout_buffer_queue,
34343 + };
34344
34345 vout = video_drvdata(file);
34346 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34347 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34348 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34349
34350 q = &vout->vbq;
34351 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34352 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34353 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34354 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34355 spin_lock_init(&vout->vbq_lock);
34356
34357 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34358 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34359 index 036952f..80d356d 100644
34360 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34361 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34362 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34363
34364 /* I2C stuff */
34365 struct i2c_adapter i2c_adap;
34366 - struct i2c_algorithm i2c_algo;
34367 + i2c_algorithm_no_const i2c_algo;
34368 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34369 int i2c_cx25840_hack_state;
34370 int i2c_linked;
34371 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34372 index 02194c0..091733b 100644
34373 --- a/drivers/media/video/timblogiw.c
34374 +++ b/drivers/media/video/timblogiw.c
34375 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34376
34377 /* Platform device functions */
34378
34379 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34380 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34381 .vidioc_querycap = timblogiw_querycap,
34382 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34383 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34384 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34385 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34386 };
34387
34388 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34389 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34390 .owner = THIS_MODULE,
34391 .open = timblogiw_open,
34392 .release = timblogiw_close,
34393 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34394 index d99db56..a16b959 100644
34395 --- a/drivers/message/fusion/mptbase.c
34396 +++ b/drivers/message/fusion/mptbase.c
34397 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34398 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34399 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34400
34401 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34402 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34403 +#else
34404 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34405 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34406 +#endif
34407 +
34408 /*
34409 * Rounding UP to nearest 4-kB boundary here...
34410 */
34411 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34412 index 551262e..7551198 100644
34413 --- a/drivers/message/fusion/mptsas.c
34414 +++ b/drivers/message/fusion/mptsas.c
34415 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34416 return 0;
34417 }
34418
34419 +static inline void
34420 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34421 +{
34422 + if (phy_info->port_details) {
34423 + phy_info->port_details->rphy = rphy;
34424 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34425 + ioc->name, rphy));
34426 + }
34427 +
34428 + if (rphy) {
34429 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34430 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34431 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34432 + ioc->name, rphy, rphy->dev.release));
34433 + }
34434 +}
34435 +
34436 /* no mutex */
34437 static void
34438 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34439 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34440 return NULL;
34441 }
34442
34443 -static inline void
34444 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34445 -{
34446 - if (phy_info->port_details) {
34447 - phy_info->port_details->rphy = rphy;
34448 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34449 - ioc->name, rphy));
34450 - }
34451 -
34452 - if (rphy) {
34453 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34454 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34455 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34456 - ioc->name, rphy, rphy->dev.release));
34457 - }
34458 -}
34459 -
34460 static inline struct sas_port *
34461 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34462 {
34463 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34464 index 0c3ced7..1fe34ec 100644
34465 --- a/drivers/message/fusion/mptscsih.c
34466 +++ b/drivers/message/fusion/mptscsih.c
34467 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34468
34469 h = shost_priv(SChost);
34470
34471 - if (h) {
34472 - if (h->info_kbuf == NULL)
34473 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34474 - return h->info_kbuf;
34475 - h->info_kbuf[0] = '\0';
34476 + if (!h)
34477 + return NULL;
34478
34479 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34480 - h->info_kbuf[size-1] = '\0';
34481 - }
34482 + if (h->info_kbuf == NULL)
34483 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34484 + return h->info_kbuf;
34485 + h->info_kbuf[0] = '\0';
34486 +
34487 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34488 + h->info_kbuf[size-1] = '\0';
34489
34490 return h->info_kbuf;
34491 }
34492 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34493 index 8001aa6..b137580 100644
34494 --- a/drivers/message/i2o/i2o_proc.c
34495 +++ b/drivers/message/i2o/i2o_proc.c
34496 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34497 "Array Controller Device"
34498 };
34499
34500 -static char *chtostr(char *tmp, u8 *chars, int n)
34501 -{
34502 - tmp[0] = 0;
34503 - return strncat(tmp, (char *)chars, n);
34504 -}
34505 -
34506 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34507 char *group)
34508 {
34509 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34510 } *result;
34511
34512 i2o_exec_execute_ddm_table ddm_table;
34513 - char tmp[28 + 1];
34514
34515 result = kmalloc(sizeof(*result), GFP_KERNEL);
34516 if (!result)
34517 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34518
34519 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34520 seq_printf(seq, "%-#8x", ddm_table.module_id);
34521 - seq_printf(seq, "%-29s",
34522 - chtostr(tmp, ddm_table.module_name_version, 28));
34523 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34524 seq_printf(seq, "%9d ", ddm_table.data_size);
34525 seq_printf(seq, "%8d", ddm_table.code_size);
34526
34527 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34528
34529 i2o_driver_result_table *result;
34530 i2o_driver_store_table *dst;
34531 - char tmp[28 + 1];
34532
34533 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34534 if (result == NULL)
34535 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34536
34537 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34538 seq_printf(seq, "%-#8x", dst->module_id);
34539 - seq_printf(seq, "%-29s",
34540 - chtostr(tmp, dst->module_name_version, 28));
34541 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34542 + seq_printf(seq, "%-.28s", dst->module_name_version);
34543 + seq_printf(seq, "%-.8s", dst->date);
34544 seq_printf(seq, "%8d ", dst->module_size);
34545 seq_printf(seq, "%8d ", dst->mpb_size);
34546 seq_printf(seq, "0x%04x", dst->module_flags);
34547 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34548 // == (allow) 512d bytes (max)
34549 static u16 *work16 = (u16 *) work32;
34550 int token;
34551 - char tmp[16 + 1];
34552
34553 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34554
34555 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34556 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34557 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34558 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34559 - seq_printf(seq, "Vendor info : %s\n",
34560 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34561 - seq_printf(seq, "Product info : %s\n",
34562 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34563 - seq_printf(seq, "Description : %s\n",
34564 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34565 - seq_printf(seq, "Product rev. : %s\n",
34566 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34567 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34568 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34569 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34570 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34571
34572 seq_printf(seq, "Serial number : ");
34573 print_serial_number(seq, (u8 *) (work32 + 16),
34574 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34575 u8 pad[256]; // allow up to 256 byte (max) serial number
34576 } result;
34577
34578 - char tmp[24 + 1];
34579 -
34580 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34581
34582 if (token < 0) {
34583 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34584 }
34585
34586 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34587 - seq_printf(seq, "Module name : %s\n",
34588 - chtostr(tmp, result.module_name, 24));
34589 - seq_printf(seq, "Module revision : %s\n",
34590 - chtostr(tmp, result.module_rev, 8));
34591 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34592 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34593
34594 seq_printf(seq, "Serial number : ");
34595 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34596 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34597 u8 instance_number[4];
34598 } result;
34599
34600 - char tmp[64 + 1];
34601 -
34602 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34603
34604 if (token < 0) {
34605 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34606 return 0;
34607 }
34608
34609 - seq_printf(seq, "Device name : %s\n",
34610 - chtostr(tmp, result.device_name, 64));
34611 - seq_printf(seq, "Service name : %s\n",
34612 - chtostr(tmp, result.service_name, 64));
34613 - seq_printf(seq, "Physical name : %s\n",
34614 - chtostr(tmp, result.physical_location, 64));
34615 - seq_printf(seq, "Instance number : %s\n",
34616 - chtostr(tmp, result.instance_number, 4));
34617 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34618 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34619 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34620 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34621
34622 return 0;
34623 }
34624 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34625 index a8c08f3..155fe3d 100644
34626 --- a/drivers/message/i2o/iop.c
34627 +++ b/drivers/message/i2o/iop.c
34628 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34629
34630 spin_lock_irqsave(&c->context_list_lock, flags);
34631
34632 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34633 - atomic_inc(&c->context_list_counter);
34634 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34635 + atomic_inc_unchecked(&c->context_list_counter);
34636
34637 - entry->context = atomic_read(&c->context_list_counter);
34638 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34639
34640 list_add(&entry->list, &c->context_list);
34641
34642 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34643
34644 #if BITS_PER_LONG == 64
34645 spin_lock_init(&c->context_list_lock);
34646 - atomic_set(&c->context_list_counter, 0);
34647 + atomic_set_unchecked(&c->context_list_counter, 0);
34648 INIT_LIST_HEAD(&c->context_list);
34649 #endif
34650
34651 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34652 index 7ce65f4..e66e9bc 100644
34653 --- a/drivers/mfd/abx500-core.c
34654 +++ b/drivers/mfd/abx500-core.c
34655 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34656
34657 struct abx500_device_entry {
34658 struct list_head list;
34659 - struct abx500_ops ops;
34660 + abx500_ops_no_const ops;
34661 struct device *dev;
34662 };
34663
34664 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34665 index 965c480..71f2db9 100644
34666 --- a/drivers/mfd/janz-cmodio.c
34667 +++ b/drivers/mfd/janz-cmodio.c
34668 @@ -13,6 +13,7 @@
34669
34670 #include <linux/kernel.h>
34671 #include <linux/module.h>
34672 +#include <linux/slab.h>
34673 #include <linux/init.h>
34674 #include <linux/pci.h>
34675 #include <linux/interrupt.h>
34676 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34677 index a981e2a..5ca0c8b 100644
34678 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34679 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34680 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34681 * the lid is closed. This leads to interrupts as soon as a little move
34682 * is done.
34683 */
34684 - atomic_inc(&lis3->count);
34685 + atomic_inc_unchecked(&lis3->count);
34686
34687 wake_up_interruptible(&lis3->misc_wait);
34688 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34689 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34690 if (lis3->pm_dev)
34691 pm_runtime_get_sync(lis3->pm_dev);
34692
34693 - atomic_set(&lis3->count, 0);
34694 + atomic_set_unchecked(&lis3->count, 0);
34695 return 0;
34696 }
34697
34698 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34699 add_wait_queue(&lis3->misc_wait, &wait);
34700 while (true) {
34701 set_current_state(TASK_INTERRUPTIBLE);
34702 - data = atomic_xchg(&lis3->count, 0);
34703 + data = atomic_xchg_unchecked(&lis3->count, 0);
34704 if (data)
34705 break;
34706
34707 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34708 struct lis3lv02d, miscdev);
34709
34710 poll_wait(file, &lis3->misc_wait, wait);
34711 - if (atomic_read(&lis3->count))
34712 + if (atomic_read_unchecked(&lis3->count))
34713 return POLLIN | POLLRDNORM;
34714 return 0;
34715 }
34716 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34717 index 2b1482a..5d33616 100644
34718 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34719 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34720 @@ -266,7 +266,7 @@ struct lis3lv02d {
34721 struct input_polled_dev *idev; /* input device */
34722 struct platform_device *pdev; /* platform device */
34723 struct regulator_bulk_data regulators[2];
34724 - atomic_t count; /* interrupt count after last read */
34725 + atomic_unchecked_t count; /* interrupt count after last read */
34726 union axis_conversion ac; /* hw -> logical axis */
34727 int mapped_btns[3];
34728
34729 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34730 index 2f30bad..c4c13d0 100644
34731 --- a/drivers/misc/sgi-gru/gruhandles.c
34732 +++ b/drivers/misc/sgi-gru/gruhandles.c
34733 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34734 unsigned long nsec;
34735
34736 nsec = CLKS2NSEC(clks);
34737 - atomic_long_inc(&mcs_op_statistics[op].count);
34738 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34739 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34740 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34741 if (mcs_op_statistics[op].max < nsec)
34742 mcs_op_statistics[op].max = nsec;
34743 }
34744 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34745 index 950dbe9..eeef0f8 100644
34746 --- a/drivers/misc/sgi-gru/gruprocfs.c
34747 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34748 @@ -32,9 +32,9 @@
34749
34750 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34751
34752 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34753 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34754 {
34755 - unsigned long val = atomic_long_read(v);
34756 + unsigned long val = atomic_long_read_unchecked(v);
34757
34758 seq_printf(s, "%16lu %s\n", val, id);
34759 }
34760 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34761
34762 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34763 for (op = 0; op < mcsop_last; op++) {
34764 - count = atomic_long_read(&mcs_op_statistics[op].count);
34765 - total = atomic_long_read(&mcs_op_statistics[op].total);
34766 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34767 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34768 max = mcs_op_statistics[op].max;
34769 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34770 count ? total / count : 0, max);
34771 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34772 index 5c3ce24..4915ccb 100644
34773 --- a/drivers/misc/sgi-gru/grutables.h
34774 +++ b/drivers/misc/sgi-gru/grutables.h
34775 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34776 * GRU statistics.
34777 */
34778 struct gru_stats_s {
34779 - atomic_long_t vdata_alloc;
34780 - atomic_long_t vdata_free;
34781 - atomic_long_t gts_alloc;
34782 - atomic_long_t gts_free;
34783 - atomic_long_t gms_alloc;
34784 - atomic_long_t gms_free;
34785 - atomic_long_t gts_double_allocate;
34786 - atomic_long_t assign_context;
34787 - atomic_long_t assign_context_failed;
34788 - atomic_long_t free_context;
34789 - atomic_long_t load_user_context;
34790 - atomic_long_t load_kernel_context;
34791 - atomic_long_t lock_kernel_context;
34792 - atomic_long_t unlock_kernel_context;
34793 - atomic_long_t steal_user_context;
34794 - atomic_long_t steal_kernel_context;
34795 - atomic_long_t steal_context_failed;
34796 - atomic_long_t nopfn;
34797 - atomic_long_t asid_new;
34798 - atomic_long_t asid_next;
34799 - atomic_long_t asid_wrap;
34800 - atomic_long_t asid_reuse;
34801 - atomic_long_t intr;
34802 - atomic_long_t intr_cbr;
34803 - atomic_long_t intr_tfh;
34804 - atomic_long_t intr_spurious;
34805 - atomic_long_t intr_mm_lock_failed;
34806 - atomic_long_t call_os;
34807 - atomic_long_t call_os_wait_queue;
34808 - atomic_long_t user_flush_tlb;
34809 - atomic_long_t user_unload_context;
34810 - atomic_long_t user_exception;
34811 - atomic_long_t set_context_option;
34812 - atomic_long_t check_context_retarget_intr;
34813 - atomic_long_t check_context_unload;
34814 - atomic_long_t tlb_dropin;
34815 - atomic_long_t tlb_preload_page;
34816 - atomic_long_t tlb_dropin_fail_no_asid;
34817 - atomic_long_t tlb_dropin_fail_upm;
34818 - atomic_long_t tlb_dropin_fail_invalid;
34819 - atomic_long_t tlb_dropin_fail_range_active;
34820 - atomic_long_t tlb_dropin_fail_idle;
34821 - atomic_long_t tlb_dropin_fail_fmm;
34822 - atomic_long_t tlb_dropin_fail_no_exception;
34823 - atomic_long_t tfh_stale_on_fault;
34824 - atomic_long_t mmu_invalidate_range;
34825 - atomic_long_t mmu_invalidate_page;
34826 - atomic_long_t flush_tlb;
34827 - atomic_long_t flush_tlb_gru;
34828 - atomic_long_t flush_tlb_gru_tgh;
34829 - atomic_long_t flush_tlb_gru_zero_asid;
34830 + atomic_long_unchecked_t vdata_alloc;
34831 + atomic_long_unchecked_t vdata_free;
34832 + atomic_long_unchecked_t gts_alloc;
34833 + atomic_long_unchecked_t gts_free;
34834 + atomic_long_unchecked_t gms_alloc;
34835 + atomic_long_unchecked_t gms_free;
34836 + atomic_long_unchecked_t gts_double_allocate;
34837 + atomic_long_unchecked_t assign_context;
34838 + atomic_long_unchecked_t assign_context_failed;
34839 + atomic_long_unchecked_t free_context;
34840 + atomic_long_unchecked_t load_user_context;
34841 + atomic_long_unchecked_t load_kernel_context;
34842 + atomic_long_unchecked_t lock_kernel_context;
34843 + atomic_long_unchecked_t unlock_kernel_context;
34844 + atomic_long_unchecked_t steal_user_context;
34845 + atomic_long_unchecked_t steal_kernel_context;
34846 + atomic_long_unchecked_t steal_context_failed;
34847 + atomic_long_unchecked_t nopfn;
34848 + atomic_long_unchecked_t asid_new;
34849 + atomic_long_unchecked_t asid_next;
34850 + atomic_long_unchecked_t asid_wrap;
34851 + atomic_long_unchecked_t asid_reuse;
34852 + atomic_long_unchecked_t intr;
34853 + atomic_long_unchecked_t intr_cbr;
34854 + atomic_long_unchecked_t intr_tfh;
34855 + atomic_long_unchecked_t intr_spurious;
34856 + atomic_long_unchecked_t intr_mm_lock_failed;
34857 + atomic_long_unchecked_t call_os;
34858 + atomic_long_unchecked_t call_os_wait_queue;
34859 + atomic_long_unchecked_t user_flush_tlb;
34860 + atomic_long_unchecked_t user_unload_context;
34861 + atomic_long_unchecked_t user_exception;
34862 + atomic_long_unchecked_t set_context_option;
34863 + atomic_long_unchecked_t check_context_retarget_intr;
34864 + atomic_long_unchecked_t check_context_unload;
34865 + atomic_long_unchecked_t tlb_dropin;
34866 + atomic_long_unchecked_t tlb_preload_page;
34867 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34868 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34869 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34870 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34871 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34872 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34873 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34874 + atomic_long_unchecked_t tfh_stale_on_fault;
34875 + atomic_long_unchecked_t mmu_invalidate_range;
34876 + atomic_long_unchecked_t mmu_invalidate_page;
34877 + atomic_long_unchecked_t flush_tlb;
34878 + atomic_long_unchecked_t flush_tlb_gru;
34879 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34880 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34881
34882 - atomic_long_t copy_gpa;
34883 - atomic_long_t read_gpa;
34884 + atomic_long_unchecked_t copy_gpa;
34885 + atomic_long_unchecked_t read_gpa;
34886
34887 - atomic_long_t mesq_receive;
34888 - atomic_long_t mesq_receive_none;
34889 - atomic_long_t mesq_send;
34890 - atomic_long_t mesq_send_failed;
34891 - atomic_long_t mesq_noop;
34892 - atomic_long_t mesq_send_unexpected_error;
34893 - atomic_long_t mesq_send_lb_overflow;
34894 - atomic_long_t mesq_send_qlimit_reached;
34895 - atomic_long_t mesq_send_amo_nacked;
34896 - atomic_long_t mesq_send_put_nacked;
34897 - atomic_long_t mesq_page_overflow;
34898 - atomic_long_t mesq_qf_locked;
34899 - atomic_long_t mesq_qf_noop_not_full;
34900 - atomic_long_t mesq_qf_switch_head_failed;
34901 - atomic_long_t mesq_qf_unexpected_error;
34902 - atomic_long_t mesq_noop_unexpected_error;
34903 - atomic_long_t mesq_noop_lb_overflow;
34904 - atomic_long_t mesq_noop_qlimit_reached;
34905 - atomic_long_t mesq_noop_amo_nacked;
34906 - atomic_long_t mesq_noop_put_nacked;
34907 - atomic_long_t mesq_noop_page_overflow;
34908 + atomic_long_unchecked_t mesq_receive;
34909 + atomic_long_unchecked_t mesq_receive_none;
34910 + atomic_long_unchecked_t mesq_send;
34911 + atomic_long_unchecked_t mesq_send_failed;
34912 + atomic_long_unchecked_t mesq_noop;
34913 + atomic_long_unchecked_t mesq_send_unexpected_error;
34914 + atomic_long_unchecked_t mesq_send_lb_overflow;
34915 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34916 + atomic_long_unchecked_t mesq_send_amo_nacked;
34917 + atomic_long_unchecked_t mesq_send_put_nacked;
34918 + atomic_long_unchecked_t mesq_page_overflow;
34919 + atomic_long_unchecked_t mesq_qf_locked;
34920 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34921 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34922 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34923 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34924 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34925 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34926 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34927 + atomic_long_unchecked_t mesq_noop_put_nacked;
34928 + atomic_long_unchecked_t mesq_noop_page_overflow;
34929
34930 };
34931
34932 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34933 tghop_invalidate, mcsop_last};
34934
34935 struct mcs_op_statistic {
34936 - atomic_long_t count;
34937 - atomic_long_t total;
34938 + atomic_long_unchecked_t count;
34939 + atomic_long_unchecked_t total;
34940 unsigned long max;
34941 };
34942
34943 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34944
34945 #define STAT(id) do { \
34946 if (gru_options & OPT_STATS) \
34947 - atomic_long_inc(&gru_stats.id); \
34948 + atomic_long_inc_unchecked(&gru_stats.id); \
34949 } while (0)
34950
34951 #ifdef CONFIG_SGI_GRU_DEBUG
34952 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34953 index c862cd4..0d176fe 100644
34954 --- a/drivers/misc/sgi-xp/xp.h
34955 +++ b/drivers/misc/sgi-xp/xp.h
34956 @@ -288,7 +288,7 @@ struct xpc_interface {
34957 xpc_notify_func, void *);
34958 void (*received) (short, int, void *);
34959 enum xp_retval (*partid_to_nasids) (short, void *);
34960 -};
34961 +} __no_const;
34962
34963 extern struct xpc_interface xpc_interface;
34964
34965 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34966 index b94d5f7..7f494c5 100644
34967 --- a/drivers/misc/sgi-xp/xpc.h
34968 +++ b/drivers/misc/sgi-xp/xpc.h
34969 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34970 void (*received_payload) (struct xpc_channel *, void *);
34971 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34972 };
34973 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34974
34975 /* struct xpc_partition act_state values (for XPC HB) */
34976
34977 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34978 /* found in xpc_main.c */
34979 extern struct device *xpc_part;
34980 extern struct device *xpc_chan;
34981 -extern struct xpc_arch_operations xpc_arch_ops;
34982 +extern xpc_arch_operations_no_const xpc_arch_ops;
34983 extern int xpc_disengage_timelimit;
34984 extern int xpc_disengage_timedout;
34985 extern int xpc_activate_IRQ_rcvd;
34986 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34987 index 8d082b4..aa749ae 100644
34988 --- a/drivers/misc/sgi-xp/xpc_main.c
34989 +++ b/drivers/misc/sgi-xp/xpc_main.c
34990 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34991 .notifier_call = xpc_system_die,
34992 };
34993
34994 -struct xpc_arch_operations xpc_arch_ops;
34995 +xpc_arch_operations_no_const xpc_arch_ops;
34996
34997 /*
34998 * Timer function to enforce the timelimit on the partition disengage.
34999 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
35000 index 504da71..9722d43 100644
35001 --- a/drivers/mmc/host/sdhci-pci.c
35002 +++ b/drivers/mmc/host/sdhci-pci.c
35003 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
35004 .probe = via_probe,
35005 };
35006
35007 -static const struct pci_device_id pci_ids[] __devinitdata = {
35008 +static const struct pci_device_id pci_ids[] __devinitconst = {
35009 {
35010 .vendor = PCI_VENDOR_ID_RICOH,
35011 .device = PCI_DEVICE_ID_RICOH_R5C822,
35012 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
35013 index a4eb8b5..8c0628f 100644
35014 --- a/drivers/mtd/devices/doc2000.c
35015 +++ b/drivers/mtd/devices/doc2000.c
35016 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
35017
35018 /* The ECC will not be calculated correctly if less than 512 is written */
35019 /* DBB-
35020 - if (len != 0x200 && eccbuf)
35021 + if (len != 0x200)
35022 printk(KERN_WARNING
35023 "ECC needs a full sector write (adr: %lx size %lx)\n",
35024 (long) to, (long) len);
35025 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
35026 index 0650aaf..7718762 100644
35027 --- a/drivers/mtd/nand/denali.c
35028 +++ b/drivers/mtd/nand/denali.c
35029 @@ -26,6 +26,7 @@
35030 #include <linux/pci.h>
35031 #include <linux/mtd/mtd.h>
35032 #include <linux/module.h>
35033 +#include <linux/slab.h>
35034
35035 #include "denali.h"
35036
35037 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
35038 index 51b9d6a..52af9a7 100644
35039 --- a/drivers/mtd/nftlmount.c
35040 +++ b/drivers/mtd/nftlmount.c
35041 @@ -24,6 +24,7 @@
35042 #include <asm/errno.h>
35043 #include <linux/delay.h>
35044 #include <linux/slab.h>
35045 +#include <linux/sched.h>
35046 #include <linux/mtd/mtd.h>
35047 #include <linux/mtd/nand.h>
35048 #include <linux/mtd/nftl.h>
35049 diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
35050 index dc15d24..ef8d2a0 100644
35051 --- a/drivers/net/bonding/bond_sysfs.c
35052 +++ b/drivers/net/bonding/bond_sysfs.c
35053 @@ -1060,7 +1060,7 @@ static ssize_t bonding_store_primary(struct device *d,
35054 goto out;
35055 }
35056
35057 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
35058 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
35059
35060 /* check to see if we are clearing primary */
35061 if (!strlen(ifname) || buf[0] == '\n') {
35062 @@ -1237,7 +1237,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
35063 goto out;
35064 }
35065
35066 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
35067 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
35068
35069 /* check to see if we are clearing active */
35070 if (!strlen(ifname) || buf[0] == '\n') {
35071 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
35072 index 57d64b8..623dd86 100644
35073 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
35074 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
35075 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
35076 */
35077
35078 #define ATL2_PARAM(X, desc) \
35079 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
35080 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
35081 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
35082 MODULE_PARM_DESC(X, desc);
35083 #else
35084 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35085 index b028b5e..2ef481f 100644
35086 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35087 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35088 @@ -3051,9 +3051,8 @@ static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
35089 struct eth_stats_info *ether_stat =
35090 &bp->slowpath->drv_info_to_mcp.ether_stat;
35091
35092 - /* leave last char as NULL */
35093 - memcpy(ether_stat->version, DRV_MODULE_VERSION,
35094 - ETH_STAT_INFO_VERSION_LEN - 1);
35095 + strlcpy(ether_stat->version, DRV_MODULE_VERSION,
35096 + ETH_STAT_INFO_VERSION_LEN);
35097
35098 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
35099 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
35100 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35101 index f83e033..8b4f43a 100644
35102 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35103 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35104 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
35105
35106 int (*wait_comp)(struct bnx2x *bp,
35107 struct bnx2x_rx_mode_ramrod_params *p);
35108 -};
35109 +} __no_const;
35110
35111 /********************** Set multicast group ***********************************/
35112
35113 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
35114 index 6d52cb2..bc95640 100644
35115 --- a/drivers/net/ethernet/broadcom/tg3.h
35116 +++ b/drivers/net/ethernet/broadcom/tg3.h
35117 @@ -140,6 +140,7 @@
35118 #define CHIPREV_ID_5750_A0 0x4000
35119 #define CHIPREV_ID_5750_A1 0x4001
35120 #define CHIPREV_ID_5750_A3 0x4003
35121 +#define CHIPREV_ID_5750_C1 0x4201
35122 #define CHIPREV_ID_5750_C2 0x4202
35123 #define CHIPREV_ID_5752_A0_HW 0x5000
35124 #define CHIPREV_ID_5752_A0 0x6000
35125 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35126 index 8cffcdf..aadf043 100644
35127 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35128 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35129 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
35130 */
35131 struct l2t_skb_cb {
35132 arp_failure_handler_func arp_failure_handler;
35133 -};
35134 +} __no_const;
35135
35136 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
35137
35138 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
35139 index f879e92..726f20f 100644
35140 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
35141 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
35142 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35143 for (i=0; i<ETH_ALEN; i++) {
35144 tmp.addr[i] = dev->dev_addr[i];
35145 }
35146 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35147 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35148 break;
35149
35150 case DE4X5_SET_HWADDR: /* Set the hardware address */
35151 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35152 spin_lock_irqsave(&lp->lock, flags);
35153 memcpy(&statbuf, &lp->pktStats, ioc->len);
35154 spin_unlock_irqrestore(&lp->lock, flags);
35155 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
35156 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35157 return -EFAULT;
35158 break;
35159 }
35160 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
35161 index ed7d1dc..d426748 100644
35162 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
35163 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
35164 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
35165 {NULL}};
35166
35167
35168 -static const char *block_name[] __devinitdata = {
35169 +static const char *block_name[] __devinitconst = {
35170 "21140 non-MII",
35171 "21140 MII PHY",
35172 "21142 Serial PHY",
35173 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
35174 index 75d45f8..3d9c55b 100644
35175 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
35176 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
35177 @@ -129,7 +129,7 @@ struct uli526x_board_info {
35178 struct uli_phy_ops {
35179 void (*write)(struct uli526x_board_info *, u8, u8, u16);
35180 u16 (*read)(struct uli526x_board_info *, u8, u8);
35181 - } phy;
35182 + } __no_const phy;
35183 struct net_device *next_dev; /* next device */
35184 struct pci_dev *pdev; /* PCI device */
35185 spinlock_t lock;
35186 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
35187 index 4d1ffca..7c1ec4d 100644
35188 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
35189 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
35190 @@ -236,7 +236,7 @@ struct pci_id_info {
35191 int drv_flags; /* Driver use, intended as capability flags. */
35192 };
35193
35194 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35195 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35196 { /* Sometime a Level-One switch card. */
35197 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
35198 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
35199 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
35200 index d7bb52a..3b83588 100644
35201 --- a/drivers/net/ethernet/dlink/sundance.c
35202 +++ b/drivers/net/ethernet/dlink/sundance.c
35203 @@ -218,7 +218,7 @@ enum {
35204 struct pci_id_info {
35205 const char *name;
35206 };
35207 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35208 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35209 {"D-Link DFE-550TX FAST Ethernet Adapter"},
35210 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
35211 {"D-Link DFE-580TX 4 port Server Adapter"},
35212 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
35213 index 78b8aa8..dd6323a 100644
35214 --- a/drivers/net/ethernet/emulex/benet/be_main.c
35215 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
35216 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
35217
35218 if (wrapped)
35219 newacc += 65536;
35220 - ACCESS_ONCE(*acc) = newacc;
35221 + ACCESS_ONCE_RW(*acc) = newacc;
35222 }
35223
35224 void be_parse_stats(struct be_adapter *adapter)
35225 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
35226 index 74d749e..eefb1bd 100644
35227 --- a/drivers/net/ethernet/faraday/ftgmac100.c
35228 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
35229 @@ -31,6 +31,8 @@
35230 #include <linux/netdevice.h>
35231 #include <linux/phy.h>
35232 #include <linux/platform_device.h>
35233 +#include <linux/interrupt.h>
35234 +#include <linux/irqreturn.h>
35235 #include <net/ip.h>
35236
35237 #include "ftgmac100.h"
35238 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
35239 index b901a01..1ff32ee 100644
35240 --- a/drivers/net/ethernet/faraday/ftmac100.c
35241 +++ b/drivers/net/ethernet/faraday/ftmac100.c
35242 @@ -31,6 +31,8 @@
35243 #include <linux/module.h>
35244 #include <linux/netdevice.h>
35245 #include <linux/platform_device.h>
35246 +#include <linux/interrupt.h>
35247 +#include <linux/irqreturn.h>
35248
35249 #include "ftmac100.h"
35250
35251 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
35252 index 9d71c9c..0e4a0ac 100644
35253 --- a/drivers/net/ethernet/fealnx.c
35254 +++ b/drivers/net/ethernet/fealnx.c
35255 @@ -150,7 +150,7 @@ struct chip_info {
35256 int flags;
35257 };
35258
35259 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35260 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35261 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35262 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35263 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35264 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35265 index ed5b409..ec37828 100644
35266 --- a/drivers/net/ethernet/intel/e1000e/hw.h
35267 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
35268 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
35269 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35270 s32 (*read_mac_addr)(struct e1000_hw *);
35271 };
35272 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35273
35274 /*
35275 * When to use various PHY register access functions:
35276 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
35277 void (*power_up)(struct e1000_hw *);
35278 void (*power_down)(struct e1000_hw *);
35279 };
35280 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35281
35282 /* Function pointers for the NVM. */
35283 struct e1000_nvm_operations {
35284 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35285 s32 (*validate)(struct e1000_hw *);
35286 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35287 };
35288 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35289
35290 struct e1000_mac_info {
35291 - struct e1000_mac_operations ops;
35292 + e1000_mac_operations_no_const ops;
35293 u8 addr[ETH_ALEN];
35294 u8 perm_addr[ETH_ALEN];
35295
35296 @@ -892,7 +895,7 @@ struct e1000_mac_info {
35297 };
35298
35299 struct e1000_phy_info {
35300 - struct e1000_phy_operations ops;
35301 + e1000_phy_operations_no_const ops;
35302
35303 enum e1000_phy_type type;
35304
35305 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35306 };
35307
35308 struct e1000_nvm_info {
35309 - struct e1000_nvm_operations ops;
35310 + e1000_nvm_operations_no_const ops;
35311
35312 enum e1000_nvm_type type;
35313 enum e1000_nvm_override override;
35314 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35315 index c2a51dc..c2bd262 100644
35316 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35317 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35318 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35319 void (*release_swfw_sync)(struct e1000_hw *, u16);
35320
35321 };
35322 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35323
35324 struct e1000_phy_operations {
35325 s32 (*acquire)(struct e1000_hw *);
35326 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35327 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35328 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35329 };
35330 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35331
35332 struct e1000_nvm_operations {
35333 s32 (*acquire)(struct e1000_hw *);
35334 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35335 s32 (*validate)(struct e1000_hw *);
35336 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35337 };
35338 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35339
35340 struct e1000_info {
35341 s32 (*get_invariants)(struct e1000_hw *);
35342 @@ -364,7 +367,7 @@ struct e1000_info {
35343 extern const struct e1000_info e1000_82575_info;
35344
35345 struct e1000_mac_info {
35346 - struct e1000_mac_operations ops;
35347 + e1000_mac_operations_no_const ops;
35348
35349 u8 addr[6];
35350 u8 perm_addr[6];
35351 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35352 };
35353
35354 struct e1000_phy_info {
35355 - struct e1000_phy_operations ops;
35356 + e1000_phy_operations_no_const ops;
35357
35358 enum e1000_phy_type type;
35359
35360 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35361 };
35362
35363 struct e1000_nvm_info {
35364 - struct e1000_nvm_operations ops;
35365 + e1000_nvm_operations_no_const ops;
35366 enum e1000_nvm_type type;
35367 enum e1000_nvm_override override;
35368
35369 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35370 s32 (*check_for_ack)(struct e1000_hw *, u16);
35371 s32 (*check_for_rst)(struct e1000_hw *, u16);
35372 };
35373 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35374
35375 struct e1000_mbx_stats {
35376 u32 msgs_tx;
35377 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35378 };
35379
35380 struct e1000_mbx_info {
35381 - struct e1000_mbx_operations ops;
35382 + e1000_mbx_operations_no_const ops;
35383 struct e1000_mbx_stats stats;
35384 u32 timeout;
35385 u32 usec_delay;
35386 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35387 index 57db3c6..aa825fc 100644
35388 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35389 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35390 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35391 s32 (*read_mac_addr)(struct e1000_hw *);
35392 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35393 };
35394 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35395
35396 struct e1000_mac_info {
35397 - struct e1000_mac_operations ops;
35398 + e1000_mac_operations_no_const ops;
35399 u8 addr[6];
35400 u8 perm_addr[6];
35401
35402 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35403 s32 (*check_for_ack)(struct e1000_hw *);
35404 s32 (*check_for_rst)(struct e1000_hw *);
35405 };
35406 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35407
35408 struct e1000_mbx_stats {
35409 u32 msgs_tx;
35410 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35411 };
35412
35413 struct e1000_mbx_info {
35414 - struct e1000_mbx_operations ops;
35415 + e1000_mbx_operations_no_const ops;
35416 struct e1000_mbx_stats stats;
35417 u32 timeout;
35418 u32 usec_delay;
35419 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35420 index 3456d56..b688d81 100644
35421 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35422 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35423 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35424 /* store the new cycle speed */
35425 adapter->cycle_speed = cycle_speed;
35426
35427 - ACCESS_ONCE(adapter->base_incval) = incval;
35428 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35429 smp_mb();
35430
35431 /* grab the ptp lock */
35432 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35433 index 0722f33..771758a 100644
35434 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35435 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35436 @@ -2800,6 +2800,7 @@ struct ixgbe_eeprom_operations {
35437 s32 (*update_checksum)(struct ixgbe_hw *);
35438 u16 (*calc_checksum)(struct ixgbe_hw *);
35439 };
35440 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35441
35442 struct ixgbe_mac_operations {
35443 s32 (*init_hw)(struct ixgbe_hw *);
35444 @@ -2866,6 +2867,7 @@ struct ixgbe_mac_operations {
35445 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35446 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35447 };
35448 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35449
35450 struct ixgbe_phy_operations {
35451 s32 (*identify)(struct ixgbe_hw *);
35452 @@ -2885,9 +2887,10 @@ struct ixgbe_phy_operations {
35453 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35454 s32 (*check_overtemp)(struct ixgbe_hw *);
35455 };
35456 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35457
35458 struct ixgbe_eeprom_info {
35459 - struct ixgbe_eeprom_operations ops;
35460 + ixgbe_eeprom_operations_no_const ops;
35461 enum ixgbe_eeprom_type type;
35462 u32 semaphore_delay;
35463 u16 word_size;
35464 @@ -2897,7 +2900,7 @@ struct ixgbe_eeprom_info {
35465
35466 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35467 struct ixgbe_mac_info {
35468 - struct ixgbe_mac_operations ops;
35469 + ixgbe_mac_operations_no_const ops;
35470 enum ixgbe_mac_type type;
35471 u8 addr[ETH_ALEN];
35472 u8 perm_addr[ETH_ALEN];
35473 @@ -2927,7 +2930,7 @@ struct ixgbe_mac_info {
35474 };
35475
35476 struct ixgbe_phy_info {
35477 - struct ixgbe_phy_operations ops;
35478 + ixgbe_phy_operations_no_const ops;
35479 struct mdio_if_info mdio;
35480 enum ixgbe_phy_type type;
35481 u32 id;
35482 @@ -2955,6 +2958,7 @@ struct ixgbe_mbx_operations {
35483 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35484 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35485 };
35486 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35487
35488 struct ixgbe_mbx_stats {
35489 u32 msgs_tx;
35490 @@ -2966,7 +2970,7 @@ struct ixgbe_mbx_stats {
35491 };
35492
35493 struct ixgbe_mbx_info {
35494 - struct ixgbe_mbx_operations ops;
35495 + ixgbe_mbx_operations_no_const ops;
35496 struct ixgbe_mbx_stats stats;
35497 u32 timeout;
35498 u32 usec_delay;
35499 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35500 index 25c951d..cc7cf33 100644
35501 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35502 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35503 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35504 s32 (*clear_vfta)(struct ixgbe_hw *);
35505 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35506 };
35507 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35508
35509 enum ixgbe_mac_type {
35510 ixgbe_mac_unknown = 0,
35511 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35512 };
35513
35514 struct ixgbe_mac_info {
35515 - struct ixgbe_mac_operations ops;
35516 + ixgbe_mac_operations_no_const ops;
35517 u8 addr[6];
35518 u8 perm_addr[6];
35519
35520 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35521 s32 (*check_for_ack)(struct ixgbe_hw *);
35522 s32 (*check_for_rst)(struct ixgbe_hw *);
35523 };
35524 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35525
35526 struct ixgbe_mbx_stats {
35527 u32 msgs_tx;
35528 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35529 };
35530
35531 struct ixgbe_mbx_info {
35532 - struct ixgbe_mbx_operations ops;
35533 + ixgbe_mbx_operations_no_const ops;
35534 struct ixgbe_mbx_stats stats;
35535 u32 timeout;
35536 u32 udelay;
35537 diff --git a/drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c b/drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c
35538 index 5d367958..b799ab12 100644
35539 --- a/drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c
35540 +++ b/drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c
35541 @@ -237,7 +237,7 @@ static int mlx4_en_dcbnl_ieee_setmaxrate(struct net_device *dev,
35542 if (err)
35543 return err;
35544
35545 - memcpy(priv->maxrate, tmp, sizeof(*priv->maxrate));
35546 + memcpy(priv->maxrate, tmp, sizeof(priv->maxrate));
35547
35548 return 0;
35549 }
35550 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35551 index 9e0c1ee..8471f77 100644
35552 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35553 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35554 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35555 void (*link_down)(struct __vxge_hw_device *devh);
35556 void (*crit_err)(struct __vxge_hw_device *devh,
35557 enum vxge_hw_event type, u64 ext_data);
35558 -};
35559 +} __no_const;
35560
35561 /*
35562 * struct __vxge_hw_blockpool_entry - Block private data structure
35563 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35564 index 4a518a3..936b334 100644
35565 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35566 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35567 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35568 struct vxge_hw_mempool_dma *dma_object,
35569 u32 index,
35570 u32 is_last);
35571 -};
35572 +} __no_const;
35573
35574 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35575 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35576 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35577 index df7bbba..162f850 100644
35578 --- a/drivers/net/ethernet/realtek/r8169.c
35579 +++ b/drivers/net/ethernet/realtek/r8169.c
35580 @@ -745,22 +745,22 @@ struct rtl8169_private {
35581 struct mdio_ops {
35582 void (*write)(struct rtl8169_private *, int, int);
35583 int (*read)(struct rtl8169_private *, int);
35584 - } mdio_ops;
35585 + } __no_const mdio_ops;
35586
35587 struct pll_power_ops {
35588 void (*down)(struct rtl8169_private *);
35589 void (*up)(struct rtl8169_private *);
35590 - } pll_power_ops;
35591 + } __no_const pll_power_ops;
35592
35593 struct jumbo_ops {
35594 void (*enable)(struct rtl8169_private *);
35595 void (*disable)(struct rtl8169_private *);
35596 - } jumbo_ops;
35597 + } __no_const jumbo_ops;
35598
35599 struct csi_ops {
35600 void (*write)(struct rtl8169_private *, int, int);
35601 u32 (*read)(struct rtl8169_private *, int);
35602 - } csi_ops;
35603 + } __no_const csi_ops;
35604
35605 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35606 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35607 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35608 index 4613591..d816601 100644
35609 --- a/drivers/net/ethernet/sis/sis190.c
35610 +++ b/drivers/net/ethernet/sis/sis190.c
35611 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35612 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35613 struct net_device *dev)
35614 {
35615 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35616 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35617 struct sis190_private *tp = netdev_priv(dev);
35618 struct pci_dev *isa_bridge;
35619 u8 reg, tmp8;
35620 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35621 index 0c74a70..3bc6f68 100644
35622 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35623 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35624 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35625
35626 writel(value, ioaddr + MMC_CNTRL);
35627
35628 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35629 - MMC_CNTRL, value);
35630 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35631 +// MMC_CNTRL, value);
35632 }
35633
35634 /* To mask all all interrupts.*/
35635 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35636 index 95ceb35..318fc12 100644
35637 --- a/drivers/net/hyperv/hyperv_net.h
35638 +++ b/drivers/net/hyperv/hyperv_net.h
35639 @@ -99,7 +99,7 @@ struct rndis_device {
35640
35641 enum rndis_device_state state;
35642 bool link_state;
35643 - atomic_t new_req_id;
35644 + atomic_unchecked_t new_req_id;
35645
35646 spinlock_t request_lock;
35647 struct list_head req_list;
35648 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35649 index 1e88a10..1b01736 100644
35650 --- a/drivers/net/hyperv/rndis_filter.c
35651 +++ b/drivers/net/hyperv/rndis_filter.c
35652 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35653 * template
35654 */
35655 set = &rndis_msg->msg.set_req;
35656 - set->req_id = atomic_inc_return(&dev->new_req_id);
35657 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35658
35659 /* Add to the request list */
35660 spin_lock_irqsave(&dev->request_lock, flags);
35661 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35662
35663 /* Setup the rndis set */
35664 halt = &request->request_msg.msg.halt_req;
35665 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35666 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35667
35668 /* Ignore return since this msg is optional. */
35669 rndis_filter_send_request(dev, request);
35670 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35671 index daec9b0..6428fcb 100644
35672 --- a/drivers/net/phy/mdio-bitbang.c
35673 +++ b/drivers/net/phy/mdio-bitbang.c
35674 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35675 struct mdiobb_ctrl *ctrl = bus->priv;
35676
35677 module_put(ctrl->ops->owner);
35678 + mdiobus_unregister(bus);
35679 mdiobus_free(bus);
35680 }
35681 EXPORT_SYMBOL(free_mdio_bitbang);
35682 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35683 index 5c05572..389610b 100644
35684 --- a/drivers/net/ppp/ppp_generic.c
35685 +++ b/drivers/net/ppp/ppp_generic.c
35686 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35687 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35688 struct ppp_stats stats;
35689 struct ppp_comp_stats cstats;
35690 - char *vers;
35691
35692 switch (cmd) {
35693 case SIOCGPPPSTATS:
35694 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35695 break;
35696
35697 case SIOCGPPPVER:
35698 - vers = PPP_VERSION;
35699 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35700 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35701 break;
35702 err = 0;
35703 break;
35704 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35705 index 3a16d4f..a311cec 100644
35706 --- a/drivers/net/tun.c
35707 +++ b/drivers/net/tun.c
35708 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35709 }
35710
35711 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35712 - unsigned long arg, int ifreq_len)
35713 + unsigned long arg, size_t ifreq_len)
35714 {
35715 struct tun_file *tfile = file->private_data;
35716 struct tun_struct *tun;
35717 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35718 int vnet_hdr_sz;
35719 int ret;
35720
35721 + if (ifreq_len > sizeof ifr)
35722 + return -EFAULT;
35723 +
35724 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35725 if (copy_from_user(&ifr, argp, ifreq_len))
35726 return -EFAULT;
35727 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35728 index 62f30b4..ff99dfd 100644
35729 --- a/drivers/net/usb/hso.c
35730 +++ b/drivers/net/usb/hso.c
35731 @@ -71,7 +71,7 @@
35732 #include <asm/byteorder.h>
35733 #include <linux/serial_core.h>
35734 #include <linux/serial.h>
35735 -
35736 +#include <asm/local.h>
35737
35738 #define MOD_AUTHOR "Option Wireless"
35739 #define MOD_DESCRIPTION "USB High Speed Option driver"
35740 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35741 struct urb *urb;
35742
35743 urb = serial->rx_urb[0];
35744 - if (serial->port.count > 0) {
35745 + if (atomic_read(&serial->port.count) > 0) {
35746 count = put_rxbuf_data(urb, serial);
35747 if (count == -1)
35748 return;
35749 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35750 DUMP1(urb->transfer_buffer, urb->actual_length);
35751
35752 /* Anyone listening? */
35753 - if (serial->port.count == 0)
35754 + if (atomic_read(&serial->port.count) == 0)
35755 return;
35756
35757 if (status == 0) {
35758 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35759 tty_port_tty_set(&serial->port, tty);
35760
35761 /* check for port already opened, if not set the termios */
35762 - serial->port.count++;
35763 - if (serial->port.count == 1) {
35764 + if (atomic_inc_return(&serial->port.count) == 1) {
35765 serial->rx_state = RX_IDLE;
35766 /* Force default termio settings */
35767 _hso_serial_set_termios(tty, NULL);
35768 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35769 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35770 if (result) {
35771 hso_stop_serial_device(serial->parent);
35772 - serial->port.count--;
35773 + atomic_dec(&serial->port.count);
35774 kref_put(&serial->parent->ref, hso_serial_ref_free);
35775 }
35776 } else {
35777 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35778
35779 /* reset the rts and dtr */
35780 /* do the actual close */
35781 - serial->port.count--;
35782 + atomic_dec(&serial->port.count);
35783
35784 - if (serial->port.count <= 0) {
35785 - serial->port.count = 0;
35786 + if (atomic_read(&serial->port.count) <= 0) {
35787 + atomic_set(&serial->port.count, 0);
35788 tty_port_tty_set(&serial->port, NULL);
35789 if (!usb_gone)
35790 hso_stop_serial_device(serial->parent);
35791 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35792
35793 /* the actual setup */
35794 spin_lock_irqsave(&serial->serial_lock, flags);
35795 - if (serial->port.count)
35796 + if (atomic_read(&serial->port.count))
35797 _hso_serial_set_termios(tty, old);
35798 else
35799 tty->termios = old;
35800 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35801 D1("Pending read interrupt on port %d\n", i);
35802 spin_lock(&serial->serial_lock);
35803 if (serial->rx_state == RX_IDLE &&
35804 - serial->port.count > 0) {
35805 + atomic_read(&serial->port.count) > 0) {
35806 /* Setup and send a ctrl req read on
35807 * port i */
35808 if (!serial->rx_urb_filled[0]) {
35809 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35810 /* Start all serial ports */
35811 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35812 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35813 - if (dev2ser(serial_table[i])->port.count) {
35814 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35815 result =
35816 hso_start_serial_device(serial_table[i], GFP_NOIO);
35817 hso_kick_transmit(dev2ser(serial_table[i]));
35818 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35819 index 6169fbd..40e8422 100644
35820 --- a/drivers/net/wireless/ath/ath.h
35821 +++ b/drivers/net/wireless/ath/ath.h
35822 @@ -119,6 +119,7 @@ struct ath_ops {
35823 void (*write_flush) (void *);
35824 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35825 };
35826 +typedef struct ath_ops __no_const ath_ops_no_const;
35827
35828 struct ath_common;
35829 struct ath_bus_ops;
35830 diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
35831 index 2aab20e..b761ef8 100644
35832 --- a/drivers/net/wireless/ath/ath5k/base.c
35833 +++ b/drivers/net/wireless/ath/ath5k/base.c
35834 @@ -1803,7 +1803,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35835 {
35836 int ret;
35837 struct ath5k_hw *ah = hw->priv;
35838 - struct ath5k_vif *avf = (void *)vif->drv_priv;
35839 + struct ath5k_vif *avf;
35840 struct sk_buff *skb;
35841
35842 if (WARN_ON(!vif)) {
35843 @@ -1818,6 +1818,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35844 goto out;
35845 }
35846
35847 + avf = (void *)vif->drv_priv;
35848 ath5k_txbuf_free_skb(ah, avf->bbuf);
35849 avf->bbuf->skb = skb;
35850 ret = ath5k_beacon_setup(ah, avf->bbuf);
35851 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35852 index 8d78253..bebbb68 100644
35853 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35854 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35855 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35856 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35857 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35858
35859 - ACCESS_ONCE(ads->ds_link) = i->link;
35860 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35861 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35862 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35863
35864 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35865 ctl6 = SM(i->keytype, AR_EncrType);
35866 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35867
35868 if ((i->is_first || i->is_last) &&
35869 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35870 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35871 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35872 | set11nTries(i->rates, 1)
35873 | set11nTries(i->rates, 2)
35874 | set11nTries(i->rates, 3)
35875 | (i->dur_update ? AR_DurUpdateEna : 0)
35876 | SM(0, AR_BurstDur);
35877
35878 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35879 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35880 | set11nRate(i->rates, 1)
35881 | set11nRate(i->rates, 2)
35882 | set11nRate(i->rates, 3);
35883 } else {
35884 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35885 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35886 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35887 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35888 }
35889
35890 if (!i->is_first) {
35891 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35892 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35893 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35894 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35895 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35896 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35897 return;
35898 }
35899
35900 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35901 break;
35902 }
35903
35904 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35905 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35906 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35907 | SM(i->txpower, AR_XmitPower)
35908 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35909 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35910 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35911 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35912
35913 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35914 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35915 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35916 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35917
35918 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35919 return;
35920
35921 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35922 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35923 | set11nPktDurRTSCTS(i->rates, 1);
35924
35925 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35926 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35927 | set11nPktDurRTSCTS(i->rates, 3);
35928
35929 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35930 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35931 | set11nRateFlags(i->rates, 1)
35932 | set11nRateFlags(i->rates, 2)
35933 | set11nRateFlags(i->rates, 3)
35934 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35935 index 78816b8..1fcdfae 100644
35936 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35937 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35938 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35939 (i->qcu << AR_TxQcuNum_S) | desc_len;
35940
35941 checksum += val;
35942 - ACCESS_ONCE(ads->info) = val;
35943 + ACCESS_ONCE_RW(ads->info) = val;
35944
35945 checksum += i->link;
35946 - ACCESS_ONCE(ads->link) = i->link;
35947 + ACCESS_ONCE_RW(ads->link) = i->link;
35948
35949 checksum += i->buf_addr[0];
35950 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35951 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35952 checksum += i->buf_addr[1];
35953 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35954 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35955 checksum += i->buf_addr[2];
35956 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35957 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35958 checksum += i->buf_addr[3];
35959 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35960 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35961
35962 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35963 - ACCESS_ONCE(ads->ctl3) = val;
35964 + ACCESS_ONCE_RW(ads->ctl3) = val;
35965 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35966 - ACCESS_ONCE(ads->ctl5) = val;
35967 + ACCESS_ONCE_RW(ads->ctl5) = val;
35968 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35969 - ACCESS_ONCE(ads->ctl7) = val;
35970 + ACCESS_ONCE_RW(ads->ctl7) = val;
35971 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35972 - ACCESS_ONCE(ads->ctl9) = val;
35973 + ACCESS_ONCE_RW(ads->ctl9) = val;
35974
35975 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35976 - ACCESS_ONCE(ads->ctl10) = checksum;
35977 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35978
35979 if (i->is_first || i->is_last) {
35980 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35981 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35982 | set11nTries(i->rates, 1)
35983 | set11nTries(i->rates, 2)
35984 | set11nTries(i->rates, 3)
35985 | (i->dur_update ? AR_DurUpdateEna : 0)
35986 | SM(0, AR_BurstDur);
35987
35988 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35989 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35990 | set11nRate(i->rates, 1)
35991 | set11nRate(i->rates, 2)
35992 | set11nRate(i->rates, 3);
35993 } else {
35994 - ACCESS_ONCE(ads->ctl13) = 0;
35995 - ACCESS_ONCE(ads->ctl14) = 0;
35996 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35997 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35998 }
35999
36000 ads->ctl20 = 0;
36001 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36002
36003 ctl17 = SM(i->keytype, AR_EncrType);
36004 if (!i->is_first) {
36005 - ACCESS_ONCE(ads->ctl11) = 0;
36006 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36007 - ACCESS_ONCE(ads->ctl15) = 0;
36008 - ACCESS_ONCE(ads->ctl16) = 0;
36009 - ACCESS_ONCE(ads->ctl17) = ctl17;
36010 - ACCESS_ONCE(ads->ctl18) = 0;
36011 - ACCESS_ONCE(ads->ctl19) = 0;
36012 + ACCESS_ONCE_RW(ads->ctl11) = 0;
36013 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36014 + ACCESS_ONCE_RW(ads->ctl15) = 0;
36015 + ACCESS_ONCE_RW(ads->ctl16) = 0;
36016 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36017 + ACCESS_ONCE_RW(ads->ctl18) = 0;
36018 + ACCESS_ONCE_RW(ads->ctl19) = 0;
36019 return;
36020 }
36021
36022 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36023 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36024 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36025 | SM(i->txpower, AR_XmitPower)
36026 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36027 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36028 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
36029 ctl12 |= SM(val, AR_PAPRDChainMask);
36030
36031 - ACCESS_ONCE(ads->ctl12) = ctl12;
36032 - ACCESS_ONCE(ads->ctl17) = ctl17;
36033 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
36034 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36035
36036 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36037 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36038 | set11nPktDurRTSCTS(i->rates, 1);
36039
36040 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36041 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36042 | set11nPktDurRTSCTS(i->rates, 3);
36043
36044 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
36045 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
36046 | set11nRateFlags(i->rates, 1)
36047 | set11nRateFlags(i->rates, 2)
36048 | set11nRateFlags(i->rates, 3)
36049 | SM(i->rtscts_rate, AR_RTSCTSRate);
36050
36051 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
36052 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
36053 }
36054
36055 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
36056 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
36057 index de6968f..29ac4c1 100644
36058 --- a/drivers/net/wireless/ath/ath9k/hw.h
36059 +++ b/drivers/net/wireless/ath/ath9k/hw.h
36060 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
36061
36062 /* ANI */
36063 void (*ani_cache_ini_regs)(struct ath_hw *ah);
36064 -};
36065 +} __no_const;
36066
36067 /**
36068 * struct ath_hw_ops - callbacks used by hardware code and driver code
36069 @@ -686,7 +686,7 @@ struct ath_hw_ops {
36070 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
36071 struct ath_hw_antcomb_conf *antconf);
36072
36073 -};
36074 +} __no_const;
36075
36076 struct ath_nf_limits {
36077 s16 max;
36078 @@ -706,7 +706,7 @@ enum ath_cal_list {
36079 #define AH_FASTCC 0x4
36080
36081 struct ath_hw {
36082 - struct ath_ops reg_ops;
36083 + ath_ops_no_const reg_ops;
36084
36085 struct ieee80211_hw *hw;
36086 struct ath_common common;
36087 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36088 index af00e2c..ab04d34 100644
36089 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36090 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36091 @@ -545,7 +545,7 @@ struct phy_func_ptr {
36092 void (*carrsuppr)(struct brcms_phy *);
36093 s32 (*rxsigpwr)(struct brcms_phy *, s32);
36094 void (*detach)(struct brcms_phy *);
36095 -};
36096 +} __no_const;
36097
36098 struct brcms_phy {
36099 struct brcms_phy_pub pubpi_ro;
36100 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
36101 index faec404..a5277f1 100644
36102 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
36103 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
36104 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
36105 */
36106 if (il3945_mod_params.disable_hw_scan) {
36107 D_INFO("Disabling hw_scan\n");
36108 - il3945_mac_ops.hw_scan = NULL;
36109 + pax_open_kernel();
36110 + *(void **)&il3945_mac_ops.hw_scan = NULL;
36111 + pax_close_kernel();
36112 }
36113
36114 D_INFO("*** LOAD DRIVER ***\n");
36115 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36116 index a47b306..297daf2 100644
36117 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36118 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36119 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
36120 {
36121 struct iwl_priv *priv = file->private_data;
36122 char buf[64];
36123 - int buf_size;
36124 + size_t buf_size;
36125 u32 offset, len;
36126
36127 memset(buf, 0, sizeof(buf));
36128 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
36129 struct iwl_priv *priv = file->private_data;
36130
36131 char buf[8];
36132 - int buf_size;
36133 + size_t buf_size;
36134 u32 reset_flag;
36135
36136 memset(buf, 0, sizeof(buf));
36137 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
36138 {
36139 struct iwl_priv *priv = file->private_data;
36140 char buf[8];
36141 - int buf_size;
36142 + size_t buf_size;
36143 int ht40;
36144
36145 memset(buf, 0, sizeof(buf));
36146 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
36147 {
36148 struct iwl_priv *priv = file->private_data;
36149 char buf[8];
36150 - int buf_size;
36151 + size_t buf_size;
36152 int value;
36153
36154 memset(buf, 0, sizeof(buf));
36155 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
36156 {
36157 struct iwl_priv *priv = file->private_data;
36158 char buf[8];
36159 - int buf_size;
36160 + size_t buf_size;
36161 int clear;
36162
36163 memset(buf, 0, sizeof(buf));
36164 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
36165 {
36166 struct iwl_priv *priv = file->private_data;
36167 char buf[8];
36168 - int buf_size;
36169 + size_t buf_size;
36170 int trace;
36171
36172 memset(buf, 0, sizeof(buf));
36173 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
36174 {
36175 struct iwl_priv *priv = file->private_data;
36176 char buf[8];
36177 - int buf_size;
36178 + size_t buf_size;
36179 int missed;
36180
36181 memset(buf, 0, sizeof(buf));
36182 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
36183
36184 struct iwl_priv *priv = file->private_data;
36185 char buf[8];
36186 - int buf_size;
36187 + size_t buf_size;
36188 int plcp;
36189
36190 memset(buf, 0, sizeof(buf));
36191 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
36192
36193 struct iwl_priv *priv = file->private_data;
36194 char buf[8];
36195 - int buf_size;
36196 + size_t buf_size;
36197 int flush;
36198
36199 memset(buf, 0, sizeof(buf));
36200 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
36201
36202 struct iwl_priv *priv = file->private_data;
36203 char buf[8];
36204 - int buf_size;
36205 + size_t buf_size;
36206 int rts;
36207
36208 if (!priv->cfg->ht_params)
36209 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
36210 {
36211 struct iwl_priv *priv = file->private_data;
36212 char buf[8];
36213 - int buf_size;
36214 + size_t buf_size;
36215
36216 memset(buf, 0, sizeof(buf));
36217 buf_size = min(count, sizeof(buf) - 1);
36218 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
36219 struct iwl_priv *priv = file->private_data;
36220 u32 event_log_flag;
36221 char buf[8];
36222 - int buf_size;
36223 + size_t buf_size;
36224
36225 /* check that the interface is up */
36226 if (!iwl_is_ready(priv))
36227 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
36228 struct iwl_priv *priv = file->private_data;
36229 char buf[8];
36230 u32 calib_disabled;
36231 - int buf_size;
36232 + size_t buf_size;
36233
36234 memset(buf, 0, sizeof(buf));
36235 buf_size = min(count, sizeof(buf) - 1);
36236 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
36237 index dbeebef..b45a152 100644
36238 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
36239 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
36240 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
36241 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
36242
36243 char buf[8];
36244 - int buf_size;
36245 + size_t buf_size;
36246 u32 reset_flag;
36247
36248 memset(buf, 0, sizeof(buf));
36249 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36250 {
36251 struct iwl_trans *trans = file->private_data;
36252 char buf[8];
36253 - int buf_size;
36254 + size_t buf_size;
36255 int csr;
36256
36257 memset(buf, 0, sizeof(buf));
36258 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36259 index 0083839..fcb7225 100644
36260 --- a/drivers/net/wireless/mac80211_hwsim.c
36261 +++ b/drivers/net/wireless/mac80211_hwsim.c
36262 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
36263 return -EINVAL;
36264
36265 if (fake_hw_scan) {
36266 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36267 - mac80211_hwsim_ops.sw_scan_start = NULL;
36268 - mac80211_hwsim_ops.sw_scan_complete = NULL;
36269 + pax_open_kernel();
36270 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36271 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36272 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36273 + pax_close_kernel();
36274 }
36275
36276 spin_lock_init(&hwsim_radio_lock);
36277 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36278 index e7c2a82..582e228 100644
36279 --- a/drivers/net/wireless/mwifiex/main.h
36280 +++ b/drivers/net/wireless/mwifiex/main.h
36281 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
36282 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36283 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
36284 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
36285 -};
36286 +} __no_const;
36287
36288 struct mwifiex_adapter {
36289 u8 iface_type;
36290 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36291 index 7a4ae9e..56e00bd 100644
36292 --- a/drivers/net/wireless/rndis_wlan.c
36293 +++ b/drivers/net/wireless/rndis_wlan.c
36294 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36295
36296 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36297
36298 - if (rts_threshold < 0 || rts_threshold > 2347)
36299 + if (rts_threshold > 2347)
36300 rts_threshold = 2347;
36301
36302 tmp = cpu_to_le32(rts_threshold);
36303 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36304 index 8afb546..0c0dc5c 100644
36305 --- a/drivers/net/wireless/rt2x00/rt2x00.h
36306 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
36307 @@ -397,7 +397,7 @@ struct rt2x00_intf {
36308 * for hardware which doesn't support hardware
36309 * sequence counting.
36310 */
36311 - atomic_t seqno;
36312 + atomic_unchecked_t seqno;
36313 };
36314
36315 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36316 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36317 index f7e74a0..da71431 100644
36318 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36319 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36320 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36321 * sequence counter given by mac80211.
36322 */
36323 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36324 - seqno = atomic_add_return(0x10, &intf->seqno);
36325 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36326 else
36327 - seqno = atomic_read(&intf->seqno);
36328 + seqno = atomic_read_unchecked(&intf->seqno);
36329
36330 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36331 hdr->seq_ctrl |= cpu_to_le16(seqno);
36332 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36333 index fd02060..74ee481 100644
36334 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
36335 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36336 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
36337 void (*reset)(struct wl1251 *wl);
36338 void (*enable_irq)(struct wl1251 *wl);
36339 void (*disable_irq)(struct wl1251 *wl);
36340 -};
36341 +} __no_const;
36342
36343 struct wl1251 {
36344 struct ieee80211_hw *hw;
36345 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36346 index 0ce7a8e..56a0ccf 100644
36347 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36348 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36349 @@ -81,7 +81,7 @@ struct wlcore_ops {
36350 struct ieee80211_sta *sta,
36351 struct ieee80211_key_conf *key_conf);
36352 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36353 -};
36354 +} __no_const;
36355
36356 enum wlcore_partitions {
36357 PART_DOWN,
36358 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36359 index f34b5b2..b5abb9f 100644
36360 --- a/drivers/oprofile/buffer_sync.c
36361 +++ b/drivers/oprofile/buffer_sync.c
36362 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36363 if (cookie == NO_COOKIE)
36364 offset = pc;
36365 if (cookie == INVALID_COOKIE) {
36366 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36367 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36368 offset = pc;
36369 }
36370 if (cookie != last_cookie) {
36371 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36372 /* add userspace sample */
36373
36374 if (!mm) {
36375 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36376 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36377 return 0;
36378 }
36379
36380 cookie = lookup_dcookie(mm, s->eip, &offset);
36381
36382 if (cookie == INVALID_COOKIE) {
36383 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36384 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36385 return 0;
36386 }
36387
36388 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36389 /* ignore backtraces if failed to add a sample */
36390 if (state == sb_bt_start) {
36391 state = sb_bt_ignore;
36392 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36393 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36394 }
36395 }
36396 release_mm(mm);
36397 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36398 index c0cc4e7..44d4e54 100644
36399 --- a/drivers/oprofile/event_buffer.c
36400 +++ b/drivers/oprofile/event_buffer.c
36401 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36402 }
36403
36404 if (buffer_pos == buffer_size) {
36405 - atomic_inc(&oprofile_stats.event_lost_overflow);
36406 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36407 return;
36408 }
36409
36410 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36411 index ed2c3ec..deda85a 100644
36412 --- a/drivers/oprofile/oprof.c
36413 +++ b/drivers/oprofile/oprof.c
36414 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36415 if (oprofile_ops.switch_events())
36416 return;
36417
36418 - atomic_inc(&oprofile_stats.multiplex_counter);
36419 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36420 start_switch_worker();
36421 }
36422
36423 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36424 index 917d28e..d62d981 100644
36425 --- a/drivers/oprofile/oprofile_stats.c
36426 +++ b/drivers/oprofile/oprofile_stats.c
36427 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36428 cpu_buf->sample_invalid_eip = 0;
36429 }
36430
36431 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36432 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36433 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36434 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36435 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36436 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36437 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36438 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36439 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36440 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36441 }
36442
36443
36444 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36445 index 38b6fc0..b5cbfce 100644
36446 --- a/drivers/oprofile/oprofile_stats.h
36447 +++ b/drivers/oprofile/oprofile_stats.h
36448 @@ -13,11 +13,11 @@
36449 #include <linux/atomic.h>
36450
36451 struct oprofile_stat_struct {
36452 - atomic_t sample_lost_no_mm;
36453 - atomic_t sample_lost_no_mapping;
36454 - atomic_t bt_lost_no_mapping;
36455 - atomic_t event_lost_overflow;
36456 - atomic_t multiplex_counter;
36457 + atomic_unchecked_t sample_lost_no_mm;
36458 + atomic_unchecked_t sample_lost_no_mapping;
36459 + atomic_unchecked_t bt_lost_no_mapping;
36460 + atomic_unchecked_t event_lost_overflow;
36461 + atomic_unchecked_t multiplex_counter;
36462 };
36463
36464 extern struct oprofile_stat_struct oprofile_stats;
36465 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36466 index 849357c..b83c1e0 100644
36467 --- a/drivers/oprofile/oprofilefs.c
36468 +++ b/drivers/oprofile/oprofilefs.c
36469 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36470
36471
36472 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36473 - char const *name, atomic_t *val)
36474 + char const *name, atomic_unchecked_t *val)
36475 {
36476 return __oprofilefs_create_file(sb, root, name,
36477 &atomic_ro_fops, 0444, val);
36478 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36479 index 3f56bc0..707d642 100644
36480 --- a/drivers/parport/procfs.c
36481 +++ b/drivers/parport/procfs.c
36482 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36483
36484 *ppos += len;
36485
36486 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36487 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36488 }
36489
36490 #ifdef CONFIG_PARPORT_1284
36491 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36492
36493 *ppos += len;
36494
36495 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36496 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36497 }
36498 #endif /* IEEE1284.3 support. */
36499
36500 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36501 index 9fff878..ad0ad53 100644
36502 --- a/drivers/pci/hotplug/cpci_hotplug.h
36503 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36504 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36505 int (*hardware_test) (struct slot* slot, u32 value);
36506 u8 (*get_power) (struct slot* slot);
36507 int (*set_power) (struct slot* slot, int value);
36508 -};
36509 +} __no_const;
36510
36511 struct cpci_hp_controller {
36512 unsigned int irq;
36513 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36514 index 76ba8a1..20ca857 100644
36515 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36516 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36517 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36518
36519 void compaq_nvram_init (void __iomem *rom_start)
36520 {
36521 +
36522 +#ifndef CONFIG_PAX_KERNEXEC
36523 if (rom_start) {
36524 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36525 }
36526 +#endif
36527 +
36528 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36529
36530 /* initialize our int15 lock */
36531 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36532 index b500840..d7159d3 100644
36533 --- a/drivers/pci/pcie/aspm.c
36534 +++ b/drivers/pci/pcie/aspm.c
36535 @@ -27,9 +27,9 @@
36536 #define MODULE_PARAM_PREFIX "pcie_aspm."
36537
36538 /* Note: those are not register definitions */
36539 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36540 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36541 -#define ASPM_STATE_L1 (4) /* L1 state */
36542 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36543 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36544 +#define ASPM_STATE_L1 (4U) /* L1 state */
36545 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36546 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36547
36548 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36549 index 61859d0..124539e 100644
36550 --- a/drivers/pci/probe.c
36551 +++ b/drivers/pci/probe.c
36552 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36553 struct pci_bus_region region;
36554 bool bar_too_big = false, bar_disabled = false;
36555
36556 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36557 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36558
36559 /* No printks while decoding is disabled! */
36560 if (!dev->mmio_always_on) {
36561 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36562 index af028c7..654cdfc 100644
36563 --- a/drivers/pci/proc.c
36564 +++ b/drivers/pci/proc.c
36565 @@ -484,7 +484,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36566 static int __init pci_proc_init(void)
36567 {
36568 struct pci_dev *dev = NULL;
36569 +
36570 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36571 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36572 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36573 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36574 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36575 +#endif
36576 +#else
36577 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36578 +#endif
36579 proc_create("devices", 0, proc_bus_pci_dir,
36580 &proc_bus_pci_dev_operations);
36581 proc_initialized = 1;
36582 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36583 index 52daaa8..d6b81eb 100644
36584 --- a/drivers/platform/x86/thinkpad_acpi.c
36585 +++ b/drivers/platform/x86/thinkpad_acpi.c
36586 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36587 return 0;
36588 }
36589
36590 -void static hotkey_mask_warn_incomplete_mask(void)
36591 +static void hotkey_mask_warn_incomplete_mask(void)
36592 {
36593 /* log only what the user can fix... */
36594 const u32 wantedmask = hotkey_driver_mask &
36595 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36596 }
36597 }
36598
36599 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36600 - struct tp_nvram_state *newn,
36601 - const u32 event_mask)
36602 -{
36603 -
36604 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36605 do { \
36606 if ((event_mask & (1 << __scancode)) && \
36607 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36608 tpacpi_hotkey_send_key(__scancode); \
36609 } while (0)
36610
36611 - void issue_volchange(const unsigned int oldvol,
36612 - const unsigned int newvol)
36613 - {
36614 - unsigned int i = oldvol;
36615 +static void issue_volchange(const unsigned int oldvol,
36616 + const unsigned int newvol,
36617 + const u32 event_mask)
36618 +{
36619 + unsigned int i = oldvol;
36620
36621 - while (i > newvol) {
36622 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36623 - i--;
36624 - }
36625 - while (i < newvol) {
36626 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36627 - i++;
36628 - }
36629 + while (i > newvol) {
36630 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36631 + i--;
36632 }
36633 + while (i < newvol) {
36634 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36635 + i++;
36636 + }
36637 +}
36638
36639 - void issue_brightnesschange(const unsigned int oldbrt,
36640 - const unsigned int newbrt)
36641 - {
36642 - unsigned int i = oldbrt;
36643 +static void issue_brightnesschange(const unsigned int oldbrt,
36644 + const unsigned int newbrt,
36645 + const u32 event_mask)
36646 +{
36647 + unsigned int i = oldbrt;
36648
36649 - while (i > newbrt) {
36650 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36651 - i--;
36652 - }
36653 - while (i < newbrt) {
36654 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36655 - i++;
36656 - }
36657 + while (i > newbrt) {
36658 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36659 + i--;
36660 + }
36661 + while (i < newbrt) {
36662 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36663 + i++;
36664 }
36665 +}
36666
36667 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36668 + struct tp_nvram_state *newn,
36669 + const u32 event_mask)
36670 +{
36671 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36672 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36673 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36674 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36675 oldn->volume_level != newn->volume_level) {
36676 /* recently muted, or repeated mute keypress, or
36677 * multiple presses ending in mute */
36678 - issue_volchange(oldn->volume_level, newn->volume_level);
36679 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36680 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36681 }
36682 } else {
36683 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36684 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36685 }
36686 if (oldn->volume_level != newn->volume_level) {
36687 - issue_volchange(oldn->volume_level, newn->volume_level);
36688 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36689 } else if (oldn->volume_toggle != newn->volume_toggle) {
36690 /* repeated vol up/down keypress at end of scale ? */
36691 if (newn->volume_level == 0)
36692 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36693 /* handle brightness */
36694 if (oldn->brightness_level != newn->brightness_level) {
36695 issue_brightnesschange(oldn->brightness_level,
36696 - newn->brightness_level);
36697 + newn->brightness_level,
36698 + event_mask);
36699 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36700 /* repeated key presses that didn't change state */
36701 if (newn->brightness_level == 0)
36702 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36703 && !tp_features.bright_unkfw)
36704 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36705 }
36706 +}
36707
36708 #undef TPACPI_COMPARE_KEY
36709 #undef TPACPI_MAY_SEND_KEY
36710 -}
36711
36712 /*
36713 * Polling driver
36714 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36715 index 769d265..a3a05ca 100644
36716 --- a/drivers/pnp/pnpbios/bioscalls.c
36717 +++ b/drivers/pnp/pnpbios/bioscalls.c
36718 @@ -58,7 +58,7 @@ do { \
36719 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36720 } while(0)
36721
36722 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36723 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36724 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36725
36726 /*
36727 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36728
36729 cpu = get_cpu();
36730 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36731 +
36732 + pax_open_kernel();
36733 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36734 + pax_close_kernel();
36735
36736 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36737 spin_lock_irqsave(&pnp_bios_lock, flags);
36738 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36739 :"memory");
36740 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36741
36742 + pax_open_kernel();
36743 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36744 + pax_close_kernel();
36745 +
36746 put_cpu();
36747
36748 /* If we get here and this is set then the PnP BIOS faulted on us. */
36749 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36750 return status;
36751 }
36752
36753 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36754 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36755 {
36756 int i;
36757
36758 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36759 pnp_bios_callpoint.offset = header->fields.pm16offset;
36760 pnp_bios_callpoint.segment = PNP_CS16;
36761
36762 + pax_open_kernel();
36763 +
36764 for_each_possible_cpu(i) {
36765 struct desc_struct *gdt = get_cpu_gdt_table(i);
36766 if (!gdt)
36767 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36768 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36769 (unsigned long)__va(header->fields.pm16dseg));
36770 }
36771 +
36772 + pax_close_kernel();
36773 }
36774 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36775 index b0ecacb..7c9da2e 100644
36776 --- a/drivers/pnp/resource.c
36777 +++ b/drivers/pnp/resource.c
36778 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36779 return 1;
36780
36781 /* check if the resource is valid */
36782 - if (*irq < 0 || *irq > 15)
36783 + if (*irq > 15)
36784 return 0;
36785
36786 /* check if the resource is reserved */
36787 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36788 return 1;
36789
36790 /* check if the resource is valid */
36791 - if (*dma < 0 || *dma == 4 || *dma > 7)
36792 + if (*dma == 4 || *dma > 7)
36793 return 0;
36794
36795 /* check if the resource is reserved */
36796 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36797 index 181ddec..774b6da 100644
36798 --- a/drivers/power/bq27x00_battery.c
36799 +++ b/drivers/power/bq27x00_battery.c
36800 @@ -80,7 +80,7 @@
36801 struct bq27x00_device_info;
36802 struct bq27x00_access_methods {
36803 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36804 -};
36805 +} __no_const;
36806
36807 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36808
36809 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36810 index 8d53174..04c65de 100644
36811 --- a/drivers/regulator/max8660.c
36812 +++ b/drivers/regulator/max8660.c
36813 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36814 max8660->shadow_regs[MAX8660_OVER1] = 5;
36815 } else {
36816 /* Otherwise devices can be toggled via software */
36817 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36818 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36819 + pax_open_kernel();
36820 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36821 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36822 + pax_close_kernel();
36823 }
36824
36825 /*
36826 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36827 index b388b74..ed82573 100644
36828 --- a/drivers/regulator/mc13892-regulator.c
36829 +++ b/drivers/regulator/mc13892-regulator.c
36830 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36831 }
36832 mc13xxx_unlock(mc13892);
36833
36834 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36835 + pax_open_kernel();
36836 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36837 = mc13892_vcam_set_mode;
36838 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36839 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36840 = mc13892_vcam_get_mode;
36841 + pax_close_kernel();
36842
36843 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36844 ARRAY_SIZE(mc13892_regulators));
36845 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36846 index cace6d3..f623fda 100644
36847 --- a/drivers/rtc/rtc-dev.c
36848 +++ b/drivers/rtc/rtc-dev.c
36849 @@ -14,6 +14,7 @@
36850 #include <linux/module.h>
36851 #include <linux/rtc.h>
36852 #include <linux/sched.h>
36853 +#include <linux/grsecurity.h>
36854 #include "rtc-core.h"
36855
36856 static dev_t rtc_devt;
36857 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36858 if (copy_from_user(&tm, uarg, sizeof(tm)))
36859 return -EFAULT;
36860
36861 + gr_log_timechange();
36862 +
36863 return rtc_set_time(rtc, &tm);
36864
36865 case RTC_PIE_ON:
36866 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36867 index 9e933a8..4f969f7 100644
36868 --- a/drivers/scsi/aacraid/aacraid.h
36869 +++ b/drivers/scsi/aacraid/aacraid.h
36870 @@ -503,7 +503,7 @@ struct adapter_ops
36871 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36872 /* Administrative operations */
36873 int (*adapter_comm)(struct aac_dev * dev, int comm);
36874 -};
36875 +} __no_const;
36876
36877 /*
36878 * Define which interrupt handler needs to be installed
36879 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36880 index 7199534..cb7f158 100644
36881 --- a/drivers/scsi/aacraid/linit.c
36882 +++ b/drivers/scsi/aacraid/linit.c
36883 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36884 #elif defined(__devinitconst)
36885 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36886 #else
36887 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36888 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36889 #endif
36890 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36891 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36892 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36893 index ff80552..1c4120c 100644
36894 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36895 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36896 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36897 .lldd_ata_set_dmamode = asd_set_dmamode,
36898 };
36899
36900 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36901 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36902 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36903 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36904 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36905 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36906 index 4ad7e36..d004679 100644
36907 --- a/drivers/scsi/bfa/bfa.h
36908 +++ b/drivers/scsi/bfa/bfa.h
36909 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36910 u32 *end);
36911 int cpe_vec_q0;
36912 int rme_vec_q0;
36913 -};
36914 +} __no_const;
36915 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36916
36917 struct bfa_faa_cbfn_s {
36918 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36919 index f0f80e2..8ec946b 100644
36920 --- a/drivers/scsi/bfa/bfa_fcpim.c
36921 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36922 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36923
36924 bfa_iotag_attach(fcp);
36925
36926 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36927 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36928 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36929 (fcp->num_itns * sizeof(struct bfa_itn_s));
36930 memset(fcp->itn_arr, 0,
36931 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36932 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36933 {
36934 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36935 - struct bfa_itn_s *itn;
36936 + bfa_itn_s_no_const *itn;
36937
36938 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36939 itn->isr = isr;
36940 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36941 index 36f26da..38a34a8 100644
36942 --- a/drivers/scsi/bfa/bfa_fcpim.h
36943 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36944 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36945 struct bfa_itn_s {
36946 bfa_isr_func_t isr;
36947 };
36948 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36949
36950 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36951 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36952 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36953 struct list_head iotag_tio_free_q; /* free IO resources */
36954 struct list_head iotag_unused_q; /* unused IO resources*/
36955 struct bfa_iotag_s *iotag_arr;
36956 - struct bfa_itn_s *itn_arr;
36957 + bfa_itn_s_no_const *itn_arr;
36958 int num_ioim_reqs;
36959 int num_fwtio_reqs;
36960 int num_itns;
36961 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36962 index 1a99d4b..e85d64b 100644
36963 --- a/drivers/scsi/bfa/bfa_ioc.h
36964 +++ b/drivers/scsi/bfa/bfa_ioc.h
36965 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36966 bfa_ioc_disable_cbfn_t disable_cbfn;
36967 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36968 bfa_ioc_reset_cbfn_t reset_cbfn;
36969 -};
36970 +} __no_const;
36971
36972 /*
36973 * IOC event notification mechanism.
36974 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36975 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36976 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36977 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36978 -};
36979 +} __no_const;
36980
36981 /*
36982 * Queue element to wait for room in request queue. FIFO order is
36983 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36984 index 593085a..47aa999 100644
36985 --- a/drivers/scsi/hosts.c
36986 +++ b/drivers/scsi/hosts.c
36987 @@ -42,7 +42,7 @@
36988 #include "scsi_logging.h"
36989
36990
36991 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36992 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36993
36994
36995 static void scsi_host_cls_release(struct device *dev)
36996 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36997 * subtract one because we increment first then return, but we need to
36998 * know what the next host number was before increment
36999 */
37000 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
37001 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
37002 shost->dma_channel = 0xff;
37003
37004 /* These three are default values which can be overridden */
37005 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
37006 index f9823f2..7bc3e81 100644
37007 --- a/drivers/scsi/hpsa.c
37008 +++ b/drivers/scsi/hpsa.c
37009 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
37010 unsigned long flags;
37011
37012 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37013 - return h->access.command_completed(h, q);
37014 + return h->access->command_completed(h, q);
37015
37016 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
37017 a = rq->head[rq->current_entry];
37018 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
37019 while (!list_empty(&h->reqQ)) {
37020 c = list_entry(h->reqQ.next, struct CommandList, list);
37021 /* can't do anything if fifo is full */
37022 - if ((h->access.fifo_full(h))) {
37023 + if ((h->access->fifo_full(h))) {
37024 dev_warn(&h->pdev->dev, "fifo full\n");
37025 break;
37026 }
37027 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
37028
37029 /* Tell the controller execute command */
37030 spin_unlock_irqrestore(&h->lock, flags);
37031 - h->access.submit_command(h, c);
37032 + h->access->submit_command(h, c);
37033 spin_lock_irqsave(&h->lock, flags);
37034 }
37035 spin_unlock_irqrestore(&h->lock, flags);
37036 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
37037
37038 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
37039 {
37040 - return h->access.command_completed(h, q);
37041 + return h->access->command_completed(h, q);
37042 }
37043
37044 static inline bool interrupt_pending(struct ctlr_info *h)
37045 {
37046 - return h->access.intr_pending(h);
37047 + return h->access->intr_pending(h);
37048 }
37049
37050 static inline long interrupt_not_for_us(struct ctlr_info *h)
37051 {
37052 - return (h->access.intr_pending(h) == 0) ||
37053 + return (h->access->intr_pending(h) == 0) ||
37054 (h->interrupts_enabled == 0);
37055 }
37056
37057 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
37058 if (prod_index < 0)
37059 return -ENODEV;
37060 h->product_name = products[prod_index].product_name;
37061 - h->access = *(products[prod_index].access);
37062 + h->access = products[prod_index].access;
37063
37064 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
37065 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
37066 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
37067
37068 assert_spin_locked(&lockup_detector_lock);
37069 remove_ctlr_from_lockup_detector_list(h);
37070 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37071 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37072 spin_lock_irqsave(&h->lock, flags);
37073 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
37074 spin_unlock_irqrestore(&h->lock, flags);
37075 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
37076 }
37077
37078 /* make sure the board interrupts are off */
37079 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37080 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37081
37082 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
37083 goto clean2;
37084 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
37085 * fake ones to scoop up any residual completions.
37086 */
37087 spin_lock_irqsave(&h->lock, flags);
37088 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37089 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37090 spin_unlock_irqrestore(&h->lock, flags);
37091 free_irqs(h);
37092 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
37093 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
37094 dev_info(&h->pdev->dev, "Board READY.\n");
37095 dev_info(&h->pdev->dev,
37096 "Waiting for stale completions to drain.\n");
37097 - h->access.set_intr_mask(h, HPSA_INTR_ON);
37098 + h->access->set_intr_mask(h, HPSA_INTR_ON);
37099 msleep(10000);
37100 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37101 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37102
37103 rc = controller_reset_failed(h->cfgtable);
37104 if (rc)
37105 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
37106 }
37107
37108 /* Turn the interrupts on so we can service requests */
37109 - h->access.set_intr_mask(h, HPSA_INTR_ON);
37110 + h->access->set_intr_mask(h, HPSA_INTR_ON);
37111
37112 hpsa_hba_inquiry(h);
37113 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
37114 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
37115 * To write all data in the battery backed cache to disks
37116 */
37117 hpsa_flush_cache(h);
37118 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37119 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37120 hpsa_free_irqs_and_disable_msix(h);
37121 }
37122
37123 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
37124 return;
37125 }
37126 /* Change the access methods to the performant access methods */
37127 - h->access = SA5_performant_access;
37128 + h->access = &SA5_performant_access;
37129 h->transMethod = CFGTBL_Trans_Performant;
37130 }
37131
37132 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
37133 index 9816479..c5d4e97 100644
37134 --- a/drivers/scsi/hpsa.h
37135 +++ b/drivers/scsi/hpsa.h
37136 @@ -79,7 +79,7 @@ struct ctlr_info {
37137 unsigned int msix_vector;
37138 unsigned int msi_vector;
37139 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
37140 - struct access_method access;
37141 + struct access_method *access;
37142
37143 /* queue and queue Info */
37144 struct list_head reqQ;
37145 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
37146 index f2df059..a3a9930 100644
37147 --- a/drivers/scsi/ips.h
37148 +++ b/drivers/scsi/ips.h
37149 @@ -1027,7 +1027,7 @@ typedef struct {
37150 int (*intr)(struct ips_ha *);
37151 void (*enableint)(struct ips_ha *);
37152 uint32_t (*statupd)(struct ips_ha *);
37153 -} ips_hw_func_t;
37154 +} __no_const ips_hw_func_t;
37155
37156 typedef struct ips_ha {
37157 uint8_t ha_id[IPS_MAX_CHANNELS+1];
37158 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
37159 index c772d8d..35c362c 100644
37160 --- a/drivers/scsi/libfc/fc_exch.c
37161 +++ b/drivers/scsi/libfc/fc_exch.c
37162 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
37163 u16 pool_max_index;
37164
37165 struct {
37166 - atomic_t no_free_exch;
37167 - atomic_t no_free_exch_xid;
37168 - atomic_t xid_not_found;
37169 - atomic_t xid_busy;
37170 - atomic_t seq_not_found;
37171 - atomic_t non_bls_resp;
37172 + atomic_unchecked_t no_free_exch;
37173 + atomic_unchecked_t no_free_exch_xid;
37174 + atomic_unchecked_t xid_not_found;
37175 + atomic_unchecked_t xid_busy;
37176 + atomic_unchecked_t seq_not_found;
37177 + atomic_unchecked_t non_bls_resp;
37178 } stats;
37179 };
37180
37181 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
37182 /* allocate memory for exchange */
37183 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37184 if (!ep) {
37185 - atomic_inc(&mp->stats.no_free_exch);
37186 + atomic_inc_unchecked(&mp->stats.no_free_exch);
37187 goto out;
37188 }
37189 memset(ep, 0, sizeof(*ep));
37190 @@ -786,7 +786,7 @@ out:
37191 return ep;
37192 err:
37193 spin_unlock_bh(&pool->lock);
37194 - atomic_inc(&mp->stats.no_free_exch_xid);
37195 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37196 mempool_free(ep, mp->ep_pool);
37197 return NULL;
37198 }
37199 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37200 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37201 ep = fc_exch_find(mp, xid);
37202 if (!ep) {
37203 - atomic_inc(&mp->stats.xid_not_found);
37204 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37205 reject = FC_RJT_OX_ID;
37206 goto out;
37207 }
37208 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37209 ep = fc_exch_find(mp, xid);
37210 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37211 if (ep) {
37212 - atomic_inc(&mp->stats.xid_busy);
37213 + atomic_inc_unchecked(&mp->stats.xid_busy);
37214 reject = FC_RJT_RX_ID;
37215 goto rel;
37216 }
37217 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37218 }
37219 xid = ep->xid; /* get our XID */
37220 } else if (!ep) {
37221 - atomic_inc(&mp->stats.xid_not_found);
37222 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37223 reject = FC_RJT_RX_ID; /* XID not found */
37224 goto out;
37225 }
37226 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37227 } else {
37228 sp = &ep->seq;
37229 if (sp->id != fh->fh_seq_id) {
37230 - atomic_inc(&mp->stats.seq_not_found);
37231 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37232 if (f_ctl & FC_FC_END_SEQ) {
37233 /*
37234 * Update sequence_id based on incoming last
37235 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37236
37237 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37238 if (!ep) {
37239 - atomic_inc(&mp->stats.xid_not_found);
37240 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37241 goto out;
37242 }
37243 if (ep->esb_stat & ESB_ST_COMPLETE) {
37244 - atomic_inc(&mp->stats.xid_not_found);
37245 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37246 goto rel;
37247 }
37248 if (ep->rxid == FC_XID_UNKNOWN)
37249 ep->rxid = ntohs(fh->fh_rx_id);
37250 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37251 - atomic_inc(&mp->stats.xid_not_found);
37252 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37253 goto rel;
37254 }
37255 if (ep->did != ntoh24(fh->fh_s_id) &&
37256 ep->did != FC_FID_FLOGI) {
37257 - atomic_inc(&mp->stats.xid_not_found);
37258 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37259 goto rel;
37260 }
37261 sof = fr_sof(fp);
37262 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37263 sp->ssb_stat |= SSB_ST_RESP;
37264 sp->id = fh->fh_seq_id;
37265 } else if (sp->id != fh->fh_seq_id) {
37266 - atomic_inc(&mp->stats.seq_not_found);
37267 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37268 goto rel;
37269 }
37270
37271 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37272 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37273
37274 if (!sp)
37275 - atomic_inc(&mp->stats.xid_not_found);
37276 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37277 else
37278 - atomic_inc(&mp->stats.non_bls_resp);
37279 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37280
37281 fc_frame_free(fp);
37282 }
37283 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
37284
37285 list_for_each_entry(ema, &lport->ema_list, ema_list) {
37286 mp = ema->mp;
37287 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
37288 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
37289 st->fc_no_free_exch_xid +=
37290 - atomic_read(&mp->stats.no_free_exch_xid);
37291 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
37292 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
37293 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
37294 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
37295 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
37296 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
37297 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
37298 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
37299 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
37300 }
37301 }
37302 EXPORT_SYMBOL(fc_exch_update_stats);
37303 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37304 index a59fcdc..abe55f3 100644
37305 --- a/drivers/scsi/libsas/sas_ata.c
37306 +++ b/drivers/scsi/libsas/sas_ata.c
37307 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
37308 .postreset = ata_std_postreset,
37309 .error_handler = ata_std_error_handler,
37310 .post_internal_cmd = sas_ata_post_internal,
37311 - .qc_defer = ata_std_qc_defer,
37312 + .qc_defer = ata_std_qc_defer,
37313 .qc_prep = ata_noop_qc_prep,
37314 .qc_issue = sas_ata_qc_issue,
37315 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37316 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37317 index a65c05a..a39e402 100644
37318 --- a/drivers/scsi/lpfc/lpfc.h
37319 +++ b/drivers/scsi/lpfc/lpfc.h
37320 @@ -420,7 +420,7 @@ struct lpfc_vport {
37321 struct dentry *debug_nodelist;
37322 struct dentry *vport_debugfs_root;
37323 struct lpfc_debugfs_trc *disc_trc;
37324 - atomic_t disc_trc_cnt;
37325 + atomic_unchecked_t disc_trc_cnt;
37326 #endif
37327 uint8_t stat_data_enabled;
37328 uint8_t stat_data_blocked;
37329 @@ -834,8 +834,8 @@ struct lpfc_hba {
37330 struct timer_list fabric_block_timer;
37331 unsigned long bit_flags;
37332 #define FABRIC_COMANDS_BLOCKED 0
37333 - atomic_t num_rsrc_err;
37334 - atomic_t num_cmd_success;
37335 + atomic_unchecked_t num_rsrc_err;
37336 + atomic_unchecked_t num_cmd_success;
37337 unsigned long last_rsrc_error_time;
37338 unsigned long last_ramp_down_time;
37339 unsigned long last_ramp_up_time;
37340 @@ -871,7 +871,7 @@ struct lpfc_hba {
37341
37342 struct dentry *debug_slow_ring_trc;
37343 struct lpfc_debugfs_trc *slow_ring_trc;
37344 - atomic_t slow_ring_trc_cnt;
37345 + atomic_unchecked_t slow_ring_trc_cnt;
37346 /* iDiag debugfs sub-directory */
37347 struct dentry *idiag_root;
37348 struct dentry *idiag_pci_cfg;
37349 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37350 index 3217d63..c417981 100644
37351 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37352 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37353 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37354
37355 #include <linux/debugfs.h>
37356
37357 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37358 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37359 static unsigned long lpfc_debugfs_start_time = 0L;
37360
37361 /* iDiag */
37362 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37363 lpfc_debugfs_enable = 0;
37364
37365 len = 0;
37366 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37367 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37368 (lpfc_debugfs_max_disc_trc - 1);
37369 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37370 dtp = vport->disc_trc + i;
37371 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37372 lpfc_debugfs_enable = 0;
37373
37374 len = 0;
37375 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37376 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37377 (lpfc_debugfs_max_slow_ring_trc - 1);
37378 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37379 dtp = phba->slow_ring_trc + i;
37380 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37381 !vport || !vport->disc_trc)
37382 return;
37383
37384 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37385 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37386 (lpfc_debugfs_max_disc_trc - 1);
37387 dtp = vport->disc_trc + index;
37388 dtp->fmt = fmt;
37389 dtp->data1 = data1;
37390 dtp->data2 = data2;
37391 dtp->data3 = data3;
37392 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37393 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37394 dtp->jif = jiffies;
37395 #endif
37396 return;
37397 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37398 !phba || !phba->slow_ring_trc)
37399 return;
37400
37401 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37402 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37403 (lpfc_debugfs_max_slow_ring_trc - 1);
37404 dtp = phba->slow_ring_trc + index;
37405 dtp->fmt = fmt;
37406 dtp->data1 = data1;
37407 dtp->data2 = data2;
37408 dtp->data3 = data3;
37409 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37410 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37411 dtp->jif = jiffies;
37412 #endif
37413 return;
37414 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37415 "slow_ring buffer\n");
37416 goto debug_failed;
37417 }
37418 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37419 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37420 memset(phba->slow_ring_trc, 0,
37421 (sizeof(struct lpfc_debugfs_trc) *
37422 lpfc_debugfs_max_slow_ring_trc));
37423 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37424 "buffer\n");
37425 goto debug_failed;
37426 }
37427 - atomic_set(&vport->disc_trc_cnt, 0);
37428 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37429
37430 snprintf(name, sizeof(name), "discovery_trace");
37431 vport->debug_disc_trc =
37432 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37433 index 45c1520..35ba744 100644
37434 --- a/drivers/scsi/lpfc/lpfc_init.c
37435 +++ b/drivers/scsi/lpfc/lpfc_init.c
37436 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37437 "misc_register returned with status %d", error);
37438
37439 if (lpfc_enable_npiv) {
37440 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37441 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37442 + pax_open_kernel();
37443 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37444 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37445 + pax_close_kernel();
37446 }
37447 lpfc_transport_template =
37448 fc_attach_transport(&lpfc_transport_functions);
37449 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37450 index 925975d..0f1fc07 100644
37451 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37452 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37453 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37454 uint32_t evt_posted;
37455
37456 spin_lock_irqsave(&phba->hbalock, flags);
37457 - atomic_inc(&phba->num_rsrc_err);
37458 + atomic_inc_unchecked(&phba->num_rsrc_err);
37459 phba->last_rsrc_error_time = jiffies;
37460
37461 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37462 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37463 unsigned long flags;
37464 struct lpfc_hba *phba = vport->phba;
37465 uint32_t evt_posted;
37466 - atomic_inc(&phba->num_cmd_success);
37467 + atomic_inc_unchecked(&phba->num_cmd_success);
37468
37469 if (vport->cfg_lun_queue_depth <= queue_depth)
37470 return;
37471 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37472 unsigned long num_rsrc_err, num_cmd_success;
37473 int i;
37474
37475 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37476 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37477 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37478 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37479
37480 /*
37481 * The error and success command counters are global per
37482 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37483 }
37484 }
37485 lpfc_destroy_vport_work_array(phba, vports);
37486 - atomic_set(&phba->num_rsrc_err, 0);
37487 - atomic_set(&phba->num_cmd_success, 0);
37488 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37489 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37490 }
37491
37492 /**
37493 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37494 }
37495 }
37496 lpfc_destroy_vport_work_array(phba, vports);
37497 - atomic_set(&phba->num_rsrc_err, 0);
37498 - atomic_set(&phba->num_cmd_success, 0);
37499 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37500 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37501 }
37502
37503 /**
37504 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37505 index ea8a0b4..812a124 100644
37506 --- a/drivers/scsi/pmcraid.c
37507 +++ b/drivers/scsi/pmcraid.c
37508 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37509 res->scsi_dev = scsi_dev;
37510 scsi_dev->hostdata = res;
37511 res->change_detected = 0;
37512 - atomic_set(&res->read_failures, 0);
37513 - atomic_set(&res->write_failures, 0);
37514 + atomic_set_unchecked(&res->read_failures, 0);
37515 + atomic_set_unchecked(&res->write_failures, 0);
37516 rc = 0;
37517 }
37518 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37519 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37520
37521 /* If this was a SCSI read/write command keep count of errors */
37522 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37523 - atomic_inc(&res->read_failures);
37524 + atomic_inc_unchecked(&res->read_failures);
37525 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37526 - atomic_inc(&res->write_failures);
37527 + atomic_inc_unchecked(&res->write_failures);
37528
37529 if (!RES_IS_GSCSI(res->cfg_entry) &&
37530 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37531 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37532 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37533 * hrrq_id assigned here in queuecommand
37534 */
37535 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37536 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37537 pinstance->num_hrrq;
37538 cmd->cmd_done = pmcraid_io_done;
37539
37540 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37541 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37542 * hrrq_id assigned here in queuecommand
37543 */
37544 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37545 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37546 pinstance->num_hrrq;
37547
37548 if (request_size) {
37549 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37550
37551 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37552 /* add resources only after host is added into system */
37553 - if (!atomic_read(&pinstance->expose_resources))
37554 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37555 return;
37556
37557 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37558 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37559 init_waitqueue_head(&pinstance->reset_wait_q);
37560
37561 atomic_set(&pinstance->outstanding_cmds, 0);
37562 - atomic_set(&pinstance->last_message_id, 0);
37563 - atomic_set(&pinstance->expose_resources, 0);
37564 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37565 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37566
37567 INIT_LIST_HEAD(&pinstance->free_res_q);
37568 INIT_LIST_HEAD(&pinstance->used_res_q);
37569 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37570 /* Schedule worker thread to handle CCN and take care of adding and
37571 * removing devices to OS
37572 */
37573 - atomic_set(&pinstance->expose_resources, 1);
37574 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37575 schedule_work(&pinstance->worker_q);
37576 return rc;
37577
37578 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37579 index e1d150f..6c6df44 100644
37580 --- a/drivers/scsi/pmcraid.h
37581 +++ b/drivers/scsi/pmcraid.h
37582 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37583 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37584
37585 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37586 - atomic_t last_message_id;
37587 + atomic_unchecked_t last_message_id;
37588
37589 /* configuration table */
37590 struct pmcraid_config_table *cfg_table;
37591 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37592 atomic_t outstanding_cmds;
37593
37594 /* should add/delete resources to mid-layer now ?*/
37595 - atomic_t expose_resources;
37596 + atomic_unchecked_t expose_resources;
37597
37598
37599
37600 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37601 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37602 };
37603 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37604 - atomic_t read_failures; /* count of failed READ commands */
37605 - atomic_t write_failures; /* count of failed WRITE commands */
37606 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37607 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37608
37609 /* To indicate add/delete/modify during CCN */
37610 u8 change_detected;
37611 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37612 index 5ab9530..2dd80f7 100644
37613 --- a/drivers/scsi/qla2xxx/qla_attr.c
37614 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37615 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37616 return 0;
37617 }
37618
37619 -struct fc_function_template qla2xxx_transport_functions = {
37620 +fc_function_template_no_const qla2xxx_transport_functions = {
37621
37622 .show_host_node_name = 1,
37623 .show_host_port_name = 1,
37624 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37625 .bsg_timeout = qla24xx_bsg_timeout,
37626 };
37627
37628 -struct fc_function_template qla2xxx_transport_vport_functions = {
37629 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37630
37631 .show_host_node_name = 1,
37632 .show_host_port_name = 1,
37633 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37634 index 39007f5..7fafc64 100644
37635 --- a/drivers/scsi/qla2xxx/qla_def.h
37636 +++ b/drivers/scsi/qla2xxx/qla_def.h
37637 @@ -2284,7 +2284,7 @@ struct isp_operations {
37638 int (*start_scsi) (srb_t *);
37639 int (*abort_isp) (struct scsi_qla_host *);
37640 int (*iospace_config)(struct qla_hw_data*);
37641 -};
37642 +} __no_const;
37643
37644 /* MSI-X Support *************************************************************/
37645
37646 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37647 index 9eacd2d..d79629c 100644
37648 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37649 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37650 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37651 struct device_attribute;
37652 extern struct device_attribute *qla2x00_host_attrs[];
37653 struct fc_function_template;
37654 -extern struct fc_function_template qla2xxx_transport_functions;
37655 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37656 +extern fc_function_template_no_const qla2xxx_transport_functions;
37657 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37658 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37659 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37660 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37661 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37662 index 7fdba7f..1b4b2c2 100644
37663 --- a/drivers/scsi/qla4xxx/ql4_def.h
37664 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37665 @@ -268,7 +268,7 @@ struct ddb_entry {
37666 * (4000 only) */
37667 atomic_t relogin_timer; /* Max Time to wait for
37668 * relogin to complete */
37669 - atomic_t relogin_retry_count; /* Num of times relogin has been
37670 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37671 * retried */
37672 uint32_t default_time2wait; /* Default Min time between
37673 * relogins (+aens) */
37674 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37675 index 9da4266..377b3b6 100644
37676 --- a/drivers/scsi/qla4xxx/ql4_os.c
37677 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37678 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37679 */
37680 if (!iscsi_is_session_online(cls_sess)) {
37681 /* Reset retry relogin timer */
37682 - atomic_inc(&ddb_entry->relogin_retry_count);
37683 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37684 DEBUG2(ql4_printk(KERN_INFO, ha,
37685 "%s: index[%d] relogin timed out-retrying"
37686 " relogin (%d), retry (%d)\n", __func__,
37687 ddb_entry->fw_ddb_index,
37688 - atomic_read(&ddb_entry->relogin_retry_count),
37689 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37690 ddb_entry->default_time2wait + 4));
37691 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37692 atomic_set(&ddb_entry->retry_relogin_timer,
37693 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37694
37695 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37696 atomic_set(&ddb_entry->relogin_timer, 0);
37697 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37698 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37699 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37700 ddb_entry->default_relogin_timeout =
37701 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37702 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37703 index 2936b44..546ecdb 100644
37704 --- a/drivers/scsi/scsi.c
37705 +++ b/drivers/scsi/scsi.c
37706 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37707 unsigned long timeout;
37708 int rtn = 0;
37709
37710 - atomic_inc(&cmd->device->iorequest_cnt);
37711 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37712
37713 /* check if the device is still usable */
37714 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37715 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37716 index faa790f..7e351ddd 100644
37717 --- a/drivers/scsi/scsi_lib.c
37718 +++ b/drivers/scsi/scsi_lib.c
37719 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37720 shost = sdev->host;
37721 scsi_init_cmd_errh(cmd);
37722 cmd->result = DID_NO_CONNECT << 16;
37723 - atomic_inc(&cmd->device->iorequest_cnt);
37724 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37725
37726 /*
37727 * SCSI request completion path will do scsi_device_unbusy(),
37728 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37729
37730 INIT_LIST_HEAD(&cmd->eh_entry);
37731
37732 - atomic_inc(&cmd->device->iodone_cnt);
37733 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37734 if (cmd->result)
37735 - atomic_inc(&cmd->device->ioerr_cnt);
37736 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37737
37738 disposition = scsi_decide_disposition(cmd);
37739 if (disposition != SUCCESS &&
37740 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37741 index ce5224c..8c6d071 100644
37742 --- a/drivers/scsi/scsi_sysfs.c
37743 +++ b/drivers/scsi/scsi_sysfs.c
37744 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37745 char *buf) \
37746 { \
37747 struct scsi_device *sdev = to_scsi_device(dev); \
37748 - unsigned long long count = atomic_read(&sdev->field); \
37749 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37750 return snprintf(buf, 20, "0x%llx\n", count); \
37751 } \
37752 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37753 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37754 index 84a1fdf..693b0d6 100644
37755 --- a/drivers/scsi/scsi_tgt_lib.c
37756 +++ b/drivers/scsi/scsi_tgt_lib.c
37757 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37758 int err;
37759
37760 dprintk("%lx %u\n", uaddr, len);
37761 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37762 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37763 if (err) {
37764 /*
37765 * TODO: need to fixup sg_tablesize, max_segment_size,
37766 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37767 index e894ca7..de9d7660 100644
37768 --- a/drivers/scsi/scsi_transport_fc.c
37769 +++ b/drivers/scsi/scsi_transport_fc.c
37770 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37771 * Netlink Infrastructure
37772 */
37773
37774 -static atomic_t fc_event_seq;
37775 +static atomic_unchecked_t fc_event_seq;
37776
37777 /**
37778 * fc_get_event_number - Obtain the next sequential FC event number
37779 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37780 u32
37781 fc_get_event_number(void)
37782 {
37783 - return atomic_add_return(1, &fc_event_seq);
37784 + return atomic_add_return_unchecked(1, &fc_event_seq);
37785 }
37786 EXPORT_SYMBOL(fc_get_event_number);
37787
37788 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37789 {
37790 int error;
37791
37792 - atomic_set(&fc_event_seq, 0);
37793 + atomic_set_unchecked(&fc_event_seq, 0);
37794
37795 error = transport_class_register(&fc_host_class);
37796 if (error)
37797 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37798 char *cp;
37799
37800 *val = simple_strtoul(buf, &cp, 0);
37801 - if ((*cp && (*cp != '\n')) || (*val < 0))
37802 + if (*cp && (*cp != '\n'))
37803 return -EINVAL;
37804 /*
37805 * Check for overflow; dev_loss_tmo is u32
37806 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37807 index fa1dfaa..4bb620c 100644
37808 --- a/drivers/scsi/scsi_transport_iscsi.c
37809 +++ b/drivers/scsi/scsi_transport_iscsi.c
37810 @@ -79,7 +79,7 @@ struct iscsi_internal {
37811 struct transport_container session_cont;
37812 };
37813
37814 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37815 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37816 static struct workqueue_struct *iscsi_eh_timer_workq;
37817
37818 static DEFINE_IDA(iscsi_sess_ida);
37819 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37820 int err;
37821
37822 ihost = shost->shost_data;
37823 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37824 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37825
37826 if (target_id == ISCSI_MAX_TARGET) {
37827 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37828 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37829 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37830 ISCSI_TRANSPORT_VERSION);
37831
37832 - atomic_set(&iscsi_session_nr, 0);
37833 + atomic_set_unchecked(&iscsi_session_nr, 0);
37834
37835 err = class_register(&iscsi_transport_class);
37836 if (err)
37837 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37838 index 21a045e..ec89e03 100644
37839 --- a/drivers/scsi/scsi_transport_srp.c
37840 +++ b/drivers/scsi/scsi_transport_srp.c
37841 @@ -33,7 +33,7 @@
37842 #include "scsi_transport_srp_internal.h"
37843
37844 struct srp_host_attrs {
37845 - atomic_t next_port_id;
37846 + atomic_unchecked_t next_port_id;
37847 };
37848 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37849
37850 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37851 struct Scsi_Host *shost = dev_to_shost(dev);
37852 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37853
37854 - atomic_set(&srp_host->next_port_id, 0);
37855 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37856 return 0;
37857 }
37858
37859 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37860 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37861 rport->roles = ids->roles;
37862
37863 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37864 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37865 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37866
37867 transport_setup_device(&rport->dev);
37868 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37869 index 4df73e5..b691c58 100644
37870 --- a/drivers/scsi/sd.c
37871 +++ b/drivers/scsi/sd.c
37872 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37873 sdkp->disk = gd;
37874 sdkp->index = index;
37875 atomic_set(&sdkp->openers, 0);
37876 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37877 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37878
37879 if (!sdp->request_queue->rq_timeout) {
37880 if (sdp->type != TYPE_MOD)
37881 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37882 index 9c5c5f2..8414557 100644
37883 --- a/drivers/scsi/sg.c
37884 +++ b/drivers/scsi/sg.c
37885 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37886 sdp->disk->disk_name,
37887 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37888 NULL,
37889 - (char *)arg);
37890 + (char __user *)arg);
37891 case BLKTRACESTART:
37892 return blk_trace_startstop(sdp->device->request_queue, 1);
37893 case BLKTRACESTOP:
37894 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37895 index 84c2861..ece0a31 100644
37896 --- a/drivers/spi/spi.c
37897 +++ b/drivers/spi/spi.c
37898 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37899 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37900
37901 /* portable code must never pass more than 32 bytes */
37902 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37903 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37904
37905 static u8 *buf;
37906
37907 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37908 index 34afc16..ffe44dd 100644
37909 --- a/drivers/staging/octeon/ethernet-rx.c
37910 +++ b/drivers/staging/octeon/ethernet-rx.c
37911 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37912 /* Increment RX stats for virtual ports */
37913 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37914 #ifdef CONFIG_64BIT
37915 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37916 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37917 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37918 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37919 #else
37920 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37921 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37922 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37923 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37924 #endif
37925 }
37926 netif_receive_skb(skb);
37927 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37928 dev->name);
37929 */
37930 #ifdef CONFIG_64BIT
37931 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37932 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37933 #else
37934 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37935 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37936 #endif
37937 dev_kfree_skb_irq(skb);
37938 }
37939 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37940 index 683bedc..86dba9a 100644
37941 --- a/drivers/staging/octeon/ethernet.c
37942 +++ b/drivers/staging/octeon/ethernet.c
37943 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37944 * since the RX tasklet also increments it.
37945 */
37946 #ifdef CONFIG_64BIT
37947 - atomic64_add(rx_status.dropped_packets,
37948 - (atomic64_t *)&priv->stats.rx_dropped);
37949 + atomic64_add_unchecked(rx_status.dropped_packets,
37950 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37951 #else
37952 - atomic_add(rx_status.dropped_packets,
37953 - (atomic_t *)&priv->stats.rx_dropped);
37954 + atomic_add_unchecked(rx_status.dropped_packets,
37955 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37956 #endif
37957 }
37958
37959 diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c
37960 index 4beab94..44149ee 100644
37961 --- a/drivers/staging/omapdrm/omap_drv.c
37962 +++ b/drivers/staging/omapdrm/omap_drv.c
37963 @@ -761,7 +761,6 @@ static struct drm_driver omap_drm_driver = {
37964 .irq_postinstall = dev_irq_postinstall,
37965 .irq_uninstall = dev_irq_uninstall,
37966 .irq_handler = dev_irq_handler,
37967 - .reclaim_buffers = drm_core_reclaim_buffers,
37968 #ifdef CONFIG_DEBUG_FS
37969 .debugfs_init = omap_debugfs_init,
37970 .debugfs_cleanup = omap_debugfs_cleanup,
37971 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37972 index dc23395..cf7e9b1 100644
37973 --- a/drivers/staging/rtl8712/rtl871x_io.h
37974 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37975 @@ -108,7 +108,7 @@ struct _io_ops {
37976 u8 *pmem);
37977 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37978 u8 *pmem);
37979 -};
37980 +} __no_const;
37981
37982 struct io_req {
37983 struct list_head list;
37984 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37985 index c7b5e8b..783d6cb 100644
37986 --- a/drivers/staging/sbe-2t3e3/netdev.c
37987 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37988 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37989 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37990
37991 if (rlen)
37992 - if (copy_to_user(data, &resp, rlen))
37993 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37994 return -EFAULT;
37995
37996 return 0;
37997 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37998 index 5d89c0f..9261317 100644
37999 --- a/drivers/staging/usbip/usbip_common.h
38000 +++ b/drivers/staging/usbip/usbip_common.h
38001 @@ -289,7 +289,7 @@ struct usbip_device {
38002 void (*shutdown)(struct usbip_device *);
38003 void (*reset)(struct usbip_device *);
38004 void (*unusable)(struct usbip_device *);
38005 - } eh_ops;
38006 + } __no_const eh_ops;
38007 };
38008
38009 #define kthread_get_run(threadfn, data, namefmt, ...) \
38010 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
38011 index c66b8b3..a4a035b 100644
38012 --- a/drivers/staging/usbip/vhci.h
38013 +++ b/drivers/staging/usbip/vhci.h
38014 @@ -83,7 +83,7 @@ struct vhci_hcd {
38015 unsigned resuming:1;
38016 unsigned long re_timeout;
38017
38018 - atomic_t seqnum;
38019 + atomic_unchecked_t seqnum;
38020
38021 /*
38022 * NOTE:
38023 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
38024 index 12a9a5f..afd8295 100644
38025 --- a/drivers/staging/usbip/vhci_hcd.c
38026 +++ b/drivers/staging/usbip/vhci_hcd.c
38027 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
38028 return;
38029 }
38030
38031 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
38032 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38033 if (priv->seqnum == 0xffff)
38034 dev_info(&urb->dev->dev, "seqnum max\n");
38035
38036 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
38037 return -ENOMEM;
38038 }
38039
38040 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
38041 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38042 if (unlink->seqnum == 0xffff)
38043 pr_info("seqnum max\n");
38044
38045 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
38046 vdev->rhport = rhport;
38047 }
38048
38049 - atomic_set(&vhci->seqnum, 0);
38050 + atomic_set_unchecked(&vhci->seqnum, 0);
38051 spin_lock_init(&vhci->lock);
38052
38053 hcd->power_budget = 0; /* no limit */
38054 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
38055 index f0eaf04..5a82e06 100644
38056 --- a/drivers/staging/usbip/vhci_rx.c
38057 +++ b/drivers/staging/usbip/vhci_rx.c
38058 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
38059 if (!urb) {
38060 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
38061 pr_info("max seqnum %d\n",
38062 - atomic_read(&the_controller->seqnum));
38063 + atomic_read_unchecked(&the_controller->seqnum));
38064 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
38065 return;
38066 }
38067 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
38068 index 6ac6f45..1b208ba 100644
38069 --- a/drivers/staging/vt6655/hostap.c
38070 +++ b/drivers/staging/vt6655/hostap.c
38071 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
38072 *
38073 */
38074
38075 +static net_device_ops_no_const apdev_netdev_ops;
38076 +
38077 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38078 {
38079 PSDevice apdev_priv;
38080 struct net_device *dev = pDevice->dev;
38081 int ret;
38082 - const struct net_device_ops apdev_netdev_ops = {
38083 - .ndo_start_xmit = pDevice->tx_80211,
38084 - };
38085
38086 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38087
38088 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38089 *apdev_priv = *pDevice;
38090 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38091
38092 + /* only half broken now */
38093 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38094 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38095
38096 pDevice->apdev->type = ARPHRD_IEEE80211;
38097 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
38098 index 682002a..35ed5cf 100644
38099 --- a/drivers/staging/vt6656/hostap.c
38100 +++ b/drivers/staging/vt6656/hostap.c
38101 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
38102 *
38103 */
38104
38105 +static net_device_ops_no_const apdev_netdev_ops;
38106 +
38107 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38108 {
38109 PSDevice apdev_priv;
38110 struct net_device *dev = pDevice->dev;
38111 int ret;
38112 - const struct net_device_ops apdev_netdev_ops = {
38113 - .ndo_start_xmit = pDevice->tx_80211,
38114 - };
38115
38116 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38117
38118 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38119 *apdev_priv = *pDevice;
38120 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38121
38122 + /* only half broken now */
38123 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38124 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38125
38126 pDevice->apdev->type = ARPHRD_IEEE80211;
38127 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
38128 index 7843dfd..3db105f 100644
38129 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
38130 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
38131 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
38132
38133 struct usbctlx_completor {
38134 int (*complete) (struct usbctlx_completor *);
38135 -};
38136 +} __no_const;
38137
38138 static int
38139 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
38140 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
38141 index eaa9021..43f023b 100644
38142 --- a/drivers/staging/zcache/tmem.c
38143 +++ b/drivers/staging/zcache/tmem.c
38144 @@ -39,7 +39,7 @@
38145 * A tmem host implementation must use this function to register callbacks
38146 * for memory allocation.
38147 */
38148 -static struct tmem_hostops tmem_hostops;
38149 +static tmem_hostops_no_const tmem_hostops;
38150
38151 static void tmem_objnode_tree_init(void);
38152
38153 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
38154 * A tmem host implementation must use this function to register
38155 * callbacks for a page-accessible memory (PAM) implementation
38156 */
38157 -static struct tmem_pamops tmem_pamops;
38158 +static tmem_pamops_no_const tmem_pamops;
38159
38160 void tmem_register_pamops(struct tmem_pamops *m)
38161 {
38162 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
38163 index 0d4aa82..f7832d4 100644
38164 --- a/drivers/staging/zcache/tmem.h
38165 +++ b/drivers/staging/zcache/tmem.h
38166 @@ -180,6 +180,7 @@ struct tmem_pamops {
38167 void (*new_obj)(struct tmem_obj *);
38168 int (*replace_in_obj)(void *, struct tmem_obj *);
38169 };
38170 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
38171 extern void tmem_register_pamops(struct tmem_pamops *m);
38172
38173 /* memory allocation methods provided by the host implementation */
38174 @@ -189,6 +190,7 @@ struct tmem_hostops {
38175 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
38176 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
38177 };
38178 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
38179 extern void tmem_register_hostops(struct tmem_hostops *m);
38180
38181 /* core tmem accessor functions */
38182 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
38183 index c87ef74..6d32e54 100644
38184 --- a/drivers/target/target_core_transport.c
38185 +++ b/drivers/target/target_core_transport.c
38186 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
38187 spin_lock_init(&dev->se_port_lock);
38188 spin_lock_init(&dev->se_tmr_lock);
38189 spin_lock_init(&dev->qf_cmd_lock);
38190 - atomic_set(&dev->dev_ordered_id, 0);
38191 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
38192
38193 se_dev_set_default_attribs(dev, dev_limits);
38194
38195 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
38196 * Used to determine when ORDERED commands should go from
38197 * Dormant to Active status.
38198 */
38199 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
38200 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
38201 smp_mb__after_atomic_inc();
38202 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
38203 cmd->se_ordered_id, cmd->sam_task_attr,
38204 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
38205 index e61cabd..7617d26 100644
38206 --- a/drivers/tty/cyclades.c
38207 +++ b/drivers/tty/cyclades.c
38208 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
38209 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
38210 info->port.count);
38211 #endif
38212 - info->port.count++;
38213 + atomic_inc(&info->port.count);
38214 #ifdef CY_DEBUG_COUNT
38215 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
38216 - current->pid, info->port.count);
38217 + current->pid, atomic_read(&info->port.count));
38218 #endif
38219
38220 /*
38221 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
38222 for (j = 0; j < cy_card[i].nports; j++) {
38223 info = &cy_card[i].ports[j];
38224
38225 - if (info->port.count) {
38226 + if (atomic_read(&info->port.count)) {
38227 /* XXX is the ldisc num worth this? */
38228 struct tty_struct *tty;
38229 struct tty_ldisc *ld;
38230 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
38231 index 2d691eb..be02ebd 100644
38232 --- a/drivers/tty/hvc/hvc_console.c
38233 +++ b/drivers/tty/hvc/hvc_console.c
38234 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
38235
38236 spin_lock_irqsave(&hp->port.lock, flags);
38237 /* Check and then increment for fast path open. */
38238 - if (hp->port.count++ > 0) {
38239 + if (atomic_inc_return(&hp->port.count) > 1) {
38240 spin_unlock_irqrestore(&hp->port.lock, flags);
38241 hvc_kick();
38242 return 0;
38243 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38244
38245 spin_lock_irqsave(&hp->port.lock, flags);
38246
38247 - if (--hp->port.count == 0) {
38248 + if (atomic_dec_return(&hp->port.count) == 0) {
38249 spin_unlock_irqrestore(&hp->port.lock, flags);
38250 /* We are done with the tty pointer now. */
38251 tty_port_tty_set(&hp->port, NULL);
38252 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38253 */
38254 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
38255 } else {
38256 - if (hp->port.count < 0)
38257 + if (atomic_read(&hp->port.count) < 0)
38258 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38259 - hp->vtermno, hp->port.count);
38260 + hp->vtermno, atomic_read(&hp->port.count));
38261 spin_unlock_irqrestore(&hp->port.lock, flags);
38262 }
38263
38264 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
38265 * open->hangup case this can be called after the final close so prevent
38266 * that from happening for now.
38267 */
38268 - if (hp->port.count <= 0) {
38269 + if (atomic_read(&hp->port.count) <= 0) {
38270 spin_unlock_irqrestore(&hp->port.lock, flags);
38271 return;
38272 }
38273
38274 - temp_open_count = hp->port.count;
38275 - hp->port.count = 0;
38276 + temp_open_count = atomic_read(&hp->port.count);
38277 + atomic_set(&hp->port.count, 0);
38278 spin_unlock_irqrestore(&hp->port.lock, flags);
38279 tty_port_tty_set(&hp->port, NULL);
38280
38281 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38282 return -EPIPE;
38283
38284 /* FIXME what's this (unprotected) check for? */
38285 - if (hp->port.count <= 0)
38286 + if (atomic_read(&hp->port.count) <= 0)
38287 return -EIO;
38288
38289 spin_lock_irqsave(&hp->lock, flags);
38290 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38291 index d56788c..12d8f85 100644
38292 --- a/drivers/tty/hvc/hvcs.c
38293 +++ b/drivers/tty/hvc/hvcs.c
38294 @@ -83,6 +83,7 @@
38295 #include <asm/hvcserver.h>
38296 #include <asm/uaccess.h>
38297 #include <asm/vio.h>
38298 +#include <asm/local.h>
38299
38300 /*
38301 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38302 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38303
38304 spin_lock_irqsave(&hvcsd->lock, flags);
38305
38306 - if (hvcsd->port.count > 0) {
38307 + if (atomic_read(&hvcsd->port.count) > 0) {
38308 spin_unlock_irqrestore(&hvcsd->lock, flags);
38309 printk(KERN_INFO "HVCS: vterm state unchanged. "
38310 "The hvcs device node is still in use.\n");
38311 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38312 if ((retval = hvcs_partner_connect(hvcsd)))
38313 goto error_release;
38314
38315 - hvcsd->port.count = 1;
38316 + atomic_set(&hvcsd->port.count, 1);
38317 hvcsd->port.tty = tty;
38318 tty->driver_data = hvcsd;
38319
38320 @@ -1168,7 +1169,7 @@ fast_open:
38321
38322 spin_lock_irqsave(&hvcsd->lock, flags);
38323 tty_port_get(&hvcsd->port);
38324 - hvcsd->port.count++;
38325 + atomic_inc(&hvcsd->port.count);
38326 hvcsd->todo_mask |= HVCS_SCHED_READ;
38327 spin_unlock_irqrestore(&hvcsd->lock, flags);
38328
38329 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38330 hvcsd = tty->driver_data;
38331
38332 spin_lock_irqsave(&hvcsd->lock, flags);
38333 - if (--hvcsd->port.count == 0) {
38334 + if (atomic_dec_and_test(&hvcsd->port.count)) {
38335
38336 vio_disable_interrupts(hvcsd->vdev);
38337
38338 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38339 free_irq(irq, hvcsd);
38340 tty_port_put(&hvcsd->port);
38341 return;
38342 - } else if (hvcsd->port.count < 0) {
38343 + } else if (atomic_read(&hvcsd->port.count) < 0) {
38344 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38345 " is missmanaged.\n",
38346 - hvcsd->vdev->unit_address, hvcsd->port.count);
38347 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38348 }
38349
38350 spin_unlock_irqrestore(&hvcsd->lock, flags);
38351 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38352
38353 spin_lock_irqsave(&hvcsd->lock, flags);
38354 /* Preserve this so that we know how many kref refs to put */
38355 - temp_open_count = hvcsd->port.count;
38356 + temp_open_count = atomic_read(&hvcsd->port.count);
38357
38358 /*
38359 * Don't kref put inside the spinlock because the destruction
38360 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38361 tty->driver_data = NULL;
38362 hvcsd->port.tty = NULL;
38363
38364 - hvcsd->port.count = 0;
38365 + atomic_set(&hvcsd->port.count, 0);
38366
38367 /* This will drop any buffered data on the floor which is OK in a hangup
38368 * scenario. */
38369 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38370 * the middle of a write operation? This is a crummy place to do this
38371 * but we want to keep it all in the spinlock.
38372 */
38373 - if (hvcsd->port.count <= 0) {
38374 + if (atomic_read(&hvcsd->port.count) <= 0) {
38375 spin_unlock_irqrestore(&hvcsd->lock, flags);
38376 return -ENODEV;
38377 }
38378 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38379 {
38380 struct hvcs_struct *hvcsd = tty->driver_data;
38381
38382 - if (!hvcsd || hvcsd->port.count <= 0)
38383 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38384 return 0;
38385
38386 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38387 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38388 index f8b5fa0..4ba9f89 100644
38389 --- a/drivers/tty/ipwireless/tty.c
38390 +++ b/drivers/tty/ipwireless/tty.c
38391 @@ -29,6 +29,7 @@
38392 #include <linux/tty_driver.h>
38393 #include <linux/tty_flip.h>
38394 #include <linux/uaccess.h>
38395 +#include <asm/local.h>
38396
38397 #include "tty.h"
38398 #include "network.h"
38399 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38400 mutex_unlock(&tty->ipw_tty_mutex);
38401 return -ENODEV;
38402 }
38403 - if (tty->port.count == 0)
38404 + if (atomic_read(&tty->port.count) == 0)
38405 tty->tx_bytes_queued = 0;
38406
38407 - tty->port.count++;
38408 + atomic_inc(&tty->port.count);
38409
38410 tty->port.tty = linux_tty;
38411 linux_tty->driver_data = tty;
38412 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38413
38414 static void do_ipw_close(struct ipw_tty *tty)
38415 {
38416 - tty->port.count--;
38417 -
38418 - if (tty->port.count == 0) {
38419 + if (atomic_dec_return(&tty->port.count) == 0) {
38420 struct tty_struct *linux_tty = tty->port.tty;
38421
38422 if (linux_tty != NULL) {
38423 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38424 return;
38425
38426 mutex_lock(&tty->ipw_tty_mutex);
38427 - if (tty->port.count == 0) {
38428 + if (atomic_read(&tty->port.count) == 0) {
38429 mutex_unlock(&tty->ipw_tty_mutex);
38430 return;
38431 }
38432 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38433 return;
38434 }
38435
38436 - if (!tty->port.count) {
38437 + if (!atomic_read(&tty->port.count)) {
38438 mutex_unlock(&tty->ipw_tty_mutex);
38439 return;
38440 }
38441 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38442 return -ENODEV;
38443
38444 mutex_lock(&tty->ipw_tty_mutex);
38445 - if (!tty->port.count) {
38446 + if (!atomic_read(&tty->port.count)) {
38447 mutex_unlock(&tty->ipw_tty_mutex);
38448 return -EINVAL;
38449 }
38450 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38451 if (!tty)
38452 return -ENODEV;
38453
38454 - if (!tty->port.count)
38455 + if (!atomic_read(&tty->port.count))
38456 return -EINVAL;
38457
38458 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38459 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38460 if (!tty)
38461 return 0;
38462
38463 - if (!tty->port.count)
38464 + if (!atomic_read(&tty->port.count))
38465 return 0;
38466
38467 return tty->tx_bytes_queued;
38468 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38469 if (!tty)
38470 return -ENODEV;
38471
38472 - if (!tty->port.count)
38473 + if (!atomic_read(&tty->port.count))
38474 return -EINVAL;
38475
38476 return get_control_lines(tty);
38477 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38478 if (!tty)
38479 return -ENODEV;
38480
38481 - if (!tty->port.count)
38482 + if (!atomic_read(&tty->port.count))
38483 return -EINVAL;
38484
38485 return set_control_lines(tty, set, clear);
38486 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38487 if (!tty)
38488 return -ENODEV;
38489
38490 - if (!tty->port.count)
38491 + if (!atomic_read(&tty->port.count))
38492 return -EINVAL;
38493
38494 /* FIXME: Exactly how is the tty object locked here .. */
38495 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38496 * are gone */
38497 mutex_lock(&ttyj->ipw_tty_mutex);
38498 }
38499 - while (ttyj->port.count)
38500 + while (atomic_read(&ttyj->port.count))
38501 do_ipw_close(ttyj);
38502 ipwireless_disassociate_network_ttys(network,
38503 ttyj->channel_idx);
38504 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38505 index 324467d..504cc25 100644
38506 --- a/drivers/tty/moxa.c
38507 +++ b/drivers/tty/moxa.c
38508 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38509 }
38510
38511 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38512 - ch->port.count++;
38513 + atomic_inc(&ch->port.count);
38514 tty->driver_data = ch;
38515 tty_port_tty_set(&ch->port, tty);
38516 mutex_lock(&ch->port.mutex);
38517 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38518 index 90dff82..08119c3 100644
38519 --- a/drivers/tty/n_gsm.c
38520 +++ b/drivers/tty/n_gsm.c
38521 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38522 kref_init(&dlci->ref);
38523 mutex_init(&dlci->mutex);
38524 dlci->fifo = &dlci->_fifo;
38525 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38526 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38527 kfree(dlci);
38528 return NULL;
38529 }
38530 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38531 if (dlci == NULL)
38532 return -ENOMEM;
38533 port = &dlci->port;
38534 - port->count++;
38535 + atomic_inc(&port->count);
38536 tty->driver_data = dlci;
38537 dlci_get(dlci);
38538 dlci_get(dlci->gsm->dlci[0]);
38539 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38540 index 26f0d0e..b7c4273 100644
38541 --- a/drivers/tty/n_tty.c
38542 +++ b/drivers/tty/n_tty.c
38543 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38544 {
38545 *ops = tty_ldisc_N_TTY;
38546 ops->owner = NULL;
38547 - ops->refcount = ops->flags = 0;
38548 + atomic_set(&ops->refcount, 0);
38549 + ops->flags = 0;
38550 }
38551 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38552 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38553 index 5505ffc..7affff9 100644
38554 --- a/drivers/tty/pty.c
38555 +++ b/drivers/tty/pty.c
38556 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38557 panic("Couldn't register Unix98 pts driver");
38558
38559 /* Now create the /dev/ptmx special device */
38560 + pax_open_kernel();
38561 tty_default_fops(&ptmx_fops);
38562 - ptmx_fops.open = ptmx_open;
38563 + *(void **)&ptmx_fops.open = ptmx_open;
38564 + pax_close_kernel();
38565
38566 cdev_init(&ptmx_cdev, &ptmx_fops);
38567 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38568 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38569 index 777d5f9..56d67ca 100644
38570 --- a/drivers/tty/rocket.c
38571 +++ b/drivers/tty/rocket.c
38572 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38573 tty->driver_data = info;
38574 tty_port_tty_set(port, tty);
38575
38576 - if (port->count++ == 0) {
38577 + if (atomic_inc_return(&port->count) == 1) {
38578 atomic_inc(&rp_num_ports_open);
38579
38580 #ifdef ROCKET_DEBUG_OPEN
38581 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38582 #endif
38583 }
38584 #ifdef ROCKET_DEBUG_OPEN
38585 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38586 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38587 #endif
38588
38589 /*
38590 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38591 spin_unlock_irqrestore(&info->port.lock, flags);
38592 return;
38593 }
38594 - if (info->port.count)
38595 + if (atomic_read(&info->port.count))
38596 atomic_dec(&rp_num_ports_open);
38597 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38598 spin_unlock_irqrestore(&info->port.lock, flags);
38599 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38600 index 2b42a01..32a2ed3 100644
38601 --- a/drivers/tty/serial/kgdboc.c
38602 +++ b/drivers/tty/serial/kgdboc.c
38603 @@ -24,8 +24,9 @@
38604 #define MAX_CONFIG_LEN 40
38605
38606 static struct kgdb_io kgdboc_io_ops;
38607 +static struct kgdb_io kgdboc_io_ops_console;
38608
38609 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38610 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38611 static int configured = -1;
38612
38613 static char config[MAX_CONFIG_LEN];
38614 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38615 kgdboc_unregister_kbd();
38616 if (configured == 1)
38617 kgdb_unregister_io_module(&kgdboc_io_ops);
38618 + else if (configured == 2)
38619 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38620 }
38621
38622 static int configure_kgdboc(void)
38623 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38624 int err;
38625 char *cptr = config;
38626 struct console *cons;
38627 + int is_console = 0;
38628
38629 err = kgdboc_option_setup(config);
38630 if (err || !strlen(config) || isspace(config[0]))
38631 goto noconfig;
38632
38633 err = -ENODEV;
38634 - kgdboc_io_ops.is_console = 0;
38635 kgdb_tty_driver = NULL;
38636
38637 kgdboc_use_kms = 0;
38638 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38639 int idx;
38640 if (cons->device && cons->device(cons, &idx) == p &&
38641 idx == tty_line) {
38642 - kgdboc_io_ops.is_console = 1;
38643 + is_console = 1;
38644 break;
38645 }
38646 cons = cons->next;
38647 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38648 kgdb_tty_line = tty_line;
38649
38650 do_register:
38651 - err = kgdb_register_io_module(&kgdboc_io_ops);
38652 + if (is_console) {
38653 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38654 + configured = 2;
38655 + } else {
38656 + err = kgdb_register_io_module(&kgdboc_io_ops);
38657 + configured = 1;
38658 + }
38659 if (err)
38660 goto noconfig;
38661
38662 - configured = 1;
38663 -
38664 return 0;
38665
38666 noconfig:
38667 @@ -213,7 +220,7 @@ noconfig:
38668 static int __init init_kgdboc(void)
38669 {
38670 /* Already configured? */
38671 - if (configured == 1)
38672 + if (configured >= 1)
38673 return 0;
38674
38675 return configure_kgdboc();
38676 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38677 if (config[len - 1] == '\n')
38678 config[len - 1] = '\0';
38679
38680 - if (configured == 1)
38681 + if (configured >= 1)
38682 cleanup_kgdboc();
38683
38684 /* Go and configure with the new params. */
38685 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38686 .post_exception = kgdboc_post_exp_handler,
38687 };
38688
38689 +static struct kgdb_io kgdboc_io_ops_console = {
38690 + .name = "kgdboc",
38691 + .read_char = kgdboc_get_char,
38692 + .write_char = kgdboc_put_char,
38693 + .pre_exception = kgdboc_pre_exp_handler,
38694 + .post_exception = kgdboc_post_exp_handler,
38695 + .is_console = 1
38696 +};
38697 +
38698 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38699 /* This is only available if kgdboc is a built in for early debugging */
38700 static int __init kgdboc_early_init(char *opt)
38701 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38702 index a21dc8e..fe43e9e 100644
38703 --- a/drivers/tty/serial/serial_core.c
38704 +++ b/drivers/tty/serial/serial_core.c
38705 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38706 uart_flush_buffer(tty);
38707 uart_shutdown(tty, state);
38708 spin_lock_irqsave(&port->lock, flags);
38709 - port->count = 0;
38710 + atomic_set(&port->count, 0);
38711 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38712 spin_unlock_irqrestore(&port->lock, flags);
38713 tty_port_tty_set(port, NULL);
38714 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38715 goto end;
38716 }
38717
38718 - port->count++;
38719 + atomic_inc(&port->count);
38720 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38721 retval = -ENXIO;
38722 goto err_dec_count;
38723 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38724 /*
38725 * Make sure the device is in D0 state.
38726 */
38727 - if (port->count == 1)
38728 + if (atomic_read(&port->count) == 1)
38729 uart_change_pm(state, 0);
38730
38731 /*
38732 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38733 end:
38734 return retval;
38735 err_dec_count:
38736 - port->count--;
38737 + atomic_inc(&port->count);
38738 mutex_unlock(&port->mutex);
38739 goto end;
38740 }
38741 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38742 index 593d40a..bdc61f3 100644
38743 --- a/drivers/tty/synclink.c
38744 +++ b/drivers/tty/synclink.c
38745 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38746
38747 if (debug_level >= DEBUG_LEVEL_INFO)
38748 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38749 - __FILE__,__LINE__, info->device_name, info->port.count);
38750 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38751
38752 if (tty_port_close_start(&info->port, tty, filp) == 0)
38753 goto cleanup;
38754 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38755 cleanup:
38756 if (debug_level >= DEBUG_LEVEL_INFO)
38757 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38758 - tty->driver->name, info->port.count);
38759 + tty->driver->name, atomic_read(&info->port.count));
38760
38761 } /* end of mgsl_close() */
38762
38763 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38764
38765 mgsl_flush_buffer(tty);
38766 shutdown(info);
38767 -
38768 - info->port.count = 0;
38769 +
38770 + atomic_set(&info->port.count, 0);
38771 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38772 info->port.tty = NULL;
38773
38774 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38775
38776 if (debug_level >= DEBUG_LEVEL_INFO)
38777 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38778 - __FILE__,__LINE__, tty->driver->name, port->count );
38779 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38780
38781 spin_lock_irqsave(&info->irq_spinlock, flags);
38782 if (!tty_hung_up_p(filp)) {
38783 extra_count = true;
38784 - port->count--;
38785 + atomic_dec(&port->count);
38786 }
38787 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38788 port->blocked_open++;
38789 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38790
38791 if (debug_level >= DEBUG_LEVEL_INFO)
38792 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38793 - __FILE__,__LINE__, tty->driver->name, port->count );
38794 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38795
38796 tty_unlock();
38797 schedule();
38798 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38799
38800 /* FIXME: Racy on hangup during close wait */
38801 if (extra_count)
38802 - port->count++;
38803 + atomic_inc(&port->count);
38804 port->blocked_open--;
38805
38806 if (debug_level >= DEBUG_LEVEL_INFO)
38807 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38808 - __FILE__,__LINE__, tty->driver->name, port->count );
38809 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38810
38811 if (!retval)
38812 port->flags |= ASYNC_NORMAL_ACTIVE;
38813 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38814
38815 if (debug_level >= DEBUG_LEVEL_INFO)
38816 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38817 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38818 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38819
38820 /* If port is closing, signal caller to try again */
38821 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38822 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38823 spin_unlock_irqrestore(&info->netlock, flags);
38824 goto cleanup;
38825 }
38826 - info->port.count++;
38827 + atomic_inc(&info->port.count);
38828 spin_unlock_irqrestore(&info->netlock, flags);
38829
38830 - if (info->port.count == 1) {
38831 + if (atomic_read(&info->port.count) == 1) {
38832 /* 1st open on this device, init hardware */
38833 retval = startup(info);
38834 if (retval < 0)
38835 @@ -3444,8 +3444,8 @@ cleanup:
38836 if (retval) {
38837 if (tty->count == 1)
38838 info->port.tty = NULL; /* tty layer will release tty struct */
38839 - if(info->port.count)
38840 - info->port.count--;
38841 + if (atomic_read(&info->port.count))
38842 + atomic_dec(&info->port.count);
38843 }
38844
38845 return retval;
38846 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38847 unsigned short new_crctype;
38848
38849 /* return error if TTY interface open */
38850 - if (info->port.count)
38851 + if (atomic_read(&info->port.count))
38852 return -EBUSY;
38853
38854 switch (encoding)
38855 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38856
38857 /* arbitrate between network and tty opens */
38858 spin_lock_irqsave(&info->netlock, flags);
38859 - if (info->port.count != 0 || info->netcount != 0) {
38860 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38861 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38862 spin_unlock_irqrestore(&info->netlock, flags);
38863 return -EBUSY;
38864 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38865 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38866
38867 /* return error if TTY interface open */
38868 - if (info->port.count)
38869 + if (atomic_read(&info->port.count))
38870 return -EBUSY;
38871
38872 if (cmd != SIOCWANDEV)
38873 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38874 index aa1debf..9297a16 100644
38875 --- a/drivers/tty/synclink_gt.c
38876 +++ b/drivers/tty/synclink_gt.c
38877 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38878 tty->driver_data = info;
38879 info->port.tty = tty;
38880
38881 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38882 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38883
38884 /* If port is closing, signal caller to try again */
38885 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38886 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38887 mutex_unlock(&info->port.mutex);
38888 goto cleanup;
38889 }
38890 - info->port.count++;
38891 + atomic_inc(&info->port.count);
38892 spin_unlock_irqrestore(&info->netlock, flags);
38893
38894 - if (info->port.count == 1) {
38895 + if (atomic_read(&info->port.count) == 1) {
38896 /* 1st open on this device, init hardware */
38897 retval = startup(info);
38898 if (retval < 0) {
38899 @@ -716,8 +716,8 @@ cleanup:
38900 if (retval) {
38901 if (tty->count == 1)
38902 info->port.tty = NULL; /* tty layer will release tty struct */
38903 - if(info->port.count)
38904 - info->port.count--;
38905 + if(atomic_read(&info->port.count))
38906 + atomic_dec(&info->port.count);
38907 }
38908
38909 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38910 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38911
38912 if (sanity_check(info, tty->name, "close"))
38913 return;
38914 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38915 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38916
38917 if (tty_port_close_start(&info->port, tty, filp) == 0)
38918 goto cleanup;
38919 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38920 tty_port_close_end(&info->port, tty);
38921 info->port.tty = NULL;
38922 cleanup:
38923 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38924 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38925 }
38926
38927 static void hangup(struct tty_struct *tty)
38928 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38929 shutdown(info);
38930
38931 spin_lock_irqsave(&info->port.lock, flags);
38932 - info->port.count = 0;
38933 + atomic_set(&info->port.count, 0);
38934 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38935 info->port.tty = NULL;
38936 spin_unlock_irqrestore(&info->port.lock, flags);
38937 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38938 unsigned short new_crctype;
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 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38946 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38947
38948 /* arbitrate between network and tty opens */
38949 spin_lock_irqsave(&info->netlock, flags);
38950 - if (info->port.count != 0 || info->netcount != 0) {
38951 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38952 DBGINFO(("%s hdlc_open busy\n", dev->name));
38953 spin_unlock_irqrestore(&info->netlock, flags);
38954 return -EBUSY;
38955 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38956 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38957
38958 /* return error if TTY interface open */
38959 - if (info->port.count)
38960 + if (atomic_read(&info->port.count))
38961 return -EBUSY;
38962
38963 if (cmd != SIOCWANDEV)
38964 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38965 if (port == NULL)
38966 continue;
38967 spin_lock(&port->lock);
38968 - if ((port->port.count || port->netcount) &&
38969 + if ((atomic_read(&port->port.count) || port->netcount) &&
38970 port->pending_bh && !port->bh_running &&
38971 !port->bh_requested) {
38972 DBGISR(("%s bh queued\n", port->device_name));
38973 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38974 spin_lock_irqsave(&info->lock, flags);
38975 if (!tty_hung_up_p(filp)) {
38976 extra_count = true;
38977 - port->count--;
38978 + atomic_dec(&port->count);
38979 }
38980 spin_unlock_irqrestore(&info->lock, flags);
38981 port->blocked_open++;
38982 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38983 remove_wait_queue(&port->open_wait, &wait);
38984
38985 if (extra_count)
38986 - port->count++;
38987 + atomic_inc(&port->count);
38988 port->blocked_open--;
38989
38990 if (!retval)
38991 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38992 index a3dddc1..8905ab2 100644
38993 --- a/drivers/tty/synclinkmp.c
38994 +++ b/drivers/tty/synclinkmp.c
38995 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38996
38997 if (debug_level >= DEBUG_LEVEL_INFO)
38998 printk("%s(%d):%s open(), old ref count = %d\n",
38999 - __FILE__,__LINE__,tty->driver->name, info->port.count);
39000 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
39001
39002 /* If port is closing, signal caller to try again */
39003 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
39004 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
39005 spin_unlock_irqrestore(&info->netlock, flags);
39006 goto cleanup;
39007 }
39008 - info->port.count++;
39009 + atomic_inc(&info->port.count);
39010 spin_unlock_irqrestore(&info->netlock, flags);
39011
39012 - if (info->port.count == 1) {
39013 + if (atomic_read(&info->port.count) == 1) {
39014 /* 1st open on this device, init hardware */
39015 retval = startup(info);
39016 if (retval < 0)
39017 @@ -788,8 +788,8 @@ cleanup:
39018 if (retval) {
39019 if (tty->count == 1)
39020 info->port.tty = NULL; /* tty layer will release tty struct */
39021 - if(info->port.count)
39022 - info->port.count--;
39023 + if(atomic_read(&info->port.count))
39024 + atomic_dec(&info->port.count);
39025 }
39026
39027 return retval;
39028 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39029
39030 if (debug_level >= DEBUG_LEVEL_INFO)
39031 printk("%s(%d):%s close() entry, count=%d\n",
39032 - __FILE__,__LINE__, info->device_name, info->port.count);
39033 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
39034
39035 if (tty_port_close_start(&info->port, tty, filp) == 0)
39036 goto cleanup;
39037 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39038 cleanup:
39039 if (debug_level >= DEBUG_LEVEL_INFO)
39040 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
39041 - tty->driver->name, info->port.count);
39042 + tty->driver->name, atomic_read(&info->port.count));
39043 }
39044
39045 /* Called by tty_hangup() when a hangup is signaled.
39046 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
39047 shutdown(info);
39048
39049 spin_lock_irqsave(&info->port.lock, flags);
39050 - info->port.count = 0;
39051 + atomic_set(&info->port.count, 0);
39052 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39053 info->port.tty = NULL;
39054 spin_unlock_irqrestore(&info->port.lock, flags);
39055 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39056 unsigned short new_crctype;
39057
39058 /* return error if TTY interface open */
39059 - if (info->port.count)
39060 + if (atomic_read(&info->port.count))
39061 return -EBUSY;
39062
39063 switch (encoding)
39064 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
39065
39066 /* arbitrate between network and tty opens */
39067 spin_lock_irqsave(&info->netlock, flags);
39068 - if (info->port.count != 0 || info->netcount != 0) {
39069 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39070 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39071 spin_unlock_irqrestore(&info->netlock, flags);
39072 return -EBUSY;
39073 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39074 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
39075
39076 /* return error if TTY interface open */
39077 - if (info->port.count)
39078 + if (atomic_read(&info->port.count))
39079 return -EBUSY;
39080
39081 if (cmd != SIOCWANDEV)
39082 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
39083 * do not request bottom half processing if the
39084 * device is not open in a normal mode.
39085 */
39086 - if ( port && (port->port.count || port->netcount) &&
39087 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
39088 port->pending_bh && !port->bh_running &&
39089 !port->bh_requested ) {
39090 if ( debug_level >= DEBUG_LEVEL_ISR )
39091 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39092
39093 if (debug_level >= DEBUG_LEVEL_INFO)
39094 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
39095 - __FILE__,__LINE__, tty->driver->name, port->count );
39096 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39097
39098 spin_lock_irqsave(&info->lock, flags);
39099 if (!tty_hung_up_p(filp)) {
39100 extra_count = true;
39101 - port->count--;
39102 + atomic_dec(&port->count);
39103 }
39104 spin_unlock_irqrestore(&info->lock, flags);
39105 port->blocked_open++;
39106 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39107
39108 if (debug_level >= DEBUG_LEVEL_INFO)
39109 printk("%s(%d):%s block_til_ready() count=%d\n",
39110 - __FILE__,__LINE__, tty->driver->name, port->count );
39111 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39112
39113 tty_unlock();
39114 schedule();
39115 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39116 remove_wait_queue(&port->open_wait, &wait);
39117
39118 if (extra_count)
39119 - port->count++;
39120 + atomic_inc(&port->count);
39121 port->blocked_open--;
39122
39123 if (debug_level >= DEBUG_LEVEL_INFO)
39124 printk("%s(%d):%s block_til_ready() after, count=%d\n",
39125 - __FILE__,__LINE__, tty->driver->name, port->count );
39126 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39127
39128 if (!retval)
39129 port->flags |= ASYNC_NORMAL_ACTIVE;
39130 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
39131 index 05728894..b9d44c6 100644
39132 --- a/drivers/tty/sysrq.c
39133 +++ b/drivers/tty/sysrq.c
39134 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
39135 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
39136 size_t count, loff_t *ppos)
39137 {
39138 - if (count) {
39139 + if (count && capable(CAP_SYS_ADMIN)) {
39140 char c;
39141
39142 if (get_user(c, buf))
39143 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
39144 index b425c79..08a3f06 100644
39145 --- a/drivers/tty/tty_io.c
39146 +++ b/drivers/tty/tty_io.c
39147 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
39148
39149 void tty_default_fops(struct file_operations *fops)
39150 {
39151 - *fops = tty_fops;
39152 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
39153 }
39154
39155 /*
39156 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
39157 index 6f99c99..8947bc4 100644
39158 --- a/drivers/tty/tty_ldisc.c
39159 +++ b/drivers/tty/tty_ldisc.c
39160 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
39161 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
39162 struct tty_ldisc_ops *ldo = ld->ops;
39163
39164 - ldo->refcount--;
39165 + atomic_dec(&ldo->refcount);
39166 module_put(ldo->owner);
39167 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39168
39169 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
39170 spin_lock_irqsave(&tty_ldisc_lock, flags);
39171 tty_ldiscs[disc] = new_ldisc;
39172 new_ldisc->num = disc;
39173 - new_ldisc->refcount = 0;
39174 + atomic_set(&new_ldisc->refcount, 0);
39175 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39176
39177 return ret;
39178 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
39179 return -EINVAL;
39180
39181 spin_lock_irqsave(&tty_ldisc_lock, flags);
39182 - if (tty_ldiscs[disc]->refcount)
39183 + if (atomic_read(&tty_ldiscs[disc]->refcount))
39184 ret = -EBUSY;
39185 else
39186 tty_ldiscs[disc] = NULL;
39187 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
39188 if (ldops) {
39189 ret = ERR_PTR(-EAGAIN);
39190 if (try_module_get(ldops->owner)) {
39191 - ldops->refcount++;
39192 + atomic_inc(&ldops->refcount);
39193 ret = ldops;
39194 }
39195 }
39196 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
39197 unsigned long flags;
39198
39199 spin_lock_irqsave(&tty_ldisc_lock, flags);
39200 - ldops->refcount--;
39201 + atomic_dec(&ldops->refcount);
39202 module_put(ldops->owner);
39203 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39204 }
39205 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
39206 index bf6e238..d401c04 100644
39207 --- a/drivers/tty/tty_port.c
39208 +++ b/drivers/tty/tty_port.c
39209 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
39210 unsigned long flags;
39211
39212 spin_lock_irqsave(&port->lock, flags);
39213 - port->count = 0;
39214 + atomic_set(&port->count, 0);
39215 port->flags &= ~ASYNC_NORMAL_ACTIVE;
39216 if (port->tty) {
39217 set_bit(TTY_IO_ERROR, &port->tty->flags);
39218 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39219 /* The port lock protects the port counts */
39220 spin_lock_irqsave(&port->lock, flags);
39221 if (!tty_hung_up_p(filp))
39222 - port->count--;
39223 + atomic_dec(&port->count);
39224 port->blocked_open++;
39225 spin_unlock_irqrestore(&port->lock, flags);
39226
39227 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39228 we must not mess that up further */
39229 spin_lock_irqsave(&port->lock, flags);
39230 if (!tty_hung_up_p(filp))
39231 - port->count++;
39232 + atomic_inc(&port->count);
39233 port->blocked_open--;
39234 if (retval == 0)
39235 port->flags |= ASYNC_NORMAL_ACTIVE;
39236 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
39237 return 0;
39238 }
39239
39240 - if (tty->count == 1 && port->count != 1) {
39241 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
39242 printk(KERN_WARNING
39243 "tty_port_close_start: tty->count = 1 port count = %d.\n",
39244 - port->count);
39245 - port->count = 1;
39246 + atomic_read(&port->count));
39247 + atomic_set(&port->count, 1);
39248 }
39249 - if (--port->count < 0) {
39250 + if (atomic_dec_return(&port->count) < 0) {
39251 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
39252 - port->count);
39253 - port->count = 0;
39254 + atomic_read(&port->count));
39255 + atomic_set(&port->count, 0);
39256 }
39257
39258 - if (port->count) {
39259 + if (atomic_read(&port->count)) {
39260 spin_unlock_irqrestore(&port->lock, flags);
39261 if (port->ops->drop)
39262 port->ops->drop(port);
39263 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39264 {
39265 spin_lock_irq(&port->lock);
39266 if (!tty_hung_up_p(filp))
39267 - ++port->count;
39268 + atomic_inc(&port->count);
39269 spin_unlock_irq(&port->lock);
39270 tty_port_tty_set(port, tty);
39271
39272 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39273 index 770a854..e5d3db3 100644
39274 --- a/drivers/tty/vt/keyboard.c
39275 +++ b/drivers/tty/vt/keyboard.c
39276 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39277 kbd->kbdmode == VC_OFF) &&
39278 value != KVAL(K_SAK))
39279 return; /* SAK is allowed even in raw mode */
39280 +
39281 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39282 + {
39283 + void *func = fn_handler[value];
39284 + if (func == fn_show_state || func == fn_show_ptregs ||
39285 + func == fn_show_mem)
39286 + return;
39287 + }
39288 +#endif
39289 +
39290 fn_handler[value](vc);
39291 }
39292
39293 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39294 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39295 return -EFAULT;
39296
39297 - if (!capable(CAP_SYS_TTY_CONFIG))
39298 - perm = 0;
39299 -
39300 switch (cmd) {
39301 case KDGKBENT:
39302 /* Ensure another thread doesn't free it under us */
39303 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39304 spin_unlock_irqrestore(&kbd_event_lock, flags);
39305 return put_user(val, &user_kbe->kb_value);
39306 case KDSKBENT:
39307 + if (!capable(CAP_SYS_TTY_CONFIG))
39308 + perm = 0;
39309 +
39310 if (!perm)
39311 return -EPERM;
39312 if (!i && v == K_NOSUCHMAP) {
39313 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39314 int i, j, k;
39315 int ret;
39316
39317 - if (!capable(CAP_SYS_TTY_CONFIG))
39318 - perm = 0;
39319 -
39320 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39321 if (!kbs) {
39322 ret = -ENOMEM;
39323 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39324 kfree(kbs);
39325 return ((p && *p) ? -EOVERFLOW : 0);
39326 case KDSKBSENT:
39327 + if (!capable(CAP_SYS_TTY_CONFIG))
39328 + perm = 0;
39329 +
39330 if (!perm) {
39331 ret = -EPERM;
39332 goto reterr;
39333 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39334 index a783d53..cb30d94 100644
39335 --- a/drivers/uio/uio.c
39336 +++ b/drivers/uio/uio.c
39337 @@ -25,6 +25,7 @@
39338 #include <linux/kobject.h>
39339 #include <linux/cdev.h>
39340 #include <linux/uio_driver.h>
39341 +#include <asm/local.h>
39342
39343 #define UIO_MAX_DEVICES (1U << MINORBITS)
39344
39345 @@ -32,10 +33,10 @@ struct uio_device {
39346 struct module *owner;
39347 struct device *dev;
39348 int minor;
39349 - atomic_t event;
39350 + atomic_unchecked_t event;
39351 struct fasync_struct *async_queue;
39352 wait_queue_head_t wait;
39353 - int vma_count;
39354 + local_t vma_count;
39355 struct uio_info *info;
39356 struct kobject *map_dir;
39357 struct kobject *portio_dir;
39358 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39359 struct device_attribute *attr, char *buf)
39360 {
39361 struct uio_device *idev = dev_get_drvdata(dev);
39362 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39363 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39364 }
39365
39366 static struct device_attribute uio_class_attributes[] = {
39367 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39368 {
39369 struct uio_device *idev = info->uio_dev;
39370
39371 - atomic_inc(&idev->event);
39372 + atomic_inc_unchecked(&idev->event);
39373 wake_up_interruptible(&idev->wait);
39374 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39375 }
39376 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39377 }
39378
39379 listener->dev = idev;
39380 - listener->event_count = atomic_read(&idev->event);
39381 + listener->event_count = atomic_read_unchecked(&idev->event);
39382 filep->private_data = listener;
39383
39384 if (idev->info->open) {
39385 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39386 return -EIO;
39387
39388 poll_wait(filep, &idev->wait, wait);
39389 - if (listener->event_count != atomic_read(&idev->event))
39390 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39391 return POLLIN | POLLRDNORM;
39392 return 0;
39393 }
39394 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39395 do {
39396 set_current_state(TASK_INTERRUPTIBLE);
39397
39398 - event_count = atomic_read(&idev->event);
39399 + event_count = atomic_read_unchecked(&idev->event);
39400 if (event_count != listener->event_count) {
39401 if (copy_to_user(buf, &event_count, count))
39402 retval = -EFAULT;
39403 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39404 static void uio_vma_open(struct vm_area_struct *vma)
39405 {
39406 struct uio_device *idev = vma->vm_private_data;
39407 - idev->vma_count++;
39408 + local_inc(&idev->vma_count);
39409 }
39410
39411 static void uio_vma_close(struct vm_area_struct *vma)
39412 {
39413 struct uio_device *idev = vma->vm_private_data;
39414 - idev->vma_count--;
39415 + local_dec(&idev->vma_count);
39416 }
39417
39418 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39419 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39420 idev->owner = owner;
39421 idev->info = info;
39422 init_waitqueue_head(&idev->wait);
39423 - atomic_set(&idev->event, 0);
39424 + atomic_set_unchecked(&idev->event, 0);
39425
39426 ret = uio_get_minor(idev);
39427 if (ret)
39428 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39429 index b7eb86a..36d28af 100644
39430 --- a/drivers/usb/atm/cxacru.c
39431 +++ b/drivers/usb/atm/cxacru.c
39432 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39433 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39434 if (ret < 2)
39435 return -EINVAL;
39436 - if (index < 0 || index > 0x7f)
39437 + if (index > 0x7f)
39438 return -EINVAL;
39439 pos += tmp;
39440
39441 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39442 index ee62b35..b663594 100644
39443 --- a/drivers/usb/atm/usbatm.c
39444 +++ b/drivers/usb/atm/usbatm.c
39445 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39446 if (printk_ratelimit())
39447 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39448 __func__, vpi, vci);
39449 - atomic_inc(&vcc->stats->rx_err);
39450 + atomic_inc_unchecked(&vcc->stats->rx_err);
39451 return;
39452 }
39453
39454 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39455 if (length > ATM_MAX_AAL5_PDU) {
39456 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39457 __func__, length, vcc);
39458 - atomic_inc(&vcc->stats->rx_err);
39459 + atomic_inc_unchecked(&vcc->stats->rx_err);
39460 goto out;
39461 }
39462
39463 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39464 if (sarb->len < pdu_length) {
39465 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39466 __func__, pdu_length, sarb->len, vcc);
39467 - atomic_inc(&vcc->stats->rx_err);
39468 + atomic_inc_unchecked(&vcc->stats->rx_err);
39469 goto out;
39470 }
39471
39472 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39473 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39474 __func__, vcc);
39475 - atomic_inc(&vcc->stats->rx_err);
39476 + atomic_inc_unchecked(&vcc->stats->rx_err);
39477 goto out;
39478 }
39479
39480 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39481 if (printk_ratelimit())
39482 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39483 __func__, length);
39484 - atomic_inc(&vcc->stats->rx_drop);
39485 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39486 goto out;
39487 }
39488
39489 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39490
39491 vcc->push(vcc, skb);
39492
39493 - atomic_inc(&vcc->stats->rx);
39494 + atomic_inc_unchecked(&vcc->stats->rx);
39495 out:
39496 skb_trim(sarb, 0);
39497 }
39498 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39499 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39500
39501 usbatm_pop(vcc, skb);
39502 - atomic_inc(&vcc->stats->tx);
39503 + atomic_inc_unchecked(&vcc->stats->tx);
39504
39505 skb = skb_dequeue(&instance->sndqueue);
39506 }
39507 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39508 if (!left--)
39509 return sprintf(page,
39510 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39511 - atomic_read(&atm_dev->stats.aal5.tx),
39512 - atomic_read(&atm_dev->stats.aal5.tx_err),
39513 - atomic_read(&atm_dev->stats.aal5.rx),
39514 - atomic_read(&atm_dev->stats.aal5.rx_err),
39515 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39516 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39517 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39518 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39519 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39520 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39521
39522 if (!left--) {
39523 if (instance->disconnected)
39524 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39525 index 3440812..2a4ef1f 100644
39526 --- a/drivers/usb/core/devices.c
39527 +++ b/drivers/usb/core/devices.c
39528 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39529 * time it gets called.
39530 */
39531 static struct device_connect_event {
39532 - atomic_t count;
39533 + atomic_unchecked_t count;
39534 wait_queue_head_t wait;
39535 } device_event = {
39536 .count = ATOMIC_INIT(1),
39537 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39538
39539 void usbfs_conn_disc_event(void)
39540 {
39541 - atomic_add(2, &device_event.count);
39542 + atomic_add_unchecked(2, &device_event.count);
39543 wake_up(&device_event.wait);
39544 }
39545
39546 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39547
39548 poll_wait(file, &device_event.wait, wait);
39549
39550 - event_count = atomic_read(&device_event.count);
39551 + event_count = atomic_read_unchecked(&device_event.count);
39552 if (file->f_version != event_count) {
39553 file->f_version = event_count;
39554 return POLLIN | POLLRDNORM;
39555 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
39556 index 75ba209..08bf89e 100644
39557 --- a/drivers/usb/core/hcd.c
39558 +++ b/drivers/usb/core/hcd.c
39559 @@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
39560 */
39561 usb_get_urb(urb);
39562 atomic_inc(&urb->use_count);
39563 - atomic_inc(&urb->dev->urbnum);
39564 + atomic_inc_unchecked(&urb->dev->urbnum);
39565 usbmon_urb_submit(&hcd->self, urb);
39566
39567 /* NOTE requirements on root-hub callers (usbfs and the hub
39568 @@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
39569 urb->hcpriv = NULL;
39570 INIT_LIST_HEAD(&urb->urb_list);
39571 atomic_dec(&urb->use_count);
39572 - atomic_dec(&urb->dev->urbnum);
39573 + atomic_dec_unchecked(&urb->dev->urbnum);
39574 if (atomic_read(&urb->reject))
39575 wake_up(&usb_kill_urb_queue);
39576 usb_put_urb(urb);
39577 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
39578 index 682e825..06d4f69 100644
39579 --- a/drivers/usb/core/sysfs.c
39580 +++ b/drivers/usb/core/sysfs.c
39581 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
39582 struct usb_device *udev;
39583
39584 udev = to_usb_device(dev);
39585 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
39586 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
39587 }
39588 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
39589
39590 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
39591 index cd8fb44..17fbe0c 100644
39592 --- a/drivers/usb/core/usb.c
39593 +++ b/drivers/usb/core/usb.c
39594 @@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
39595 set_dev_node(&dev->dev, dev_to_node(bus->controller));
39596 dev->state = USB_STATE_ATTACHED;
39597 dev->lpm_disable_count = 1;
39598 - atomic_set(&dev->urbnum, 0);
39599 + atomic_set_unchecked(&dev->urbnum, 0);
39600
39601 INIT_LIST_HEAD(&dev->ep0.urb_list);
39602 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
39603 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39604 index 89dcf15..481800b 100644
39605 --- a/drivers/usb/early/ehci-dbgp.c
39606 +++ b/drivers/usb/early/ehci-dbgp.c
39607 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39608
39609 #ifdef CONFIG_KGDB
39610 static struct kgdb_io kgdbdbgp_io_ops;
39611 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39612 +static struct kgdb_io kgdbdbgp_io_ops_console;
39613 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39614 #else
39615 #define dbgp_kgdb_mode (0)
39616 #endif
39617 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39618 .write_char = kgdbdbgp_write_char,
39619 };
39620
39621 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39622 + .name = "kgdbdbgp",
39623 + .read_char = kgdbdbgp_read_char,
39624 + .write_char = kgdbdbgp_write_char,
39625 + .is_console = 1
39626 +};
39627 +
39628 static int kgdbdbgp_wait_time;
39629
39630 static int __init kgdbdbgp_parse_config(char *str)
39631 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39632 ptr++;
39633 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39634 }
39635 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39636 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39637 + if (early_dbgp_console.index != -1)
39638 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39639 + else
39640 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39641
39642 return 0;
39643 }
39644 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39645 index da6d479..80ed10b 100644
39646 --- a/drivers/usb/gadget/u_serial.c
39647 +++ b/drivers/usb/gadget/u_serial.c
39648 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39649 spin_lock_irq(&port->port_lock);
39650
39651 /* already open? Great. */
39652 - if (port->port.count) {
39653 + if (atomic_read(&port->port.count)) {
39654 status = 0;
39655 - port->port.count++;
39656 + atomic_inc(&port->port.count);
39657
39658 /* currently opening/closing? wait ... */
39659 } else if (port->openclose) {
39660 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39661 tty->driver_data = port;
39662 port->port.tty = tty;
39663
39664 - port->port.count = 1;
39665 + atomic_set(&port->port.count, 1);
39666 port->openclose = false;
39667
39668 /* if connected, start the I/O stream */
39669 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39670
39671 spin_lock_irq(&port->port_lock);
39672
39673 - if (port->port.count != 1) {
39674 - if (port->port.count == 0)
39675 + if (atomic_read(&port->port.count) != 1) {
39676 + if (atomic_read(&port->port.count) == 0)
39677 WARN_ON(1);
39678 else
39679 - --port->port.count;
39680 + atomic_dec(&port->port.count);
39681 goto exit;
39682 }
39683
39684 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39685 * and sleep if necessary
39686 */
39687 port->openclose = true;
39688 - port->port.count = 0;
39689 + atomic_set(&port->port.count, 0);
39690
39691 gser = port->port_usb;
39692 if (gser && gser->disconnect)
39693 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39694 int cond;
39695
39696 spin_lock_irq(&port->port_lock);
39697 - cond = (port->port.count == 0) && !port->openclose;
39698 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39699 spin_unlock_irq(&port->port_lock);
39700 return cond;
39701 }
39702 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39703 /* if it's already open, start I/O ... and notify the serial
39704 * protocol about open/close status (connect/disconnect).
39705 */
39706 - if (port->port.count) {
39707 + if (atomic_read(&port->port.count)) {
39708 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39709 gs_start_io(port);
39710 if (gser->connect)
39711 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39712
39713 port->port_usb = NULL;
39714 gser->ioport = NULL;
39715 - if (port->port.count > 0 || port->openclose) {
39716 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39717 wake_up_interruptible(&port->drain_wait);
39718 if (port->port.tty)
39719 tty_hangup(port->port.tty);
39720 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39721
39722 /* finally, free any unused/unusable I/O buffers */
39723 spin_lock_irqsave(&port->port_lock, flags);
39724 - if (port->port.count == 0 && !port->openclose)
39725 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39726 gs_buf_free(&port->port_write_buf);
39727 gs_free_requests(gser->out, &port->read_pool, NULL);
39728 gs_free_requests(gser->out, &port->read_queue, NULL);
39729 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39730 index b9cca6d..75c75df 100644
39731 --- a/drivers/usb/serial/console.c
39732 +++ b/drivers/usb/serial/console.c
39733 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39734
39735 info->port = port;
39736
39737 - ++port->port.count;
39738 + atomic_inc(&port->port.count);
39739 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39740 if (serial->type->set_termios) {
39741 /*
39742 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39743 }
39744 /* Now that any required fake tty operations are completed restore
39745 * the tty port count */
39746 - --port->port.count;
39747 + atomic_dec(&port->port.count);
39748 /* The console is special in terms of closing the device so
39749 * indicate this port is now acting as a system console. */
39750 port->port.console = 1;
39751 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39752 free_tty:
39753 kfree(tty);
39754 reset_open_count:
39755 - port->port.count = 0;
39756 + atomic_set(&port->port.count, 0);
39757 usb_autopm_put_interface(serial->interface);
39758 error_get_interface:
39759 usb_serial_put(serial);
39760 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39761 index d6bea3e..60b250e 100644
39762 --- a/drivers/usb/wusbcore/wa-hc.h
39763 +++ b/drivers/usb/wusbcore/wa-hc.h
39764 @@ -192,7 +192,7 @@ struct wahc {
39765 struct list_head xfer_delayed_list;
39766 spinlock_t xfer_list_lock;
39767 struct work_struct xfer_work;
39768 - atomic_t xfer_id_count;
39769 + atomic_unchecked_t xfer_id_count;
39770 };
39771
39772
39773 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39774 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39775 spin_lock_init(&wa->xfer_list_lock);
39776 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39777 - atomic_set(&wa->xfer_id_count, 1);
39778 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39779 }
39780
39781 /**
39782 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39783 index 57c01ab..8a05959 100644
39784 --- a/drivers/usb/wusbcore/wa-xfer.c
39785 +++ b/drivers/usb/wusbcore/wa-xfer.c
39786 @@ -296,7 +296,7 @@ out:
39787 */
39788 static void wa_xfer_id_init(struct wa_xfer *xfer)
39789 {
39790 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39791 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39792 }
39793
39794 /*
39795 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39796 index ef82a0d..78a026b 100644
39797 --- a/drivers/vhost/vhost.c
39798 +++ b/drivers/vhost/vhost.c
39799 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39800 return 0;
39801 }
39802
39803 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39804 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39805 {
39806 struct file *eventfp, *filep = NULL,
39807 *pollstart = NULL, *pollstop = NULL;
39808 @@ -1076,7 +1076,7 @@ static int translate_desc(struct vhost_dev *dev, u64 addr, u32 len,
39809 }
39810 _iov = iov + ret;
39811 size = reg->memory_size - addr + reg->guest_phys_addr;
39812 - _iov->iov_len = min((u64)len, size);
39813 + _iov->iov_len = min((u64)len - s, size);
39814 _iov->iov_base = (void __user *)(unsigned long)
39815 (reg->userspace_addr + addr - reg->guest_phys_addr);
39816 s += size;
39817 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39818 index 747442d..7c0c434 100644
39819 --- a/drivers/video/aty/aty128fb.c
39820 +++ b/drivers/video/aty/aty128fb.c
39821 @@ -149,7 +149,7 @@ enum {
39822 };
39823
39824 /* Must match above enum */
39825 -static const char *r128_family[] __devinitdata = {
39826 +static const char *r128_family[] __devinitconst = {
39827 "AGP",
39828 "PCI",
39829 "PRO AGP",
39830 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39831 index 5c3960d..15cf8fc 100644
39832 --- a/drivers/video/fbcmap.c
39833 +++ b/drivers/video/fbcmap.c
39834 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39835 rc = -ENODEV;
39836 goto out;
39837 }
39838 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39839 - !info->fbops->fb_setcmap)) {
39840 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39841 rc = -EINVAL;
39842 goto out1;
39843 }
39844 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39845 index 0dff12a..2ef47b3 100644
39846 --- a/drivers/video/fbmem.c
39847 +++ b/drivers/video/fbmem.c
39848 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39849 image->dx += image->width + 8;
39850 }
39851 } else if (rotate == FB_ROTATE_UD) {
39852 - for (x = 0; x < num && image->dx >= 0; x++) {
39853 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39854 info->fbops->fb_imageblit(info, image);
39855 image->dx -= image->width + 8;
39856 }
39857 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39858 image->dy += image->height + 8;
39859 }
39860 } else if (rotate == FB_ROTATE_CCW) {
39861 - for (x = 0; x < num && image->dy >= 0; x++) {
39862 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39863 info->fbops->fb_imageblit(info, image);
39864 image->dy -= image->height + 8;
39865 }
39866 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39867 return -EFAULT;
39868 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39869 return -EINVAL;
39870 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39871 + if (con2fb.framebuffer >= FB_MAX)
39872 return -EINVAL;
39873 if (!registered_fb[con2fb.framebuffer])
39874 request_module("fb%d", con2fb.framebuffer);
39875 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39876 index 5a5d092..265c5ed 100644
39877 --- a/drivers/video/geode/gx1fb_core.c
39878 +++ b/drivers/video/geode/gx1fb_core.c
39879 @@ -29,7 +29,7 @@ static int crt_option = 1;
39880 static char panel_option[32] = "";
39881
39882 /* Modes relevant to the GX1 (taken from modedb.c) */
39883 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39884 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39885 /* 640x480-60 VESA */
39886 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39887 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39888 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39889 index 0fad23f..0e9afa4 100644
39890 --- a/drivers/video/gxt4500.c
39891 +++ b/drivers/video/gxt4500.c
39892 @@ -156,7 +156,7 @@ struct gxt4500_par {
39893 static char *mode_option;
39894
39895 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39896 -static const struct fb_videomode defaultmode __devinitdata = {
39897 +static const struct fb_videomode defaultmode __devinitconst = {
39898 .refresh = 60,
39899 .xres = 1280,
39900 .yres = 1024,
39901 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39902 return 0;
39903 }
39904
39905 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39906 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39907 .id = "IBM GXT4500P",
39908 .type = FB_TYPE_PACKED_PIXELS,
39909 .visual = FB_VISUAL_PSEUDOCOLOR,
39910 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39911 index 7672d2e..b56437f 100644
39912 --- a/drivers/video/i810/i810_accel.c
39913 +++ b/drivers/video/i810/i810_accel.c
39914 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39915 }
39916 }
39917 printk("ringbuffer lockup!!!\n");
39918 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39919 i810_report_error(mmio);
39920 par->dev_flags |= LOCKUP;
39921 info->pixmap.scan_align = 1;
39922 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39923 index b83f361..2b05a91 100644
39924 --- a/drivers/video/i810/i810_main.c
39925 +++ b/drivers/video/i810/i810_main.c
39926 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39927 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39928
39929 /* PCI */
39930 -static const char *i810_pci_list[] __devinitdata = {
39931 +static const char *i810_pci_list[] __devinitconst = {
39932 "Intel(R) 810 Framebuffer Device" ,
39933 "Intel(R) 810-DC100 Framebuffer Device" ,
39934 "Intel(R) 810E Framebuffer Device" ,
39935 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39936 index de36693..3c63fc2 100644
39937 --- a/drivers/video/jz4740_fb.c
39938 +++ b/drivers/video/jz4740_fb.c
39939 @@ -136,7 +136,7 @@ struct jzfb {
39940 uint32_t pseudo_palette[16];
39941 };
39942
39943 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39944 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39945 .id = "JZ4740 FB",
39946 .type = FB_TYPE_PACKED_PIXELS,
39947 .visual = FB_VISUAL_TRUECOLOR,
39948 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39949 index 3c14e43..eafa544 100644
39950 --- a/drivers/video/logo/logo_linux_clut224.ppm
39951 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39952 @@ -1,1604 +1,1123 @@
39953 P3
39954 -# Standard 224-color Linux logo
39955 80 80
39956 255
39957 - 0 0 0 0 0 0 0 0 0 0 0 0
39958 - 0 0 0 0 0 0 0 0 0 0 0 0
39959 - 0 0 0 0 0 0 0 0 0 0 0 0
39960 - 0 0 0 0 0 0 0 0 0 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 0 0 0
39962 - 0 0 0 0 0 0 0 0 0 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 0 0 0
39965 - 0 0 0 0 0 0 0 0 0 0 0 0
39966 - 6 6 6 6 6 6 10 10 10 10 10 10
39967 - 10 10 10 6 6 6 6 6 6 6 6 6
39968 - 0 0 0 0 0 0 0 0 0 0 0 0
39969 - 0 0 0 0 0 0 0 0 0 0 0 0
39970 - 0 0 0 0 0 0 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 0 0 0
39972 - 0 0 0 0 0 0 0 0 0 0 0 0
39973 - 0 0 0 0 0 0 0 0 0 0 0 0
39974 - 0 0 0 0 0 0 0 0 0 0 0 0
39975 - 0 0 0 0 0 0 0 0 0 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 0 0 0
39979 - 0 0 0 0 0 0 0 0 0 0 0 0
39980 - 0 0 0 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 0 0 0
39985 - 0 0 0 6 6 6 10 10 10 14 14 14
39986 - 22 22 22 26 26 26 30 30 30 34 34 34
39987 - 30 30 30 30 30 30 26 26 26 18 18 18
39988 - 14 14 14 10 10 10 6 6 6 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 1 0 0 1 0 0 0
39999 - 0 0 0 0 0 0 0 0 0 0 0 0
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 0 0 0
40005 - 6 6 6 14 14 14 26 26 26 42 42 42
40006 - 54 54 54 66 66 66 78 78 78 78 78 78
40007 - 78 78 78 74 74 74 66 66 66 54 54 54
40008 - 42 42 42 26 26 26 18 18 18 10 10 10
40009 - 6 6 6 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 0 0 0 0 0 0 0
40015 - 0 0 0 0 0 0 0 0 0 0 0 0
40016 - 0 0 0 0 0 0 0 0 0 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 0 0 0
40018 - 0 0 1 0 0 0 0 0 0 0 0 0
40019 - 0 0 0 0 0 0 0 0 0 0 0 0
40020 - 0 0 0 0 0 0 0 0 0 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 0 0 0 0 0 0 0 0 0 0 0 0
40024 - 0 0 0 0 0 0 0 0 0 10 10 10
40025 - 22 22 22 42 42 42 66 66 66 86 86 86
40026 - 66 66 66 38 38 38 38 38 38 22 22 22
40027 - 26 26 26 34 34 34 54 54 54 66 66 66
40028 - 86 86 86 70 70 70 46 46 46 26 26 26
40029 - 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0 0
40035 - 0 0 0 0 0 0 0 0 0 0 0 0
40036 - 0 0 0 0 0 0 0 0 0 0 0 0
40037 - 0 0 0 0 0 0 0 0 0 0 0 0
40038 - 0 0 1 0 0 1 0 0 1 0 0 0
40039 - 0 0 0 0 0 0 0 0 0 0 0 0
40040 - 0 0 0 0 0 0 0 0 0 0 0 0
40041 - 0 0 0 0 0 0 0 0 0 0 0 0
40042 - 0 0 0 0 0 0 0 0 0 0 0 0
40043 - 0 0 0 0 0 0 0 0 0 0 0 0
40044 - 0 0 0 0 0 0 10 10 10 26 26 26
40045 - 50 50 50 82 82 82 58 58 58 6 6 6
40046 - 2 2 6 2 2 6 2 2 6 2 2 6
40047 - 2 2 6 2 2 6 2 2 6 2 2 6
40048 - 6 6 6 54 54 54 86 86 86 66 66 66
40049 - 38 38 38 18 18 18 6 6 6 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 0 0 0
40053 - 0 0 0 0 0 0 0 0 0 0 0 0
40054 - 0 0 0 0 0 0 0 0 0 0 0 0
40055 - 0 0 0 0 0 0 0 0 0 0 0 0
40056 - 0 0 0 0 0 0 0 0 0 0 0 0
40057 - 0 0 0 0 0 0 0 0 0 0 0 0
40058 - 0 0 0 0 0 0 0 0 0 0 0 0
40059 - 0 0 0 0 0 0 0 0 0 0 0 0
40060 - 0 0 0 0 0 0 0 0 0 0 0 0
40061 - 0 0 0 0 0 0 0 0 0 0 0 0
40062 - 0 0 0 0 0 0 0 0 0 0 0 0
40063 - 0 0 0 0 0 0 0 0 0 0 0 0
40064 - 0 0 0 6 6 6 22 22 22 50 50 50
40065 - 78 78 78 34 34 34 2 2 6 2 2 6
40066 - 2 2 6 2 2 6 2 2 6 2 2 6
40067 - 2 2 6 2 2 6 2 2 6 2 2 6
40068 - 2 2 6 2 2 6 6 6 6 70 70 70
40069 - 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 0 0 0
40079 - 0 0 0 0 0 0 0 0 0 0 0 0
40080 - 0 0 0 0 0 0 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 0 0 0 0
40082 - 0 0 0 0 0 0 0 0 0 0 0 0
40083 - 0 0 0 0 0 0 0 0 0 0 0 0
40084 - 6 6 6 18 18 18 42 42 42 82 82 82
40085 - 26 26 26 2 2 6 2 2 6 2 2 6
40086 - 2 2 6 2 2 6 2 2 6 2 2 6
40087 - 2 2 6 2 2 6 2 2 6 14 14 14
40088 - 46 46 46 34 34 34 6 6 6 2 2 6
40089 - 42 42 42 78 78 78 42 42 42 18 18 18
40090 - 6 6 6 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 0 0 0 0 0 0
40093 - 0 0 0 0 0 0 0 0 0 0 0 0
40094 - 0 0 0 0 0 0 0 0 0 0 0 0
40095 - 0 0 0 0 0 0 0 0 0 0 0 0
40096 - 0 0 0 0 0 0 0 0 0 0 0 0
40097 - 0 0 0 0 0 0 0 0 0 0 0 0
40098 - 0 0 1 0 0 0 0 0 1 0 0 0
40099 - 0 0 0 0 0 0 0 0 0 0 0 0
40100 - 0 0 0 0 0 0 0 0 0 0 0 0
40101 - 0 0 0 0 0 0 0 0 0 0 0 0
40102 - 0 0 0 0 0 0 0 0 0 0 0 0
40103 - 0 0 0 0 0 0 0 0 0 0 0 0
40104 - 10 10 10 30 30 30 66 66 66 58 58 58
40105 - 2 2 6 2 2 6 2 2 6 2 2 6
40106 - 2 2 6 2 2 6 2 2 6 2 2 6
40107 - 2 2 6 2 2 6 2 2 6 26 26 26
40108 - 86 86 86 101 101 101 46 46 46 10 10 10
40109 - 2 2 6 58 58 58 70 70 70 34 34 34
40110 - 10 10 10 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 0 0 0 0 0 0
40113 - 0 0 0 0 0 0 0 0 0 0 0 0
40114 - 0 0 0 0 0 0 0 0 0 0 0 0
40115 - 0 0 0 0 0 0 0 0 0 0 0 0
40116 - 0 0 0 0 0 0 0 0 0 0 0 0
40117 - 0 0 0 0 0 0 0 0 0 0 0 0
40118 - 0 0 1 0 0 1 0 0 1 0 0 0
40119 - 0 0 0 0 0 0 0 0 0 0 0 0
40120 - 0 0 0 0 0 0 0 0 0 0 0 0
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 0 0 0 0 0 0 0 0 0 0 0 0
40123 - 0 0 0 0 0 0 0 0 0 0 0 0
40124 - 14 14 14 42 42 42 86 86 86 10 10 10
40125 - 2 2 6 2 2 6 2 2 6 2 2 6
40126 - 2 2 6 2 2 6 2 2 6 2 2 6
40127 - 2 2 6 2 2 6 2 2 6 30 30 30
40128 - 94 94 94 94 94 94 58 58 58 26 26 26
40129 - 2 2 6 6 6 6 78 78 78 54 54 54
40130 - 22 22 22 6 6 6 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 0 0 0 0 0 0
40133 - 0 0 0 0 0 0 0 0 0 0 0 0
40134 - 0 0 0 0 0 0 0 0 0 0 0 0
40135 - 0 0 0 0 0 0 0 0 0 0 0 0
40136 - 0 0 0 0 0 0 0 0 0 0 0 0
40137 - 0 0 0 0 0 0 0 0 0 0 0 0
40138 - 0 0 0 0 0 0 0 0 0 0 0 0
40139 - 0 0 0 0 0 0 0 0 0 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 0 0 0 0 0 0 0 0 0 0 0 0
40143 - 0 0 0 0 0 0 0 0 0 6 6 6
40144 - 22 22 22 62 62 62 62 62 62 2 2 6
40145 - 2 2 6 2 2 6 2 2 6 2 2 6
40146 - 2 2 6 2 2 6 2 2 6 2 2 6
40147 - 2 2 6 2 2 6 2 2 6 26 26 26
40148 - 54 54 54 38 38 38 18 18 18 10 10 10
40149 - 2 2 6 2 2 6 34 34 34 82 82 82
40150 - 38 38 38 14 14 14 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 1 0 0 1 0 0 0
40159 - 0 0 0 0 0 0 0 0 0 0 0 0
40160 - 0 0 0 0 0 0 0 0 0 0 0 0
40161 - 0 0 0 0 0 0 0 0 0 0 0 0
40162 - 0 0 0 0 0 0 0 0 0 0 0 0
40163 - 0 0 0 0 0 0 0 0 0 6 6 6
40164 - 30 30 30 78 78 78 30 30 30 2 2 6
40165 - 2 2 6 2 2 6 2 2 6 2 2 6
40166 - 2 2 6 2 2 6 2 2 6 2 2 6
40167 - 2 2 6 2 2 6 2 2 6 10 10 10
40168 - 10 10 10 2 2 6 2 2 6 2 2 6
40169 - 2 2 6 2 2 6 2 2 6 78 78 78
40170 - 50 50 50 18 18 18 6 6 6 0 0 0
40171 - 0 0 0 0 0 0 0 0 0 0 0 0
40172 - 0 0 0 0 0 0 0 0 0 0 0 0
40173 - 0 0 0 0 0 0 0 0 0 0 0 0
40174 - 0 0 0 0 0 0 0 0 0 0 0 0
40175 - 0 0 0 0 0 0 0 0 0 0 0 0
40176 - 0 0 0 0 0 0 0 0 0 0 0 0
40177 - 0 0 0 0 0 0 0 0 0 0 0 0
40178 - 0 0 1 0 0 0 0 0 0 0 0 0
40179 - 0 0 0 0 0 0 0 0 0 0 0 0
40180 - 0 0 0 0 0 0 0 0 0 0 0 0
40181 - 0 0 0 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 10 10 10
40184 - 38 38 38 86 86 86 14 14 14 2 2 6
40185 - 2 2 6 2 2 6 2 2 6 2 2 6
40186 - 2 2 6 2 2 6 2 2 6 2 2 6
40187 - 2 2 6 2 2 6 2 2 6 2 2 6
40188 - 2 2 6 2 2 6 2 2 6 2 2 6
40189 - 2 2 6 2 2 6 2 2 6 54 54 54
40190 - 66 66 66 26 26 26 6 6 6 0 0 0
40191 - 0 0 0 0 0 0 0 0 0 0 0 0
40192 - 0 0 0 0 0 0 0 0 0 0 0 0
40193 - 0 0 0 0 0 0 0 0 0 0 0 0
40194 - 0 0 0 0 0 0 0 0 0 0 0 0
40195 - 0 0 0 0 0 0 0 0 0 0 0 0
40196 - 0 0 0 0 0 0 0 0 0 0 0 0
40197 - 0 0 0 0 0 0 0 0 0 0 0 0
40198 - 0 0 0 0 0 1 0 0 1 0 0 0
40199 - 0 0 0 0 0 0 0 0 0 0 0 0
40200 - 0 0 0 0 0 0 0 0 0 0 0 0
40201 - 0 0 0 0 0 0 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 14 14 14
40204 - 42 42 42 82 82 82 2 2 6 2 2 6
40205 - 2 2 6 6 6 6 10 10 10 2 2 6
40206 - 2 2 6 2 2 6 2 2 6 2 2 6
40207 - 2 2 6 2 2 6 2 2 6 6 6 6
40208 - 14 14 14 10 10 10 2 2 6 2 2 6
40209 - 2 2 6 2 2 6 2 2 6 18 18 18
40210 - 82 82 82 34 34 34 10 10 10 0 0 0
40211 - 0 0 0 0 0 0 0 0 0 0 0 0
40212 - 0 0 0 0 0 0 0 0 0 0 0 0
40213 - 0 0 0 0 0 0 0 0 0 0 0 0
40214 - 0 0 0 0 0 0 0 0 0 0 0 0
40215 - 0 0 0 0 0 0 0 0 0 0 0 0
40216 - 0 0 0 0 0 0 0 0 0 0 0 0
40217 - 0 0 0 0 0 0 0 0 0 0 0 0
40218 - 0 0 1 0 0 0 0 0 0 0 0 0
40219 - 0 0 0 0 0 0 0 0 0 0 0 0
40220 - 0 0 0 0 0 0 0 0 0 0 0 0
40221 - 0 0 0 0 0 0 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 14 14 14
40224 - 46 46 46 86 86 86 2 2 6 2 2 6
40225 - 6 6 6 6 6 6 22 22 22 34 34 34
40226 - 6 6 6 2 2 6 2 2 6 2 2 6
40227 - 2 2 6 2 2 6 18 18 18 34 34 34
40228 - 10 10 10 50 50 50 22 22 22 2 2 6
40229 - 2 2 6 2 2 6 2 2 6 10 10 10
40230 - 86 86 86 42 42 42 14 14 14 0 0 0
40231 - 0 0 0 0 0 0 0 0 0 0 0 0
40232 - 0 0 0 0 0 0 0 0 0 0 0 0
40233 - 0 0 0 0 0 0 0 0 0 0 0 0
40234 - 0 0 0 0 0 0 0 0 0 0 0 0
40235 - 0 0 0 0 0 0 0 0 0 0 0 0
40236 - 0 0 0 0 0 0 0 0 0 0 0 0
40237 - 0 0 0 0 0 0 0 0 0 0 0 0
40238 - 0 0 1 0 0 1 0 0 1 0 0 0
40239 - 0 0 0 0 0 0 0 0 0 0 0 0
40240 - 0 0 0 0 0 0 0 0 0 0 0 0
40241 - 0 0 0 0 0 0 0 0 0 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 14 14 14
40244 - 46 46 46 86 86 86 2 2 6 2 2 6
40245 - 38 38 38 116 116 116 94 94 94 22 22 22
40246 - 22 22 22 2 2 6 2 2 6 2 2 6
40247 - 14 14 14 86 86 86 138 138 138 162 162 162
40248 -154 154 154 38 38 38 26 26 26 6 6 6
40249 - 2 2 6 2 2 6 2 2 6 2 2 6
40250 - 86 86 86 46 46 46 14 14 14 0 0 0
40251 - 0 0 0 0 0 0 0 0 0 0 0 0
40252 - 0 0 0 0 0 0 0 0 0 0 0 0
40253 - 0 0 0 0 0 0 0 0 0 0 0 0
40254 - 0 0 0 0 0 0 0 0 0 0 0 0
40255 - 0 0 0 0 0 0 0 0 0 0 0 0
40256 - 0 0 0 0 0 0 0 0 0 0 0 0
40257 - 0 0 0 0 0 0 0 0 0 0 0 0
40258 - 0 0 0 0 0 0 0 0 0 0 0 0
40259 - 0 0 0 0 0 0 0 0 0 0 0 0
40260 - 0 0 0 0 0 0 0 0 0 0 0 0
40261 - 0 0 0 0 0 0 0 0 0 0 0 0
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 14 14 14
40264 - 46 46 46 86 86 86 2 2 6 14 14 14
40265 -134 134 134 198 198 198 195 195 195 116 116 116
40266 - 10 10 10 2 2 6 2 2 6 6 6 6
40267 -101 98 89 187 187 187 210 210 210 218 218 218
40268 -214 214 214 134 134 134 14 14 14 6 6 6
40269 - 2 2 6 2 2 6 2 2 6 2 2 6
40270 - 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
40278 - 0 0 1 0 0 1 0 0 1 0 0 0
40279 - 0 0 0 0 0 0 0 0 0 0 0 0
40280 - 0 0 0 0 0 0 0 0 0 0 0 0
40281 - 0 0 0 0 0 0 0 0 0 0 0 0
40282 - 0 0 0 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 14 14 14
40284 - 46 46 46 86 86 86 2 2 6 54 54 54
40285 -218 218 218 195 195 195 226 226 226 246 246 246
40286 - 58 58 58 2 2 6 2 2 6 30 30 30
40287 -210 210 210 253 253 253 174 174 174 123 123 123
40288 -221 221 221 234 234 234 74 74 74 2 2 6
40289 - 2 2 6 2 2 6 2 2 6 2 2 6
40290 - 70 70 70 58 58 58 22 22 22 6 6 6
40291 - 0 0 0 0 0 0 0 0 0 0 0 0
40292 - 0 0 0 0 0 0 0 0 0 0 0 0
40293 - 0 0 0 0 0 0 0 0 0 0 0 0
40294 - 0 0 0 0 0 0 0 0 0 0 0 0
40295 - 0 0 0 0 0 0 0 0 0 0 0 0
40296 - 0 0 0 0 0 0 0 0 0 0 0 0
40297 - 0 0 0 0 0 0 0 0 0 0 0 0
40298 - 0 0 0 0 0 0 0 0 0 0 0 0
40299 - 0 0 0 0 0 0 0 0 0 0 0 0
40300 - 0 0 0 0 0 0 0 0 0 0 0 0
40301 - 0 0 0 0 0 0 0 0 0 0 0 0
40302 - 0 0 0 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 14 14 14
40304 - 46 46 46 82 82 82 2 2 6 106 106 106
40305 -170 170 170 26 26 26 86 86 86 226 226 226
40306 -123 123 123 10 10 10 14 14 14 46 46 46
40307 -231 231 231 190 190 190 6 6 6 70 70 70
40308 - 90 90 90 238 238 238 158 158 158 2 2 6
40309 - 2 2 6 2 2 6 2 2 6 2 2 6
40310 - 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
40318 - 0 0 1 0 0 1 0 0 1 0 0 0
40319 - 0 0 0 0 0 0 0 0 0 0 0 0
40320 - 0 0 0 0 0 0 0 0 0 0 0 0
40321 - 0 0 0 0 0 0 0 0 0 0 0 0
40322 - 0 0 0 0 0 0 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 14 14 14
40324 - 42 42 42 86 86 86 6 6 6 116 116 116
40325 -106 106 106 6 6 6 70 70 70 149 149 149
40326 -128 128 128 18 18 18 38 38 38 54 54 54
40327 -221 221 221 106 106 106 2 2 6 14 14 14
40328 - 46 46 46 190 190 190 198 198 198 2 2 6
40329 - 2 2 6 2 2 6 2 2 6 2 2 6
40330 - 74 74 74 62 62 62 22 22 22 6 6 6
40331 - 0 0 0 0 0 0 0 0 0 0 0 0
40332 - 0 0 0 0 0 0 0 0 0 0 0 0
40333 - 0 0 0 0 0 0 0 0 0 0 0 0
40334 - 0 0 0 0 0 0 0 0 0 0 0 0
40335 - 0 0 0 0 0 0 0 0 0 0 0 0
40336 - 0 0 0 0 0 0 0 0 0 0 0 0
40337 - 0 0 0 0 0 0 0 0 1 0 0 0
40338 - 0 0 1 0 0 0 0 0 1 0 0 0
40339 - 0 0 0 0 0 0 0 0 0 0 0 0
40340 - 0 0 0 0 0 0 0 0 0 0 0 0
40341 - 0 0 0 0 0 0 0 0 0 0 0 0
40342 - 0 0 0 0 0 0 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 0 0 0 14 14 14
40344 - 42 42 42 94 94 94 14 14 14 101 101 101
40345 -128 128 128 2 2 6 18 18 18 116 116 116
40346 -118 98 46 121 92 8 121 92 8 98 78 10
40347 -162 162 162 106 106 106 2 2 6 2 2 6
40348 - 2 2 6 195 195 195 195 195 195 6 6 6
40349 - 2 2 6 2 2 6 2 2 6 2 2 6
40350 - 74 74 74 62 62 62 22 22 22 6 6 6
40351 - 0 0 0 0 0 0 0 0 0 0 0 0
40352 - 0 0 0 0 0 0 0 0 0 0 0 0
40353 - 0 0 0 0 0 0 0 0 0 0 0 0
40354 - 0 0 0 0 0 0 0 0 0 0 0 0
40355 - 0 0 0 0 0 0 0 0 0 0 0 0
40356 - 0 0 0 0 0 0 0 0 0 0 0 0
40357 - 0 0 0 0 0 0 0 0 1 0 0 1
40358 - 0 0 1 0 0 0 0 0 1 0 0 0
40359 - 0 0 0 0 0 0 0 0 0 0 0 0
40360 - 0 0 0 0 0 0 0 0 0 0 0 0
40361 - 0 0 0 0 0 0 0 0 0 0 0 0
40362 - 0 0 0 0 0 0 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 0 0 0 10 10 10
40364 - 38 38 38 90 90 90 14 14 14 58 58 58
40365 -210 210 210 26 26 26 54 38 6 154 114 10
40366 -226 170 11 236 186 11 225 175 15 184 144 12
40367 -215 174 15 175 146 61 37 26 9 2 2 6
40368 - 70 70 70 246 246 246 138 138 138 2 2 6
40369 - 2 2 6 2 2 6 2 2 6 2 2 6
40370 - 70 70 70 66 66 66 26 26 26 6 6 6
40371 - 0 0 0 0 0 0 0 0 0 0 0 0
40372 - 0 0 0 0 0 0 0 0 0 0 0 0
40373 - 0 0 0 0 0 0 0 0 0 0 0 0
40374 - 0 0 0 0 0 0 0 0 0 0 0 0
40375 - 0 0 0 0 0 0 0 0 0 0 0 0
40376 - 0 0 0 0 0 0 0 0 0 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 0 0 0
40380 - 0 0 0 0 0 0 0 0 0 0 0 0
40381 - 0 0 0 0 0 0 0 0 0 0 0 0
40382 - 0 0 0 0 0 0 0 0 0 0 0 0
40383 - 0 0 0 0 0 0 0 0 0 10 10 10
40384 - 38 38 38 86 86 86 14 14 14 10 10 10
40385 -195 195 195 188 164 115 192 133 9 225 175 15
40386 -239 182 13 234 190 10 232 195 16 232 200 30
40387 -245 207 45 241 208 19 232 195 16 184 144 12
40388 -218 194 134 211 206 186 42 42 42 2 2 6
40389 - 2 2 6 2 2 6 2 2 6 2 2 6
40390 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
40400 - 0 0 0 0 0 0 0 0 0 0 0 0
40401 - 0 0 0 0 0 0 0 0 0 0 0 0
40402 - 0 0 0 0 0 0 0 0 0 0 0 0
40403 - 0 0 0 0 0 0 0 0 0 10 10 10
40404 - 34 34 34 86 86 86 14 14 14 2 2 6
40405 -121 87 25 192 133 9 219 162 10 239 182 13
40406 -236 186 11 232 195 16 241 208 19 244 214 54
40407 -246 218 60 246 218 38 246 215 20 241 208 19
40408 -241 208 19 226 184 13 121 87 25 2 2 6
40409 - 2 2 6 2 2 6 2 2 6 2 2 6
40410 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
40420 - 0 0 0 0 0 0 0 0 0 0 0 0
40421 - 0 0 0 0 0 0 0 0 0 0 0 0
40422 - 0 0 0 0 0 0 0 0 0 0 0 0
40423 - 0 0 0 0 0 0 0 0 0 10 10 10
40424 - 34 34 34 82 82 82 30 30 30 61 42 6
40425 -180 123 7 206 145 10 230 174 11 239 182 13
40426 -234 190 10 238 202 15 241 208 19 246 218 74
40427 -246 218 38 246 215 20 246 215 20 246 215 20
40428 -226 184 13 215 174 15 184 144 12 6 6 6
40429 - 2 2 6 2 2 6 2 2 6 2 2 6
40430 - 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
40440 - 0 0 0 0 0 0 0 0 0 0 0 0
40441 - 0 0 0 0 0 0 0 0 0 0 0 0
40442 - 0 0 0 0 0 0 0 0 0 0 0 0
40443 - 0 0 0 0 0 0 0 0 0 10 10 10
40444 - 30 30 30 78 78 78 50 50 50 104 69 6
40445 -192 133 9 216 158 10 236 178 12 236 186 11
40446 -232 195 16 241 208 19 244 214 54 245 215 43
40447 -246 215 20 246 215 20 241 208 19 198 155 10
40448 -200 144 11 216 158 10 156 118 10 2 2 6
40449 - 2 2 6 2 2 6 2 2 6 2 2 6
40450 - 6 6 6 90 90 90 54 54 54 18 18 18
40451 - 6 6 6 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 0 0 0
40460 - 0 0 0 0 0 0 0 0 0 0 0 0
40461 - 0 0 0 0 0 0 0 0 0 0 0 0
40462 - 0 0 0 0 0 0 0 0 0 0 0 0
40463 - 0 0 0 0 0 0 0 0 0 10 10 10
40464 - 30 30 30 78 78 78 46 46 46 22 22 22
40465 -137 92 6 210 162 10 239 182 13 238 190 10
40466 -238 202 15 241 208 19 246 215 20 246 215 20
40467 -241 208 19 203 166 17 185 133 11 210 150 10
40468 -216 158 10 210 150 10 102 78 10 2 2 6
40469 - 6 6 6 54 54 54 14 14 14 2 2 6
40470 - 2 2 6 62 62 62 74 74 74 30 30 30
40471 - 10 10 10 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 0 0 0
40480 - 0 0 0 0 0 0 0 0 0 0 0 0
40481 - 0 0 0 0 0 0 0 0 0 0 0 0
40482 - 0 0 0 0 0 0 0 0 0 0 0 0
40483 - 0 0 0 0 0 0 0 0 0 10 10 10
40484 - 34 34 34 78 78 78 50 50 50 6 6 6
40485 - 94 70 30 139 102 15 190 146 13 226 184 13
40486 -232 200 30 232 195 16 215 174 15 190 146 13
40487 -168 122 10 192 133 9 210 150 10 213 154 11
40488 -202 150 34 182 157 106 101 98 89 2 2 6
40489 - 2 2 6 78 78 78 116 116 116 58 58 58
40490 - 2 2 6 22 22 22 90 90 90 46 46 46
40491 - 18 18 18 6 6 6 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 0 0 0
40500 - 0 0 0 0 0 0 0 0 0 0 0 0
40501 - 0 0 0 0 0 0 0 0 0 0 0 0
40502 - 0 0 0 0 0 0 0 0 0 0 0 0
40503 - 0 0 0 0 0 0 0 0 0 10 10 10
40504 - 38 38 38 86 86 86 50 50 50 6 6 6
40505 -128 128 128 174 154 114 156 107 11 168 122 10
40506 -198 155 10 184 144 12 197 138 11 200 144 11
40507 -206 145 10 206 145 10 197 138 11 188 164 115
40508 -195 195 195 198 198 198 174 174 174 14 14 14
40509 - 2 2 6 22 22 22 116 116 116 116 116 116
40510 - 22 22 22 2 2 6 74 74 74 70 70 70
40511 - 30 30 30 10 10 10 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 0 0 0
40520 - 0 0 0 0 0 0 0 0 0 0 0 0
40521 - 0 0 0 0 0 0 0 0 0 0 0 0
40522 - 0 0 0 0 0 0 0 0 0 0 0 0
40523 - 0 0 0 0 0 0 6 6 6 18 18 18
40524 - 50 50 50 101 101 101 26 26 26 10 10 10
40525 -138 138 138 190 190 190 174 154 114 156 107 11
40526 -197 138 11 200 144 11 197 138 11 192 133 9
40527 -180 123 7 190 142 34 190 178 144 187 187 187
40528 -202 202 202 221 221 221 214 214 214 66 66 66
40529 - 2 2 6 2 2 6 50 50 50 62 62 62
40530 - 6 6 6 2 2 6 10 10 10 90 90 90
40531 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0
40540 - 0 0 0 0 0 0 0 0 0 0 0 0
40541 - 0 0 0 0 0 0 0 0 0 0 0 0
40542 - 0 0 0 0 0 0 0 0 0 0 0 0
40543 - 0 0 0 0 0 0 10 10 10 34 34 34
40544 - 74 74 74 74 74 74 2 2 6 6 6 6
40545 -144 144 144 198 198 198 190 190 190 178 166 146
40546 -154 121 60 156 107 11 156 107 11 168 124 44
40547 -174 154 114 187 187 187 190 190 190 210 210 210
40548 -246 246 246 253 253 253 253 253 253 182 182 182
40549 - 6 6 6 2 2 6 2 2 6 2 2 6
40550 - 2 2 6 2 2 6 2 2 6 62 62 62
40551 - 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0
40560 - 0 0 0 0 0 0 0 0 0 0 0 0
40561 - 0 0 0 0 0 0 0 0 0 0 0 0
40562 - 0 0 0 0 0 0 0 0 0 0 0 0
40563 - 0 0 0 10 10 10 22 22 22 54 54 54
40564 - 94 94 94 18 18 18 2 2 6 46 46 46
40565 -234 234 234 221 221 221 190 190 190 190 190 190
40566 -190 190 190 187 187 187 187 187 187 190 190 190
40567 -190 190 190 195 195 195 214 214 214 242 242 242
40568 -253 253 253 253 253 253 253 253 253 253 253 253
40569 - 82 82 82 2 2 6 2 2 6 2 2 6
40570 - 2 2 6 2 2 6 2 2 6 14 14 14
40571 - 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
40580 - 0 0 0 0 0 0 0 0 0 0 0 0
40581 - 0 0 0 0 0 0 0 0 0 0 0 0
40582 - 0 0 0 0 0 0 0 0 0 0 0 0
40583 - 6 6 6 18 18 18 46 46 46 90 90 90
40584 - 46 46 46 18 18 18 6 6 6 182 182 182
40585 -253 253 253 246 246 246 206 206 206 190 190 190
40586 -190 190 190 190 190 190 190 190 190 190 190 190
40587 -206 206 206 231 231 231 250 250 250 253 253 253
40588 -253 253 253 253 253 253 253 253 253 253 253 253
40589 -202 202 202 14 14 14 2 2 6 2 2 6
40590 - 2 2 6 2 2 6 2 2 6 2 2 6
40591 - 42 42 42 86 86 86 42 42 42 18 18 18
40592 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40600 - 0 0 0 0 0 0 0 0 0 0 0 0
40601 - 0 0 0 0 0 0 0 0 0 0 0 0
40602 - 0 0 0 0 0 0 0 0 0 6 6 6
40603 - 14 14 14 38 38 38 74 74 74 66 66 66
40604 - 2 2 6 6 6 6 90 90 90 250 250 250
40605 -253 253 253 253 253 253 238 238 238 198 198 198
40606 -190 190 190 190 190 190 195 195 195 221 221 221
40607 -246 246 246 253 253 253 253 253 253 253 253 253
40608 -253 253 253 253 253 253 253 253 253 253 253 253
40609 -253 253 253 82 82 82 2 2 6 2 2 6
40610 - 2 2 6 2 2 6 2 2 6 2 2 6
40611 - 2 2 6 78 78 78 70 70 70 34 34 34
40612 - 14 14 14 6 6 6 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 0 0 0
40619 - 0 0 0 0 0 0 0 0 0 0 0 0
40620 - 0 0 0 0 0 0 0 0 0 0 0 0
40621 - 0 0 0 0 0 0 0 0 0 0 0 0
40622 - 0 0 0 0 0 0 0 0 0 14 14 14
40623 - 34 34 34 66 66 66 78 78 78 6 6 6
40624 - 2 2 6 18 18 18 218 218 218 253 253 253
40625 -253 253 253 253 253 253 253 253 253 246 246 246
40626 -226 226 226 231 231 231 246 246 246 253 253 253
40627 -253 253 253 253 253 253 253 253 253 253 253 253
40628 -253 253 253 253 253 253 253 253 253 253 253 253
40629 -253 253 253 178 178 178 2 2 6 2 2 6
40630 - 2 2 6 2 2 6 2 2 6 2 2 6
40631 - 2 2 6 18 18 18 90 90 90 62 62 62
40632 - 30 30 30 10 10 10 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 0 0 0
40639 - 0 0 0 0 0 0 0 0 0 0 0 0
40640 - 0 0 0 0 0 0 0 0 0 0 0 0
40641 - 0 0 0 0 0 0 0 0 0 0 0 0
40642 - 0 0 0 0 0 0 10 10 10 26 26 26
40643 - 58 58 58 90 90 90 18 18 18 2 2 6
40644 - 2 2 6 110 110 110 253 253 253 253 253 253
40645 -253 253 253 253 253 253 253 253 253 253 253 253
40646 -250 250 250 253 253 253 253 253 253 253 253 253
40647 -253 253 253 253 253 253 253 253 253 253 253 253
40648 -253 253 253 253 253 253 253 253 253 253 253 253
40649 -253 253 253 231 231 231 18 18 18 2 2 6
40650 - 2 2 6 2 2 6 2 2 6 2 2 6
40651 - 2 2 6 2 2 6 18 18 18 94 94 94
40652 - 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0
40659 - 0 0 0 0 0 0 0 0 0 0 0 0
40660 - 0 0 0 0 0 0 0 0 0 0 0 0
40661 - 0 0 0 0 0 0 0 0 0 0 0 0
40662 - 0 0 0 6 6 6 22 22 22 50 50 50
40663 - 90 90 90 26 26 26 2 2 6 2 2 6
40664 - 14 14 14 195 195 195 250 250 250 253 253 253
40665 -253 253 253 253 253 253 253 253 253 253 253 253
40666 -253 253 253 253 253 253 253 253 253 253 253 253
40667 -253 253 253 253 253 253 253 253 253 253 253 253
40668 -253 253 253 253 253 253 253 253 253 253 253 253
40669 -250 250 250 242 242 242 54 54 54 2 2 6
40670 - 2 2 6 2 2 6 2 2 6 2 2 6
40671 - 2 2 6 2 2 6 2 2 6 38 38 38
40672 - 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
40679 - 0 0 0 0 0 0 0 0 0 0 0 0
40680 - 0 0 0 0 0 0 0 0 0 0 0 0
40681 - 0 0 0 0 0 0 0 0 0 0 0 0
40682 - 6 6 6 14 14 14 38 38 38 82 82 82
40683 - 34 34 34 2 2 6 2 2 6 2 2 6
40684 - 42 42 42 195 195 195 246 246 246 253 253 253
40685 -253 253 253 253 253 253 253 253 253 250 250 250
40686 -242 242 242 242 242 242 250 250 250 253 253 253
40687 -253 253 253 253 253 253 253 253 253 253 253 253
40688 -253 253 253 250 250 250 246 246 246 238 238 238
40689 -226 226 226 231 231 231 101 101 101 6 6 6
40690 - 2 2 6 2 2 6 2 2 6 2 2 6
40691 - 2 2 6 2 2 6 2 2 6 2 2 6
40692 - 38 38 38 82 82 82 42 42 42 14 14 14
40693 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40699 - 0 0 0 0 0 0 0 0 0 0 0 0
40700 - 0 0 0 0 0 0 0 0 0 0 0 0
40701 - 0 0 0 0 0 0 0 0 0 0 0 0
40702 - 10 10 10 26 26 26 62 62 62 66 66 66
40703 - 2 2 6 2 2 6 2 2 6 6 6 6
40704 - 70 70 70 170 170 170 206 206 206 234 234 234
40705 -246 246 246 250 250 250 250 250 250 238 238 238
40706 -226 226 226 231 231 231 238 238 238 250 250 250
40707 -250 250 250 250 250 250 246 246 246 231 231 231
40708 -214 214 214 206 206 206 202 202 202 202 202 202
40709 -198 198 198 202 202 202 182 182 182 18 18 18
40710 - 2 2 6 2 2 6 2 2 6 2 2 6
40711 - 2 2 6 2 2 6 2 2 6 2 2 6
40712 - 2 2 6 62 62 62 66 66 66 30 30 30
40713 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40719 - 0 0 0 0 0 0 0 0 0 0 0 0
40720 - 0 0 0 0 0 0 0 0 0 0 0 0
40721 - 0 0 0 0 0 0 0 0 0 0 0 0
40722 - 14 14 14 42 42 42 82 82 82 18 18 18
40723 - 2 2 6 2 2 6 2 2 6 10 10 10
40724 - 94 94 94 182 182 182 218 218 218 242 242 242
40725 -250 250 250 253 253 253 253 253 253 250 250 250
40726 -234 234 234 253 253 253 253 253 253 253 253 253
40727 -253 253 253 253 253 253 253 253 253 246 246 246
40728 -238 238 238 226 226 226 210 210 210 202 202 202
40729 -195 195 195 195 195 195 210 210 210 158 158 158
40730 - 6 6 6 14 14 14 50 50 50 14 14 14
40731 - 2 2 6 2 2 6 2 2 6 2 2 6
40732 - 2 2 6 6 6 6 86 86 86 46 46 46
40733 - 18 18 18 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40739 - 0 0 0 0 0 0 0 0 0 0 0 0
40740 - 0 0 0 0 0 0 0 0 0 0 0 0
40741 - 0 0 0 0 0 0 0 0 0 6 6 6
40742 - 22 22 22 54 54 54 70 70 70 2 2 6
40743 - 2 2 6 10 10 10 2 2 6 22 22 22
40744 -166 166 166 231 231 231 250 250 250 253 253 253
40745 -253 253 253 253 253 253 253 253 253 250 250 250
40746 -242 242 242 253 253 253 253 253 253 253 253 253
40747 -253 253 253 253 253 253 253 253 253 253 253 253
40748 -253 253 253 253 253 253 253 253 253 246 246 246
40749 -231 231 231 206 206 206 198 198 198 226 226 226
40750 - 94 94 94 2 2 6 6 6 6 38 38 38
40751 - 30 30 30 2 2 6 2 2 6 2 2 6
40752 - 2 2 6 2 2 6 62 62 62 66 66 66
40753 - 26 26 26 10 10 10 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 0 0 0
40758 - 0 0 0 0 0 0 0 0 0 0 0 0
40759 - 0 0 0 0 0 0 0 0 0 0 0 0
40760 - 0 0 0 0 0 0 0 0 0 0 0 0
40761 - 0 0 0 0 0 0 0 0 0 10 10 10
40762 - 30 30 30 74 74 74 50 50 50 2 2 6
40763 - 26 26 26 26 26 26 2 2 6 106 106 106
40764 -238 238 238 253 253 253 253 253 253 253 253 253
40765 -253 253 253 253 253 253 253 253 253 253 253 253
40766 -253 253 253 253 253 253 253 253 253 253 253 253
40767 -253 253 253 253 253 253 253 253 253 253 253 253
40768 -253 253 253 253 253 253 253 253 253 253 253 253
40769 -253 253 253 246 246 246 218 218 218 202 202 202
40770 -210 210 210 14 14 14 2 2 6 2 2 6
40771 - 30 30 30 22 22 22 2 2 6 2 2 6
40772 - 2 2 6 2 2 6 18 18 18 86 86 86
40773 - 42 42 42 14 14 14 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 0 0 0
40778 - 0 0 0 0 0 0 0 0 0 0 0 0
40779 - 0 0 0 0 0 0 0 0 0 0 0 0
40780 - 0 0 0 0 0 0 0 0 0 0 0 0
40781 - 0 0 0 0 0 0 0 0 0 14 14 14
40782 - 42 42 42 90 90 90 22 22 22 2 2 6
40783 - 42 42 42 2 2 6 18 18 18 218 218 218
40784 -253 253 253 253 253 253 253 253 253 253 253 253
40785 -253 253 253 253 253 253 253 253 253 253 253 253
40786 -253 253 253 253 253 253 253 253 253 253 253 253
40787 -253 253 253 253 253 253 253 253 253 253 253 253
40788 -253 253 253 253 253 253 253 253 253 253 253 253
40789 -253 253 253 253 253 253 250 250 250 221 221 221
40790 -218 218 218 101 101 101 2 2 6 14 14 14
40791 - 18 18 18 38 38 38 10 10 10 2 2 6
40792 - 2 2 6 2 2 6 2 2 6 78 78 78
40793 - 58 58 58 22 22 22 6 6 6 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 0 0 0
40798 - 0 0 0 0 0 0 0 0 0 0 0 0
40799 - 0 0 0 0 0 0 0 0 0 0 0 0
40800 - 0 0 0 0 0 0 0 0 0 0 0 0
40801 - 0 0 0 0 0 0 6 6 6 18 18 18
40802 - 54 54 54 82 82 82 2 2 6 26 26 26
40803 - 22 22 22 2 2 6 123 123 123 253 253 253
40804 -253 253 253 253 253 253 253 253 253 253 253 253
40805 -253 253 253 253 253 253 253 253 253 253 253 253
40806 -253 253 253 253 253 253 253 253 253 253 253 253
40807 -253 253 253 253 253 253 253 253 253 253 253 253
40808 -253 253 253 253 253 253 253 253 253 253 253 253
40809 -253 253 253 253 253 253 253 253 253 250 250 250
40810 -238 238 238 198 198 198 6 6 6 38 38 38
40811 - 58 58 58 26 26 26 38 38 38 2 2 6
40812 - 2 2 6 2 2 6 2 2 6 46 46 46
40813 - 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0
40818 - 0 0 0 0 0 0 0 0 0 0 0 0
40819 - 0 0 0 0 0 0 0 0 0 0 0 0
40820 - 0 0 0 0 0 0 0 0 0 0 0 0
40821 - 0 0 0 0 0 0 10 10 10 30 30 30
40822 - 74 74 74 58 58 58 2 2 6 42 42 42
40823 - 2 2 6 22 22 22 231 231 231 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 -253 253 253 253 253 253 253 253 253 253 253 253
40827 -253 253 253 253 253 253 253 253 253 253 253 253
40828 -253 253 253 253 253 253 253 253 253 253 253 253
40829 -253 253 253 253 253 253 253 253 253 253 253 253
40830 -253 253 253 246 246 246 46 46 46 38 38 38
40831 - 42 42 42 14 14 14 38 38 38 14 14 14
40832 - 2 2 6 2 2 6 2 2 6 6 6 6
40833 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0
40838 - 0 0 0 0 0 0 0 0 0 0 0 0
40839 - 0 0 0 0 0 0 0 0 0 0 0 0
40840 - 0 0 0 0 0 0 0 0 0 0 0 0
40841 - 0 0 0 6 6 6 14 14 14 42 42 42
40842 - 90 90 90 18 18 18 18 18 18 26 26 26
40843 - 2 2 6 116 116 116 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 250 250 250 238 238 238
40846 -253 253 253 253 253 253 253 253 253 253 253 253
40847 -253 253 253 253 253 253 253 253 253 253 253 253
40848 -253 253 253 253 253 253 253 253 253 253 253 253
40849 -253 253 253 253 253 253 253 253 253 253 253 253
40850 -253 253 253 253 253 253 94 94 94 6 6 6
40851 - 2 2 6 2 2 6 10 10 10 34 34 34
40852 - 2 2 6 2 2 6 2 2 6 2 2 6
40853 - 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
40858 - 0 0 0 0 0 0 0 0 0 0 0 0
40859 - 0 0 0 0 0 0 0 0 0 0 0 0
40860 - 0 0 0 0 0 0 0 0 0 0 0 0
40861 - 0 0 0 10 10 10 26 26 26 66 66 66
40862 - 82 82 82 2 2 6 38 38 38 6 6 6
40863 - 14 14 14 210 210 210 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 246 246 246 242 242 242
40866 -253 253 253 253 253 253 253 253 253 253 253 253
40867 -253 253 253 253 253 253 253 253 253 253 253 253
40868 -253 253 253 253 253 253 253 253 253 253 253 253
40869 -253 253 253 253 253 253 253 253 253 253 253 253
40870 -253 253 253 253 253 253 144 144 144 2 2 6
40871 - 2 2 6 2 2 6 2 2 6 46 46 46
40872 - 2 2 6 2 2 6 2 2 6 2 2 6
40873 - 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0 0 0 0 0 0 0
40878 - 0 0 0 0 0 0 0 0 0 0 0 0
40879 - 0 0 0 0 0 0 0 0 0 0 0 0
40880 - 0 0 0 0 0 0 0 0 0 0 0 0
40881 - 6 6 6 14 14 14 42 42 42 90 90 90
40882 - 26 26 26 6 6 6 42 42 42 2 2 6
40883 - 74 74 74 250 250 250 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 242 242 242 242 242 242
40886 -253 253 253 253 253 253 253 253 253 253 253 253
40887 -253 253 253 253 253 253 253 253 253 253 253 253
40888 -253 253 253 253 253 253 253 253 253 253 253 253
40889 -253 253 253 253 253 253 253 253 253 253 253 253
40890 -253 253 253 253 253 253 182 182 182 2 2 6
40891 - 2 2 6 2 2 6 2 2 6 46 46 46
40892 - 2 2 6 2 2 6 2 2 6 2 2 6
40893 - 10 10 10 86 86 86 38 38 38 10 10 10
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40898 - 0 0 0 0 0 0 0 0 0 0 0 0
40899 - 0 0 0 0 0 0 0 0 0 0 0 0
40900 - 0 0 0 0 0 0 0 0 0 0 0 0
40901 - 10 10 10 26 26 26 66 66 66 82 82 82
40902 - 2 2 6 22 22 22 18 18 18 2 2 6
40903 -149 149 149 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 234 234 234 242 242 242
40906 -253 253 253 253 253 253 253 253 253 253 253 253
40907 -253 253 253 253 253 253 253 253 253 253 253 253
40908 -253 253 253 253 253 253 253 253 253 253 253 253
40909 -253 253 253 253 253 253 253 253 253 253 253 253
40910 -253 253 253 253 253 253 206 206 206 2 2 6
40911 - 2 2 6 2 2 6 2 2 6 38 38 38
40912 - 2 2 6 2 2 6 2 2 6 2 2 6
40913 - 6 6 6 86 86 86 46 46 46 14 14 14
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40918 - 0 0 0 0 0 0 0 0 0 0 0 0
40919 - 0 0 0 0 0 0 0 0 0 0 0 0
40920 - 0 0 0 0 0 0 0 0 0 6 6 6
40921 - 18 18 18 46 46 46 86 86 86 18 18 18
40922 - 2 2 6 34 34 34 10 10 10 6 6 6
40923 -210 210 210 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 234 234 234 242 242 242
40926 -253 253 253 253 253 253 253 253 253 253 253 253
40927 -253 253 253 253 253 253 253 253 253 253 253 253
40928 -253 253 253 253 253 253 253 253 253 253 253 253
40929 -253 253 253 253 253 253 253 253 253 253 253 253
40930 -253 253 253 253 253 253 221 221 221 6 6 6
40931 - 2 2 6 2 2 6 6 6 6 30 30 30
40932 - 2 2 6 2 2 6 2 2 6 2 2 6
40933 - 2 2 6 82 82 82 54 54 54 18 18 18
40934 - 6 6 6 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 0 0 0
40937 - 0 0 0 0 0 0 0 0 0 0 0 0
40938 - 0 0 0 0 0 0 0 0 0 0 0 0
40939 - 0 0 0 0 0 0 0 0 0 0 0 0
40940 - 0 0 0 0 0 0 0 0 0 10 10 10
40941 - 26 26 26 66 66 66 62 62 62 2 2 6
40942 - 2 2 6 38 38 38 10 10 10 26 26 26
40943 -238 238 238 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 231 231 231 238 238 238
40946 -253 253 253 253 253 253 253 253 253 253 253 253
40947 -253 253 253 253 253 253 253 253 253 253 253 253
40948 -253 253 253 253 253 253 253 253 253 253 253 253
40949 -253 253 253 253 253 253 253 253 253 253 253 253
40950 -253 253 253 253 253 253 231 231 231 6 6 6
40951 - 2 2 6 2 2 6 10 10 10 30 30 30
40952 - 2 2 6 2 2 6 2 2 6 2 2 6
40953 - 2 2 6 66 66 66 58 58 58 22 22 22
40954 - 6 6 6 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 0 0 0
40957 - 0 0 0 0 0 0 0 0 0 0 0 0
40958 - 0 0 0 0 0 0 0 0 0 0 0 0
40959 - 0 0 0 0 0 0 0 0 0 0 0 0
40960 - 0 0 0 0 0 0 0 0 0 10 10 10
40961 - 38 38 38 78 78 78 6 6 6 2 2 6
40962 - 2 2 6 46 46 46 14 14 14 42 42 42
40963 -246 246 246 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 231 231 231 242 242 242
40966 -253 253 253 253 253 253 253 253 253 253 253 253
40967 -253 253 253 253 253 253 253 253 253 253 253 253
40968 -253 253 253 253 253 253 253 253 253 253 253 253
40969 -253 253 253 253 253 253 253 253 253 253 253 253
40970 -253 253 253 253 253 253 234 234 234 10 10 10
40971 - 2 2 6 2 2 6 22 22 22 14 14 14
40972 - 2 2 6 2 2 6 2 2 6 2 2 6
40973 - 2 2 6 66 66 66 62 62 62 22 22 22
40974 - 6 6 6 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 0 0 0
40977 - 0 0 0 0 0 0 0 0 0 0 0 0
40978 - 0 0 0 0 0 0 0 0 0 0 0 0
40979 - 0 0 0 0 0 0 0 0 0 0 0 0
40980 - 0 0 0 0 0 0 6 6 6 18 18 18
40981 - 50 50 50 74 74 74 2 2 6 2 2 6
40982 - 14 14 14 70 70 70 34 34 34 62 62 62
40983 -250 250 250 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 231 231 231 246 246 246
40986 -253 253 253 253 253 253 253 253 253 253 253 253
40987 -253 253 253 253 253 253 253 253 253 253 253 253
40988 -253 253 253 253 253 253 253 253 253 253 253 253
40989 -253 253 253 253 253 253 253 253 253 253 253 253
40990 -253 253 253 253 253 253 234 234 234 14 14 14
40991 - 2 2 6 2 2 6 30 30 30 2 2 6
40992 - 2 2 6 2 2 6 2 2 6 2 2 6
40993 - 2 2 6 66 66 66 62 62 62 22 22 22
40994 - 6 6 6 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 0 0 0 0 0 0
40997 - 0 0 0 0 0 0 0 0 0 0 0 0
40998 - 0 0 0 0 0 0 0 0 0 0 0 0
40999 - 0 0 0 0 0 0 0 0 0 0 0 0
41000 - 0 0 0 0 0 0 6 6 6 18 18 18
41001 - 54 54 54 62 62 62 2 2 6 2 2 6
41002 - 2 2 6 30 30 30 46 46 46 70 70 70
41003 -250 250 250 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 231 231 231 246 246 246
41006 -253 253 253 253 253 253 253 253 253 253 253 253
41007 -253 253 253 253 253 253 253 253 253 253 253 253
41008 -253 253 253 253 253 253 253 253 253 253 253 253
41009 -253 253 253 253 253 253 253 253 253 253 253 253
41010 -253 253 253 253 253 253 226 226 226 10 10 10
41011 - 2 2 6 6 6 6 30 30 30 2 2 6
41012 - 2 2 6 2 2 6 2 2 6 2 2 6
41013 - 2 2 6 66 66 66 58 58 58 22 22 22
41014 - 6 6 6 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 0 0 0 0 0 0
41017 - 0 0 0 0 0 0 0 0 0 0 0 0
41018 - 0 0 0 0 0 0 0 0 0 0 0 0
41019 - 0 0 0 0 0 0 0 0 0 0 0 0
41020 - 0 0 0 0 0 0 6 6 6 22 22 22
41021 - 58 58 58 62 62 62 2 2 6 2 2 6
41022 - 2 2 6 2 2 6 30 30 30 78 78 78
41023 -250 250 250 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 231 231 231 246 246 246
41026 -253 253 253 253 253 253 253 253 253 253 253 253
41027 -253 253 253 253 253 253 253 253 253 253 253 253
41028 -253 253 253 253 253 253 253 253 253 253 253 253
41029 -253 253 253 253 253 253 253 253 253 253 253 253
41030 -253 253 253 253 253 253 206 206 206 2 2 6
41031 - 22 22 22 34 34 34 18 14 6 22 22 22
41032 - 26 26 26 18 18 18 6 6 6 2 2 6
41033 - 2 2 6 82 82 82 54 54 54 18 18 18
41034 - 6 6 6 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 0 0 0 0 0 0
41037 - 0 0 0 0 0 0 0 0 0 0 0 0
41038 - 0 0 0 0 0 0 0 0 0 0 0 0
41039 - 0 0 0 0 0 0 0 0 0 0 0 0
41040 - 0 0 0 0 0 0 6 6 6 26 26 26
41041 - 62 62 62 106 106 106 74 54 14 185 133 11
41042 -210 162 10 121 92 8 6 6 6 62 62 62
41043 -238 238 238 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 231 231 231 246 246 246
41046 -253 253 253 253 253 253 253 253 253 253 253 253
41047 -253 253 253 253 253 253 253 253 253 253 253 253
41048 -253 253 253 253 253 253 253 253 253 253 253 253
41049 -253 253 253 253 253 253 253 253 253 253 253 253
41050 -253 253 253 253 253 253 158 158 158 18 18 18
41051 - 14 14 14 2 2 6 2 2 6 2 2 6
41052 - 6 6 6 18 18 18 66 66 66 38 38 38
41053 - 6 6 6 94 94 94 50 50 50 18 18 18
41054 - 6 6 6 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 0 0 0 0 0 0
41057 - 0 0 0 0 0 0 0 0 0 0 0 0
41058 - 0 0 0 0 0 0 0 0 0 0 0 0
41059 - 0 0 0 0 0 0 0 0 0 6 6 6
41060 - 10 10 10 10 10 10 18 18 18 38 38 38
41061 - 78 78 78 142 134 106 216 158 10 242 186 14
41062 -246 190 14 246 190 14 156 118 10 10 10 10
41063 - 90 90 90 238 238 238 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 231 231 231 250 250 250
41066 -253 253 253 253 253 253 253 253 253 253 253 253
41067 -253 253 253 253 253 253 253 253 253 253 253 253
41068 -253 253 253 253 253 253 253 253 253 253 253 253
41069 -253 253 253 253 253 253 253 253 253 246 230 190
41070 -238 204 91 238 204 91 181 142 44 37 26 9
41071 - 2 2 6 2 2 6 2 2 6 2 2 6
41072 - 2 2 6 2 2 6 38 38 38 46 46 46
41073 - 26 26 26 106 106 106 54 54 54 18 18 18
41074 - 6 6 6 0 0 0 0 0 0 0 0 0
41075 - 0 0 0 0 0 0 0 0 0 0 0 0
41076 - 0 0 0 0 0 0 0 0 0 0 0 0
41077 - 0 0 0 0 0 0 0 0 0 0 0 0
41078 - 0 0 0 0 0 0 0 0 0 0 0 0
41079 - 0 0 0 6 6 6 14 14 14 22 22 22
41080 - 30 30 30 38 38 38 50 50 50 70 70 70
41081 -106 106 106 190 142 34 226 170 11 242 186 14
41082 -246 190 14 246 190 14 246 190 14 154 114 10
41083 - 6 6 6 74 74 74 226 226 226 253 253 253
41084 -253 253 253 253 253 253 253 253 253 253 253 253
41085 -253 253 253 253 253 253 231 231 231 250 250 250
41086 -253 253 253 253 253 253 253 253 253 253 253 253
41087 -253 253 253 253 253 253 253 253 253 253 253 253
41088 -253 253 253 253 253 253 253 253 253 253 253 253
41089 -253 253 253 253 253 253 253 253 253 228 184 62
41090 -241 196 14 241 208 19 232 195 16 38 30 10
41091 - 2 2 6 2 2 6 2 2 6 2 2 6
41092 - 2 2 6 6 6 6 30 30 30 26 26 26
41093 -203 166 17 154 142 90 66 66 66 26 26 26
41094 - 6 6 6 0 0 0 0 0 0 0 0 0
41095 - 0 0 0 0 0 0 0 0 0 0 0 0
41096 - 0 0 0 0 0 0 0 0 0 0 0 0
41097 - 0 0 0 0 0 0 0 0 0 0 0 0
41098 - 0 0 0 0 0 0 0 0 0 0 0 0
41099 - 6 6 6 18 18 18 38 38 38 58 58 58
41100 - 78 78 78 86 86 86 101 101 101 123 123 123
41101 -175 146 61 210 150 10 234 174 13 246 186 14
41102 -246 190 14 246 190 14 246 190 14 238 190 10
41103 -102 78 10 2 2 6 46 46 46 198 198 198
41104 -253 253 253 253 253 253 253 253 253 253 253 253
41105 -253 253 253 253 253 253 234 234 234 242 242 242
41106 -253 253 253 253 253 253 253 253 253 253 253 253
41107 -253 253 253 253 253 253 253 253 253 253 253 253
41108 -253 253 253 253 253 253 253 253 253 253 253 253
41109 -253 253 253 253 253 253 253 253 253 224 178 62
41110 -242 186 14 241 196 14 210 166 10 22 18 6
41111 - 2 2 6 2 2 6 2 2 6 2 2 6
41112 - 2 2 6 2 2 6 6 6 6 121 92 8
41113 -238 202 15 232 195 16 82 82 82 34 34 34
41114 - 10 10 10 0 0 0 0 0 0 0 0 0
41115 - 0 0 0 0 0 0 0 0 0 0 0 0
41116 - 0 0 0 0 0 0 0 0 0 0 0 0
41117 - 0 0 0 0 0 0 0 0 0 0 0 0
41118 - 0 0 0 0 0 0 0 0 0 0 0 0
41119 - 14 14 14 38 38 38 70 70 70 154 122 46
41120 -190 142 34 200 144 11 197 138 11 197 138 11
41121 -213 154 11 226 170 11 242 186 14 246 190 14
41122 -246 190 14 246 190 14 246 190 14 246 190 14
41123 -225 175 15 46 32 6 2 2 6 22 22 22
41124 -158 158 158 250 250 250 253 253 253 253 253 253
41125 -253 253 253 253 253 253 253 253 253 253 253 253
41126 -253 253 253 253 253 253 253 253 253 253 253 253
41127 -253 253 253 253 253 253 253 253 253 253 253 253
41128 -253 253 253 253 253 253 253 253 253 253 253 253
41129 -253 253 253 250 250 250 242 242 242 224 178 62
41130 -239 182 13 236 186 11 213 154 11 46 32 6
41131 - 2 2 6 2 2 6 2 2 6 2 2 6
41132 - 2 2 6 2 2 6 61 42 6 225 175 15
41133 -238 190 10 236 186 11 112 100 78 42 42 42
41134 - 14 14 14 0 0 0 0 0 0 0 0 0
41135 - 0 0 0 0 0 0 0 0 0 0 0 0
41136 - 0 0 0 0 0 0 0 0 0 0 0 0
41137 - 0 0 0 0 0 0 0 0 0 0 0 0
41138 - 0 0 0 0 0 0 0 0 0 6 6 6
41139 - 22 22 22 54 54 54 154 122 46 213 154 11
41140 -226 170 11 230 174 11 226 170 11 226 170 11
41141 -236 178 12 242 186 14 246 190 14 246 190 14
41142 -246 190 14 246 190 14 246 190 14 246 190 14
41143 -241 196 14 184 144 12 10 10 10 2 2 6
41144 - 6 6 6 116 116 116 242 242 242 253 253 253
41145 -253 253 253 253 253 253 253 253 253 253 253 253
41146 -253 253 253 253 253 253 253 253 253 253 253 253
41147 -253 253 253 253 253 253 253 253 253 253 253 253
41148 -253 253 253 253 253 253 253 253 253 253 253 253
41149 -253 253 253 231 231 231 198 198 198 214 170 54
41150 -236 178 12 236 178 12 210 150 10 137 92 6
41151 - 18 14 6 2 2 6 2 2 6 2 2 6
41152 - 6 6 6 70 47 6 200 144 11 236 178 12
41153 -239 182 13 239 182 13 124 112 88 58 58 58
41154 - 22 22 22 6 6 6 0 0 0 0 0 0
41155 - 0 0 0 0 0 0 0 0 0 0 0 0
41156 - 0 0 0 0 0 0 0 0 0 0 0 0
41157 - 0 0 0 0 0 0 0 0 0 0 0 0
41158 - 0 0 0 0 0 0 0 0 0 10 10 10
41159 - 30 30 30 70 70 70 180 133 36 226 170 11
41160 -239 182 13 242 186 14 242 186 14 246 186 14
41161 -246 190 14 246 190 14 246 190 14 246 190 14
41162 -246 190 14 246 190 14 246 190 14 246 190 14
41163 -246 190 14 232 195 16 98 70 6 2 2 6
41164 - 2 2 6 2 2 6 66 66 66 221 221 221
41165 -253 253 253 253 253 253 253 253 253 253 253 253
41166 -253 253 253 253 253 253 253 253 253 253 253 253
41167 -253 253 253 253 253 253 253 253 253 253 253 253
41168 -253 253 253 253 253 253 253 253 253 253 253 253
41169 -253 253 253 206 206 206 198 198 198 214 166 58
41170 -230 174 11 230 174 11 216 158 10 192 133 9
41171 -163 110 8 116 81 8 102 78 10 116 81 8
41172 -167 114 7 197 138 11 226 170 11 239 182 13
41173 -242 186 14 242 186 14 162 146 94 78 78 78
41174 - 34 34 34 14 14 14 6 6 6 0 0 0
41175 - 0 0 0 0 0 0 0 0 0 0 0 0
41176 - 0 0 0 0 0 0 0 0 0 0 0 0
41177 - 0 0 0 0 0 0 0 0 0 0 0 0
41178 - 0 0 0 0 0 0 0 0 0 6 6 6
41179 - 30 30 30 78 78 78 190 142 34 226 170 11
41180 -239 182 13 246 190 14 246 190 14 246 190 14
41181 -246 190 14 246 190 14 246 190 14 246 190 14
41182 -246 190 14 246 190 14 246 190 14 246 190 14
41183 -246 190 14 241 196 14 203 166 17 22 18 6
41184 - 2 2 6 2 2 6 2 2 6 38 38 38
41185 -218 218 218 253 253 253 253 253 253 253 253 253
41186 -253 253 253 253 253 253 253 253 253 253 253 253
41187 -253 253 253 253 253 253 253 253 253 253 253 253
41188 -253 253 253 253 253 253 253 253 253 253 253 253
41189 -250 250 250 206 206 206 198 198 198 202 162 69
41190 -226 170 11 236 178 12 224 166 10 210 150 10
41191 -200 144 11 197 138 11 192 133 9 197 138 11
41192 -210 150 10 226 170 11 242 186 14 246 190 14
41193 -246 190 14 246 186 14 225 175 15 124 112 88
41194 - 62 62 62 30 30 30 14 14 14 6 6 6
41195 - 0 0 0 0 0 0 0 0 0 0 0 0
41196 - 0 0 0 0 0 0 0 0 0 0 0 0
41197 - 0 0 0 0 0 0 0 0 0 0 0 0
41198 - 0 0 0 0 0 0 0 0 0 10 10 10
41199 - 30 30 30 78 78 78 174 135 50 224 166 10
41200 -239 182 13 246 190 14 246 190 14 246 190 14
41201 -246 190 14 246 190 14 246 190 14 246 190 14
41202 -246 190 14 246 190 14 246 190 14 246 190 14
41203 -246 190 14 246 190 14 241 196 14 139 102 15
41204 - 2 2 6 2 2 6 2 2 6 2 2 6
41205 - 78 78 78 250 250 250 253 253 253 253 253 253
41206 -253 253 253 253 253 253 253 253 253 253 253 253
41207 -253 253 253 253 253 253 253 253 253 253 253 253
41208 -253 253 253 253 253 253 253 253 253 253 253 253
41209 -250 250 250 214 214 214 198 198 198 190 150 46
41210 -219 162 10 236 178 12 234 174 13 224 166 10
41211 -216 158 10 213 154 11 213 154 11 216 158 10
41212 -226 170 11 239 182 13 246 190 14 246 190 14
41213 -246 190 14 246 190 14 242 186 14 206 162 42
41214 -101 101 101 58 58 58 30 30 30 14 14 14
41215 - 6 6 6 0 0 0 0 0 0 0 0 0
41216 - 0 0 0 0 0 0 0 0 0 0 0 0
41217 - 0 0 0 0 0 0 0 0 0 0 0 0
41218 - 0 0 0 0 0 0 0 0 0 10 10 10
41219 - 30 30 30 74 74 74 174 135 50 216 158 10
41220 -236 178 12 246 190 14 246 190 14 246 190 14
41221 -246 190 14 246 190 14 246 190 14 246 190 14
41222 -246 190 14 246 190 14 246 190 14 246 190 14
41223 -246 190 14 246 190 14 241 196 14 226 184 13
41224 - 61 42 6 2 2 6 2 2 6 2 2 6
41225 - 22 22 22 238 238 238 253 253 253 253 253 253
41226 -253 253 253 253 253 253 253 253 253 253 253 253
41227 -253 253 253 253 253 253 253 253 253 253 253 253
41228 -253 253 253 253 253 253 253 253 253 253 253 253
41229 -253 253 253 226 226 226 187 187 187 180 133 36
41230 -216 158 10 236 178 12 239 182 13 236 178 12
41231 -230 174 11 226 170 11 226 170 11 230 174 11
41232 -236 178 12 242 186 14 246 190 14 246 190 14
41233 -246 190 14 246 190 14 246 186 14 239 182 13
41234 -206 162 42 106 106 106 66 66 66 34 34 34
41235 - 14 14 14 6 6 6 0 0 0 0 0 0
41236 - 0 0 0 0 0 0 0 0 0 0 0 0
41237 - 0 0 0 0 0 0 0 0 0 0 0 0
41238 - 0 0 0 0 0 0 0 0 0 6 6 6
41239 - 26 26 26 70 70 70 163 133 67 213 154 11
41240 -236 178 12 246 190 14 246 190 14 246 190 14
41241 -246 190 14 246 190 14 246 190 14 246 190 14
41242 -246 190 14 246 190 14 246 190 14 246 190 14
41243 -246 190 14 246 190 14 246 190 14 241 196 14
41244 -190 146 13 18 14 6 2 2 6 2 2 6
41245 - 46 46 46 246 246 246 253 253 253 253 253 253
41246 -253 253 253 253 253 253 253 253 253 253 253 253
41247 -253 253 253 253 253 253 253 253 253 253 253 253
41248 -253 253 253 253 253 253 253 253 253 253 253 253
41249 -253 253 253 221 221 221 86 86 86 156 107 11
41250 -216 158 10 236 178 12 242 186 14 246 186 14
41251 -242 186 14 239 182 13 239 182 13 242 186 14
41252 -242 186 14 246 186 14 246 190 14 246 190 14
41253 -246 190 14 246 190 14 246 190 14 246 190 14
41254 -242 186 14 225 175 15 142 122 72 66 66 66
41255 - 30 30 30 10 10 10 0 0 0 0 0 0
41256 - 0 0 0 0 0 0 0 0 0 0 0 0
41257 - 0 0 0 0 0 0 0 0 0 0 0 0
41258 - 0 0 0 0 0 0 0 0 0 6 6 6
41259 - 26 26 26 70 70 70 163 133 67 210 150 10
41260 -236 178 12 246 190 14 246 190 14 246 190 14
41261 -246 190 14 246 190 14 246 190 14 246 190 14
41262 -246 190 14 246 190 14 246 190 14 246 190 14
41263 -246 190 14 246 190 14 246 190 14 246 190 14
41264 -232 195 16 121 92 8 34 34 34 106 106 106
41265 -221 221 221 253 253 253 253 253 253 253 253 253
41266 -253 253 253 253 253 253 253 253 253 253 253 253
41267 -253 253 253 253 253 253 253 253 253 253 253 253
41268 -253 253 253 253 253 253 253 253 253 253 253 253
41269 -242 242 242 82 82 82 18 14 6 163 110 8
41270 -216 158 10 236 178 12 242 186 14 246 190 14
41271 -246 190 14 246 190 14 246 190 14 246 190 14
41272 -246 190 14 246 190 14 246 190 14 246 190 14
41273 -246 190 14 246 190 14 246 190 14 246 190 14
41274 -246 190 14 246 190 14 242 186 14 163 133 67
41275 - 46 46 46 18 18 18 6 6 6 0 0 0
41276 - 0 0 0 0 0 0 0 0 0 0 0 0
41277 - 0 0 0 0 0 0 0 0 0 0 0 0
41278 - 0 0 0 0 0 0 0 0 0 10 10 10
41279 - 30 30 30 78 78 78 163 133 67 210 150 10
41280 -236 178 12 246 186 14 246 190 14 246 190 14
41281 -246 190 14 246 190 14 246 190 14 246 190 14
41282 -246 190 14 246 190 14 246 190 14 246 190 14
41283 -246 190 14 246 190 14 246 190 14 246 190 14
41284 -241 196 14 215 174 15 190 178 144 253 253 253
41285 -253 253 253 253 253 253 253 253 253 253 253 253
41286 -253 253 253 253 253 253 253 253 253 253 253 253
41287 -253 253 253 253 253 253 253 253 253 253 253 253
41288 -253 253 253 253 253 253 253 253 253 218 218 218
41289 - 58 58 58 2 2 6 22 18 6 167 114 7
41290 -216 158 10 236 178 12 246 186 14 246 190 14
41291 -246 190 14 246 190 14 246 190 14 246 190 14
41292 -246 190 14 246 190 14 246 190 14 246 190 14
41293 -246 190 14 246 190 14 246 190 14 246 190 14
41294 -246 190 14 246 186 14 242 186 14 190 150 46
41295 - 54 54 54 22 22 22 6 6 6 0 0 0
41296 - 0 0 0 0 0 0 0 0 0 0 0 0
41297 - 0 0 0 0 0 0 0 0 0 0 0 0
41298 - 0 0 0 0 0 0 0 0 0 14 14 14
41299 - 38 38 38 86 86 86 180 133 36 213 154 11
41300 -236 178 12 246 186 14 246 190 14 246 190 14
41301 -246 190 14 246 190 14 246 190 14 246 190 14
41302 -246 190 14 246 190 14 246 190 14 246 190 14
41303 -246 190 14 246 190 14 246 190 14 246 190 14
41304 -246 190 14 232 195 16 190 146 13 214 214 214
41305 -253 253 253 253 253 253 253 253 253 253 253 253
41306 -253 253 253 253 253 253 253 253 253 253 253 253
41307 -253 253 253 253 253 253 253 253 253 253 253 253
41308 -253 253 253 250 250 250 170 170 170 26 26 26
41309 - 2 2 6 2 2 6 37 26 9 163 110 8
41310 -219 162 10 239 182 13 246 186 14 246 190 14
41311 -246 190 14 246 190 14 246 190 14 246 190 14
41312 -246 190 14 246 190 14 246 190 14 246 190 14
41313 -246 190 14 246 190 14 246 190 14 246 190 14
41314 -246 186 14 236 178 12 224 166 10 142 122 72
41315 - 46 46 46 18 18 18 6 6 6 0 0 0
41316 - 0 0 0 0 0 0 0 0 0 0 0 0
41317 - 0 0 0 0 0 0 0 0 0 0 0 0
41318 - 0 0 0 0 0 0 6 6 6 18 18 18
41319 - 50 50 50 109 106 95 192 133 9 224 166 10
41320 -242 186 14 246 190 14 246 190 14 246 190 14
41321 -246 190 14 246 190 14 246 190 14 246 190 14
41322 -246 190 14 246 190 14 246 190 14 246 190 14
41323 -246 190 14 246 190 14 246 190 14 246 190 14
41324 -242 186 14 226 184 13 210 162 10 142 110 46
41325 -226 226 226 253 253 253 253 253 253 253 253 253
41326 -253 253 253 253 253 253 253 253 253 253 253 253
41327 -253 253 253 253 253 253 253 253 253 253 253 253
41328 -198 198 198 66 66 66 2 2 6 2 2 6
41329 - 2 2 6 2 2 6 50 34 6 156 107 11
41330 -219 162 10 239 182 13 246 186 14 246 190 14
41331 -246 190 14 246 190 14 246 190 14 246 190 14
41332 -246 190 14 246 190 14 246 190 14 246 190 14
41333 -246 190 14 246 190 14 246 190 14 242 186 14
41334 -234 174 13 213 154 11 154 122 46 66 66 66
41335 - 30 30 30 10 10 10 0 0 0 0 0 0
41336 - 0 0 0 0 0 0 0 0 0 0 0 0
41337 - 0 0 0 0 0 0 0 0 0 0 0 0
41338 - 0 0 0 0 0 0 6 6 6 22 22 22
41339 - 58 58 58 154 121 60 206 145 10 234 174 13
41340 -242 186 14 246 186 14 246 190 14 246 190 14
41341 -246 190 14 246 190 14 246 190 14 246 190 14
41342 -246 190 14 246 190 14 246 190 14 246 190 14
41343 -246 190 14 246 190 14 246 190 14 246 190 14
41344 -246 186 14 236 178 12 210 162 10 163 110 8
41345 - 61 42 6 138 138 138 218 218 218 250 250 250
41346 -253 253 253 253 253 253 253 253 253 250 250 250
41347 -242 242 242 210 210 210 144 144 144 66 66 66
41348 - 6 6 6 2 2 6 2 2 6 2 2 6
41349 - 2 2 6 2 2 6 61 42 6 163 110 8
41350 -216 158 10 236 178 12 246 190 14 246 190 14
41351 -246 190 14 246 190 14 246 190 14 246 190 14
41352 -246 190 14 246 190 14 246 190 14 246 190 14
41353 -246 190 14 239 182 13 230 174 11 216 158 10
41354 -190 142 34 124 112 88 70 70 70 38 38 38
41355 - 18 18 18 6 6 6 0 0 0 0 0 0
41356 - 0 0 0 0 0 0 0 0 0 0 0 0
41357 - 0 0 0 0 0 0 0 0 0 0 0 0
41358 - 0 0 0 0 0 0 6 6 6 22 22 22
41359 - 62 62 62 168 124 44 206 145 10 224 166 10
41360 -236 178 12 239 182 13 242 186 14 242 186 14
41361 -246 186 14 246 190 14 246 190 14 246 190 14
41362 -246 190 14 246 190 14 246 190 14 246 190 14
41363 -246 190 14 246 190 14 246 190 14 246 190 14
41364 -246 190 14 236 178 12 216 158 10 175 118 6
41365 - 80 54 7 2 2 6 6 6 6 30 30 30
41366 - 54 54 54 62 62 62 50 50 50 38 38 38
41367 - 14 14 14 2 2 6 2 2 6 2 2 6
41368 - 2 2 6 2 2 6 2 2 6 2 2 6
41369 - 2 2 6 6 6 6 80 54 7 167 114 7
41370 -213 154 11 236 178 12 246 190 14 246 190 14
41371 -246 190 14 246 190 14 246 190 14 246 190 14
41372 -246 190 14 242 186 14 239 182 13 239 182 13
41373 -230 174 11 210 150 10 174 135 50 124 112 88
41374 - 82 82 82 54 54 54 34 34 34 18 18 18
41375 - 6 6 6 0 0 0 0 0 0 0 0 0
41376 - 0 0 0 0 0 0 0 0 0 0 0 0
41377 - 0 0 0 0 0 0 0 0 0 0 0 0
41378 - 0 0 0 0 0 0 6 6 6 18 18 18
41379 - 50 50 50 158 118 36 192 133 9 200 144 11
41380 -216 158 10 219 162 10 224 166 10 226 170 11
41381 -230 174 11 236 178 12 239 182 13 239 182 13
41382 -242 186 14 246 186 14 246 190 14 246 190 14
41383 -246 190 14 246 190 14 246 190 14 246 190 14
41384 -246 186 14 230 174 11 210 150 10 163 110 8
41385 -104 69 6 10 10 10 2 2 6 2 2 6
41386 - 2 2 6 2 2 6 2 2 6 2 2 6
41387 - 2 2 6 2 2 6 2 2 6 2 2 6
41388 - 2 2 6 2 2 6 2 2 6 2 2 6
41389 - 2 2 6 6 6 6 91 60 6 167 114 7
41390 -206 145 10 230 174 11 242 186 14 246 190 14
41391 -246 190 14 246 190 14 246 186 14 242 186 14
41392 -239 182 13 230 174 11 224 166 10 213 154 11
41393 -180 133 36 124 112 88 86 86 86 58 58 58
41394 - 38 38 38 22 22 22 10 10 10 6 6 6
41395 - 0 0 0 0 0 0 0 0 0 0 0 0
41396 - 0 0 0 0 0 0 0 0 0 0 0 0
41397 - 0 0 0 0 0 0 0 0 0 0 0 0
41398 - 0 0 0 0 0 0 0 0 0 14 14 14
41399 - 34 34 34 70 70 70 138 110 50 158 118 36
41400 -167 114 7 180 123 7 192 133 9 197 138 11
41401 -200 144 11 206 145 10 213 154 11 219 162 10
41402 -224 166 10 230 174 11 239 182 13 242 186 14
41403 -246 186 14 246 186 14 246 186 14 246 186 14
41404 -239 182 13 216 158 10 185 133 11 152 99 6
41405 -104 69 6 18 14 6 2 2 6 2 2 6
41406 - 2 2 6 2 2 6 2 2 6 2 2 6
41407 - 2 2 6 2 2 6 2 2 6 2 2 6
41408 - 2 2 6 2 2 6 2 2 6 2 2 6
41409 - 2 2 6 6 6 6 80 54 7 152 99 6
41410 -192 133 9 219 162 10 236 178 12 239 182 13
41411 -246 186 14 242 186 14 239 182 13 236 178 12
41412 -224 166 10 206 145 10 192 133 9 154 121 60
41413 - 94 94 94 62 62 62 42 42 42 22 22 22
41414 - 14 14 14 6 6 6 0 0 0 0 0 0
41415 - 0 0 0 0 0 0 0 0 0 0 0 0
41416 - 0 0 0 0 0 0 0 0 0 0 0 0
41417 - 0 0 0 0 0 0 0 0 0 0 0 0
41418 - 0 0 0 0 0 0 0 0 0 6 6 6
41419 - 18 18 18 34 34 34 58 58 58 78 78 78
41420 -101 98 89 124 112 88 142 110 46 156 107 11
41421 -163 110 8 167 114 7 175 118 6 180 123 7
41422 -185 133 11 197 138 11 210 150 10 219 162 10
41423 -226 170 11 236 178 12 236 178 12 234 174 13
41424 -219 162 10 197 138 11 163 110 8 130 83 6
41425 - 91 60 6 10 10 10 2 2 6 2 2 6
41426 - 18 18 18 38 38 38 38 38 38 38 38 38
41427 - 38 38 38 38 38 38 38 38 38 38 38 38
41428 - 38 38 38 38 38 38 26 26 26 2 2 6
41429 - 2 2 6 6 6 6 70 47 6 137 92 6
41430 -175 118 6 200 144 11 219 162 10 230 174 11
41431 -234 174 13 230 174 11 219 162 10 210 150 10
41432 -192 133 9 163 110 8 124 112 88 82 82 82
41433 - 50 50 50 30 30 30 14 14 14 6 6 6
41434 - 0 0 0 0 0 0 0 0 0 0 0 0
41435 - 0 0 0 0 0 0 0 0 0 0 0 0
41436 - 0 0 0 0 0 0 0 0 0 0 0 0
41437 - 0 0 0 0 0 0 0 0 0 0 0 0
41438 - 0 0 0 0 0 0 0 0 0 0 0 0
41439 - 6 6 6 14 14 14 22 22 22 34 34 34
41440 - 42 42 42 58 58 58 74 74 74 86 86 86
41441 -101 98 89 122 102 70 130 98 46 121 87 25
41442 -137 92 6 152 99 6 163 110 8 180 123 7
41443 -185 133 11 197 138 11 206 145 10 200 144 11
41444 -180 123 7 156 107 11 130 83 6 104 69 6
41445 - 50 34 6 54 54 54 110 110 110 101 98 89
41446 - 86 86 86 82 82 82 78 78 78 78 78 78
41447 - 78 78 78 78 78 78 78 78 78 78 78 78
41448 - 78 78 78 82 82 82 86 86 86 94 94 94
41449 -106 106 106 101 101 101 86 66 34 124 80 6
41450 -156 107 11 180 123 7 192 133 9 200 144 11
41451 -206 145 10 200 144 11 192 133 9 175 118 6
41452 -139 102 15 109 106 95 70 70 70 42 42 42
41453 - 22 22 22 10 10 10 0 0 0 0 0 0
41454 - 0 0 0 0 0 0 0 0 0 0 0 0
41455 - 0 0 0 0 0 0 0 0 0 0 0 0
41456 - 0 0 0 0 0 0 0 0 0 0 0 0
41457 - 0 0 0 0 0 0 0 0 0 0 0 0
41458 - 0 0 0 0 0 0 0 0 0 0 0 0
41459 - 0 0 0 0 0 0 6 6 6 10 10 10
41460 - 14 14 14 22 22 22 30 30 30 38 38 38
41461 - 50 50 50 62 62 62 74 74 74 90 90 90
41462 -101 98 89 112 100 78 121 87 25 124 80 6
41463 -137 92 6 152 99 6 152 99 6 152 99 6
41464 -138 86 6 124 80 6 98 70 6 86 66 30
41465 -101 98 89 82 82 82 58 58 58 46 46 46
41466 - 38 38 38 34 34 34 34 34 34 34 34 34
41467 - 34 34 34 34 34 34 34 34 34 34 34 34
41468 - 34 34 34 34 34 34 38 38 38 42 42 42
41469 - 54 54 54 82 82 82 94 86 76 91 60 6
41470 -134 86 6 156 107 11 167 114 7 175 118 6
41471 -175 118 6 167 114 7 152 99 6 121 87 25
41472 -101 98 89 62 62 62 34 34 34 18 18 18
41473 - 6 6 6 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 0 0 0 0 0 0
41476 - 0 0 0 0 0 0 0 0 0 0 0 0
41477 - 0 0 0 0 0 0 0 0 0 0 0 0
41478 - 0 0 0 0 0 0 0 0 0 0 0 0
41479 - 0 0 0 0 0 0 0 0 0 0 0 0
41480 - 0 0 0 6 6 6 6 6 6 10 10 10
41481 - 18 18 18 22 22 22 30 30 30 42 42 42
41482 - 50 50 50 66 66 66 86 86 86 101 98 89
41483 -106 86 58 98 70 6 104 69 6 104 69 6
41484 -104 69 6 91 60 6 82 62 34 90 90 90
41485 - 62 62 62 38 38 38 22 22 22 14 14 14
41486 - 10 10 10 10 10 10 10 10 10 10 10 10
41487 - 10 10 10 10 10 10 6 6 6 10 10 10
41488 - 10 10 10 10 10 10 10 10 10 14 14 14
41489 - 22 22 22 42 42 42 70 70 70 89 81 66
41490 - 80 54 7 104 69 6 124 80 6 137 92 6
41491 -134 86 6 116 81 8 100 82 52 86 86 86
41492 - 58 58 58 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0 0 0 0
41497 - 0 0 0 0 0 0 0 0 0 0 0 0
41498 - 0 0 0 0 0 0 0 0 0 0 0 0
41499 - 0 0 0 0 0 0 0 0 0 0 0 0
41500 - 0 0 0 0 0 0 0 0 0 0 0 0
41501 - 0 0 0 6 6 6 10 10 10 14 14 14
41502 - 18 18 18 26 26 26 38 38 38 54 54 54
41503 - 70 70 70 86 86 86 94 86 76 89 81 66
41504 - 89 81 66 86 86 86 74 74 74 50 50 50
41505 - 30 30 30 14 14 14 6 6 6 0 0 0
41506 - 0 0 0 0 0 0 0 0 0 0 0 0
41507 - 0 0 0 0 0 0 0 0 0 0 0 0
41508 - 0 0 0 0 0 0 0 0 0 0 0 0
41509 - 6 6 6 18 18 18 34 34 34 58 58 58
41510 - 82 82 82 89 81 66 89 81 66 89 81 66
41511 - 94 86 66 94 86 76 74 74 74 50 50 50
41512 - 26 26 26 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0
41518 - 0 0 0 0 0 0 0 0 0 0 0 0
41519 - 0 0 0 0 0 0 0 0 0 0 0 0
41520 - 0 0 0 0 0 0 0 0 0 0 0 0
41521 - 0 0 0 0 0 0 0 0 0 0 0 0
41522 - 6 6 6 6 6 6 14 14 14 18 18 18
41523 - 30 30 30 38 38 38 46 46 46 54 54 54
41524 - 50 50 50 42 42 42 30 30 30 18 18 18
41525 - 10 10 10 0 0 0 0 0 0 0 0 0
41526 - 0 0 0 0 0 0 0 0 0 0 0 0
41527 - 0 0 0 0 0 0 0 0 0 0 0 0
41528 - 0 0 0 0 0 0 0 0 0 0 0 0
41529 - 0 0 0 6 6 6 14 14 14 26 26 26
41530 - 38 38 38 50 50 50 58 58 58 58 58 58
41531 - 54 54 54 42 42 42 30 30 30 18 18 18
41532 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
41539 - 0 0 0 0 0 0 0 0 0 0 0 0
41540 - 0 0 0 0 0 0 0 0 0 0 0 0
41541 - 0 0 0 0 0 0 0 0 0 0 0 0
41542 - 0 0 0 0 0 0 0 0 0 6 6 6
41543 - 6 6 6 10 10 10 14 14 14 18 18 18
41544 - 18 18 18 14 14 14 10 10 10 6 6 6
41545 - 0 0 0 0 0 0 0 0 0 0 0 0
41546 - 0 0 0 0 0 0 0 0 0 0 0 0
41547 - 0 0 0 0 0 0 0 0 0 0 0 0
41548 - 0 0 0 0 0 0 0 0 0 0 0 0
41549 - 0 0 0 0 0 0 0 0 0 6 6 6
41550 - 14 14 14 18 18 18 22 22 22 22 22 22
41551 - 18 18 18 14 14 14 10 10 10 6 6 6
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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41566 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41570 +4 4 4 4 4 4
41571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41574 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
41587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41588 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
41601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41602 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
41615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41616 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
41629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41630 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
41643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41645 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41646 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
41651 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41652 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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 4 4 4 4 4 4 4 4 4 4 4 4
41657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41659 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41660 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41661 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 1 1 1 6 6 6
41665 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41666 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41667 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41668 +4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
41671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41673 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41674 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41675 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41678 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41679 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41680 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41681 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41682 +4 4 4 4 4 4
41683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41686 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41687 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41688 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41689 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41691 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41692 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41693 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41694 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41695 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41696 +4 4 4 4 4 4
41697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41700 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41701 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41702 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41703 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41704 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41705 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41706 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41707 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41708 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41709 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41710 +4 4 4 4 4 4
41711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41714 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41715 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41716 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41717 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41718 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41719 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41720 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41721 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41722 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41723 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41724 +4 4 4 4 4 4
41725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41727 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41728 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41729 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41730 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41731 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41732 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41733 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41734 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41735 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41736 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41737 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41738 +4 4 4 4 4 4
41739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41741 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41742 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41743 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41744 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41745 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41746 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41747 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41748 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41749 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41750 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41751 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41752 +4 4 4 4 4 4
41753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41755 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41756 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41757 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41758 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41759 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41760 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41761 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41762 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41763 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41764 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41765 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41766 +4 4 4 4 4 4
41767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41769 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41770 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41771 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41772 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41773 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41774 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41775 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41776 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41777 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41778 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41779 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41780 +4 4 4 4 4 4
41781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41782 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41783 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41784 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41785 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41786 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41787 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41788 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41789 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41790 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41791 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41792 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41793 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41794 +4 4 4 4 4 4
41795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41796 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41797 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41798 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41799 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41800 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41801 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41802 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41803 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41804 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41805 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41806 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41807 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41808 +0 0 0 4 4 4
41809 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41810 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41811 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41812 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41813 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41814 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41815 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41816 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41817 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41818 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41819 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41820 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41821 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41822 +2 0 0 0 0 0
41823 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41824 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41825 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41826 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41827 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41828 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41829 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41830 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41831 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41832 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41833 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41834 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41835 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41836 +37 38 37 0 0 0
41837 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41838 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41839 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41840 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41841 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41842 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41843 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41844 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41845 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41846 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41847 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41848 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41849 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41850 +85 115 134 4 0 0
41851 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41852 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41853 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41854 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41855 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41856 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41857 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41858 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41859 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41860 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41861 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41862 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41863 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41864 +60 73 81 4 0 0
41865 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41866 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41867 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41868 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41869 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41870 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41871 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41872 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41873 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41874 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41875 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41876 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41877 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41878 +16 19 21 4 0 0
41879 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41880 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41881 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41882 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41883 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41884 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41885 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41886 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41887 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41888 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41889 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41890 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41891 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41892 +4 0 0 4 3 3
41893 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41894 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41895 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41897 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41898 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41899 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41900 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41901 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41902 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41903 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41904 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41905 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41906 +3 2 2 4 4 4
41907 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41908 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41909 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41910 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41911 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41912 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41913 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41914 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41915 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41916 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41917 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41918 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41919 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41920 +4 4 4 4 4 4
41921 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41922 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41923 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41924 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41925 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41926 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41927 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41928 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41929 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41930 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41931 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41932 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41933 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41934 +4 4 4 4 4 4
41935 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41936 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41937 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41938 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41939 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41940 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41941 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41942 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41943 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41944 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41945 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41946 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41947 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41948 +5 5 5 5 5 5
41949 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41950 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41951 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41952 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41953 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41954 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41955 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41956 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41957 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41958 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41959 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41960 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41961 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41962 +5 5 5 4 4 4
41963 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41964 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41965 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41966 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41967 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41968 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41969 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41970 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41971 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41972 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41973 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41974 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41976 +4 4 4 4 4 4
41977 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41978 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41979 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41980 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41981 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41982 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41983 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41984 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41985 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41986 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41987 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41988 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41990 +4 4 4 4 4 4
41991 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41992 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41993 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41994 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41995 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41996 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41997 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41998 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41999 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
42000 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
42001 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
42002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42004 +4 4 4 4 4 4
42005 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
42006 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
42007 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
42008 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
42009 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42010 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42011 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42012 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
42013 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
42014 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
42015 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
42016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42018 +4 4 4 4 4 4
42019 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
42020 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
42021 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
42022 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
42023 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42024 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
42025 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
42026 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
42027 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
42028 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
42029 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42032 +4 4 4 4 4 4
42033 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
42034 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
42035 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
42036 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
42037 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42038 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
42039 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
42040 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
42041 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
42042 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
42043 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
42044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42046 +4 4 4 4 4 4
42047 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
42048 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
42049 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
42050 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
42051 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
42052 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
42053 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
42054 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
42055 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
42056 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
42057 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
42058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42060 +4 4 4 4 4 4
42061 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
42062 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
42063 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
42064 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
42065 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
42066 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
42067 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
42068 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
42069 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
42070 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
42071 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42074 +4 4 4 4 4 4
42075 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
42076 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
42077 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
42078 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
42079 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42080 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
42081 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
42082 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
42083 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
42084 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
42085 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42088 +4 4 4 4 4 4
42089 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
42090 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
42091 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
42092 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
42093 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42094 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
42095 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
42096 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
42097 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
42098 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
42099 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42102 +4 4 4 4 4 4
42103 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
42104 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
42105 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
42106 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
42107 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42108 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
42109 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
42110 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
42111 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
42112 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42113 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42116 +4 4 4 4 4 4
42117 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
42118 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
42119 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
42120 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
42121 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
42122 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
42123 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
42124 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
42125 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42126 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42127 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42130 +4 4 4 4 4 4
42131 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
42132 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
42133 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
42134 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
42135 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42136 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
42137 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
42138 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
42139 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42140 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42141 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42144 +4 4 4 4 4 4
42145 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
42146 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
42147 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
42148 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
42149 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
42150 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
42151 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
42152 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
42153 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42154 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42155 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42158 +4 4 4 4 4 4
42159 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
42160 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
42161 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42162 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
42163 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
42164 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
42165 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
42166 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
42167 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
42168 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42169 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42172 +4 4 4 4 4 4
42173 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
42174 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
42175 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
42176 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
42177 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
42178 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
42179 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
42180 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
42181 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42182 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42183 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42186 +4 4 4 4 4 4
42187 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
42188 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
42189 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42190 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
42191 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
42192 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
42193 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
42194 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
42195 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
42196 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42197 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42200 +4 4 4 4 4 4
42201 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
42202 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
42203 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
42204 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
42205 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
42206 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
42207 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
42208 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
42209 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42210 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42211 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42214 +4 4 4 4 4 4
42215 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42216 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
42217 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42218 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
42219 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
42220 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
42221 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
42222 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
42223 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42224 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42225 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42228 +4 4 4 4 4 4
42229 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42230 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
42231 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
42232 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
42233 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
42234 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
42235 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42236 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
42237 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42238 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42239 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42242 +4 4 4 4 4 4
42243 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42244 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
42245 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
42246 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42247 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
42248 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
42249 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42250 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
42251 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42252 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42253 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42256 +4 4 4 4 4 4
42257 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42258 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
42259 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
42260 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
42261 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
42262 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
42263 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
42264 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
42265 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
42266 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42267 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42270 +4 4 4 4 4 4
42271 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42272 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
42273 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
42274 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
42275 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
42276 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
42277 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
42278 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
42279 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
42280 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42281 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42284 +4 4 4 4 4 4
42285 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
42286 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
42287 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
42288 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
42289 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42290 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
42291 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
42292 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
42293 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
42294 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42295 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42298 +4 4 4 4 4 4
42299 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42300 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42301 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42302 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42303 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42304 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42305 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42306 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42307 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42308 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42309 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42312 +4 4 4 4 4 4
42313 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42314 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42315 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42316 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42317 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42318 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42319 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42320 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42321 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42322 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42323 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42326 +4 4 4 4 4 4
42327 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42328 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42329 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42330 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42331 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42332 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42333 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42334 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42335 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42336 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42337 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42340 +4 4 4 4 4 4
42341 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42342 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42343 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42344 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42345 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42346 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42347 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42348 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42349 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42350 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42351 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42354 +4 4 4 4 4 4
42355 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42356 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42357 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42358 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42359 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42360 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42361 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42362 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42363 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42364 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42365 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42368 +4 4 4 4 4 4
42369 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42370 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42371 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42372 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42373 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42374 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42375 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42376 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42377 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42378 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42382 +4 4 4 4 4 4
42383 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42384 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42385 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42386 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42387 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42388 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42389 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42390 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42391 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42392 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
42397 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42398 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42399 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42400 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42401 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42402 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42403 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42404 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42405 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42406 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42408 +4 4 4 4 4 4 4 4 4 4 4 4 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
42411 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42412 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42413 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42414 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42415 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42416 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42417 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42418 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42419 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42420 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42422 +4 4 4 4 4 4 4 4 4 4 4 4 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
42425 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42426 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42427 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42428 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42429 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42430 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42431 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42432 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42433 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42436 +4 4 4 4 4 4 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
42439 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42440 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42441 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42442 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42443 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42444 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42445 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42446 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42447 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
42453 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42454 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42455 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42456 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42457 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42458 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42459 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42460 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42461 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42463 +4 4 4 4 4 4 4 4 4 4 4 4 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
42467 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42468 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42469 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42470 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42471 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42472 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42473 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42474 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42477 +4 4 4 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
42481 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42482 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42483 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42484 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42485 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42486 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42487 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42488 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
42495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42496 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42497 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42498 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42499 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42500 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42501 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42502 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42504 +4 4 4 4 4 4 4 4 4 4 4 4 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
42509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42510 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42511 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42512 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42513 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42514 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42515 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42516 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42518 +4 4 4 4 4 4 4 4 4 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
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 4 4 4 5 5 5 5 5 5 5 5 5
42525 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42526 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42527 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42528 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42529 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42530 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42532 +4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42539 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42540 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42541 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42542 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42543 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42544 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42546 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42554 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42555 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42556 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42557 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42560 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42569 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42570 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42571 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
42583 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42584 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42585 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5
42597 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42598 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42599 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5
42611 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42612 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42613 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42626 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42627 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42629 +4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42640 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42641 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42643 +4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 6 6 6
42654 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42657 +4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3
42668 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
42677 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42678 index 38fcfff..0072dcd 100644
42679 --- a/drivers/video/udlfb.c
42680 +++ b/drivers/video/udlfb.c
42681 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42682 dlfb_urb_completion(urb);
42683
42684 error:
42685 - atomic_add(bytes_sent, &dev->bytes_sent);
42686 - atomic_add(bytes_identical, &dev->bytes_identical);
42687 - atomic_add(width*height*2, &dev->bytes_rendered);
42688 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42689 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42690 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42691 end_cycles = get_cycles();
42692 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42693 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42694 >> 10)), /* Kcycles */
42695 &dev->cpu_kcycles_used);
42696
42697 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
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(bytes_rendered, &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(bytes_rendered, &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 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42714 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42715 struct dlfb_data *dev = fb_info->par;
42716 return snprintf(buf, PAGE_SIZE, "%u\n",
42717 - atomic_read(&dev->bytes_rendered));
42718 + atomic_read_unchecked(&dev->bytes_rendered));
42719 }
42720
42721 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42722 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42723 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42724 struct dlfb_data *dev = fb_info->par;
42725 return snprintf(buf, PAGE_SIZE, "%u\n",
42726 - atomic_read(&dev->bytes_identical));
42727 + atomic_read_unchecked(&dev->bytes_identical));
42728 }
42729
42730 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42731 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42732 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42733 struct dlfb_data *dev = fb_info->par;
42734 return snprintf(buf, PAGE_SIZE, "%u\n",
42735 - atomic_read(&dev->bytes_sent));
42736 + atomic_read_unchecked(&dev->bytes_sent));
42737 }
42738
42739 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42740 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42741 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42742 struct dlfb_data *dev = fb_info->par;
42743 return snprintf(buf, PAGE_SIZE, "%u\n",
42744 - atomic_read(&dev->cpu_kcycles_used));
42745 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42746 }
42747
42748 static ssize_t edid_show(
42749 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42750 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42751 struct dlfb_data *dev = fb_info->par;
42752
42753 - atomic_set(&dev->bytes_rendered, 0);
42754 - atomic_set(&dev->bytes_identical, 0);
42755 - atomic_set(&dev->bytes_sent, 0);
42756 - atomic_set(&dev->cpu_kcycles_used, 0);
42757 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42758 + atomic_set_unchecked(&dev->bytes_identical, 0);
42759 + atomic_set_unchecked(&dev->bytes_sent, 0);
42760 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42761
42762 return count;
42763 }
42764 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42765 index b0e2a42..e2df3ad 100644
42766 --- a/drivers/video/uvesafb.c
42767 +++ b/drivers/video/uvesafb.c
42768 @@ -19,6 +19,7 @@
42769 #include <linux/io.h>
42770 #include <linux/mutex.h>
42771 #include <linux/slab.h>
42772 +#include <linux/moduleloader.h>
42773 #include <video/edid.h>
42774 #include <video/uvesafb.h>
42775 #ifdef CONFIG_X86
42776 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42777 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42778 par->pmi_setpal = par->ypan = 0;
42779 } else {
42780 +
42781 +#ifdef CONFIG_PAX_KERNEXEC
42782 +#ifdef CONFIG_MODULES
42783 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42784 +#endif
42785 + if (!par->pmi_code) {
42786 + par->pmi_setpal = par->ypan = 0;
42787 + return 0;
42788 + }
42789 +#endif
42790 +
42791 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42792 + task->t.regs.edi);
42793 +
42794 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42795 + pax_open_kernel();
42796 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42797 + pax_close_kernel();
42798 +
42799 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42800 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42801 +#else
42802 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42803 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42804 +#endif
42805 +
42806 printk(KERN_INFO "uvesafb: protected mode interface info at "
42807 "%04x:%04x\n",
42808 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42809 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42810 par->ypan = ypan;
42811
42812 if (par->pmi_setpal || par->ypan) {
42813 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42814 if (__supported_pte_mask & _PAGE_NX) {
42815 par->pmi_setpal = par->ypan = 0;
42816 printk(KERN_WARNING "uvesafb: NX protection is actively."
42817 "We have better not to use the PMI.\n");
42818 - } else {
42819 + } else
42820 +#endif
42821 uvesafb_vbe_getpmi(task, par);
42822 - }
42823 }
42824 #else
42825 /* The protected mode interface is not available on non-x86. */
42826 @@ -1836,6 +1860,11 @@ out:
42827 if (par->vbe_modes)
42828 kfree(par->vbe_modes);
42829
42830 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42831 + if (par->pmi_code)
42832 + module_free_exec(NULL, par->pmi_code);
42833 +#endif
42834 +
42835 framebuffer_release(info);
42836 return err;
42837 }
42838 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42839 kfree(par->vbe_state_orig);
42840 if (par->vbe_state_saved)
42841 kfree(par->vbe_state_saved);
42842 +
42843 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42844 + if (par->pmi_code)
42845 + module_free_exec(NULL, par->pmi_code);
42846 +#endif
42847 +
42848 }
42849
42850 framebuffer_release(info);
42851 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42852 index 501b340..86bd4cf 100644
42853 --- a/drivers/video/vesafb.c
42854 +++ b/drivers/video/vesafb.c
42855 @@ -9,6 +9,7 @@
42856 */
42857
42858 #include <linux/module.h>
42859 +#include <linux/moduleloader.h>
42860 #include <linux/kernel.h>
42861 #include <linux/errno.h>
42862 #include <linux/string.h>
42863 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42864 static int vram_total __initdata; /* Set total amount of memory */
42865 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42866 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42867 -static void (*pmi_start)(void) __read_mostly;
42868 -static void (*pmi_pal) (void) __read_mostly;
42869 +static void (*pmi_start)(void) __read_only;
42870 +static void (*pmi_pal) (void) __read_only;
42871 static int depth __read_mostly;
42872 static int vga_compat __read_mostly;
42873 /* --------------------------------------------------------------------- */
42874 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42875 unsigned int size_vmode;
42876 unsigned int size_remap;
42877 unsigned int size_total;
42878 + void *pmi_code = NULL;
42879
42880 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42881 return -ENODEV;
42882 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42883 size_remap = size_total;
42884 vesafb_fix.smem_len = size_remap;
42885
42886 -#ifndef __i386__
42887 - screen_info.vesapm_seg = 0;
42888 -#endif
42889 -
42890 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42891 printk(KERN_WARNING
42892 "vesafb: cannot reserve video memory at 0x%lx\n",
42893 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42894 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42895 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42896
42897 +#ifdef __i386__
42898 +
42899 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42900 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42901 + if (!pmi_code)
42902 +#elif !defined(CONFIG_PAX_KERNEXEC)
42903 + if (0)
42904 +#endif
42905 +
42906 +#endif
42907 + screen_info.vesapm_seg = 0;
42908 +
42909 if (screen_info.vesapm_seg) {
42910 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42911 - screen_info.vesapm_seg,screen_info.vesapm_off);
42912 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42913 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42914 }
42915
42916 if (screen_info.vesapm_seg < 0xc000)
42917 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42918
42919 if (ypan || pmi_setpal) {
42920 unsigned short *pmi_base;
42921 +
42922 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42923 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42924 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42925 +
42926 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42927 + pax_open_kernel();
42928 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42929 +#else
42930 + pmi_code = pmi_base;
42931 +#endif
42932 +
42933 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42934 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42935 +
42936 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42937 + pmi_start = ktva_ktla(pmi_start);
42938 + pmi_pal = ktva_ktla(pmi_pal);
42939 + pax_close_kernel();
42940 +#endif
42941 +
42942 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42943 if (pmi_base[3]) {
42944 printk(KERN_INFO "vesafb: pmi: ports = ");
42945 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42946 info->node, info->fix.id);
42947 return 0;
42948 err:
42949 +
42950 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42951 + module_free_exec(NULL, pmi_code);
42952 +#endif
42953 +
42954 if (info->screen_base)
42955 iounmap(info->screen_base);
42956 framebuffer_release(info);
42957 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42958 index 88714ae..16c2e11 100644
42959 --- a/drivers/video/via/via_clock.h
42960 +++ b/drivers/video/via/via_clock.h
42961 @@ -56,7 +56,7 @@ struct via_clock {
42962
42963 void (*set_engine_pll_state)(u8 state);
42964 void (*set_engine_pll)(struct via_pll_config config);
42965 -};
42966 +} __no_const;
42967
42968
42969 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42970 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42971 index 453db0c..604973e 100644
42972 --- a/drivers/virtio/virtio_mmio.c
42973 +++ b/drivers/virtio/virtio_mmio.c
42974 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42975
42976 resources[0].end = memparse(device, &str) - 1;
42977
42978 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42979 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42980 &base, &resources[1].start, &consumed,
42981 &vm_cmdline_id, &consumed);
42982
42983 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42984 index e56c934..fc22f4b 100644
42985 --- a/drivers/xen/xen-pciback/conf_space.h
42986 +++ b/drivers/xen/xen-pciback/conf_space.h
42987 @@ -44,15 +44,15 @@ struct config_field {
42988 struct {
42989 conf_dword_write write;
42990 conf_dword_read read;
42991 - } dw;
42992 + } __no_const dw;
42993 struct {
42994 conf_word_write write;
42995 conf_word_read read;
42996 - } w;
42997 + } __no_const w;
42998 struct {
42999 conf_byte_write write;
43000 conf_byte_read read;
43001 - } b;
43002 + } __no_const b;
43003 } u;
43004 struct list_head list;
43005 };
43006 diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
43007 index 89f7625..ac72702 100644
43008 --- a/drivers/xen/xenbus/xenbus_dev_frontend.c
43009 +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
43010 @@ -458,7 +458,7 @@ static ssize_t xenbus_file_write(struct file *filp,
43011 goto out;
43012
43013 /* Can't write a xenbus message larger we can buffer */
43014 - if ((len + u->len) > sizeof(u->u.buffer)) {
43015 + if (len > sizeof(u->u.buffer) - u->len) {
43016 /* On error, dump existing buffer */
43017 u->len = 0;
43018 rc = -EINVAL;
43019 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
43020 index fef20db..d28b1ab 100644
43021 --- a/drivers/xen/xenfs/xenstored.c
43022 +++ b/drivers/xen/xenfs/xenstored.c
43023 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
43024 static int xsd_kva_open(struct inode *inode, struct file *file)
43025 {
43026 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
43027 +#ifdef CONFIG_GRKERNSEC_HIDESYM
43028 + NULL);
43029 +#else
43030 xen_store_interface);
43031 +#endif
43032 +
43033 if (!file->private_data)
43034 return -ENOMEM;
43035 return 0;
43036 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
43037 index cbf9dbb..35c3af7 100644
43038 --- a/fs/9p/vfs_inode.c
43039 +++ b/fs/9p/vfs_inode.c
43040 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43041 void
43042 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43043 {
43044 - char *s = nd_get_link(nd);
43045 + const char *s = nd_get_link(nd);
43046
43047 p9_debug(P9_DEBUG_VFS, " %s %s\n",
43048 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
43049 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
43050 index 0225742..1cd4732 100644
43051 --- a/fs/Kconfig.binfmt
43052 +++ b/fs/Kconfig.binfmt
43053 @@ -89,7 +89,7 @@ config HAVE_AOUT
43054
43055 config BINFMT_AOUT
43056 tristate "Kernel support for a.out and ECOFF binaries"
43057 - depends on HAVE_AOUT
43058 + depends on HAVE_AOUT && BROKEN
43059 ---help---
43060 A.out (Assembler.OUTput) is a set of formats for libraries and
43061 executables used in the earliest versions of UNIX. Linux used
43062 diff --git a/fs/aio.c b/fs/aio.c
43063 index 71f613c..9d01f1f 100644
43064 --- a/fs/aio.c
43065 +++ b/fs/aio.c
43066 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
43067 size += sizeof(struct io_event) * nr_events;
43068 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
43069
43070 - if (nr_pages < 0)
43071 + if (nr_pages <= 0)
43072 return -EINVAL;
43073
43074 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
43075 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
43076 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43077 {
43078 ssize_t ret;
43079 + struct iovec iovstack;
43080
43081 #ifdef CONFIG_COMPAT
43082 if (compat)
43083 ret = compat_rw_copy_check_uvector(type,
43084 (struct compat_iovec __user *)kiocb->ki_buf,
43085 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43086 + kiocb->ki_nbytes, 1, &iovstack,
43087 &kiocb->ki_iovec);
43088 else
43089 #endif
43090 ret = rw_copy_check_uvector(type,
43091 (struct iovec __user *)kiocb->ki_buf,
43092 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43093 + kiocb->ki_nbytes, 1, &iovstack,
43094 &kiocb->ki_iovec);
43095 if (ret < 0)
43096 goto out;
43097 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43098 if (ret < 0)
43099 goto out;
43100
43101 + if (kiocb->ki_iovec == &iovstack) {
43102 + kiocb->ki_inline_vec = iovstack;
43103 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
43104 + }
43105 kiocb->ki_nr_segs = kiocb->ki_nbytes;
43106 kiocb->ki_cur_seg = 0;
43107 /* ki_nbytes/left now reflect bytes instead of segs */
43108 diff --git a/fs/attr.c b/fs/attr.c
43109 index 29e38a1..2bc037b 100644
43110 --- a/fs/attr.c
43111 +++ b/fs/attr.c
43112 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
43113 unsigned long limit;
43114
43115 limit = rlimit(RLIMIT_FSIZE);
43116 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
43117 if (limit != RLIM_INFINITY && offset > limit)
43118 goto out_sig;
43119 if (offset > inode->i_sb->s_maxbytes)
43120 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
43121 index da8876d..4456166 100644
43122 --- a/fs/autofs4/waitq.c
43123 +++ b/fs/autofs4/waitq.c
43124 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
43125 {
43126 unsigned long sigpipe, flags;
43127 mm_segment_t fs;
43128 - const char *data = (const char *)addr;
43129 + const char __user *data = (const char __force_user *)addr;
43130 ssize_t wr = 0;
43131
43132 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
43133 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
43134 return 1;
43135 }
43136
43137 +#ifdef CONFIG_GRKERNSEC_HIDESYM
43138 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
43139 +#endif
43140 +
43141 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
43142 enum autofs_notify notify)
43143 {
43144 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
43145
43146 /* If this is a direct mount request create a dummy name */
43147 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
43148 +#ifdef CONFIG_GRKERNSEC_HIDESYM
43149 + /* this name does get written to userland via autofs4_write() */
43150 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
43151 +#else
43152 qstr.len = sprintf(name, "%p", dentry);
43153 +#endif
43154 else {
43155 qstr.len = autofs4_getpath(sbi, dentry, &name);
43156 if (!qstr.len) {
43157 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
43158 index cf7f3c6..f61080d 100644
43159 --- a/fs/befs/linuxvfs.c
43160 +++ b/fs/befs/linuxvfs.c
43161 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43162 {
43163 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
43164 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
43165 - char *link = nd_get_link(nd);
43166 + const char *link = nd_get_link(nd);
43167 if (!IS_ERR(link))
43168 kfree(link);
43169 }
43170 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
43171 index d146e18..12d1bd1 100644
43172 --- a/fs/binfmt_aout.c
43173 +++ b/fs/binfmt_aout.c
43174 @@ -16,6 +16,7 @@
43175 #include <linux/string.h>
43176 #include <linux/fs.h>
43177 #include <linux/file.h>
43178 +#include <linux/security.h>
43179 #include <linux/stat.h>
43180 #include <linux/fcntl.h>
43181 #include <linux/ptrace.h>
43182 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
43183 #endif
43184 # define START_STACK(u) ((void __user *)u.start_stack)
43185
43186 + memset(&dump, 0, sizeof(dump));
43187 +
43188 fs = get_fs();
43189 set_fs(KERNEL_DS);
43190 has_dumped = 1;
43191 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
43192
43193 /* If the size of the dump file exceeds the rlimit, then see what would happen
43194 if we wrote the stack, but not the data area. */
43195 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
43196 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
43197 dump.u_dsize = 0;
43198
43199 /* Make sure we have enough room to write the stack and data areas. */
43200 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
43201 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
43202 dump.u_ssize = 0;
43203
43204 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43205 rlim = rlimit(RLIMIT_DATA);
43206 if (rlim >= RLIM_INFINITY)
43207 rlim = ~0;
43208 +
43209 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
43210 if (ex.a_data + ex.a_bss > rlim)
43211 return -ENOMEM;
43212
43213 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43214
43215 install_exec_creds(bprm);
43216
43217 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43218 + current->mm->pax_flags = 0UL;
43219 +#endif
43220 +
43221 +#ifdef CONFIG_PAX_PAGEEXEC
43222 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
43223 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
43224 +
43225 +#ifdef CONFIG_PAX_EMUTRAMP
43226 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
43227 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
43228 +#endif
43229 +
43230 +#ifdef CONFIG_PAX_MPROTECT
43231 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
43232 + current->mm->pax_flags |= MF_PAX_MPROTECT;
43233 +#endif
43234 +
43235 + }
43236 +#endif
43237 +
43238 if (N_MAGIC(ex) == OMAGIC) {
43239 unsigned long text_addr, map_size;
43240 loff_t pos;
43241 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43242 }
43243
43244 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
43245 - PROT_READ | PROT_WRITE | PROT_EXEC,
43246 + PROT_READ | PROT_WRITE,
43247 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
43248 fd_offset + ex.a_text);
43249 if (error != N_DATADDR(ex)) {
43250 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
43251 index 0225fdd..0c0d35d 100644
43252 --- a/fs/binfmt_elf.c
43253 +++ b/fs/binfmt_elf.c
43254 @@ -32,6 +32,7 @@
43255 #include <linux/elf.h>
43256 #include <linux/utsname.h>
43257 #include <linux/coredump.h>
43258 +#include <linux/xattr.h>
43259 #include <asm/uaccess.h>
43260 #include <asm/param.h>
43261 #include <asm/page.h>
43262 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
43263 #define elf_core_dump NULL
43264 #endif
43265
43266 +#ifdef CONFIG_PAX_MPROTECT
43267 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43268 +#endif
43269 +
43270 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43271 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43272 #else
43273 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
43274 .load_binary = load_elf_binary,
43275 .load_shlib = load_elf_library,
43276 .core_dump = elf_core_dump,
43277 +
43278 +#ifdef CONFIG_PAX_MPROTECT
43279 + .handle_mprotect= elf_handle_mprotect,
43280 +#endif
43281 +
43282 .min_coredump = ELF_EXEC_PAGESIZE,
43283 };
43284
43285 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
43286
43287 static int set_brk(unsigned long start, unsigned long end)
43288 {
43289 + unsigned long e = end;
43290 +
43291 start = ELF_PAGEALIGN(start);
43292 end = ELF_PAGEALIGN(end);
43293 if (end > start) {
43294 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
43295 if (BAD_ADDR(addr))
43296 return addr;
43297 }
43298 - current->mm->start_brk = current->mm->brk = end;
43299 + current->mm->start_brk = current->mm->brk = e;
43300 return 0;
43301 }
43302
43303 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43304 elf_addr_t __user *u_rand_bytes;
43305 const char *k_platform = ELF_PLATFORM;
43306 const char *k_base_platform = ELF_BASE_PLATFORM;
43307 - unsigned char k_rand_bytes[16];
43308 + u32 k_rand_bytes[4];
43309 int items;
43310 elf_addr_t *elf_info;
43311 int ei_index = 0;
43312 const struct cred *cred = current_cred();
43313 struct vm_area_struct *vma;
43314 + unsigned long saved_auxv[AT_VECTOR_SIZE];
43315
43316 /*
43317 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43318 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43319 * Generate 16 random bytes for userspace PRNG seeding.
43320 */
43321 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43322 - u_rand_bytes = (elf_addr_t __user *)
43323 - STACK_ALLOC(p, sizeof(k_rand_bytes));
43324 + srandom32(k_rand_bytes[0] ^ random32());
43325 + srandom32(k_rand_bytes[1] ^ random32());
43326 + srandom32(k_rand_bytes[2] ^ random32());
43327 + srandom32(k_rand_bytes[3] ^ random32());
43328 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43329 + u_rand_bytes = (elf_addr_t __user *) p;
43330 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43331 return -EFAULT;
43332
43333 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43334 return -EFAULT;
43335 current->mm->env_end = p;
43336
43337 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43338 +
43339 /* Put the elf_info on the stack in the right place. */
43340 sp = (elf_addr_t __user *)envp + 1;
43341 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43342 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43343 return -EFAULT;
43344 return 0;
43345 }
43346 @@ -373,15 +392,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
43347 an ELF header */
43348
43349 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43350 - struct file *interpreter, unsigned long *interp_map_addr,
43351 - unsigned long no_base)
43352 + struct file *interpreter, unsigned long no_base)
43353 {
43354 struct elf_phdr *elf_phdata;
43355 struct elf_phdr *eppnt;
43356 - unsigned long load_addr = 0;
43357 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43358 int load_addr_set = 0;
43359 unsigned long last_bss = 0, elf_bss = 0;
43360 - unsigned long error = ~0UL;
43361 + unsigned long error = -EINVAL;
43362 unsigned long total_size;
43363 int retval, i, size;
43364
43365 @@ -427,6 +445,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43366 goto out_close;
43367 }
43368
43369 +#ifdef CONFIG_PAX_SEGMEXEC
43370 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43371 + pax_task_size = SEGMEXEC_TASK_SIZE;
43372 +#endif
43373 +
43374 eppnt = elf_phdata;
43375 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43376 if (eppnt->p_type == PT_LOAD) {
43377 @@ -450,8 +473,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43378 map_addr = elf_map(interpreter, load_addr + vaddr,
43379 eppnt, elf_prot, elf_type, total_size);
43380 total_size = 0;
43381 - if (!*interp_map_addr)
43382 - *interp_map_addr = map_addr;
43383 error = map_addr;
43384 if (BAD_ADDR(map_addr))
43385 goto out_close;
43386 @@ -470,8 +491,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43387 k = load_addr + eppnt->p_vaddr;
43388 if (BAD_ADDR(k) ||
43389 eppnt->p_filesz > eppnt->p_memsz ||
43390 - eppnt->p_memsz > TASK_SIZE ||
43391 - TASK_SIZE - eppnt->p_memsz < k) {
43392 + eppnt->p_memsz > pax_task_size ||
43393 + pax_task_size - eppnt->p_memsz < k) {
43394 error = -ENOMEM;
43395 goto out_close;
43396 }
43397 @@ -523,6 +544,315 @@ out:
43398 return error;
43399 }
43400
43401 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43402 +#ifdef CONFIG_PAX_SOFTMODE
43403 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43404 +{
43405 + unsigned long pax_flags = 0UL;
43406 +
43407 +#ifdef CONFIG_PAX_PAGEEXEC
43408 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43409 + pax_flags |= MF_PAX_PAGEEXEC;
43410 +#endif
43411 +
43412 +#ifdef CONFIG_PAX_SEGMEXEC
43413 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43414 + pax_flags |= MF_PAX_SEGMEXEC;
43415 +#endif
43416 +
43417 +#ifdef CONFIG_PAX_EMUTRAMP
43418 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43419 + pax_flags |= MF_PAX_EMUTRAMP;
43420 +#endif
43421 +
43422 +#ifdef CONFIG_PAX_MPROTECT
43423 + if (elf_phdata->p_flags & PF_MPROTECT)
43424 + pax_flags |= MF_PAX_MPROTECT;
43425 +#endif
43426 +
43427 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43428 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43429 + pax_flags |= MF_PAX_RANDMMAP;
43430 +#endif
43431 +
43432 + return pax_flags;
43433 +}
43434 +#endif
43435 +
43436 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43437 +{
43438 + unsigned long pax_flags = 0UL;
43439 +
43440 +#ifdef CONFIG_PAX_PAGEEXEC
43441 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43442 + pax_flags |= MF_PAX_PAGEEXEC;
43443 +#endif
43444 +
43445 +#ifdef CONFIG_PAX_SEGMEXEC
43446 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43447 + pax_flags |= MF_PAX_SEGMEXEC;
43448 +#endif
43449 +
43450 +#ifdef CONFIG_PAX_EMUTRAMP
43451 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43452 + pax_flags |= MF_PAX_EMUTRAMP;
43453 +#endif
43454 +
43455 +#ifdef CONFIG_PAX_MPROTECT
43456 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43457 + pax_flags |= MF_PAX_MPROTECT;
43458 +#endif
43459 +
43460 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43461 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43462 + pax_flags |= MF_PAX_RANDMMAP;
43463 +#endif
43464 +
43465 + return pax_flags;
43466 +}
43467 +#endif
43468 +
43469 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43470 +#ifdef CONFIG_PAX_SOFTMODE
43471 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43472 +{
43473 + unsigned long pax_flags = 0UL;
43474 +
43475 +#ifdef CONFIG_PAX_PAGEEXEC
43476 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43477 + pax_flags |= MF_PAX_PAGEEXEC;
43478 +#endif
43479 +
43480 +#ifdef CONFIG_PAX_SEGMEXEC
43481 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43482 + pax_flags |= MF_PAX_SEGMEXEC;
43483 +#endif
43484 +
43485 +#ifdef CONFIG_PAX_EMUTRAMP
43486 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43487 + pax_flags |= MF_PAX_EMUTRAMP;
43488 +#endif
43489 +
43490 +#ifdef CONFIG_PAX_MPROTECT
43491 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43492 + pax_flags |= MF_PAX_MPROTECT;
43493 +#endif
43494 +
43495 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43496 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43497 + pax_flags |= MF_PAX_RANDMMAP;
43498 +#endif
43499 +
43500 + return pax_flags;
43501 +}
43502 +#endif
43503 +
43504 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43505 +{
43506 + unsigned long pax_flags = 0UL;
43507 +
43508 +#ifdef CONFIG_PAX_PAGEEXEC
43509 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43510 + pax_flags |= MF_PAX_PAGEEXEC;
43511 +#endif
43512 +
43513 +#ifdef CONFIG_PAX_SEGMEXEC
43514 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43515 + pax_flags |= MF_PAX_SEGMEXEC;
43516 +#endif
43517 +
43518 +#ifdef CONFIG_PAX_EMUTRAMP
43519 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43520 + pax_flags |= MF_PAX_EMUTRAMP;
43521 +#endif
43522 +
43523 +#ifdef CONFIG_PAX_MPROTECT
43524 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43525 + pax_flags |= MF_PAX_MPROTECT;
43526 +#endif
43527 +
43528 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43529 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43530 + pax_flags |= MF_PAX_RANDMMAP;
43531 +#endif
43532 +
43533 + return pax_flags;
43534 +}
43535 +#endif
43536 +
43537 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43538 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43539 +{
43540 + unsigned long pax_flags = 0UL;
43541 +
43542 +#ifdef CONFIG_PAX_EI_PAX
43543 +
43544 +#ifdef CONFIG_PAX_PAGEEXEC
43545 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43546 + pax_flags |= MF_PAX_PAGEEXEC;
43547 +#endif
43548 +
43549 +#ifdef CONFIG_PAX_SEGMEXEC
43550 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43551 + pax_flags |= MF_PAX_SEGMEXEC;
43552 +#endif
43553 +
43554 +#ifdef CONFIG_PAX_EMUTRAMP
43555 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43556 + pax_flags |= MF_PAX_EMUTRAMP;
43557 +#endif
43558 +
43559 +#ifdef CONFIG_PAX_MPROTECT
43560 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43561 + pax_flags |= MF_PAX_MPROTECT;
43562 +#endif
43563 +
43564 +#ifdef CONFIG_PAX_ASLR
43565 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43566 + pax_flags |= MF_PAX_RANDMMAP;
43567 +#endif
43568 +
43569 +#else
43570 +
43571 +#ifdef CONFIG_PAX_PAGEEXEC
43572 + pax_flags |= MF_PAX_PAGEEXEC;
43573 +#endif
43574 +
43575 +#ifdef CONFIG_PAX_SEGMEXEC
43576 + pax_flags |= MF_PAX_SEGMEXEC;
43577 +#endif
43578 +
43579 +#ifdef CONFIG_PAX_MPROTECT
43580 + pax_flags |= MF_PAX_MPROTECT;
43581 +#endif
43582 +
43583 +#ifdef CONFIG_PAX_RANDMMAP
43584 + if (randomize_va_space)
43585 + pax_flags |= MF_PAX_RANDMMAP;
43586 +#endif
43587 +
43588 +#endif
43589 +
43590 + return pax_flags;
43591 +}
43592 +
43593 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43594 +{
43595 +
43596 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43597 + unsigned long i;
43598 +
43599 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43600 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43601 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43602 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43603 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43604 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43605 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43606 + return ~0UL;
43607 +
43608 +#ifdef CONFIG_PAX_SOFTMODE
43609 + if (pax_softmode)
43610 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43611 + else
43612 +#endif
43613 +
43614 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43615 + break;
43616 + }
43617 +#endif
43618 +
43619 + return ~0UL;
43620 +}
43621 +
43622 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43623 +{
43624 +
43625 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43626 + ssize_t xattr_size, i;
43627 + unsigned char xattr_value[5];
43628 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43629 +
43630 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43631 + if (xattr_size <= 0 || xattr_size > 5)
43632 + return ~0UL;
43633 +
43634 + for (i = 0; i < xattr_size; i++)
43635 + switch (xattr_value[i]) {
43636 + default:
43637 + return ~0UL;
43638 +
43639 +#define parse_flag(option1, option2, flag) \
43640 + case option1: \
43641 + if (pax_flags_hardmode & MF_PAX_##flag) \
43642 + return ~0UL; \
43643 + pax_flags_hardmode |= MF_PAX_##flag; \
43644 + break; \
43645 + case option2: \
43646 + if (pax_flags_softmode & MF_PAX_##flag) \
43647 + return ~0UL; \
43648 + pax_flags_softmode |= MF_PAX_##flag; \
43649 + break;
43650 +
43651 + parse_flag('p', 'P', PAGEEXEC);
43652 + parse_flag('e', 'E', EMUTRAMP);
43653 + parse_flag('m', 'M', MPROTECT);
43654 + parse_flag('r', 'R', RANDMMAP);
43655 + parse_flag('s', 'S', SEGMEXEC);
43656 +
43657 +#undef parse_flag
43658 + }
43659 +
43660 + if (pax_flags_hardmode & pax_flags_softmode)
43661 + return ~0UL;
43662 +
43663 +#ifdef CONFIG_PAX_SOFTMODE
43664 + if (pax_softmode)
43665 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43666 + else
43667 +#endif
43668 +
43669 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43670 +#else
43671 + return ~0UL;
43672 +#endif
43673 +
43674 +}
43675 +
43676 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43677 +{
43678 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43679 +
43680 + pax_flags = pax_parse_ei_pax(elf_ex);
43681 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43682 + xattr_pax_flags = pax_parse_xattr_pax(file);
43683 +
43684 + if (pt_pax_flags == ~0UL)
43685 + pt_pax_flags = xattr_pax_flags;
43686 + else if (xattr_pax_flags == ~0UL)
43687 + xattr_pax_flags = pt_pax_flags;
43688 + if (pt_pax_flags != xattr_pax_flags)
43689 + return -EINVAL;
43690 + if (pt_pax_flags != ~0UL)
43691 + pax_flags = pt_pax_flags;
43692 +
43693 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43694 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43695 + if ((__supported_pte_mask & _PAGE_NX))
43696 + pax_flags &= ~MF_PAX_SEGMEXEC;
43697 + else
43698 + pax_flags &= ~MF_PAX_PAGEEXEC;
43699 + }
43700 +#endif
43701 +
43702 + if (0 > pax_check_flags(&pax_flags))
43703 + return -EINVAL;
43704 +
43705 + current->mm->pax_flags = pax_flags;
43706 + return 0;
43707 +}
43708 +#endif
43709 +
43710 /*
43711 * These are the functions used to load ELF style executables and shared
43712 * libraries. There is no binary dependent code anywhere else.
43713 @@ -539,6 +869,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43714 {
43715 unsigned int random_variable = 0;
43716
43717 +#ifdef CONFIG_PAX_RANDUSTACK
43718 + if (randomize_va_space)
43719 + return stack_top - current->mm->delta_stack;
43720 +#endif
43721 +
43722 if ((current->flags & PF_RANDOMIZE) &&
43723 !(current->personality & ADDR_NO_RANDOMIZE)) {
43724 random_variable = get_random_int() & STACK_RND_MASK;
43725 @@ -557,7 +892,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43726 unsigned long load_addr = 0, load_bias = 0;
43727 int load_addr_set = 0;
43728 char * elf_interpreter = NULL;
43729 - unsigned long error;
43730 + unsigned long error = 0;
43731 struct elf_phdr *elf_ppnt, *elf_phdata;
43732 unsigned long elf_bss, elf_brk;
43733 int retval, i;
43734 @@ -567,11 +902,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43735 unsigned long start_code, end_code, start_data, end_data;
43736 unsigned long reloc_func_desc __maybe_unused = 0;
43737 int executable_stack = EXSTACK_DEFAULT;
43738 - unsigned long def_flags = 0;
43739 struct {
43740 struct elfhdr elf_ex;
43741 struct elfhdr interp_elf_ex;
43742 } *loc;
43743 + unsigned long pax_task_size = TASK_SIZE;
43744
43745 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43746 if (!loc) {
43747 @@ -707,11 +1042,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43748 goto out_free_dentry;
43749
43750 /* OK, This is the point of no return */
43751 - current->mm->def_flags = def_flags;
43752 +
43753 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43754 + current->mm->pax_flags = 0UL;
43755 +#endif
43756 +
43757 +#ifdef CONFIG_PAX_DLRESOLVE
43758 + current->mm->call_dl_resolve = 0UL;
43759 +#endif
43760 +
43761 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43762 + current->mm->call_syscall = 0UL;
43763 +#endif
43764 +
43765 +#ifdef CONFIG_PAX_ASLR
43766 + current->mm->delta_mmap = 0UL;
43767 + current->mm->delta_stack = 0UL;
43768 +#endif
43769 +
43770 + current->mm->def_flags = 0;
43771 +
43772 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43773 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43774 + send_sig(SIGKILL, current, 0);
43775 + goto out_free_dentry;
43776 + }
43777 +#endif
43778 +
43779 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43780 + pax_set_initial_flags(bprm);
43781 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43782 + if (pax_set_initial_flags_func)
43783 + (pax_set_initial_flags_func)(bprm);
43784 +#endif
43785 +
43786 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43787 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43788 + current->mm->context.user_cs_limit = PAGE_SIZE;
43789 + current->mm->def_flags |= VM_PAGEEXEC;
43790 + }
43791 +#endif
43792 +
43793 +#ifdef CONFIG_PAX_SEGMEXEC
43794 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43795 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43796 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43797 + pax_task_size = SEGMEXEC_TASK_SIZE;
43798 + current->mm->def_flags |= VM_NOHUGEPAGE;
43799 + }
43800 +#endif
43801 +
43802 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43803 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43804 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43805 + put_cpu();
43806 + }
43807 +#endif
43808
43809 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43810 may depend on the personality. */
43811 SET_PERSONALITY(loc->elf_ex);
43812 +
43813 +#ifdef CONFIG_PAX_ASLR
43814 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43815 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43816 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43817 + }
43818 +#endif
43819 +
43820 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43821 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43822 + executable_stack = EXSTACK_DISABLE_X;
43823 + current->personality &= ~READ_IMPLIES_EXEC;
43824 + } else
43825 +#endif
43826 +
43827 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43828 current->personality |= READ_IMPLIES_EXEC;
43829
43830 @@ -802,6 +1207,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43831 #else
43832 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43833 #endif
43834 +
43835 +#ifdef CONFIG_PAX_RANDMMAP
43836 + /* PaX: randomize base address at the default exe base if requested */
43837 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43838 +#ifdef CONFIG_SPARC64
43839 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43840 +#else
43841 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43842 +#endif
43843 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43844 + elf_flags |= MAP_FIXED;
43845 + }
43846 +#endif
43847 +
43848 }
43849
43850 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43851 @@ -834,9 +1253,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43852 * allowed task size. Note that p_filesz must always be
43853 * <= p_memsz so it is only necessary to check p_memsz.
43854 */
43855 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43856 - elf_ppnt->p_memsz > TASK_SIZE ||
43857 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43858 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43859 + elf_ppnt->p_memsz > pax_task_size ||
43860 + pax_task_size - elf_ppnt->p_memsz < k) {
43861 /* set_brk can never work. Avoid overflows. */
43862 send_sig(SIGKILL, current, 0);
43863 retval = -EINVAL;
43864 @@ -875,17 +1294,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43865 goto out_free_dentry;
43866 }
43867 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43868 - send_sig(SIGSEGV, current, 0);
43869 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43870 - goto out_free_dentry;
43871 + /*
43872 + * This bss-zeroing can fail if the ELF
43873 + * file specifies odd protections. So
43874 + * we don't check the return value
43875 + */
43876 }
43877
43878 +#ifdef CONFIG_PAX_RANDMMAP
43879 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43880 + unsigned long start, size;
43881 +
43882 + start = ELF_PAGEALIGN(elf_brk);
43883 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43884 + down_read(&current->mm->mmap_sem);
43885 + retval = -ENOMEM;
43886 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43887 + unsigned long prot = PROT_NONE;
43888 +
43889 + up_read(&current->mm->mmap_sem);
43890 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43891 +// if (current->personality & ADDR_NO_RANDOMIZE)
43892 +// prot = PROT_READ;
43893 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43894 + retval = IS_ERR_VALUE(start) ? start : 0;
43895 + } else
43896 + up_read(&current->mm->mmap_sem);
43897 + if (retval == 0)
43898 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43899 + if (retval < 0) {
43900 + send_sig(SIGKILL, current, 0);
43901 + goto out_free_dentry;
43902 + }
43903 + }
43904 +#endif
43905 +
43906 if (elf_interpreter) {
43907 - unsigned long uninitialized_var(interp_map_addr);
43908 -
43909 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43910 interpreter,
43911 - &interp_map_addr,
43912 load_bias);
43913 if (!IS_ERR((void *)elf_entry)) {
43914 /*
43915 @@ -1107,7 +1553,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43916 * Decide what to dump of a segment, part, all or none.
43917 */
43918 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43919 - unsigned long mm_flags)
43920 + unsigned long mm_flags, long signr)
43921 {
43922 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43923
43924 @@ -1144,7 +1590,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43925 if (vma->vm_file == NULL)
43926 return 0;
43927
43928 - if (FILTER(MAPPED_PRIVATE))
43929 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43930 goto whole;
43931
43932 /*
43933 @@ -1366,9 +1812,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43934 {
43935 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43936 int i = 0;
43937 - do
43938 + do {
43939 i += 2;
43940 - while (auxv[i - 2] != AT_NULL);
43941 + } while (auxv[i - 2] != AT_NULL);
43942 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43943 }
43944
43945 @@ -1879,14 +2325,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43946 }
43947
43948 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43949 - unsigned long mm_flags)
43950 + struct coredump_params *cprm)
43951 {
43952 struct vm_area_struct *vma;
43953 size_t size = 0;
43954
43955 for (vma = first_vma(current, gate_vma); vma != NULL;
43956 vma = next_vma(vma, gate_vma))
43957 - size += vma_dump_size(vma, mm_flags);
43958 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43959 return size;
43960 }
43961
43962 @@ -1980,7 +2426,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43963
43964 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43965
43966 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43967 + offset += elf_core_vma_data_size(gate_vma, cprm);
43968 offset += elf_core_extra_data_size();
43969 e_shoff = offset;
43970
43971 @@ -1994,10 +2440,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43972 offset = dataoff;
43973
43974 size += sizeof(*elf);
43975 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43976 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43977 goto end_coredump;
43978
43979 size += sizeof(*phdr4note);
43980 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43981 if (size > cprm->limit
43982 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43983 goto end_coredump;
43984 @@ -2011,7 +2459,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43985 phdr.p_offset = offset;
43986 phdr.p_vaddr = vma->vm_start;
43987 phdr.p_paddr = 0;
43988 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43989 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43990 phdr.p_memsz = vma->vm_end - vma->vm_start;
43991 offset += phdr.p_filesz;
43992 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43993 @@ -2022,6 +2470,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43994 phdr.p_align = ELF_EXEC_PAGESIZE;
43995
43996 size += sizeof(phdr);
43997 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43998 if (size > cprm->limit
43999 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
44000 goto end_coredump;
44001 @@ -2046,7 +2495,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44002 unsigned long addr;
44003 unsigned long end;
44004
44005 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
44006 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
44007
44008 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
44009 struct page *page;
44010 @@ -2055,6 +2504,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44011 page = get_dump_page(addr);
44012 if (page) {
44013 void *kaddr = kmap(page);
44014 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
44015 stop = ((size += PAGE_SIZE) > cprm->limit) ||
44016 !dump_write(cprm->file, kaddr,
44017 PAGE_SIZE);
44018 @@ -2072,6 +2522,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44019
44020 if (e_phnum == PN_XNUM) {
44021 size += sizeof(*shdr4extnum);
44022 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44023 if (size > cprm->limit
44024 || !dump_write(cprm->file, shdr4extnum,
44025 sizeof(*shdr4extnum)))
44026 @@ -2092,6 +2543,97 @@ out:
44027
44028 #endif /* CONFIG_ELF_CORE */
44029
44030 +#ifdef CONFIG_PAX_MPROTECT
44031 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
44032 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
44033 + * we'll remove VM_MAYWRITE for good on RELRO segments.
44034 + *
44035 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
44036 + * basis because we want to allow the common case and not the special ones.
44037 + */
44038 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
44039 +{
44040 + struct elfhdr elf_h;
44041 + struct elf_phdr elf_p;
44042 + unsigned long i;
44043 + unsigned long oldflags;
44044 + bool is_textrel_rw, is_textrel_rx, is_relro;
44045 +
44046 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
44047 + return;
44048 +
44049 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
44050 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
44051 +
44052 +#ifdef CONFIG_PAX_ELFRELOCS
44053 + /* possible TEXTREL */
44054 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
44055 + 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);
44056 +#else
44057 + is_textrel_rw = false;
44058 + is_textrel_rx = false;
44059 +#endif
44060 +
44061 + /* possible RELRO */
44062 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
44063 +
44064 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
44065 + return;
44066 +
44067 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
44068 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
44069 +
44070 +#ifdef CONFIG_PAX_ETEXECRELOCS
44071 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44072 +#else
44073 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
44074 +#endif
44075 +
44076 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44077 + !elf_check_arch(&elf_h) ||
44078 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
44079 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
44080 + return;
44081 +
44082 + for (i = 0UL; i < elf_h.e_phnum; i++) {
44083 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
44084 + return;
44085 + switch (elf_p.p_type) {
44086 + case PT_DYNAMIC:
44087 + if (!is_textrel_rw && !is_textrel_rx)
44088 + continue;
44089 + i = 0UL;
44090 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
44091 + elf_dyn dyn;
44092 +
44093 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
44094 + return;
44095 + if (dyn.d_tag == DT_NULL)
44096 + return;
44097 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
44098 + gr_log_textrel(vma);
44099 + if (is_textrel_rw)
44100 + vma->vm_flags |= VM_MAYWRITE;
44101 + else
44102 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
44103 + vma->vm_flags &= ~VM_MAYWRITE;
44104 + return;
44105 + }
44106 + i++;
44107 + }
44108 + return;
44109 +
44110 + case PT_GNU_RELRO:
44111 + if (!is_relro)
44112 + continue;
44113 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
44114 + vma->vm_flags &= ~VM_MAYWRITE;
44115 + return;
44116 + }
44117 + }
44118 +}
44119 +#endif
44120 +
44121 static int __init init_elf_binfmt(void)
44122 {
44123 register_binfmt(&elf_format);
44124 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
44125 index 178cb70..8972997 100644
44126 --- a/fs/binfmt_flat.c
44127 +++ b/fs/binfmt_flat.c
44128 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
44129 realdatastart = (unsigned long) -ENOMEM;
44130 printk("Unable to allocate RAM for process data, errno %d\n",
44131 (int)-realdatastart);
44132 + down_write(&current->mm->mmap_sem);
44133 vm_munmap(textpos, text_len);
44134 + up_write(&current->mm->mmap_sem);
44135 ret = realdatastart;
44136 goto err;
44137 }
44138 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
44139 }
44140 if (IS_ERR_VALUE(result)) {
44141 printk("Unable to read data+bss, errno %d\n", (int)-result);
44142 + down_write(&current->mm->mmap_sem);
44143 vm_munmap(textpos, text_len);
44144 vm_munmap(realdatastart, len);
44145 + up_write(&current->mm->mmap_sem);
44146 ret = result;
44147 goto err;
44148 }
44149 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
44150 }
44151 if (IS_ERR_VALUE(result)) {
44152 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
44153 + down_write(&current->mm->mmap_sem);
44154 vm_munmap(textpos, text_len + data_len + extra +
44155 MAX_SHARED_LIBS * sizeof(unsigned long));
44156 + up_write(&current->mm->mmap_sem);
44157 ret = result;
44158 goto err;
44159 }
44160 diff --git a/fs/bio.c b/fs/bio.c
44161 index 71072ab..439851b 100644
44162 --- a/fs/bio.c
44163 +++ b/fs/bio.c
44164 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
44165 /*
44166 * Overflow, abort
44167 */
44168 - if (end < start)
44169 + if (end < start || end - start > INT_MAX - nr_pages)
44170 return ERR_PTR(-EINVAL);
44171
44172 nr_pages += end - start;
44173 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
44174 /*
44175 * Overflow, abort
44176 */
44177 - if (end < start)
44178 + if (end < start || end - start > INT_MAX - nr_pages)
44179 return ERR_PTR(-EINVAL);
44180
44181 nr_pages += end - start;
44182 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
44183 const int read = bio_data_dir(bio) == READ;
44184 struct bio_map_data *bmd = bio->bi_private;
44185 int i;
44186 - char *p = bmd->sgvecs[0].iov_base;
44187 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
44188
44189 __bio_for_each_segment(bvec, bio, i, 0) {
44190 char *addr = page_address(bvec->bv_page);
44191 diff --git a/fs/block_dev.c b/fs/block_dev.c
44192 index 38e721b..7a9c5bc 100644
44193 --- a/fs/block_dev.c
44194 +++ b/fs/block_dev.c
44195 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
44196 else if (bdev->bd_contains == bdev)
44197 return true; /* is a whole device which isn't held */
44198
44199 - else if (whole->bd_holder == bd_may_claim)
44200 + else if (whole->bd_holder == (void *)bd_may_claim)
44201 return true; /* is a partition of a device that is being partitioned */
44202 else if (whole->bd_holder != NULL)
44203 return false; /* is a partition of a held device */
44204 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
44205 index 9197e2e..7f731f8 100644
44206 --- a/fs/btrfs/check-integrity.c
44207 +++ b/fs/btrfs/check-integrity.c
44208 @@ -155,7 +155,7 @@ struct btrfsic_block {
44209 union {
44210 bio_end_io_t *bio;
44211 bh_end_io_t *bh;
44212 - } orig_bio_bh_end_io;
44213 + } __no_const orig_bio_bh_end_io;
44214 int submit_bio_bh_rw;
44215 u64 flush_gen; /* only valid if !never_written */
44216 };
44217 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
44218 index 6d183f6..f47cc7a 100644
44219 --- a/fs/btrfs/ctree.c
44220 +++ b/fs/btrfs/ctree.c
44221 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
44222 free_extent_buffer(buf);
44223 add_root_to_dirty_list(root);
44224 } else {
44225 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
44226 - parent_start = parent->start;
44227 - else
44228 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
44229 + if (parent)
44230 + parent_start = parent->start;
44231 + else
44232 + parent_start = 0;
44233 + } else
44234 parent_start = 0;
44235
44236 WARN_ON(trans->transid != btrfs_header_generation(parent));
44237 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
44238 index ec154f9..bf617a7 100644
44239 --- a/fs/btrfs/inode.c
44240 +++ b/fs/btrfs/inode.c
44241 @@ -7126,7 +7126,7 @@ fail:
44242 return -ENOMEM;
44243 }
44244
44245 -static int btrfs_getattr(struct vfsmount *mnt,
44246 +int btrfs_getattr(struct vfsmount *mnt,
44247 struct dentry *dentry, struct kstat *stat)
44248 {
44249 struct inode *inode = dentry->d_inode;
44250 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
44251 return 0;
44252 }
44253
44254 +EXPORT_SYMBOL(btrfs_getattr);
44255 +
44256 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
44257 +{
44258 + return BTRFS_I(inode)->root->anon_dev;
44259 +}
44260 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
44261 +
44262 /*
44263 * If a file is moved, it will inherit the cow and compression flags of the new
44264 * directory.
44265 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
44266 index 9df50fa..6cd20d0 100644
44267 --- a/fs/btrfs/ioctl.c
44268 +++ b/fs/btrfs/ioctl.c
44269 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44270 for (i = 0; i < num_types; i++) {
44271 struct btrfs_space_info *tmp;
44272
44273 + /* Don't copy in more than we allocated */
44274 if (!slot_count)
44275 break;
44276
44277 + slot_count--;
44278 +
44279 info = NULL;
44280 rcu_read_lock();
44281 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44282 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44283 memcpy(dest, &space, sizeof(space));
44284 dest++;
44285 space_args.total_spaces++;
44286 - slot_count--;
44287 }
44288 - if (!slot_count)
44289 - break;
44290 }
44291 up_read(&info->groups_sem);
44292 }
44293 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
44294 index 4da0865..01c4778 100644
44295 --- a/fs/btrfs/relocation.c
44296 +++ b/fs/btrfs/relocation.c
44297 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
44298 }
44299 spin_unlock(&rc->reloc_root_tree.lock);
44300
44301 - BUG_ON((struct btrfs_root *)node->data != root);
44302 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
44303
44304 if (!del) {
44305 spin_lock(&rc->reloc_root_tree.lock);
44306 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
44307 index 622f469..e8d2d55 100644
44308 --- a/fs/cachefiles/bind.c
44309 +++ b/fs/cachefiles/bind.c
44310 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
44311 args);
44312
44313 /* start by checking things over */
44314 - ASSERT(cache->fstop_percent >= 0 &&
44315 - cache->fstop_percent < cache->fcull_percent &&
44316 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
44317 cache->fcull_percent < cache->frun_percent &&
44318 cache->frun_percent < 100);
44319
44320 - ASSERT(cache->bstop_percent >= 0 &&
44321 - cache->bstop_percent < cache->bcull_percent &&
44322 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
44323 cache->bcull_percent < cache->brun_percent &&
44324 cache->brun_percent < 100);
44325
44326 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
44327 index 0a1467b..6a53245 100644
44328 --- a/fs/cachefiles/daemon.c
44329 +++ b/fs/cachefiles/daemon.c
44330 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
44331 if (n > buflen)
44332 return -EMSGSIZE;
44333
44334 - if (copy_to_user(_buffer, buffer, n) != 0)
44335 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44336 return -EFAULT;
44337
44338 return n;
44339 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
44340 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44341 return -EIO;
44342
44343 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44344 + if (datalen > PAGE_SIZE - 1)
44345 return -EOPNOTSUPP;
44346
44347 /* drag the command string into the kernel so we can parse it */
44348 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
44349 if (args[0] != '%' || args[1] != '\0')
44350 return -EINVAL;
44351
44352 - if (fstop < 0 || fstop >= cache->fcull_percent)
44353 + if (fstop >= cache->fcull_percent)
44354 return cachefiles_daemon_range_error(cache, args);
44355
44356 cache->fstop_percent = fstop;
44357 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44358 if (args[0] != '%' || args[1] != '\0')
44359 return -EINVAL;
44360
44361 - if (bstop < 0 || bstop >= cache->bcull_percent)
44362 + if (bstop >= cache->bcull_percent)
44363 return cachefiles_daemon_range_error(cache, args);
44364
44365 cache->bstop_percent = bstop;
44366 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44367 index bd6bc1b..b627b53 100644
44368 --- a/fs/cachefiles/internal.h
44369 +++ b/fs/cachefiles/internal.h
44370 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44371 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44372 struct rb_root active_nodes; /* active nodes (can't be culled) */
44373 rwlock_t active_lock; /* lock for active_nodes */
44374 - atomic_t gravecounter; /* graveyard uniquifier */
44375 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44376 unsigned frun_percent; /* when to stop culling (% files) */
44377 unsigned fcull_percent; /* when to start culling (% files) */
44378 unsigned fstop_percent; /* when to stop allocating (% files) */
44379 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44380 * proc.c
44381 */
44382 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44383 -extern atomic_t cachefiles_lookup_histogram[HZ];
44384 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44385 -extern atomic_t cachefiles_create_histogram[HZ];
44386 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44387 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44388 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44389
44390 extern int __init cachefiles_proc_init(void);
44391 extern void cachefiles_proc_cleanup(void);
44392 static inline
44393 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44394 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44395 {
44396 unsigned long jif = jiffies - start_jif;
44397 if (jif >= HZ)
44398 jif = HZ - 1;
44399 - atomic_inc(&histogram[jif]);
44400 + atomic_inc_unchecked(&histogram[jif]);
44401 }
44402
44403 #else
44404 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44405 index b0b5f7c..039bb26 100644
44406 --- a/fs/cachefiles/namei.c
44407 +++ b/fs/cachefiles/namei.c
44408 @@ -318,7 +318,7 @@ try_again:
44409 /* first step is to make up a grave dentry in the graveyard */
44410 sprintf(nbuffer, "%08x%08x",
44411 (uint32_t) get_seconds(),
44412 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44413 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44414
44415 /* do the multiway lock magic */
44416 trap = lock_rename(cache->graveyard, dir);
44417 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44418 index eccd339..4c1d995 100644
44419 --- a/fs/cachefiles/proc.c
44420 +++ b/fs/cachefiles/proc.c
44421 @@ -14,9 +14,9 @@
44422 #include <linux/seq_file.h>
44423 #include "internal.h"
44424
44425 -atomic_t cachefiles_lookup_histogram[HZ];
44426 -atomic_t cachefiles_mkdir_histogram[HZ];
44427 -atomic_t cachefiles_create_histogram[HZ];
44428 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44429 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44430 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44431
44432 /*
44433 * display the latency histogram
44434 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44435 return 0;
44436 default:
44437 index = (unsigned long) v - 3;
44438 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44439 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44440 - z = atomic_read(&cachefiles_create_histogram[index]);
44441 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44442 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44443 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44444 if (x == 0 && y == 0 && z == 0)
44445 return 0;
44446
44447 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44448 index c994691..2a1537f 100644
44449 --- a/fs/cachefiles/rdwr.c
44450 +++ b/fs/cachefiles/rdwr.c
44451 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44452 old_fs = get_fs();
44453 set_fs(KERNEL_DS);
44454 ret = file->f_op->write(
44455 - file, (const void __user *) data, len, &pos);
44456 + file, (const void __force_user *) data, len, &pos);
44457 set_fs(old_fs);
44458 kunmap(page);
44459 if (ret != len)
44460 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44461 index e5b7731..b9c59fb 100644
44462 --- a/fs/ceph/dir.c
44463 +++ b/fs/ceph/dir.c
44464 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44465 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44466 struct ceph_mds_client *mdsc = fsc->mdsc;
44467 unsigned frag = fpos_frag(filp->f_pos);
44468 - int off = fpos_off(filp->f_pos);
44469 + unsigned int off = fpos_off(filp->f_pos);
44470 int err;
44471 u32 ftype;
44472 struct ceph_mds_reply_info_parsed *rinfo;
44473 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44474 index d9ea6ed..1e6c8ac 100644
44475 --- a/fs/cifs/cifs_debug.c
44476 +++ b/fs/cifs/cifs_debug.c
44477 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44478
44479 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44480 #ifdef CONFIG_CIFS_STATS2
44481 - atomic_set(&totBufAllocCount, 0);
44482 - atomic_set(&totSmBufAllocCount, 0);
44483 + atomic_set_unchecked(&totBufAllocCount, 0);
44484 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44485 #endif /* CONFIG_CIFS_STATS2 */
44486 spin_lock(&cifs_tcp_ses_lock);
44487 list_for_each(tmp1, &cifs_tcp_ses_list) {
44488 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44489 tcon = list_entry(tmp3,
44490 struct cifs_tcon,
44491 tcon_list);
44492 - atomic_set(&tcon->num_smbs_sent, 0);
44493 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44494 if (server->ops->clear_stats)
44495 server->ops->clear_stats(tcon);
44496 }
44497 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44498 smBufAllocCount.counter, cifs_min_small);
44499 #ifdef CONFIG_CIFS_STATS2
44500 seq_printf(m, "Total Large %d Small %d Allocations\n",
44501 - atomic_read(&totBufAllocCount),
44502 - atomic_read(&totSmBufAllocCount));
44503 + atomic_read_unchecked(&totBufAllocCount),
44504 + atomic_read_unchecked(&totSmBufAllocCount));
44505 #endif /* CONFIG_CIFS_STATS2 */
44506
44507 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44508 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44509 if (tcon->need_reconnect)
44510 seq_puts(m, "\tDISCONNECTED ");
44511 seq_printf(m, "\nSMBs: %d",
44512 - atomic_read(&tcon->num_smbs_sent));
44513 + atomic_read_unchecked(&tcon->num_smbs_sent));
44514 if (server->ops->print_stats)
44515 server->ops->print_stats(m, tcon);
44516 }
44517 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44518 index db8a404..c712e2e 100644
44519 --- a/fs/cifs/cifsfs.c
44520 +++ b/fs/cifs/cifsfs.c
44521 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44522 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44523 cifs_req_cachep = kmem_cache_create("cifs_request",
44524 CIFSMaxBufSize + max_hdr_size, 0,
44525 - SLAB_HWCACHE_ALIGN, NULL);
44526 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44527 if (cifs_req_cachep == NULL)
44528 return -ENOMEM;
44529
44530 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44531 efficient to alloc 1 per page off the slab compared to 17K (5page)
44532 alloc of large cifs buffers even when page debugging is on */
44533 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44534 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44535 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44536 NULL);
44537 if (cifs_sm_req_cachep == NULL) {
44538 mempool_destroy(cifs_req_poolp);
44539 @@ -1115,8 +1115,8 @@ init_cifs(void)
44540 atomic_set(&bufAllocCount, 0);
44541 atomic_set(&smBufAllocCount, 0);
44542 #ifdef CONFIG_CIFS_STATS2
44543 - atomic_set(&totBufAllocCount, 0);
44544 - atomic_set(&totSmBufAllocCount, 0);
44545 + atomic_set_unchecked(&totBufAllocCount, 0);
44546 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44547 #endif /* CONFIG_CIFS_STATS2 */
44548
44549 atomic_set(&midCount, 0);
44550 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44551 index 977dc0e..ba48ab9 100644
44552 --- a/fs/cifs/cifsglob.h
44553 +++ b/fs/cifs/cifsglob.h
44554 @@ -590,35 +590,35 @@ struct cifs_tcon {
44555 __u16 Flags; /* optional support bits */
44556 enum statusEnum tidStatus;
44557 #ifdef CONFIG_CIFS_STATS
44558 - atomic_t num_smbs_sent;
44559 + atomic_unchecked_t num_smbs_sent;
44560 union {
44561 struct {
44562 - atomic_t num_writes;
44563 - atomic_t num_reads;
44564 - atomic_t num_flushes;
44565 - atomic_t num_oplock_brks;
44566 - atomic_t num_opens;
44567 - atomic_t num_closes;
44568 - atomic_t num_deletes;
44569 - atomic_t num_mkdirs;
44570 - atomic_t num_posixopens;
44571 - atomic_t num_posixmkdirs;
44572 - atomic_t num_rmdirs;
44573 - atomic_t num_renames;
44574 - atomic_t num_t2renames;
44575 - atomic_t num_ffirst;
44576 - atomic_t num_fnext;
44577 - atomic_t num_fclose;
44578 - atomic_t num_hardlinks;
44579 - atomic_t num_symlinks;
44580 - atomic_t num_locks;
44581 - atomic_t num_acl_get;
44582 - atomic_t num_acl_set;
44583 + atomic_unchecked_t num_writes;
44584 + atomic_unchecked_t num_reads;
44585 + atomic_unchecked_t num_flushes;
44586 + atomic_unchecked_t num_oplock_brks;
44587 + atomic_unchecked_t num_opens;
44588 + atomic_unchecked_t num_closes;
44589 + atomic_unchecked_t num_deletes;
44590 + atomic_unchecked_t num_mkdirs;
44591 + atomic_unchecked_t num_posixopens;
44592 + atomic_unchecked_t num_posixmkdirs;
44593 + atomic_unchecked_t num_rmdirs;
44594 + atomic_unchecked_t num_renames;
44595 + atomic_unchecked_t num_t2renames;
44596 + atomic_unchecked_t num_ffirst;
44597 + atomic_unchecked_t num_fnext;
44598 + atomic_unchecked_t num_fclose;
44599 + atomic_unchecked_t num_hardlinks;
44600 + atomic_unchecked_t num_symlinks;
44601 + atomic_unchecked_t num_locks;
44602 + atomic_unchecked_t num_acl_get;
44603 + atomic_unchecked_t num_acl_set;
44604 } cifs_stats;
44605 #ifdef CONFIG_CIFS_SMB2
44606 struct {
44607 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44608 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44609 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44610 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44611 } smb2_stats;
44612 #endif /* CONFIG_CIFS_SMB2 */
44613 } stats;
44614 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44615 }
44616
44617 #ifdef CONFIG_CIFS_STATS
44618 -#define cifs_stats_inc atomic_inc
44619 +#define cifs_stats_inc atomic_inc_unchecked
44620
44621 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44622 unsigned int bytes)
44623 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44624 /* Various Debug counters */
44625 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44626 #ifdef CONFIG_CIFS_STATS2
44627 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44628 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44629 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44630 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44631 #endif
44632 GLOBAL_EXTERN atomic_t smBufAllocCount;
44633 GLOBAL_EXTERN atomic_t midCount;
44634 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44635 index e6ce3b1..adc21fd 100644
44636 --- a/fs/cifs/link.c
44637 +++ b/fs/cifs/link.c
44638 @@ -602,7 +602,7 @@ symlink_exit:
44639
44640 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44641 {
44642 - char *p = nd_get_link(nd);
44643 + const char *p = nd_get_link(nd);
44644 if (!IS_ERR(p))
44645 kfree(p);
44646 }
44647 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44648 index ce41fee..ac0d27a 100644
44649 --- a/fs/cifs/misc.c
44650 +++ b/fs/cifs/misc.c
44651 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44652 memset(ret_buf, 0, buf_size + 3);
44653 atomic_inc(&bufAllocCount);
44654 #ifdef CONFIG_CIFS_STATS2
44655 - atomic_inc(&totBufAllocCount);
44656 + atomic_inc_unchecked(&totBufAllocCount);
44657 #endif /* CONFIG_CIFS_STATS2 */
44658 }
44659
44660 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44661 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44662 atomic_inc(&smBufAllocCount);
44663 #ifdef CONFIG_CIFS_STATS2
44664 - atomic_inc(&totSmBufAllocCount);
44665 + atomic_inc_unchecked(&totSmBufAllocCount);
44666 #endif /* CONFIG_CIFS_STATS2 */
44667
44668 }
44669 diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
44670 index d87f826..1bab9d4 100644
44671 --- a/fs/cifs/readdir.c
44672 +++ b/fs/cifs/readdir.c
44673 @@ -86,14 +86,17 @@ cifs_readdir_lookup(struct dentry *parent, struct qstr *name,
44674
44675 dentry = d_lookup(parent, name);
44676 if (dentry) {
44677 + int err;
44678 inode = dentry->d_inode;
44679 /* update inode in place if i_ino didn't change */
44680 if (inode && CIFS_I(inode)->uniqueid == fattr->cf_uniqueid) {
44681 cifs_fattr_to_inode(inode, fattr);
44682 return dentry;
44683 }
44684 - d_drop(dentry);
44685 + err = d_invalidate(dentry);
44686 dput(dentry);
44687 + if (err)
44688 + return NULL;
44689 }
44690
44691 dentry = d_alloc(parent, name);
44692 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44693 index 3129ac7..cc4a948 100644
44694 --- a/fs/cifs/smb1ops.c
44695 +++ b/fs/cifs/smb1ops.c
44696 @@ -524,27 +524,27 @@ static void
44697 cifs_clear_stats(struct cifs_tcon *tcon)
44698 {
44699 #ifdef CONFIG_CIFS_STATS
44700 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44701 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44702 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44703 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44704 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44705 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44706 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44707 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44708 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44709 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44710 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44711 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44712 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44713 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44714 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44715 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44716 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44717 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44718 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44719 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44720 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44721 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44722 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44723 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44724 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44725 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44726 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44727 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44728 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44729 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44730 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44731 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44732 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44733 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44734 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44735 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44736 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44737 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44738 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44739 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44740 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44741 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44742 #endif
44743 }
44744
44745 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44746 {
44747 #ifdef CONFIG_CIFS_STATS
44748 seq_printf(m, " Oplocks breaks: %d",
44749 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44750 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44751 seq_printf(m, "\nReads: %d Bytes: %llu",
44752 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44753 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44754 (long long)(tcon->bytes_read));
44755 seq_printf(m, "\nWrites: %d Bytes: %llu",
44756 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44757 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44758 (long long)(tcon->bytes_written));
44759 seq_printf(m, "\nFlushes: %d",
44760 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44761 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44762 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44763 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44764 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44765 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44766 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44767 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44768 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44769 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44770 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44771 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44772 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44773 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44774 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44775 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44776 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44777 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44778 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44779 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44780 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44781 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44782 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44783 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44784 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44785 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44786 seq_printf(m, "\nRenames: %d T2 Renames %d",
44787 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44788 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44789 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44790 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44791 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44792 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44793 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44794 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44795 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44796 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44797 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44798 #endif
44799 }
44800
44801 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44802 index 826209b..fa460f4 100644
44803 --- a/fs/cifs/smb2ops.c
44804 +++ b/fs/cifs/smb2ops.c
44805 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44806 #ifdef CONFIG_CIFS_STATS
44807 int i;
44808 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44809 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44810 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44811 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44812 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44813 }
44814 #endif
44815 }
44816 @@ -229,66 +229,66 @@ static void
44817 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44818 {
44819 #ifdef CONFIG_CIFS_STATS
44820 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44821 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44822 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44823 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44824 seq_printf(m, "\nNegotiates: %d sent %d failed",
44825 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44826 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44827 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44828 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44829 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44830 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44831 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44832 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44833 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44834 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44835 seq_printf(m, "\nLogoffs: %d sent %d failed",
44836 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44837 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44838 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44839 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44840 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44841 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44842 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44843 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44844 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44845 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44846 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44847 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44848 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44849 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44850 seq_printf(m, "\nCreates: %d sent %d failed",
44851 - atomic_read(&sent[SMB2_CREATE_HE]),
44852 - atomic_read(&failed[SMB2_CREATE_HE]));
44853 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44854 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44855 seq_printf(m, "\nCloses: %d sent %d failed",
44856 - atomic_read(&sent[SMB2_CLOSE_HE]),
44857 - atomic_read(&failed[SMB2_CLOSE_HE]));
44858 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44859 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44860 seq_printf(m, "\nFlushes: %d sent %d failed",
44861 - atomic_read(&sent[SMB2_FLUSH_HE]),
44862 - atomic_read(&failed[SMB2_FLUSH_HE]));
44863 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44864 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44865 seq_printf(m, "\nReads: %d sent %d failed",
44866 - atomic_read(&sent[SMB2_READ_HE]),
44867 - atomic_read(&failed[SMB2_READ_HE]));
44868 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44869 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44870 seq_printf(m, "\nWrites: %d sent %d failed",
44871 - atomic_read(&sent[SMB2_WRITE_HE]),
44872 - atomic_read(&failed[SMB2_WRITE_HE]));
44873 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44874 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44875 seq_printf(m, "\nLocks: %d sent %d failed",
44876 - atomic_read(&sent[SMB2_LOCK_HE]),
44877 - atomic_read(&failed[SMB2_LOCK_HE]));
44878 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44879 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44880 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44881 - atomic_read(&sent[SMB2_IOCTL_HE]),
44882 - atomic_read(&failed[SMB2_IOCTL_HE]));
44883 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44884 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44885 seq_printf(m, "\nCancels: %d sent %d failed",
44886 - atomic_read(&sent[SMB2_CANCEL_HE]),
44887 - atomic_read(&failed[SMB2_CANCEL_HE]));
44888 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44889 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44890 seq_printf(m, "\nEchos: %d sent %d failed",
44891 - atomic_read(&sent[SMB2_ECHO_HE]),
44892 - atomic_read(&failed[SMB2_ECHO_HE]));
44893 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44894 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44895 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44896 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44897 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44898 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44899 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44900 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44901 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44902 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44903 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44904 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44905 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44906 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44907 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44908 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44909 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44910 seq_printf(m, "\nSetInfos: %d sent %d failed",
44911 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44912 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44913 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44914 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44915 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44916 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44917 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44918 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44919 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44920 #endif
44921 }
44922
44923 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44924 index 958ae0e..505c9d0 100644
44925 --- a/fs/coda/cache.c
44926 +++ b/fs/coda/cache.c
44927 @@ -24,7 +24,7 @@
44928 #include "coda_linux.h"
44929 #include "coda_cache.h"
44930
44931 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44932 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44933
44934 /* replace or extend an acl cache hit */
44935 void coda_cache_enter(struct inode *inode, int mask)
44936 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44937 struct coda_inode_info *cii = ITOC(inode);
44938
44939 spin_lock(&cii->c_lock);
44940 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44941 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44942 if (cii->c_uid != current_fsuid()) {
44943 cii->c_uid = current_fsuid();
44944 cii->c_cached_perm = mask;
44945 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44946 {
44947 struct coda_inode_info *cii = ITOC(inode);
44948 spin_lock(&cii->c_lock);
44949 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44950 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44951 spin_unlock(&cii->c_lock);
44952 }
44953
44954 /* remove all acl caches */
44955 void coda_cache_clear_all(struct super_block *sb)
44956 {
44957 - atomic_inc(&permission_epoch);
44958 + atomic_inc_unchecked(&permission_epoch);
44959 }
44960
44961
44962 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44963 spin_lock(&cii->c_lock);
44964 hit = (mask & cii->c_cached_perm) == mask &&
44965 cii->c_uid == current_fsuid() &&
44966 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44967 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44968 spin_unlock(&cii->c_lock);
44969
44970 return hit;
44971 diff --git a/fs/compat.c b/fs/compat.c
44972 index 1bdb350..9f28287 100644
44973 --- a/fs/compat.c
44974 +++ b/fs/compat.c
44975 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44976
44977 set_fs(KERNEL_DS);
44978 /* The __user pointer cast is valid because of the set_fs() */
44979 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44980 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44981 set_fs(oldfs);
44982 /* truncating is ok because it's a user address */
44983 if (!ret)
44984 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44985 goto out;
44986
44987 ret = -EINVAL;
44988 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44989 + if (nr_segs > UIO_MAXIOV)
44990 goto out;
44991 if (nr_segs > fast_segs) {
44992 ret = -ENOMEM;
44993 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44994
44995 struct compat_readdir_callback {
44996 struct compat_old_linux_dirent __user *dirent;
44997 + struct file * file;
44998 int result;
44999 };
45000
45001 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
45002 buf->result = -EOVERFLOW;
45003 return -EOVERFLOW;
45004 }
45005 +
45006 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45007 + return 0;
45008 +
45009 buf->result++;
45010 dirent = buf->dirent;
45011 if (!access_ok(VERIFY_WRITE, dirent,
45012 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
45013
45014 buf.result = 0;
45015 buf.dirent = dirent;
45016 + buf.file = file;
45017
45018 error = vfs_readdir(file, compat_fillonedir, &buf);
45019 if (buf.result)
45020 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
45021 struct compat_getdents_callback {
45022 struct compat_linux_dirent __user *current_dir;
45023 struct compat_linux_dirent __user *previous;
45024 + struct file * file;
45025 int count;
45026 int error;
45027 };
45028 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
45029 buf->error = -EOVERFLOW;
45030 return -EOVERFLOW;
45031 }
45032 +
45033 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45034 + return 0;
45035 +
45036 dirent = buf->previous;
45037 if (dirent) {
45038 if (__put_user(offset, &dirent->d_off))
45039 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
45040 buf.previous = NULL;
45041 buf.count = count;
45042 buf.error = 0;
45043 + buf.file = file;
45044
45045 error = vfs_readdir(file, compat_filldir, &buf);
45046 if (error >= 0)
45047 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
45048 struct compat_getdents_callback64 {
45049 struct linux_dirent64 __user *current_dir;
45050 struct linux_dirent64 __user *previous;
45051 + struct file * file;
45052 int count;
45053 int error;
45054 };
45055 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
45056 buf->error = -EINVAL; /* only used if we fail.. */
45057 if (reclen > buf->count)
45058 return -EINVAL;
45059 +
45060 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45061 + return 0;
45062 +
45063 dirent = buf->previous;
45064
45065 if (dirent) {
45066 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
45067 buf.previous = NULL;
45068 buf.count = count;
45069 buf.error = 0;
45070 + buf.file = file;
45071
45072 error = vfs_readdir(file, compat_filldir64, &buf);
45073 if (error >= 0)
45074 error = buf.error;
45075 lastdirent = buf.previous;
45076 if (lastdirent) {
45077 - typeof(lastdirent->d_off) d_off = file->f_pos;
45078 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
45079 if (__put_user_unaligned(d_off, &lastdirent->d_off))
45080 error = -EFAULT;
45081 else
45082 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
45083 index 112e45a..b59845b 100644
45084 --- a/fs/compat_binfmt_elf.c
45085 +++ b/fs/compat_binfmt_elf.c
45086 @@ -30,11 +30,13 @@
45087 #undef elf_phdr
45088 #undef elf_shdr
45089 #undef elf_note
45090 +#undef elf_dyn
45091 #undef elf_addr_t
45092 #define elfhdr elf32_hdr
45093 #define elf_phdr elf32_phdr
45094 #define elf_shdr elf32_shdr
45095 #define elf_note elf32_note
45096 +#define elf_dyn Elf32_Dyn
45097 #define elf_addr_t Elf32_Addr
45098
45099 /*
45100 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
45101 index 5d2069f..75d31d4 100644
45102 --- a/fs/compat_ioctl.c
45103 +++ b/fs/compat_ioctl.c
45104 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
45105 return -EFAULT;
45106 if (__get_user(udata, &ss32->iomem_base))
45107 return -EFAULT;
45108 - ss.iomem_base = compat_ptr(udata);
45109 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
45110 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
45111 __get_user(ss.port_high, &ss32->port_high))
45112 return -EFAULT;
45113 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
45114 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
45115 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
45116 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
45117 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
45118 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
45119 return -EFAULT;
45120
45121 return ioctl_preallocate(file, p);
45122 @@ -1612,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
45123 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
45124 {
45125 unsigned int a, b;
45126 - a = *(unsigned int *)p;
45127 - b = *(unsigned int *)q;
45128 + a = *(const unsigned int *)p;
45129 + b = *(const unsigned int *)q;
45130 if (a > b)
45131 return 1;
45132 if (a < b)
45133 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
45134 index 7414ae2..d98ad6d 100644
45135 --- a/fs/configfs/dir.c
45136 +++ b/fs/configfs/dir.c
45137 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
45138 }
45139 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
45140 struct configfs_dirent *next;
45141 - const char * name;
45142 + const unsigned char * name;
45143 + char d_name[sizeof(next->s_dentry->d_iname)];
45144 int len;
45145 struct inode *inode = NULL;
45146
45147 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
45148 continue;
45149
45150 name = configfs_get_name(next);
45151 - len = strlen(name);
45152 + if (next->s_dentry && name == next->s_dentry->d_iname) {
45153 + len = next->s_dentry->d_name.len;
45154 + memcpy(d_name, name, len);
45155 + name = d_name;
45156 + } else
45157 + len = strlen(name);
45158
45159 /*
45160 * We'll have a dentry and an inode for
45161 diff --git a/fs/dcache.c b/fs/dcache.c
45162 index 693f95b..95f1223 100644
45163 --- a/fs/dcache.c
45164 +++ b/fs/dcache.c
45165 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
45166 mempages -= reserve;
45167
45168 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
45169 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
45170 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
45171
45172 dcache_init();
45173 inode_init();
45174 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
45175 index 4733eab..71ef6fa 100644
45176 --- a/fs/debugfs/inode.c
45177 +++ b/fs/debugfs/inode.c
45178 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
45179 */
45180 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
45181 {
45182 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
45183 + return __create_file(name, S_IFDIR | S_IRWXU,
45184 +#else
45185 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
45186 +#endif
45187 parent, NULL, NULL);
45188 }
45189 EXPORT_SYMBOL_GPL(debugfs_create_dir);
45190 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
45191 index cc7709e..7e7211f 100644
45192 --- a/fs/ecryptfs/inode.c
45193 +++ b/fs/ecryptfs/inode.c
45194 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
45195 old_fs = get_fs();
45196 set_fs(get_ds());
45197 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
45198 - (char __user *)lower_buf,
45199 + (char __force_user *)lower_buf,
45200 PATH_MAX);
45201 set_fs(old_fs);
45202 if (rc < 0)
45203 @@ -706,7 +706,7 @@ out:
45204 static void
45205 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
45206 {
45207 - char *buf = nd_get_link(nd);
45208 + const char *buf = nd_get_link(nd);
45209 if (!IS_ERR(buf)) {
45210 /* Free the char* */
45211 kfree(buf);
45212 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
45213 index 412e6ed..4292d22 100644
45214 --- a/fs/ecryptfs/miscdev.c
45215 +++ b/fs/ecryptfs/miscdev.c
45216 @@ -315,7 +315,7 @@ check_list:
45217 goto out_unlock_msg_ctx;
45218 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
45219 if (msg_ctx->msg) {
45220 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
45221 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
45222 goto out_unlock_msg_ctx;
45223 i += packet_length_size;
45224 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
45225 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
45226 index b2a34a1..162fa69 100644
45227 --- a/fs/ecryptfs/read_write.c
45228 +++ b/fs/ecryptfs/read_write.c
45229 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
45230 return -EIO;
45231 fs_save = get_fs();
45232 set_fs(get_ds());
45233 - rc = vfs_write(lower_file, data, size, &offset);
45234 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
45235 set_fs(fs_save);
45236 mark_inode_dirty_sync(ecryptfs_inode);
45237 return rc;
45238 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
45239 return -EIO;
45240 fs_save = get_fs();
45241 set_fs(get_ds());
45242 - rc = vfs_read(lower_file, data, size, &offset);
45243 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
45244 set_fs(fs_save);
45245 return rc;
45246 }
45247 diff --git a/fs/exec.c b/fs/exec.c
45248 index fab2c6d..9b2fad8 100644
45249 --- a/fs/exec.c
45250 +++ b/fs/exec.c
45251 @@ -55,6 +55,15 @@
45252 #include <linux/pipe_fs_i.h>
45253 #include <linux/oom.h>
45254 #include <linux/compat.h>
45255 +#include <linux/random.h>
45256 +#include <linux/seq_file.h>
45257 +
45258 +#ifdef CONFIG_PAX_REFCOUNT
45259 +#include <linux/kallsyms.h>
45260 +#include <linux/kdebug.h>
45261 +#endif
45262 +
45263 +#include <trace/events/fs.h>
45264
45265 #include <asm/uaccess.h>
45266 #include <asm/mmu_context.h>
45267 @@ -66,6 +75,18 @@
45268
45269 #include <trace/events/sched.h>
45270
45271 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45272 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
45273 +{
45274 + 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");
45275 +}
45276 +#endif
45277 +
45278 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45279 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45280 +EXPORT_SYMBOL(pax_set_initial_flags_func);
45281 +#endif
45282 +
45283 int core_uses_pid;
45284 char core_pattern[CORENAME_MAX_SIZE] = "core";
45285 unsigned int core_pipe_limit;
45286 @@ -75,7 +96,7 @@ struct core_name {
45287 char *corename;
45288 int used, size;
45289 };
45290 -static atomic_t call_count = ATOMIC_INIT(1);
45291 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45292
45293 /* The maximal length of core_pattern is also specified in sysctl.c */
45294
45295 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45296 int write)
45297 {
45298 struct page *page;
45299 - int ret;
45300
45301 -#ifdef CONFIG_STACK_GROWSUP
45302 - if (write) {
45303 - ret = expand_downwards(bprm->vma, pos);
45304 - if (ret < 0)
45305 - return NULL;
45306 - }
45307 -#endif
45308 - ret = get_user_pages(current, bprm->mm, pos,
45309 - 1, write, 1, &page, NULL);
45310 - if (ret <= 0)
45311 + if (0 > expand_downwards(bprm->vma, pos))
45312 + return NULL;
45313 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45314 return NULL;
45315
45316 if (write) {
45317 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45318 if (size <= ARG_MAX)
45319 return page;
45320
45321 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45322 + // only allow 512KB for argv+env on suid/sgid binaries
45323 + // to prevent easy ASLR exhaustion
45324 + if (((bprm->cred->euid != current_euid()) ||
45325 + (bprm->cred->egid != current_egid())) &&
45326 + (size > (512 * 1024))) {
45327 + put_page(page);
45328 + return NULL;
45329 + }
45330 +#endif
45331 +
45332 /*
45333 * Limit to 1/4-th the stack size for the argv+env strings.
45334 * This ensures that:
45335 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45336 vma->vm_end = STACK_TOP_MAX;
45337 vma->vm_start = vma->vm_end - PAGE_SIZE;
45338 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45339 +
45340 +#ifdef CONFIG_PAX_SEGMEXEC
45341 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45342 +#endif
45343 +
45344 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45345 INIT_LIST_HEAD(&vma->anon_vma_chain);
45346
45347 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45348 mm->stack_vm = mm->total_vm = 1;
45349 up_write(&mm->mmap_sem);
45350 bprm->p = vma->vm_end - sizeof(void *);
45351 +
45352 +#ifdef CONFIG_PAX_RANDUSTACK
45353 + if (randomize_va_space)
45354 + bprm->p ^= random32() & ~PAGE_MASK;
45355 +#endif
45356 +
45357 return 0;
45358 err:
45359 up_write(&mm->mmap_sem);
45360 @@ -395,19 +430,7 @@ err:
45361 return err;
45362 }
45363
45364 -struct user_arg_ptr {
45365 -#ifdef CONFIG_COMPAT
45366 - bool is_compat;
45367 -#endif
45368 - union {
45369 - const char __user *const __user *native;
45370 -#ifdef CONFIG_COMPAT
45371 - compat_uptr_t __user *compat;
45372 -#endif
45373 - } ptr;
45374 -};
45375 -
45376 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45377 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45378 {
45379 const char __user *native;
45380
45381 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45382 compat_uptr_t compat;
45383
45384 if (get_user(compat, argv.ptr.compat + nr))
45385 - return ERR_PTR(-EFAULT);
45386 + return (const char __force_user *)ERR_PTR(-EFAULT);
45387
45388 return compat_ptr(compat);
45389 }
45390 #endif
45391
45392 if (get_user(native, argv.ptr.native + nr))
45393 - return ERR_PTR(-EFAULT);
45394 + return (const char __force_user *)ERR_PTR(-EFAULT);
45395
45396 return native;
45397 }
45398 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
45399 if (!p)
45400 break;
45401
45402 - if (IS_ERR(p))
45403 + if (IS_ERR((const char __force_kernel *)p))
45404 return -EFAULT;
45405
45406 if (i++ >= max)
45407 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45408
45409 ret = -EFAULT;
45410 str = get_user_arg_ptr(argv, argc);
45411 - if (IS_ERR(str))
45412 + if (IS_ERR((const char __force_kernel *)str))
45413 goto out;
45414
45415 len = strnlen_user(str, MAX_ARG_STRLEN);
45416 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45417 int r;
45418 mm_segment_t oldfs = get_fs();
45419 struct user_arg_ptr argv = {
45420 - .ptr.native = (const char __user *const __user *)__argv,
45421 + .ptr.native = (const char __force_user *const __force_user *)__argv,
45422 };
45423
45424 set_fs(KERNEL_DS);
45425 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45426 unsigned long new_end = old_end - shift;
45427 struct mmu_gather tlb;
45428
45429 - BUG_ON(new_start > new_end);
45430 + if (new_start >= new_end || new_start < mmap_min_addr)
45431 + return -ENOMEM;
45432
45433 /*
45434 * ensure there are no vmas between where we want to go
45435 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45436 if (vma != find_vma(mm, new_start))
45437 return -EFAULT;
45438
45439 +#ifdef CONFIG_PAX_SEGMEXEC
45440 + BUG_ON(pax_find_mirror_vma(vma));
45441 +#endif
45442 +
45443 /*
45444 * cover the whole range: [new_start, old_end)
45445 */
45446 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45447 stack_top = arch_align_stack(stack_top);
45448 stack_top = PAGE_ALIGN(stack_top);
45449
45450 - if (unlikely(stack_top < mmap_min_addr) ||
45451 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45452 - return -ENOMEM;
45453 -
45454 stack_shift = vma->vm_end - stack_top;
45455
45456 bprm->p -= stack_shift;
45457 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45458 bprm->exec -= stack_shift;
45459
45460 down_write(&mm->mmap_sem);
45461 +
45462 + /* Move stack pages down in memory. */
45463 + if (stack_shift) {
45464 + ret = shift_arg_pages(vma, stack_shift);
45465 + if (ret)
45466 + goto out_unlock;
45467 + }
45468 +
45469 vm_flags = VM_STACK_FLAGS;
45470
45471 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45472 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45473 + vm_flags &= ~VM_EXEC;
45474 +
45475 +#ifdef CONFIG_PAX_MPROTECT
45476 + if (mm->pax_flags & MF_PAX_MPROTECT)
45477 + vm_flags &= ~VM_MAYEXEC;
45478 +#endif
45479 +
45480 + }
45481 +#endif
45482 +
45483 /*
45484 * Adjust stack execute permissions; explicitly enable for
45485 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45486 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45487 goto out_unlock;
45488 BUG_ON(prev != vma);
45489
45490 - /* Move stack pages down in memory. */
45491 - if (stack_shift) {
45492 - ret = shift_arg_pages(vma, stack_shift);
45493 - if (ret)
45494 - goto out_unlock;
45495 - }
45496 -
45497 /* mprotect_fixup is overkill to remove the temporary stack flags */
45498 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45499
45500 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45501
45502 fsnotify_open(file);
45503
45504 + trace_open_exec(name);
45505 +
45506 err = deny_write_access(file);
45507 if (err)
45508 goto exit;
45509 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45510 old_fs = get_fs();
45511 set_fs(get_ds());
45512 /* The cast to a user pointer is valid due to the set_fs() */
45513 - result = vfs_read(file, (void __user *)addr, count, &pos);
45514 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45515 set_fs(old_fs);
45516 return result;
45517 }
45518 @@ -1258,7 +1297,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45519 }
45520 rcu_read_unlock();
45521
45522 - if (p->fs->users > n_fs) {
45523 + if (atomic_read(&p->fs->users) > n_fs) {
45524 bprm->unsafe |= LSM_UNSAFE_SHARE;
45525 } else {
45526 res = -EAGAIN;
45527 @@ -1461,6 +1500,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45528
45529 EXPORT_SYMBOL(search_binary_handler);
45530
45531 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45532 +static DEFINE_PER_CPU(u64, exec_counter);
45533 +static int __init init_exec_counters(void)
45534 +{
45535 + unsigned int cpu;
45536 +
45537 + for_each_possible_cpu(cpu) {
45538 + per_cpu(exec_counter, cpu) = (u64)cpu;
45539 + }
45540 +
45541 + return 0;
45542 +}
45543 +early_initcall(init_exec_counters);
45544 +static inline void increment_exec_counter(void)
45545 +{
45546 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45547 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45548 +}
45549 +#else
45550 +static inline void increment_exec_counter(void) {}
45551 +#endif
45552 +
45553 /*
45554 * sys_execve() executes a new program.
45555 */
45556 @@ -1469,6 +1530,11 @@ static int do_execve_common(const char *filename,
45557 struct user_arg_ptr envp,
45558 struct pt_regs *regs)
45559 {
45560 +#ifdef CONFIG_GRKERNSEC
45561 + struct file *old_exec_file;
45562 + struct acl_subject_label *old_acl;
45563 + struct rlimit old_rlim[RLIM_NLIMITS];
45564 +#endif
45565 struct linux_binprm *bprm;
45566 struct file *file;
45567 struct files_struct *displaced;
45568 @@ -1476,6 +1542,8 @@ static int do_execve_common(const char *filename,
45569 int retval;
45570 const struct cred *cred = current_cred();
45571
45572 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45573 +
45574 /*
45575 * We move the actual failure in case of RLIMIT_NPROC excess from
45576 * set*uid() to execve() because too many poorly written programs
45577 @@ -1516,12 +1584,27 @@ static int do_execve_common(const char *filename,
45578 if (IS_ERR(file))
45579 goto out_unmark;
45580
45581 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45582 + retval = -EPERM;
45583 + goto out_file;
45584 + }
45585 +
45586 sched_exec();
45587
45588 bprm->file = file;
45589 bprm->filename = filename;
45590 bprm->interp = filename;
45591
45592 + if (gr_process_user_ban()) {
45593 + retval = -EPERM;
45594 + goto out_file;
45595 + }
45596 +
45597 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45598 + retval = -EACCES;
45599 + goto out_file;
45600 + }
45601 +
45602 retval = bprm_mm_init(bprm);
45603 if (retval)
45604 goto out_file;
45605 @@ -1538,24 +1621,65 @@ static int do_execve_common(const char *filename,
45606 if (retval < 0)
45607 goto out;
45608
45609 +#ifdef CONFIG_GRKERNSEC
45610 + old_acl = current->acl;
45611 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45612 + old_exec_file = current->exec_file;
45613 + get_file(file);
45614 + current->exec_file = file;
45615 +#endif
45616 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45617 + /* limit suid stack to 8MB
45618 + we saved the old limits above and will restore them if this exec fails
45619 + */
45620 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45621 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45622 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45623 +#endif
45624 +
45625 + if (!gr_tpe_allow(file)) {
45626 + retval = -EACCES;
45627 + goto out_fail;
45628 + }
45629 +
45630 + if (gr_check_crash_exec(file)) {
45631 + retval = -EACCES;
45632 + goto out_fail;
45633 + }
45634 +
45635 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45636 + bprm->unsafe);
45637 + if (retval < 0)
45638 + goto out_fail;
45639 +
45640 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45641 if (retval < 0)
45642 - goto out;
45643 + goto out_fail;
45644
45645 bprm->exec = bprm->p;
45646 retval = copy_strings(bprm->envc, envp, bprm);
45647 if (retval < 0)
45648 - goto out;
45649 + goto out_fail;
45650
45651 retval = copy_strings(bprm->argc, argv, bprm);
45652 if (retval < 0)
45653 - goto out;
45654 + goto out_fail;
45655 +
45656 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45657 +
45658 + gr_handle_exec_args(bprm, argv);
45659
45660 retval = search_binary_handler(bprm,regs);
45661 if (retval < 0)
45662 - goto out;
45663 + goto out_fail;
45664 +#ifdef CONFIG_GRKERNSEC
45665 + if (old_exec_file)
45666 + fput(old_exec_file);
45667 +#endif
45668
45669 /* execve succeeded */
45670 +
45671 + increment_exec_counter();
45672 current->fs->in_exec = 0;
45673 current->in_execve = 0;
45674 acct_update_integrals(current);
45675 @@ -1564,6 +1688,14 @@ static int do_execve_common(const char *filename,
45676 put_files_struct(displaced);
45677 return retval;
45678
45679 +out_fail:
45680 +#ifdef CONFIG_GRKERNSEC
45681 + current->acl = old_acl;
45682 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45683 + fput(current->exec_file);
45684 + current->exec_file = old_exec_file;
45685 +#endif
45686 +
45687 out:
45688 if (bprm->mm) {
45689 acct_arg_size(bprm, 0);
45690 @@ -1637,7 +1769,7 @@ static int expand_corename(struct core_name *cn)
45691 {
45692 char *old_corename = cn->corename;
45693
45694 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45695 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45696 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45697
45698 if (!cn->corename) {
45699 @@ -1734,7 +1866,7 @@ static int format_corename(struct core_name *cn, long signr)
45700 int pid_in_pattern = 0;
45701 int err = 0;
45702
45703 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45704 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45705 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45706 cn->used = 0;
45707
45708 @@ -1831,6 +1963,250 @@ out:
45709 return ispipe;
45710 }
45711
45712 +int pax_check_flags(unsigned long *flags)
45713 +{
45714 + int retval = 0;
45715 +
45716 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45717 + if (*flags & MF_PAX_SEGMEXEC)
45718 + {
45719 + *flags &= ~MF_PAX_SEGMEXEC;
45720 + retval = -EINVAL;
45721 + }
45722 +#endif
45723 +
45724 + if ((*flags & MF_PAX_PAGEEXEC)
45725 +
45726 +#ifdef CONFIG_PAX_PAGEEXEC
45727 + && (*flags & MF_PAX_SEGMEXEC)
45728 +#endif
45729 +
45730 + )
45731 + {
45732 + *flags &= ~MF_PAX_PAGEEXEC;
45733 + retval = -EINVAL;
45734 + }
45735 +
45736 + if ((*flags & MF_PAX_MPROTECT)
45737 +
45738 +#ifdef CONFIG_PAX_MPROTECT
45739 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45740 +#endif
45741 +
45742 + )
45743 + {
45744 + *flags &= ~MF_PAX_MPROTECT;
45745 + retval = -EINVAL;
45746 + }
45747 +
45748 + if ((*flags & MF_PAX_EMUTRAMP)
45749 +
45750 +#ifdef CONFIG_PAX_EMUTRAMP
45751 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45752 +#endif
45753 +
45754 + )
45755 + {
45756 + *flags &= ~MF_PAX_EMUTRAMP;
45757 + retval = -EINVAL;
45758 + }
45759 +
45760 + return retval;
45761 +}
45762 +
45763 +EXPORT_SYMBOL(pax_check_flags);
45764 +
45765 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45766 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45767 +{
45768 + struct task_struct *tsk = current;
45769 + struct mm_struct *mm = current->mm;
45770 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45771 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45772 + char *path_exec = NULL;
45773 + char *path_fault = NULL;
45774 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45775 +
45776 + if (buffer_exec && buffer_fault) {
45777 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45778 +
45779 + down_read(&mm->mmap_sem);
45780 + vma = mm->mmap;
45781 + while (vma && (!vma_exec || !vma_fault)) {
45782 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45783 + vma_exec = vma;
45784 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45785 + vma_fault = vma;
45786 + vma = vma->vm_next;
45787 + }
45788 + if (vma_exec) {
45789 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45790 + if (IS_ERR(path_exec))
45791 + path_exec = "<path too long>";
45792 + else {
45793 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45794 + if (path_exec) {
45795 + *path_exec = 0;
45796 + path_exec = buffer_exec;
45797 + } else
45798 + path_exec = "<path too long>";
45799 + }
45800 + }
45801 + if (vma_fault) {
45802 + start = vma_fault->vm_start;
45803 + end = vma_fault->vm_end;
45804 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45805 + if (vma_fault->vm_file) {
45806 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45807 + if (IS_ERR(path_fault))
45808 + path_fault = "<path too long>";
45809 + else {
45810 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45811 + if (path_fault) {
45812 + *path_fault = 0;
45813 + path_fault = buffer_fault;
45814 + } else
45815 + path_fault = "<path too long>";
45816 + }
45817 + } else
45818 + path_fault = "<anonymous mapping>";
45819 + }
45820 + up_read(&mm->mmap_sem);
45821 + }
45822 + if (tsk->signal->curr_ip)
45823 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45824 + else
45825 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45826 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45827 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45828 + task_uid(tsk), task_euid(tsk), pc, sp);
45829 + free_page((unsigned long)buffer_exec);
45830 + free_page((unsigned long)buffer_fault);
45831 + pax_report_insns(regs, pc, sp);
45832 + do_coredump(SIGKILL, SIGKILL, regs);
45833 +}
45834 +#endif
45835 +
45836 +#ifdef CONFIG_PAX_REFCOUNT
45837 +void pax_report_refcount_overflow(struct pt_regs *regs)
45838 +{
45839 + if (current->signal->curr_ip)
45840 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45841 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45842 + else
45843 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45844 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45845 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45846 + show_regs(regs);
45847 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45848 +}
45849 +#endif
45850 +
45851 +#ifdef CONFIG_PAX_USERCOPY
45852 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45853 +static noinline int check_stack_object(const void *obj, unsigned long len)
45854 +{
45855 + const void * const stack = task_stack_page(current);
45856 + const void * const stackend = stack + THREAD_SIZE;
45857 +
45858 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45859 + const void *frame = NULL;
45860 + const void *oldframe;
45861 +#endif
45862 +
45863 + if (obj + len < obj)
45864 + return -1;
45865 +
45866 + if (obj + len <= stack || stackend <= obj)
45867 + return 0;
45868 +
45869 + if (obj < stack || stackend < obj + len)
45870 + return -1;
45871 +
45872 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45873 + oldframe = __builtin_frame_address(1);
45874 + if (oldframe)
45875 + frame = __builtin_frame_address(2);
45876 + /*
45877 + low ----------------------------------------------> high
45878 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45879 + ^----------------^
45880 + allow copies only within here
45881 + */
45882 + while (stack <= frame && frame < stackend) {
45883 + /* if obj + len extends past the last frame, this
45884 + check won't pass and the next frame will be 0,
45885 + causing us to bail out and correctly report
45886 + the copy as invalid
45887 + */
45888 + if (obj + len <= frame)
45889 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45890 + oldframe = frame;
45891 + frame = *(const void * const *)frame;
45892 + }
45893 + return -1;
45894 +#else
45895 + return 1;
45896 +#endif
45897 +}
45898 +
45899 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45900 +{
45901 + if (current->signal->curr_ip)
45902 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45903 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45904 + else
45905 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45906 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45907 + dump_stack();
45908 + gr_handle_kernel_exploit();
45909 + do_group_exit(SIGKILL);
45910 +}
45911 +#endif
45912 +
45913 +void check_object_size(const void *ptr, unsigned long n, bool to)
45914 +{
45915 +
45916 +#ifdef CONFIG_PAX_USERCOPY
45917 + const char *type;
45918 +
45919 + if (!n)
45920 + return;
45921 +
45922 + type = check_heap_object(ptr, n, to);
45923 + if (!type) {
45924 + if (check_stack_object(ptr, n) != -1)
45925 + return;
45926 + type = "<process stack>";
45927 + }
45928 +
45929 + pax_report_usercopy(ptr, n, to, type);
45930 +#endif
45931 +
45932 +}
45933 +EXPORT_SYMBOL(check_object_size);
45934 +
45935 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45936 +void pax_track_stack(void)
45937 +{
45938 + unsigned long sp = (unsigned long)&sp;
45939 + if (sp < current_thread_info()->lowest_stack &&
45940 + sp > (unsigned long)task_stack_page(current))
45941 + current_thread_info()->lowest_stack = sp;
45942 +}
45943 +EXPORT_SYMBOL(pax_track_stack);
45944 +#endif
45945 +
45946 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45947 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45948 +{
45949 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45950 + dump_stack();
45951 + do_group_exit(SIGKILL);
45952 +}
45953 +EXPORT_SYMBOL(report_size_overflow);
45954 +#endif
45955 +
45956 static int zap_process(struct task_struct *start, int exit_code)
45957 {
45958 struct task_struct *t;
45959 @@ -2041,17 +2417,17 @@ static void wait_for_dump_helpers(struct file *file)
45960 pipe = file->f_path.dentry->d_inode->i_pipe;
45961
45962 pipe_lock(pipe);
45963 - pipe->readers++;
45964 - pipe->writers--;
45965 + atomic_inc(&pipe->readers);
45966 + atomic_dec(&pipe->writers);
45967
45968 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45969 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45970 wake_up_interruptible_sync(&pipe->wait);
45971 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45972 pipe_wait(pipe);
45973 }
45974
45975 - pipe->readers--;
45976 - pipe->writers++;
45977 + atomic_dec(&pipe->readers);
45978 + atomic_inc(&pipe->writers);
45979 pipe_unlock(pipe);
45980
45981 }
45982 @@ -2106,7 +2482,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45983 int flag = 0;
45984 int ispipe;
45985 bool need_nonrelative = false;
45986 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45987 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45988 struct coredump_params cprm = {
45989 .signr = signr,
45990 .regs = regs,
45991 @@ -2121,6 +2497,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45992
45993 audit_core_dumps(signr);
45994
45995 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45996 + gr_handle_brute_attach(cprm.mm_flags);
45997 +
45998 binfmt = mm->binfmt;
45999 if (!binfmt || !binfmt->core_dump)
46000 goto fail;
46001 @@ -2191,7 +2570,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
46002 }
46003 cprm.limit = RLIM_INFINITY;
46004
46005 - dump_count = atomic_inc_return(&core_dump_count);
46006 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
46007 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46008 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46009 task_tgid_vnr(current), current->comm);
46010 @@ -2218,6 +2597,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
46011 } else {
46012 struct inode *inode;
46013
46014 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46015 +
46016 if (cprm.limit < binfmt->min_coredump)
46017 goto fail_unlock;
46018
46019 @@ -2269,7 +2650,7 @@ close_fail:
46020 filp_close(cprm.file, NULL);
46021 fail_dropcount:
46022 if (ispipe)
46023 - atomic_dec(&core_dump_count);
46024 + atomic_dec_unchecked(&core_dump_count);
46025 fail_unlock:
46026 kfree(cn.corename);
46027 fail_corename:
46028 @@ -2288,7 +2669,7 @@ fail:
46029 */
46030 int dump_write(struct file *file, const void *addr, int nr)
46031 {
46032 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46033 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46034 }
46035 EXPORT_SYMBOL(dump_write);
46036
46037 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
46038 index 376aa77..59a129c 100644
46039 --- a/fs/ext2/balloc.c
46040 +++ b/fs/ext2/balloc.c
46041 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
46042
46043 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
46044 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
46045 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
46046 + if (free_blocks < root_blocks + 1 &&
46047 !uid_eq(sbi->s_resuid, current_fsuid()) &&
46048 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
46049 - !in_group_p (sbi->s_resgid))) {
46050 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
46051 return 0;
46052 }
46053 return 1;
46054 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
46055 index 90d901f..159975f 100644
46056 --- a/fs/ext3/balloc.c
46057 +++ b/fs/ext3/balloc.c
46058 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
46059
46060 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
46061 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
46062 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
46063 + if (free_blocks < root_blocks + 1 &&
46064 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
46065 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
46066 - !in_group_p (sbi->s_resgid))) {
46067 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
46068 return 0;
46069 }
46070 return 1;
46071 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
46072 index cf18217..8f6b9c3 100644
46073 --- a/fs/ext4/balloc.c
46074 +++ b/fs/ext4/balloc.c
46075 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
46076 /* Hm, nope. Are (enough) root reserved clusters available? */
46077 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
46078 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
46079 - capable(CAP_SYS_RESOURCE) ||
46080 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
46081 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
46082 + capable_nolog(CAP_SYS_RESOURCE)) {
46083
46084 if (free_clusters >= (nclusters + dirty_clusters))
46085 return 1;
46086 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
46087 index b686b43..4b46d01 100644
46088 --- a/fs/ext4/ext4.h
46089 +++ b/fs/ext4/ext4.h
46090 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
46091 unsigned long s_mb_last_start;
46092
46093 /* stats for buddy allocator */
46094 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
46095 - atomic_t s_bal_success; /* we found long enough chunks */
46096 - atomic_t s_bal_allocated; /* in blocks */
46097 - atomic_t s_bal_ex_scanned; /* total extents scanned */
46098 - atomic_t s_bal_goals; /* goal hits */
46099 - atomic_t s_bal_breaks; /* too long searches */
46100 - atomic_t s_bal_2orders; /* 2^order hits */
46101 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
46102 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
46103 + atomic_unchecked_t s_bal_allocated; /* in blocks */
46104 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
46105 + atomic_unchecked_t s_bal_goals; /* goal hits */
46106 + atomic_unchecked_t s_bal_breaks; /* too long searches */
46107 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
46108 spinlock_t s_bal_lock;
46109 unsigned long s_mb_buddies_generated;
46110 unsigned long long s_mb_generation_time;
46111 - atomic_t s_mb_lost_chunks;
46112 - atomic_t s_mb_preallocated;
46113 - atomic_t s_mb_discarded;
46114 + atomic_unchecked_t s_mb_lost_chunks;
46115 + atomic_unchecked_t s_mb_preallocated;
46116 + atomic_unchecked_t s_mb_discarded;
46117 atomic_t s_lock_busy;
46118
46119 /* locality groups */
46120 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
46121 index b26410c..7383d90 100644
46122 --- a/fs/ext4/mballoc.c
46123 +++ b/fs/ext4/mballoc.c
46124 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
46125 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
46126
46127 if (EXT4_SB(sb)->s_mb_stats)
46128 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
46129 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
46130
46131 break;
46132 }
46133 @@ -2040,7 +2040,7 @@ repeat:
46134 ac->ac_status = AC_STATUS_CONTINUE;
46135 ac->ac_flags |= EXT4_MB_HINT_FIRST;
46136 cr = 3;
46137 - atomic_inc(&sbi->s_mb_lost_chunks);
46138 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
46139 goto repeat;
46140 }
46141 }
46142 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
46143 if (sbi->s_mb_stats) {
46144 ext4_msg(sb, KERN_INFO,
46145 "mballoc: %u blocks %u reqs (%u success)",
46146 - atomic_read(&sbi->s_bal_allocated),
46147 - atomic_read(&sbi->s_bal_reqs),
46148 - atomic_read(&sbi->s_bal_success));
46149 + atomic_read_unchecked(&sbi->s_bal_allocated),
46150 + atomic_read_unchecked(&sbi->s_bal_reqs),
46151 + atomic_read_unchecked(&sbi->s_bal_success));
46152 ext4_msg(sb, KERN_INFO,
46153 "mballoc: %u extents scanned, %u goal hits, "
46154 "%u 2^N hits, %u breaks, %u lost",
46155 - atomic_read(&sbi->s_bal_ex_scanned),
46156 - atomic_read(&sbi->s_bal_goals),
46157 - atomic_read(&sbi->s_bal_2orders),
46158 - atomic_read(&sbi->s_bal_breaks),
46159 - atomic_read(&sbi->s_mb_lost_chunks));
46160 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
46161 + atomic_read_unchecked(&sbi->s_bal_goals),
46162 + atomic_read_unchecked(&sbi->s_bal_2orders),
46163 + atomic_read_unchecked(&sbi->s_bal_breaks),
46164 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
46165 ext4_msg(sb, KERN_INFO,
46166 "mballoc: %lu generated and it took %Lu",
46167 sbi->s_mb_buddies_generated,
46168 sbi->s_mb_generation_time);
46169 ext4_msg(sb, KERN_INFO,
46170 "mballoc: %u preallocated, %u discarded",
46171 - atomic_read(&sbi->s_mb_preallocated),
46172 - atomic_read(&sbi->s_mb_discarded));
46173 + atomic_read_unchecked(&sbi->s_mb_preallocated),
46174 + atomic_read_unchecked(&sbi->s_mb_discarded));
46175 }
46176
46177 free_percpu(sbi->s_locality_groups);
46178 @@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
46179 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
46180
46181 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
46182 - atomic_inc(&sbi->s_bal_reqs);
46183 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46184 + atomic_inc_unchecked(&sbi->s_bal_reqs);
46185 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46186 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
46187 - atomic_inc(&sbi->s_bal_success);
46188 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
46189 + atomic_inc_unchecked(&sbi->s_bal_success);
46190 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
46191 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
46192 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
46193 - atomic_inc(&sbi->s_bal_goals);
46194 + atomic_inc_unchecked(&sbi->s_bal_goals);
46195 if (ac->ac_found > sbi->s_mb_max_to_scan)
46196 - atomic_inc(&sbi->s_bal_breaks);
46197 + atomic_inc_unchecked(&sbi->s_bal_breaks);
46198 }
46199
46200 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
46201 @@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
46202 trace_ext4_mb_new_inode_pa(ac, pa);
46203
46204 ext4_mb_use_inode_pa(ac, pa);
46205 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
46206 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
46207
46208 ei = EXT4_I(ac->ac_inode);
46209 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46210 @@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
46211 trace_ext4_mb_new_group_pa(ac, pa);
46212
46213 ext4_mb_use_group_pa(ac, pa);
46214 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46215 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46216
46217 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46218 lg = ac->ac_lg;
46219 @@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
46220 * from the bitmap and continue.
46221 */
46222 }
46223 - atomic_add(free, &sbi->s_mb_discarded);
46224 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
46225
46226 return err;
46227 }
46228 @@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
46229 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
46230 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
46231 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
46232 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46233 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46234 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
46235
46236 return 0;
46237 diff --git a/fs/fcntl.c b/fs/fcntl.c
46238 index 887b5ba..0e3f2c3 100644
46239 --- a/fs/fcntl.c
46240 +++ b/fs/fcntl.c
46241 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
46242 if (err)
46243 return err;
46244
46245 + if (gr_handle_chroot_fowner(pid, type))
46246 + return -ENOENT;
46247 + if (gr_check_protected_task_fowner(pid, type))
46248 + return -EACCES;
46249 +
46250 f_modown(filp, pid, type, force);
46251 return 0;
46252 }
46253 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
46254
46255 static int f_setown_ex(struct file *filp, unsigned long arg)
46256 {
46257 - struct f_owner_ex * __user owner_p = (void * __user)arg;
46258 + struct f_owner_ex __user *owner_p = (void __user *)arg;
46259 struct f_owner_ex owner;
46260 struct pid *pid;
46261 int type;
46262 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
46263
46264 static int f_getown_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 int ret = 0;
46270
46271 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
46272 switch (cmd) {
46273 case F_DUPFD:
46274 case F_DUPFD_CLOEXEC:
46275 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
46276 if (arg >= rlimit(RLIMIT_NOFILE))
46277 break;
46278 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
46279 diff --git a/fs/fifo.c b/fs/fifo.c
46280 index cf6f434..3d7942c 100644
46281 --- a/fs/fifo.c
46282 +++ b/fs/fifo.c
46283 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
46284 */
46285 filp->f_op = &read_pipefifo_fops;
46286 pipe->r_counter++;
46287 - if (pipe->readers++ == 0)
46288 + if (atomic_inc_return(&pipe->readers) == 1)
46289 wake_up_partner(inode);
46290
46291 - if (!pipe->writers) {
46292 + if (!atomic_read(&pipe->writers)) {
46293 if ((filp->f_flags & O_NONBLOCK)) {
46294 /* suppress POLLHUP until we have
46295 * seen a writer */
46296 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
46297 * errno=ENXIO when there is no process reading the FIFO.
46298 */
46299 ret = -ENXIO;
46300 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46301 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46302 goto err;
46303
46304 filp->f_op = &write_pipefifo_fops;
46305 pipe->w_counter++;
46306 - if (!pipe->writers++)
46307 + if (atomic_inc_return(&pipe->writers) == 1)
46308 wake_up_partner(inode);
46309
46310 - if (!pipe->readers) {
46311 + if (!atomic_read(&pipe->readers)) {
46312 if (wait_for_partner(inode, &pipe->r_counter))
46313 goto err_wr;
46314 }
46315 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
46316 */
46317 filp->f_op = &rdwr_pipefifo_fops;
46318
46319 - pipe->readers++;
46320 - pipe->writers++;
46321 + atomic_inc(&pipe->readers);
46322 + atomic_inc(&pipe->writers);
46323 pipe->r_counter++;
46324 pipe->w_counter++;
46325 - if (pipe->readers == 1 || pipe->writers == 1)
46326 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46327 wake_up_partner(inode);
46328 break;
46329
46330 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
46331 return 0;
46332
46333 err_rd:
46334 - if (!--pipe->readers)
46335 + if (atomic_dec_and_test(&pipe->readers))
46336 wake_up_interruptible(&pipe->wait);
46337 ret = -ERESTARTSYS;
46338 goto err;
46339
46340 err_wr:
46341 - if (!--pipe->writers)
46342 + if (atomic_dec_and_test(&pipe->writers))
46343 wake_up_interruptible(&pipe->wait);
46344 ret = -ERESTARTSYS;
46345 goto err;
46346
46347 err:
46348 - if (!pipe->readers && !pipe->writers)
46349 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46350 free_pipe_info(inode);
46351
46352 err_nocleanup:
46353 diff --git a/fs/file.c b/fs/file.c
46354 index ba3f605..fade102 100644
46355 --- a/fs/file.c
46356 +++ b/fs/file.c
46357 @@ -15,6 +15,7 @@
46358 #include <linux/slab.h>
46359 #include <linux/vmalloc.h>
46360 #include <linux/file.h>
46361 +#include <linux/security.h>
46362 #include <linux/fdtable.h>
46363 #include <linux/bitops.h>
46364 #include <linux/interrupt.h>
46365 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
46366 * N.B. For clone tasks sharing a files structure, this test
46367 * will limit the total number of files that can be opened.
46368 */
46369 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46370 if (nr >= rlimit(RLIMIT_NOFILE))
46371 return -EMFILE;
46372
46373 diff --git a/fs/filesystems.c b/fs/filesystems.c
46374 index 96f2428..f5eeb8e 100644
46375 --- a/fs/filesystems.c
46376 +++ b/fs/filesystems.c
46377 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
46378 int len = dot ? dot - name : strlen(name);
46379
46380 fs = __get_fs_type(name, len);
46381 +
46382 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
46383 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46384 +#else
46385 if (!fs && (request_module("%.*s", len, name) == 0))
46386 +#endif
46387 fs = __get_fs_type(name, len);
46388
46389 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46390 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
46391 index 5df4775..f656176 100644
46392 --- a/fs/fs_struct.c
46393 +++ b/fs/fs_struct.c
46394 @@ -4,6 +4,7 @@
46395 #include <linux/path.h>
46396 #include <linux/slab.h>
46397 #include <linux/fs_struct.h>
46398 +#include <linux/grsecurity.h>
46399 #include "internal.h"
46400
46401 /*
46402 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
46403 write_seqcount_begin(&fs->seq);
46404 old_root = fs->root;
46405 fs->root = *path;
46406 + gr_set_chroot_entries(current, path);
46407 write_seqcount_end(&fs->seq);
46408 spin_unlock(&fs->lock);
46409 if (old_root.dentry)
46410 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
46411 return 1;
46412 }
46413
46414 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
46415 +{
46416 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
46417 + return 0;
46418 + *p = *new;
46419 +
46420 + /* This function is only called from pivot_root(). Leave our
46421 + gr_chroot_dentry and is_chrooted flags as-is, so that a
46422 + pivoted root isn't treated as a chroot
46423 + */
46424 + //gr_set_chroot_entries(task, new);
46425 +
46426 + return 1;
46427 +}
46428 +
46429 void chroot_fs_refs(struct path *old_root, struct path *new_root)
46430 {
46431 struct task_struct *g, *p;
46432 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
46433 int hits = 0;
46434 spin_lock(&fs->lock);
46435 write_seqcount_begin(&fs->seq);
46436 - hits += replace_path(&fs->root, old_root, new_root);
46437 + hits += replace_root_path(p, &fs->root, old_root, new_root);
46438 hits += replace_path(&fs->pwd, old_root, new_root);
46439 write_seqcount_end(&fs->seq);
46440 while (hits--) {
46441 @@ -94,12 +111,15 @@ void exit_fs(struct task_struct *tsk)
46442 {
46443 struct fs_struct *fs = tsk->fs;
46444
46445 + gr_put_exec_file(tsk);
46446 +
46447 if (fs) {
46448 int kill;
46449 task_lock(tsk);
46450 spin_lock(&fs->lock);
46451 tsk->fs = NULL;
46452 - kill = !--fs->users;
46453 + gr_clear_chroot_entries(tsk);
46454 + kill = !atomic_dec_return(&fs->users);
46455 spin_unlock(&fs->lock);
46456 task_unlock(tsk);
46457 if (kill)
46458 @@ -112,7 +132,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46459 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46460 /* We don't need to lock fs - think why ;-) */
46461 if (fs) {
46462 - fs->users = 1;
46463 + atomic_set(&fs->users, 1);
46464 fs->in_exec = 0;
46465 spin_lock_init(&fs->lock);
46466 seqcount_init(&fs->seq);
46467 @@ -121,6 +141,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46468 spin_lock(&old->lock);
46469 fs->root = old->root;
46470 path_get(&fs->root);
46471 + /* instead of calling gr_set_chroot_entries here,
46472 + we call it from every caller of this function
46473 + */
46474 fs->pwd = old->pwd;
46475 path_get(&fs->pwd);
46476 spin_unlock(&old->lock);
46477 @@ -139,8 +162,9 @@ int unshare_fs_struct(void)
46478
46479 task_lock(current);
46480 spin_lock(&fs->lock);
46481 - kill = !--fs->users;
46482 + kill = !atomic_dec_return(&fs->users);
46483 current->fs = new_fs;
46484 + gr_set_chroot_entries(current, &new_fs->root);
46485 spin_unlock(&fs->lock);
46486 task_unlock(current);
46487
46488 @@ -153,13 +177,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46489
46490 int current_umask(void)
46491 {
46492 - return current->fs->umask;
46493 + return current->fs->umask | gr_acl_umask();
46494 }
46495 EXPORT_SYMBOL(current_umask);
46496
46497 /* to be mentioned only in INIT_TASK */
46498 struct fs_struct init_fs = {
46499 - .users = 1,
46500 + .users = ATOMIC_INIT(1),
46501 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46502 .seq = SEQCNT_ZERO,
46503 .umask = 0022,
46504 @@ -169,18 +193,21 @@ void daemonize_fs_struct(void)
46505 {
46506 struct fs_struct *fs = current->fs;
46507
46508 + gr_put_exec_file(current);
46509 +
46510 if (fs) {
46511 int kill;
46512
46513 task_lock(current);
46514
46515 spin_lock(&init_fs.lock);
46516 - init_fs.users++;
46517 + atomic_inc(&init_fs.users);
46518 spin_unlock(&init_fs.lock);
46519
46520 spin_lock(&fs->lock);
46521 current->fs = &init_fs;
46522 - kill = !--fs->users;
46523 + gr_set_chroot_entries(current, &current->fs->root);
46524 + kill = !atomic_dec_return(&fs->users);
46525 spin_unlock(&fs->lock);
46526
46527 task_unlock(current);
46528 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46529 index 9905350..02eaec4 100644
46530 --- a/fs/fscache/cookie.c
46531 +++ b/fs/fscache/cookie.c
46532 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46533 parent ? (char *) parent->def->name : "<no-parent>",
46534 def->name, netfs_data);
46535
46536 - fscache_stat(&fscache_n_acquires);
46537 + fscache_stat_unchecked(&fscache_n_acquires);
46538
46539 /* if there's no parent cookie, then we don't create one here either */
46540 if (!parent) {
46541 - fscache_stat(&fscache_n_acquires_null);
46542 + fscache_stat_unchecked(&fscache_n_acquires_null);
46543 _leave(" [no parent]");
46544 return NULL;
46545 }
46546 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46547 /* allocate and initialise a cookie */
46548 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46549 if (!cookie) {
46550 - fscache_stat(&fscache_n_acquires_oom);
46551 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46552 _leave(" [ENOMEM]");
46553 return NULL;
46554 }
46555 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46556
46557 switch (cookie->def->type) {
46558 case FSCACHE_COOKIE_TYPE_INDEX:
46559 - fscache_stat(&fscache_n_cookie_index);
46560 + fscache_stat_unchecked(&fscache_n_cookie_index);
46561 break;
46562 case FSCACHE_COOKIE_TYPE_DATAFILE:
46563 - fscache_stat(&fscache_n_cookie_data);
46564 + fscache_stat_unchecked(&fscache_n_cookie_data);
46565 break;
46566 default:
46567 - fscache_stat(&fscache_n_cookie_special);
46568 + fscache_stat_unchecked(&fscache_n_cookie_special);
46569 break;
46570 }
46571
46572 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46573 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46574 atomic_dec(&parent->n_children);
46575 __fscache_cookie_put(cookie);
46576 - fscache_stat(&fscache_n_acquires_nobufs);
46577 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46578 _leave(" = NULL");
46579 return NULL;
46580 }
46581 }
46582
46583 - fscache_stat(&fscache_n_acquires_ok);
46584 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46585 _leave(" = %p", cookie);
46586 return cookie;
46587 }
46588 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46589 cache = fscache_select_cache_for_object(cookie->parent);
46590 if (!cache) {
46591 up_read(&fscache_addremove_sem);
46592 - fscache_stat(&fscache_n_acquires_no_cache);
46593 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46594 _leave(" = -ENOMEDIUM [no cache]");
46595 return -ENOMEDIUM;
46596 }
46597 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46598 object = cache->ops->alloc_object(cache, cookie);
46599 fscache_stat_d(&fscache_n_cop_alloc_object);
46600 if (IS_ERR(object)) {
46601 - fscache_stat(&fscache_n_object_no_alloc);
46602 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46603 ret = PTR_ERR(object);
46604 goto error;
46605 }
46606
46607 - fscache_stat(&fscache_n_object_alloc);
46608 + fscache_stat_unchecked(&fscache_n_object_alloc);
46609
46610 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46611
46612 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46613 struct fscache_object *object;
46614 struct hlist_node *_p;
46615
46616 - fscache_stat(&fscache_n_updates);
46617 + fscache_stat_unchecked(&fscache_n_updates);
46618
46619 if (!cookie) {
46620 - fscache_stat(&fscache_n_updates_null);
46621 + fscache_stat_unchecked(&fscache_n_updates_null);
46622 _leave(" [no cookie]");
46623 return;
46624 }
46625 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46626 struct fscache_object *object;
46627 unsigned long event;
46628
46629 - fscache_stat(&fscache_n_relinquishes);
46630 + fscache_stat_unchecked(&fscache_n_relinquishes);
46631 if (retire)
46632 - fscache_stat(&fscache_n_relinquishes_retire);
46633 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46634
46635 if (!cookie) {
46636 - fscache_stat(&fscache_n_relinquishes_null);
46637 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46638 _leave(" [no cookie]");
46639 return;
46640 }
46641 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46642
46643 /* wait for the cookie to finish being instantiated (or to fail) */
46644 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46645 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46646 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46647 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46648 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46649 }
46650 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46651 index f6aad48..88dcf26 100644
46652 --- a/fs/fscache/internal.h
46653 +++ b/fs/fscache/internal.h
46654 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46655 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46656 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46657
46658 -extern atomic_t fscache_n_op_pend;
46659 -extern atomic_t fscache_n_op_run;
46660 -extern atomic_t fscache_n_op_enqueue;
46661 -extern atomic_t fscache_n_op_deferred_release;
46662 -extern atomic_t fscache_n_op_release;
46663 -extern atomic_t fscache_n_op_gc;
46664 -extern atomic_t fscache_n_op_cancelled;
46665 -extern atomic_t fscache_n_op_rejected;
46666 +extern atomic_unchecked_t fscache_n_op_pend;
46667 +extern atomic_unchecked_t fscache_n_op_run;
46668 +extern atomic_unchecked_t fscache_n_op_enqueue;
46669 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46670 +extern atomic_unchecked_t fscache_n_op_release;
46671 +extern atomic_unchecked_t fscache_n_op_gc;
46672 +extern atomic_unchecked_t fscache_n_op_cancelled;
46673 +extern atomic_unchecked_t fscache_n_op_rejected;
46674
46675 -extern atomic_t fscache_n_attr_changed;
46676 -extern atomic_t fscache_n_attr_changed_ok;
46677 -extern atomic_t fscache_n_attr_changed_nobufs;
46678 -extern atomic_t fscache_n_attr_changed_nomem;
46679 -extern atomic_t fscache_n_attr_changed_calls;
46680 +extern atomic_unchecked_t fscache_n_attr_changed;
46681 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46682 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46683 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46684 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46685
46686 -extern atomic_t fscache_n_allocs;
46687 -extern atomic_t fscache_n_allocs_ok;
46688 -extern atomic_t fscache_n_allocs_wait;
46689 -extern atomic_t fscache_n_allocs_nobufs;
46690 -extern atomic_t fscache_n_allocs_intr;
46691 -extern atomic_t fscache_n_allocs_object_dead;
46692 -extern atomic_t fscache_n_alloc_ops;
46693 -extern atomic_t fscache_n_alloc_op_waits;
46694 +extern atomic_unchecked_t fscache_n_allocs;
46695 +extern atomic_unchecked_t fscache_n_allocs_ok;
46696 +extern atomic_unchecked_t fscache_n_allocs_wait;
46697 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46698 +extern atomic_unchecked_t fscache_n_allocs_intr;
46699 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46700 +extern atomic_unchecked_t fscache_n_alloc_ops;
46701 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46702
46703 -extern atomic_t fscache_n_retrievals;
46704 -extern atomic_t fscache_n_retrievals_ok;
46705 -extern atomic_t fscache_n_retrievals_wait;
46706 -extern atomic_t fscache_n_retrievals_nodata;
46707 -extern atomic_t fscache_n_retrievals_nobufs;
46708 -extern atomic_t fscache_n_retrievals_intr;
46709 -extern atomic_t fscache_n_retrievals_nomem;
46710 -extern atomic_t fscache_n_retrievals_object_dead;
46711 -extern atomic_t fscache_n_retrieval_ops;
46712 -extern atomic_t fscache_n_retrieval_op_waits;
46713 +extern atomic_unchecked_t fscache_n_retrievals;
46714 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46715 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46716 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46717 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46718 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46719 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46720 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46721 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46722 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46723
46724 -extern atomic_t fscache_n_stores;
46725 -extern atomic_t fscache_n_stores_ok;
46726 -extern atomic_t fscache_n_stores_again;
46727 -extern atomic_t fscache_n_stores_nobufs;
46728 -extern atomic_t fscache_n_stores_oom;
46729 -extern atomic_t fscache_n_store_ops;
46730 -extern atomic_t fscache_n_store_calls;
46731 -extern atomic_t fscache_n_store_pages;
46732 -extern atomic_t fscache_n_store_radix_deletes;
46733 -extern atomic_t fscache_n_store_pages_over_limit;
46734 +extern atomic_unchecked_t fscache_n_stores;
46735 +extern atomic_unchecked_t fscache_n_stores_ok;
46736 +extern atomic_unchecked_t fscache_n_stores_again;
46737 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46738 +extern atomic_unchecked_t fscache_n_stores_oom;
46739 +extern atomic_unchecked_t fscache_n_store_ops;
46740 +extern atomic_unchecked_t fscache_n_store_calls;
46741 +extern atomic_unchecked_t fscache_n_store_pages;
46742 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46743 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46744
46745 -extern atomic_t fscache_n_store_vmscan_not_storing;
46746 -extern atomic_t fscache_n_store_vmscan_gone;
46747 -extern atomic_t fscache_n_store_vmscan_busy;
46748 -extern atomic_t fscache_n_store_vmscan_cancelled;
46749 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46750 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46751 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46752 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46753
46754 -extern atomic_t fscache_n_marks;
46755 -extern atomic_t fscache_n_uncaches;
46756 +extern atomic_unchecked_t fscache_n_marks;
46757 +extern atomic_unchecked_t fscache_n_uncaches;
46758
46759 -extern atomic_t fscache_n_acquires;
46760 -extern atomic_t fscache_n_acquires_null;
46761 -extern atomic_t fscache_n_acquires_no_cache;
46762 -extern atomic_t fscache_n_acquires_ok;
46763 -extern atomic_t fscache_n_acquires_nobufs;
46764 -extern atomic_t fscache_n_acquires_oom;
46765 +extern atomic_unchecked_t fscache_n_acquires;
46766 +extern atomic_unchecked_t fscache_n_acquires_null;
46767 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46768 +extern atomic_unchecked_t fscache_n_acquires_ok;
46769 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46770 +extern atomic_unchecked_t fscache_n_acquires_oom;
46771
46772 -extern atomic_t fscache_n_updates;
46773 -extern atomic_t fscache_n_updates_null;
46774 -extern atomic_t fscache_n_updates_run;
46775 +extern atomic_unchecked_t fscache_n_updates;
46776 +extern atomic_unchecked_t fscache_n_updates_null;
46777 +extern atomic_unchecked_t fscache_n_updates_run;
46778
46779 -extern atomic_t fscache_n_relinquishes;
46780 -extern atomic_t fscache_n_relinquishes_null;
46781 -extern atomic_t fscache_n_relinquishes_waitcrt;
46782 -extern atomic_t fscache_n_relinquishes_retire;
46783 +extern atomic_unchecked_t fscache_n_relinquishes;
46784 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46785 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46786 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46787
46788 -extern atomic_t fscache_n_cookie_index;
46789 -extern atomic_t fscache_n_cookie_data;
46790 -extern atomic_t fscache_n_cookie_special;
46791 +extern atomic_unchecked_t fscache_n_cookie_index;
46792 +extern atomic_unchecked_t fscache_n_cookie_data;
46793 +extern atomic_unchecked_t fscache_n_cookie_special;
46794
46795 -extern atomic_t fscache_n_object_alloc;
46796 -extern atomic_t fscache_n_object_no_alloc;
46797 -extern atomic_t fscache_n_object_lookups;
46798 -extern atomic_t fscache_n_object_lookups_negative;
46799 -extern atomic_t fscache_n_object_lookups_positive;
46800 -extern atomic_t fscache_n_object_lookups_timed_out;
46801 -extern atomic_t fscache_n_object_created;
46802 -extern atomic_t fscache_n_object_avail;
46803 -extern atomic_t fscache_n_object_dead;
46804 +extern atomic_unchecked_t fscache_n_object_alloc;
46805 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46806 +extern atomic_unchecked_t fscache_n_object_lookups;
46807 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46808 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46809 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46810 +extern atomic_unchecked_t fscache_n_object_created;
46811 +extern atomic_unchecked_t fscache_n_object_avail;
46812 +extern atomic_unchecked_t fscache_n_object_dead;
46813
46814 -extern atomic_t fscache_n_checkaux_none;
46815 -extern atomic_t fscache_n_checkaux_okay;
46816 -extern atomic_t fscache_n_checkaux_update;
46817 -extern atomic_t fscache_n_checkaux_obsolete;
46818 +extern atomic_unchecked_t fscache_n_checkaux_none;
46819 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46820 +extern atomic_unchecked_t fscache_n_checkaux_update;
46821 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46822
46823 extern atomic_t fscache_n_cop_alloc_object;
46824 extern atomic_t fscache_n_cop_lookup_object;
46825 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46826 atomic_inc(stat);
46827 }
46828
46829 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46830 +{
46831 + atomic_inc_unchecked(stat);
46832 +}
46833 +
46834 static inline void fscache_stat_d(atomic_t *stat)
46835 {
46836 atomic_dec(stat);
46837 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46838
46839 #define __fscache_stat(stat) (NULL)
46840 #define fscache_stat(stat) do {} while (0)
46841 +#define fscache_stat_unchecked(stat) do {} while (0)
46842 #define fscache_stat_d(stat) do {} while (0)
46843 #endif
46844
46845 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46846 index b6b897c..0ffff9c 100644
46847 --- a/fs/fscache/object.c
46848 +++ b/fs/fscache/object.c
46849 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46850 /* update the object metadata on disk */
46851 case FSCACHE_OBJECT_UPDATING:
46852 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46853 - fscache_stat(&fscache_n_updates_run);
46854 + fscache_stat_unchecked(&fscache_n_updates_run);
46855 fscache_stat(&fscache_n_cop_update_object);
46856 object->cache->ops->update_object(object);
46857 fscache_stat_d(&fscache_n_cop_update_object);
46858 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46859 spin_lock(&object->lock);
46860 object->state = FSCACHE_OBJECT_DEAD;
46861 spin_unlock(&object->lock);
46862 - fscache_stat(&fscache_n_object_dead);
46863 + fscache_stat_unchecked(&fscache_n_object_dead);
46864 goto terminal_transit;
46865
46866 /* handle the parent cache of this object being withdrawn from
46867 @@ -232,7 +232,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 /* complain about the object being woken up once it is
46876 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46877 parent->cookie->def->name, cookie->def->name,
46878 object->cache->tag->name);
46879
46880 - fscache_stat(&fscache_n_object_lookups);
46881 + fscache_stat_unchecked(&fscache_n_object_lookups);
46882 fscache_stat(&fscache_n_cop_lookup_object);
46883 ret = object->cache->ops->lookup_object(object);
46884 fscache_stat_d(&fscache_n_cop_lookup_object);
46885 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46886 if (ret == -ETIMEDOUT) {
46887 /* probably stuck behind another object, so move this one to
46888 * the back of the queue */
46889 - fscache_stat(&fscache_n_object_lookups_timed_out);
46890 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46891 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46892 }
46893
46894 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46895
46896 spin_lock(&object->lock);
46897 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46898 - fscache_stat(&fscache_n_object_lookups_negative);
46899 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46900
46901 /* transit here to allow write requests to begin stacking up
46902 * and read requests to begin returning ENODATA */
46903 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46904 * result, in which case there may be data available */
46905 spin_lock(&object->lock);
46906 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46907 - fscache_stat(&fscache_n_object_lookups_positive);
46908 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46909
46910 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46911
46912 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46913 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46914 } else {
46915 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46916 - fscache_stat(&fscache_n_object_created);
46917 + fscache_stat_unchecked(&fscache_n_object_created);
46918
46919 object->state = FSCACHE_OBJECT_AVAILABLE;
46920 spin_unlock(&object->lock);
46921 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46922 fscache_enqueue_dependents(object);
46923
46924 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46925 - fscache_stat(&fscache_n_object_avail);
46926 + fscache_stat_unchecked(&fscache_n_object_avail);
46927
46928 _leave("");
46929 }
46930 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46931 enum fscache_checkaux result;
46932
46933 if (!object->cookie->def->check_aux) {
46934 - fscache_stat(&fscache_n_checkaux_none);
46935 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46936 return FSCACHE_CHECKAUX_OKAY;
46937 }
46938
46939 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46940 switch (result) {
46941 /* entry okay as is */
46942 case FSCACHE_CHECKAUX_OKAY:
46943 - fscache_stat(&fscache_n_checkaux_okay);
46944 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46945 break;
46946
46947 /* entry requires update */
46948 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46949 - fscache_stat(&fscache_n_checkaux_update);
46950 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46951 break;
46952
46953 /* entry requires deletion */
46954 case FSCACHE_CHECKAUX_OBSOLETE:
46955 - fscache_stat(&fscache_n_checkaux_obsolete);
46956 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46957 break;
46958
46959 default:
46960 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46961 index 30afdfa..2256596 100644
46962 --- a/fs/fscache/operation.c
46963 +++ b/fs/fscache/operation.c
46964 @@ -17,7 +17,7 @@
46965 #include <linux/slab.h>
46966 #include "internal.h"
46967
46968 -atomic_t fscache_op_debug_id;
46969 +atomic_unchecked_t fscache_op_debug_id;
46970 EXPORT_SYMBOL(fscache_op_debug_id);
46971
46972 /**
46973 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46974 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46975 ASSERTCMP(atomic_read(&op->usage), >, 0);
46976
46977 - fscache_stat(&fscache_n_op_enqueue);
46978 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46979 switch (op->flags & FSCACHE_OP_TYPE) {
46980 case FSCACHE_OP_ASYNC:
46981 _debug("queue async");
46982 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46983 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46984 if (op->processor)
46985 fscache_enqueue_operation(op);
46986 - fscache_stat(&fscache_n_op_run);
46987 + fscache_stat_unchecked(&fscache_n_op_run);
46988 }
46989
46990 /*
46991 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46992 if (object->n_ops > 1) {
46993 atomic_inc(&op->usage);
46994 list_add_tail(&op->pend_link, &object->pending_ops);
46995 - fscache_stat(&fscache_n_op_pend);
46996 + fscache_stat_unchecked(&fscache_n_op_pend);
46997 } else if (!list_empty(&object->pending_ops)) {
46998 atomic_inc(&op->usage);
46999 list_add_tail(&op->pend_link, &object->pending_ops);
47000 - fscache_stat(&fscache_n_op_pend);
47001 + fscache_stat_unchecked(&fscache_n_op_pend);
47002 fscache_start_operations(object);
47003 } else {
47004 ASSERTCMP(object->n_in_progress, ==, 0);
47005 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
47006 object->n_exclusive++; /* reads and writes must wait */
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 ret = 0;
47012 } else {
47013 /* not allowed to submit ops in any other state */
47014 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
47015 if (object->n_exclusive > 0) {
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 } else if (!list_empty(&object->pending_ops)) {
47021 atomic_inc(&op->usage);
47022 list_add_tail(&op->pend_link, &object->pending_ops);
47023 - fscache_stat(&fscache_n_op_pend);
47024 + fscache_stat_unchecked(&fscache_n_op_pend);
47025 fscache_start_operations(object);
47026 } else {
47027 ASSERTCMP(object->n_exclusive, ==, 0);
47028 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
47029 object->n_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 ret = 0;
47035 } else if (object->state == FSCACHE_OBJECT_DYING ||
47036 object->state == FSCACHE_OBJECT_LC_DYING ||
47037 object->state == FSCACHE_OBJECT_WITHDRAWING) {
47038 - fscache_stat(&fscache_n_op_rejected);
47039 + fscache_stat_unchecked(&fscache_n_op_rejected);
47040 ret = -ENOBUFS;
47041 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
47042 fscache_report_unexpected_submission(object, op, ostate);
47043 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
47044
47045 ret = -EBUSY;
47046 if (!list_empty(&op->pend_link)) {
47047 - fscache_stat(&fscache_n_op_cancelled);
47048 + fscache_stat_unchecked(&fscache_n_op_cancelled);
47049 list_del_init(&op->pend_link);
47050 object->n_ops--;
47051 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
47052 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
47053 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
47054 BUG();
47055
47056 - fscache_stat(&fscache_n_op_release);
47057 + fscache_stat_unchecked(&fscache_n_op_release);
47058
47059 if (op->release) {
47060 op->release(op);
47061 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
47062 * lock, and defer it otherwise */
47063 if (!spin_trylock(&object->lock)) {
47064 _debug("defer put");
47065 - fscache_stat(&fscache_n_op_deferred_release);
47066 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
47067
47068 cache = object->cache;
47069 spin_lock(&cache->op_gc_list_lock);
47070 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
47071
47072 _debug("GC DEFERRED REL OBJ%x OP%x",
47073 object->debug_id, op->debug_id);
47074 - fscache_stat(&fscache_n_op_gc);
47075 + fscache_stat_unchecked(&fscache_n_op_gc);
47076
47077 ASSERTCMP(atomic_read(&op->usage), ==, 0);
47078
47079 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
47080 index 3f7a59b..cf196cc 100644
47081 --- a/fs/fscache/page.c
47082 +++ b/fs/fscache/page.c
47083 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
47084 val = radix_tree_lookup(&cookie->stores, page->index);
47085 if (!val) {
47086 rcu_read_unlock();
47087 - fscache_stat(&fscache_n_store_vmscan_not_storing);
47088 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
47089 __fscache_uncache_page(cookie, page);
47090 return true;
47091 }
47092 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
47093 spin_unlock(&cookie->stores_lock);
47094
47095 if (xpage) {
47096 - fscache_stat(&fscache_n_store_vmscan_cancelled);
47097 - fscache_stat(&fscache_n_store_radix_deletes);
47098 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
47099 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
47100 ASSERTCMP(xpage, ==, page);
47101 } else {
47102 - fscache_stat(&fscache_n_store_vmscan_gone);
47103 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
47104 }
47105
47106 wake_up_bit(&cookie->flags, 0);
47107 @@ -107,7 +107,7 @@ page_busy:
47108 /* we might want to wait here, but that could deadlock the allocator as
47109 * the work threads writing to the cache may all end up sleeping
47110 * on memory allocation */
47111 - fscache_stat(&fscache_n_store_vmscan_busy);
47112 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
47113 return false;
47114 }
47115 EXPORT_SYMBOL(__fscache_maybe_release_page);
47116 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
47117 FSCACHE_COOKIE_STORING_TAG);
47118 if (!radix_tree_tag_get(&cookie->stores, page->index,
47119 FSCACHE_COOKIE_PENDING_TAG)) {
47120 - fscache_stat(&fscache_n_store_radix_deletes);
47121 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
47122 xpage = radix_tree_delete(&cookie->stores, page->index);
47123 }
47124 spin_unlock(&cookie->stores_lock);
47125 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
47126
47127 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
47128
47129 - fscache_stat(&fscache_n_attr_changed_calls);
47130 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
47131
47132 if (fscache_object_is_active(object)) {
47133 fscache_stat(&fscache_n_cop_attr_changed);
47134 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47135
47136 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47137
47138 - fscache_stat(&fscache_n_attr_changed);
47139 + fscache_stat_unchecked(&fscache_n_attr_changed);
47140
47141 op = kzalloc(sizeof(*op), GFP_KERNEL);
47142 if (!op) {
47143 - fscache_stat(&fscache_n_attr_changed_nomem);
47144 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
47145 _leave(" = -ENOMEM");
47146 return -ENOMEM;
47147 }
47148 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47149 if (fscache_submit_exclusive_op(object, op) < 0)
47150 goto nobufs;
47151 spin_unlock(&cookie->lock);
47152 - fscache_stat(&fscache_n_attr_changed_ok);
47153 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
47154 fscache_put_operation(op);
47155 _leave(" = 0");
47156 return 0;
47157 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47158 nobufs:
47159 spin_unlock(&cookie->lock);
47160 kfree(op);
47161 - fscache_stat(&fscache_n_attr_changed_nobufs);
47162 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
47163 _leave(" = %d", -ENOBUFS);
47164 return -ENOBUFS;
47165 }
47166 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
47167 /* allocate a retrieval operation and attempt to submit it */
47168 op = kzalloc(sizeof(*op), GFP_NOIO);
47169 if (!op) {
47170 - fscache_stat(&fscache_n_retrievals_nomem);
47171 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47172 return NULL;
47173 }
47174
47175 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
47176 return 0;
47177 }
47178
47179 - fscache_stat(&fscache_n_retrievals_wait);
47180 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
47181
47182 jif = jiffies;
47183 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
47184 fscache_wait_bit_interruptible,
47185 TASK_INTERRUPTIBLE) != 0) {
47186 - fscache_stat(&fscache_n_retrievals_intr);
47187 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47188 _leave(" = -ERESTARTSYS");
47189 return -ERESTARTSYS;
47190 }
47191 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
47192 */
47193 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47194 struct fscache_retrieval *op,
47195 - atomic_t *stat_op_waits,
47196 - atomic_t *stat_object_dead)
47197 + atomic_unchecked_t *stat_op_waits,
47198 + atomic_unchecked_t *stat_object_dead)
47199 {
47200 int ret;
47201
47202 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47203 goto check_if_dead;
47204
47205 _debug(">>> WT");
47206 - fscache_stat(stat_op_waits);
47207 + fscache_stat_unchecked(stat_op_waits);
47208 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
47209 fscache_wait_bit_interruptible,
47210 TASK_INTERRUPTIBLE) < 0) {
47211 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47212
47213 check_if_dead:
47214 if (unlikely(fscache_object_is_dead(object))) {
47215 - fscache_stat(stat_object_dead);
47216 + fscache_stat_unchecked(stat_object_dead);
47217 return -ENOBUFS;
47218 }
47219 return 0;
47220 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47221
47222 _enter("%p,%p,,,", cookie, page);
47223
47224 - fscache_stat(&fscache_n_retrievals);
47225 + fscache_stat_unchecked(&fscache_n_retrievals);
47226
47227 if (hlist_empty(&cookie->backing_objects))
47228 goto nobufs;
47229 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47230 goto nobufs_unlock;
47231 spin_unlock(&cookie->lock);
47232
47233 - fscache_stat(&fscache_n_retrieval_ops);
47234 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
47235
47236 /* pin the netfs read context in case we need to do the actual netfs
47237 * read because we've encountered a cache read failure */
47238 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47239
47240 error:
47241 if (ret == -ENOMEM)
47242 - fscache_stat(&fscache_n_retrievals_nomem);
47243 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47244 else if (ret == -ERESTARTSYS)
47245 - fscache_stat(&fscache_n_retrievals_intr);
47246 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47247 else if (ret == -ENODATA)
47248 - fscache_stat(&fscache_n_retrievals_nodata);
47249 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47250 else if (ret < 0)
47251 - fscache_stat(&fscache_n_retrievals_nobufs);
47252 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47253 else
47254 - fscache_stat(&fscache_n_retrievals_ok);
47255 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47256
47257 fscache_put_retrieval(op);
47258 _leave(" = %d", ret);
47259 @@ -429,7 +429,7 @@ nobufs_unlock:
47260 spin_unlock(&cookie->lock);
47261 kfree(op);
47262 nobufs:
47263 - fscache_stat(&fscache_n_retrievals_nobufs);
47264 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47265 _leave(" = -ENOBUFS");
47266 return -ENOBUFS;
47267 }
47268 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47269
47270 _enter("%p,,%d,,,", cookie, *nr_pages);
47271
47272 - fscache_stat(&fscache_n_retrievals);
47273 + fscache_stat_unchecked(&fscache_n_retrievals);
47274
47275 if (hlist_empty(&cookie->backing_objects))
47276 goto nobufs;
47277 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47278 goto nobufs_unlock;
47279 spin_unlock(&cookie->lock);
47280
47281 - fscache_stat(&fscache_n_retrieval_ops);
47282 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
47283
47284 /* pin the netfs read context in case we need to do the actual netfs
47285 * read because we've encountered a cache read failure */
47286 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47287
47288 error:
47289 if (ret == -ENOMEM)
47290 - fscache_stat(&fscache_n_retrievals_nomem);
47291 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47292 else if (ret == -ERESTARTSYS)
47293 - fscache_stat(&fscache_n_retrievals_intr);
47294 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47295 else if (ret == -ENODATA)
47296 - fscache_stat(&fscache_n_retrievals_nodata);
47297 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47298 else if (ret < 0)
47299 - fscache_stat(&fscache_n_retrievals_nobufs);
47300 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47301 else
47302 - fscache_stat(&fscache_n_retrievals_ok);
47303 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47304
47305 fscache_put_retrieval(op);
47306 _leave(" = %d", ret);
47307 @@ -545,7 +545,7 @@ nobufs_unlock:
47308 spin_unlock(&cookie->lock);
47309 kfree(op);
47310 nobufs:
47311 - fscache_stat(&fscache_n_retrievals_nobufs);
47312 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47313 _leave(" = -ENOBUFS");
47314 return -ENOBUFS;
47315 }
47316 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47317
47318 _enter("%p,%p,,,", cookie, page);
47319
47320 - fscache_stat(&fscache_n_allocs);
47321 + fscache_stat_unchecked(&fscache_n_allocs);
47322
47323 if (hlist_empty(&cookie->backing_objects))
47324 goto nobufs;
47325 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47326 goto nobufs_unlock;
47327 spin_unlock(&cookie->lock);
47328
47329 - fscache_stat(&fscache_n_alloc_ops);
47330 + fscache_stat_unchecked(&fscache_n_alloc_ops);
47331
47332 ret = fscache_wait_for_retrieval_activation(
47333 object, op,
47334 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47335
47336 error:
47337 if (ret == -ERESTARTSYS)
47338 - fscache_stat(&fscache_n_allocs_intr);
47339 + fscache_stat_unchecked(&fscache_n_allocs_intr);
47340 else if (ret < 0)
47341 - fscache_stat(&fscache_n_allocs_nobufs);
47342 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47343 else
47344 - fscache_stat(&fscache_n_allocs_ok);
47345 + fscache_stat_unchecked(&fscache_n_allocs_ok);
47346
47347 fscache_put_retrieval(op);
47348 _leave(" = %d", ret);
47349 @@ -625,7 +625,7 @@ nobufs_unlock:
47350 spin_unlock(&cookie->lock);
47351 kfree(op);
47352 nobufs:
47353 - fscache_stat(&fscache_n_allocs_nobufs);
47354 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47355 _leave(" = -ENOBUFS");
47356 return -ENOBUFS;
47357 }
47358 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47359
47360 spin_lock(&cookie->stores_lock);
47361
47362 - fscache_stat(&fscache_n_store_calls);
47363 + fscache_stat_unchecked(&fscache_n_store_calls);
47364
47365 /* find a page to store */
47366 page = NULL;
47367 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47368 page = results[0];
47369 _debug("gang %d [%lx]", n, page->index);
47370 if (page->index > op->store_limit) {
47371 - fscache_stat(&fscache_n_store_pages_over_limit);
47372 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47373 goto superseded;
47374 }
47375
47376 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47377 spin_unlock(&cookie->stores_lock);
47378 spin_unlock(&object->lock);
47379
47380 - fscache_stat(&fscache_n_store_pages);
47381 + fscache_stat_unchecked(&fscache_n_store_pages);
47382 fscache_stat(&fscache_n_cop_write_page);
47383 ret = object->cache->ops->write_page(op, page);
47384 fscache_stat_d(&fscache_n_cop_write_page);
47385 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47386 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47387 ASSERT(PageFsCache(page));
47388
47389 - fscache_stat(&fscache_n_stores);
47390 + fscache_stat_unchecked(&fscache_n_stores);
47391
47392 op = kzalloc(sizeof(*op), GFP_NOIO);
47393 if (!op)
47394 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47395 spin_unlock(&cookie->stores_lock);
47396 spin_unlock(&object->lock);
47397
47398 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47399 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47400 op->store_limit = object->store_limit;
47401
47402 if (fscache_submit_op(object, &op->op) < 0)
47403 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47404
47405 spin_unlock(&cookie->lock);
47406 radix_tree_preload_end();
47407 - fscache_stat(&fscache_n_store_ops);
47408 - fscache_stat(&fscache_n_stores_ok);
47409 + fscache_stat_unchecked(&fscache_n_store_ops);
47410 + fscache_stat_unchecked(&fscache_n_stores_ok);
47411
47412 /* the work queue now carries its own ref on the object */
47413 fscache_put_operation(&op->op);
47414 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47415 return 0;
47416
47417 already_queued:
47418 - fscache_stat(&fscache_n_stores_again);
47419 + fscache_stat_unchecked(&fscache_n_stores_again);
47420 already_pending:
47421 spin_unlock(&cookie->stores_lock);
47422 spin_unlock(&object->lock);
47423 spin_unlock(&cookie->lock);
47424 radix_tree_preload_end();
47425 kfree(op);
47426 - fscache_stat(&fscache_n_stores_ok);
47427 + fscache_stat_unchecked(&fscache_n_stores_ok);
47428 _leave(" = 0");
47429 return 0;
47430
47431 @@ -851,14 +851,14 @@ nobufs:
47432 spin_unlock(&cookie->lock);
47433 radix_tree_preload_end();
47434 kfree(op);
47435 - fscache_stat(&fscache_n_stores_nobufs);
47436 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47437 _leave(" = -ENOBUFS");
47438 return -ENOBUFS;
47439
47440 nomem_free:
47441 kfree(op);
47442 nomem:
47443 - fscache_stat(&fscache_n_stores_oom);
47444 + fscache_stat_unchecked(&fscache_n_stores_oom);
47445 _leave(" = -ENOMEM");
47446 return -ENOMEM;
47447 }
47448 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
47449 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47450 ASSERTCMP(page, !=, NULL);
47451
47452 - fscache_stat(&fscache_n_uncaches);
47453 + fscache_stat_unchecked(&fscache_n_uncaches);
47454
47455 /* cache withdrawal may beat us to it */
47456 if (!PageFsCache(page))
47457 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47458 unsigned long loop;
47459
47460 #ifdef CONFIG_FSCACHE_STATS
47461 - atomic_add(pagevec->nr, &fscache_n_marks);
47462 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47463 #endif
47464
47465 for (loop = 0; loop < pagevec->nr; loop++) {
47466 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47467 index 4765190..2a067f2 100644
47468 --- a/fs/fscache/stats.c
47469 +++ b/fs/fscache/stats.c
47470 @@ -18,95 +18,95 @@
47471 /*
47472 * operation counters
47473 */
47474 -atomic_t fscache_n_op_pend;
47475 -atomic_t fscache_n_op_run;
47476 -atomic_t fscache_n_op_enqueue;
47477 -atomic_t fscache_n_op_requeue;
47478 -atomic_t fscache_n_op_deferred_release;
47479 -atomic_t fscache_n_op_release;
47480 -atomic_t fscache_n_op_gc;
47481 -atomic_t fscache_n_op_cancelled;
47482 -atomic_t fscache_n_op_rejected;
47483 +atomic_unchecked_t fscache_n_op_pend;
47484 +atomic_unchecked_t fscache_n_op_run;
47485 +atomic_unchecked_t fscache_n_op_enqueue;
47486 +atomic_unchecked_t fscache_n_op_requeue;
47487 +atomic_unchecked_t fscache_n_op_deferred_release;
47488 +atomic_unchecked_t fscache_n_op_release;
47489 +atomic_unchecked_t fscache_n_op_gc;
47490 +atomic_unchecked_t fscache_n_op_cancelled;
47491 +atomic_unchecked_t fscache_n_op_rejected;
47492
47493 -atomic_t fscache_n_attr_changed;
47494 -atomic_t fscache_n_attr_changed_ok;
47495 -atomic_t fscache_n_attr_changed_nobufs;
47496 -atomic_t fscache_n_attr_changed_nomem;
47497 -atomic_t fscache_n_attr_changed_calls;
47498 +atomic_unchecked_t fscache_n_attr_changed;
47499 +atomic_unchecked_t fscache_n_attr_changed_ok;
47500 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47501 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47502 +atomic_unchecked_t fscache_n_attr_changed_calls;
47503
47504 -atomic_t fscache_n_allocs;
47505 -atomic_t fscache_n_allocs_ok;
47506 -atomic_t fscache_n_allocs_wait;
47507 -atomic_t fscache_n_allocs_nobufs;
47508 -atomic_t fscache_n_allocs_intr;
47509 -atomic_t fscache_n_allocs_object_dead;
47510 -atomic_t fscache_n_alloc_ops;
47511 -atomic_t fscache_n_alloc_op_waits;
47512 +atomic_unchecked_t fscache_n_allocs;
47513 +atomic_unchecked_t fscache_n_allocs_ok;
47514 +atomic_unchecked_t fscache_n_allocs_wait;
47515 +atomic_unchecked_t fscache_n_allocs_nobufs;
47516 +atomic_unchecked_t fscache_n_allocs_intr;
47517 +atomic_unchecked_t fscache_n_allocs_object_dead;
47518 +atomic_unchecked_t fscache_n_alloc_ops;
47519 +atomic_unchecked_t fscache_n_alloc_op_waits;
47520
47521 -atomic_t fscache_n_retrievals;
47522 -atomic_t fscache_n_retrievals_ok;
47523 -atomic_t fscache_n_retrievals_wait;
47524 -atomic_t fscache_n_retrievals_nodata;
47525 -atomic_t fscache_n_retrievals_nobufs;
47526 -atomic_t fscache_n_retrievals_intr;
47527 -atomic_t fscache_n_retrievals_nomem;
47528 -atomic_t fscache_n_retrievals_object_dead;
47529 -atomic_t fscache_n_retrieval_ops;
47530 -atomic_t fscache_n_retrieval_op_waits;
47531 +atomic_unchecked_t fscache_n_retrievals;
47532 +atomic_unchecked_t fscache_n_retrievals_ok;
47533 +atomic_unchecked_t fscache_n_retrievals_wait;
47534 +atomic_unchecked_t fscache_n_retrievals_nodata;
47535 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47536 +atomic_unchecked_t fscache_n_retrievals_intr;
47537 +atomic_unchecked_t fscache_n_retrievals_nomem;
47538 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47539 +atomic_unchecked_t fscache_n_retrieval_ops;
47540 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47541
47542 -atomic_t fscache_n_stores;
47543 -atomic_t fscache_n_stores_ok;
47544 -atomic_t fscache_n_stores_again;
47545 -atomic_t fscache_n_stores_nobufs;
47546 -atomic_t fscache_n_stores_oom;
47547 -atomic_t fscache_n_store_ops;
47548 -atomic_t fscache_n_store_calls;
47549 -atomic_t fscache_n_store_pages;
47550 -atomic_t fscache_n_store_radix_deletes;
47551 -atomic_t fscache_n_store_pages_over_limit;
47552 +atomic_unchecked_t fscache_n_stores;
47553 +atomic_unchecked_t fscache_n_stores_ok;
47554 +atomic_unchecked_t fscache_n_stores_again;
47555 +atomic_unchecked_t fscache_n_stores_nobufs;
47556 +atomic_unchecked_t fscache_n_stores_oom;
47557 +atomic_unchecked_t fscache_n_store_ops;
47558 +atomic_unchecked_t fscache_n_store_calls;
47559 +atomic_unchecked_t fscache_n_store_pages;
47560 +atomic_unchecked_t fscache_n_store_radix_deletes;
47561 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47562
47563 -atomic_t fscache_n_store_vmscan_not_storing;
47564 -atomic_t fscache_n_store_vmscan_gone;
47565 -atomic_t fscache_n_store_vmscan_busy;
47566 -atomic_t fscache_n_store_vmscan_cancelled;
47567 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47568 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47569 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47570 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47571
47572 -atomic_t fscache_n_marks;
47573 -atomic_t fscache_n_uncaches;
47574 +atomic_unchecked_t fscache_n_marks;
47575 +atomic_unchecked_t fscache_n_uncaches;
47576
47577 -atomic_t fscache_n_acquires;
47578 -atomic_t fscache_n_acquires_null;
47579 -atomic_t fscache_n_acquires_no_cache;
47580 -atomic_t fscache_n_acquires_ok;
47581 -atomic_t fscache_n_acquires_nobufs;
47582 -atomic_t fscache_n_acquires_oom;
47583 +atomic_unchecked_t fscache_n_acquires;
47584 +atomic_unchecked_t fscache_n_acquires_null;
47585 +atomic_unchecked_t fscache_n_acquires_no_cache;
47586 +atomic_unchecked_t fscache_n_acquires_ok;
47587 +atomic_unchecked_t fscache_n_acquires_nobufs;
47588 +atomic_unchecked_t fscache_n_acquires_oom;
47589
47590 -atomic_t fscache_n_updates;
47591 -atomic_t fscache_n_updates_null;
47592 -atomic_t fscache_n_updates_run;
47593 +atomic_unchecked_t fscache_n_updates;
47594 +atomic_unchecked_t fscache_n_updates_null;
47595 +atomic_unchecked_t fscache_n_updates_run;
47596
47597 -atomic_t fscache_n_relinquishes;
47598 -atomic_t fscache_n_relinquishes_null;
47599 -atomic_t fscache_n_relinquishes_waitcrt;
47600 -atomic_t fscache_n_relinquishes_retire;
47601 +atomic_unchecked_t fscache_n_relinquishes;
47602 +atomic_unchecked_t fscache_n_relinquishes_null;
47603 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47604 +atomic_unchecked_t fscache_n_relinquishes_retire;
47605
47606 -atomic_t fscache_n_cookie_index;
47607 -atomic_t fscache_n_cookie_data;
47608 -atomic_t fscache_n_cookie_special;
47609 +atomic_unchecked_t fscache_n_cookie_index;
47610 +atomic_unchecked_t fscache_n_cookie_data;
47611 +atomic_unchecked_t fscache_n_cookie_special;
47612
47613 -atomic_t fscache_n_object_alloc;
47614 -atomic_t fscache_n_object_no_alloc;
47615 -atomic_t fscache_n_object_lookups;
47616 -atomic_t fscache_n_object_lookups_negative;
47617 -atomic_t fscache_n_object_lookups_positive;
47618 -atomic_t fscache_n_object_lookups_timed_out;
47619 -atomic_t fscache_n_object_created;
47620 -atomic_t fscache_n_object_avail;
47621 -atomic_t fscache_n_object_dead;
47622 +atomic_unchecked_t fscache_n_object_alloc;
47623 +atomic_unchecked_t fscache_n_object_no_alloc;
47624 +atomic_unchecked_t fscache_n_object_lookups;
47625 +atomic_unchecked_t fscache_n_object_lookups_negative;
47626 +atomic_unchecked_t fscache_n_object_lookups_positive;
47627 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47628 +atomic_unchecked_t fscache_n_object_created;
47629 +atomic_unchecked_t fscache_n_object_avail;
47630 +atomic_unchecked_t fscache_n_object_dead;
47631
47632 -atomic_t fscache_n_checkaux_none;
47633 -atomic_t fscache_n_checkaux_okay;
47634 -atomic_t fscache_n_checkaux_update;
47635 -atomic_t fscache_n_checkaux_obsolete;
47636 +atomic_unchecked_t fscache_n_checkaux_none;
47637 +atomic_unchecked_t fscache_n_checkaux_okay;
47638 +atomic_unchecked_t fscache_n_checkaux_update;
47639 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47640
47641 atomic_t fscache_n_cop_alloc_object;
47642 atomic_t fscache_n_cop_lookup_object;
47643 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47644 seq_puts(m, "FS-Cache statistics\n");
47645
47646 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47647 - atomic_read(&fscache_n_cookie_index),
47648 - atomic_read(&fscache_n_cookie_data),
47649 - atomic_read(&fscache_n_cookie_special));
47650 + atomic_read_unchecked(&fscache_n_cookie_index),
47651 + atomic_read_unchecked(&fscache_n_cookie_data),
47652 + atomic_read_unchecked(&fscache_n_cookie_special));
47653
47654 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47655 - atomic_read(&fscache_n_object_alloc),
47656 - atomic_read(&fscache_n_object_no_alloc),
47657 - atomic_read(&fscache_n_object_avail),
47658 - atomic_read(&fscache_n_object_dead));
47659 + atomic_read_unchecked(&fscache_n_object_alloc),
47660 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47661 + atomic_read_unchecked(&fscache_n_object_avail),
47662 + atomic_read_unchecked(&fscache_n_object_dead));
47663 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47664 - atomic_read(&fscache_n_checkaux_none),
47665 - atomic_read(&fscache_n_checkaux_okay),
47666 - atomic_read(&fscache_n_checkaux_update),
47667 - atomic_read(&fscache_n_checkaux_obsolete));
47668 + atomic_read_unchecked(&fscache_n_checkaux_none),
47669 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47670 + atomic_read_unchecked(&fscache_n_checkaux_update),
47671 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47672
47673 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47674 - atomic_read(&fscache_n_marks),
47675 - atomic_read(&fscache_n_uncaches));
47676 + atomic_read_unchecked(&fscache_n_marks),
47677 + atomic_read_unchecked(&fscache_n_uncaches));
47678
47679 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47680 " oom=%u\n",
47681 - atomic_read(&fscache_n_acquires),
47682 - atomic_read(&fscache_n_acquires_null),
47683 - atomic_read(&fscache_n_acquires_no_cache),
47684 - atomic_read(&fscache_n_acquires_ok),
47685 - atomic_read(&fscache_n_acquires_nobufs),
47686 - atomic_read(&fscache_n_acquires_oom));
47687 + atomic_read_unchecked(&fscache_n_acquires),
47688 + atomic_read_unchecked(&fscache_n_acquires_null),
47689 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47690 + atomic_read_unchecked(&fscache_n_acquires_ok),
47691 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47692 + atomic_read_unchecked(&fscache_n_acquires_oom));
47693
47694 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47695 - atomic_read(&fscache_n_object_lookups),
47696 - atomic_read(&fscache_n_object_lookups_negative),
47697 - atomic_read(&fscache_n_object_lookups_positive),
47698 - atomic_read(&fscache_n_object_created),
47699 - atomic_read(&fscache_n_object_lookups_timed_out));
47700 + atomic_read_unchecked(&fscache_n_object_lookups),
47701 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47702 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47703 + atomic_read_unchecked(&fscache_n_object_created),
47704 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47705
47706 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47707 - atomic_read(&fscache_n_updates),
47708 - atomic_read(&fscache_n_updates_null),
47709 - atomic_read(&fscache_n_updates_run));
47710 + atomic_read_unchecked(&fscache_n_updates),
47711 + atomic_read_unchecked(&fscache_n_updates_null),
47712 + atomic_read_unchecked(&fscache_n_updates_run));
47713
47714 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47715 - atomic_read(&fscache_n_relinquishes),
47716 - atomic_read(&fscache_n_relinquishes_null),
47717 - atomic_read(&fscache_n_relinquishes_waitcrt),
47718 - atomic_read(&fscache_n_relinquishes_retire));
47719 + atomic_read_unchecked(&fscache_n_relinquishes),
47720 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47721 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47722 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47723
47724 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47725 - atomic_read(&fscache_n_attr_changed),
47726 - atomic_read(&fscache_n_attr_changed_ok),
47727 - atomic_read(&fscache_n_attr_changed_nobufs),
47728 - atomic_read(&fscache_n_attr_changed_nomem),
47729 - atomic_read(&fscache_n_attr_changed_calls));
47730 + atomic_read_unchecked(&fscache_n_attr_changed),
47731 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47732 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47733 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47734 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47735
47736 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47737 - atomic_read(&fscache_n_allocs),
47738 - atomic_read(&fscache_n_allocs_ok),
47739 - atomic_read(&fscache_n_allocs_wait),
47740 - atomic_read(&fscache_n_allocs_nobufs),
47741 - atomic_read(&fscache_n_allocs_intr));
47742 + atomic_read_unchecked(&fscache_n_allocs),
47743 + atomic_read_unchecked(&fscache_n_allocs_ok),
47744 + atomic_read_unchecked(&fscache_n_allocs_wait),
47745 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47746 + atomic_read_unchecked(&fscache_n_allocs_intr));
47747 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47748 - atomic_read(&fscache_n_alloc_ops),
47749 - atomic_read(&fscache_n_alloc_op_waits),
47750 - atomic_read(&fscache_n_allocs_object_dead));
47751 + atomic_read_unchecked(&fscache_n_alloc_ops),
47752 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47753 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47754
47755 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47756 " int=%u oom=%u\n",
47757 - atomic_read(&fscache_n_retrievals),
47758 - atomic_read(&fscache_n_retrievals_ok),
47759 - atomic_read(&fscache_n_retrievals_wait),
47760 - atomic_read(&fscache_n_retrievals_nodata),
47761 - atomic_read(&fscache_n_retrievals_nobufs),
47762 - atomic_read(&fscache_n_retrievals_intr),
47763 - atomic_read(&fscache_n_retrievals_nomem));
47764 + atomic_read_unchecked(&fscache_n_retrievals),
47765 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47766 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47767 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47768 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47769 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47770 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47771 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47772 - atomic_read(&fscache_n_retrieval_ops),
47773 - atomic_read(&fscache_n_retrieval_op_waits),
47774 - atomic_read(&fscache_n_retrievals_object_dead));
47775 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47776 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47777 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47778
47779 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47780 - atomic_read(&fscache_n_stores),
47781 - atomic_read(&fscache_n_stores_ok),
47782 - atomic_read(&fscache_n_stores_again),
47783 - atomic_read(&fscache_n_stores_nobufs),
47784 - atomic_read(&fscache_n_stores_oom));
47785 + atomic_read_unchecked(&fscache_n_stores),
47786 + atomic_read_unchecked(&fscache_n_stores_ok),
47787 + atomic_read_unchecked(&fscache_n_stores_again),
47788 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47789 + atomic_read_unchecked(&fscache_n_stores_oom));
47790 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47791 - atomic_read(&fscache_n_store_ops),
47792 - atomic_read(&fscache_n_store_calls),
47793 - atomic_read(&fscache_n_store_pages),
47794 - atomic_read(&fscache_n_store_radix_deletes),
47795 - atomic_read(&fscache_n_store_pages_over_limit));
47796 + atomic_read_unchecked(&fscache_n_store_ops),
47797 + atomic_read_unchecked(&fscache_n_store_calls),
47798 + atomic_read_unchecked(&fscache_n_store_pages),
47799 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47800 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47801
47802 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47803 - atomic_read(&fscache_n_store_vmscan_not_storing),
47804 - atomic_read(&fscache_n_store_vmscan_gone),
47805 - atomic_read(&fscache_n_store_vmscan_busy),
47806 - atomic_read(&fscache_n_store_vmscan_cancelled));
47807 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47808 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47809 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47810 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47811
47812 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47813 - atomic_read(&fscache_n_op_pend),
47814 - atomic_read(&fscache_n_op_run),
47815 - atomic_read(&fscache_n_op_enqueue),
47816 - atomic_read(&fscache_n_op_cancelled),
47817 - atomic_read(&fscache_n_op_rejected));
47818 + atomic_read_unchecked(&fscache_n_op_pend),
47819 + atomic_read_unchecked(&fscache_n_op_run),
47820 + atomic_read_unchecked(&fscache_n_op_enqueue),
47821 + atomic_read_unchecked(&fscache_n_op_cancelled),
47822 + atomic_read_unchecked(&fscache_n_op_rejected));
47823 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47824 - atomic_read(&fscache_n_op_deferred_release),
47825 - atomic_read(&fscache_n_op_release),
47826 - atomic_read(&fscache_n_op_gc));
47827 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47828 + atomic_read_unchecked(&fscache_n_op_release),
47829 + atomic_read_unchecked(&fscache_n_op_gc));
47830
47831 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47832 atomic_read(&fscache_n_cop_alloc_object),
47833 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47834 index ee8d550..7189d8c 100644
47835 --- a/fs/fuse/cuse.c
47836 +++ b/fs/fuse/cuse.c
47837 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47838 INIT_LIST_HEAD(&cuse_conntbl[i]);
47839
47840 /* inherit and extend fuse_dev_operations */
47841 - cuse_channel_fops = fuse_dev_operations;
47842 - cuse_channel_fops.owner = THIS_MODULE;
47843 - cuse_channel_fops.open = cuse_channel_open;
47844 - cuse_channel_fops.release = cuse_channel_release;
47845 + pax_open_kernel();
47846 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47847 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47848 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47849 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47850 + pax_close_kernel();
47851
47852 cuse_class = class_create(THIS_MODULE, "cuse");
47853 if (IS_ERR(cuse_class))
47854 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47855 index f4246cf..b4aed1d 100644
47856 --- a/fs/fuse/dev.c
47857 +++ b/fs/fuse/dev.c
47858 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47859 ret = 0;
47860 pipe_lock(pipe);
47861
47862 - if (!pipe->readers) {
47863 + if (!atomic_read(&pipe->readers)) {
47864 send_sig(SIGPIPE, current, 0);
47865 if (!ret)
47866 ret = -EPIPE;
47867 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47868 index 324bc08..4fdd56e 100644
47869 --- a/fs/fuse/dir.c
47870 +++ b/fs/fuse/dir.c
47871 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47872 return link;
47873 }
47874
47875 -static void free_link(char *link)
47876 +static void free_link(const char *link)
47877 {
47878 if (!IS_ERR(link))
47879 free_page((unsigned long) link);
47880 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47881 index 753af3d..f7b021a 100644
47882 --- a/fs/gfs2/inode.c
47883 +++ b/fs/gfs2/inode.c
47884 @@ -1498,7 +1498,7 @@ out:
47885
47886 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47887 {
47888 - char *s = nd_get_link(nd);
47889 + const char *s = nd_get_link(nd);
47890 if (!IS_ERR(s))
47891 kfree(s);
47892 }
47893 diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
47894 index a3bde91..2524579 100644
47895 --- a/fs/gfs2/quota.c
47896 +++ b/fs/gfs2/quota.c
47897 @@ -497,8 +497,11 @@ int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
47898 struct gfs2_quota_data **qd;
47899 int error;
47900
47901 - if (ip->i_res == NULL)
47902 - gfs2_rs_alloc(ip);
47903 + if (ip->i_res == NULL) {
47904 + error = gfs2_rs_alloc(ip);
47905 + if (error)
47906 + return error;
47907 + }
47908
47909 qd = ip->i_res->rs_qa_qd;
47910
47911 diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
47912 index c9ed814..4a45d5f 100644
47913 --- a/fs/gfs2/rgrp.c
47914 +++ b/fs/gfs2/rgrp.c
47915 @@ -477,7 +477,6 @@ void gfs2_free_clones(struct gfs2_rgrpd *rgd)
47916 */
47917 int gfs2_rs_alloc(struct gfs2_inode *ip)
47918 {
47919 - int error = 0;
47920 struct gfs2_blkreserv *res;
47921
47922 if (ip->i_res)
47923 @@ -485,7 +484,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47924
47925 res = kmem_cache_zalloc(gfs2_rsrv_cachep, GFP_NOFS);
47926 if (!res)
47927 - error = -ENOMEM;
47928 + return -ENOMEM;
47929
47930 down_write(&ip->i_rw_mutex);
47931 if (ip->i_res)
47932 @@ -493,7 +492,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47933 else
47934 ip->i_res = res;
47935 up_write(&ip->i_rw_mutex);
47936 - return error;
47937 + return 0;
47938 }
47939
47940 static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs)
47941 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47942 index 8349a89..51a0254 100644
47943 --- a/fs/hugetlbfs/inode.c
47944 +++ b/fs/hugetlbfs/inode.c
47945 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47946 .kill_sb = kill_litter_super,
47947 };
47948
47949 -static struct vfsmount *hugetlbfs_vfsmount;
47950 +struct vfsmount *hugetlbfs_vfsmount;
47951
47952 static int can_do_hugetlb_shm(void)
47953 {
47954 diff --git a/fs/inode.c b/fs/inode.c
47955 index 7c14897..d40169e 100644
47956 --- a/fs/inode.c
47957 +++ b/fs/inode.c
47958 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
47959
47960 #ifdef CONFIG_SMP
47961 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47962 - static atomic_t shared_last_ino;
47963 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47964 + static atomic_unchecked_t shared_last_ino;
47965 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47966
47967 res = next - LAST_INO_BATCH;
47968 }
47969 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47970 index 4a6cf28..d3a29d3 100644
47971 --- a/fs/jffs2/erase.c
47972 +++ b/fs/jffs2/erase.c
47973 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47974 struct jffs2_unknown_node marker = {
47975 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47976 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47977 - .totlen = cpu_to_je32(c->cleanmarker_size)
47978 + .totlen = cpu_to_je32(c->cleanmarker_size),
47979 + .hdr_crc = cpu_to_je32(0)
47980 };
47981
47982 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47983 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47984 index a6597d6..41b30ec 100644
47985 --- a/fs/jffs2/wbuf.c
47986 +++ b/fs/jffs2/wbuf.c
47987 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47988 {
47989 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47990 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47991 - .totlen = constant_cpu_to_je32(8)
47992 + .totlen = constant_cpu_to_je32(8),
47993 + .hdr_crc = constant_cpu_to_je32(0)
47994 };
47995
47996 /*
47997 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47998 index c55c745..f67ee56 100644
47999 --- a/fs/jfs/super.c
48000 +++ b/fs/jfs/super.c
48001 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
48002
48003 jfs_inode_cachep =
48004 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
48005 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
48006 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
48007 init_once);
48008 if (jfs_inode_cachep == NULL)
48009 return -ENOMEM;
48010 diff --git a/fs/libfs.c b/fs/libfs.c
48011 index a74cb17..37fcbe4 100644
48012 --- a/fs/libfs.c
48013 +++ b/fs/libfs.c
48014 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
48015
48016 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
48017 struct dentry *next;
48018 + char d_name[sizeof(next->d_iname)];
48019 + const unsigned char *name;
48020 +
48021 next = list_entry(p, struct dentry, d_u.d_child);
48022 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
48023 if (!simple_positive(next)) {
48024 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
48025
48026 spin_unlock(&next->d_lock);
48027 spin_unlock(&dentry->d_lock);
48028 - if (filldir(dirent, next->d_name.name,
48029 + name = next->d_name.name;
48030 + if (name == next->d_iname) {
48031 + memcpy(d_name, name, next->d_name.len);
48032 + name = d_name;
48033 + }
48034 + if (filldir(dirent, name,
48035 next->d_name.len, filp->f_pos,
48036 next->d_inode->i_ino,
48037 dt_type(next->d_inode)) < 0)
48038 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
48039 index 05d2912..760abfa 100644
48040 --- a/fs/lockd/clntproc.c
48041 +++ b/fs/lockd/clntproc.c
48042 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
48043 /*
48044 * Cookie counter for NLM requests
48045 */
48046 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
48047 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
48048
48049 void nlmclnt_next_cookie(struct nlm_cookie *c)
48050 {
48051 - u32 cookie = atomic_inc_return(&nlm_cookie);
48052 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
48053
48054 memcpy(c->data, &cookie, 4);
48055 c->len=4;
48056 diff --git a/fs/locks.c b/fs/locks.c
48057 index 7e81bfc..c3649aa 100644
48058 --- a/fs/locks.c
48059 +++ b/fs/locks.c
48060 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
48061 return;
48062
48063 if (filp->f_op && filp->f_op->flock) {
48064 - struct file_lock fl = {
48065 + struct file_lock flock = {
48066 .fl_pid = current->tgid,
48067 .fl_file = filp,
48068 .fl_flags = FL_FLOCK,
48069 .fl_type = F_UNLCK,
48070 .fl_end = OFFSET_MAX,
48071 };
48072 - filp->f_op->flock(filp, F_SETLKW, &fl);
48073 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
48074 - fl.fl_ops->fl_release_private(&fl);
48075 + filp->f_op->flock(filp, F_SETLKW, &flock);
48076 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
48077 + flock.fl_ops->fl_release_private(&flock);
48078 }
48079
48080 lock_flocks();
48081 diff --git a/fs/namei.c b/fs/namei.c
48082 index 091c4b7..eb220a4 100644
48083 --- a/fs/namei.c
48084 +++ b/fs/namei.c
48085 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
48086 if (ret != -EACCES)
48087 return ret;
48088
48089 +#ifdef CONFIG_GRKERNSEC
48090 + /* we'll block if we have to log due to a denied capability use */
48091 + if (mask & MAY_NOT_BLOCK)
48092 + return -ECHILD;
48093 +#endif
48094 +
48095 if (S_ISDIR(inode->i_mode)) {
48096 /* DACs are overridable for directories */
48097 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
48098 - return 0;
48099 if (!(mask & MAY_WRITE))
48100 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
48101 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
48102 + inode_capable(inode, CAP_DAC_READ_SEARCH))
48103 return 0;
48104 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
48105 + return 0;
48106 return -EACCES;
48107 }
48108 /*
48109 + * Searching includes executable on directories, else just read.
48110 + */
48111 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48112 + if (mask == MAY_READ)
48113 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
48114 + inode_capable(inode, CAP_DAC_READ_SEARCH))
48115 + return 0;
48116 +
48117 + /*
48118 * Read/write DACs are always overridable.
48119 * Executable DACs are overridable when there is
48120 * at least one exec bit set.
48121 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
48122 if (inode_capable(inode, CAP_DAC_OVERRIDE))
48123 return 0;
48124
48125 - /*
48126 - * Searching includes executable on directories, else just read.
48127 - */
48128 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48129 - if (mask == MAY_READ)
48130 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
48131 - return 0;
48132 -
48133 return -EACCES;
48134 }
48135
48136 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
48137 {
48138 struct dentry *dentry = link->dentry;
48139 int error;
48140 - char *s;
48141 + const char *s;
48142
48143 BUG_ON(nd->flags & LOOKUP_RCU);
48144
48145 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
48146 if (error)
48147 goto out_put_nd_path;
48148
48149 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
48150 + dentry->d_inode, dentry, nd->path.mnt)) {
48151 + error = -EACCES;
48152 + goto out_put_nd_path;
48153 + }
48154 +
48155 nd->last_type = LAST_BIND;
48156 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
48157 error = PTR_ERR(*p);
48158 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
48159 break;
48160 res = walk_component(nd, path, &nd->last,
48161 nd->last_type, LOOKUP_FOLLOW);
48162 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
48163 + res = -EACCES;
48164 put_link(nd, &link, cookie);
48165 } while (res > 0);
48166
48167 @@ -1648,7 +1664,7 @@ EXPORT_SYMBOL(full_name_hash);
48168 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
48169 {
48170 unsigned long a, b, adata, bdata, mask, hash, len;
48171 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
48172 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
48173
48174 hash = a = 0;
48175 len = -sizeof(unsigned long);
48176 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
48177 if (err)
48178 break;
48179 err = lookup_last(nd, &path);
48180 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
48181 + err = -EACCES;
48182 put_link(nd, &link, cookie);
48183 }
48184 }
48185 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
48186 if (!err)
48187 err = complete_walk(nd);
48188
48189 + if (!(nd->flags & LOOKUP_PARENT)) {
48190 +#ifdef CONFIG_GRKERNSEC
48191 + if (flags & LOOKUP_RCU) {
48192 + if (!err)
48193 + path_put(&nd->path);
48194 + err = -ECHILD;
48195 + } else
48196 +#endif
48197 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48198 + if (!err)
48199 + path_put(&nd->path);
48200 + err = -ENOENT;
48201 + }
48202 + }
48203 +
48204 if (!err && nd->flags & LOOKUP_DIRECTORY) {
48205 if (!nd->inode->i_op->lookup) {
48206 path_put(&nd->path);
48207 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
48208 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
48209
48210 if (likely(!retval)) {
48211 + if (*name != '/' && nd->path.dentry && nd->inode) {
48212 +#ifdef CONFIG_GRKERNSEC
48213 + if (flags & LOOKUP_RCU)
48214 + return -ECHILD;
48215 +#endif
48216 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
48217 + return -ENOENT;
48218 + }
48219 +
48220 if (unlikely(!audit_dummy_context())) {
48221 if (nd->path.dentry && nd->inode)
48222 audit_inode(name, nd->path.dentry);
48223 @@ -2076,6 +2118,11 @@ struct dentry *lookup_one_len(const char *name, struct dentry *base, int len)
48224 if (!len)
48225 return ERR_PTR(-EACCES);
48226
48227 + if (unlikely(name[0] == '.')) {
48228 + if (len < 2 || (len == 2 && name[1] == '.'))
48229 + return ERR_PTR(-EACCES);
48230 + }
48231 +
48232 while (len--) {
48233 c = *(const unsigned char *)name++;
48234 if (c == '/' || c == '\0')
48235 @@ -2336,6 +2383,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
48236 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
48237 return -EPERM;
48238
48239 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
48240 + return -EPERM;
48241 + if (gr_handle_rawio(inode))
48242 + return -EPERM;
48243 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
48244 + return -EACCES;
48245 +
48246 return 0;
48247 }
48248
48249 @@ -2557,7 +2611,7 @@ looked_up:
48250 * cleared otherwise prior to returning.
48251 */
48252 static int lookup_open(struct nameidata *nd, struct path *path,
48253 - struct file *file,
48254 + struct path *link, struct file *file,
48255 const struct open_flags *op,
48256 bool got_write, int *opened)
48257 {
48258 @@ -2592,6 +2646,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
48259 /* Negative dentry, just create the file */
48260 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
48261 umode_t mode = op->mode;
48262 +
48263 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
48264 + error = -EACCES;
48265 + goto out_dput;
48266 + }
48267 +
48268 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
48269 + error = -EACCES;
48270 + goto out_dput;
48271 + }
48272 +
48273 if (!IS_POSIXACL(dir->d_inode))
48274 mode &= ~current_umask();
48275 /*
48276 @@ -2613,6 +2678,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
48277 nd->flags & LOOKUP_EXCL);
48278 if (error)
48279 goto out_dput;
48280 + else
48281 + gr_handle_create(dentry, nd->path.mnt);
48282 }
48283 out_no_open:
48284 path->dentry = dentry;
48285 @@ -2627,7 +2694,7 @@ out_dput:
48286 /*
48287 * Handle the last step of open()
48288 */
48289 -static int do_last(struct nameidata *nd, struct path *path,
48290 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
48291 struct file *file, const struct open_flags *op,
48292 int *opened, const char *pathname)
48293 {
48294 @@ -2656,16 +2723,44 @@ static int do_last(struct nameidata *nd, struct path *path,
48295 error = complete_walk(nd);
48296 if (error)
48297 return error;
48298 +#ifdef CONFIG_GRKERNSEC
48299 + if (nd->flags & LOOKUP_RCU) {
48300 + error = -ECHILD;
48301 + goto out;
48302 + }
48303 +#endif
48304 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48305 + error = -ENOENT;
48306 + goto out;
48307 + }
48308 audit_inode(pathname, nd->path.dentry);
48309 if (open_flag & O_CREAT) {
48310 error = -EISDIR;
48311 goto out;
48312 }
48313 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48314 + error = -EACCES;
48315 + goto out;
48316 + }
48317 goto finish_open;
48318 case LAST_BIND:
48319 error = complete_walk(nd);
48320 if (error)
48321 return error;
48322 +#ifdef CONFIG_GRKERNSEC
48323 + if (nd->flags & LOOKUP_RCU) {
48324 + error = -ECHILD;
48325 + goto out;
48326 + }
48327 +#endif
48328 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
48329 + error = -ENOENT;
48330 + goto out;
48331 + }
48332 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48333 + error = -EACCES;
48334 + goto out;
48335 + }
48336 audit_inode(pathname, dir);
48337 goto finish_open;
48338 }
48339 @@ -2714,7 +2809,7 @@ retry_lookup:
48340 */
48341 }
48342 mutex_lock(&dir->d_inode->i_mutex);
48343 - error = lookup_open(nd, path, file, op, got_write, opened);
48344 + error = lookup_open(nd, path, link, file, op, got_write, opened);
48345 mutex_unlock(&dir->d_inode->i_mutex);
48346
48347 if (error <= 0) {
48348 @@ -2738,11 +2833,28 @@ retry_lookup:
48349 goto finish_open_created;
48350 }
48351
48352 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
48353 + error = -ENOENT;
48354 + goto exit_dput;
48355 + }
48356 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
48357 + error = -EACCES;
48358 + goto exit_dput;
48359 + }
48360 +
48361 /*
48362 * create/update audit record if it already exists.
48363 */
48364 - if (path->dentry->d_inode)
48365 + if (path->dentry->d_inode) {
48366 + /* only check if O_CREAT is specified, all other checks need to go
48367 + into may_open */
48368 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
48369 + error = -EACCES;
48370 + goto exit_dput;
48371 + }
48372 +
48373 audit_inode(pathname, path->dentry);
48374 + }
48375
48376 /*
48377 * If atomic_open() acquired write access it is dropped now due to
48378 @@ -2783,6 +2895,11 @@ finish_lookup:
48379 }
48380 }
48381 BUG_ON(inode != path->dentry->d_inode);
48382 + /* if we're resolving a symlink to another symlink */
48383 + if (link && gr_handle_symlink_owner(link, inode)) {
48384 + error = -EACCES;
48385 + goto out;
48386 + }
48387 return 1;
48388 }
48389
48390 @@ -2792,7 +2909,6 @@ finish_lookup:
48391 save_parent.dentry = nd->path.dentry;
48392 save_parent.mnt = mntget(path->mnt);
48393 nd->path.dentry = path->dentry;
48394 -
48395 }
48396 nd->inode = inode;
48397 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
48398 @@ -2801,6 +2917,22 @@ finish_lookup:
48399 path_put(&save_parent);
48400 return error;
48401 }
48402 +
48403 +#ifdef CONFIG_GRKERNSEC
48404 + if (nd->flags & LOOKUP_RCU) {
48405 + error = -ECHILD;
48406 + goto out;
48407 + }
48408 +#endif
48409 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48410 + error = -ENOENT;
48411 + goto out;
48412 + }
48413 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48414 + error = -EACCES;
48415 + goto out;
48416 + }
48417 +
48418 error = -EISDIR;
48419 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
48420 goto out;
48421 @@ -2899,7 +3031,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48422 if (unlikely(error))
48423 goto out;
48424
48425 - error = do_last(nd, &path, file, op, &opened, pathname);
48426 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
48427 while (unlikely(error > 0)) { /* trailing symlink */
48428 struct path link = path;
48429 void *cookie;
48430 @@ -2917,7 +3049,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48431 error = follow_link(&link, nd, &cookie);
48432 if (unlikely(error))
48433 break;
48434 - error = do_last(nd, &path, file, op, &opened, pathname);
48435 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
48436 put_link(nd, &link, cookie);
48437 }
48438 out:
48439 @@ -3006,8 +3138,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
48440 goto unlock;
48441
48442 error = -EEXIST;
48443 - if (dentry->d_inode)
48444 + if (dentry->d_inode) {
48445 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
48446 + error = -ENOENT;
48447 + }
48448 goto fail;
48449 + }
48450 /*
48451 * Special case - lookup gave negative, but... we had foo/bar/
48452 * From the vfs_mknod() POV we just have a negative dentry -
48453 @@ -3058,6 +3194,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
48454 }
48455 EXPORT_SYMBOL(user_path_create);
48456
48457 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
48458 +{
48459 + char *tmp = getname(pathname);
48460 + struct dentry *res;
48461 + if (IS_ERR(tmp))
48462 + return ERR_CAST(tmp);
48463 + res = kern_path_create(dfd, tmp, path, is_dir);
48464 + if (IS_ERR(res))
48465 + putname(tmp);
48466 + else
48467 + *to = tmp;
48468 + return res;
48469 +}
48470 +
48471 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
48472 {
48473 int error = may_create(dir, dentry);
48474 @@ -3119,6 +3269,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48475
48476 if (!IS_POSIXACL(path.dentry->d_inode))
48477 mode &= ~current_umask();
48478 +
48479 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
48480 + error = -EPERM;
48481 + goto out;
48482 + }
48483 +
48484 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
48485 + error = -EACCES;
48486 + goto out;
48487 + }
48488 +
48489 error = security_path_mknod(&path, dentry, mode, dev);
48490 if (error)
48491 goto out;
48492 @@ -3135,6 +3296,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48493 break;
48494 }
48495 out:
48496 + if (!error)
48497 + gr_handle_create(dentry, path.mnt);
48498 done_path_create(&path, dentry);
48499 return error;
48500 }
48501 @@ -3181,9 +3344,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
48502
48503 if (!IS_POSIXACL(path.dentry->d_inode))
48504 mode &= ~current_umask();
48505 +
48506 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
48507 + error = -EACCES;
48508 + goto out;
48509 + }
48510 +
48511 error = security_path_mkdir(&path, dentry, mode);
48512 if (!error)
48513 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48514 + if (!error)
48515 + gr_handle_create(dentry, path.mnt);
48516 +out:
48517 done_path_create(&path, dentry);
48518 return error;
48519 }
48520 @@ -3260,6 +3432,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48521 char * name;
48522 struct dentry *dentry;
48523 struct nameidata nd;
48524 + ino_t saved_ino = 0;
48525 + dev_t saved_dev = 0;
48526
48527 error = user_path_parent(dfd, pathname, &nd, &name);
48528 if (error)
48529 @@ -3291,10 +3465,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
48530 error = -ENOENT;
48531 goto exit3;
48532 }
48533 +
48534 + saved_ino = dentry->d_inode->i_ino;
48535 + saved_dev = gr_get_dev_from_dentry(dentry);
48536 +
48537 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48538 + error = -EACCES;
48539 + goto exit3;
48540 + }
48541 +
48542 error = security_path_rmdir(&nd.path, dentry);
48543 if (error)
48544 goto exit3;
48545 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48546 + if (!error && (saved_dev || saved_ino))
48547 + gr_handle_delete(saved_ino, saved_dev);
48548 exit3:
48549 dput(dentry);
48550 exit2:
48551 @@ -3356,6 +3541,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48552 struct dentry *dentry;
48553 struct nameidata nd;
48554 struct inode *inode = NULL;
48555 + ino_t saved_ino = 0;
48556 + dev_t saved_dev = 0;
48557
48558 error = user_path_parent(dfd, pathname, &nd, &name);
48559 if (error)
48560 @@ -3381,10 +3568,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48561 if (!inode)
48562 goto slashes;
48563 ihold(inode);
48564 +
48565 + if (inode->i_nlink <= 1) {
48566 + saved_ino = inode->i_ino;
48567 + saved_dev = gr_get_dev_from_dentry(dentry);
48568 + }
48569 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48570 + error = -EACCES;
48571 + goto exit2;
48572 + }
48573 +
48574 error = security_path_unlink(&nd.path, dentry);
48575 if (error)
48576 goto exit2;
48577 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48578 + if (!error && (saved_ino || saved_dev))
48579 + gr_handle_delete(saved_ino, saved_dev);
48580 exit2:
48581 dput(dentry);
48582 }
48583 @@ -3456,9 +3655,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48584 if (IS_ERR(dentry))
48585 goto out_putname;
48586
48587 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48588 + error = -EACCES;
48589 + goto out;
48590 + }
48591 +
48592 error = security_path_symlink(&path, dentry, from);
48593 if (!error)
48594 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48595 + if (!error)
48596 + gr_handle_create(dentry, path.mnt);
48597 +out:
48598 done_path_create(&path, dentry);
48599 out_putname:
48600 putname(from);
48601 @@ -3528,6 +3735,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48602 {
48603 struct dentry *new_dentry;
48604 struct path old_path, new_path;
48605 + char *to = NULL;
48606 int how = 0;
48607 int error;
48608
48609 @@ -3551,7 +3759,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48610 if (error)
48611 return error;
48612
48613 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48614 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48615 error = PTR_ERR(new_dentry);
48616 if (IS_ERR(new_dentry))
48617 goto out;
48618 @@ -3562,11 +3770,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48619 error = may_linkat(&old_path);
48620 if (unlikely(error))
48621 goto out_dput;
48622 +
48623 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48624 + old_path.dentry->d_inode,
48625 + old_path.dentry->d_inode->i_mode, to)) {
48626 + error = -EACCES;
48627 + goto out_dput;
48628 + }
48629 +
48630 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48631 + old_path.dentry, old_path.mnt, to)) {
48632 + error = -EACCES;
48633 + goto out_dput;
48634 + }
48635 +
48636 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48637 if (error)
48638 goto out_dput;
48639 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48640 + if (!error)
48641 + gr_handle_create(new_dentry, new_path.mnt);
48642 out_dput:
48643 + putname(to);
48644 done_path_create(&new_path, new_dentry);
48645 out:
48646 path_put(&old_path);
48647 @@ -3802,12 +4027,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48648 if (new_dentry == trap)
48649 goto exit5;
48650
48651 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48652 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48653 + to);
48654 + if (error)
48655 + goto exit5;
48656 +
48657 error = security_path_rename(&oldnd.path, old_dentry,
48658 &newnd.path, new_dentry);
48659 if (error)
48660 goto exit5;
48661 error = vfs_rename(old_dir->d_inode, old_dentry,
48662 new_dir->d_inode, new_dentry);
48663 + if (!error)
48664 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48665 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48666 exit5:
48667 dput(new_dentry);
48668 exit4:
48669 @@ -3832,6 +4066,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48670
48671 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48672 {
48673 + char tmpbuf[64];
48674 + const char *newlink;
48675 int len;
48676
48677 len = PTR_ERR(link);
48678 @@ -3841,7 +4077,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48679 len = strlen(link);
48680 if (len > (unsigned) buflen)
48681 len = buflen;
48682 - if (copy_to_user(buffer, link, len))
48683 +
48684 + if (len < sizeof(tmpbuf)) {
48685 + memcpy(tmpbuf, link, len);
48686 + newlink = tmpbuf;
48687 + } else
48688 + newlink = link;
48689 +
48690 + if (copy_to_user(buffer, newlink, len))
48691 len = -EFAULT;
48692 out:
48693 return len;
48694 diff --git a/fs/namespace.c b/fs/namespace.c
48695 index 7bdf790..eb79c4b 100644
48696 --- a/fs/namespace.c
48697 +++ b/fs/namespace.c
48698 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48699 if (!(sb->s_flags & MS_RDONLY))
48700 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48701 up_write(&sb->s_umount);
48702 +
48703 + gr_log_remount(mnt->mnt_devname, retval);
48704 +
48705 return retval;
48706 }
48707
48708 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48709 br_write_unlock(&vfsmount_lock);
48710 up_write(&namespace_sem);
48711 release_mounts(&umount_list);
48712 +
48713 + gr_log_unmount(mnt->mnt_devname, retval);
48714 +
48715 return retval;
48716 }
48717
48718 @@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48719 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48720 MS_STRICTATIME);
48721
48722 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48723 + retval = -EPERM;
48724 + goto dput_out;
48725 + }
48726 +
48727 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48728 + retval = -EPERM;
48729 + goto dput_out;
48730 + }
48731 +
48732 if (flags & MS_REMOUNT)
48733 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48734 data_page);
48735 @@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48736 dev_name, data_page);
48737 dput_out:
48738 path_put(&path);
48739 +
48740 + gr_log_mount(dev_name, dir_name, retval);
48741 +
48742 return retval;
48743 }
48744
48745 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48746 if (error)
48747 goto out2;
48748
48749 + if (gr_handle_chroot_pivot()) {
48750 + error = -EPERM;
48751 + goto out2;
48752 + }
48753 +
48754 get_fs_root(current->fs, &root);
48755 error = lock_mount(&old);
48756 if (error)
48757 diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
48758 index 627f108..afc1fc5b 100644
48759 --- a/fs/nfs/dir.c
48760 +++ b/fs/nfs/dir.c
48761 @@ -450,7 +450,8 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
48762 nfs_refresh_inode(dentry->d_inode, entry->fattr);
48763 goto out;
48764 } else {
48765 - d_drop(dentry);
48766 + if (d_invalidate(dentry) != 0)
48767 + goto out;
48768 dput(dentry);
48769 }
48770 }
48771 @@ -1100,6 +1101,8 @@ out_set_verifier:
48772 out_zap_parent:
48773 nfs_zap_caches(dir);
48774 out_bad:
48775 + nfs_free_fattr(fattr);
48776 + nfs_free_fhandle(fhandle);
48777 nfs_mark_for_revalidate(dir);
48778 if (inode && S_ISDIR(inode->i_mode)) {
48779 /* Purge readdir caches. */
48780 @@ -1112,8 +1115,6 @@ out_zap_parent:
48781 shrink_dcache_parent(dentry);
48782 }
48783 d_drop(dentry);
48784 - nfs_free_fattr(fattr);
48785 - nfs_free_fhandle(fhandle);
48786 dput(parent);
48787 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n",
48788 __func__, dentry->d_parent->d_name.name,
48789 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48790 index 9b47610..066975e 100644
48791 --- a/fs/nfs/inode.c
48792 +++ b/fs/nfs/inode.c
48793 @@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48794 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48795 }
48796
48797 -static atomic_long_t nfs_attr_generation_counter;
48798 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48799
48800 static unsigned long nfs_read_attr_generation_counter(void)
48801 {
48802 - return atomic_long_read(&nfs_attr_generation_counter);
48803 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48804 }
48805
48806 unsigned long nfs_inc_attr_generation_counter(void)
48807 {
48808 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48809 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48810 }
48811
48812 void nfs_fattr_init(struct nfs_fattr *fattr)
48813 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48814 index a9269f1..5490437 100644
48815 --- a/fs/nfsd/vfs.c
48816 +++ b/fs/nfsd/vfs.c
48817 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48818 } else {
48819 oldfs = get_fs();
48820 set_fs(KERNEL_DS);
48821 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48822 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48823 set_fs(oldfs);
48824 }
48825
48826 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48827
48828 /* Write the data. */
48829 oldfs = get_fs(); set_fs(KERNEL_DS);
48830 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48831 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48832 set_fs(oldfs);
48833 if (host_err < 0)
48834 goto out_nfserr;
48835 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48836 */
48837
48838 oldfs = get_fs(); set_fs(KERNEL_DS);
48839 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48840 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48841 set_fs(oldfs);
48842
48843 if (host_err < 0)
48844 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48845 index d438036..0ecadde 100644
48846 --- a/fs/notify/fanotify/fanotify_user.c
48847 +++ b/fs/notify/fanotify/fanotify_user.c
48848 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48849 goto out_close_fd;
48850
48851 ret = -EFAULT;
48852 - if (copy_to_user(buf, &fanotify_event_metadata,
48853 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48854 + copy_to_user(buf, &fanotify_event_metadata,
48855 fanotify_event_metadata.event_len))
48856 goto out_kill_access_response;
48857
48858 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48859 index c887b13..0fdf472 100644
48860 --- a/fs/notify/notification.c
48861 +++ b/fs/notify/notification.c
48862 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48863 * get set to 0 so it will never get 'freed'
48864 */
48865 static struct fsnotify_event *q_overflow_event;
48866 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48867 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48868
48869 /**
48870 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48871 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48872 */
48873 u32 fsnotify_get_cookie(void)
48874 {
48875 - return atomic_inc_return(&fsnotify_sync_cookie);
48876 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48877 }
48878 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48879
48880 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48881 index 99e3610..02c1068 100644
48882 --- a/fs/ntfs/dir.c
48883 +++ b/fs/ntfs/dir.c
48884 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48885 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48886 ~(s64)(ndir->itype.index.block_size - 1)));
48887 /* Bounds checks. */
48888 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48889 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48890 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48891 "inode 0x%lx or driver bug.", vdir->i_ino);
48892 goto err_out;
48893 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48894 index 1ecf464..e1ff8bf 100644
48895 --- a/fs/ntfs/file.c
48896 +++ b/fs/ntfs/file.c
48897 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48898 #endif /* NTFS_RW */
48899 };
48900
48901 -const struct file_operations ntfs_empty_file_ops = {};
48902 +const struct file_operations ntfs_empty_file_ops __read_only;
48903
48904 -const struct inode_operations ntfs_empty_inode_ops = {};
48905 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48906 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48907 index a9f78c7..ed8a381 100644
48908 --- a/fs/ocfs2/localalloc.c
48909 +++ b/fs/ocfs2/localalloc.c
48910 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48911 goto bail;
48912 }
48913
48914 - atomic_inc(&osb->alloc_stats.moves);
48915 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48916
48917 bail:
48918 if (handle)
48919 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48920 index d355e6e..578d905 100644
48921 --- a/fs/ocfs2/ocfs2.h
48922 +++ b/fs/ocfs2/ocfs2.h
48923 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48924
48925 struct ocfs2_alloc_stats
48926 {
48927 - atomic_t moves;
48928 - atomic_t local_data;
48929 - atomic_t bitmap_data;
48930 - atomic_t bg_allocs;
48931 - atomic_t bg_extends;
48932 + atomic_unchecked_t moves;
48933 + atomic_unchecked_t local_data;
48934 + atomic_unchecked_t bitmap_data;
48935 + atomic_unchecked_t bg_allocs;
48936 + atomic_unchecked_t bg_extends;
48937 };
48938
48939 enum ocfs2_local_alloc_state
48940 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48941 index f169da4..9112253 100644
48942 --- a/fs/ocfs2/suballoc.c
48943 +++ b/fs/ocfs2/suballoc.c
48944 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48945 mlog_errno(status);
48946 goto bail;
48947 }
48948 - atomic_inc(&osb->alloc_stats.bg_extends);
48949 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48950
48951 /* You should never ask for this much metadata */
48952 BUG_ON(bits_wanted >
48953 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48954 mlog_errno(status);
48955 goto bail;
48956 }
48957 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48958 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48959
48960 *suballoc_loc = res.sr_bg_blkno;
48961 *suballoc_bit_start = res.sr_bit_offset;
48962 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48963 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48964 res->sr_bits);
48965
48966 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48967 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48968
48969 BUG_ON(res->sr_bits != 1);
48970
48971 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48972 mlog_errno(status);
48973 goto bail;
48974 }
48975 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48976 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48977
48978 BUG_ON(res.sr_bits != 1);
48979
48980 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48981 cluster_start,
48982 num_clusters);
48983 if (!status)
48984 - atomic_inc(&osb->alloc_stats.local_data);
48985 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48986 } else {
48987 if (min_clusters > (osb->bitmap_cpg - 1)) {
48988 /* The only paths asking for contiguousness
48989 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48990 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48991 res.sr_bg_blkno,
48992 res.sr_bit_offset);
48993 - atomic_inc(&osb->alloc_stats.bitmap_data);
48994 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48995 *num_clusters = res.sr_bits;
48996 }
48997 }
48998 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48999 index 68f4541..89cfe6a 100644
49000 --- a/fs/ocfs2/super.c
49001 +++ b/fs/ocfs2/super.c
49002 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
49003 "%10s => GlobalAllocs: %d LocalAllocs: %d "
49004 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
49005 "Stats",
49006 - atomic_read(&osb->alloc_stats.bitmap_data),
49007 - atomic_read(&osb->alloc_stats.local_data),
49008 - atomic_read(&osb->alloc_stats.bg_allocs),
49009 - atomic_read(&osb->alloc_stats.moves),
49010 - atomic_read(&osb->alloc_stats.bg_extends));
49011 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
49012 + atomic_read_unchecked(&osb->alloc_stats.local_data),
49013 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
49014 + atomic_read_unchecked(&osb->alloc_stats.moves),
49015 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
49016
49017 out += snprintf(buf + out, len - out,
49018 "%10s => State: %u Descriptor: %llu Size: %u bits "
49019 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
49020 spin_lock_init(&osb->osb_xattr_lock);
49021 ocfs2_init_steal_slots(osb);
49022
49023 - atomic_set(&osb->alloc_stats.moves, 0);
49024 - atomic_set(&osb->alloc_stats.local_data, 0);
49025 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
49026 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
49027 - atomic_set(&osb->alloc_stats.bg_extends, 0);
49028 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
49029 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
49030 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
49031 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
49032 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
49033
49034 /* Copy the blockcheck stats from the superblock probe */
49035 osb->osb_ecc_stats = *stats;
49036 diff --git a/fs/open.c b/fs/open.c
49037 index e1f2cdb..3bd5f39 100644
49038 --- a/fs/open.c
49039 +++ b/fs/open.c
49040 @@ -31,6 +31,8 @@
49041 #include <linux/ima.h>
49042 #include <linux/dnotify.h>
49043
49044 +#define CREATE_TRACE_POINTS
49045 +#include <trace/events/fs.h>
49046 #include "internal.h"
49047
49048 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
49049 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
49050 error = locks_verify_truncate(inode, NULL, length);
49051 if (!error)
49052 error = security_path_truncate(&path);
49053 +
49054 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
49055 + error = -EACCES;
49056 +
49057 if (!error)
49058 error = do_truncate(path.dentry, length, 0, NULL);
49059
49060 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
49061 if (__mnt_is_readonly(path.mnt))
49062 res = -EROFS;
49063
49064 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
49065 + res = -EACCES;
49066 +
49067 out_path_release:
49068 path_put(&path);
49069 out:
49070 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
49071 if (error)
49072 goto dput_and_out;
49073
49074 + gr_log_chdir(path.dentry, path.mnt);
49075 +
49076 set_fs_pwd(current->fs, &path);
49077
49078 dput_and_out:
49079 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
49080 goto out_putf;
49081
49082 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
49083 +
49084 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
49085 + error = -EPERM;
49086 +
49087 + if (!error)
49088 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
49089 +
49090 if (!error)
49091 set_fs_pwd(current->fs, &file->f_path);
49092 out_putf:
49093 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
49094 if (error)
49095 goto dput_and_out;
49096
49097 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
49098 + goto dput_and_out;
49099 +
49100 set_fs_root(current->fs, &path);
49101 +
49102 + gr_handle_chroot_chdir(&path);
49103 +
49104 error = 0;
49105 dput_and_out:
49106 path_put(&path);
49107 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
49108 if (error)
49109 return error;
49110 mutex_lock(&inode->i_mutex);
49111 +
49112 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
49113 + error = -EACCES;
49114 + goto out_unlock;
49115 + }
49116 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
49117 + error = -EACCES;
49118 + goto out_unlock;
49119 + }
49120 +
49121 error = security_path_chmod(path, mode);
49122 if (error)
49123 goto out_unlock;
49124 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
49125 uid = make_kuid(current_user_ns(), user);
49126 gid = make_kgid(current_user_ns(), group);
49127
49128 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
49129 + return -EACCES;
49130 +
49131 newattrs.ia_valid = ATTR_CTIME;
49132 if (user != (uid_t) -1) {
49133 if (!uid_valid(uid))
49134 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
49135 } else {
49136 fsnotify_open(f);
49137 fd_install(fd, f);
49138 + trace_do_sys_open(tmp, flags, mode);
49139 }
49140 }
49141 putname(tmp);
49142 diff --git a/fs/pipe.c b/fs/pipe.c
49143 index 8d85d70..581036b 100644
49144 --- a/fs/pipe.c
49145 +++ b/fs/pipe.c
49146 @@ -438,9 +438,9 @@ redo:
49147 }
49148 if (bufs) /* More to do? */
49149 continue;
49150 - if (!pipe->writers)
49151 + if (!atomic_read(&pipe->writers))
49152 break;
49153 - if (!pipe->waiting_writers) {
49154 + if (!atomic_read(&pipe->waiting_writers)) {
49155 /* syscall merging: Usually we must not sleep
49156 * if O_NONBLOCK is set, or if we got some data.
49157 * But if a writer sleeps in kernel space, then
49158 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
49159 mutex_lock(&inode->i_mutex);
49160 pipe = inode->i_pipe;
49161
49162 - if (!pipe->readers) {
49163 + if (!atomic_read(&pipe->readers)) {
49164 send_sig(SIGPIPE, current, 0);
49165 ret = -EPIPE;
49166 goto out;
49167 @@ -553,7 +553,7 @@ redo1:
49168 for (;;) {
49169 int bufs;
49170
49171 - if (!pipe->readers) {
49172 + if (!atomic_read(&pipe->readers)) {
49173 send_sig(SIGPIPE, current, 0);
49174 if (!ret)
49175 ret = -EPIPE;
49176 @@ -644,9 +644,9 @@ redo2:
49177 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49178 do_wakeup = 0;
49179 }
49180 - pipe->waiting_writers++;
49181 + atomic_inc(&pipe->waiting_writers);
49182 pipe_wait(pipe);
49183 - pipe->waiting_writers--;
49184 + atomic_dec(&pipe->waiting_writers);
49185 }
49186 out:
49187 mutex_unlock(&inode->i_mutex);
49188 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
49189 mask = 0;
49190 if (filp->f_mode & FMODE_READ) {
49191 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
49192 - if (!pipe->writers && filp->f_version != pipe->w_counter)
49193 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
49194 mask |= POLLHUP;
49195 }
49196
49197 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
49198 * Most Unices do not set POLLERR for FIFOs but on Linux they
49199 * behave exactly like pipes for poll().
49200 */
49201 - if (!pipe->readers)
49202 + if (!atomic_read(&pipe->readers))
49203 mask |= POLLERR;
49204 }
49205
49206 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
49207
49208 mutex_lock(&inode->i_mutex);
49209 pipe = inode->i_pipe;
49210 - pipe->readers -= decr;
49211 - pipe->writers -= decw;
49212 + atomic_sub(decr, &pipe->readers);
49213 + atomic_sub(decw, &pipe->writers);
49214
49215 - if (!pipe->readers && !pipe->writers) {
49216 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
49217 free_pipe_info(inode);
49218 } else {
49219 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
49220 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
49221
49222 if (inode->i_pipe) {
49223 ret = 0;
49224 - inode->i_pipe->readers++;
49225 + atomic_inc(&inode->i_pipe->readers);
49226 }
49227
49228 mutex_unlock(&inode->i_mutex);
49229 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
49230
49231 if (inode->i_pipe) {
49232 ret = 0;
49233 - inode->i_pipe->writers++;
49234 + atomic_inc(&inode->i_pipe->writers);
49235 }
49236
49237 mutex_unlock(&inode->i_mutex);
49238 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
49239 if (inode->i_pipe) {
49240 ret = 0;
49241 if (filp->f_mode & FMODE_READ)
49242 - inode->i_pipe->readers++;
49243 + atomic_inc(&inode->i_pipe->readers);
49244 if (filp->f_mode & FMODE_WRITE)
49245 - inode->i_pipe->writers++;
49246 + atomic_inc(&inode->i_pipe->writers);
49247 }
49248
49249 mutex_unlock(&inode->i_mutex);
49250 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
49251 inode->i_pipe = NULL;
49252 }
49253
49254 -static struct vfsmount *pipe_mnt __read_mostly;
49255 +struct vfsmount *pipe_mnt __read_mostly;
49256
49257 /*
49258 * pipefs_dname() is called from d_path().
49259 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
49260 goto fail_iput;
49261 inode->i_pipe = pipe;
49262
49263 - pipe->readers = pipe->writers = 1;
49264 + atomic_set(&pipe->readers, 1);
49265 + atomic_set(&pipe->writers, 1);
49266 inode->i_fop = &rdwr_pipefifo_fops;
49267
49268 /*
49269 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
49270 index 15af622..0e9f4467 100644
49271 --- a/fs/proc/Kconfig
49272 +++ b/fs/proc/Kconfig
49273 @@ -30,12 +30,12 @@ config PROC_FS
49274
49275 config PROC_KCORE
49276 bool "/proc/kcore support" if !ARM
49277 - depends on PROC_FS && MMU
49278 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
49279
49280 config PROC_VMCORE
49281 bool "/proc/vmcore support"
49282 - depends on PROC_FS && CRASH_DUMP
49283 - default y
49284 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
49285 + default n
49286 help
49287 Exports the dump image of crashed kernel in ELF format.
49288
49289 @@ -59,8 +59,8 @@ config PROC_SYSCTL
49290 limited in memory.
49291
49292 config PROC_PAGE_MONITOR
49293 - default y
49294 - depends on PROC_FS && MMU
49295 + default n
49296 + depends on PROC_FS && MMU && !GRKERNSEC
49297 bool "Enable /proc page monitoring" if EXPERT
49298 help
49299 Various /proc files exist to monitor process memory utilization:
49300 diff --git a/fs/proc/array.c b/fs/proc/array.c
49301 index c1c207c..01ce725 100644
49302 --- a/fs/proc/array.c
49303 +++ b/fs/proc/array.c
49304 @@ -60,6 +60,7 @@
49305 #include <linux/tty.h>
49306 #include <linux/string.h>
49307 #include <linux/mman.h>
49308 +#include <linux/grsecurity.h>
49309 #include <linux/proc_fs.h>
49310 #include <linux/ioport.h>
49311 #include <linux/uaccess.h>
49312 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
49313 seq_putc(m, '\n');
49314 }
49315
49316 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49317 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
49318 +{
49319 + if (p->mm)
49320 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
49321 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
49322 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
49323 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
49324 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
49325 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
49326 + else
49327 + seq_printf(m, "PaX:\t-----\n");
49328 +}
49329 +#endif
49330 +
49331 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49332 struct pid *pid, struct task_struct *task)
49333 {
49334 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49335 task_cpus_allowed(m, task);
49336 cpuset_task_status_allowed(m, task);
49337 task_context_switch_counts(m, task);
49338 +
49339 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49340 + task_pax(m, task);
49341 +#endif
49342 +
49343 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
49344 + task_grsec_rbac(m, task);
49345 +#endif
49346 +
49347 return 0;
49348 }
49349
49350 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49351 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49352 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49353 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49354 +#endif
49355 +
49356 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49357 struct pid *pid, struct task_struct *task, int whole)
49358 {
49359 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49360 char tcomm[sizeof(task->comm)];
49361 unsigned long flags;
49362
49363 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49364 + if (current->exec_id != m->exec_id) {
49365 + gr_log_badprocpid("stat");
49366 + return 0;
49367 + }
49368 +#endif
49369 +
49370 state = *get_task_state(task);
49371 vsize = eip = esp = 0;
49372 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49373 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49374 gtime = task->gtime;
49375 }
49376
49377 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49378 + if (PAX_RAND_FLAGS(mm)) {
49379 + eip = 0;
49380 + esp = 0;
49381 + wchan = 0;
49382 + }
49383 +#endif
49384 +#ifdef CONFIG_GRKERNSEC_HIDESYM
49385 + wchan = 0;
49386 + eip =0;
49387 + esp =0;
49388 +#endif
49389 +
49390 /* scale priority and nice values from timeslices to -20..20 */
49391 /* to make it look like a "normal" Unix priority/nice value */
49392 priority = task_prio(task);
49393 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49394 seq_put_decimal_ull(m, ' ', vsize);
49395 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
49396 seq_put_decimal_ull(m, ' ', rsslim);
49397 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49398 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
49399 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
49400 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
49401 +#else
49402 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
49403 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
49404 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
49405 +#endif
49406 seq_put_decimal_ull(m, ' ', esp);
49407 seq_put_decimal_ull(m, ' ', eip);
49408 /* The signal information here is obsolete.
49409 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49410 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
49411 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
49412
49413 - if (mm && permitted) {
49414 + if (mm && permitted
49415 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49416 + && !PAX_RAND_FLAGS(mm)
49417 +#endif
49418 + ) {
49419 seq_put_decimal_ull(m, ' ', mm->start_data);
49420 seq_put_decimal_ull(m, ' ', mm->end_data);
49421 seq_put_decimal_ull(m, ' ', mm->start_brk);
49422 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49423 struct pid *pid, struct task_struct *task)
49424 {
49425 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
49426 - struct mm_struct *mm = get_task_mm(task);
49427 + struct mm_struct *mm;
49428
49429 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49430 + if (current->exec_id != m->exec_id) {
49431 + gr_log_badprocpid("statm");
49432 + return 0;
49433 + }
49434 +#endif
49435 + mm = get_task_mm(task);
49436 if (mm) {
49437 size = task_statm(mm, &shared, &text, &data, &resident);
49438 mmput(mm);
49439 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49440 return 0;
49441 }
49442
49443 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49444 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49445 +{
49446 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
49447 +}
49448 +#endif
49449 +
49450 #ifdef CONFIG_CHECKPOINT_RESTORE
49451 static struct pid *
49452 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
49453 diff --git a/fs/proc/base.c b/fs/proc/base.c
49454 index 1b6c84c..66b738b 100644
49455 --- a/fs/proc/base.c
49456 +++ b/fs/proc/base.c
49457 @@ -110,6 +110,14 @@ struct pid_entry {
49458 union proc_op op;
49459 };
49460
49461 +struct getdents_callback {
49462 + struct linux_dirent __user * current_dir;
49463 + struct linux_dirent __user * previous;
49464 + struct file * file;
49465 + int count;
49466 + int error;
49467 +};
49468 +
49469 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49470 .name = (NAME), \
49471 .len = sizeof(NAME) - 1, \
49472 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
49473 if (!mm->arg_end)
49474 goto out_mm; /* Shh! No looking before we're done */
49475
49476 + if (gr_acl_handle_procpidmem(task))
49477 + goto out_mm;
49478 +
49479 len = mm->arg_end - mm->arg_start;
49480
49481 if (len > PAGE_SIZE)
49482 @@ -236,12 +247,28 @@ out:
49483 return res;
49484 }
49485
49486 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49487 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49488 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49489 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49490 +#endif
49491 +
49492 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49493 {
49494 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
49495 int res = PTR_ERR(mm);
49496 if (mm && !IS_ERR(mm)) {
49497 unsigned int nwords = 0;
49498 +
49499 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49500 + /* allow if we're currently ptracing this task */
49501 + if (PAX_RAND_FLAGS(mm) &&
49502 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49503 + mmput(mm);
49504 + return 0;
49505 + }
49506 +#endif
49507 +
49508 do {
49509 nwords += 2;
49510 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49511 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
49512 }
49513
49514
49515 -#ifdef CONFIG_KALLSYMS
49516 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49517 /*
49518 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49519 * Returns the resolved symbol. If that fails, simply return the address.
49520 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
49521 mutex_unlock(&task->signal->cred_guard_mutex);
49522 }
49523
49524 -#ifdef CONFIG_STACKTRACE
49525 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49526
49527 #define MAX_STACK_TRACE_DEPTH 64
49528
49529 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
49530 return count;
49531 }
49532
49533 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49534 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49535 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49536 {
49537 long nr;
49538 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49539 /************************************************************************/
49540
49541 /* permission checks */
49542 -static int proc_fd_access_allowed(struct inode *inode)
49543 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49544 {
49545 struct task_struct *task;
49546 int allowed = 0;
49547 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49548 */
49549 task = get_proc_task(inode);
49550 if (task) {
49551 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49552 + if (log)
49553 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49554 + else
49555 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49556 put_task_struct(task);
49557 }
49558 return allowed;
49559 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49560 struct task_struct *task,
49561 int hide_pid_min)
49562 {
49563 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49564 + return false;
49565 +
49566 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49567 + rcu_read_lock();
49568 + {
49569 + const struct cred *tmpcred = current_cred();
49570 + const struct cred *cred = __task_cred(task);
49571 +
49572 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49573 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49574 + || in_group_p(grsec_proc_gid)
49575 +#endif
49576 + ) {
49577 + rcu_read_unlock();
49578 + return true;
49579 + }
49580 + }
49581 + rcu_read_unlock();
49582 +
49583 + if (!pid->hide_pid)
49584 + return false;
49585 +#endif
49586 +
49587 if (pid->hide_pid < hide_pid_min)
49588 return true;
49589 if (in_group_p(pid->pid_gid))
49590 return true;
49591 +
49592 return ptrace_may_access(task, PTRACE_MODE_READ);
49593 }
49594
49595 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49596 put_task_struct(task);
49597
49598 if (!has_perms) {
49599 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49600 + {
49601 +#else
49602 if (pid->hide_pid == 2) {
49603 +#endif
49604 /*
49605 * Let's make getdents(), stat(), and open()
49606 * consistent with each other. If a process
49607 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49608 if (!task)
49609 return -ESRCH;
49610
49611 + if (gr_acl_handle_procpidmem(task)) {
49612 + put_task_struct(task);
49613 + return -EPERM;
49614 + }
49615 +
49616 mm = mm_access(task, mode);
49617 put_task_struct(task);
49618
49619 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49620
49621 file->private_data = mm;
49622
49623 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49624 + file->f_version = current->exec_id;
49625 +#endif
49626 +
49627 return 0;
49628 }
49629
49630 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49631 ssize_t copied;
49632 char *page;
49633
49634 +#ifdef CONFIG_GRKERNSEC
49635 + if (write)
49636 + return -EPERM;
49637 +#endif
49638 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49639 + if (file->f_version != current->exec_id) {
49640 + gr_log_badprocpid("mem");
49641 + return 0;
49642 + }
49643 +#endif
49644 +
49645 if (!mm)
49646 return 0;
49647
49648 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49649 if (!mm)
49650 return 0;
49651
49652 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49653 + if (file->f_version != current->exec_id) {
49654 + gr_log_badprocpid("environ");
49655 + return 0;
49656 + }
49657 +#endif
49658 +
49659 page = (char *)__get_free_page(GFP_TEMPORARY);
49660 if (!page)
49661 return -ENOMEM;
49662 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49663 int error = -EACCES;
49664
49665 /* Are we allowed to snoop on the tasks file descriptors? */
49666 - if (!proc_fd_access_allowed(inode))
49667 + if (!proc_fd_access_allowed(inode, 0))
49668 goto out;
49669
49670 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49671 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49672 struct path path;
49673
49674 /* Are we allowed to snoop on the tasks file descriptors? */
49675 - if (!proc_fd_access_allowed(inode))
49676 - goto out;
49677 + /* logging this is needed for learning on chromium to work properly,
49678 + but we don't want to flood the logs from 'ps' which does a readlink
49679 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49680 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49681 + */
49682 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49683 + if (!proc_fd_access_allowed(inode,0))
49684 + goto out;
49685 + } else {
49686 + if (!proc_fd_access_allowed(inode,1))
49687 + goto out;
49688 + }
49689
49690 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49691 if (error)
49692 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49693 rcu_read_lock();
49694 cred = __task_cred(task);
49695 inode->i_uid = cred->euid;
49696 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49697 + inode->i_gid = grsec_proc_gid;
49698 +#else
49699 inode->i_gid = cred->egid;
49700 +#endif
49701 rcu_read_unlock();
49702 }
49703 security_task_to_inode(task, inode);
49704 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49705 return -ENOENT;
49706 }
49707 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49708 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49709 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49710 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49711 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49712 +#endif
49713 task_dumpable(task)) {
49714 cred = __task_cred(task);
49715 stat->uid = cred->euid;
49716 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49717 + stat->gid = grsec_proc_gid;
49718 +#else
49719 stat->gid = cred->egid;
49720 +#endif
49721 }
49722 }
49723 rcu_read_unlock();
49724 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49725
49726 if (task) {
49727 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49728 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49729 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49730 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49731 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49732 +#endif
49733 task_dumpable(task)) {
49734 rcu_read_lock();
49735 cred = __task_cred(task);
49736 inode->i_uid = cred->euid;
49737 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49738 + inode->i_gid = grsec_proc_gid;
49739 +#else
49740 inode->i_gid = cred->egid;
49741 +#endif
49742 rcu_read_unlock();
49743 } else {
49744 inode->i_uid = GLOBAL_ROOT_UID;
49745 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49746 int fd = proc_fd(inode);
49747
49748 if (task) {
49749 - files = get_files_struct(task);
49750 + if (!gr_acl_handle_procpidmem(task))
49751 + files = get_files_struct(task);
49752 put_task_struct(task);
49753 }
49754 if (files) {
49755 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49756 */
49757 static int proc_fd_permission(struct inode *inode, int mask)
49758 {
49759 + struct task_struct *task;
49760 int rv = generic_permission(inode, mask);
49761 - if (rv == 0)
49762 - return 0;
49763 +
49764 if (task_pid(current) == proc_pid(inode))
49765 rv = 0;
49766 +
49767 + task = get_proc_task(inode);
49768 + if (task == NULL)
49769 + return rv;
49770 +
49771 + if (gr_acl_handle_procpidmem(task))
49772 + rv = -EACCES;
49773 +
49774 + put_task_struct(task);
49775 +
49776 return rv;
49777 }
49778
49779 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49780 if (!task)
49781 goto out_no_task;
49782
49783 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49784 + goto out;
49785 +
49786 /*
49787 * Yes, it does not scale. And it should not. Don't add
49788 * new entries into /proc/<tgid>/ without very good reasons.
49789 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49790 if (!task)
49791 goto out_no_task;
49792
49793 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49794 + goto out;
49795 +
49796 ret = 0;
49797 i = filp->f_pos;
49798 switch (i) {
49799 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49800 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49801 void *cookie)
49802 {
49803 - char *s = nd_get_link(nd);
49804 + const char *s = nd_get_link(nd);
49805 if (!IS_ERR(s))
49806 __putname(s);
49807 }
49808 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49809 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49810 #endif
49811 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49812 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49813 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49814 INF("syscall", S_IRUGO, proc_pid_syscall),
49815 #endif
49816 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49817 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49818 #ifdef CONFIG_SECURITY
49819 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49820 #endif
49821 -#ifdef CONFIG_KALLSYMS
49822 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49823 INF("wchan", S_IRUGO, proc_pid_wchan),
49824 #endif
49825 -#ifdef CONFIG_STACKTRACE
49826 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49827 ONE("stack", S_IRUGO, proc_pid_stack),
49828 #endif
49829 #ifdef CONFIG_SCHEDSTATS
49830 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49831 #ifdef CONFIG_HARDWALL
49832 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49833 #endif
49834 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49835 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49836 +#endif
49837 #ifdef CONFIG_USER_NS
49838 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49839 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49840 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49841 if (!inode)
49842 goto out;
49843
49844 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49845 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49846 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49847 + inode->i_gid = grsec_proc_gid;
49848 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49849 +#else
49850 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49851 +#endif
49852 inode->i_op = &proc_tgid_base_inode_operations;
49853 inode->i_fop = &proc_tgid_base_operations;
49854 inode->i_flags|=S_IMMUTABLE;
49855 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49856 if (!task)
49857 goto out;
49858
49859 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49860 + goto out_put_task;
49861 +
49862 result = proc_pid_instantiate(dir, dentry, task, NULL);
49863 +out_put_task:
49864 put_task_struct(task);
49865 out:
49866 return result;
49867 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49868 static int fake_filldir(void *buf, const char *name, int namelen,
49869 loff_t offset, u64 ino, unsigned d_type)
49870 {
49871 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49872 + __buf->error = -EINVAL;
49873 return 0;
49874 }
49875
49876 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49877 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49878 #endif
49879 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49880 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49881 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49882 INF("syscall", S_IRUGO, proc_pid_syscall),
49883 #endif
49884 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49885 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49886 #ifdef CONFIG_SECURITY
49887 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49888 #endif
49889 -#ifdef CONFIG_KALLSYMS
49890 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49891 INF("wchan", S_IRUGO, proc_pid_wchan),
49892 #endif
49893 -#ifdef CONFIG_STACKTRACE
49894 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49895 ONE("stack", S_IRUGO, proc_pid_stack),
49896 #endif
49897 #ifdef CONFIG_SCHEDSTATS
49898 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49899 index 82676e3..5f8518a 100644
49900 --- a/fs/proc/cmdline.c
49901 +++ b/fs/proc/cmdline.c
49902 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49903
49904 static int __init proc_cmdline_init(void)
49905 {
49906 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49907 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49908 +#else
49909 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49910 +#endif
49911 return 0;
49912 }
49913 module_init(proc_cmdline_init);
49914 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49915 index b143471..bb105e5 100644
49916 --- a/fs/proc/devices.c
49917 +++ b/fs/proc/devices.c
49918 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49919
49920 static int __init proc_devices_init(void)
49921 {
49922 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49923 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49924 +#else
49925 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49926 +#endif
49927 return 0;
49928 }
49929 module_init(proc_devices_init);
49930 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49931 index 7ac817b..c5c9eb0 100644
49932 --- a/fs/proc/inode.c
49933 +++ b/fs/proc/inode.c
49934 @@ -21,11 +21,17 @@
49935 #include <linux/seq_file.h>
49936 #include <linux/slab.h>
49937 #include <linux/mount.h>
49938 +#include <linux/grsecurity.h>
49939
49940 #include <asm/uaccess.h>
49941
49942 #include "internal.h"
49943
49944 +#ifdef CONFIG_PROC_SYSCTL
49945 +extern const struct inode_operations proc_sys_inode_operations;
49946 +extern const struct inode_operations proc_sys_dir_operations;
49947 +#endif
49948 +
49949 static void proc_evict_inode(struct inode *inode)
49950 {
49951 struct proc_dir_entry *de;
49952 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49953 ns_ops = PROC_I(inode)->ns_ops;
49954 if (ns_ops && ns_ops->put)
49955 ns_ops->put(PROC_I(inode)->ns);
49956 +
49957 +#ifdef CONFIG_PROC_SYSCTL
49958 + if (inode->i_op == &proc_sys_inode_operations ||
49959 + inode->i_op == &proc_sys_dir_operations)
49960 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49961 +#endif
49962 +
49963 }
49964
49965 static struct kmem_cache * proc_inode_cachep;
49966 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49967 if (de->mode) {
49968 inode->i_mode = de->mode;
49969 inode->i_uid = de->uid;
49970 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49971 + inode->i_gid = grsec_proc_gid;
49972 +#else
49973 inode->i_gid = de->gid;
49974 +#endif
49975 }
49976 if (de->size)
49977 inode->i_size = de->size;
49978 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49979 index e1167a1..bd24f20 100644
49980 --- a/fs/proc/internal.h
49981 +++ b/fs/proc/internal.h
49982 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49983 struct pid *pid, struct task_struct *task);
49984 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49985 struct pid *pid, struct task_struct *task);
49986 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49987 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49988 +#endif
49989 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49990
49991 extern const struct file_operations proc_tid_children_operations;
49992 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49993 index 86c67ee..cdca321 100644
49994 --- a/fs/proc/kcore.c
49995 +++ b/fs/proc/kcore.c
49996 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49997 * the addresses in the elf_phdr on our list.
49998 */
49999 start = kc_offset_to_vaddr(*fpos - elf_buflen);
50000 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
50001 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
50002 + if (tsz > buflen)
50003 tsz = buflen;
50004 -
50005 +
50006 while (buflen) {
50007 struct kcore_list *m;
50008
50009 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50010 kfree(elf_buf);
50011 } else {
50012 if (kern_addr_valid(start)) {
50013 - unsigned long n;
50014 + char *elf_buf;
50015 + mm_segment_t oldfs;
50016
50017 - n = copy_to_user(buffer, (char *)start, tsz);
50018 - /*
50019 - * We cannot distinguish between fault on source
50020 - * and fault on destination. When this happens
50021 - * we clear too and hope it will trigger the
50022 - * EFAULT again.
50023 - */
50024 - if (n) {
50025 - if (clear_user(buffer + tsz - n,
50026 - n))
50027 + elf_buf = kmalloc(tsz, GFP_KERNEL);
50028 + if (!elf_buf)
50029 + return -ENOMEM;
50030 + oldfs = get_fs();
50031 + set_fs(KERNEL_DS);
50032 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
50033 + set_fs(oldfs);
50034 + if (copy_to_user(buffer, elf_buf, tsz)) {
50035 + kfree(elf_buf);
50036 return -EFAULT;
50037 + }
50038 }
50039 + set_fs(oldfs);
50040 + kfree(elf_buf);
50041 } else {
50042 if (clear_user(buffer, tsz))
50043 return -EFAULT;
50044 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50045
50046 static int open_kcore(struct inode *inode, struct file *filp)
50047 {
50048 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
50049 + return -EPERM;
50050 +#endif
50051 if (!capable(CAP_SYS_RAWIO))
50052 return -EPERM;
50053 if (kcore_need_update)
50054 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
50055 index 80e4645..53e5fcf 100644
50056 --- a/fs/proc/meminfo.c
50057 +++ b/fs/proc/meminfo.c
50058 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
50059 vmi.used >> 10,
50060 vmi.largest_chunk >> 10
50061 #ifdef CONFIG_MEMORY_FAILURE
50062 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
50063 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
50064 #endif
50065 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
50066 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
50067 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
50068 index b1822dd..df622cb 100644
50069 --- a/fs/proc/nommu.c
50070 +++ b/fs/proc/nommu.c
50071 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
50072 if (len < 1)
50073 len = 1;
50074 seq_printf(m, "%*c", len, ' ');
50075 - seq_path(m, &file->f_path, "");
50076 + seq_path(m, &file->f_path, "\n\\");
50077 }
50078
50079 seq_putc(m, '\n');
50080 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
50081 index fe72cd0..cb9b67d 100644
50082 --- a/fs/proc/proc_net.c
50083 +++ b/fs/proc/proc_net.c
50084 @@ -23,6 +23,7 @@
50085 #include <linux/nsproxy.h>
50086 #include <net/net_namespace.h>
50087 #include <linux/seq_file.h>
50088 +#include <linux/grsecurity.h>
50089
50090 #include "internal.h"
50091
50092 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
50093 struct task_struct *task;
50094 struct nsproxy *ns;
50095 struct net *net = NULL;
50096 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50097 + const struct cred *cred = current_cred();
50098 +#endif
50099 +
50100 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50101 + if (cred->fsuid)
50102 + return net;
50103 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50104 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
50105 + return net;
50106 +#endif
50107
50108 rcu_read_lock();
50109 task = pid_task(proc_pid(dir), PIDTYPE_PID);
50110 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
50111 index eb7cc91..7327a46 100644
50112 --- a/fs/proc/proc_sysctl.c
50113 +++ b/fs/proc/proc_sysctl.c
50114 @@ -12,11 +12,15 @@
50115 #include <linux/module.h>
50116 #include "internal.h"
50117
50118 +extern int gr_handle_chroot_sysctl(const int op);
50119 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
50120 + const int op);
50121 +
50122 static const struct dentry_operations proc_sys_dentry_operations;
50123 static const struct file_operations proc_sys_file_operations;
50124 -static const struct inode_operations proc_sys_inode_operations;
50125 +const struct inode_operations proc_sys_inode_operations;
50126 static const struct file_operations proc_sys_dir_file_operations;
50127 -static const struct inode_operations proc_sys_dir_operations;
50128 +const struct inode_operations proc_sys_dir_operations;
50129
50130 void proc_sys_poll_notify(struct ctl_table_poll *poll)
50131 {
50132 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
50133
50134 err = NULL;
50135 d_set_d_op(dentry, &proc_sys_dentry_operations);
50136 +
50137 + gr_handle_proc_create(dentry, inode);
50138 +
50139 d_add(dentry, inode);
50140
50141 out:
50142 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
50143 struct inode *inode = filp->f_path.dentry->d_inode;
50144 struct ctl_table_header *head = grab_header(inode);
50145 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
50146 + int op = write ? MAY_WRITE : MAY_READ;
50147 ssize_t error;
50148 size_t res;
50149
50150 if (IS_ERR(head))
50151 return PTR_ERR(head);
50152
50153 +
50154 /*
50155 * At this point we know that the sysctl was not unregistered
50156 * and won't be until we finish.
50157 */
50158 error = -EPERM;
50159 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
50160 + if (sysctl_perm(head->root, table, op))
50161 goto out;
50162
50163 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
50164 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
50165 if (!table->proc_handler)
50166 goto out;
50167
50168 +#ifdef CONFIG_GRKERNSEC
50169 + error = -EPERM;
50170 + if (gr_handle_chroot_sysctl(op))
50171 + goto out;
50172 + dget(filp->f_path.dentry);
50173 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
50174 + dput(filp->f_path.dentry);
50175 + goto out;
50176 + }
50177 + dput(filp->f_path.dentry);
50178 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
50179 + goto out;
50180 + if (write && !capable(CAP_SYS_ADMIN))
50181 + goto out;
50182 +#endif
50183 +
50184 /* careful: calling conventions are nasty here */
50185 res = count;
50186 error = table->proc_handler(table, write, buf, &res, ppos);
50187 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
50188 return -ENOMEM;
50189 } else {
50190 d_set_d_op(child, &proc_sys_dentry_operations);
50191 +
50192 + gr_handle_proc_create(child, inode);
50193 +
50194 d_add(child, inode);
50195 }
50196 } else {
50197 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
50198 if ((*pos)++ < file->f_pos)
50199 return 0;
50200
50201 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
50202 + return 0;
50203 +
50204 if (unlikely(S_ISLNK(table->mode)))
50205 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
50206 else
50207 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
50208 if (IS_ERR(head))
50209 return PTR_ERR(head);
50210
50211 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
50212 + return -ENOENT;
50213 +
50214 generic_fillattr(inode, stat);
50215 if (table)
50216 stat->mode = (stat->mode & S_IFMT) | table->mode;
50217 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
50218 .llseek = generic_file_llseek,
50219 };
50220
50221 -static const struct inode_operations proc_sys_inode_operations = {
50222 +const struct inode_operations proc_sys_inode_operations = {
50223 .permission = proc_sys_permission,
50224 .setattr = proc_sys_setattr,
50225 .getattr = proc_sys_getattr,
50226 };
50227
50228 -static const struct inode_operations proc_sys_dir_operations = {
50229 +const struct inode_operations proc_sys_dir_operations = {
50230 .lookup = proc_sys_lookup,
50231 .permission = proc_sys_permission,
50232 .setattr = proc_sys_setattr,
50233 diff --git a/fs/proc/root.c b/fs/proc/root.c
50234 index 9a2d9fd..ddfc92a 100644
50235 --- a/fs/proc/root.c
50236 +++ b/fs/proc/root.c
50237 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
50238 #ifdef CONFIG_PROC_DEVICETREE
50239 proc_device_tree_init();
50240 #endif
50241 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50242 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50243 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
50244 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50245 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50246 +#endif
50247 +#else
50248 proc_mkdir("bus", NULL);
50249 +#endif
50250 proc_sys_init();
50251 }
50252
50253 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
50254 index 4540b8f..1b9772f 100644
50255 --- a/fs/proc/task_mmu.c
50256 +++ b/fs/proc/task_mmu.c
50257 @@ -11,12 +11,19 @@
50258 #include <linux/rmap.h>
50259 #include <linux/swap.h>
50260 #include <linux/swapops.h>
50261 +#include <linux/grsecurity.h>
50262
50263 #include <asm/elf.h>
50264 #include <asm/uaccess.h>
50265 #include <asm/tlbflush.h>
50266 #include "internal.h"
50267
50268 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50269 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50270 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50271 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50272 +#endif
50273 +
50274 void task_mem(struct seq_file *m, struct mm_struct *mm)
50275 {
50276 unsigned long data, text, lib, swap;
50277 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50278 "VmExe:\t%8lu kB\n"
50279 "VmLib:\t%8lu kB\n"
50280 "VmPTE:\t%8lu kB\n"
50281 - "VmSwap:\t%8lu kB\n",
50282 - hiwater_vm << (PAGE_SHIFT-10),
50283 + "VmSwap:\t%8lu kB\n"
50284 +
50285 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50286 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
50287 +#endif
50288 +
50289 + ,hiwater_vm << (PAGE_SHIFT-10),
50290 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
50291 mm->locked_vm << (PAGE_SHIFT-10),
50292 mm->pinned_vm << (PAGE_SHIFT-10),
50293 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50294 data << (PAGE_SHIFT-10),
50295 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
50296 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
50297 - swap << (PAGE_SHIFT-10));
50298 + swap << (PAGE_SHIFT-10)
50299 +
50300 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50301 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50302 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
50303 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
50304 +#else
50305 + , mm->context.user_cs_base
50306 + , mm->context.user_cs_limit
50307 +#endif
50308 +#endif
50309 +
50310 + );
50311 }
50312
50313 unsigned long task_vsize(struct mm_struct *mm)
50314 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50315 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
50316 }
50317
50318 - /* We don't show the stack guard page in /proc/maps */
50319 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50320 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
50321 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
50322 +#else
50323 start = vma->vm_start;
50324 - if (stack_guard_page_start(vma, start))
50325 - start += PAGE_SIZE;
50326 end = vma->vm_end;
50327 - if (stack_guard_page_end(vma, end))
50328 - end -= PAGE_SIZE;
50329 +#endif
50330
50331 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
50332 start,
50333 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50334 flags & VM_WRITE ? 'w' : '-',
50335 flags & VM_EXEC ? 'x' : '-',
50336 flags & VM_MAYSHARE ? 's' : 'p',
50337 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50338 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
50339 +#else
50340 pgoff,
50341 +#endif
50342 MAJOR(dev), MINOR(dev), ino, &len);
50343
50344 /*
50345 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50346 */
50347 if (file) {
50348 pad_len_spaces(m, len);
50349 - seq_path(m, &file->f_path, "\n");
50350 + seq_path(m, &file->f_path, "\n\\");
50351 goto done;
50352 }
50353
50354 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50355 * Thread stack in /proc/PID/task/TID/maps or
50356 * the main process stack.
50357 */
50358 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
50359 - vma->vm_end >= mm->start_stack)) {
50360 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
50361 + (vma->vm_start <= mm->start_stack &&
50362 + vma->vm_end >= mm->start_stack)) {
50363 name = "[stack]";
50364 } else {
50365 /* Thread stack in /proc/PID/maps */
50366 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
50367 struct proc_maps_private *priv = m->private;
50368 struct task_struct *task = priv->task;
50369
50370 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50371 + if (current->exec_id != m->exec_id) {
50372 + gr_log_badprocpid("maps");
50373 + return 0;
50374 + }
50375 +#endif
50376 +
50377 show_map_vma(m, vma, is_pid);
50378
50379 if (m->count < m->size) /* vma is copied successfully */
50380 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50381 .private = &mss,
50382 };
50383
50384 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50385 + if (current->exec_id != m->exec_id) {
50386 + gr_log_badprocpid("smaps");
50387 + return 0;
50388 + }
50389 +#endif
50390 memset(&mss, 0, sizeof mss);
50391 - mss.vma = vma;
50392 - /* mmap_sem is held in m_start */
50393 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50394 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50395 -
50396 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50397 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50398 +#endif
50399 + mss.vma = vma;
50400 + /* mmap_sem is held in m_start */
50401 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50402 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50403 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50404 + }
50405 +#endif
50406 show_map_vma(m, vma, is_pid);
50407
50408 seq_printf(m,
50409 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50410 "KernelPageSize: %8lu kB\n"
50411 "MMUPageSize: %8lu kB\n"
50412 "Locked: %8lu kB\n",
50413 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50414 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50415 +#else
50416 (vma->vm_end - vma->vm_start) >> 10,
50417 +#endif
50418 mss.resident >> 10,
50419 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50420 mss.shared_clean >> 10,
50421 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50422 int n;
50423 char buffer[50];
50424
50425 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50426 + if (current->exec_id != m->exec_id) {
50427 + gr_log_badprocpid("numa_maps");
50428 + return 0;
50429 + }
50430 +#endif
50431 +
50432 if (!mm)
50433 return 0;
50434
50435 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50436 mpol_to_str(buffer, sizeof(buffer), pol, 0);
50437 mpol_cond_put(pol);
50438
50439 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50440 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
50441 +#else
50442 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
50443 +#endif
50444
50445 if (file) {
50446 seq_printf(m, " file=");
50447 - seq_path(m, &file->f_path, "\n\t= ");
50448 + seq_path(m, &file->f_path, "\n\t\\= ");
50449 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
50450 seq_printf(m, " heap");
50451 } else {
50452 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
50453 index 1ccfa53..0848f95 100644
50454 --- a/fs/proc/task_nommu.c
50455 +++ b/fs/proc/task_nommu.c
50456 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50457 else
50458 bytes += kobjsize(mm);
50459
50460 - if (current->fs && current->fs->users > 1)
50461 + if (current->fs && atomic_read(&current->fs->users) > 1)
50462 sbytes += kobjsize(current->fs);
50463 else
50464 bytes += kobjsize(current->fs);
50465 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
50466
50467 if (file) {
50468 pad_len_spaces(m, len);
50469 - seq_path(m, &file->f_path, "");
50470 + seq_path(m, &file->f_path, "\n\\");
50471 } else if (mm) {
50472 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
50473
50474 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
50475 index d67908b..d13f6a6 100644
50476 --- a/fs/quota/netlink.c
50477 +++ b/fs/quota/netlink.c
50478 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
50479 void quota_send_warning(short type, unsigned int id, dev_t dev,
50480 const char warntype)
50481 {
50482 - static atomic_t seq;
50483 + static atomic_unchecked_t seq;
50484 struct sk_buff *skb;
50485 void *msg_head;
50486 int ret;
50487 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
50488 "VFS: Not enough memory to send quota warning.\n");
50489 return;
50490 }
50491 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50492 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50493 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50494 if (!msg_head) {
50495 printk(KERN_ERR
50496 diff --git a/fs/readdir.c b/fs/readdir.c
50497 index 39e3370..20d446d 100644
50498 --- a/fs/readdir.c
50499 +++ b/fs/readdir.c
50500 @@ -17,6 +17,7 @@
50501 #include <linux/security.h>
50502 #include <linux/syscalls.h>
50503 #include <linux/unistd.h>
50504 +#include <linux/namei.h>
50505
50506 #include <asm/uaccess.h>
50507
50508 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50509
50510 struct readdir_callback {
50511 struct old_linux_dirent __user * dirent;
50512 + struct file * file;
50513 int result;
50514 };
50515
50516 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
50517 buf->result = -EOVERFLOW;
50518 return -EOVERFLOW;
50519 }
50520 +
50521 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50522 + return 0;
50523 +
50524 buf->result++;
50525 dirent = buf->dirent;
50526 if (!access_ok(VERIFY_WRITE, dirent,
50527 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50528
50529 buf.result = 0;
50530 buf.dirent = dirent;
50531 + buf.file = file;
50532
50533 error = vfs_readdir(file, fillonedir, &buf);
50534 if (buf.result)
50535 @@ -141,6 +148,7 @@ struct linux_dirent {
50536 struct getdents_callback {
50537 struct linux_dirent __user * current_dir;
50538 struct linux_dirent __user * previous;
50539 + struct file * file;
50540 int count;
50541 int error;
50542 };
50543 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50544 buf->error = -EOVERFLOW;
50545 return -EOVERFLOW;
50546 }
50547 +
50548 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50549 + return 0;
50550 +
50551 dirent = buf->previous;
50552 if (dirent) {
50553 if (__put_user(offset, &dirent->d_off))
50554 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50555 buf.previous = NULL;
50556 buf.count = count;
50557 buf.error = 0;
50558 + buf.file = file;
50559
50560 error = vfs_readdir(file, filldir, &buf);
50561 if (error >= 0)
50562 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50563 struct getdents_callback64 {
50564 struct linux_dirent64 __user * current_dir;
50565 struct linux_dirent64 __user * previous;
50566 + struct file *file;
50567 int count;
50568 int error;
50569 };
50570 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50571 buf->error = -EINVAL; /* only used if we fail.. */
50572 if (reclen > buf->count)
50573 return -EINVAL;
50574 +
50575 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50576 + return 0;
50577 +
50578 dirent = buf->previous;
50579 if (dirent) {
50580 if (__put_user(offset, &dirent->d_off))
50581 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50582
50583 buf.current_dir = dirent;
50584 buf.previous = NULL;
50585 + buf.file = file;
50586 buf.count = count;
50587 buf.error = 0;
50588
50589 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50590 error = buf.error;
50591 lastdirent = buf.previous;
50592 if (lastdirent) {
50593 - typeof(lastdirent->d_off) d_off = file->f_pos;
50594 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50595 if (__put_user(d_off, &lastdirent->d_off))
50596 error = -EFAULT;
50597 else
50598 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50599 index 2b7882b..1c5ef48 100644
50600 --- a/fs/reiserfs/do_balan.c
50601 +++ b/fs/reiserfs/do_balan.c
50602 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50603 return;
50604 }
50605
50606 - atomic_inc(&(fs_generation(tb->tb_sb)));
50607 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50608 do_balance_starts(tb);
50609
50610 /* balance leaf returns 0 except if combining L R and S into
50611 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50612 index e60e870..f40ac16 100644
50613 --- a/fs/reiserfs/procfs.c
50614 +++ b/fs/reiserfs/procfs.c
50615 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50616 "SMALL_TAILS " : "NO_TAILS ",
50617 replay_only(sb) ? "REPLAY_ONLY " : "",
50618 convert_reiserfs(sb) ? "CONV " : "",
50619 - atomic_read(&r->s_generation_counter),
50620 + atomic_read_unchecked(&r->s_generation_counter),
50621 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50622 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50623 SF(s_good_search_by_key_reada), SF(s_bmaps),
50624 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50625 index 33215f5..c5d427a 100644
50626 --- a/fs/reiserfs/reiserfs.h
50627 +++ b/fs/reiserfs/reiserfs.h
50628 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50629 /* Comment? -Hans */
50630 wait_queue_head_t s_wait;
50631 /* To be obsoleted soon by per buffer seals.. -Hans */
50632 - atomic_t s_generation_counter; // increased by one every time the
50633 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50634 // tree gets re-balanced
50635 unsigned long s_properties; /* File system properties. Currently holds
50636 on-disk FS format */
50637 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50638 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50639
50640 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50641 -#define get_generation(s) atomic_read (&fs_generation(s))
50642 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50643 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50644 #define __fs_changed(gen,s) (gen != get_generation (s))
50645 #define fs_changed(gen,s) \
50646 diff --git a/fs/select.c b/fs/select.c
50647 index db14c78..3aae1bd 100644
50648 --- a/fs/select.c
50649 +++ b/fs/select.c
50650 @@ -20,6 +20,7 @@
50651 #include <linux/export.h>
50652 #include <linux/slab.h>
50653 #include <linux/poll.h>
50654 +#include <linux/security.h>
50655 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50656 #include <linux/file.h>
50657 #include <linux/fdtable.h>
50658 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50659 struct poll_list *walk = head;
50660 unsigned long todo = nfds;
50661
50662 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50663 if (nfds > rlimit(RLIMIT_NOFILE))
50664 return -EINVAL;
50665
50666 diff --git a/fs/seq_file.c b/fs/seq_file.c
50667 index 14cf9de..adc4d5b 100644
50668 --- a/fs/seq_file.c
50669 +++ b/fs/seq_file.c
50670 @@ -9,6 +9,7 @@
50671 #include <linux/export.h>
50672 #include <linux/seq_file.h>
50673 #include <linux/slab.h>
50674 +#include <linux/sched.h>
50675
50676 #include <asm/uaccess.h>
50677 #include <asm/page.h>
50678 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50679 memset(p, 0, sizeof(*p));
50680 mutex_init(&p->lock);
50681 p->op = op;
50682 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50683 + p->exec_id = current->exec_id;
50684 +#endif
50685
50686 /*
50687 * Wrappers around seq_open(e.g. swaps_open) need to be
50688 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50689 return 0;
50690 }
50691 if (!m->buf) {
50692 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50693 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50694 if (!m->buf)
50695 return -ENOMEM;
50696 }
50697 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50698 Eoverflow:
50699 m->op->stop(m, p);
50700 kfree(m->buf);
50701 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50702 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50703 return !m->buf ? -ENOMEM : -EAGAIN;
50704 }
50705
50706 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50707
50708 /* grab buffer if we didn't have one */
50709 if (!m->buf) {
50710 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50711 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50712 if (!m->buf)
50713 goto Enomem;
50714 }
50715 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50716 goto Fill;
50717 m->op->stop(m, p);
50718 kfree(m->buf);
50719 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50720 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50721 if (!m->buf)
50722 goto Enomem;
50723 m->count = 0;
50724 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50725 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50726 void *data)
50727 {
50728 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50729 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50730 int res = -ENOMEM;
50731
50732 if (op) {
50733 diff --git a/fs/splice.c b/fs/splice.c
50734 index 41514dd..6564a93 100644
50735 --- a/fs/splice.c
50736 +++ b/fs/splice.c
50737 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50738 pipe_lock(pipe);
50739
50740 for (;;) {
50741 - if (!pipe->readers) {
50742 + if (!atomic_read(&pipe->readers)) {
50743 send_sig(SIGPIPE, current, 0);
50744 if (!ret)
50745 ret = -EPIPE;
50746 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50747 do_wakeup = 0;
50748 }
50749
50750 - pipe->waiting_writers++;
50751 + atomic_inc(&pipe->waiting_writers);
50752 pipe_wait(pipe);
50753 - pipe->waiting_writers--;
50754 + atomic_dec(&pipe->waiting_writers);
50755 }
50756
50757 pipe_unlock(pipe);
50758 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50759 old_fs = get_fs();
50760 set_fs(get_ds());
50761 /* The cast to a user pointer is valid due to the set_fs() */
50762 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50763 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50764 set_fs(old_fs);
50765
50766 return res;
50767 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50768 old_fs = get_fs();
50769 set_fs(get_ds());
50770 /* The cast to a user pointer is valid due to the set_fs() */
50771 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50772 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50773 set_fs(old_fs);
50774
50775 return res;
50776 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50777 goto err;
50778
50779 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50780 - vec[i].iov_base = (void __user *) page_address(page);
50781 + vec[i].iov_base = (void __force_user *) page_address(page);
50782 vec[i].iov_len = this_len;
50783 spd.pages[i] = page;
50784 spd.nr_pages++;
50785 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50786 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50787 {
50788 while (!pipe->nrbufs) {
50789 - if (!pipe->writers)
50790 + if (!atomic_read(&pipe->writers))
50791 return 0;
50792
50793 - if (!pipe->waiting_writers && sd->num_spliced)
50794 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50795 return 0;
50796
50797 if (sd->flags & SPLICE_F_NONBLOCK)
50798 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50799 * out of the pipe right after the splice_to_pipe(). So set
50800 * PIPE_READERS appropriately.
50801 */
50802 - pipe->readers = 1;
50803 + atomic_set(&pipe->readers, 1);
50804
50805 current->splice_pipe = pipe;
50806 }
50807 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50808 ret = -ERESTARTSYS;
50809 break;
50810 }
50811 - if (!pipe->writers)
50812 + if (!atomic_read(&pipe->writers))
50813 break;
50814 - if (!pipe->waiting_writers) {
50815 + if (!atomic_read(&pipe->waiting_writers)) {
50816 if (flags & SPLICE_F_NONBLOCK) {
50817 ret = -EAGAIN;
50818 break;
50819 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50820 pipe_lock(pipe);
50821
50822 while (pipe->nrbufs >= pipe->buffers) {
50823 - if (!pipe->readers) {
50824 + if (!atomic_read(&pipe->readers)) {
50825 send_sig(SIGPIPE, current, 0);
50826 ret = -EPIPE;
50827 break;
50828 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50829 ret = -ERESTARTSYS;
50830 break;
50831 }
50832 - pipe->waiting_writers++;
50833 + atomic_inc(&pipe->waiting_writers);
50834 pipe_wait(pipe);
50835 - pipe->waiting_writers--;
50836 + atomic_dec(&pipe->waiting_writers);
50837 }
50838
50839 pipe_unlock(pipe);
50840 @@ -1828,14 +1828,14 @@ retry:
50841 pipe_double_lock(ipipe, opipe);
50842
50843 do {
50844 - if (!opipe->readers) {
50845 + if (!atomic_read(&opipe->readers)) {
50846 send_sig(SIGPIPE, current, 0);
50847 if (!ret)
50848 ret = -EPIPE;
50849 break;
50850 }
50851
50852 - if (!ipipe->nrbufs && !ipipe->writers)
50853 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50854 break;
50855
50856 /*
50857 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50858 pipe_double_lock(ipipe, opipe);
50859
50860 do {
50861 - if (!opipe->readers) {
50862 + if (!atomic_read(&opipe->readers)) {
50863 send_sig(SIGPIPE, current, 0);
50864 if (!ret)
50865 ret = -EPIPE;
50866 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50867 * return EAGAIN if we have the potential of some data in the
50868 * future, otherwise just return 0
50869 */
50870 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50871 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50872 ret = -EAGAIN;
50873
50874 pipe_unlock(ipipe);
50875 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50876 index 2fbdff6..5530a61 100644
50877 --- a/fs/sysfs/dir.c
50878 +++ b/fs/sysfs/dir.c
50879 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50880 struct sysfs_dirent *sd;
50881 int rc;
50882
50883 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50884 + const char *parent_name = parent_sd->s_name;
50885 +
50886 + mode = S_IFDIR | S_IRWXU;
50887 +
50888 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50889 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50890 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50891 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50892 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50893 +#endif
50894 +
50895 /* allocate */
50896 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50897 if (!sd)
50898 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50899 index 00012e3..8392349 100644
50900 --- a/fs/sysfs/file.c
50901 +++ b/fs/sysfs/file.c
50902 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50903
50904 struct sysfs_open_dirent {
50905 atomic_t refcnt;
50906 - atomic_t event;
50907 + atomic_unchecked_t event;
50908 wait_queue_head_t poll;
50909 struct list_head buffers; /* goes through sysfs_buffer.list */
50910 };
50911 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50912 if (!sysfs_get_active(attr_sd))
50913 return -ENODEV;
50914
50915 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50916 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50917 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50918
50919 sysfs_put_active(attr_sd);
50920 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50921 return -ENOMEM;
50922
50923 atomic_set(&new_od->refcnt, 0);
50924 - atomic_set(&new_od->event, 1);
50925 + atomic_set_unchecked(&new_od->event, 1);
50926 init_waitqueue_head(&new_od->poll);
50927 INIT_LIST_HEAD(&new_od->buffers);
50928 goto retry;
50929 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50930
50931 sysfs_put_active(attr_sd);
50932
50933 - if (buffer->event != atomic_read(&od->event))
50934 + if (buffer->event != atomic_read_unchecked(&od->event))
50935 goto trigger;
50936
50937 return DEFAULT_POLLMASK;
50938 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50939
50940 od = sd->s_attr.open;
50941 if (od) {
50942 - atomic_inc(&od->event);
50943 + atomic_inc_unchecked(&od->event);
50944 wake_up_interruptible(&od->poll);
50945 }
50946
50947 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50948 index a7ac78f..02158e1 100644
50949 --- a/fs/sysfs/symlink.c
50950 +++ b/fs/sysfs/symlink.c
50951 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50952
50953 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50954 {
50955 - char *page = nd_get_link(nd);
50956 + const char *page = nd_get_link(nd);
50957 if (!IS_ERR(page))
50958 free_page((unsigned long)page);
50959 }
50960 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50961 index c175b4d..8f36a16 100644
50962 --- a/fs/udf/misc.c
50963 +++ b/fs/udf/misc.c
50964 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50965
50966 u8 udf_tag_checksum(const struct tag *t)
50967 {
50968 - u8 *data = (u8 *)t;
50969 + const u8 *data = (const u8 *)t;
50970 u8 checksum = 0;
50971 int i;
50972 for (i = 0; i < sizeof(struct tag); ++i)
50973 diff --git a/fs/utimes.c b/fs/utimes.c
50974 index fa4dbe4..e12d1b9 100644
50975 --- a/fs/utimes.c
50976 +++ b/fs/utimes.c
50977 @@ -1,6 +1,7 @@
50978 #include <linux/compiler.h>
50979 #include <linux/file.h>
50980 #include <linux/fs.h>
50981 +#include <linux/security.h>
50982 #include <linux/linkage.h>
50983 #include <linux/mount.h>
50984 #include <linux/namei.h>
50985 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50986 goto mnt_drop_write_and_out;
50987 }
50988 }
50989 +
50990 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50991 + error = -EACCES;
50992 + goto mnt_drop_write_and_out;
50993 + }
50994 +
50995 mutex_lock(&inode->i_mutex);
50996 error = notify_change(path->dentry, &newattrs);
50997 mutex_unlock(&inode->i_mutex);
50998 diff --git a/fs/xattr.c b/fs/xattr.c
50999 index 4d45b71..2ec08e10 100644
51000 --- a/fs/xattr.c
51001 +++ b/fs/xattr.c
51002 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
51003 * Extended attribute SET operations
51004 */
51005 static long
51006 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
51007 +setxattr(struct path *path, const char __user *name, const void __user *value,
51008 size_t size, int flags)
51009 {
51010 int error;
51011 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
51012 }
51013 }
51014
51015 - error = vfs_setxattr(d, kname, kvalue, size, flags);
51016 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
51017 + error = -EACCES;
51018 + goto out;
51019 + }
51020 +
51021 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
51022 out:
51023 if (vvalue)
51024 vfree(vvalue);
51025 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
51026 return error;
51027 error = mnt_want_write(path.mnt);
51028 if (!error) {
51029 - error = setxattr(path.dentry, name, value, size, flags);
51030 + error = setxattr(&path, name, value, size, flags);
51031 mnt_drop_write(path.mnt);
51032 }
51033 path_put(&path);
51034 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
51035 return error;
51036 error = mnt_want_write(path.mnt);
51037 if (!error) {
51038 - error = setxattr(path.dentry, name, value, size, flags);
51039 + error = setxattr(&path, name, value, size, flags);
51040 mnt_drop_write(path.mnt);
51041 }
51042 path_put(&path);
51043 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
51044 {
51045 int fput_needed;
51046 struct file *f;
51047 - struct dentry *dentry;
51048 int error = -EBADF;
51049
51050 f = fget_light(fd, &fput_needed);
51051 if (!f)
51052 return error;
51053 - dentry = f->f_path.dentry;
51054 - audit_inode(NULL, dentry);
51055 + audit_inode(NULL, f->f_path.dentry);
51056 error = mnt_want_write_file(f);
51057 if (!error) {
51058 - error = setxattr(dentry, name, value, size, flags);
51059 + error = setxattr(&f->f_path, name, value, size, flags);
51060 mnt_drop_write_file(f);
51061 }
51062 fput_light(f, fput_needed);
51063 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
51064 index 69d06b0..c0996e5 100644
51065 --- a/fs/xattr_acl.c
51066 +++ b/fs/xattr_acl.c
51067 @@ -17,8 +17,8 @@
51068 struct posix_acl *
51069 posix_acl_from_xattr(const void *value, size_t size)
51070 {
51071 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
51072 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
51073 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
51074 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
51075 int count;
51076 struct posix_acl *acl;
51077 struct posix_acl_entry *acl_e;
51078 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
51079 index 848ffa7..1f249bf 100644
51080 --- a/fs/xfs/xfs_bmap.c
51081 +++ b/fs/xfs/xfs_bmap.c
51082 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
51083 int nmap,
51084 int ret_nmap);
51085 #else
51086 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
51087 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
51088 #endif /* DEBUG */
51089
51090 STATIC int
51091 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
51092 index 1b9fc3e..e1bdde0 100644
51093 --- a/fs/xfs/xfs_dir2_sf.c
51094 +++ b/fs/xfs/xfs_dir2_sf.c
51095 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
51096 }
51097
51098 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
51099 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51100 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
51101 + char name[sfep->namelen];
51102 + memcpy(name, sfep->name, sfep->namelen);
51103 + if (filldir(dirent, name, sfep->namelen,
51104 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
51105 + *offset = off & 0x7fffffff;
51106 + return 0;
51107 + }
51108 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51109 off & 0x7fffffff, ino, DT_UNKNOWN)) {
51110 *offset = off & 0x7fffffff;
51111 return 0;
51112 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
51113 index 0e0232c..fa5c3fe 100644
51114 --- a/fs/xfs/xfs_ioctl.c
51115 +++ b/fs/xfs/xfs_ioctl.c
51116 @@ -126,7 +126,7 @@ xfs_find_handle(
51117 }
51118
51119 error = -EFAULT;
51120 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
51121 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
51122 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
51123 goto out_put;
51124
51125 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
51126 index 4e00cf0..3374374 100644
51127 --- a/fs/xfs/xfs_iops.c
51128 +++ b/fs/xfs/xfs_iops.c
51129 @@ -394,7 +394,7 @@ xfs_vn_put_link(
51130 struct nameidata *nd,
51131 void *p)
51132 {
51133 - char *s = nd_get_link(nd);
51134 + const char *s = nd_get_link(nd);
51135
51136 if (!IS_ERR(s))
51137 kfree(s);
51138 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
51139 new file mode 100644
51140 index 0000000..10c36fb
51141 --- /dev/null
51142 +++ b/grsecurity/Kconfig
51143 @@ -0,0 +1,964 @@
51144 +#
51145 +# grecurity configuration
51146 +#
51147 +menu "Memory Protections"
51148 +depends on GRKERNSEC
51149 +
51150 +config GRKERNSEC_KMEM
51151 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
51152 + default y if GRKERNSEC_CONFIG_AUTO
51153 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
51154 + help
51155 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
51156 + be written to or read from to modify or leak the contents of the running
51157 + kernel. /dev/port will also not be allowed to be opened. If you have module
51158 + support disabled, enabling this will close up four ways that are
51159 + currently used to insert malicious code into the running kernel.
51160 + Even with all these features enabled, we still highly recommend that
51161 + you use the RBAC system, as it is still possible for an attacker to
51162 + modify the running kernel through privileged I/O granted by ioperm/iopl.
51163 + If you are not using XFree86, you may be able to stop this additional
51164 + case by enabling the 'Disable privileged I/O' option. Though nothing
51165 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
51166 + but only to video memory, which is the only writing we allow in this
51167 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
51168 + not be allowed to mprotect it with PROT_WRITE later.
51169 + It is highly recommended that you say Y here if you meet all the
51170 + conditions above.
51171 +
51172 +config GRKERNSEC_VM86
51173 + bool "Restrict VM86 mode"
51174 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51175 + depends on X86_32
51176 +
51177 + help
51178 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
51179 + make use of a special execution mode on 32bit x86 processors called
51180 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
51181 + video cards and will still work with this option enabled. The purpose
51182 + of the option is to prevent exploitation of emulation errors in
51183 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
51184 + Nearly all users should be able to enable this option.
51185 +
51186 +config GRKERNSEC_IO
51187 + bool "Disable privileged I/O"
51188 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51189 + depends on X86
51190 + select RTC_CLASS
51191 + select RTC_INTF_DEV
51192 + select RTC_DRV_CMOS
51193 +
51194 + help
51195 + If you say Y here, all ioperm and iopl calls will return an error.
51196 + Ioperm and iopl can be used to modify the running kernel.
51197 + Unfortunately, some programs need this access to operate properly,
51198 + the most notable of which are XFree86 and hwclock. hwclock can be
51199 + remedied by having RTC support in the kernel, so real-time
51200 + clock support is enabled if this option is enabled, to ensure
51201 + that hwclock operates correctly. XFree86 still will not
51202 + operate correctly with this option enabled, so DO NOT CHOOSE Y
51203 + IF YOU USE XFree86. If you use XFree86 and you still want to
51204 + protect your kernel against modification, use the RBAC system.
51205 +
51206 +config GRKERNSEC_JIT_HARDEN
51207 + bool "Harden BPF JIT against spray attacks"
51208 + default y if GRKERNSEC_CONFIG_AUTO
51209 + depends on BPF_JIT
51210 + help
51211 + If you say Y here, the native code generated by the kernel's Berkeley
51212 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
51213 + attacks that attempt to fit attacker-beneficial instructions in
51214 + 32bit immediate fields of JIT-generated native instructions. The
51215 + attacker will generally aim to cause an unintended instruction sequence
51216 + of JIT-generated native code to execute by jumping into the middle of
51217 + a generated instruction. This feature effectively randomizes the 32bit
51218 + immediate constants present in the generated code to thwart such attacks.
51219 +
51220 + If you're using KERNEXEC, it's recommended that you enable this option
51221 + to supplement the hardening of the kernel.
51222 +
51223 +config GRKERNSEC_PROC_MEMMAP
51224 + bool "Harden ASLR against information leaks and entropy reduction"
51225 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
51226 + depends on PAX_NOEXEC || PAX_ASLR
51227 + help
51228 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
51229 + give no information about the addresses of its mappings if
51230 + PaX features that rely on random addresses are enabled on the task.
51231 + In addition to sanitizing this information and disabling other
51232 + dangerous sources of information, this option causes reads of sensitive
51233 + /proc/<pid> entries where the file descriptor was opened in a different
51234 + task than the one performing the read. Such attempts are logged.
51235 + This option also limits argv/env strings for suid/sgid binaries
51236 + to 512KB to prevent a complete exhaustion of the stack entropy provided
51237 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
51238 + binaries to prevent alternative mmap layouts from being abused.
51239 +
51240 + If you use PaX it is essential that you say Y here as it closes up
51241 + several holes that make full ASLR useless locally.
51242 +
51243 +config GRKERNSEC_BRUTE
51244 + bool "Deter exploit bruteforcing"
51245 + default y if GRKERNSEC_CONFIG_AUTO
51246 + help
51247 + If you say Y here, attempts to bruteforce exploits against forking
51248 + daemons such as apache or sshd, as well as against suid/sgid binaries
51249 + will be deterred. When a child of a forking daemon is killed by PaX
51250 + or crashes due to an illegal instruction or other suspicious signal,
51251 + the parent process will be delayed 30 seconds upon every subsequent
51252 + fork until the administrator is able to assess the situation and
51253 + restart the daemon.
51254 + In the suid/sgid case, the attempt is logged, the user has all their
51255 + processes terminated, and they are prevented from executing any further
51256 + processes for 15 minutes.
51257 + It is recommended that you also enable signal logging in the auditing
51258 + section so that logs are generated when a process triggers a suspicious
51259 + signal.
51260 + If the sysctl option is enabled, a sysctl option with name
51261 + "deter_bruteforce" is created.
51262 +
51263 +
51264 +config GRKERNSEC_MODHARDEN
51265 + bool "Harden module auto-loading"
51266 + default y if GRKERNSEC_CONFIG_AUTO
51267 + depends on MODULES
51268 + help
51269 + If you say Y here, module auto-loading in response to use of some
51270 + feature implemented by an unloaded module will be restricted to
51271 + root users. Enabling this option helps defend against attacks
51272 + by unprivileged users who abuse the auto-loading behavior to
51273 + cause a vulnerable module to load that is then exploited.
51274 +
51275 + If this option prevents a legitimate use of auto-loading for a
51276 + non-root user, the administrator can execute modprobe manually
51277 + with the exact name of the module mentioned in the alert log.
51278 + Alternatively, the administrator can add the module to the list
51279 + of modules loaded at boot by modifying init scripts.
51280 +
51281 + Modification of init scripts will most likely be needed on
51282 + Ubuntu servers with encrypted home directory support enabled,
51283 + as the first non-root user logging in will cause the ecb(aes),
51284 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
51285 +
51286 +config GRKERNSEC_HIDESYM
51287 + bool "Hide kernel symbols"
51288 + default y if GRKERNSEC_CONFIG_AUTO
51289 + select PAX_USERCOPY_SLABS
51290 + help
51291 + If you say Y here, getting information on loaded modules, and
51292 + displaying all kernel symbols through a syscall will be restricted
51293 + to users with CAP_SYS_MODULE. For software compatibility reasons,
51294 + /proc/kallsyms will be restricted to the root user. The RBAC
51295 + system can hide that entry even from root.
51296 +
51297 + This option also prevents leaking of kernel addresses through
51298 + several /proc entries.
51299 +
51300 + Note that this option is only effective provided the following
51301 + conditions are met:
51302 + 1) The kernel using grsecurity is not precompiled by some distribution
51303 + 2) You have also enabled GRKERNSEC_DMESG
51304 + 3) You are using the RBAC system and hiding other files such as your
51305 + kernel image and System.map. Alternatively, enabling this option
51306 + causes the permissions on /boot, /lib/modules, and the kernel
51307 + source directory to change at compile time to prevent
51308 + reading by non-root users.
51309 + If the above conditions are met, this option will aid in providing a
51310 + useful protection against local kernel exploitation of overflows
51311 + and arbitrary read/write vulnerabilities.
51312 +
51313 +config GRKERNSEC_KERN_LOCKOUT
51314 + bool "Active kernel exploit response"
51315 + default y if GRKERNSEC_CONFIG_AUTO
51316 + depends on X86 || ARM || PPC || SPARC
51317 + help
51318 + If you say Y here, when a PaX alert is triggered due to suspicious
51319 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
51320 + or an OOPS occurs due to bad memory accesses, instead of just
51321 + terminating the offending process (and potentially allowing
51322 + a subsequent exploit from the same user), we will take one of two
51323 + actions:
51324 + If the user was root, we will panic the system
51325 + If the user was non-root, we will log the attempt, terminate
51326 + all processes owned by the user, then prevent them from creating
51327 + any new processes until the system is restarted
51328 + This deters repeated kernel exploitation/bruteforcing attempts
51329 + and is useful for later forensics.
51330 +
51331 +endmenu
51332 +menu "Role Based Access Control Options"
51333 +depends on GRKERNSEC
51334 +
51335 +config GRKERNSEC_RBAC_DEBUG
51336 + bool
51337 +
51338 +config GRKERNSEC_NO_RBAC
51339 + bool "Disable RBAC system"
51340 + help
51341 + If you say Y here, the /dev/grsec device will be removed from the kernel,
51342 + preventing the RBAC system from being enabled. You should only say Y
51343 + here if you have no intention of using the RBAC system, so as to prevent
51344 + an attacker with root access from misusing the RBAC system to hide files
51345 + and processes when loadable module support and /dev/[k]mem have been
51346 + locked down.
51347 +
51348 +config GRKERNSEC_ACL_HIDEKERN
51349 + bool "Hide kernel processes"
51350 + help
51351 + If you say Y here, all kernel threads will be hidden to all
51352 + processes but those whose subject has the "view hidden processes"
51353 + flag.
51354 +
51355 +config GRKERNSEC_ACL_MAXTRIES
51356 + int "Maximum tries before password lockout"
51357 + default 3
51358 + help
51359 + This option enforces the maximum number of times a user can attempt
51360 + to authorize themselves with the grsecurity RBAC system before being
51361 + denied the ability to attempt authorization again for a specified time.
51362 + The lower the number, the harder it will be to brute-force a password.
51363 +
51364 +config GRKERNSEC_ACL_TIMEOUT
51365 + int "Time to wait after max password tries, in seconds"
51366 + default 30
51367 + help
51368 + This option specifies the time the user must wait after attempting to
51369 + authorize to the RBAC system with the maximum number of invalid
51370 + passwords. The higher the number, the harder it will be to brute-force
51371 + a password.
51372 +
51373 +endmenu
51374 +menu "Filesystem Protections"
51375 +depends on GRKERNSEC
51376 +
51377 +config GRKERNSEC_PROC
51378 + bool "Proc restrictions"
51379 + default y if GRKERNSEC_CONFIG_AUTO
51380 + help
51381 + If you say Y here, the permissions of the /proc filesystem
51382 + will be altered to enhance system security and privacy. You MUST
51383 + choose either a user only restriction or a user and group restriction.
51384 + Depending upon the option you choose, you can either restrict users to
51385 + see only the processes they themselves run, or choose a group that can
51386 + view all processes and files normally restricted to root if you choose
51387 + the "restrict to user only" option. NOTE: If you're running identd or
51388 + ntpd as a non-root user, you will have to run it as the group you
51389 + specify here.
51390 +
51391 +config GRKERNSEC_PROC_USER
51392 + bool "Restrict /proc to user only"
51393 + depends on GRKERNSEC_PROC
51394 + help
51395 + If you say Y here, non-root users will only be able to view their own
51396 + processes, and restricts them from viewing network-related information,
51397 + and viewing kernel symbol and module information.
51398 +
51399 +config GRKERNSEC_PROC_USERGROUP
51400 + bool "Allow special group"
51401 + default y if GRKERNSEC_CONFIG_AUTO
51402 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
51403 + help
51404 + If you say Y here, you will be able to select a group that will be
51405 + able to view all processes and network-related information. If you've
51406 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
51407 + remain hidden. This option is useful if you want to run identd as
51408 + a non-root user. The group you select may also be chosen at boot time
51409 + via "grsec_proc_gid=" on the kernel commandline.
51410 +
51411 +config GRKERNSEC_PROC_GID
51412 + int "GID for special group"
51413 + depends on GRKERNSEC_PROC_USERGROUP
51414 + default 1001
51415 +
51416 +config GRKERNSEC_PROC_ADD
51417 + bool "Additional restrictions"
51418 + default y if GRKERNSEC_CONFIG_AUTO
51419 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
51420 + help
51421 + If you say Y here, additional restrictions will be placed on
51422 + /proc that keep normal users from viewing device information and
51423 + slabinfo information that could be useful for exploits.
51424 +
51425 +config GRKERNSEC_LINK
51426 + bool "Linking restrictions"
51427 + default y if GRKERNSEC_CONFIG_AUTO
51428 + help
51429 + If you say Y here, /tmp race exploits will be prevented, since users
51430 + will no longer be able to follow symlinks owned by other users in
51431 + world-writable +t directories (e.g. /tmp), unless the owner of the
51432 + symlink is the owner of the directory. users will also not be
51433 + able to hardlink to files they do not own. If the sysctl option is
51434 + enabled, a sysctl option with name "linking_restrictions" is created.
51435 +
51436 +config GRKERNSEC_SYMLINKOWN
51437 + bool "Kernel-enforced SymlinksIfOwnerMatch"
51438 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51439 + help
51440 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
51441 + that prevents it from being used as a security feature. As Apache
51442 + verifies the symlink by performing a stat() against the target of
51443 + the symlink before it is followed, an attacker can setup a symlink
51444 + to point to a same-owned file, then replace the symlink with one
51445 + that targets another user's file just after Apache "validates" the
51446 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
51447 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
51448 + will be in place for the group you specify. If the sysctl option
51449 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
51450 + created.
51451 +
51452 +config GRKERNSEC_SYMLINKOWN_GID
51453 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
51454 + depends on GRKERNSEC_SYMLINKOWN
51455 + default 1006
51456 + help
51457 + Setting this GID determines what group kernel-enforced
51458 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
51459 + is enabled, a sysctl option with name "symlinkown_gid" is created.
51460 +
51461 +config GRKERNSEC_FIFO
51462 + bool "FIFO restrictions"
51463 + default y if GRKERNSEC_CONFIG_AUTO
51464 + help
51465 + If you say Y here, users will not be able to write to FIFOs they don't
51466 + own in world-writable +t directories (e.g. /tmp), unless the owner of
51467 + the FIFO is the same owner of the directory it's held in. If the sysctl
51468 + option is enabled, a sysctl option with name "fifo_restrictions" is
51469 + created.
51470 +
51471 +config GRKERNSEC_SYSFS_RESTRICT
51472 + bool "Sysfs/debugfs restriction"
51473 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51474 + depends on SYSFS
51475 + help
51476 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51477 + any filesystem normally mounted under it (e.g. debugfs) will be
51478 + mostly accessible only by root. These filesystems generally provide access
51479 + to hardware and debug information that isn't appropriate for unprivileged
51480 + users of the system. Sysfs and debugfs have also become a large source
51481 + of new vulnerabilities, ranging from infoleaks to local compromise.
51482 + There has been very little oversight with an eye toward security involved
51483 + in adding new exporters of information to these filesystems, so their
51484 + use is discouraged.
51485 + For reasons of compatibility, a few directories have been whitelisted
51486 + for access by non-root users:
51487 + /sys/fs/selinux
51488 + /sys/fs/fuse
51489 + /sys/devices/system/cpu
51490 +
51491 +config GRKERNSEC_ROFS
51492 + bool "Runtime read-only mount protection"
51493 + help
51494 + If you say Y here, a sysctl option with name "romount_protect" will
51495 + be created. By setting this option to 1 at runtime, filesystems
51496 + will be protected in the following ways:
51497 + * No new writable mounts will be allowed
51498 + * Existing read-only mounts won't be able to be remounted read/write
51499 + * Write operations will be denied on all block devices
51500 + This option acts independently of grsec_lock: once it is set to 1,
51501 + it cannot be turned off. Therefore, please be mindful of the resulting
51502 + behavior if this option is enabled in an init script on a read-only
51503 + filesystem. This feature is mainly intended for secure embedded systems.
51504 +
51505 +config GRKERNSEC_CHROOT
51506 + bool "Chroot jail restrictions"
51507 + default y if GRKERNSEC_CONFIG_AUTO
51508 + help
51509 + If you say Y here, you will be able to choose several options that will
51510 + make breaking out of a chrooted jail much more difficult. If you
51511 + encounter no software incompatibilities with the following options, it
51512 + is recommended that you enable each one.
51513 +
51514 +config GRKERNSEC_CHROOT_MOUNT
51515 + bool "Deny mounts"
51516 + default y if GRKERNSEC_CONFIG_AUTO
51517 + depends on GRKERNSEC_CHROOT
51518 + help
51519 + If you say Y here, processes inside a chroot will not be able to
51520 + mount or remount filesystems. If the sysctl option is enabled, a
51521 + sysctl option with name "chroot_deny_mount" is created.
51522 +
51523 +config GRKERNSEC_CHROOT_DOUBLE
51524 + bool "Deny double-chroots"
51525 + default y if GRKERNSEC_CONFIG_AUTO
51526 + depends on GRKERNSEC_CHROOT
51527 + help
51528 + If you say Y here, processes inside a chroot will not be able to chroot
51529 + again outside the chroot. This is a widely used method of breaking
51530 + out of a chroot jail and should not be allowed. If the sysctl
51531 + option is enabled, a sysctl option with name
51532 + "chroot_deny_chroot" is created.
51533 +
51534 +config GRKERNSEC_CHROOT_PIVOT
51535 + bool "Deny pivot_root in chroot"
51536 + default y if GRKERNSEC_CONFIG_AUTO
51537 + depends on GRKERNSEC_CHROOT
51538 + help
51539 + If you say Y here, processes inside a chroot will not be able to use
51540 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51541 + works similar to chroot in that it changes the root filesystem. This
51542 + function could be misused in a chrooted process to attempt to break out
51543 + of the chroot, and therefore should not be allowed. If the sysctl
51544 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51545 + created.
51546 +
51547 +config GRKERNSEC_CHROOT_CHDIR
51548 + bool "Enforce chdir(\"/\") on all chroots"
51549 + default y if GRKERNSEC_CONFIG_AUTO
51550 + depends on GRKERNSEC_CHROOT
51551 + help
51552 + If you say Y here, the current working directory of all newly-chrooted
51553 + applications will be set to the the root directory of the chroot.
51554 + The man page on chroot(2) states:
51555 + Note that this call does not change the current working
51556 + directory, so that `.' can be outside the tree rooted at
51557 + `/'. In particular, the super-user can escape from a
51558 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51559 +
51560 + It is recommended that you say Y here, since it's not known to break
51561 + any software. If the sysctl option is enabled, a sysctl option with
51562 + name "chroot_enforce_chdir" is created.
51563 +
51564 +config GRKERNSEC_CHROOT_CHMOD
51565 + bool "Deny (f)chmod +s"
51566 + default y if GRKERNSEC_CONFIG_AUTO
51567 + depends on GRKERNSEC_CHROOT
51568 + help
51569 + If you say Y here, processes inside a chroot will not be able to chmod
51570 + or fchmod files to make them have suid or sgid bits. This protects
51571 + against another published method of breaking a chroot. If the sysctl
51572 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51573 + created.
51574 +
51575 +config GRKERNSEC_CHROOT_FCHDIR
51576 + bool "Deny fchdir out of chroot"
51577 + default y if GRKERNSEC_CONFIG_AUTO
51578 + depends on GRKERNSEC_CHROOT
51579 + help
51580 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51581 + to a file descriptor of the chrooting process that points to a directory
51582 + outside the filesystem will be stopped. If the sysctl option
51583 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51584 +
51585 +config GRKERNSEC_CHROOT_MKNOD
51586 + bool "Deny mknod"
51587 + default y if GRKERNSEC_CONFIG_AUTO
51588 + depends on GRKERNSEC_CHROOT
51589 + help
51590 + If you say Y here, processes inside a chroot will not be allowed to
51591 + mknod. The problem with using mknod inside a chroot is that it
51592 + would allow an attacker to create a device entry that is the same
51593 + as one on the physical root of your system, which could range from
51594 + anything from the console device to a device for your harddrive (which
51595 + they could then use to wipe the drive or steal data). It is recommended
51596 + that you say Y here, unless you run into software incompatibilities.
51597 + If the sysctl option is enabled, a sysctl option with name
51598 + "chroot_deny_mknod" is created.
51599 +
51600 +config GRKERNSEC_CHROOT_SHMAT
51601 + bool "Deny shmat() out of chroot"
51602 + default y if GRKERNSEC_CONFIG_AUTO
51603 + depends on GRKERNSEC_CHROOT
51604 + help
51605 + If you say Y here, processes inside a chroot will not be able to attach
51606 + to shared memory segments that were created outside of the chroot jail.
51607 + It is recommended that you say Y here. If the sysctl option is enabled,
51608 + a sysctl option with name "chroot_deny_shmat" is created.
51609 +
51610 +config GRKERNSEC_CHROOT_UNIX
51611 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51612 + default y if GRKERNSEC_CONFIG_AUTO
51613 + depends on GRKERNSEC_CHROOT
51614 + help
51615 + If you say Y here, processes inside a chroot will not be able to
51616 + connect to abstract (meaning not belonging to a filesystem) Unix
51617 + domain sockets that were bound outside of a chroot. It is recommended
51618 + that you say Y here. If the sysctl option is enabled, a sysctl option
51619 + with name "chroot_deny_unix" is created.
51620 +
51621 +config GRKERNSEC_CHROOT_FINDTASK
51622 + bool "Protect outside processes"
51623 + default y if GRKERNSEC_CONFIG_AUTO
51624 + depends on GRKERNSEC_CHROOT
51625 + help
51626 + If you say Y here, processes inside a chroot will not be able to
51627 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51628 + getsid, or view any process outside of the chroot. If the sysctl
51629 + option is enabled, a sysctl option with name "chroot_findtask" is
51630 + created.
51631 +
51632 +config GRKERNSEC_CHROOT_NICE
51633 + bool "Restrict priority changes"
51634 + default y if GRKERNSEC_CONFIG_AUTO
51635 + depends on GRKERNSEC_CHROOT
51636 + help
51637 + If you say Y here, processes inside a chroot will not be able to raise
51638 + the priority of processes in the chroot, or alter the priority of
51639 + processes outside the chroot. This provides more security than simply
51640 + removing CAP_SYS_NICE from the process' capability set. If the
51641 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51642 + is created.
51643 +
51644 +config GRKERNSEC_CHROOT_SYSCTL
51645 + bool "Deny sysctl writes"
51646 + default y if GRKERNSEC_CONFIG_AUTO
51647 + depends on GRKERNSEC_CHROOT
51648 + help
51649 + If you say Y here, an attacker in a chroot will not be able to
51650 + write to sysctl entries, either by sysctl(2) or through a /proc
51651 + interface. It is strongly recommended that you say Y here. If the
51652 + sysctl option is enabled, a sysctl option with name
51653 + "chroot_deny_sysctl" is created.
51654 +
51655 +config GRKERNSEC_CHROOT_CAPS
51656 + bool "Capability restrictions"
51657 + default y if GRKERNSEC_CONFIG_AUTO
51658 + depends on GRKERNSEC_CHROOT
51659 + help
51660 + If you say Y here, the capabilities on all processes within a
51661 + chroot jail will be lowered to stop module insertion, raw i/o,
51662 + system and net admin tasks, rebooting the system, modifying immutable
51663 + files, modifying IPC owned by another, and changing the system time.
51664 + This is left an option because it can break some apps. Disable this
51665 + if your chrooted apps are having problems performing those kinds of
51666 + tasks. If the sysctl option is enabled, a sysctl option with
51667 + name "chroot_caps" is created.
51668 +
51669 +endmenu
51670 +menu "Kernel Auditing"
51671 +depends on GRKERNSEC
51672 +
51673 +config GRKERNSEC_AUDIT_GROUP
51674 + bool "Single group for auditing"
51675 + help
51676 + If you say Y here, the exec, chdir, and (un)mount logging features
51677 + will only operate on a group you specify. This option is recommended
51678 + if you only want to watch certain users instead of having a large
51679 + amount of logs from the entire system. If the sysctl option is enabled,
51680 + a sysctl option with name "audit_group" is created.
51681 +
51682 +config GRKERNSEC_AUDIT_GID
51683 + int "GID for auditing"
51684 + depends on GRKERNSEC_AUDIT_GROUP
51685 + default 1007
51686 +
51687 +config GRKERNSEC_EXECLOG
51688 + bool "Exec logging"
51689 + help
51690 + If you say Y here, all execve() calls will be logged (since the
51691 + other exec*() calls are frontends to execve(), all execution
51692 + will be logged). Useful for shell-servers that like to keep track
51693 + of their users. If the sysctl option is enabled, a sysctl option with
51694 + name "exec_logging" is created.
51695 + WARNING: This option when enabled will produce a LOT of logs, especially
51696 + on an active system.
51697 +
51698 +config GRKERNSEC_RESLOG
51699 + bool "Resource logging"
51700 + default y if GRKERNSEC_CONFIG_AUTO
51701 + help
51702 + If you say Y here, all attempts to overstep resource limits will
51703 + be logged with the resource name, the requested size, and the current
51704 + limit. It is highly recommended that you say Y here. If the sysctl
51705 + option is enabled, a sysctl option with name "resource_logging" is
51706 + created. If the RBAC system is enabled, the sysctl value is ignored.
51707 +
51708 +config GRKERNSEC_CHROOT_EXECLOG
51709 + bool "Log execs within chroot"
51710 + help
51711 + If you say Y here, all executions inside a chroot jail will be logged
51712 + to syslog. This can cause a large amount of logs if certain
51713 + applications (eg. djb's daemontools) are installed on the system, and
51714 + is therefore left as an option. If the sysctl option is enabled, a
51715 + sysctl option with name "chroot_execlog" is created.
51716 +
51717 +config GRKERNSEC_AUDIT_PTRACE
51718 + bool "Ptrace logging"
51719 + help
51720 + If you say Y here, all attempts to attach to a process via ptrace
51721 + will be logged. If the sysctl option is enabled, a sysctl option
51722 + with name "audit_ptrace" is created.
51723 +
51724 +config GRKERNSEC_AUDIT_CHDIR
51725 + bool "Chdir logging"
51726 + help
51727 + If you say Y here, all chdir() calls will be logged. If the sysctl
51728 + option is enabled, a sysctl option with name "audit_chdir" is created.
51729 +
51730 +config GRKERNSEC_AUDIT_MOUNT
51731 + bool "(Un)Mount logging"
51732 + help
51733 + If you say Y here, all mounts and unmounts will be logged. If the
51734 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51735 + created.
51736 +
51737 +config GRKERNSEC_SIGNAL
51738 + bool "Signal logging"
51739 + default y if GRKERNSEC_CONFIG_AUTO
51740 + help
51741 + If you say Y here, certain important signals will be logged, such as
51742 + SIGSEGV, which will as a result inform you of when a error in a program
51743 + occurred, which in some cases could mean a possible exploit attempt.
51744 + If the sysctl option is enabled, a sysctl option with name
51745 + "signal_logging" is created.
51746 +
51747 +config GRKERNSEC_FORKFAIL
51748 + bool "Fork failure logging"
51749 + help
51750 + If you say Y here, all failed fork() attempts will be logged.
51751 + This could suggest a fork bomb, or someone attempting to overstep
51752 + their process limit. If the sysctl option is enabled, a sysctl option
51753 + with name "forkfail_logging" is created.
51754 +
51755 +config GRKERNSEC_TIME
51756 + bool "Time change logging"
51757 + default y if GRKERNSEC_CONFIG_AUTO
51758 + help
51759 + If you say Y here, any changes of the system clock will be logged.
51760 + If the sysctl option is enabled, a sysctl option with name
51761 + "timechange_logging" is created.
51762 +
51763 +config GRKERNSEC_PROC_IPADDR
51764 + bool "/proc/<pid>/ipaddr support"
51765 + default y if GRKERNSEC_CONFIG_AUTO
51766 + help
51767 + If you say Y here, a new entry will be added to each /proc/<pid>
51768 + directory that contains the IP address of the person using the task.
51769 + The IP is carried across local TCP and AF_UNIX stream sockets.
51770 + This information can be useful for IDS/IPSes to perform remote response
51771 + to a local attack. The entry is readable by only the owner of the
51772 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51773 + the RBAC system), and thus does not create privacy concerns.
51774 +
51775 +config GRKERNSEC_RWXMAP_LOG
51776 + bool 'Denied RWX mmap/mprotect logging'
51777 + default y if GRKERNSEC_CONFIG_AUTO
51778 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51779 + help
51780 + If you say Y here, calls to mmap() and mprotect() with explicit
51781 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51782 + denied by the PAX_MPROTECT feature. If the sysctl option is
51783 + enabled, a sysctl option with name "rwxmap_logging" is created.
51784 +
51785 +config GRKERNSEC_AUDIT_TEXTREL
51786 + bool 'ELF text relocations logging (READ HELP)'
51787 + depends on PAX_MPROTECT
51788 + help
51789 + If you say Y here, text relocations will be logged with the filename
51790 + of the offending library or binary. The purpose of the feature is
51791 + to help Linux distribution developers get rid of libraries and
51792 + binaries that need text relocations which hinder the future progress
51793 + of PaX. Only Linux distribution developers should say Y here, and
51794 + never on a production machine, as this option creates an information
51795 + leak that could aid an attacker in defeating the randomization of
51796 + a single memory region. If the sysctl option is enabled, a sysctl
51797 + option with name "audit_textrel" is created.
51798 +
51799 +endmenu
51800 +
51801 +menu "Executable Protections"
51802 +depends on GRKERNSEC
51803 +
51804 +config GRKERNSEC_DMESG
51805 + bool "Dmesg(8) restriction"
51806 + default y if GRKERNSEC_CONFIG_AUTO
51807 + help
51808 + If you say Y here, non-root users will not be able to use dmesg(8)
51809 + to view up to the last 4kb of messages in the kernel's log buffer.
51810 + The kernel's log buffer often contains kernel addresses and other
51811 + identifying information useful to an attacker in fingerprinting a
51812 + system for a targeted exploit.
51813 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51814 + created.
51815 +
51816 +config GRKERNSEC_HARDEN_PTRACE
51817 + bool "Deter ptrace-based process snooping"
51818 + default y if GRKERNSEC_CONFIG_AUTO
51819 + help
51820 + If you say Y here, TTY sniffers and other malicious monitoring
51821 + programs implemented through ptrace will be defeated. If you
51822 + have been using the RBAC system, this option has already been
51823 + enabled for several years for all users, with the ability to make
51824 + fine-grained exceptions.
51825 +
51826 + This option only affects the ability of non-root users to ptrace
51827 + processes that are not a descendent of the ptracing process.
51828 + This means that strace ./binary and gdb ./binary will still work,
51829 + but attaching to arbitrary processes will not. If the sysctl
51830 + option is enabled, a sysctl option with name "harden_ptrace" is
51831 + created.
51832 +
51833 +config GRKERNSEC_PTRACE_READEXEC
51834 + bool "Require read access to ptrace sensitive binaries"
51835 + default y if GRKERNSEC_CONFIG_AUTO
51836 + help
51837 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51838 + binaries. This option is useful in environments that
51839 + remove the read bits (e.g. file mode 4711) from suid binaries to
51840 + prevent infoleaking of their contents. This option adds
51841 + consistency to the use of that file mode, as the binary could normally
51842 + be read out when run without privileges while ptracing.
51843 +
51844 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51845 + is created.
51846 +
51847 +config GRKERNSEC_SETXID
51848 + bool "Enforce consistent multithreaded privileges"
51849 + default y if GRKERNSEC_CONFIG_AUTO
51850 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51851 + help
51852 + If you say Y here, a change from a root uid to a non-root uid
51853 + in a multithreaded application will cause the resulting uids,
51854 + gids, supplementary groups, and capabilities in that thread
51855 + to be propagated to the other threads of the process. In most
51856 + cases this is unnecessary, as glibc will emulate this behavior
51857 + on behalf of the application. Other libcs do not act in the
51858 + same way, allowing the other threads of the process to continue
51859 + running with root privileges. If the sysctl option is enabled,
51860 + a sysctl option with name "consistent_setxid" is created.
51861 +
51862 +config GRKERNSEC_TPE
51863 + bool "Trusted Path Execution (TPE)"
51864 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51865 + help
51866 + If you say Y here, you will be able to choose a gid to add to the
51867 + supplementary groups of users you want to mark as "untrusted."
51868 + These users will not be able to execute any files that are not in
51869 + root-owned directories writable only by root. If the sysctl option
51870 + is enabled, a sysctl option with name "tpe" is created.
51871 +
51872 +config GRKERNSEC_TPE_ALL
51873 + bool "Partially restrict all non-root users"
51874 + depends on GRKERNSEC_TPE
51875 + help
51876 + If you say Y here, all non-root users will be covered under
51877 + a weaker TPE restriction. This is separate from, and in addition to,
51878 + the main TPE options that you have selected elsewhere. Thus, if a
51879 + "trusted" GID is chosen, this restriction applies to even that GID.
51880 + Under this restriction, all non-root users will only be allowed to
51881 + execute files in directories they own that are not group or
51882 + world-writable, or in directories owned by root and writable only by
51883 + root. If the sysctl option is enabled, a sysctl option with name
51884 + "tpe_restrict_all" is created.
51885 +
51886 +config GRKERNSEC_TPE_INVERT
51887 + bool "Invert GID option"
51888 + depends on GRKERNSEC_TPE
51889 + help
51890 + If you say Y here, the group you specify in the TPE configuration will
51891 + decide what group TPE restrictions will be *disabled* for. This
51892 + option is useful if you want TPE restrictions to be applied to most
51893 + users on the system. If the sysctl option is enabled, a sysctl option
51894 + with name "tpe_invert" is created. Unlike other sysctl options, this
51895 + entry will default to on for backward-compatibility.
51896 +
51897 +config GRKERNSEC_TPE_GID
51898 + int
51899 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51900 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51901 +
51902 +config GRKERNSEC_TPE_UNTRUSTED_GID
51903 + int "GID for TPE-untrusted users"
51904 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51905 + default 1005
51906 + help
51907 + Setting this GID determines what group TPE restrictions will be
51908 + *enabled* for. If the sysctl option is enabled, a sysctl option
51909 + with name "tpe_gid" is created.
51910 +
51911 +config GRKERNSEC_TPE_TRUSTED_GID
51912 + int "GID for TPE-trusted users"
51913 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51914 + default 1005
51915 + help
51916 + Setting this GID determines what group TPE restrictions will be
51917 + *disabled* for. If the sysctl option is enabled, a sysctl option
51918 + with name "tpe_gid" is created.
51919 +
51920 +endmenu
51921 +menu "Network Protections"
51922 +depends on GRKERNSEC
51923 +
51924 +config GRKERNSEC_RANDNET
51925 + bool "Larger entropy pools"
51926 + default y if GRKERNSEC_CONFIG_AUTO
51927 + help
51928 + If you say Y here, the entropy pools used for many features of Linux
51929 + and grsecurity will be doubled in size. Since several grsecurity
51930 + features use additional randomness, it is recommended that you say Y
51931 + here. Saying Y here has a similar effect as modifying
51932 + /proc/sys/kernel/random/poolsize.
51933 +
51934 +config GRKERNSEC_BLACKHOLE
51935 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51936 + default y if GRKERNSEC_CONFIG_AUTO
51937 + depends on NET
51938 + help
51939 + If you say Y here, neither TCP resets nor ICMP
51940 + destination-unreachable packets will be sent in response to packets
51941 + sent to ports for which no associated listening process exists.
51942 + This feature supports both IPV4 and IPV6 and exempts the
51943 + loopback interface from blackholing. Enabling this feature
51944 + makes a host more resilient to DoS attacks and reduces network
51945 + visibility against scanners.
51946 +
51947 + The blackhole feature as-implemented is equivalent to the FreeBSD
51948 + blackhole feature, as it prevents RST responses to all packets, not
51949 + just SYNs. Under most application behavior this causes no
51950 + problems, but applications (like haproxy) may not close certain
51951 + connections in a way that cleanly terminates them on the remote
51952 + end, leaving the remote host in LAST_ACK state. Because of this
51953 + side-effect and to prevent intentional LAST_ACK DoSes, this
51954 + feature also adds automatic mitigation against such attacks.
51955 + The mitigation drastically reduces the amount of time a socket
51956 + can spend in LAST_ACK state. If you're using haproxy and not
51957 + all servers it connects to have this option enabled, consider
51958 + disabling this feature on the haproxy host.
51959 +
51960 + If the sysctl option is enabled, two sysctl options with names
51961 + "ip_blackhole" and "lastack_retries" will be created.
51962 + While "ip_blackhole" takes the standard zero/non-zero on/off
51963 + toggle, "lastack_retries" uses the same kinds of values as
51964 + "tcp_retries1" and "tcp_retries2". The default value of 4
51965 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51966 + state.
51967 +
51968 +config GRKERNSEC_SOCKET
51969 + bool "Socket restrictions"
51970 + depends on NET
51971 + help
51972 + If you say Y here, you will be able to choose from several options.
51973 + If you assign a GID on your system and add it to the supplementary
51974 + groups of users you want to restrict socket access to, this patch
51975 + will perform up to three things, based on the option(s) you choose.
51976 +
51977 +config GRKERNSEC_SOCKET_ALL
51978 + bool "Deny any sockets to group"
51979 + depends on GRKERNSEC_SOCKET
51980 + help
51981 + If you say Y here, you will be able to choose a GID of whose users will
51982 + be unable to connect to other hosts from your machine or run server
51983 + applications from your machine. If the sysctl option is enabled, a
51984 + sysctl option with name "socket_all" is created.
51985 +
51986 +config GRKERNSEC_SOCKET_ALL_GID
51987 + int "GID to deny all sockets for"
51988 + depends on GRKERNSEC_SOCKET_ALL
51989 + default 1004
51990 + help
51991 + Here you can choose the GID to disable socket access for. Remember to
51992 + add the users you want socket access disabled for to the GID
51993 + specified here. If the sysctl option is enabled, a sysctl option
51994 + with name "socket_all_gid" is created.
51995 +
51996 +config GRKERNSEC_SOCKET_CLIENT
51997 + bool "Deny client sockets to group"
51998 + depends on GRKERNSEC_SOCKET
51999 + help
52000 + If you say Y here, you will be able to choose a GID of whose users will
52001 + be unable to connect to other hosts from your machine, but will be
52002 + able to run servers. If this option is enabled, all users in the group
52003 + you specify will have to use passive mode when initiating ftp transfers
52004 + from the shell on your machine. If the sysctl option is enabled, a
52005 + sysctl option with name "socket_client" is created.
52006 +
52007 +config GRKERNSEC_SOCKET_CLIENT_GID
52008 + int "GID to deny client sockets for"
52009 + depends on GRKERNSEC_SOCKET_CLIENT
52010 + default 1003
52011 + help
52012 + Here you can choose the GID to disable client socket access for.
52013 + Remember to add the users you want client socket access disabled for to
52014 + the GID specified here. If the sysctl option is enabled, a sysctl
52015 + option with name "socket_client_gid" is created.
52016 +
52017 +config GRKERNSEC_SOCKET_SERVER
52018 + bool "Deny server sockets to group"
52019 + depends on GRKERNSEC_SOCKET
52020 + help
52021 + If you say Y here, you will be able to choose a GID of whose users will
52022 + be unable to run server applications from your machine. If the sysctl
52023 + option is enabled, a sysctl option with name "socket_server" is created.
52024 +
52025 +config GRKERNSEC_SOCKET_SERVER_GID
52026 + int "GID to deny server sockets for"
52027 + depends on GRKERNSEC_SOCKET_SERVER
52028 + default 1002
52029 + help
52030 + Here you can choose the GID to disable server socket access for.
52031 + Remember to add the users you want server socket access disabled for to
52032 + the GID specified here. If the sysctl option is enabled, a sysctl
52033 + option with name "socket_server_gid" is created.
52034 +
52035 +endmenu
52036 +menu "Sysctl Support"
52037 +depends on GRKERNSEC && SYSCTL
52038 +
52039 +config GRKERNSEC_SYSCTL
52040 + bool "Sysctl support"
52041 + default y if GRKERNSEC_CONFIG_AUTO
52042 + help
52043 + If you say Y here, you will be able to change the options that
52044 + grsecurity runs with at bootup, without having to recompile your
52045 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
52046 + to enable (1) or disable (0) various features. All the sysctl entries
52047 + are mutable until the "grsec_lock" entry is set to a non-zero value.
52048 + All features enabled in the kernel configuration are disabled at boot
52049 + if you do not say Y to the "Turn on features by default" option.
52050 + All options should be set at startup, and the grsec_lock entry should
52051 + be set to a non-zero value after all the options are set.
52052 + *THIS IS EXTREMELY IMPORTANT*
52053 +
52054 +config GRKERNSEC_SYSCTL_DISTRO
52055 + bool "Extra sysctl support for distro makers (READ HELP)"
52056 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
52057 + help
52058 + If you say Y here, additional sysctl options will be created
52059 + for features that affect processes running as root. Therefore,
52060 + it is critical when using this option that the grsec_lock entry be
52061 + enabled after boot. Only distros with prebuilt kernel packages
52062 + with this option enabled that can ensure grsec_lock is enabled
52063 + after boot should use this option.
52064 + *Failure to set grsec_lock after boot makes all grsec features
52065 + this option covers useless*
52066 +
52067 + Currently this option creates the following sysctl entries:
52068 + "Disable Privileged I/O": "disable_priv_io"
52069 +
52070 +config GRKERNSEC_SYSCTL_ON
52071 + bool "Turn on features by default"
52072 + default y if GRKERNSEC_CONFIG_AUTO
52073 + depends on GRKERNSEC_SYSCTL
52074 + help
52075 + If you say Y here, instead of having all features enabled in the
52076 + kernel configuration disabled at boot time, the features will be
52077 + enabled at boot time. It is recommended you say Y here unless
52078 + there is some reason you would want all sysctl-tunable features to
52079 + be disabled by default. As mentioned elsewhere, it is important
52080 + to enable the grsec_lock entry once you have finished modifying
52081 + the sysctl entries.
52082 +
52083 +endmenu
52084 +menu "Logging Options"
52085 +depends on GRKERNSEC
52086 +
52087 +config GRKERNSEC_FLOODTIME
52088 + int "Seconds in between log messages (minimum)"
52089 + default 10
52090 + help
52091 + This option allows you to enforce the number of seconds between
52092 + grsecurity log messages. The default should be suitable for most
52093 + people, however, if you choose to change it, choose a value small enough
52094 + to allow informative logs to be produced, but large enough to
52095 + prevent flooding.
52096 +
52097 +config GRKERNSEC_FLOODBURST
52098 + int "Number of messages in a burst (maximum)"
52099 + default 6
52100 + help
52101 + This option allows you to choose the maximum number of messages allowed
52102 + within the flood time interval you chose in a separate option. The
52103 + default should be suitable for most people, however if you find that
52104 + many of your logs are being interpreted as flooding, you may want to
52105 + raise this value.
52106 +
52107 +endmenu
52108 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
52109 new file mode 100644
52110 index 0000000..1b9afa9
52111 --- /dev/null
52112 +++ b/grsecurity/Makefile
52113 @@ -0,0 +1,38 @@
52114 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
52115 +# during 2001-2009 it has been completely redesigned by Brad Spengler
52116 +# into an RBAC system
52117 +#
52118 +# All code in this directory and various hooks inserted throughout the kernel
52119 +# are copyright Brad Spengler - Open Source Security, Inc., and released
52120 +# under the GPL v2 or higher
52121 +
52122 +KBUILD_CFLAGS += -Werror
52123 +
52124 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
52125 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
52126 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
52127 +
52128 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
52129 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
52130 + gracl_learn.o grsec_log.o
52131 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
52132 +
52133 +ifdef CONFIG_NET
52134 +obj-y += grsec_sock.o
52135 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
52136 +endif
52137 +
52138 +ifndef CONFIG_GRKERNSEC
52139 +obj-y += grsec_disabled.o
52140 +endif
52141 +
52142 +ifdef CONFIG_GRKERNSEC_HIDESYM
52143 +extra-y := grsec_hidesym.o
52144 +$(obj)/grsec_hidesym.o:
52145 + @-chmod -f 500 /boot
52146 + @-chmod -f 500 /lib/modules
52147 + @-chmod -f 500 /lib64/modules
52148 + @-chmod -f 500 /lib32/modules
52149 + @-chmod -f 700 .
52150 + @echo ' grsec: protected kernel image paths'
52151 +endif
52152 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
52153 new file mode 100644
52154 index 0000000..4428c82
52155 --- /dev/null
52156 +++ b/grsecurity/gracl.c
52157 @@ -0,0 +1,4056 @@
52158 +#include <linux/kernel.h>
52159 +#include <linux/module.h>
52160 +#include <linux/sched.h>
52161 +#include <linux/mm.h>
52162 +#include <linux/file.h>
52163 +#include <linux/fs.h>
52164 +#include <linux/namei.h>
52165 +#include <linux/mount.h>
52166 +#include <linux/tty.h>
52167 +#include <linux/proc_fs.h>
52168 +#include <linux/lglock.h>
52169 +#include <linux/slab.h>
52170 +#include <linux/vmalloc.h>
52171 +#include <linux/types.h>
52172 +#include <linux/sysctl.h>
52173 +#include <linux/netdevice.h>
52174 +#include <linux/ptrace.h>
52175 +#include <linux/gracl.h>
52176 +#include <linux/gralloc.h>
52177 +#include <linux/security.h>
52178 +#include <linux/grinternal.h>
52179 +#include <linux/pid_namespace.h>
52180 +#include <linux/stop_machine.h>
52181 +#include <linux/fdtable.h>
52182 +#include <linux/percpu.h>
52183 +#include <linux/lglock.h>
52184 +#include "../fs/mount.h"
52185 +
52186 +#include <asm/uaccess.h>
52187 +#include <asm/errno.h>
52188 +#include <asm/mman.h>
52189 +
52190 +extern struct lglock vfsmount_lock;
52191 +
52192 +static struct acl_role_db acl_role_set;
52193 +static struct name_db name_set;
52194 +static struct inodev_db inodev_set;
52195 +
52196 +/* for keeping track of userspace pointers used for subjects, so we
52197 + can share references in the kernel as well
52198 +*/
52199 +
52200 +static struct path real_root;
52201 +
52202 +static struct acl_subj_map_db subj_map_set;
52203 +
52204 +static struct acl_role_label *default_role;
52205 +
52206 +static struct acl_role_label *role_list;
52207 +
52208 +static u16 acl_sp_role_value;
52209 +
52210 +extern char *gr_shared_page[4];
52211 +static DEFINE_MUTEX(gr_dev_mutex);
52212 +DEFINE_RWLOCK(gr_inode_lock);
52213 +
52214 +struct gr_arg *gr_usermode;
52215 +
52216 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
52217 +
52218 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
52219 +extern void gr_clear_learn_entries(void);
52220 +
52221 +#ifdef CONFIG_GRKERNSEC_RESLOG
52222 +extern void gr_log_resource(const struct task_struct *task,
52223 + const int res, const unsigned long wanted, const int gt);
52224 +#endif
52225 +
52226 +unsigned char *gr_system_salt;
52227 +unsigned char *gr_system_sum;
52228 +
52229 +static struct sprole_pw **acl_special_roles = NULL;
52230 +static __u16 num_sprole_pws = 0;
52231 +
52232 +static struct acl_role_label *kernel_role = NULL;
52233 +
52234 +static unsigned int gr_auth_attempts = 0;
52235 +static unsigned long gr_auth_expires = 0UL;
52236 +
52237 +#ifdef CONFIG_NET
52238 +extern struct vfsmount *sock_mnt;
52239 +#endif
52240 +
52241 +extern struct vfsmount *pipe_mnt;
52242 +extern struct vfsmount *shm_mnt;
52243 +#ifdef CONFIG_HUGETLBFS
52244 +extern struct vfsmount *hugetlbfs_vfsmount;
52245 +#endif
52246 +
52247 +static struct acl_object_label *fakefs_obj_rw;
52248 +static struct acl_object_label *fakefs_obj_rwx;
52249 +
52250 +extern int gr_init_uidset(void);
52251 +extern void gr_free_uidset(void);
52252 +extern void gr_remove_uid(uid_t uid);
52253 +extern int gr_find_uid(uid_t uid);
52254 +
52255 +__inline__ int
52256 +gr_acl_is_enabled(void)
52257 +{
52258 + return (gr_status & GR_READY);
52259 +}
52260 +
52261 +#ifdef CONFIG_BTRFS_FS
52262 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
52263 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
52264 +#endif
52265 +
52266 +static inline dev_t __get_dev(const struct dentry *dentry)
52267 +{
52268 +#ifdef CONFIG_BTRFS_FS
52269 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
52270 + return get_btrfs_dev_from_inode(dentry->d_inode);
52271 + else
52272 +#endif
52273 + return dentry->d_inode->i_sb->s_dev;
52274 +}
52275 +
52276 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
52277 +{
52278 + return __get_dev(dentry);
52279 +}
52280 +
52281 +static char gr_task_roletype_to_char(struct task_struct *task)
52282 +{
52283 + switch (task->role->roletype &
52284 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
52285 + GR_ROLE_SPECIAL)) {
52286 + case GR_ROLE_DEFAULT:
52287 + return 'D';
52288 + case GR_ROLE_USER:
52289 + return 'U';
52290 + case GR_ROLE_GROUP:
52291 + return 'G';
52292 + case GR_ROLE_SPECIAL:
52293 + return 'S';
52294 + }
52295 +
52296 + return 'X';
52297 +}
52298 +
52299 +char gr_roletype_to_char(void)
52300 +{
52301 + return gr_task_roletype_to_char(current);
52302 +}
52303 +
52304 +__inline__ int
52305 +gr_acl_tpe_check(void)
52306 +{
52307 + if (unlikely(!(gr_status & GR_READY)))
52308 + return 0;
52309 + if (current->role->roletype & GR_ROLE_TPE)
52310 + return 1;
52311 + else
52312 + return 0;
52313 +}
52314 +
52315 +int
52316 +gr_handle_rawio(const struct inode *inode)
52317 +{
52318 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
52319 + if (inode && S_ISBLK(inode->i_mode) &&
52320 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
52321 + !capable(CAP_SYS_RAWIO))
52322 + return 1;
52323 +#endif
52324 + return 0;
52325 +}
52326 +
52327 +static int
52328 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
52329 +{
52330 + if (likely(lena != lenb))
52331 + return 0;
52332 +
52333 + return !memcmp(a, b, lena);
52334 +}
52335 +
52336 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
52337 +{
52338 + *buflen -= namelen;
52339 + if (*buflen < 0)
52340 + return -ENAMETOOLONG;
52341 + *buffer -= namelen;
52342 + memcpy(*buffer, str, namelen);
52343 + return 0;
52344 +}
52345 +
52346 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
52347 +{
52348 + return prepend(buffer, buflen, name->name, name->len);
52349 +}
52350 +
52351 +static int prepend_path(const struct path *path, struct path *root,
52352 + char **buffer, int *buflen)
52353 +{
52354 + struct dentry *dentry = path->dentry;
52355 + struct vfsmount *vfsmnt = path->mnt;
52356 + struct mount *mnt = real_mount(vfsmnt);
52357 + bool slash = false;
52358 + int error = 0;
52359 +
52360 + while (dentry != root->dentry || vfsmnt != root->mnt) {
52361 + struct dentry * parent;
52362 +
52363 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
52364 + /* Global root? */
52365 + if (!mnt_has_parent(mnt)) {
52366 + goto out;
52367 + }
52368 + dentry = mnt->mnt_mountpoint;
52369 + mnt = mnt->mnt_parent;
52370 + vfsmnt = &mnt->mnt;
52371 + continue;
52372 + }
52373 + parent = dentry->d_parent;
52374 + prefetch(parent);
52375 + spin_lock(&dentry->d_lock);
52376 + error = prepend_name(buffer, buflen, &dentry->d_name);
52377 + spin_unlock(&dentry->d_lock);
52378 + if (!error)
52379 + error = prepend(buffer, buflen, "/", 1);
52380 + if (error)
52381 + break;
52382 +
52383 + slash = true;
52384 + dentry = parent;
52385 + }
52386 +
52387 +out:
52388 + if (!error && !slash)
52389 + error = prepend(buffer, buflen, "/", 1);
52390 +
52391 + return error;
52392 +}
52393 +
52394 +/* this must be called with vfsmount_lock and rename_lock held */
52395 +
52396 +static char *__our_d_path(const struct path *path, struct path *root,
52397 + char *buf, int buflen)
52398 +{
52399 + char *res = buf + buflen;
52400 + int error;
52401 +
52402 + prepend(&res, &buflen, "\0", 1);
52403 + error = prepend_path(path, root, &res, &buflen);
52404 + if (error)
52405 + return ERR_PTR(error);
52406 +
52407 + return res;
52408 +}
52409 +
52410 +static char *
52411 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
52412 +{
52413 + char *retval;
52414 +
52415 + retval = __our_d_path(path, root, buf, buflen);
52416 + if (unlikely(IS_ERR(retval)))
52417 + retval = strcpy(buf, "<path too long>");
52418 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
52419 + retval[1] = '\0';
52420 +
52421 + return retval;
52422 +}
52423 +
52424 +static char *
52425 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52426 + char *buf, int buflen)
52427 +{
52428 + struct path path;
52429 + char *res;
52430 +
52431 + path.dentry = (struct dentry *)dentry;
52432 + path.mnt = (struct vfsmount *)vfsmnt;
52433 +
52434 + /* we can use real_root.dentry, real_root.mnt, because this is only called
52435 + by the RBAC system */
52436 + res = gen_full_path(&path, &real_root, buf, buflen);
52437 +
52438 + return res;
52439 +}
52440 +
52441 +static char *
52442 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52443 + char *buf, int buflen)
52444 +{
52445 + char *res;
52446 + struct path path;
52447 + struct path root;
52448 + struct task_struct *reaper = init_pid_ns.child_reaper;
52449 +
52450 + path.dentry = (struct dentry *)dentry;
52451 + path.mnt = (struct vfsmount *)vfsmnt;
52452 +
52453 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
52454 + get_fs_root(reaper->fs, &root);
52455 +
52456 + write_seqlock(&rename_lock);
52457 + br_read_lock(&vfsmount_lock);
52458 + res = gen_full_path(&path, &root, buf, buflen);
52459 + br_read_unlock(&vfsmount_lock);
52460 + write_sequnlock(&rename_lock);
52461 +
52462 + path_put(&root);
52463 + return res;
52464 +}
52465 +
52466 +static char *
52467 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52468 +{
52469 + char *ret;
52470 + write_seqlock(&rename_lock);
52471 + br_read_lock(&vfsmount_lock);
52472 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52473 + PAGE_SIZE);
52474 + br_read_unlock(&vfsmount_lock);
52475 + write_sequnlock(&rename_lock);
52476 + return ret;
52477 +}
52478 +
52479 +static char *
52480 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52481 +{
52482 + char *ret;
52483 + char *buf;
52484 + int buflen;
52485 +
52486 + write_seqlock(&rename_lock);
52487 + br_read_lock(&vfsmount_lock);
52488 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52489 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52490 + buflen = (int)(ret - buf);
52491 + if (buflen >= 5)
52492 + prepend(&ret, &buflen, "/proc", 5);
52493 + else
52494 + ret = strcpy(buf, "<path too long>");
52495 + br_read_unlock(&vfsmount_lock);
52496 + write_sequnlock(&rename_lock);
52497 + return ret;
52498 +}
52499 +
52500 +char *
52501 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52502 +{
52503 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52504 + PAGE_SIZE);
52505 +}
52506 +
52507 +char *
52508 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52509 +{
52510 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52511 + PAGE_SIZE);
52512 +}
52513 +
52514 +char *
52515 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52516 +{
52517 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52518 + PAGE_SIZE);
52519 +}
52520 +
52521 +char *
52522 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52523 +{
52524 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52525 + PAGE_SIZE);
52526 +}
52527 +
52528 +char *
52529 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52530 +{
52531 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52532 + PAGE_SIZE);
52533 +}
52534 +
52535 +__inline__ __u32
52536 +to_gr_audit(const __u32 reqmode)
52537 +{
52538 + /* masks off auditable permission flags, then shifts them to create
52539 + auditing flags, and adds the special case of append auditing if
52540 + we're requesting write */
52541 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52542 +}
52543 +
52544 +struct acl_subject_label *
52545 +lookup_subject_map(const struct acl_subject_label *userp)
52546 +{
52547 + unsigned int index = shash(userp, subj_map_set.s_size);
52548 + struct subject_map *match;
52549 +
52550 + match = subj_map_set.s_hash[index];
52551 +
52552 + while (match && match->user != userp)
52553 + match = match->next;
52554 +
52555 + if (match != NULL)
52556 + return match->kernel;
52557 + else
52558 + return NULL;
52559 +}
52560 +
52561 +static void
52562 +insert_subj_map_entry(struct subject_map *subjmap)
52563 +{
52564 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52565 + struct subject_map **curr;
52566 +
52567 + subjmap->prev = NULL;
52568 +
52569 + curr = &subj_map_set.s_hash[index];
52570 + if (*curr != NULL)
52571 + (*curr)->prev = subjmap;
52572 +
52573 + subjmap->next = *curr;
52574 + *curr = subjmap;
52575 +
52576 + return;
52577 +}
52578 +
52579 +static struct acl_role_label *
52580 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52581 + const gid_t gid)
52582 +{
52583 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52584 + struct acl_role_label *match;
52585 + struct role_allowed_ip *ipp;
52586 + unsigned int x;
52587 + u32 curr_ip = task->signal->curr_ip;
52588 +
52589 + task->signal->saved_ip = curr_ip;
52590 +
52591 + match = acl_role_set.r_hash[index];
52592 +
52593 + while (match) {
52594 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52595 + for (x = 0; x < match->domain_child_num; x++) {
52596 + if (match->domain_children[x] == uid)
52597 + goto found;
52598 + }
52599 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52600 + break;
52601 + match = match->next;
52602 + }
52603 +found:
52604 + if (match == NULL) {
52605 + try_group:
52606 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52607 + match = acl_role_set.r_hash[index];
52608 +
52609 + while (match) {
52610 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52611 + for (x = 0; x < match->domain_child_num; x++) {
52612 + if (match->domain_children[x] == gid)
52613 + goto found2;
52614 + }
52615 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52616 + break;
52617 + match = match->next;
52618 + }
52619 +found2:
52620 + if (match == NULL)
52621 + match = default_role;
52622 + if (match->allowed_ips == NULL)
52623 + return match;
52624 + else {
52625 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52626 + if (likely
52627 + ((ntohl(curr_ip) & ipp->netmask) ==
52628 + (ntohl(ipp->addr) & ipp->netmask)))
52629 + return match;
52630 + }
52631 + match = default_role;
52632 + }
52633 + } else if (match->allowed_ips == NULL) {
52634 + return match;
52635 + } else {
52636 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52637 + if (likely
52638 + ((ntohl(curr_ip) & ipp->netmask) ==
52639 + (ntohl(ipp->addr) & ipp->netmask)))
52640 + return match;
52641 + }
52642 + goto try_group;
52643 + }
52644 +
52645 + return match;
52646 +}
52647 +
52648 +struct acl_subject_label *
52649 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52650 + const struct acl_role_label *role)
52651 +{
52652 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52653 + struct acl_subject_label *match;
52654 +
52655 + match = role->subj_hash[index];
52656 +
52657 + while (match && (match->inode != ino || match->device != dev ||
52658 + (match->mode & GR_DELETED))) {
52659 + match = match->next;
52660 + }
52661 +
52662 + if (match && !(match->mode & GR_DELETED))
52663 + return match;
52664 + else
52665 + return NULL;
52666 +}
52667 +
52668 +struct acl_subject_label *
52669 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52670 + const struct acl_role_label *role)
52671 +{
52672 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52673 + struct acl_subject_label *match;
52674 +
52675 + match = role->subj_hash[index];
52676 +
52677 + while (match && (match->inode != ino || match->device != dev ||
52678 + !(match->mode & GR_DELETED))) {
52679 + match = match->next;
52680 + }
52681 +
52682 + if (match && (match->mode & GR_DELETED))
52683 + return match;
52684 + else
52685 + return NULL;
52686 +}
52687 +
52688 +static struct acl_object_label *
52689 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52690 + const struct acl_subject_label *subj)
52691 +{
52692 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52693 + struct acl_object_label *match;
52694 +
52695 + match = subj->obj_hash[index];
52696 +
52697 + while (match && (match->inode != ino || match->device != dev ||
52698 + (match->mode & GR_DELETED))) {
52699 + match = match->next;
52700 + }
52701 +
52702 + if (match && !(match->mode & GR_DELETED))
52703 + return match;
52704 + else
52705 + return NULL;
52706 +}
52707 +
52708 +static struct acl_object_label *
52709 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52710 + const struct acl_subject_label *subj)
52711 +{
52712 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52713 + struct acl_object_label *match;
52714 +
52715 + match = subj->obj_hash[index];
52716 +
52717 + while (match && (match->inode != ino || match->device != dev ||
52718 + !(match->mode & GR_DELETED))) {
52719 + match = match->next;
52720 + }
52721 +
52722 + if (match && (match->mode & GR_DELETED))
52723 + return match;
52724 +
52725 + match = subj->obj_hash[index];
52726 +
52727 + while (match && (match->inode != ino || match->device != dev ||
52728 + (match->mode & GR_DELETED))) {
52729 + match = match->next;
52730 + }
52731 +
52732 + if (match && !(match->mode & GR_DELETED))
52733 + return match;
52734 + else
52735 + return NULL;
52736 +}
52737 +
52738 +static struct name_entry *
52739 +lookup_name_entry(const char *name)
52740 +{
52741 + unsigned int len = strlen(name);
52742 + unsigned int key = full_name_hash(name, len);
52743 + unsigned int index = key % name_set.n_size;
52744 + struct name_entry *match;
52745 +
52746 + match = name_set.n_hash[index];
52747 +
52748 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52749 + match = match->next;
52750 +
52751 + return match;
52752 +}
52753 +
52754 +static struct name_entry *
52755 +lookup_name_entry_create(const char *name)
52756 +{
52757 + unsigned int len = strlen(name);
52758 + unsigned int key = full_name_hash(name, len);
52759 + unsigned int index = key % name_set.n_size;
52760 + struct name_entry *match;
52761 +
52762 + match = name_set.n_hash[index];
52763 +
52764 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52765 + !match->deleted))
52766 + match = match->next;
52767 +
52768 + if (match && match->deleted)
52769 + return match;
52770 +
52771 + match = name_set.n_hash[index];
52772 +
52773 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52774 + match->deleted))
52775 + match = match->next;
52776 +
52777 + if (match && !match->deleted)
52778 + return match;
52779 + else
52780 + return NULL;
52781 +}
52782 +
52783 +static struct inodev_entry *
52784 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52785 +{
52786 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52787 + struct inodev_entry *match;
52788 +
52789 + match = inodev_set.i_hash[index];
52790 +
52791 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52792 + match = match->next;
52793 +
52794 + return match;
52795 +}
52796 +
52797 +static void
52798 +insert_inodev_entry(struct inodev_entry *entry)
52799 +{
52800 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52801 + inodev_set.i_size);
52802 + struct inodev_entry **curr;
52803 +
52804 + entry->prev = NULL;
52805 +
52806 + curr = &inodev_set.i_hash[index];
52807 + if (*curr != NULL)
52808 + (*curr)->prev = entry;
52809 +
52810 + entry->next = *curr;
52811 + *curr = entry;
52812 +
52813 + return;
52814 +}
52815 +
52816 +static void
52817 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52818 +{
52819 + unsigned int index =
52820 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52821 + struct acl_role_label **curr;
52822 + struct acl_role_label *tmp, *tmp2;
52823 +
52824 + curr = &acl_role_set.r_hash[index];
52825 +
52826 + /* simple case, slot is empty, just set it to our role */
52827 + if (*curr == NULL) {
52828 + *curr = role;
52829 + } else {
52830 + /* example:
52831 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52832 + 2 -> 3
52833 + */
52834 + /* first check to see if we can already be reached via this slot */
52835 + tmp = *curr;
52836 + while (tmp && tmp != role)
52837 + tmp = tmp->next;
52838 + if (tmp == role) {
52839 + /* we don't need to add ourselves to this slot's chain */
52840 + return;
52841 + }
52842 + /* we need to add ourselves to this chain, two cases */
52843 + if (role->next == NULL) {
52844 + /* simple case, append the current chain to our role */
52845 + role->next = *curr;
52846 + *curr = role;
52847 + } else {
52848 + /* 1 -> 2 -> 3 -> 4
52849 + 2 -> 3 -> 4
52850 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52851 + */
52852 + /* trickier case: walk our role's chain until we find
52853 + the role for the start of the current slot's chain */
52854 + tmp = role;
52855 + tmp2 = *curr;
52856 + while (tmp->next && tmp->next != tmp2)
52857 + tmp = tmp->next;
52858 + if (tmp->next == tmp2) {
52859 + /* from example above, we found 3, so just
52860 + replace this slot's chain with ours */
52861 + *curr = role;
52862 + } else {
52863 + /* we didn't find a subset of our role's chain
52864 + in the current slot's chain, so append their
52865 + chain to ours, and set us as the first role in
52866 + the slot's chain
52867 +
52868 + we could fold this case with the case above,
52869 + but making it explicit for clarity
52870 + */
52871 + tmp->next = tmp2;
52872 + *curr = role;
52873 + }
52874 + }
52875 + }
52876 +
52877 + return;
52878 +}
52879 +
52880 +static void
52881 +insert_acl_role_label(struct acl_role_label *role)
52882 +{
52883 + int i;
52884 +
52885 + if (role_list == NULL) {
52886 + role_list = role;
52887 + role->prev = NULL;
52888 + } else {
52889 + role->prev = role_list;
52890 + role_list = role;
52891 + }
52892 +
52893 + /* used for hash chains */
52894 + role->next = NULL;
52895 +
52896 + if (role->roletype & GR_ROLE_DOMAIN) {
52897 + for (i = 0; i < role->domain_child_num; i++)
52898 + __insert_acl_role_label(role, role->domain_children[i]);
52899 + } else
52900 + __insert_acl_role_label(role, role->uidgid);
52901 +}
52902 +
52903 +static int
52904 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52905 +{
52906 + struct name_entry **curr, *nentry;
52907 + struct inodev_entry *ientry;
52908 + unsigned int len = strlen(name);
52909 + unsigned int key = full_name_hash(name, len);
52910 + unsigned int index = key % name_set.n_size;
52911 +
52912 + curr = &name_set.n_hash[index];
52913 +
52914 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52915 + curr = &((*curr)->next);
52916 +
52917 + if (*curr != NULL)
52918 + return 1;
52919 +
52920 + nentry = acl_alloc(sizeof (struct name_entry));
52921 + if (nentry == NULL)
52922 + return 0;
52923 + ientry = acl_alloc(sizeof (struct inodev_entry));
52924 + if (ientry == NULL)
52925 + return 0;
52926 + ientry->nentry = nentry;
52927 +
52928 + nentry->key = key;
52929 + nentry->name = name;
52930 + nentry->inode = inode;
52931 + nentry->device = device;
52932 + nentry->len = len;
52933 + nentry->deleted = deleted;
52934 +
52935 + nentry->prev = NULL;
52936 + curr = &name_set.n_hash[index];
52937 + if (*curr != NULL)
52938 + (*curr)->prev = nentry;
52939 + nentry->next = *curr;
52940 + *curr = nentry;
52941 +
52942 + /* insert us into the table searchable by inode/dev */
52943 + insert_inodev_entry(ientry);
52944 +
52945 + return 1;
52946 +}
52947 +
52948 +static void
52949 +insert_acl_obj_label(struct acl_object_label *obj,
52950 + struct acl_subject_label *subj)
52951 +{
52952 + unsigned int index =
52953 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52954 + struct acl_object_label **curr;
52955 +
52956 +
52957 + obj->prev = NULL;
52958 +
52959 + curr = &subj->obj_hash[index];
52960 + if (*curr != NULL)
52961 + (*curr)->prev = obj;
52962 +
52963 + obj->next = *curr;
52964 + *curr = obj;
52965 +
52966 + return;
52967 +}
52968 +
52969 +static void
52970 +insert_acl_subj_label(struct acl_subject_label *obj,
52971 + struct acl_role_label *role)
52972 +{
52973 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52974 + struct acl_subject_label **curr;
52975 +
52976 + obj->prev = NULL;
52977 +
52978 + curr = &role->subj_hash[index];
52979 + if (*curr != NULL)
52980 + (*curr)->prev = obj;
52981 +
52982 + obj->next = *curr;
52983 + *curr = obj;
52984 +
52985 + return;
52986 +}
52987 +
52988 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52989 +
52990 +static void *
52991 +create_table(__u32 * len, int elementsize)
52992 +{
52993 + unsigned int table_sizes[] = {
52994 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52995 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52996 + 4194301, 8388593, 16777213, 33554393, 67108859
52997 + };
52998 + void *newtable = NULL;
52999 + unsigned int pwr = 0;
53000 +
53001 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
53002 + table_sizes[pwr] <= *len)
53003 + pwr++;
53004 +
53005 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
53006 + return newtable;
53007 +
53008 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
53009 + newtable =
53010 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
53011 + else
53012 + newtable = vmalloc(table_sizes[pwr] * elementsize);
53013 +
53014 + *len = table_sizes[pwr];
53015 +
53016 + return newtable;
53017 +}
53018 +
53019 +static int
53020 +init_variables(const struct gr_arg *arg)
53021 +{
53022 + struct task_struct *reaper = init_pid_ns.child_reaper;
53023 + unsigned int stacksize;
53024 +
53025 + subj_map_set.s_size = arg->role_db.num_subjects;
53026 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
53027 + name_set.n_size = arg->role_db.num_objects;
53028 + inodev_set.i_size = arg->role_db.num_objects;
53029 +
53030 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
53031 + !name_set.n_size || !inodev_set.i_size)
53032 + return 1;
53033 +
53034 + if (!gr_init_uidset())
53035 + return 1;
53036 +
53037 + /* set up the stack that holds allocation info */
53038 +
53039 + stacksize = arg->role_db.num_pointers + 5;
53040 +
53041 + if (!acl_alloc_stack_init(stacksize))
53042 + return 1;
53043 +
53044 + /* grab reference for the real root dentry and vfsmount */
53045 + get_fs_root(reaper->fs, &real_root);
53046 +
53047 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53048 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
53049 +#endif
53050 +
53051 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
53052 + if (fakefs_obj_rw == NULL)
53053 + return 1;
53054 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
53055 +
53056 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
53057 + if (fakefs_obj_rwx == NULL)
53058 + return 1;
53059 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
53060 +
53061 + subj_map_set.s_hash =
53062 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
53063 + acl_role_set.r_hash =
53064 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
53065 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
53066 + inodev_set.i_hash =
53067 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
53068 +
53069 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
53070 + !name_set.n_hash || !inodev_set.i_hash)
53071 + return 1;
53072 +
53073 + memset(subj_map_set.s_hash, 0,
53074 + sizeof(struct subject_map *) * subj_map_set.s_size);
53075 + memset(acl_role_set.r_hash, 0,
53076 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
53077 + memset(name_set.n_hash, 0,
53078 + sizeof (struct name_entry *) * name_set.n_size);
53079 + memset(inodev_set.i_hash, 0,
53080 + sizeof (struct inodev_entry *) * inodev_set.i_size);
53081 +
53082 + return 0;
53083 +}
53084 +
53085 +/* free information not needed after startup
53086 + currently contains user->kernel pointer mappings for subjects
53087 +*/
53088 +
53089 +static void
53090 +free_init_variables(void)
53091 +{
53092 + __u32 i;
53093 +
53094 + if (subj_map_set.s_hash) {
53095 + for (i = 0; i < subj_map_set.s_size; i++) {
53096 + if (subj_map_set.s_hash[i]) {
53097 + kfree(subj_map_set.s_hash[i]);
53098 + subj_map_set.s_hash[i] = NULL;
53099 + }
53100 + }
53101 +
53102 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
53103 + PAGE_SIZE)
53104 + kfree(subj_map_set.s_hash);
53105 + else
53106 + vfree(subj_map_set.s_hash);
53107 + }
53108 +
53109 + return;
53110 +}
53111 +
53112 +static void
53113 +free_variables(void)
53114 +{
53115 + struct acl_subject_label *s;
53116 + struct acl_role_label *r;
53117 + struct task_struct *task, *task2;
53118 + unsigned int x;
53119 +
53120 + gr_clear_learn_entries();
53121 +
53122 + read_lock(&tasklist_lock);
53123 + do_each_thread(task2, task) {
53124 + task->acl_sp_role = 0;
53125 + task->acl_role_id = 0;
53126 + task->acl = NULL;
53127 + task->role = NULL;
53128 + } while_each_thread(task2, task);
53129 + read_unlock(&tasklist_lock);
53130 +
53131 + /* release the reference to the real root dentry and vfsmount */
53132 + path_put(&real_root);
53133 + memset(&real_root, 0, sizeof(real_root));
53134 +
53135 + /* free all object hash tables */
53136 +
53137 + FOR_EACH_ROLE_START(r)
53138 + if (r->subj_hash == NULL)
53139 + goto next_role;
53140 + FOR_EACH_SUBJECT_START(r, s, x)
53141 + if (s->obj_hash == NULL)
53142 + break;
53143 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
53144 + kfree(s->obj_hash);
53145 + else
53146 + vfree(s->obj_hash);
53147 + FOR_EACH_SUBJECT_END(s, x)
53148 + FOR_EACH_NESTED_SUBJECT_START(r, s)
53149 + if (s->obj_hash == NULL)
53150 + break;
53151 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
53152 + kfree(s->obj_hash);
53153 + else
53154 + vfree(s->obj_hash);
53155 + FOR_EACH_NESTED_SUBJECT_END(s)
53156 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
53157 + kfree(r->subj_hash);
53158 + else
53159 + vfree(r->subj_hash);
53160 + r->subj_hash = NULL;
53161 +next_role:
53162 + FOR_EACH_ROLE_END(r)
53163 +
53164 + acl_free_all();
53165 +
53166 + if (acl_role_set.r_hash) {
53167 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
53168 + PAGE_SIZE)
53169 + kfree(acl_role_set.r_hash);
53170 + else
53171 + vfree(acl_role_set.r_hash);
53172 + }
53173 + if (name_set.n_hash) {
53174 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
53175 + PAGE_SIZE)
53176 + kfree(name_set.n_hash);
53177 + else
53178 + vfree(name_set.n_hash);
53179 + }
53180 +
53181 + if (inodev_set.i_hash) {
53182 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
53183 + PAGE_SIZE)
53184 + kfree(inodev_set.i_hash);
53185 + else
53186 + vfree(inodev_set.i_hash);
53187 + }
53188 +
53189 + gr_free_uidset();
53190 +
53191 + memset(&name_set, 0, sizeof (struct name_db));
53192 + memset(&inodev_set, 0, sizeof (struct inodev_db));
53193 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
53194 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
53195 +
53196 + default_role = NULL;
53197 + kernel_role = NULL;
53198 + role_list = NULL;
53199 +
53200 + return;
53201 +}
53202 +
53203 +static __u32
53204 +count_user_objs(struct acl_object_label *userp)
53205 +{
53206 + struct acl_object_label o_tmp;
53207 + __u32 num = 0;
53208 +
53209 + while (userp) {
53210 + if (copy_from_user(&o_tmp, userp,
53211 + sizeof (struct acl_object_label)))
53212 + break;
53213 +
53214 + userp = o_tmp.prev;
53215 + num++;
53216 + }
53217 +
53218 + return num;
53219 +}
53220 +
53221 +static struct acl_subject_label *
53222 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
53223 +
53224 +static int
53225 +copy_user_glob(struct acl_object_label *obj)
53226 +{
53227 + struct acl_object_label *g_tmp, **guser;
53228 + unsigned int len;
53229 + char *tmp;
53230 +
53231 + if (obj->globbed == NULL)
53232 + return 0;
53233 +
53234 + guser = &obj->globbed;
53235 + while (*guser) {
53236 + g_tmp = (struct acl_object_label *)
53237 + acl_alloc(sizeof (struct acl_object_label));
53238 + if (g_tmp == NULL)
53239 + return -ENOMEM;
53240 +
53241 + if (copy_from_user(g_tmp, *guser,
53242 + sizeof (struct acl_object_label)))
53243 + return -EFAULT;
53244 +
53245 + len = strnlen_user(g_tmp->filename, PATH_MAX);
53246 +
53247 + if (!len || len >= PATH_MAX)
53248 + return -EINVAL;
53249 +
53250 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53251 + return -ENOMEM;
53252 +
53253 + if (copy_from_user(tmp, g_tmp->filename, len))
53254 + return -EFAULT;
53255 + tmp[len-1] = '\0';
53256 + g_tmp->filename = tmp;
53257 +
53258 + *guser = g_tmp;
53259 + guser = &(g_tmp->next);
53260 + }
53261 +
53262 + return 0;
53263 +}
53264 +
53265 +static int
53266 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
53267 + struct acl_role_label *role)
53268 +{
53269 + struct acl_object_label *o_tmp;
53270 + unsigned int len;
53271 + int ret;
53272 + char *tmp;
53273 +
53274 + while (userp) {
53275 + if ((o_tmp = (struct acl_object_label *)
53276 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
53277 + return -ENOMEM;
53278 +
53279 + if (copy_from_user(o_tmp, userp,
53280 + sizeof (struct acl_object_label)))
53281 + return -EFAULT;
53282 +
53283 + userp = o_tmp->prev;
53284 +
53285 + len = strnlen_user(o_tmp->filename, PATH_MAX);
53286 +
53287 + if (!len || len >= PATH_MAX)
53288 + return -EINVAL;
53289 +
53290 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53291 + return -ENOMEM;
53292 +
53293 + if (copy_from_user(tmp, o_tmp->filename, len))
53294 + return -EFAULT;
53295 + tmp[len-1] = '\0';
53296 + o_tmp->filename = tmp;
53297 +
53298 + insert_acl_obj_label(o_tmp, subj);
53299 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
53300 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
53301 + return -ENOMEM;
53302 +
53303 + ret = copy_user_glob(o_tmp);
53304 + if (ret)
53305 + return ret;
53306 +
53307 + if (o_tmp->nested) {
53308 + int already_copied;
53309 +
53310 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
53311 + if (IS_ERR(o_tmp->nested))
53312 + return PTR_ERR(o_tmp->nested);
53313 +
53314 + /* insert into nested subject list if we haven't copied this one yet
53315 + to prevent duplicate entries */
53316 + if (!already_copied) {
53317 + o_tmp->nested->next = role->hash->first;
53318 + role->hash->first = o_tmp->nested;
53319 + }
53320 + }
53321 + }
53322 +
53323 + return 0;
53324 +}
53325 +
53326 +static __u32
53327 +count_user_subjs(struct acl_subject_label *userp)
53328 +{
53329 + struct acl_subject_label s_tmp;
53330 + __u32 num = 0;
53331 +
53332 + while (userp) {
53333 + if (copy_from_user(&s_tmp, userp,
53334 + sizeof (struct acl_subject_label)))
53335 + break;
53336 +
53337 + userp = s_tmp.prev;
53338 + /* do not count nested subjects against this count, since
53339 + they are not included in the hash table, but are
53340 + attached to objects. We have already counted
53341 + the subjects in userspace for the allocation
53342 + stack
53343 + */
53344 + if (!(s_tmp.mode & GR_NESTED))
53345 + num++;
53346 + }
53347 +
53348 + return num;
53349 +}
53350 +
53351 +static int
53352 +copy_user_allowedips(struct acl_role_label *rolep)
53353 +{
53354 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
53355 +
53356 + ruserip = rolep->allowed_ips;
53357 +
53358 + while (ruserip) {
53359 + rlast = rtmp;
53360 +
53361 + if ((rtmp = (struct role_allowed_ip *)
53362 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
53363 + return -ENOMEM;
53364 +
53365 + if (copy_from_user(rtmp, ruserip,
53366 + sizeof (struct role_allowed_ip)))
53367 + return -EFAULT;
53368 +
53369 + ruserip = rtmp->prev;
53370 +
53371 + if (!rlast) {
53372 + rtmp->prev = NULL;
53373 + rolep->allowed_ips = rtmp;
53374 + } else {
53375 + rlast->next = rtmp;
53376 + rtmp->prev = rlast;
53377 + }
53378 +
53379 + if (!ruserip)
53380 + rtmp->next = NULL;
53381 + }
53382 +
53383 + return 0;
53384 +}
53385 +
53386 +static int
53387 +copy_user_transitions(struct acl_role_label *rolep)
53388 +{
53389 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
53390 +
53391 + unsigned int len;
53392 + char *tmp;
53393 +
53394 + rusertp = rolep->transitions;
53395 +
53396 + while (rusertp) {
53397 + rlast = rtmp;
53398 +
53399 + if ((rtmp = (struct role_transition *)
53400 + acl_alloc(sizeof (struct role_transition))) == NULL)
53401 + return -ENOMEM;
53402 +
53403 + if (copy_from_user(rtmp, rusertp,
53404 + sizeof (struct role_transition)))
53405 + return -EFAULT;
53406 +
53407 + rusertp = rtmp->prev;
53408 +
53409 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
53410 +
53411 + if (!len || len >= GR_SPROLE_LEN)
53412 + return -EINVAL;
53413 +
53414 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53415 + return -ENOMEM;
53416 +
53417 + if (copy_from_user(tmp, rtmp->rolename, len))
53418 + return -EFAULT;
53419 + tmp[len-1] = '\0';
53420 + rtmp->rolename = tmp;
53421 +
53422 + if (!rlast) {
53423 + rtmp->prev = NULL;
53424 + rolep->transitions = rtmp;
53425 + } else {
53426 + rlast->next = rtmp;
53427 + rtmp->prev = rlast;
53428 + }
53429 +
53430 + if (!rusertp)
53431 + rtmp->next = NULL;
53432 + }
53433 +
53434 + return 0;
53435 +}
53436 +
53437 +static struct acl_subject_label *
53438 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
53439 +{
53440 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
53441 + unsigned int len;
53442 + char *tmp;
53443 + __u32 num_objs;
53444 + struct acl_ip_label **i_tmp, *i_utmp2;
53445 + struct gr_hash_struct ghash;
53446 + struct subject_map *subjmap;
53447 + unsigned int i_num;
53448 + int err;
53449 +
53450 + if (already_copied != NULL)
53451 + *already_copied = 0;
53452 +
53453 + s_tmp = lookup_subject_map(userp);
53454 +
53455 + /* we've already copied this subject into the kernel, just return
53456 + the reference to it, and don't copy it over again
53457 + */
53458 + if (s_tmp) {
53459 + if (already_copied != NULL)
53460 + *already_copied = 1;
53461 + return(s_tmp);
53462 + }
53463 +
53464 + if ((s_tmp = (struct acl_subject_label *)
53465 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53466 + return ERR_PTR(-ENOMEM);
53467 +
53468 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53469 + if (subjmap == NULL)
53470 + return ERR_PTR(-ENOMEM);
53471 +
53472 + subjmap->user = userp;
53473 + subjmap->kernel = s_tmp;
53474 + insert_subj_map_entry(subjmap);
53475 +
53476 + if (copy_from_user(s_tmp, userp,
53477 + sizeof (struct acl_subject_label)))
53478 + return ERR_PTR(-EFAULT);
53479 +
53480 + len = strnlen_user(s_tmp->filename, PATH_MAX);
53481 +
53482 + if (!len || len >= PATH_MAX)
53483 + return ERR_PTR(-EINVAL);
53484 +
53485 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53486 + return ERR_PTR(-ENOMEM);
53487 +
53488 + if (copy_from_user(tmp, s_tmp->filename, len))
53489 + return ERR_PTR(-EFAULT);
53490 + tmp[len-1] = '\0';
53491 + s_tmp->filename = tmp;
53492 +
53493 + if (!strcmp(s_tmp->filename, "/"))
53494 + role->root_label = s_tmp;
53495 +
53496 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53497 + return ERR_PTR(-EFAULT);
53498 +
53499 + /* copy user and group transition tables */
53500 +
53501 + if (s_tmp->user_trans_num) {
53502 + uid_t *uidlist;
53503 +
53504 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53505 + if (uidlist == NULL)
53506 + return ERR_PTR(-ENOMEM);
53507 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53508 + return ERR_PTR(-EFAULT);
53509 +
53510 + s_tmp->user_transitions = uidlist;
53511 + }
53512 +
53513 + if (s_tmp->group_trans_num) {
53514 + gid_t *gidlist;
53515 +
53516 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53517 + if (gidlist == NULL)
53518 + return ERR_PTR(-ENOMEM);
53519 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53520 + return ERR_PTR(-EFAULT);
53521 +
53522 + s_tmp->group_transitions = gidlist;
53523 + }
53524 +
53525 + /* set up object hash table */
53526 + num_objs = count_user_objs(ghash.first);
53527 +
53528 + s_tmp->obj_hash_size = num_objs;
53529 + s_tmp->obj_hash =
53530 + (struct acl_object_label **)
53531 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53532 +
53533 + if (!s_tmp->obj_hash)
53534 + return ERR_PTR(-ENOMEM);
53535 +
53536 + memset(s_tmp->obj_hash, 0,
53537 + s_tmp->obj_hash_size *
53538 + sizeof (struct acl_object_label *));
53539 +
53540 + /* add in objects */
53541 + err = copy_user_objs(ghash.first, s_tmp, role);
53542 +
53543 + if (err)
53544 + return ERR_PTR(err);
53545 +
53546 + /* set pointer for parent subject */
53547 + if (s_tmp->parent_subject) {
53548 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
53549 +
53550 + if (IS_ERR(s_tmp2))
53551 + return s_tmp2;
53552 +
53553 + s_tmp->parent_subject = s_tmp2;
53554 + }
53555 +
53556 + /* add in ip acls */
53557 +
53558 + if (!s_tmp->ip_num) {
53559 + s_tmp->ips = NULL;
53560 + goto insert;
53561 + }
53562 +
53563 + i_tmp =
53564 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53565 + sizeof (struct acl_ip_label *));
53566 +
53567 + if (!i_tmp)
53568 + return ERR_PTR(-ENOMEM);
53569 +
53570 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53571 + *(i_tmp + i_num) =
53572 + (struct acl_ip_label *)
53573 + acl_alloc(sizeof (struct acl_ip_label));
53574 + if (!*(i_tmp + i_num))
53575 + return ERR_PTR(-ENOMEM);
53576 +
53577 + if (copy_from_user
53578 + (&i_utmp2, s_tmp->ips + i_num,
53579 + sizeof (struct acl_ip_label *)))
53580 + return ERR_PTR(-EFAULT);
53581 +
53582 + if (copy_from_user
53583 + (*(i_tmp + i_num), i_utmp2,
53584 + sizeof (struct acl_ip_label)))
53585 + return ERR_PTR(-EFAULT);
53586 +
53587 + if ((*(i_tmp + i_num))->iface == NULL)
53588 + continue;
53589 +
53590 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53591 + if (!len || len >= IFNAMSIZ)
53592 + return ERR_PTR(-EINVAL);
53593 + tmp = acl_alloc(len);
53594 + if (tmp == NULL)
53595 + return ERR_PTR(-ENOMEM);
53596 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53597 + return ERR_PTR(-EFAULT);
53598 + (*(i_tmp + i_num))->iface = tmp;
53599 + }
53600 +
53601 + s_tmp->ips = i_tmp;
53602 +
53603 +insert:
53604 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53605 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53606 + return ERR_PTR(-ENOMEM);
53607 +
53608 + return s_tmp;
53609 +}
53610 +
53611 +static int
53612 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53613 +{
53614 + struct acl_subject_label s_pre;
53615 + struct acl_subject_label * ret;
53616 + int err;
53617 +
53618 + while (userp) {
53619 + if (copy_from_user(&s_pre, userp,
53620 + sizeof (struct acl_subject_label)))
53621 + return -EFAULT;
53622 +
53623 + /* do not add nested subjects here, add
53624 + while parsing objects
53625 + */
53626 +
53627 + if (s_pre.mode & GR_NESTED) {
53628 + userp = s_pre.prev;
53629 + continue;
53630 + }
53631 +
53632 + ret = do_copy_user_subj(userp, role, NULL);
53633 +
53634 + err = PTR_ERR(ret);
53635 + if (IS_ERR(ret))
53636 + return err;
53637 +
53638 + insert_acl_subj_label(ret, role);
53639 +
53640 + userp = s_pre.prev;
53641 + }
53642 +
53643 + return 0;
53644 +}
53645 +
53646 +static int
53647 +copy_user_acl(struct gr_arg *arg)
53648 +{
53649 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53650 + struct acl_subject_label *subj_list;
53651 + struct sprole_pw *sptmp;
53652 + struct gr_hash_struct *ghash;
53653 + uid_t *domainlist;
53654 + unsigned int r_num;
53655 + unsigned int len;
53656 + char *tmp;
53657 + int err = 0;
53658 + __u16 i;
53659 + __u32 num_subjs;
53660 +
53661 + /* we need a default and kernel role */
53662 + if (arg->role_db.num_roles < 2)
53663 + return -EINVAL;
53664 +
53665 + /* copy special role authentication info from userspace */
53666 +
53667 + num_sprole_pws = arg->num_sprole_pws;
53668 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53669 +
53670 + if (!acl_special_roles && num_sprole_pws)
53671 + return -ENOMEM;
53672 +
53673 + for (i = 0; i < num_sprole_pws; i++) {
53674 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53675 + if (!sptmp)
53676 + return -ENOMEM;
53677 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53678 + sizeof (struct sprole_pw)))
53679 + return -EFAULT;
53680 +
53681 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53682 +
53683 + if (!len || len >= GR_SPROLE_LEN)
53684 + return -EINVAL;
53685 +
53686 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53687 + return -ENOMEM;
53688 +
53689 + if (copy_from_user(tmp, sptmp->rolename, len))
53690 + return -EFAULT;
53691 +
53692 + tmp[len-1] = '\0';
53693 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53694 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53695 +#endif
53696 + sptmp->rolename = tmp;
53697 + acl_special_roles[i] = sptmp;
53698 + }
53699 +
53700 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53701 +
53702 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53703 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53704 +
53705 + if (!r_tmp)
53706 + return -ENOMEM;
53707 +
53708 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53709 + sizeof (struct acl_role_label *)))
53710 + return -EFAULT;
53711 +
53712 + if (copy_from_user(r_tmp, r_utmp2,
53713 + sizeof (struct acl_role_label)))
53714 + return -EFAULT;
53715 +
53716 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53717 +
53718 + if (!len || len >= PATH_MAX)
53719 + return -EINVAL;
53720 +
53721 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53722 + return -ENOMEM;
53723 +
53724 + if (copy_from_user(tmp, r_tmp->rolename, len))
53725 + return -EFAULT;
53726 +
53727 + tmp[len-1] = '\0';
53728 + r_tmp->rolename = tmp;
53729 +
53730 + if (!strcmp(r_tmp->rolename, "default")
53731 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53732 + default_role = r_tmp;
53733 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53734 + kernel_role = r_tmp;
53735 + }
53736 +
53737 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53738 + return -ENOMEM;
53739 +
53740 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53741 + return -EFAULT;
53742 +
53743 + r_tmp->hash = ghash;
53744 +
53745 + num_subjs = count_user_subjs(r_tmp->hash->first);
53746 +
53747 + r_tmp->subj_hash_size = num_subjs;
53748 + r_tmp->subj_hash =
53749 + (struct acl_subject_label **)
53750 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53751 +
53752 + if (!r_tmp->subj_hash)
53753 + return -ENOMEM;
53754 +
53755 + err = copy_user_allowedips(r_tmp);
53756 + if (err)
53757 + return err;
53758 +
53759 + /* copy domain info */
53760 + if (r_tmp->domain_children != NULL) {
53761 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53762 + if (domainlist == NULL)
53763 + return -ENOMEM;
53764 +
53765 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53766 + return -EFAULT;
53767 +
53768 + r_tmp->domain_children = domainlist;
53769 + }
53770 +
53771 + err = copy_user_transitions(r_tmp);
53772 + if (err)
53773 + return err;
53774 +
53775 + memset(r_tmp->subj_hash, 0,
53776 + r_tmp->subj_hash_size *
53777 + sizeof (struct acl_subject_label *));
53778 +
53779 + /* acquire the list of subjects, then NULL out
53780 + the list prior to parsing the subjects for this role,
53781 + as during this parsing the list is replaced with a list
53782 + of *nested* subjects for the role
53783 + */
53784 + subj_list = r_tmp->hash->first;
53785 +
53786 + /* set nested subject list to null */
53787 + r_tmp->hash->first = NULL;
53788 +
53789 + err = copy_user_subjs(subj_list, r_tmp);
53790 +
53791 + if (err)
53792 + return err;
53793 +
53794 + insert_acl_role_label(r_tmp);
53795 + }
53796 +
53797 + if (default_role == NULL || kernel_role == NULL)
53798 + return -EINVAL;
53799 +
53800 + return err;
53801 +}
53802 +
53803 +static int
53804 +gracl_init(struct gr_arg *args)
53805 +{
53806 + int error = 0;
53807 +
53808 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53809 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53810 +
53811 + if (init_variables(args)) {
53812 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53813 + error = -ENOMEM;
53814 + free_variables();
53815 + goto out;
53816 + }
53817 +
53818 + error = copy_user_acl(args);
53819 + free_init_variables();
53820 + if (error) {
53821 + free_variables();
53822 + goto out;
53823 + }
53824 +
53825 + if ((error = gr_set_acls(0))) {
53826 + free_variables();
53827 + goto out;
53828 + }
53829 +
53830 + pax_open_kernel();
53831 + gr_status |= GR_READY;
53832 + pax_close_kernel();
53833 +
53834 + out:
53835 + return error;
53836 +}
53837 +
53838 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53839 +
53840 +static int
53841 +glob_match(const char *p, const char *n)
53842 +{
53843 + char c;
53844 +
53845 + while ((c = *p++) != '\0') {
53846 + switch (c) {
53847 + case '?':
53848 + if (*n == '\0')
53849 + return 1;
53850 + else if (*n == '/')
53851 + return 1;
53852 + break;
53853 + case '\\':
53854 + if (*n != c)
53855 + return 1;
53856 + break;
53857 + case '*':
53858 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53859 + if (*n == '/')
53860 + return 1;
53861 + else if (c == '?') {
53862 + if (*n == '\0')
53863 + return 1;
53864 + else
53865 + ++n;
53866 + }
53867 + }
53868 + if (c == '\0') {
53869 + return 0;
53870 + } else {
53871 + const char *endp;
53872 +
53873 + if ((endp = strchr(n, '/')) == NULL)
53874 + endp = n + strlen(n);
53875 +
53876 + if (c == '[') {
53877 + for (--p; n < endp; ++n)
53878 + if (!glob_match(p, n))
53879 + return 0;
53880 + } else if (c == '/') {
53881 + while (*n != '\0' && *n != '/')
53882 + ++n;
53883 + if (*n == '/' && !glob_match(p, n + 1))
53884 + return 0;
53885 + } else {
53886 + for (--p; n < endp; ++n)
53887 + if (*n == c && !glob_match(p, n))
53888 + return 0;
53889 + }
53890 +
53891 + return 1;
53892 + }
53893 + case '[':
53894 + {
53895 + int not;
53896 + char cold;
53897 +
53898 + if (*n == '\0' || *n == '/')
53899 + return 1;
53900 +
53901 + not = (*p == '!' || *p == '^');
53902 + if (not)
53903 + ++p;
53904 +
53905 + c = *p++;
53906 + for (;;) {
53907 + unsigned char fn = (unsigned char)*n;
53908 +
53909 + if (c == '\0')
53910 + return 1;
53911 + else {
53912 + if (c == fn)
53913 + goto matched;
53914 + cold = c;
53915 + c = *p++;
53916 +
53917 + if (c == '-' && *p != ']') {
53918 + unsigned char cend = *p++;
53919 +
53920 + if (cend == '\0')
53921 + return 1;
53922 +
53923 + if (cold <= fn && fn <= cend)
53924 + goto matched;
53925 +
53926 + c = *p++;
53927 + }
53928 + }
53929 +
53930 + if (c == ']')
53931 + break;
53932 + }
53933 + if (!not)
53934 + return 1;
53935 + break;
53936 + matched:
53937 + while (c != ']') {
53938 + if (c == '\0')
53939 + return 1;
53940 +
53941 + c = *p++;
53942 + }
53943 + if (not)
53944 + return 1;
53945 + }
53946 + break;
53947 + default:
53948 + if (c != *n)
53949 + return 1;
53950 + }
53951 +
53952 + ++n;
53953 + }
53954 +
53955 + if (*n == '\0')
53956 + return 0;
53957 +
53958 + if (*n == '/')
53959 + return 0;
53960 +
53961 + return 1;
53962 +}
53963 +
53964 +static struct acl_object_label *
53965 +chk_glob_label(struct acl_object_label *globbed,
53966 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53967 +{
53968 + struct acl_object_label *tmp;
53969 +
53970 + if (*path == NULL)
53971 + *path = gr_to_filename_nolock(dentry, mnt);
53972 +
53973 + tmp = globbed;
53974 +
53975 + while (tmp) {
53976 + if (!glob_match(tmp->filename, *path))
53977 + return tmp;
53978 + tmp = tmp->next;
53979 + }
53980 +
53981 + return NULL;
53982 +}
53983 +
53984 +static struct acl_object_label *
53985 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53986 + const ino_t curr_ino, const dev_t curr_dev,
53987 + const struct acl_subject_label *subj, char **path, const int checkglob)
53988 +{
53989 + struct acl_subject_label *tmpsubj;
53990 + struct acl_object_label *retval;
53991 + struct acl_object_label *retval2;
53992 +
53993 + tmpsubj = (struct acl_subject_label *) subj;
53994 + read_lock(&gr_inode_lock);
53995 + do {
53996 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53997 + if (retval) {
53998 + if (checkglob && retval->globbed) {
53999 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
54000 + if (retval2)
54001 + retval = retval2;
54002 + }
54003 + break;
54004 + }
54005 + } while ((tmpsubj = tmpsubj->parent_subject));
54006 + read_unlock(&gr_inode_lock);
54007 +
54008 + return retval;
54009 +}
54010 +
54011 +static __inline__ struct acl_object_label *
54012 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
54013 + struct dentry *curr_dentry,
54014 + const struct acl_subject_label *subj, char **path, const int checkglob)
54015 +{
54016 + int newglob = checkglob;
54017 + ino_t inode;
54018 + dev_t device;
54019 +
54020 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
54021 + as we don't want a / * rule to match instead of the / object
54022 + don't do this for create lookups that call this function though, since they're looking up
54023 + on the parent and thus need globbing checks on all paths
54024 + */
54025 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
54026 + newglob = GR_NO_GLOB;
54027 +
54028 + spin_lock(&curr_dentry->d_lock);
54029 + inode = curr_dentry->d_inode->i_ino;
54030 + device = __get_dev(curr_dentry);
54031 + spin_unlock(&curr_dentry->d_lock);
54032 +
54033 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
54034 +}
54035 +
54036 +static struct acl_object_label *
54037 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54038 + const struct acl_subject_label *subj, char *path, const int checkglob)
54039 +{
54040 + struct dentry *dentry = (struct dentry *) l_dentry;
54041 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
54042 + struct mount *real_mnt = real_mount(mnt);
54043 + struct acl_object_label *retval;
54044 + struct dentry *parent;
54045 +
54046 + write_seqlock(&rename_lock);
54047 + br_read_lock(&vfsmount_lock);
54048 +
54049 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
54050 +#ifdef CONFIG_NET
54051 + mnt == sock_mnt ||
54052 +#endif
54053 +#ifdef CONFIG_HUGETLBFS
54054 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
54055 +#endif
54056 + /* ignore Eric Biederman */
54057 + IS_PRIVATE(l_dentry->d_inode))) {
54058 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
54059 + goto out;
54060 + }
54061 +
54062 + for (;;) {
54063 + if (dentry == real_root.dentry && mnt == real_root.mnt)
54064 + break;
54065 +
54066 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
54067 + if (!mnt_has_parent(real_mnt))
54068 + break;
54069 +
54070 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54071 + if (retval != NULL)
54072 + goto out;
54073 +
54074 + dentry = real_mnt->mnt_mountpoint;
54075 + real_mnt = real_mnt->mnt_parent;
54076 + mnt = &real_mnt->mnt;
54077 + continue;
54078 + }
54079 +
54080 + parent = dentry->d_parent;
54081 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54082 + if (retval != NULL)
54083 + goto out;
54084 +
54085 + dentry = parent;
54086 + }
54087 +
54088 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54089 +
54090 + /* real_root is pinned so we don't have to hold a reference */
54091 + if (retval == NULL)
54092 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
54093 +out:
54094 + br_read_unlock(&vfsmount_lock);
54095 + write_sequnlock(&rename_lock);
54096 +
54097 + BUG_ON(retval == NULL);
54098 +
54099 + return retval;
54100 +}
54101 +
54102 +static __inline__ struct acl_object_label *
54103 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54104 + const struct acl_subject_label *subj)
54105 +{
54106 + char *path = NULL;
54107 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
54108 +}
54109 +
54110 +static __inline__ struct acl_object_label *
54111 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54112 + const struct acl_subject_label *subj)
54113 +{
54114 + char *path = NULL;
54115 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
54116 +}
54117 +
54118 +static __inline__ struct acl_object_label *
54119 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54120 + const struct acl_subject_label *subj, char *path)
54121 +{
54122 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
54123 +}
54124 +
54125 +static struct acl_subject_label *
54126 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54127 + const struct acl_role_label *role)
54128 +{
54129 + struct dentry *dentry = (struct dentry *) l_dentry;
54130 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
54131 + struct mount *real_mnt = real_mount(mnt);
54132 + struct acl_subject_label *retval;
54133 + struct dentry *parent;
54134 +
54135 + write_seqlock(&rename_lock);
54136 + br_read_lock(&vfsmount_lock);
54137 +
54138 + for (;;) {
54139 + if (dentry == real_root.dentry && mnt == real_root.mnt)
54140 + break;
54141 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
54142 + if (!mnt_has_parent(real_mnt))
54143 + break;
54144 +
54145 + spin_lock(&dentry->d_lock);
54146 + read_lock(&gr_inode_lock);
54147 + retval =
54148 + lookup_acl_subj_label(dentry->d_inode->i_ino,
54149 + __get_dev(dentry), role);
54150 + read_unlock(&gr_inode_lock);
54151 + spin_unlock(&dentry->d_lock);
54152 + if (retval != NULL)
54153 + goto out;
54154 +
54155 + dentry = real_mnt->mnt_mountpoint;
54156 + real_mnt = real_mnt->mnt_parent;
54157 + mnt = &real_mnt->mnt;
54158 + continue;
54159 + }
54160 +
54161 + spin_lock(&dentry->d_lock);
54162 + read_lock(&gr_inode_lock);
54163 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
54164 + __get_dev(dentry), role);
54165 + read_unlock(&gr_inode_lock);
54166 + parent = dentry->d_parent;
54167 + spin_unlock(&dentry->d_lock);
54168 +
54169 + if (retval != NULL)
54170 + goto out;
54171 +
54172 + dentry = parent;
54173 + }
54174 +
54175 + spin_lock(&dentry->d_lock);
54176 + read_lock(&gr_inode_lock);
54177 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
54178 + __get_dev(dentry), role);
54179 + read_unlock(&gr_inode_lock);
54180 + spin_unlock(&dentry->d_lock);
54181 +
54182 + if (unlikely(retval == NULL)) {
54183 + /* real_root is pinned, we don't need to hold a reference */
54184 + read_lock(&gr_inode_lock);
54185 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
54186 + __get_dev(real_root.dentry), role);
54187 + read_unlock(&gr_inode_lock);
54188 + }
54189 +out:
54190 + br_read_unlock(&vfsmount_lock);
54191 + write_sequnlock(&rename_lock);
54192 +
54193 + BUG_ON(retval == NULL);
54194 +
54195 + return retval;
54196 +}
54197 +
54198 +static void
54199 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
54200 +{
54201 + struct task_struct *task = current;
54202 + const struct cred *cred = current_cred();
54203 +
54204 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
54205 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
54206 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
54207 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
54208 +
54209 + return;
54210 +}
54211 +
54212 +static void
54213 +gr_log_learn_id_change(const char type, const unsigned int real,
54214 + const unsigned int effective, const unsigned int fs)
54215 +{
54216 + struct task_struct *task = current;
54217 + const struct cred *cred = current_cred();
54218 +
54219 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
54220 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
54221 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
54222 + type, real, effective, fs, &task->signal->saved_ip);
54223 +
54224 + return;
54225 +}
54226 +
54227 +__u32
54228 +gr_search_file(const struct dentry * dentry, const __u32 mode,
54229 + const struct vfsmount * mnt)
54230 +{
54231 + __u32 retval = mode;
54232 + struct acl_subject_label *curracl;
54233 + struct acl_object_label *currobj;
54234 +
54235 + if (unlikely(!(gr_status & GR_READY)))
54236 + return (mode & ~GR_AUDITS);
54237 +
54238 + curracl = current->acl;
54239 +
54240 + currobj = chk_obj_label(dentry, mnt, curracl);
54241 + retval = currobj->mode & mode;
54242 +
54243 + /* if we're opening a specified transfer file for writing
54244 + (e.g. /dev/initctl), then transfer our role to init
54245 + */
54246 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
54247 + current->role->roletype & GR_ROLE_PERSIST)) {
54248 + struct task_struct *task = init_pid_ns.child_reaper;
54249 +
54250 + if (task->role != current->role) {
54251 + task->acl_sp_role = 0;
54252 + task->acl_role_id = current->acl_role_id;
54253 + task->role = current->role;
54254 + rcu_read_lock();
54255 + read_lock(&grsec_exec_file_lock);
54256 + gr_apply_subject_to_task(task);
54257 + read_unlock(&grsec_exec_file_lock);
54258 + rcu_read_unlock();
54259 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
54260 + }
54261 + }
54262 +
54263 + if (unlikely
54264 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
54265 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
54266 + __u32 new_mode = mode;
54267 +
54268 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54269 +
54270 + retval = new_mode;
54271 +
54272 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
54273 + new_mode |= GR_INHERIT;
54274 +
54275 + if (!(mode & GR_NOLEARN))
54276 + gr_log_learn(dentry, mnt, new_mode);
54277 + }
54278 +
54279 + return retval;
54280 +}
54281 +
54282 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
54283 + const struct dentry *parent,
54284 + const struct vfsmount *mnt)
54285 +{
54286 + struct name_entry *match;
54287 + struct acl_object_label *matchpo;
54288 + struct acl_subject_label *curracl;
54289 + char *path;
54290 +
54291 + if (unlikely(!(gr_status & GR_READY)))
54292 + return NULL;
54293 +
54294 + preempt_disable();
54295 + path = gr_to_filename_rbac(new_dentry, mnt);
54296 + match = lookup_name_entry_create(path);
54297 +
54298 + curracl = current->acl;
54299 +
54300 + if (match) {
54301 + read_lock(&gr_inode_lock);
54302 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
54303 + read_unlock(&gr_inode_lock);
54304 +
54305 + if (matchpo) {
54306 + preempt_enable();
54307 + return matchpo;
54308 + }
54309 + }
54310 +
54311 + // lookup parent
54312 +
54313 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
54314 +
54315 + preempt_enable();
54316 + return matchpo;
54317 +}
54318 +
54319 +__u32
54320 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
54321 + const struct vfsmount * mnt, const __u32 mode)
54322 +{
54323 + struct acl_object_label *matchpo;
54324 + __u32 retval;
54325 +
54326 + if (unlikely(!(gr_status & GR_READY)))
54327 + return (mode & ~GR_AUDITS);
54328 +
54329 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
54330 +
54331 + retval = matchpo->mode & mode;
54332 +
54333 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
54334 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54335 + __u32 new_mode = mode;
54336 +
54337 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54338 +
54339 + gr_log_learn(new_dentry, mnt, new_mode);
54340 + return new_mode;
54341 + }
54342 +
54343 + return retval;
54344 +}
54345 +
54346 +__u32
54347 +gr_check_link(const struct dentry * new_dentry,
54348 + const struct dentry * parent_dentry,
54349 + const struct vfsmount * parent_mnt,
54350 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
54351 +{
54352 + struct acl_object_label *obj;
54353 + __u32 oldmode, newmode;
54354 + __u32 needmode;
54355 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
54356 + GR_DELETE | GR_INHERIT;
54357 +
54358 + if (unlikely(!(gr_status & GR_READY)))
54359 + return (GR_CREATE | GR_LINK);
54360 +
54361 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
54362 + oldmode = obj->mode;
54363 +
54364 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
54365 + newmode = obj->mode;
54366 +
54367 + needmode = newmode & checkmodes;
54368 +
54369 + // old name for hardlink must have at least the permissions of the new name
54370 + if ((oldmode & needmode) != needmode)
54371 + goto bad;
54372 +
54373 + // if old name had restrictions/auditing, make sure the new name does as well
54374 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
54375 +
54376 + // don't allow hardlinking of suid/sgid/fcapped files without permission
54377 + if (is_privileged_binary(old_dentry))
54378 + needmode |= GR_SETID;
54379 +
54380 + if ((newmode & needmode) != needmode)
54381 + goto bad;
54382 +
54383 + // enforce minimum permissions
54384 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
54385 + return newmode;
54386 +bad:
54387 + needmode = oldmode;
54388 + if (is_privileged_binary(old_dentry))
54389 + needmode |= GR_SETID;
54390 +
54391 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
54392 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
54393 + return (GR_CREATE | GR_LINK);
54394 + } else if (newmode & GR_SUPPRESS)
54395 + return GR_SUPPRESS;
54396 + else
54397 + return 0;
54398 +}
54399 +
54400 +int
54401 +gr_check_hidden_task(const struct task_struct *task)
54402 +{
54403 + if (unlikely(!(gr_status & GR_READY)))
54404 + return 0;
54405 +
54406 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
54407 + return 1;
54408 +
54409 + return 0;
54410 +}
54411 +
54412 +int
54413 +gr_check_protected_task(const struct task_struct *task)
54414 +{
54415 + if (unlikely(!(gr_status & GR_READY) || !task))
54416 + return 0;
54417 +
54418 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54419 + task->acl != current->acl)
54420 + return 1;
54421 +
54422 + return 0;
54423 +}
54424 +
54425 +int
54426 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54427 +{
54428 + struct task_struct *p;
54429 + int ret = 0;
54430 +
54431 + if (unlikely(!(gr_status & GR_READY) || !pid))
54432 + return ret;
54433 +
54434 + read_lock(&tasklist_lock);
54435 + do_each_pid_task(pid, type, p) {
54436 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54437 + p->acl != current->acl) {
54438 + ret = 1;
54439 + goto out;
54440 + }
54441 + } while_each_pid_task(pid, type, p);
54442 +out:
54443 + read_unlock(&tasklist_lock);
54444 +
54445 + return ret;
54446 +}
54447 +
54448 +void
54449 +gr_copy_label(struct task_struct *tsk)
54450 +{
54451 + tsk->signal->used_accept = 0;
54452 + tsk->acl_sp_role = 0;
54453 + tsk->acl_role_id = current->acl_role_id;
54454 + tsk->acl = current->acl;
54455 + tsk->role = current->role;
54456 + tsk->signal->curr_ip = current->signal->curr_ip;
54457 + tsk->signal->saved_ip = current->signal->saved_ip;
54458 + if (current->exec_file)
54459 + get_file(current->exec_file);
54460 + tsk->exec_file = current->exec_file;
54461 + tsk->is_writable = current->is_writable;
54462 + if (unlikely(current->signal->used_accept)) {
54463 + current->signal->curr_ip = 0;
54464 + current->signal->saved_ip = 0;
54465 + }
54466 +
54467 + return;
54468 +}
54469 +
54470 +static void
54471 +gr_set_proc_res(struct task_struct *task)
54472 +{
54473 + struct acl_subject_label *proc;
54474 + unsigned short i;
54475 +
54476 + proc = task->acl;
54477 +
54478 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54479 + return;
54480 +
54481 + for (i = 0; i < RLIM_NLIMITS; i++) {
54482 + if (!(proc->resmask & (1 << i)))
54483 + continue;
54484 +
54485 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54486 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54487 + }
54488 +
54489 + return;
54490 +}
54491 +
54492 +extern int __gr_process_user_ban(struct user_struct *user);
54493 +
54494 +int
54495 +gr_check_user_change(int real, int effective, int fs)
54496 +{
54497 + unsigned int i;
54498 + __u16 num;
54499 + uid_t *uidlist;
54500 + int curuid;
54501 + int realok = 0;
54502 + int effectiveok = 0;
54503 + int fsok = 0;
54504 +
54505 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54506 + struct user_struct *user;
54507 +
54508 + if (real == -1)
54509 + goto skipit;
54510 +
54511 + user = find_user(real);
54512 + if (user == NULL)
54513 + goto skipit;
54514 +
54515 + if (__gr_process_user_ban(user)) {
54516 + /* for find_user */
54517 + free_uid(user);
54518 + return 1;
54519 + }
54520 +
54521 + /* for find_user */
54522 + free_uid(user);
54523 +
54524 +skipit:
54525 +#endif
54526 +
54527 + if (unlikely(!(gr_status & GR_READY)))
54528 + return 0;
54529 +
54530 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54531 + gr_log_learn_id_change('u', real, effective, fs);
54532 +
54533 + num = current->acl->user_trans_num;
54534 + uidlist = current->acl->user_transitions;
54535 +
54536 + if (uidlist == NULL)
54537 + return 0;
54538 +
54539 + if (real == -1)
54540 + realok = 1;
54541 + if (effective == -1)
54542 + effectiveok = 1;
54543 + if (fs == -1)
54544 + fsok = 1;
54545 +
54546 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54547 + for (i = 0; i < num; i++) {
54548 + curuid = (int)uidlist[i];
54549 + if (real == curuid)
54550 + realok = 1;
54551 + if (effective == curuid)
54552 + effectiveok = 1;
54553 + if (fs == curuid)
54554 + fsok = 1;
54555 + }
54556 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54557 + for (i = 0; i < num; i++) {
54558 + curuid = (int)uidlist[i];
54559 + if (real == curuid)
54560 + break;
54561 + if (effective == curuid)
54562 + break;
54563 + if (fs == curuid)
54564 + break;
54565 + }
54566 + /* not in deny list */
54567 + if (i == num) {
54568 + realok = 1;
54569 + effectiveok = 1;
54570 + fsok = 1;
54571 + }
54572 + }
54573 +
54574 + if (realok && effectiveok && fsok)
54575 + return 0;
54576 + else {
54577 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54578 + return 1;
54579 + }
54580 +}
54581 +
54582 +int
54583 +gr_check_group_change(int real, int effective, int fs)
54584 +{
54585 + unsigned int i;
54586 + __u16 num;
54587 + gid_t *gidlist;
54588 + int curgid;
54589 + int realok = 0;
54590 + int effectiveok = 0;
54591 + int fsok = 0;
54592 +
54593 + if (unlikely(!(gr_status & GR_READY)))
54594 + return 0;
54595 +
54596 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54597 + gr_log_learn_id_change('g', real, effective, fs);
54598 +
54599 + num = current->acl->group_trans_num;
54600 + gidlist = current->acl->group_transitions;
54601 +
54602 + if (gidlist == NULL)
54603 + return 0;
54604 +
54605 + if (real == -1)
54606 + realok = 1;
54607 + if (effective == -1)
54608 + effectiveok = 1;
54609 + if (fs == -1)
54610 + fsok = 1;
54611 +
54612 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54613 + for (i = 0; i < num; i++) {
54614 + curgid = (int)gidlist[i];
54615 + if (real == curgid)
54616 + realok = 1;
54617 + if (effective == curgid)
54618 + effectiveok = 1;
54619 + if (fs == curgid)
54620 + fsok = 1;
54621 + }
54622 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54623 + for (i = 0; i < num; i++) {
54624 + curgid = (int)gidlist[i];
54625 + if (real == curgid)
54626 + break;
54627 + if (effective == curgid)
54628 + break;
54629 + if (fs == curgid)
54630 + break;
54631 + }
54632 + /* not in deny list */
54633 + if (i == num) {
54634 + realok = 1;
54635 + effectiveok = 1;
54636 + fsok = 1;
54637 + }
54638 + }
54639 +
54640 + if (realok && effectiveok && fsok)
54641 + return 0;
54642 + else {
54643 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54644 + return 1;
54645 + }
54646 +}
54647 +
54648 +extern int gr_acl_is_capable(const int cap);
54649 +
54650 +void
54651 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54652 +{
54653 + struct acl_role_label *role = task->role;
54654 + struct acl_subject_label *subj = NULL;
54655 + struct acl_object_label *obj;
54656 + struct file *filp;
54657 +
54658 + if (unlikely(!(gr_status & GR_READY)))
54659 + return;
54660 +
54661 + filp = task->exec_file;
54662 +
54663 + /* kernel process, we'll give them the kernel role */
54664 + if (unlikely(!filp)) {
54665 + task->role = kernel_role;
54666 + task->acl = kernel_role->root_label;
54667 + return;
54668 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54669 + role = lookup_acl_role_label(task, uid, gid);
54670 +
54671 + /* don't change the role if we're not a privileged process */
54672 + if (role && task->role != role &&
54673 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54674 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54675 + return;
54676 +
54677 + /* perform subject lookup in possibly new role
54678 + we can use this result below in the case where role == task->role
54679 + */
54680 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54681 +
54682 + /* if we changed uid/gid, but result in the same role
54683 + and are using inheritance, don't lose the inherited subject
54684 + if current subject is other than what normal lookup
54685 + would result in, we arrived via inheritance, don't
54686 + lose subject
54687 + */
54688 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54689 + (subj == task->acl)))
54690 + task->acl = subj;
54691 +
54692 + task->role = role;
54693 +
54694 + task->is_writable = 0;
54695 +
54696 + /* ignore additional mmap checks for processes that are writable
54697 + by the default ACL */
54698 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54699 + if (unlikely(obj->mode & GR_WRITE))
54700 + task->is_writable = 1;
54701 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54702 + if (unlikely(obj->mode & GR_WRITE))
54703 + task->is_writable = 1;
54704 +
54705 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54706 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54707 +#endif
54708 +
54709 + gr_set_proc_res(task);
54710 +
54711 + return;
54712 +}
54713 +
54714 +int
54715 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54716 + const int unsafe_flags)
54717 +{
54718 + struct task_struct *task = current;
54719 + struct acl_subject_label *newacl;
54720 + struct acl_object_label *obj;
54721 + __u32 retmode;
54722 +
54723 + if (unlikely(!(gr_status & GR_READY)))
54724 + return 0;
54725 +
54726 + newacl = chk_subj_label(dentry, mnt, task->role);
54727 +
54728 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54729 + did an exec
54730 + */
54731 + rcu_read_lock();
54732 + read_lock(&tasklist_lock);
54733 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54734 + (task->parent->acl->mode & GR_POVERRIDE))) {
54735 + read_unlock(&tasklist_lock);
54736 + rcu_read_unlock();
54737 + goto skip_check;
54738 + }
54739 + read_unlock(&tasklist_lock);
54740 + rcu_read_unlock();
54741 +
54742 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54743 + !(task->role->roletype & GR_ROLE_GOD) &&
54744 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54745 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54746 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54747 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54748 + else
54749 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54750 + return -EACCES;
54751 + }
54752 +
54753 +skip_check:
54754 +
54755 + obj = chk_obj_label(dentry, mnt, task->acl);
54756 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54757 +
54758 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54759 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54760 + if (obj->nested)
54761 + task->acl = obj->nested;
54762 + else
54763 + task->acl = newacl;
54764 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54765 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54766 +
54767 + task->is_writable = 0;
54768 +
54769 + /* ignore additional mmap checks for processes that are writable
54770 + by the default ACL */
54771 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54772 + if (unlikely(obj->mode & GR_WRITE))
54773 + task->is_writable = 1;
54774 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54775 + if (unlikely(obj->mode & GR_WRITE))
54776 + task->is_writable = 1;
54777 +
54778 + gr_set_proc_res(task);
54779 +
54780 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54781 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54782 +#endif
54783 + return 0;
54784 +}
54785 +
54786 +/* always called with valid inodev ptr */
54787 +static void
54788 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54789 +{
54790 + struct acl_object_label *matchpo;
54791 + struct acl_subject_label *matchps;
54792 + struct acl_subject_label *subj;
54793 + struct acl_role_label *role;
54794 + unsigned int x;
54795 +
54796 + FOR_EACH_ROLE_START(role)
54797 + FOR_EACH_SUBJECT_START(role, subj, x)
54798 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54799 + matchpo->mode |= GR_DELETED;
54800 + FOR_EACH_SUBJECT_END(subj,x)
54801 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54802 + /* nested subjects aren't in the role's subj_hash table */
54803 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54804 + matchpo->mode |= GR_DELETED;
54805 + FOR_EACH_NESTED_SUBJECT_END(subj)
54806 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54807 + matchps->mode |= GR_DELETED;
54808 + FOR_EACH_ROLE_END(role)
54809 +
54810 + inodev->nentry->deleted = 1;
54811 +
54812 + return;
54813 +}
54814 +
54815 +void
54816 +gr_handle_delete(const ino_t ino, const dev_t dev)
54817 +{
54818 + struct inodev_entry *inodev;
54819 +
54820 + if (unlikely(!(gr_status & GR_READY)))
54821 + return;
54822 +
54823 + write_lock(&gr_inode_lock);
54824 + inodev = lookup_inodev_entry(ino, dev);
54825 + if (inodev != NULL)
54826 + do_handle_delete(inodev, ino, dev);
54827 + write_unlock(&gr_inode_lock);
54828 +
54829 + return;
54830 +}
54831 +
54832 +static void
54833 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54834 + const ino_t newinode, const dev_t newdevice,
54835 + struct acl_subject_label *subj)
54836 +{
54837 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54838 + struct acl_object_label *match;
54839 +
54840 + match = subj->obj_hash[index];
54841 +
54842 + while (match && (match->inode != oldinode ||
54843 + match->device != olddevice ||
54844 + !(match->mode & GR_DELETED)))
54845 + match = match->next;
54846 +
54847 + if (match && (match->inode == oldinode)
54848 + && (match->device == olddevice)
54849 + && (match->mode & GR_DELETED)) {
54850 + if (match->prev == NULL) {
54851 + subj->obj_hash[index] = match->next;
54852 + if (match->next != NULL)
54853 + match->next->prev = NULL;
54854 + } else {
54855 + match->prev->next = match->next;
54856 + if (match->next != NULL)
54857 + match->next->prev = match->prev;
54858 + }
54859 + match->prev = NULL;
54860 + match->next = NULL;
54861 + match->inode = newinode;
54862 + match->device = newdevice;
54863 + match->mode &= ~GR_DELETED;
54864 +
54865 + insert_acl_obj_label(match, subj);
54866 + }
54867 +
54868 + return;
54869 +}
54870 +
54871 +static void
54872 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54873 + const ino_t newinode, const dev_t newdevice,
54874 + struct acl_role_label *role)
54875 +{
54876 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54877 + struct acl_subject_label *match;
54878 +
54879 + match = role->subj_hash[index];
54880 +
54881 + while (match && (match->inode != oldinode ||
54882 + match->device != olddevice ||
54883 + !(match->mode & GR_DELETED)))
54884 + match = match->next;
54885 +
54886 + if (match && (match->inode == oldinode)
54887 + && (match->device == olddevice)
54888 + && (match->mode & GR_DELETED)) {
54889 + if (match->prev == NULL) {
54890 + role->subj_hash[index] = match->next;
54891 + if (match->next != NULL)
54892 + match->next->prev = NULL;
54893 + } else {
54894 + match->prev->next = match->next;
54895 + if (match->next != NULL)
54896 + match->next->prev = match->prev;
54897 + }
54898 + match->prev = NULL;
54899 + match->next = NULL;
54900 + match->inode = newinode;
54901 + match->device = newdevice;
54902 + match->mode &= ~GR_DELETED;
54903 +
54904 + insert_acl_subj_label(match, role);
54905 + }
54906 +
54907 + return;
54908 +}
54909 +
54910 +static void
54911 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54912 + const ino_t newinode, const dev_t newdevice)
54913 +{
54914 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54915 + struct inodev_entry *match;
54916 +
54917 + match = inodev_set.i_hash[index];
54918 +
54919 + while (match && (match->nentry->inode != oldinode ||
54920 + match->nentry->device != olddevice || !match->nentry->deleted))
54921 + match = match->next;
54922 +
54923 + if (match && (match->nentry->inode == oldinode)
54924 + && (match->nentry->device == olddevice) &&
54925 + match->nentry->deleted) {
54926 + if (match->prev == NULL) {
54927 + inodev_set.i_hash[index] = match->next;
54928 + if (match->next != NULL)
54929 + match->next->prev = NULL;
54930 + } else {
54931 + match->prev->next = match->next;
54932 + if (match->next != NULL)
54933 + match->next->prev = match->prev;
54934 + }
54935 + match->prev = NULL;
54936 + match->next = NULL;
54937 + match->nentry->inode = newinode;
54938 + match->nentry->device = newdevice;
54939 + match->nentry->deleted = 0;
54940 +
54941 + insert_inodev_entry(match);
54942 + }
54943 +
54944 + return;
54945 +}
54946 +
54947 +static void
54948 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54949 +{
54950 + struct acl_subject_label *subj;
54951 + struct acl_role_label *role;
54952 + unsigned int x;
54953 +
54954 + FOR_EACH_ROLE_START(role)
54955 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54956 +
54957 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54958 + if ((subj->inode == ino) && (subj->device == dev)) {
54959 + subj->inode = ino;
54960 + subj->device = dev;
54961 + }
54962 + /* nested subjects aren't in the role's subj_hash table */
54963 + update_acl_obj_label(matchn->inode, matchn->device,
54964 + ino, dev, subj);
54965 + FOR_EACH_NESTED_SUBJECT_END(subj)
54966 + FOR_EACH_SUBJECT_START(role, subj, x)
54967 + update_acl_obj_label(matchn->inode, matchn->device,
54968 + ino, dev, subj);
54969 + FOR_EACH_SUBJECT_END(subj,x)
54970 + FOR_EACH_ROLE_END(role)
54971 +
54972 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54973 +
54974 + return;
54975 +}
54976 +
54977 +static void
54978 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54979 + const struct vfsmount *mnt)
54980 +{
54981 + ino_t ino = dentry->d_inode->i_ino;
54982 + dev_t dev = __get_dev(dentry);
54983 +
54984 + __do_handle_create(matchn, ino, dev);
54985 +
54986 + return;
54987 +}
54988 +
54989 +void
54990 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54991 +{
54992 + struct name_entry *matchn;
54993 +
54994 + if (unlikely(!(gr_status & GR_READY)))
54995 + return;
54996 +
54997 + preempt_disable();
54998 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54999 +
55000 + if (unlikely((unsigned long)matchn)) {
55001 + write_lock(&gr_inode_lock);
55002 + do_handle_create(matchn, dentry, mnt);
55003 + write_unlock(&gr_inode_lock);
55004 + }
55005 + preempt_enable();
55006 +
55007 + return;
55008 +}
55009 +
55010 +void
55011 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
55012 +{
55013 + struct name_entry *matchn;
55014 +
55015 + if (unlikely(!(gr_status & GR_READY)))
55016 + return;
55017 +
55018 + preempt_disable();
55019 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
55020 +
55021 + if (unlikely((unsigned long)matchn)) {
55022 + write_lock(&gr_inode_lock);
55023 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
55024 + write_unlock(&gr_inode_lock);
55025 + }
55026 + preempt_enable();
55027 +
55028 + return;
55029 +}
55030 +
55031 +void
55032 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
55033 + struct dentry *old_dentry,
55034 + struct dentry *new_dentry,
55035 + struct vfsmount *mnt, const __u8 replace)
55036 +{
55037 + struct name_entry *matchn;
55038 + struct inodev_entry *inodev;
55039 + struct inode *inode = new_dentry->d_inode;
55040 + ino_t old_ino = old_dentry->d_inode->i_ino;
55041 + dev_t old_dev = __get_dev(old_dentry);
55042 +
55043 + /* vfs_rename swaps the name and parent link for old_dentry and
55044 + new_dentry
55045 + at this point, old_dentry has the new name, parent link, and inode
55046 + for the renamed file
55047 + if a file is being replaced by a rename, new_dentry has the inode
55048 + and name for the replaced file
55049 + */
55050 +
55051 + if (unlikely(!(gr_status & GR_READY)))
55052 + return;
55053 +
55054 + preempt_disable();
55055 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
55056 +
55057 + /* we wouldn't have to check d_inode if it weren't for
55058 + NFS silly-renaming
55059 + */
55060 +
55061 + write_lock(&gr_inode_lock);
55062 + if (unlikely(replace && inode)) {
55063 + ino_t new_ino = inode->i_ino;
55064 + dev_t new_dev = __get_dev(new_dentry);
55065 +
55066 + inodev = lookup_inodev_entry(new_ino, new_dev);
55067 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
55068 + do_handle_delete(inodev, new_ino, new_dev);
55069 + }
55070 +
55071 + inodev = lookup_inodev_entry(old_ino, old_dev);
55072 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
55073 + do_handle_delete(inodev, old_ino, old_dev);
55074 +
55075 + if (unlikely((unsigned long)matchn))
55076 + do_handle_create(matchn, old_dentry, mnt);
55077 +
55078 + write_unlock(&gr_inode_lock);
55079 + preempt_enable();
55080 +
55081 + return;
55082 +}
55083 +
55084 +static int
55085 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
55086 + unsigned char **sum)
55087 +{
55088 + struct acl_role_label *r;
55089 + struct role_allowed_ip *ipp;
55090 + struct role_transition *trans;
55091 + unsigned int i;
55092 + int found = 0;
55093 + u32 curr_ip = current->signal->curr_ip;
55094 +
55095 + current->signal->saved_ip = curr_ip;
55096 +
55097 + /* check transition table */
55098 +
55099 + for (trans = current->role->transitions; trans; trans = trans->next) {
55100 + if (!strcmp(rolename, trans->rolename)) {
55101 + found = 1;
55102 + break;
55103 + }
55104 + }
55105 +
55106 + if (!found)
55107 + return 0;
55108 +
55109 + /* handle special roles that do not require authentication
55110 + and check ip */
55111 +
55112 + FOR_EACH_ROLE_START(r)
55113 + if (!strcmp(rolename, r->rolename) &&
55114 + (r->roletype & GR_ROLE_SPECIAL)) {
55115 + found = 0;
55116 + if (r->allowed_ips != NULL) {
55117 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
55118 + if ((ntohl(curr_ip) & ipp->netmask) ==
55119 + (ntohl(ipp->addr) & ipp->netmask))
55120 + found = 1;
55121 + }
55122 + } else
55123 + found = 2;
55124 + if (!found)
55125 + return 0;
55126 +
55127 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
55128 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
55129 + *salt = NULL;
55130 + *sum = NULL;
55131 + return 1;
55132 + }
55133 + }
55134 + FOR_EACH_ROLE_END(r)
55135 +
55136 + for (i = 0; i < num_sprole_pws; i++) {
55137 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
55138 + *salt = acl_special_roles[i]->salt;
55139 + *sum = acl_special_roles[i]->sum;
55140 + return 1;
55141 + }
55142 + }
55143 +
55144 + return 0;
55145 +}
55146 +
55147 +static void
55148 +assign_special_role(char *rolename)
55149 +{
55150 + struct acl_object_label *obj;
55151 + struct acl_role_label *r;
55152 + struct acl_role_label *assigned = NULL;
55153 + struct task_struct *tsk;
55154 + struct file *filp;
55155 +
55156 + FOR_EACH_ROLE_START(r)
55157 + if (!strcmp(rolename, r->rolename) &&
55158 + (r->roletype & GR_ROLE_SPECIAL)) {
55159 + assigned = r;
55160 + break;
55161 + }
55162 + FOR_EACH_ROLE_END(r)
55163 +
55164 + if (!assigned)
55165 + return;
55166 +
55167 + read_lock(&tasklist_lock);
55168 + read_lock(&grsec_exec_file_lock);
55169 +
55170 + tsk = current->real_parent;
55171 + if (tsk == NULL)
55172 + goto out_unlock;
55173 +
55174 + filp = tsk->exec_file;
55175 + if (filp == NULL)
55176 + goto out_unlock;
55177 +
55178 + tsk->is_writable = 0;
55179 +
55180 + tsk->acl_sp_role = 1;
55181 + tsk->acl_role_id = ++acl_sp_role_value;
55182 + tsk->role = assigned;
55183 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
55184 +
55185 + /* ignore additional mmap checks for processes that are writable
55186 + by the default ACL */
55187 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55188 + if (unlikely(obj->mode & GR_WRITE))
55189 + tsk->is_writable = 1;
55190 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
55191 + if (unlikely(obj->mode & GR_WRITE))
55192 + tsk->is_writable = 1;
55193 +
55194 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55195 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
55196 +#endif
55197 +
55198 +out_unlock:
55199 + read_unlock(&grsec_exec_file_lock);
55200 + read_unlock(&tasklist_lock);
55201 + return;
55202 +}
55203 +
55204 +int gr_check_secure_terminal(struct task_struct *task)
55205 +{
55206 + struct task_struct *p, *p2, *p3;
55207 + struct files_struct *files;
55208 + struct fdtable *fdt;
55209 + struct file *our_file = NULL, *file;
55210 + int i;
55211 +
55212 + if (task->signal->tty == NULL)
55213 + return 1;
55214 +
55215 + files = get_files_struct(task);
55216 + if (files != NULL) {
55217 + rcu_read_lock();
55218 + fdt = files_fdtable(files);
55219 + for (i=0; i < fdt->max_fds; i++) {
55220 + file = fcheck_files(files, i);
55221 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
55222 + get_file(file);
55223 + our_file = file;
55224 + }
55225 + }
55226 + rcu_read_unlock();
55227 + put_files_struct(files);
55228 + }
55229 +
55230 + if (our_file == NULL)
55231 + return 1;
55232 +
55233 + read_lock(&tasklist_lock);
55234 + do_each_thread(p2, p) {
55235 + files = get_files_struct(p);
55236 + if (files == NULL ||
55237 + (p->signal && p->signal->tty == task->signal->tty)) {
55238 + if (files != NULL)
55239 + put_files_struct(files);
55240 + continue;
55241 + }
55242 + rcu_read_lock();
55243 + fdt = files_fdtable(files);
55244 + for (i=0; i < fdt->max_fds; i++) {
55245 + file = fcheck_files(files, i);
55246 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
55247 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
55248 + p3 = task;
55249 + while (p3->pid > 0) {
55250 + if (p3 == p)
55251 + break;
55252 + p3 = p3->real_parent;
55253 + }
55254 + if (p3 == p)
55255 + break;
55256 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
55257 + gr_handle_alertkill(p);
55258 + rcu_read_unlock();
55259 + put_files_struct(files);
55260 + read_unlock(&tasklist_lock);
55261 + fput(our_file);
55262 + return 0;
55263 + }
55264 + }
55265 + rcu_read_unlock();
55266 + put_files_struct(files);
55267 + } while_each_thread(p2, p);
55268 + read_unlock(&tasklist_lock);
55269 +
55270 + fput(our_file);
55271 + return 1;
55272 +}
55273 +
55274 +static int gr_rbac_disable(void *unused)
55275 +{
55276 + pax_open_kernel();
55277 + gr_status &= ~GR_READY;
55278 + pax_close_kernel();
55279 +
55280 + return 0;
55281 +}
55282 +
55283 +ssize_t
55284 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
55285 +{
55286 + struct gr_arg_wrapper uwrap;
55287 + unsigned char *sprole_salt = NULL;
55288 + unsigned char *sprole_sum = NULL;
55289 + int error = sizeof (struct gr_arg_wrapper);
55290 + int error2 = 0;
55291 +
55292 + mutex_lock(&gr_dev_mutex);
55293 +
55294 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
55295 + error = -EPERM;
55296 + goto out;
55297 + }
55298 +
55299 + if (count != sizeof (struct gr_arg_wrapper)) {
55300 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
55301 + error = -EINVAL;
55302 + goto out;
55303 + }
55304 +
55305 +
55306 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
55307 + gr_auth_expires = 0;
55308 + gr_auth_attempts = 0;
55309 + }
55310 +
55311 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
55312 + error = -EFAULT;
55313 + goto out;
55314 + }
55315 +
55316 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
55317 + error = -EINVAL;
55318 + goto out;
55319 + }
55320 +
55321 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
55322 + error = -EFAULT;
55323 + goto out;
55324 + }
55325 +
55326 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55327 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55328 + time_after(gr_auth_expires, get_seconds())) {
55329 + error = -EBUSY;
55330 + goto out;
55331 + }
55332 +
55333 + /* if non-root trying to do anything other than use a special role,
55334 + do not attempt authentication, do not count towards authentication
55335 + locking
55336 + */
55337 +
55338 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
55339 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55340 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
55341 + error = -EPERM;
55342 + goto out;
55343 + }
55344 +
55345 + /* ensure pw and special role name are null terminated */
55346 +
55347 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
55348 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
55349 +
55350 + /* Okay.
55351 + * We have our enough of the argument structure..(we have yet
55352 + * to copy_from_user the tables themselves) . Copy the tables
55353 + * only if we need them, i.e. for loading operations. */
55354 +
55355 + switch (gr_usermode->mode) {
55356 + case GR_STATUS:
55357 + if (gr_status & GR_READY) {
55358 + error = 1;
55359 + if (!gr_check_secure_terminal(current))
55360 + error = 3;
55361 + } else
55362 + error = 2;
55363 + goto out;
55364 + case GR_SHUTDOWN:
55365 + if ((gr_status & GR_READY)
55366 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55367 + stop_machine(gr_rbac_disable, NULL, NULL);
55368 + free_variables();
55369 + memset(gr_usermode, 0, sizeof (struct gr_arg));
55370 + memset(gr_system_salt, 0, GR_SALT_LEN);
55371 + memset(gr_system_sum, 0, GR_SHA_LEN);
55372 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
55373 + } else if (gr_status & GR_READY) {
55374 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
55375 + error = -EPERM;
55376 + } else {
55377 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
55378 + error = -EAGAIN;
55379 + }
55380 + break;
55381 + case GR_ENABLE:
55382 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
55383 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
55384 + else {
55385 + if (gr_status & GR_READY)
55386 + error = -EAGAIN;
55387 + else
55388 + error = error2;
55389 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
55390 + }
55391 + break;
55392 + case GR_RELOAD:
55393 + if (!(gr_status & GR_READY)) {
55394 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
55395 + error = -EAGAIN;
55396 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55397 + stop_machine(gr_rbac_disable, NULL, NULL);
55398 + free_variables();
55399 + error2 = gracl_init(gr_usermode);
55400 + if (!error2)
55401 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
55402 + else {
55403 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55404 + error = error2;
55405 + }
55406 + } else {
55407 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55408 + error = -EPERM;
55409 + }
55410 + break;
55411 + case GR_SEGVMOD:
55412 + if (unlikely(!(gr_status & GR_READY))) {
55413 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
55414 + error = -EAGAIN;
55415 + break;
55416 + }
55417 +
55418 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55419 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
55420 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
55421 + struct acl_subject_label *segvacl;
55422 + segvacl =
55423 + lookup_acl_subj_label(gr_usermode->segv_inode,
55424 + gr_usermode->segv_device,
55425 + current->role);
55426 + if (segvacl) {
55427 + segvacl->crashes = 0;
55428 + segvacl->expires = 0;
55429 + }
55430 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
55431 + gr_remove_uid(gr_usermode->segv_uid);
55432 + }
55433 + } else {
55434 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
55435 + error = -EPERM;
55436 + }
55437 + break;
55438 + case GR_SPROLE:
55439 + case GR_SPROLEPAM:
55440 + if (unlikely(!(gr_status & GR_READY))) {
55441 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
55442 + error = -EAGAIN;
55443 + break;
55444 + }
55445 +
55446 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
55447 + current->role->expires = 0;
55448 + current->role->auth_attempts = 0;
55449 + }
55450 +
55451 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55452 + time_after(current->role->expires, get_seconds())) {
55453 + error = -EBUSY;
55454 + goto out;
55455 + }
55456 +
55457 + if (lookup_special_role_auth
55458 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
55459 + && ((!sprole_salt && !sprole_sum)
55460 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
55461 + char *p = "";
55462 + assign_special_role(gr_usermode->sp_role);
55463 + read_lock(&tasklist_lock);
55464 + if (current->real_parent)
55465 + p = current->real_parent->role->rolename;
55466 + read_unlock(&tasklist_lock);
55467 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
55468 + p, acl_sp_role_value);
55469 + } else {
55470 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
55471 + error = -EPERM;
55472 + if(!(current->role->auth_attempts++))
55473 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55474 +
55475 + goto out;
55476 + }
55477 + break;
55478 + case GR_UNSPROLE:
55479 + if (unlikely(!(gr_status & GR_READY))) {
55480 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55481 + error = -EAGAIN;
55482 + break;
55483 + }
55484 +
55485 + if (current->role->roletype & GR_ROLE_SPECIAL) {
55486 + char *p = "";
55487 + int i = 0;
55488 +
55489 + read_lock(&tasklist_lock);
55490 + if (current->real_parent) {
55491 + p = current->real_parent->role->rolename;
55492 + i = current->real_parent->acl_role_id;
55493 + }
55494 + read_unlock(&tasklist_lock);
55495 +
55496 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55497 + gr_set_acls(1);
55498 + } else {
55499 + error = -EPERM;
55500 + goto out;
55501 + }
55502 + break;
55503 + default:
55504 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55505 + error = -EINVAL;
55506 + break;
55507 + }
55508 +
55509 + if (error != -EPERM)
55510 + goto out;
55511 +
55512 + if(!(gr_auth_attempts++))
55513 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55514 +
55515 + out:
55516 + mutex_unlock(&gr_dev_mutex);
55517 + return error;
55518 +}
55519 +
55520 +/* must be called with
55521 + rcu_read_lock();
55522 + read_lock(&tasklist_lock);
55523 + read_lock(&grsec_exec_file_lock);
55524 +*/
55525 +int gr_apply_subject_to_task(struct task_struct *task)
55526 +{
55527 + struct acl_object_label *obj;
55528 + char *tmpname;
55529 + struct acl_subject_label *tmpsubj;
55530 + struct file *filp;
55531 + struct name_entry *nmatch;
55532 +
55533 + filp = task->exec_file;
55534 + if (filp == NULL)
55535 + return 0;
55536 +
55537 + /* the following is to apply the correct subject
55538 + on binaries running when the RBAC system
55539 + is enabled, when the binaries have been
55540 + replaced or deleted since their execution
55541 + -----
55542 + when the RBAC system starts, the inode/dev
55543 + from exec_file will be one the RBAC system
55544 + is unaware of. It only knows the inode/dev
55545 + of the present file on disk, or the absence
55546 + of it.
55547 + */
55548 + preempt_disable();
55549 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55550 +
55551 + nmatch = lookup_name_entry(tmpname);
55552 + preempt_enable();
55553 + tmpsubj = NULL;
55554 + if (nmatch) {
55555 + if (nmatch->deleted)
55556 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55557 + else
55558 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55559 + if (tmpsubj != NULL)
55560 + task->acl = tmpsubj;
55561 + }
55562 + if (tmpsubj == NULL)
55563 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55564 + task->role);
55565 + if (task->acl) {
55566 + task->is_writable = 0;
55567 + /* ignore additional mmap checks for processes that are writable
55568 + by the default ACL */
55569 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55570 + if (unlikely(obj->mode & GR_WRITE))
55571 + task->is_writable = 1;
55572 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55573 + if (unlikely(obj->mode & GR_WRITE))
55574 + task->is_writable = 1;
55575 +
55576 + gr_set_proc_res(task);
55577 +
55578 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55579 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55580 +#endif
55581 + } else {
55582 + return 1;
55583 + }
55584 +
55585 + return 0;
55586 +}
55587 +
55588 +int
55589 +gr_set_acls(const int type)
55590 +{
55591 + struct task_struct *task, *task2;
55592 + struct acl_role_label *role = current->role;
55593 + __u16 acl_role_id = current->acl_role_id;
55594 + const struct cred *cred;
55595 + int ret;
55596 +
55597 + rcu_read_lock();
55598 + read_lock(&tasklist_lock);
55599 + read_lock(&grsec_exec_file_lock);
55600 + do_each_thread(task2, task) {
55601 + /* check to see if we're called from the exit handler,
55602 + if so, only replace ACLs that have inherited the admin
55603 + ACL */
55604 +
55605 + if (type && (task->role != role ||
55606 + task->acl_role_id != acl_role_id))
55607 + continue;
55608 +
55609 + task->acl_role_id = 0;
55610 + task->acl_sp_role = 0;
55611 +
55612 + if (task->exec_file) {
55613 + cred = __task_cred(task);
55614 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55615 + ret = gr_apply_subject_to_task(task);
55616 + if (ret) {
55617 + read_unlock(&grsec_exec_file_lock);
55618 + read_unlock(&tasklist_lock);
55619 + rcu_read_unlock();
55620 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55621 + return ret;
55622 + }
55623 + } else {
55624 + // it's a kernel process
55625 + task->role = kernel_role;
55626 + task->acl = kernel_role->root_label;
55627 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55628 + task->acl->mode &= ~GR_PROCFIND;
55629 +#endif
55630 + }
55631 + } while_each_thread(task2, task);
55632 + read_unlock(&grsec_exec_file_lock);
55633 + read_unlock(&tasklist_lock);
55634 + rcu_read_unlock();
55635 +
55636 + return 0;
55637 +}
55638 +
55639 +void
55640 +gr_learn_resource(const struct task_struct *task,
55641 + const int res, const unsigned long wanted, const int gt)
55642 +{
55643 + struct acl_subject_label *acl;
55644 + const struct cred *cred;
55645 +
55646 + if (unlikely((gr_status & GR_READY) &&
55647 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55648 + goto skip_reslog;
55649 +
55650 +#ifdef CONFIG_GRKERNSEC_RESLOG
55651 + gr_log_resource(task, res, wanted, gt);
55652 +#endif
55653 + skip_reslog:
55654 +
55655 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55656 + return;
55657 +
55658 + acl = task->acl;
55659 +
55660 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55661 + !(acl->resmask & (1 << (unsigned short) res))))
55662 + return;
55663 +
55664 + if (wanted >= acl->res[res].rlim_cur) {
55665 + unsigned long res_add;
55666 +
55667 + res_add = wanted;
55668 + switch (res) {
55669 + case RLIMIT_CPU:
55670 + res_add += GR_RLIM_CPU_BUMP;
55671 + break;
55672 + case RLIMIT_FSIZE:
55673 + res_add += GR_RLIM_FSIZE_BUMP;
55674 + break;
55675 + case RLIMIT_DATA:
55676 + res_add += GR_RLIM_DATA_BUMP;
55677 + break;
55678 + case RLIMIT_STACK:
55679 + res_add += GR_RLIM_STACK_BUMP;
55680 + break;
55681 + case RLIMIT_CORE:
55682 + res_add += GR_RLIM_CORE_BUMP;
55683 + break;
55684 + case RLIMIT_RSS:
55685 + res_add += GR_RLIM_RSS_BUMP;
55686 + break;
55687 + case RLIMIT_NPROC:
55688 + res_add += GR_RLIM_NPROC_BUMP;
55689 + break;
55690 + case RLIMIT_NOFILE:
55691 + res_add += GR_RLIM_NOFILE_BUMP;
55692 + break;
55693 + case RLIMIT_MEMLOCK:
55694 + res_add += GR_RLIM_MEMLOCK_BUMP;
55695 + break;
55696 + case RLIMIT_AS:
55697 + res_add += GR_RLIM_AS_BUMP;
55698 + break;
55699 + case RLIMIT_LOCKS:
55700 + res_add += GR_RLIM_LOCKS_BUMP;
55701 + break;
55702 + case RLIMIT_SIGPENDING:
55703 + res_add += GR_RLIM_SIGPENDING_BUMP;
55704 + break;
55705 + case RLIMIT_MSGQUEUE:
55706 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55707 + break;
55708 + case RLIMIT_NICE:
55709 + res_add += GR_RLIM_NICE_BUMP;
55710 + break;
55711 + case RLIMIT_RTPRIO:
55712 + res_add += GR_RLIM_RTPRIO_BUMP;
55713 + break;
55714 + case RLIMIT_RTTIME:
55715 + res_add += GR_RLIM_RTTIME_BUMP;
55716 + break;
55717 + }
55718 +
55719 + acl->res[res].rlim_cur = res_add;
55720 +
55721 + if (wanted > acl->res[res].rlim_max)
55722 + acl->res[res].rlim_max = res_add;
55723 +
55724 + /* only log the subject filename, since resource logging is supported for
55725 + single-subject learning only */
55726 + rcu_read_lock();
55727 + cred = __task_cred(task);
55728 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55729 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55730 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55731 + "", (unsigned long) res, &task->signal->saved_ip);
55732 + rcu_read_unlock();
55733 + }
55734 +
55735 + return;
55736 +}
55737 +
55738 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55739 +void
55740 +pax_set_initial_flags(struct linux_binprm *bprm)
55741 +{
55742 + struct task_struct *task = current;
55743 + struct acl_subject_label *proc;
55744 + unsigned long flags;
55745 +
55746 + if (unlikely(!(gr_status & GR_READY)))
55747 + return;
55748 +
55749 + flags = pax_get_flags(task);
55750 +
55751 + proc = task->acl;
55752 +
55753 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55754 + flags &= ~MF_PAX_PAGEEXEC;
55755 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55756 + flags &= ~MF_PAX_SEGMEXEC;
55757 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55758 + flags &= ~MF_PAX_RANDMMAP;
55759 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55760 + flags &= ~MF_PAX_EMUTRAMP;
55761 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55762 + flags &= ~MF_PAX_MPROTECT;
55763 +
55764 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55765 + flags |= MF_PAX_PAGEEXEC;
55766 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55767 + flags |= MF_PAX_SEGMEXEC;
55768 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55769 + flags |= MF_PAX_RANDMMAP;
55770 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55771 + flags |= MF_PAX_EMUTRAMP;
55772 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55773 + flags |= MF_PAX_MPROTECT;
55774 +
55775 + pax_set_flags(task, flags);
55776 +
55777 + return;
55778 +}
55779 +#endif
55780 +
55781 +int
55782 +gr_handle_proc_ptrace(struct task_struct *task)
55783 +{
55784 + struct file *filp;
55785 + struct task_struct *tmp = task;
55786 + struct task_struct *curtemp = current;
55787 + __u32 retmode;
55788 +
55789 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55790 + if (unlikely(!(gr_status & GR_READY)))
55791 + return 0;
55792 +#endif
55793 +
55794 + read_lock(&tasklist_lock);
55795 + read_lock(&grsec_exec_file_lock);
55796 + filp = task->exec_file;
55797 +
55798 + while (tmp->pid > 0) {
55799 + if (tmp == curtemp)
55800 + break;
55801 + tmp = tmp->real_parent;
55802 + }
55803 +
55804 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55805 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55806 + read_unlock(&grsec_exec_file_lock);
55807 + read_unlock(&tasklist_lock);
55808 + return 1;
55809 + }
55810 +
55811 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55812 + if (!(gr_status & GR_READY)) {
55813 + read_unlock(&grsec_exec_file_lock);
55814 + read_unlock(&tasklist_lock);
55815 + return 0;
55816 + }
55817 +#endif
55818 +
55819 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55820 + read_unlock(&grsec_exec_file_lock);
55821 + read_unlock(&tasklist_lock);
55822 +
55823 + if (retmode & GR_NOPTRACE)
55824 + return 1;
55825 +
55826 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55827 + && (current->acl != task->acl || (current->acl != current->role->root_label
55828 + && current->pid != task->pid)))
55829 + return 1;
55830 +
55831 + return 0;
55832 +}
55833 +
55834 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55835 +{
55836 + if (unlikely(!(gr_status & GR_READY)))
55837 + return;
55838 +
55839 + if (!(current->role->roletype & GR_ROLE_GOD))
55840 + return;
55841 +
55842 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55843 + p->role->rolename, gr_task_roletype_to_char(p),
55844 + p->acl->filename);
55845 +}
55846 +
55847 +int
55848 +gr_handle_ptrace(struct task_struct *task, const long request)
55849 +{
55850 + struct task_struct *tmp = task;
55851 + struct task_struct *curtemp = current;
55852 + __u32 retmode;
55853 +
55854 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55855 + if (unlikely(!(gr_status & GR_READY)))
55856 + return 0;
55857 +#endif
55858 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55859 + read_lock(&tasklist_lock);
55860 + while (tmp->pid > 0) {
55861 + if (tmp == curtemp)
55862 + break;
55863 + tmp = tmp->real_parent;
55864 + }
55865 +
55866 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55867 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55868 + read_unlock(&tasklist_lock);
55869 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55870 + return 1;
55871 + }
55872 + read_unlock(&tasklist_lock);
55873 + }
55874 +
55875 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55876 + if (!(gr_status & GR_READY))
55877 + return 0;
55878 +#endif
55879 +
55880 + read_lock(&grsec_exec_file_lock);
55881 + if (unlikely(!task->exec_file)) {
55882 + read_unlock(&grsec_exec_file_lock);
55883 + return 0;
55884 + }
55885 +
55886 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55887 + read_unlock(&grsec_exec_file_lock);
55888 +
55889 + if (retmode & GR_NOPTRACE) {
55890 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55891 + return 1;
55892 + }
55893 +
55894 + if (retmode & GR_PTRACERD) {
55895 + switch (request) {
55896 + case PTRACE_SEIZE:
55897 + case PTRACE_POKETEXT:
55898 + case PTRACE_POKEDATA:
55899 + case PTRACE_POKEUSR:
55900 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55901 + case PTRACE_SETREGS:
55902 + case PTRACE_SETFPREGS:
55903 +#endif
55904 +#ifdef CONFIG_X86
55905 + case PTRACE_SETFPXREGS:
55906 +#endif
55907 +#ifdef CONFIG_ALTIVEC
55908 + case PTRACE_SETVRREGS:
55909 +#endif
55910 + return 1;
55911 + default:
55912 + return 0;
55913 + }
55914 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55915 + !(current->role->roletype & GR_ROLE_GOD) &&
55916 + (current->acl != task->acl)) {
55917 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55918 + return 1;
55919 + }
55920 +
55921 + return 0;
55922 +}
55923 +
55924 +static int is_writable_mmap(const struct file *filp)
55925 +{
55926 + struct task_struct *task = current;
55927 + struct acl_object_label *obj, *obj2;
55928 +
55929 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55930 + !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))) {
55931 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55932 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55933 + task->role->root_label);
55934 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55935 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55936 + return 1;
55937 + }
55938 + }
55939 + return 0;
55940 +}
55941 +
55942 +int
55943 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55944 +{
55945 + __u32 mode;
55946 +
55947 + if (unlikely(!file || !(prot & PROT_EXEC)))
55948 + return 1;
55949 +
55950 + if (is_writable_mmap(file))
55951 + return 0;
55952 +
55953 + mode =
55954 + gr_search_file(file->f_path.dentry,
55955 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55956 + file->f_path.mnt);
55957 +
55958 + if (!gr_tpe_allow(file))
55959 + return 0;
55960 +
55961 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55962 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55963 + return 0;
55964 + } else if (unlikely(!(mode & GR_EXEC))) {
55965 + return 0;
55966 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55967 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55968 + return 1;
55969 + }
55970 +
55971 + return 1;
55972 +}
55973 +
55974 +int
55975 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55976 +{
55977 + __u32 mode;
55978 +
55979 + if (unlikely(!file || !(prot & PROT_EXEC)))
55980 + return 1;
55981 +
55982 + if (is_writable_mmap(file))
55983 + return 0;
55984 +
55985 + mode =
55986 + gr_search_file(file->f_path.dentry,
55987 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55988 + file->f_path.mnt);
55989 +
55990 + if (!gr_tpe_allow(file))
55991 + return 0;
55992 +
55993 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55994 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55995 + return 0;
55996 + } else if (unlikely(!(mode & GR_EXEC))) {
55997 + return 0;
55998 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55999 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
56000 + return 1;
56001 + }
56002 +
56003 + return 1;
56004 +}
56005 +
56006 +void
56007 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56008 +{
56009 + unsigned long runtime;
56010 + unsigned long cputime;
56011 + unsigned int wday, cday;
56012 + __u8 whr, chr;
56013 + __u8 wmin, cmin;
56014 + __u8 wsec, csec;
56015 + struct timespec timeval;
56016 +
56017 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
56018 + !(task->acl->mode & GR_PROCACCT)))
56019 + return;
56020 +
56021 + do_posix_clock_monotonic_gettime(&timeval);
56022 + runtime = timeval.tv_sec - task->start_time.tv_sec;
56023 + wday = runtime / (3600 * 24);
56024 + runtime -= wday * (3600 * 24);
56025 + whr = runtime / 3600;
56026 + runtime -= whr * 3600;
56027 + wmin = runtime / 60;
56028 + runtime -= wmin * 60;
56029 + wsec = runtime;
56030 +
56031 + cputime = (task->utime + task->stime) / HZ;
56032 + cday = cputime / (3600 * 24);
56033 + cputime -= cday * (3600 * 24);
56034 + chr = cputime / 3600;
56035 + cputime -= chr * 3600;
56036 + cmin = cputime / 60;
56037 + cputime -= cmin * 60;
56038 + csec = cputime;
56039 +
56040 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
56041 +
56042 + return;
56043 +}
56044 +
56045 +void gr_set_kernel_label(struct task_struct *task)
56046 +{
56047 + if (gr_status & GR_READY) {
56048 + task->role = kernel_role;
56049 + task->acl = kernel_role->root_label;
56050 + }
56051 + return;
56052 +}
56053 +
56054 +#ifdef CONFIG_TASKSTATS
56055 +int gr_is_taskstats_denied(int pid)
56056 +{
56057 + struct task_struct *task;
56058 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56059 + const struct cred *cred;
56060 +#endif
56061 + int ret = 0;
56062 +
56063 + /* restrict taskstats viewing to un-chrooted root users
56064 + who have the 'view' subject flag if the RBAC system is enabled
56065 + */
56066 +
56067 + rcu_read_lock();
56068 + read_lock(&tasklist_lock);
56069 + task = find_task_by_vpid(pid);
56070 + if (task) {
56071 +#ifdef CONFIG_GRKERNSEC_CHROOT
56072 + if (proc_is_chrooted(task))
56073 + ret = -EACCES;
56074 +#endif
56075 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56076 + cred = __task_cred(task);
56077 +#ifdef CONFIG_GRKERNSEC_PROC_USER
56078 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
56079 + ret = -EACCES;
56080 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56081 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
56082 + ret = -EACCES;
56083 +#endif
56084 +#endif
56085 + if (gr_status & GR_READY) {
56086 + if (!(task->acl->mode & GR_VIEW))
56087 + ret = -EACCES;
56088 + }
56089 + } else
56090 + ret = -ENOENT;
56091 +
56092 + read_unlock(&tasklist_lock);
56093 + rcu_read_unlock();
56094 +
56095 + return ret;
56096 +}
56097 +#endif
56098 +
56099 +/* AUXV entries are filled via a descendant of search_binary_handler
56100 + after we've already applied the subject for the target
56101 +*/
56102 +int gr_acl_enable_at_secure(void)
56103 +{
56104 + if (unlikely(!(gr_status & GR_READY)))
56105 + return 0;
56106 +
56107 + if (current->acl->mode & GR_ATSECURE)
56108 + return 1;
56109 +
56110 + return 0;
56111 +}
56112 +
56113 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
56114 +{
56115 + struct task_struct *task = current;
56116 + struct dentry *dentry = file->f_path.dentry;
56117 + struct vfsmount *mnt = file->f_path.mnt;
56118 + struct acl_object_label *obj, *tmp;
56119 + struct acl_subject_label *subj;
56120 + unsigned int bufsize;
56121 + int is_not_root;
56122 + char *path;
56123 + dev_t dev = __get_dev(dentry);
56124 +
56125 + if (unlikely(!(gr_status & GR_READY)))
56126 + return 1;
56127 +
56128 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56129 + return 1;
56130 +
56131 + /* ignore Eric Biederman */
56132 + if (IS_PRIVATE(dentry->d_inode))
56133 + return 1;
56134 +
56135 + subj = task->acl;
56136 + read_lock(&gr_inode_lock);
56137 + do {
56138 + obj = lookup_acl_obj_label(ino, dev, subj);
56139 + if (obj != NULL) {
56140 + read_unlock(&gr_inode_lock);
56141 + return (obj->mode & GR_FIND) ? 1 : 0;
56142 + }
56143 + } while ((subj = subj->parent_subject));
56144 + read_unlock(&gr_inode_lock);
56145 +
56146 + /* this is purely an optimization since we're looking for an object
56147 + for the directory we're doing a readdir on
56148 + if it's possible for any globbed object to match the entry we're
56149 + filling into the directory, then the object we find here will be
56150 + an anchor point with attached globbed objects
56151 + */
56152 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
56153 + if (obj->globbed == NULL)
56154 + return (obj->mode & GR_FIND) ? 1 : 0;
56155 +
56156 + is_not_root = ((obj->filename[0] == '/') &&
56157 + (obj->filename[1] == '\0')) ? 0 : 1;
56158 + bufsize = PAGE_SIZE - namelen - is_not_root;
56159 +
56160 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
56161 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
56162 + return 1;
56163 +
56164 + preempt_disable();
56165 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
56166 + bufsize);
56167 +
56168 + bufsize = strlen(path);
56169 +
56170 + /* if base is "/", don't append an additional slash */
56171 + if (is_not_root)
56172 + *(path + bufsize) = '/';
56173 + memcpy(path + bufsize + is_not_root, name, namelen);
56174 + *(path + bufsize + namelen + is_not_root) = '\0';
56175 +
56176 + tmp = obj->globbed;
56177 + while (tmp) {
56178 + if (!glob_match(tmp->filename, path)) {
56179 + preempt_enable();
56180 + return (tmp->mode & GR_FIND) ? 1 : 0;
56181 + }
56182 + tmp = tmp->next;
56183 + }
56184 + preempt_enable();
56185 + return (obj->mode & GR_FIND) ? 1 : 0;
56186 +}
56187 +
56188 +void gr_put_exec_file(struct task_struct *task)
56189 +{
56190 + struct file *filp;
56191 +
56192 + write_lock(&grsec_exec_file_lock);
56193 + filp = task->exec_file;
56194 + task->exec_file = NULL;
56195 + write_unlock(&grsec_exec_file_lock);
56196 +
56197 + if (filp)
56198 + fput(filp);
56199 +
56200 + return;
56201 +}
56202 +
56203 +
56204 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
56205 +EXPORT_SYMBOL(gr_acl_is_enabled);
56206 +#endif
56207 +EXPORT_SYMBOL(gr_learn_resource);
56208 +EXPORT_SYMBOL(gr_set_kernel_label);
56209 +#ifdef CONFIG_SECURITY
56210 +EXPORT_SYMBOL(gr_check_user_change);
56211 +EXPORT_SYMBOL(gr_check_group_change);
56212 +#endif
56213 +
56214 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
56215 new file mode 100644
56216 index 0000000..34fefda
56217 --- /dev/null
56218 +++ b/grsecurity/gracl_alloc.c
56219 @@ -0,0 +1,105 @@
56220 +#include <linux/kernel.h>
56221 +#include <linux/mm.h>
56222 +#include <linux/slab.h>
56223 +#include <linux/vmalloc.h>
56224 +#include <linux/gracl.h>
56225 +#include <linux/grsecurity.h>
56226 +
56227 +static unsigned long alloc_stack_next = 1;
56228 +static unsigned long alloc_stack_size = 1;
56229 +static void **alloc_stack;
56230 +
56231 +static __inline__ int
56232 +alloc_pop(void)
56233 +{
56234 + if (alloc_stack_next == 1)
56235 + return 0;
56236 +
56237 + kfree(alloc_stack[alloc_stack_next - 2]);
56238 +
56239 + alloc_stack_next--;
56240 +
56241 + return 1;
56242 +}
56243 +
56244 +static __inline__ int
56245 +alloc_push(void *buf)
56246 +{
56247 + if (alloc_stack_next >= alloc_stack_size)
56248 + return 1;
56249 +
56250 + alloc_stack[alloc_stack_next - 1] = buf;
56251 +
56252 + alloc_stack_next++;
56253 +
56254 + return 0;
56255 +}
56256 +
56257 +void *
56258 +acl_alloc(unsigned long len)
56259 +{
56260 + void *ret = NULL;
56261 +
56262 + if (!len || len > PAGE_SIZE)
56263 + goto out;
56264 +
56265 + ret = kmalloc(len, GFP_KERNEL);
56266 +
56267 + if (ret) {
56268 + if (alloc_push(ret)) {
56269 + kfree(ret);
56270 + ret = NULL;
56271 + }
56272 + }
56273 +
56274 +out:
56275 + return ret;
56276 +}
56277 +
56278 +void *
56279 +acl_alloc_num(unsigned long num, unsigned long len)
56280 +{
56281 + if (!len || (num > (PAGE_SIZE / len)))
56282 + return NULL;
56283 +
56284 + return acl_alloc(num * len);
56285 +}
56286 +
56287 +void
56288 +acl_free_all(void)
56289 +{
56290 + if (gr_acl_is_enabled() || !alloc_stack)
56291 + return;
56292 +
56293 + while (alloc_pop()) ;
56294 +
56295 + if (alloc_stack) {
56296 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
56297 + kfree(alloc_stack);
56298 + else
56299 + vfree(alloc_stack);
56300 + }
56301 +
56302 + alloc_stack = NULL;
56303 + alloc_stack_size = 1;
56304 + alloc_stack_next = 1;
56305 +
56306 + return;
56307 +}
56308 +
56309 +int
56310 +acl_alloc_stack_init(unsigned long size)
56311 +{
56312 + if ((size * sizeof (void *)) <= PAGE_SIZE)
56313 + alloc_stack =
56314 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
56315 + else
56316 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
56317 +
56318 + alloc_stack_size = size;
56319 +
56320 + if (!alloc_stack)
56321 + return 0;
56322 + else
56323 + return 1;
56324 +}
56325 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
56326 new file mode 100644
56327 index 0000000..6d21049
56328 --- /dev/null
56329 +++ b/grsecurity/gracl_cap.c
56330 @@ -0,0 +1,110 @@
56331 +#include <linux/kernel.h>
56332 +#include <linux/module.h>
56333 +#include <linux/sched.h>
56334 +#include <linux/gracl.h>
56335 +#include <linux/grsecurity.h>
56336 +#include <linux/grinternal.h>
56337 +
56338 +extern const char *captab_log[];
56339 +extern int captab_log_entries;
56340 +
56341 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56342 +{
56343 + struct acl_subject_label *curracl;
56344 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56345 + kernel_cap_t cap_audit = __cap_empty_set;
56346 +
56347 + if (!gr_acl_is_enabled())
56348 + return 1;
56349 +
56350 + curracl = task->acl;
56351 +
56352 + cap_drop = curracl->cap_lower;
56353 + cap_mask = curracl->cap_mask;
56354 + cap_audit = curracl->cap_invert_audit;
56355 +
56356 + while ((curracl = curracl->parent_subject)) {
56357 + /* if the cap isn't specified in the current computed mask but is specified in the
56358 + current level subject, and is lowered in the current level subject, then add
56359 + it to the set of dropped capabilities
56360 + otherwise, add the current level subject's mask to the current computed mask
56361 + */
56362 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56363 + cap_raise(cap_mask, cap);
56364 + if (cap_raised(curracl->cap_lower, cap))
56365 + cap_raise(cap_drop, cap);
56366 + if (cap_raised(curracl->cap_invert_audit, cap))
56367 + cap_raise(cap_audit, cap);
56368 + }
56369 + }
56370 +
56371 + if (!cap_raised(cap_drop, cap)) {
56372 + if (cap_raised(cap_audit, cap))
56373 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
56374 + return 1;
56375 + }
56376 +
56377 + curracl = task->acl;
56378 +
56379 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
56380 + && cap_raised(cred->cap_effective, cap)) {
56381 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56382 + task->role->roletype, cred->uid,
56383 + cred->gid, task->exec_file ?
56384 + gr_to_filename(task->exec_file->f_path.dentry,
56385 + task->exec_file->f_path.mnt) : curracl->filename,
56386 + curracl->filename, 0UL,
56387 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
56388 + return 1;
56389 + }
56390 +
56391 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
56392 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
56393 +
56394 + return 0;
56395 +}
56396 +
56397 +int
56398 +gr_acl_is_capable(const int cap)
56399 +{
56400 + return gr_task_acl_is_capable(current, current_cred(), cap);
56401 +}
56402 +
56403 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
56404 +{
56405 + struct acl_subject_label *curracl;
56406 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56407 +
56408 + if (!gr_acl_is_enabled())
56409 + return 1;
56410 +
56411 + curracl = task->acl;
56412 +
56413 + cap_drop = curracl->cap_lower;
56414 + cap_mask = curracl->cap_mask;
56415 +
56416 + while ((curracl = curracl->parent_subject)) {
56417 + /* if the cap isn't specified in the current computed mask but is specified in the
56418 + current level subject, and is lowered in the current level subject, then add
56419 + it to the set of dropped capabilities
56420 + otherwise, add the current level subject's mask to the current computed mask
56421 + */
56422 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56423 + cap_raise(cap_mask, cap);
56424 + if (cap_raised(curracl->cap_lower, cap))
56425 + cap_raise(cap_drop, cap);
56426 + }
56427 + }
56428 +
56429 + if (!cap_raised(cap_drop, cap))
56430 + return 1;
56431 +
56432 + return 0;
56433 +}
56434 +
56435 +int
56436 +gr_acl_is_capable_nolog(const int cap)
56437 +{
56438 + return gr_task_acl_is_capable_nolog(current, cap);
56439 +}
56440 +
56441 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
56442 new file mode 100644
56443 index 0000000..d28e241
56444 --- /dev/null
56445 +++ b/grsecurity/gracl_fs.c
56446 @@ -0,0 +1,437 @@
56447 +#include <linux/kernel.h>
56448 +#include <linux/sched.h>
56449 +#include <linux/types.h>
56450 +#include <linux/fs.h>
56451 +#include <linux/file.h>
56452 +#include <linux/stat.h>
56453 +#include <linux/grsecurity.h>
56454 +#include <linux/grinternal.h>
56455 +#include <linux/gracl.h>
56456 +
56457 +umode_t
56458 +gr_acl_umask(void)
56459 +{
56460 + if (unlikely(!gr_acl_is_enabled()))
56461 + return 0;
56462 +
56463 + return current->role->umask;
56464 +}
56465 +
56466 +__u32
56467 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56468 + const struct vfsmount * mnt)
56469 +{
56470 + __u32 mode;
56471 +
56472 + if (unlikely(!dentry->d_inode))
56473 + return GR_FIND;
56474 +
56475 + mode =
56476 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56477 +
56478 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56479 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56480 + return mode;
56481 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56482 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56483 + return 0;
56484 + } else if (unlikely(!(mode & GR_FIND)))
56485 + return 0;
56486 +
56487 + return GR_FIND;
56488 +}
56489 +
56490 +__u32
56491 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56492 + int acc_mode)
56493 +{
56494 + __u32 reqmode = GR_FIND;
56495 + __u32 mode;
56496 +
56497 + if (unlikely(!dentry->d_inode))
56498 + return reqmode;
56499 +
56500 + if (acc_mode & MAY_APPEND)
56501 + reqmode |= GR_APPEND;
56502 + else if (acc_mode & MAY_WRITE)
56503 + reqmode |= GR_WRITE;
56504 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56505 + reqmode |= GR_READ;
56506 +
56507 + mode =
56508 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56509 + mnt);
56510 +
56511 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56512 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56513 + reqmode & GR_READ ? " reading" : "",
56514 + reqmode & GR_WRITE ? " writing" : reqmode &
56515 + GR_APPEND ? " appending" : "");
56516 + return reqmode;
56517 + } else
56518 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56519 + {
56520 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56521 + reqmode & GR_READ ? " reading" : "",
56522 + reqmode & GR_WRITE ? " writing" : reqmode &
56523 + GR_APPEND ? " appending" : "");
56524 + return 0;
56525 + } else if (unlikely((mode & reqmode) != reqmode))
56526 + return 0;
56527 +
56528 + return reqmode;
56529 +}
56530 +
56531 +__u32
56532 +gr_acl_handle_creat(const struct dentry * dentry,
56533 + const struct dentry * p_dentry,
56534 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56535 + const int imode)
56536 +{
56537 + __u32 reqmode = GR_WRITE | GR_CREATE;
56538 + __u32 mode;
56539 +
56540 + if (acc_mode & MAY_APPEND)
56541 + reqmode |= GR_APPEND;
56542 + // if a directory was required or the directory already exists, then
56543 + // don't count this open as a read
56544 + if ((acc_mode & MAY_READ) &&
56545 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56546 + reqmode |= GR_READ;
56547 + if ((open_flags & O_CREAT) &&
56548 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56549 + reqmode |= GR_SETID;
56550 +
56551 + mode =
56552 + gr_check_create(dentry, p_dentry, p_mnt,
56553 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56554 +
56555 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56556 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56557 + reqmode & GR_READ ? " reading" : "",
56558 + reqmode & GR_WRITE ? " writing" : reqmode &
56559 + GR_APPEND ? " appending" : "");
56560 + return reqmode;
56561 + } else
56562 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56563 + {
56564 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56565 + reqmode & GR_READ ? " reading" : "",
56566 + reqmode & GR_WRITE ? " writing" : reqmode &
56567 + GR_APPEND ? " appending" : "");
56568 + return 0;
56569 + } else if (unlikely((mode & reqmode) != reqmode))
56570 + return 0;
56571 +
56572 + return reqmode;
56573 +}
56574 +
56575 +__u32
56576 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56577 + const int fmode)
56578 +{
56579 + __u32 mode, reqmode = GR_FIND;
56580 +
56581 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56582 + reqmode |= GR_EXEC;
56583 + if (fmode & S_IWOTH)
56584 + reqmode |= GR_WRITE;
56585 + if (fmode & S_IROTH)
56586 + reqmode |= GR_READ;
56587 +
56588 + mode =
56589 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56590 + mnt);
56591 +
56592 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56593 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56594 + reqmode & GR_READ ? " reading" : "",
56595 + reqmode & GR_WRITE ? " writing" : "",
56596 + reqmode & GR_EXEC ? " executing" : "");
56597 + return reqmode;
56598 + } else
56599 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56600 + {
56601 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56602 + reqmode & GR_READ ? " reading" : "",
56603 + reqmode & GR_WRITE ? " writing" : "",
56604 + reqmode & GR_EXEC ? " executing" : "");
56605 + return 0;
56606 + } else if (unlikely((mode & reqmode) != reqmode))
56607 + return 0;
56608 +
56609 + return reqmode;
56610 +}
56611 +
56612 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56613 +{
56614 + __u32 mode;
56615 +
56616 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56617 +
56618 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56619 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56620 + return mode;
56621 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56622 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56623 + return 0;
56624 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56625 + return 0;
56626 +
56627 + return (reqmode);
56628 +}
56629 +
56630 +__u32
56631 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56632 +{
56633 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56634 +}
56635 +
56636 +__u32
56637 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56638 +{
56639 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56640 +}
56641 +
56642 +__u32
56643 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56644 +{
56645 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56646 +}
56647 +
56648 +__u32
56649 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56650 +{
56651 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56652 +}
56653 +
56654 +__u32
56655 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56656 + umode_t *modeptr)
56657 +{
56658 + umode_t mode;
56659 +
56660 + *modeptr &= ~gr_acl_umask();
56661 + mode = *modeptr;
56662 +
56663 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56664 + return 1;
56665 +
56666 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56667 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56668 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56669 + GR_CHMOD_ACL_MSG);
56670 + } else {
56671 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56672 + }
56673 +}
56674 +
56675 +__u32
56676 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56677 +{
56678 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56679 +}
56680 +
56681 +__u32
56682 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56683 +{
56684 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56685 +}
56686 +
56687 +__u32
56688 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56689 +{
56690 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56691 +}
56692 +
56693 +__u32
56694 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56695 +{
56696 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56697 + GR_UNIXCONNECT_ACL_MSG);
56698 +}
56699 +
56700 +/* hardlinks require at minimum create and link permission,
56701 + any additional privilege required is based on the
56702 + privilege of the file being linked to
56703 +*/
56704 +__u32
56705 +gr_acl_handle_link(const struct dentry * new_dentry,
56706 + const struct dentry * parent_dentry,
56707 + const struct vfsmount * parent_mnt,
56708 + const struct dentry * old_dentry,
56709 + const struct vfsmount * old_mnt, const char *to)
56710 +{
56711 + __u32 mode;
56712 + __u32 needmode = GR_CREATE | GR_LINK;
56713 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56714 +
56715 + mode =
56716 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56717 + old_mnt);
56718 +
56719 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56720 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56721 + return mode;
56722 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56723 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56724 + return 0;
56725 + } else if (unlikely((mode & needmode) != needmode))
56726 + return 0;
56727 +
56728 + return 1;
56729 +}
56730 +
56731 +__u32
56732 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56733 + const struct dentry * parent_dentry,
56734 + const struct vfsmount * parent_mnt, const char *from)
56735 +{
56736 + __u32 needmode = GR_WRITE | GR_CREATE;
56737 + __u32 mode;
56738 +
56739 + mode =
56740 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56741 + GR_CREATE | GR_AUDIT_CREATE |
56742 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56743 +
56744 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56745 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56746 + return mode;
56747 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56748 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56749 + return 0;
56750 + } else if (unlikely((mode & needmode) != needmode))
56751 + return 0;
56752 +
56753 + return (GR_WRITE | GR_CREATE);
56754 +}
56755 +
56756 +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)
56757 +{
56758 + __u32 mode;
56759 +
56760 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56761 +
56762 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56763 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56764 + return mode;
56765 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56766 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56767 + return 0;
56768 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56769 + return 0;
56770 +
56771 + return (reqmode);
56772 +}
56773 +
56774 +__u32
56775 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56776 + const struct dentry * parent_dentry,
56777 + const struct vfsmount * parent_mnt,
56778 + const int mode)
56779 +{
56780 + __u32 reqmode = GR_WRITE | GR_CREATE;
56781 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56782 + reqmode |= GR_SETID;
56783 +
56784 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56785 + reqmode, GR_MKNOD_ACL_MSG);
56786 +}
56787 +
56788 +__u32
56789 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56790 + const struct dentry *parent_dentry,
56791 + const struct vfsmount *parent_mnt)
56792 +{
56793 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56794 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56795 +}
56796 +
56797 +#define RENAME_CHECK_SUCCESS(old, new) \
56798 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56799 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56800 +
56801 +int
56802 +gr_acl_handle_rename(struct dentry *new_dentry,
56803 + struct dentry *parent_dentry,
56804 + const struct vfsmount *parent_mnt,
56805 + struct dentry *old_dentry,
56806 + struct inode *old_parent_inode,
56807 + struct vfsmount *old_mnt, const char *newname)
56808 +{
56809 + __u32 comp1, comp2;
56810 + int error = 0;
56811 +
56812 + if (unlikely(!gr_acl_is_enabled()))
56813 + return 0;
56814 +
56815 + if (!new_dentry->d_inode) {
56816 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56817 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56818 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56819 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56820 + GR_DELETE | GR_AUDIT_DELETE |
56821 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56822 + GR_SUPPRESS, old_mnt);
56823 + } else {
56824 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56825 + GR_CREATE | GR_DELETE |
56826 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56827 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56828 + GR_SUPPRESS, parent_mnt);
56829 + comp2 =
56830 + gr_search_file(old_dentry,
56831 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56832 + GR_DELETE | GR_AUDIT_DELETE |
56833 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56834 + }
56835 +
56836 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56837 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56838 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56839 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56840 + && !(comp2 & GR_SUPPRESS)) {
56841 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56842 + error = -EACCES;
56843 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56844 + error = -EACCES;
56845 +
56846 + return error;
56847 +}
56848 +
56849 +void
56850 +gr_acl_handle_exit(void)
56851 +{
56852 + u16 id;
56853 + char *rolename;
56854 + struct file *exec_file;
56855 +
56856 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56857 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56858 + id = current->acl_role_id;
56859 + rolename = current->role->rolename;
56860 + gr_set_acls(1);
56861 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56862 + }
56863 +
56864 + write_lock(&grsec_exec_file_lock);
56865 + exec_file = current->exec_file;
56866 + current->exec_file = NULL;
56867 + write_unlock(&grsec_exec_file_lock);
56868 +
56869 + if (exec_file)
56870 + fput(exec_file);
56871 +}
56872 +
56873 +int
56874 +gr_acl_handle_procpidmem(const struct task_struct *task)
56875 +{
56876 + if (unlikely(!gr_acl_is_enabled()))
56877 + return 0;
56878 +
56879 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56880 + return -EACCES;
56881 +
56882 + return 0;
56883 +}
56884 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56885 new file mode 100644
56886 index 0000000..58800a7
56887 --- /dev/null
56888 +++ b/grsecurity/gracl_ip.c
56889 @@ -0,0 +1,384 @@
56890 +#include <linux/kernel.h>
56891 +#include <asm/uaccess.h>
56892 +#include <asm/errno.h>
56893 +#include <net/sock.h>
56894 +#include <linux/file.h>
56895 +#include <linux/fs.h>
56896 +#include <linux/net.h>
56897 +#include <linux/in.h>
56898 +#include <linux/skbuff.h>
56899 +#include <linux/ip.h>
56900 +#include <linux/udp.h>
56901 +#include <linux/types.h>
56902 +#include <linux/sched.h>
56903 +#include <linux/netdevice.h>
56904 +#include <linux/inetdevice.h>
56905 +#include <linux/gracl.h>
56906 +#include <linux/grsecurity.h>
56907 +#include <linux/grinternal.h>
56908 +
56909 +#define GR_BIND 0x01
56910 +#define GR_CONNECT 0x02
56911 +#define GR_INVERT 0x04
56912 +#define GR_BINDOVERRIDE 0x08
56913 +#define GR_CONNECTOVERRIDE 0x10
56914 +#define GR_SOCK_FAMILY 0x20
56915 +
56916 +static const char * gr_protocols[IPPROTO_MAX] = {
56917 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56918 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56919 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56920 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56921 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56922 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56923 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56924 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56925 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56926 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56927 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56928 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56929 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56930 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56931 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56932 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56933 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56934 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56935 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56936 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56937 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56938 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56939 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56940 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56941 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56942 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56943 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56944 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56945 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56946 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56947 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56948 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56949 + };
56950 +
56951 +static const char * gr_socktypes[SOCK_MAX] = {
56952 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56953 + "unknown:7", "unknown:8", "unknown:9", "packet"
56954 + };
56955 +
56956 +static const char * gr_sockfamilies[AF_MAX+1] = {
56957 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56958 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56959 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56960 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56961 + };
56962 +
56963 +const char *
56964 +gr_proto_to_name(unsigned char proto)
56965 +{
56966 + return gr_protocols[proto];
56967 +}
56968 +
56969 +const char *
56970 +gr_socktype_to_name(unsigned char type)
56971 +{
56972 + return gr_socktypes[type];
56973 +}
56974 +
56975 +const char *
56976 +gr_sockfamily_to_name(unsigned char family)
56977 +{
56978 + return gr_sockfamilies[family];
56979 +}
56980 +
56981 +int
56982 +gr_search_socket(const int domain, const int type, const int protocol)
56983 +{
56984 + struct acl_subject_label *curr;
56985 + const struct cred *cred = current_cred();
56986 +
56987 + if (unlikely(!gr_acl_is_enabled()))
56988 + goto exit;
56989 +
56990 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56991 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56992 + goto exit; // let the kernel handle it
56993 +
56994 + curr = current->acl;
56995 +
56996 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56997 + /* the family is allowed, if this is PF_INET allow it only if
56998 + the extra sock type/protocol checks pass */
56999 + if (domain == PF_INET)
57000 + goto inet_check;
57001 + goto exit;
57002 + } else {
57003 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57004 + __u32 fakeip = 0;
57005 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57006 + current->role->roletype, cred->uid,
57007 + cred->gid, current->exec_file ?
57008 + gr_to_filename(current->exec_file->f_path.dentry,
57009 + current->exec_file->f_path.mnt) :
57010 + curr->filename, curr->filename,
57011 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
57012 + &current->signal->saved_ip);
57013 + goto exit;
57014 + }
57015 + goto exit_fail;
57016 + }
57017 +
57018 +inet_check:
57019 + /* the rest of this checking is for IPv4 only */
57020 + if (!curr->ips)
57021 + goto exit;
57022 +
57023 + if ((curr->ip_type & (1 << type)) &&
57024 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
57025 + goto exit;
57026 +
57027 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57028 + /* we don't place acls on raw sockets , and sometimes
57029 + dgram/ip sockets are opened for ioctl and not
57030 + bind/connect, so we'll fake a bind learn log */
57031 + if (type == SOCK_RAW || type == SOCK_PACKET) {
57032 + __u32 fakeip = 0;
57033 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57034 + current->role->roletype, cred->uid,
57035 + cred->gid, current->exec_file ?
57036 + gr_to_filename(current->exec_file->f_path.dentry,
57037 + current->exec_file->f_path.mnt) :
57038 + curr->filename, curr->filename,
57039 + &fakeip, 0, type,
57040 + protocol, GR_CONNECT, &current->signal->saved_ip);
57041 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
57042 + __u32 fakeip = 0;
57043 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57044 + current->role->roletype, cred->uid,
57045 + cred->gid, current->exec_file ?
57046 + gr_to_filename(current->exec_file->f_path.dentry,
57047 + current->exec_file->f_path.mnt) :
57048 + curr->filename, curr->filename,
57049 + &fakeip, 0, type,
57050 + protocol, GR_BIND, &current->signal->saved_ip);
57051 + }
57052 + /* we'll log when they use connect or bind */
57053 + goto exit;
57054 + }
57055 +
57056 +exit_fail:
57057 + if (domain == PF_INET)
57058 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
57059 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
57060 + else
57061 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
57062 + gr_socktype_to_name(type), protocol);
57063 +
57064 + return 0;
57065 +exit:
57066 + return 1;
57067 +}
57068 +
57069 +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)
57070 +{
57071 + if ((ip->mode & mode) &&
57072 + (ip_port >= ip->low) &&
57073 + (ip_port <= ip->high) &&
57074 + ((ntohl(ip_addr) & our_netmask) ==
57075 + (ntohl(our_addr) & our_netmask))
57076 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
57077 + && (ip->type & (1 << type))) {
57078 + if (ip->mode & GR_INVERT)
57079 + return 2; // specifically denied
57080 + else
57081 + return 1; // allowed
57082 + }
57083 +
57084 + return 0; // not specifically allowed, may continue parsing
57085 +}
57086 +
57087 +static int
57088 +gr_search_connectbind(const int full_mode, struct sock *sk,
57089 + struct sockaddr_in *addr, const int type)
57090 +{
57091 + char iface[IFNAMSIZ] = {0};
57092 + struct acl_subject_label *curr;
57093 + struct acl_ip_label *ip;
57094 + struct inet_sock *isk;
57095 + struct net_device *dev;
57096 + struct in_device *idev;
57097 + unsigned long i;
57098 + int ret;
57099 + int mode = full_mode & (GR_BIND | GR_CONNECT);
57100 + __u32 ip_addr = 0;
57101 + __u32 our_addr;
57102 + __u32 our_netmask;
57103 + char *p;
57104 + __u16 ip_port = 0;
57105 + const struct cred *cred = current_cred();
57106 +
57107 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
57108 + return 0;
57109 +
57110 + curr = current->acl;
57111 + isk = inet_sk(sk);
57112 +
57113 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
57114 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
57115 + addr->sin_addr.s_addr = curr->inaddr_any_override;
57116 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
57117 + struct sockaddr_in saddr;
57118 + int err;
57119 +
57120 + saddr.sin_family = AF_INET;
57121 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
57122 + saddr.sin_port = isk->inet_sport;
57123 +
57124 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
57125 + if (err)
57126 + return err;
57127 +
57128 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
57129 + if (err)
57130 + return err;
57131 + }
57132 +
57133 + if (!curr->ips)
57134 + return 0;
57135 +
57136 + ip_addr = addr->sin_addr.s_addr;
57137 + ip_port = ntohs(addr->sin_port);
57138 +
57139 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57140 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57141 + current->role->roletype, cred->uid,
57142 + cred->gid, current->exec_file ?
57143 + gr_to_filename(current->exec_file->f_path.dentry,
57144 + current->exec_file->f_path.mnt) :
57145 + curr->filename, curr->filename,
57146 + &ip_addr, ip_port, type,
57147 + sk->sk_protocol, mode, &current->signal->saved_ip);
57148 + return 0;
57149 + }
57150 +
57151 + for (i = 0; i < curr->ip_num; i++) {
57152 + ip = *(curr->ips + i);
57153 + if (ip->iface != NULL) {
57154 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
57155 + p = strchr(iface, ':');
57156 + if (p != NULL)
57157 + *p = '\0';
57158 + dev = dev_get_by_name(sock_net(sk), iface);
57159 + if (dev == NULL)
57160 + continue;
57161 + idev = in_dev_get(dev);
57162 + if (idev == NULL) {
57163 + dev_put(dev);
57164 + continue;
57165 + }
57166 + rcu_read_lock();
57167 + for_ifa(idev) {
57168 + if (!strcmp(ip->iface, ifa->ifa_label)) {
57169 + our_addr = ifa->ifa_address;
57170 + our_netmask = 0xffffffff;
57171 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
57172 + if (ret == 1) {
57173 + rcu_read_unlock();
57174 + in_dev_put(idev);
57175 + dev_put(dev);
57176 + return 0;
57177 + } else if (ret == 2) {
57178 + rcu_read_unlock();
57179 + in_dev_put(idev);
57180 + dev_put(dev);
57181 + goto denied;
57182 + }
57183 + }
57184 + } endfor_ifa(idev);
57185 + rcu_read_unlock();
57186 + in_dev_put(idev);
57187 + dev_put(dev);
57188 + } else {
57189 + our_addr = ip->addr;
57190 + our_netmask = ip->netmask;
57191 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
57192 + if (ret == 1)
57193 + return 0;
57194 + else if (ret == 2)
57195 + goto denied;
57196 + }
57197 + }
57198 +
57199 +denied:
57200 + if (mode == GR_BIND)
57201 + 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));
57202 + else if (mode == GR_CONNECT)
57203 + 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));
57204 +
57205 + return -EACCES;
57206 +}
57207 +
57208 +int
57209 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
57210 +{
57211 + /* always allow disconnection of dgram sockets with connect */
57212 + if (addr->sin_family == AF_UNSPEC)
57213 + return 0;
57214 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
57215 +}
57216 +
57217 +int
57218 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
57219 +{
57220 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
57221 +}
57222 +
57223 +int gr_search_listen(struct socket *sock)
57224 +{
57225 + struct sock *sk = sock->sk;
57226 + struct sockaddr_in addr;
57227 +
57228 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
57229 + addr.sin_port = inet_sk(sk)->inet_sport;
57230 +
57231 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57232 +}
57233 +
57234 +int gr_search_accept(struct socket *sock)
57235 +{
57236 + struct sock *sk = sock->sk;
57237 + struct sockaddr_in addr;
57238 +
57239 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
57240 + addr.sin_port = inet_sk(sk)->inet_sport;
57241 +
57242 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57243 +}
57244 +
57245 +int
57246 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
57247 +{
57248 + if (addr)
57249 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
57250 + else {
57251 + struct sockaddr_in sin;
57252 + const struct inet_sock *inet = inet_sk(sk);
57253 +
57254 + sin.sin_addr.s_addr = inet->inet_daddr;
57255 + sin.sin_port = inet->inet_dport;
57256 +
57257 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57258 + }
57259 +}
57260 +
57261 +int
57262 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
57263 +{
57264 + struct sockaddr_in sin;
57265 +
57266 + if (unlikely(skb->len < sizeof (struct udphdr)))
57267 + return 0; // skip this packet
57268 +
57269 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
57270 + sin.sin_port = udp_hdr(skb)->source;
57271 +
57272 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57273 +}
57274 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
57275 new file mode 100644
57276 index 0000000..25f54ef
57277 --- /dev/null
57278 +++ b/grsecurity/gracl_learn.c
57279 @@ -0,0 +1,207 @@
57280 +#include <linux/kernel.h>
57281 +#include <linux/mm.h>
57282 +#include <linux/sched.h>
57283 +#include <linux/poll.h>
57284 +#include <linux/string.h>
57285 +#include <linux/file.h>
57286 +#include <linux/types.h>
57287 +#include <linux/vmalloc.h>
57288 +#include <linux/grinternal.h>
57289 +
57290 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
57291 + size_t count, loff_t *ppos);
57292 +extern int gr_acl_is_enabled(void);
57293 +
57294 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
57295 +static int gr_learn_attached;
57296 +
57297 +/* use a 512k buffer */
57298 +#define LEARN_BUFFER_SIZE (512 * 1024)
57299 +
57300 +static DEFINE_SPINLOCK(gr_learn_lock);
57301 +static DEFINE_MUTEX(gr_learn_user_mutex);
57302 +
57303 +/* we need to maintain two buffers, so that the kernel context of grlearn
57304 + uses a semaphore around the userspace copying, and the other kernel contexts
57305 + use a spinlock when copying into the buffer, since they cannot sleep
57306 +*/
57307 +static char *learn_buffer;
57308 +static char *learn_buffer_user;
57309 +static int learn_buffer_len;
57310 +static int learn_buffer_user_len;
57311 +
57312 +static ssize_t
57313 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
57314 +{
57315 + DECLARE_WAITQUEUE(wait, current);
57316 + ssize_t retval = 0;
57317 +
57318 + add_wait_queue(&learn_wait, &wait);
57319 + set_current_state(TASK_INTERRUPTIBLE);
57320 + do {
57321 + mutex_lock(&gr_learn_user_mutex);
57322 + spin_lock(&gr_learn_lock);
57323 + if (learn_buffer_len)
57324 + break;
57325 + spin_unlock(&gr_learn_lock);
57326 + mutex_unlock(&gr_learn_user_mutex);
57327 + if (file->f_flags & O_NONBLOCK) {
57328 + retval = -EAGAIN;
57329 + goto out;
57330 + }
57331 + if (signal_pending(current)) {
57332 + retval = -ERESTARTSYS;
57333 + goto out;
57334 + }
57335 +
57336 + schedule();
57337 + } while (1);
57338 +
57339 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
57340 + learn_buffer_user_len = learn_buffer_len;
57341 + retval = learn_buffer_len;
57342 + learn_buffer_len = 0;
57343 +
57344 + spin_unlock(&gr_learn_lock);
57345 +
57346 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
57347 + retval = -EFAULT;
57348 +
57349 + mutex_unlock(&gr_learn_user_mutex);
57350 +out:
57351 + set_current_state(TASK_RUNNING);
57352 + remove_wait_queue(&learn_wait, &wait);
57353 + return retval;
57354 +}
57355 +
57356 +static unsigned int
57357 +poll_learn(struct file * file, poll_table * wait)
57358 +{
57359 + poll_wait(file, &learn_wait, wait);
57360 +
57361 + if (learn_buffer_len)
57362 + return (POLLIN | POLLRDNORM);
57363 +
57364 + return 0;
57365 +}
57366 +
57367 +void
57368 +gr_clear_learn_entries(void)
57369 +{
57370 + char *tmp;
57371 +
57372 + mutex_lock(&gr_learn_user_mutex);
57373 + spin_lock(&gr_learn_lock);
57374 + tmp = learn_buffer;
57375 + learn_buffer = NULL;
57376 + spin_unlock(&gr_learn_lock);
57377 + if (tmp)
57378 + vfree(tmp);
57379 + if (learn_buffer_user != NULL) {
57380 + vfree(learn_buffer_user);
57381 + learn_buffer_user = NULL;
57382 + }
57383 + learn_buffer_len = 0;
57384 + mutex_unlock(&gr_learn_user_mutex);
57385 +
57386 + return;
57387 +}
57388 +
57389 +void
57390 +gr_add_learn_entry(const char *fmt, ...)
57391 +{
57392 + va_list args;
57393 + unsigned int len;
57394 +
57395 + if (!gr_learn_attached)
57396 + return;
57397 +
57398 + spin_lock(&gr_learn_lock);
57399 +
57400 + /* leave a gap at the end so we know when it's "full" but don't have to
57401 + compute the exact length of the string we're trying to append
57402 + */
57403 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
57404 + spin_unlock(&gr_learn_lock);
57405 + wake_up_interruptible(&learn_wait);
57406 + return;
57407 + }
57408 + if (learn_buffer == NULL) {
57409 + spin_unlock(&gr_learn_lock);
57410 + return;
57411 + }
57412 +
57413 + va_start(args, fmt);
57414 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
57415 + va_end(args);
57416 +
57417 + learn_buffer_len += len + 1;
57418 +
57419 + spin_unlock(&gr_learn_lock);
57420 + wake_up_interruptible(&learn_wait);
57421 +
57422 + return;
57423 +}
57424 +
57425 +static int
57426 +open_learn(struct inode *inode, struct file *file)
57427 +{
57428 + if (file->f_mode & FMODE_READ && gr_learn_attached)
57429 + return -EBUSY;
57430 + if (file->f_mode & FMODE_READ) {
57431 + int retval = 0;
57432 + mutex_lock(&gr_learn_user_mutex);
57433 + if (learn_buffer == NULL)
57434 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
57435 + if (learn_buffer_user == NULL)
57436 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
57437 + if (learn_buffer == NULL) {
57438 + retval = -ENOMEM;
57439 + goto out_error;
57440 + }
57441 + if (learn_buffer_user == NULL) {
57442 + retval = -ENOMEM;
57443 + goto out_error;
57444 + }
57445 + learn_buffer_len = 0;
57446 + learn_buffer_user_len = 0;
57447 + gr_learn_attached = 1;
57448 +out_error:
57449 + mutex_unlock(&gr_learn_user_mutex);
57450 + return retval;
57451 + }
57452 + return 0;
57453 +}
57454 +
57455 +static int
57456 +close_learn(struct inode *inode, struct file *file)
57457 +{
57458 + if (file->f_mode & FMODE_READ) {
57459 + char *tmp = NULL;
57460 + mutex_lock(&gr_learn_user_mutex);
57461 + spin_lock(&gr_learn_lock);
57462 + tmp = learn_buffer;
57463 + learn_buffer = NULL;
57464 + spin_unlock(&gr_learn_lock);
57465 + if (tmp)
57466 + vfree(tmp);
57467 + if (learn_buffer_user != NULL) {
57468 + vfree(learn_buffer_user);
57469 + learn_buffer_user = NULL;
57470 + }
57471 + learn_buffer_len = 0;
57472 + learn_buffer_user_len = 0;
57473 + gr_learn_attached = 0;
57474 + mutex_unlock(&gr_learn_user_mutex);
57475 + }
57476 +
57477 + return 0;
57478 +}
57479 +
57480 +const struct file_operations grsec_fops = {
57481 + .read = read_learn,
57482 + .write = write_grsec_handler,
57483 + .open = open_learn,
57484 + .release = close_learn,
57485 + .poll = poll_learn,
57486 +};
57487 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
57488 new file mode 100644
57489 index 0000000..39645c9
57490 --- /dev/null
57491 +++ b/grsecurity/gracl_res.c
57492 @@ -0,0 +1,68 @@
57493 +#include <linux/kernel.h>
57494 +#include <linux/sched.h>
57495 +#include <linux/gracl.h>
57496 +#include <linux/grinternal.h>
57497 +
57498 +static const char *restab_log[] = {
57499 + [RLIMIT_CPU] = "RLIMIT_CPU",
57500 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57501 + [RLIMIT_DATA] = "RLIMIT_DATA",
57502 + [RLIMIT_STACK] = "RLIMIT_STACK",
57503 + [RLIMIT_CORE] = "RLIMIT_CORE",
57504 + [RLIMIT_RSS] = "RLIMIT_RSS",
57505 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
57506 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57507 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57508 + [RLIMIT_AS] = "RLIMIT_AS",
57509 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57510 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57511 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57512 + [RLIMIT_NICE] = "RLIMIT_NICE",
57513 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57514 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57515 + [GR_CRASH_RES] = "RLIMIT_CRASH"
57516 +};
57517 +
57518 +void
57519 +gr_log_resource(const struct task_struct *task,
57520 + const int res, const unsigned long wanted, const int gt)
57521 +{
57522 + const struct cred *cred;
57523 + unsigned long rlim;
57524 +
57525 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
57526 + return;
57527 +
57528 + // not yet supported resource
57529 + if (unlikely(!restab_log[res]))
57530 + return;
57531 +
57532 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57533 + rlim = task_rlimit_max(task, res);
57534 + else
57535 + rlim = task_rlimit(task, res);
57536 +
57537 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57538 + return;
57539 +
57540 + rcu_read_lock();
57541 + cred = __task_cred(task);
57542 +
57543 + if (res == RLIMIT_NPROC &&
57544 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57545 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57546 + goto out_rcu_unlock;
57547 + else if (res == RLIMIT_MEMLOCK &&
57548 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57549 + goto out_rcu_unlock;
57550 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57551 + goto out_rcu_unlock;
57552 + rcu_read_unlock();
57553 +
57554 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57555 +
57556 + return;
57557 +out_rcu_unlock:
57558 + rcu_read_unlock();
57559 + return;
57560 +}
57561 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57562 new file mode 100644
57563 index 0000000..25197e9
57564 --- /dev/null
57565 +++ b/grsecurity/gracl_segv.c
57566 @@ -0,0 +1,299 @@
57567 +#include <linux/kernel.h>
57568 +#include <linux/mm.h>
57569 +#include <asm/uaccess.h>
57570 +#include <asm/errno.h>
57571 +#include <asm/mman.h>
57572 +#include <net/sock.h>
57573 +#include <linux/file.h>
57574 +#include <linux/fs.h>
57575 +#include <linux/net.h>
57576 +#include <linux/in.h>
57577 +#include <linux/slab.h>
57578 +#include <linux/types.h>
57579 +#include <linux/sched.h>
57580 +#include <linux/timer.h>
57581 +#include <linux/gracl.h>
57582 +#include <linux/grsecurity.h>
57583 +#include <linux/grinternal.h>
57584 +
57585 +static struct crash_uid *uid_set;
57586 +static unsigned short uid_used;
57587 +static DEFINE_SPINLOCK(gr_uid_lock);
57588 +extern rwlock_t gr_inode_lock;
57589 +extern struct acl_subject_label *
57590 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57591 + struct acl_role_label *role);
57592 +
57593 +#ifdef CONFIG_BTRFS_FS
57594 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57595 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57596 +#endif
57597 +
57598 +static inline dev_t __get_dev(const struct dentry *dentry)
57599 +{
57600 +#ifdef CONFIG_BTRFS_FS
57601 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57602 + return get_btrfs_dev_from_inode(dentry->d_inode);
57603 + else
57604 +#endif
57605 + return dentry->d_inode->i_sb->s_dev;
57606 +}
57607 +
57608 +int
57609 +gr_init_uidset(void)
57610 +{
57611 + uid_set =
57612 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57613 + uid_used = 0;
57614 +
57615 + return uid_set ? 1 : 0;
57616 +}
57617 +
57618 +void
57619 +gr_free_uidset(void)
57620 +{
57621 + if (uid_set)
57622 + kfree(uid_set);
57623 +
57624 + return;
57625 +}
57626 +
57627 +int
57628 +gr_find_uid(const uid_t uid)
57629 +{
57630 + struct crash_uid *tmp = uid_set;
57631 + uid_t buid;
57632 + int low = 0, high = uid_used - 1, mid;
57633 +
57634 + while (high >= low) {
57635 + mid = (low + high) >> 1;
57636 + buid = tmp[mid].uid;
57637 + if (buid == uid)
57638 + return mid;
57639 + if (buid > uid)
57640 + high = mid - 1;
57641 + if (buid < uid)
57642 + low = mid + 1;
57643 + }
57644 +
57645 + return -1;
57646 +}
57647 +
57648 +static __inline__ void
57649 +gr_insertsort(void)
57650 +{
57651 + unsigned short i, j;
57652 + struct crash_uid index;
57653 +
57654 + for (i = 1; i < uid_used; i++) {
57655 + index = uid_set[i];
57656 + j = i;
57657 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57658 + uid_set[j] = uid_set[j - 1];
57659 + j--;
57660 + }
57661 + uid_set[j] = index;
57662 + }
57663 +
57664 + return;
57665 +}
57666 +
57667 +static __inline__ void
57668 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57669 +{
57670 + int loc;
57671 +
57672 + if (uid_used == GR_UIDTABLE_MAX)
57673 + return;
57674 +
57675 + loc = gr_find_uid(uid);
57676 +
57677 + if (loc >= 0) {
57678 + uid_set[loc].expires = expires;
57679 + return;
57680 + }
57681 +
57682 + uid_set[uid_used].uid = uid;
57683 + uid_set[uid_used].expires = expires;
57684 + uid_used++;
57685 +
57686 + gr_insertsort();
57687 +
57688 + return;
57689 +}
57690 +
57691 +void
57692 +gr_remove_uid(const unsigned short loc)
57693 +{
57694 + unsigned short i;
57695 +
57696 + for (i = loc + 1; i < uid_used; i++)
57697 + uid_set[i - 1] = uid_set[i];
57698 +
57699 + uid_used--;
57700 +
57701 + return;
57702 +}
57703 +
57704 +int
57705 +gr_check_crash_uid(const uid_t uid)
57706 +{
57707 + int loc;
57708 + int ret = 0;
57709 +
57710 + if (unlikely(!gr_acl_is_enabled()))
57711 + return 0;
57712 +
57713 + spin_lock(&gr_uid_lock);
57714 + loc = gr_find_uid(uid);
57715 +
57716 + if (loc < 0)
57717 + goto out_unlock;
57718 +
57719 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57720 + gr_remove_uid(loc);
57721 + else
57722 + ret = 1;
57723 +
57724 +out_unlock:
57725 + spin_unlock(&gr_uid_lock);
57726 + return ret;
57727 +}
57728 +
57729 +static __inline__ int
57730 +proc_is_setxid(const struct cred *cred)
57731 +{
57732 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57733 + !uid_eq(cred->uid, cred->fsuid))
57734 + return 1;
57735 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57736 + !uid_eq(cred->gid, cred->fsgid))
57737 + return 1;
57738 +
57739 + return 0;
57740 +}
57741 +
57742 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57743 +
57744 +void
57745 +gr_handle_crash(struct task_struct *task, const int sig)
57746 +{
57747 + struct acl_subject_label *curr;
57748 + struct task_struct *tsk, *tsk2;
57749 + const struct cred *cred;
57750 + const struct cred *cred2;
57751 +
57752 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57753 + return;
57754 +
57755 + if (unlikely(!gr_acl_is_enabled()))
57756 + return;
57757 +
57758 + curr = task->acl;
57759 +
57760 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57761 + return;
57762 +
57763 + if (time_before_eq(curr->expires, get_seconds())) {
57764 + curr->expires = 0;
57765 + curr->crashes = 0;
57766 + }
57767 +
57768 + curr->crashes++;
57769 +
57770 + if (!curr->expires)
57771 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57772 +
57773 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57774 + time_after(curr->expires, get_seconds())) {
57775 + rcu_read_lock();
57776 + cred = __task_cred(task);
57777 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57778 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57779 + spin_lock(&gr_uid_lock);
57780 + gr_insert_uid(cred->uid, curr->expires);
57781 + spin_unlock(&gr_uid_lock);
57782 + curr->expires = 0;
57783 + curr->crashes = 0;
57784 + read_lock(&tasklist_lock);
57785 + do_each_thread(tsk2, tsk) {
57786 + cred2 = __task_cred(tsk);
57787 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57788 + gr_fake_force_sig(SIGKILL, tsk);
57789 + } while_each_thread(tsk2, tsk);
57790 + read_unlock(&tasklist_lock);
57791 + } else {
57792 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57793 + read_lock(&tasklist_lock);
57794 + read_lock(&grsec_exec_file_lock);
57795 + do_each_thread(tsk2, tsk) {
57796 + if (likely(tsk != task)) {
57797 + // if this thread has the same subject as the one that triggered
57798 + // RES_CRASH and it's the same binary, kill it
57799 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57800 + gr_fake_force_sig(SIGKILL, tsk);
57801 + }
57802 + } while_each_thread(tsk2, tsk);
57803 + read_unlock(&grsec_exec_file_lock);
57804 + read_unlock(&tasklist_lock);
57805 + }
57806 + rcu_read_unlock();
57807 + }
57808 +
57809 + return;
57810 +}
57811 +
57812 +int
57813 +gr_check_crash_exec(const struct file *filp)
57814 +{
57815 + struct acl_subject_label *curr;
57816 +
57817 + if (unlikely(!gr_acl_is_enabled()))
57818 + return 0;
57819 +
57820 + read_lock(&gr_inode_lock);
57821 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57822 + __get_dev(filp->f_path.dentry),
57823 + current->role);
57824 + read_unlock(&gr_inode_lock);
57825 +
57826 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57827 + (!curr->crashes && !curr->expires))
57828 + return 0;
57829 +
57830 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57831 + time_after(curr->expires, get_seconds()))
57832 + return 1;
57833 + else if (time_before_eq(curr->expires, get_seconds())) {
57834 + curr->crashes = 0;
57835 + curr->expires = 0;
57836 + }
57837 +
57838 + return 0;
57839 +}
57840 +
57841 +void
57842 +gr_handle_alertkill(struct task_struct *task)
57843 +{
57844 + struct acl_subject_label *curracl;
57845 + __u32 curr_ip;
57846 + struct task_struct *p, *p2;
57847 +
57848 + if (unlikely(!gr_acl_is_enabled()))
57849 + return;
57850 +
57851 + curracl = task->acl;
57852 + curr_ip = task->signal->curr_ip;
57853 +
57854 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57855 + read_lock(&tasklist_lock);
57856 + do_each_thread(p2, p) {
57857 + if (p->signal->curr_ip == curr_ip)
57858 + gr_fake_force_sig(SIGKILL, p);
57859 + } while_each_thread(p2, p);
57860 + read_unlock(&tasklist_lock);
57861 + } else if (curracl->mode & GR_KILLPROC)
57862 + gr_fake_force_sig(SIGKILL, task);
57863 +
57864 + return;
57865 +}
57866 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57867 new file mode 100644
57868 index 0000000..9d83a69
57869 --- /dev/null
57870 +++ b/grsecurity/gracl_shm.c
57871 @@ -0,0 +1,40 @@
57872 +#include <linux/kernel.h>
57873 +#include <linux/mm.h>
57874 +#include <linux/sched.h>
57875 +#include <linux/file.h>
57876 +#include <linux/ipc.h>
57877 +#include <linux/gracl.h>
57878 +#include <linux/grsecurity.h>
57879 +#include <linux/grinternal.h>
57880 +
57881 +int
57882 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57883 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57884 +{
57885 + struct task_struct *task;
57886 +
57887 + if (!gr_acl_is_enabled())
57888 + return 1;
57889 +
57890 + rcu_read_lock();
57891 + read_lock(&tasklist_lock);
57892 +
57893 + task = find_task_by_vpid(shm_cprid);
57894 +
57895 + if (unlikely(!task))
57896 + task = find_task_by_vpid(shm_lapid);
57897 +
57898 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57899 + (task->pid == shm_lapid)) &&
57900 + (task->acl->mode & GR_PROTSHM) &&
57901 + (task->acl != current->acl))) {
57902 + read_unlock(&tasklist_lock);
57903 + rcu_read_unlock();
57904 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57905 + return 0;
57906 + }
57907 + read_unlock(&tasklist_lock);
57908 + rcu_read_unlock();
57909 +
57910 + return 1;
57911 +}
57912 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57913 new file mode 100644
57914 index 0000000..bc0be01
57915 --- /dev/null
57916 +++ b/grsecurity/grsec_chdir.c
57917 @@ -0,0 +1,19 @@
57918 +#include <linux/kernel.h>
57919 +#include <linux/sched.h>
57920 +#include <linux/fs.h>
57921 +#include <linux/file.h>
57922 +#include <linux/grsecurity.h>
57923 +#include <linux/grinternal.h>
57924 +
57925 +void
57926 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57927 +{
57928 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57929 + if ((grsec_enable_chdir && grsec_enable_group &&
57930 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57931 + !grsec_enable_group)) {
57932 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57933 + }
57934 +#endif
57935 + return;
57936 +}
57937 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57938 new file mode 100644
57939 index 0000000..9807ee2
57940 --- /dev/null
57941 +++ b/grsecurity/grsec_chroot.c
57942 @@ -0,0 +1,368 @@
57943 +#include <linux/kernel.h>
57944 +#include <linux/module.h>
57945 +#include <linux/sched.h>
57946 +#include <linux/file.h>
57947 +#include <linux/fs.h>
57948 +#include <linux/mount.h>
57949 +#include <linux/types.h>
57950 +#include "../fs/mount.h"
57951 +#include <linux/grsecurity.h>
57952 +#include <linux/grinternal.h>
57953 +
57954 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57955 +{
57956 +#ifdef CONFIG_GRKERNSEC
57957 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57958 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57959 + task->gr_is_chrooted = 1;
57960 + else
57961 + task->gr_is_chrooted = 0;
57962 +
57963 + task->gr_chroot_dentry = path->dentry;
57964 +#endif
57965 + return;
57966 +}
57967 +
57968 +void gr_clear_chroot_entries(struct task_struct *task)
57969 +{
57970 +#ifdef CONFIG_GRKERNSEC
57971 + task->gr_is_chrooted = 0;
57972 + task->gr_chroot_dentry = NULL;
57973 +#endif
57974 + return;
57975 +}
57976 +
57977 +int
57978 +gr_handle_chroot_unix(const pid_t pid)
57979 +{
57980 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57981 + struct task_struct *p;
57982 +
57983 + if (unlikely(!grsec_enable_chroot_unix))
57984 + return 1;
57985 +
57986 + if (likely(!proc_is_chrooted(current)))
57987 + return 1;
57988 +
57989 + rcu_read_lock();
57990 + read_lock(&tasklist_lock);
57991 + p = find_task_by_vpid_unrestricted(pid);
57992 + if (unlikely(p && !have_same_root(current, p))) {
57993 + read_unlock(&tasklist_lock);
57994 + rcu_read_unlock();
57995 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57996 + return 0;
57997 + }
57998 + read_unlock(&tasklist_lock);
57999 + rcu_read_unlock();
58000 +#endif
58001 + return 1;
58002 +}
58003 +
58004 +int
58005 +gr_handle_chroot_nice(void)
58006 +{
58007 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58008 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
58009 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
58010 + return -EPERM;
58011 + }
58012 +#endif
58013 + return 0;
58014 +}
58015 +
58016 +int
58017 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
58018 +{
58019 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58020 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
58021 + && proc_is_chrooted(current)) {
58022 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
58023 + return -EACCES;
58024 + }
58025 +#endif
58026 + return 0;
58027 +}
58028 +
58029 +int
58030 +gr_handle_chroot_rawio(const struct inode *inode)
58031 +{
58032 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58033 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58034 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
58035 + return 1;
58036 +#endif
58037 + return 0;
58038 +}
58039 +
58040 +int
58041 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
58042 +{
58043 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58044 + struct task_struct *p;
58045 + int ret = 0;
58046 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
58047 + return ret;
58048 +
58049 + read_lock(&tasklist_lock);
58050 + do_each_pid_task(pid, type, p) {
58051 + if (!have_same_root(current, p)) {
58052 + ret = 1;
58053 + goto out;
58054 + }
58055 + } while_each_pid_task(pid, type, p);
58056 +out:
58057 + read_unlock(&tasklist_lock);
58058 + return ret;
58059 +#endif
58060 + return 0;
58061 +}
58062 +
58063 +int
58064 +gr_pid_is_chrooted(struct task_struct *p)
58065 +{
58066 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58067 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
58068 + return 0;
58069 +
58070 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
58071 + !have_same_root(current, p)) {
58072 + return 1;
58073 + }
58074 +#endif
58075 + return 0;
58076 +}
58077 +
58078 +EXPORT_SYMBOL(gr_pid_is_chrooted);
58079 +
58080 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
58081 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
58082 +{
58083 + struct path path, currentroot;
58084 + int ret = 0;
58085 +
58086 + path.dentry = (struct dentry *)u_dentry;
58087 + path.mnt = (struct vfsmount *)u_mnt;
58088 + get_fs_root(current->fs, &currentroot);
58089 + if (path_is_under(&path, &currentroot))
58090 + ret = 1;
58091 + path_put(&currentroot);
58092 +
58093 + return ret;
58094 +}
58095 +#endif
58096 +
58097 +int
58098 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
58099 +{
58100 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58101 + if (!grsec_enable_chroot_fchdir)
58102 + return 1;
58103 +
58104 + if (!proc_is_chrooted(current))
58105 + return 1;
58106 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
58107 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
58108 + return 0;
58109 + }
58110 +#endif
58111 + return 1;
58112 +}
58113 +
58114 +int
58115 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58116 + const time_t shm_createtime)
58117 +{
58118 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58119 + struct task_struct *p;
58120 + time_t starttime;
58121 +
58122 + if (unlikely(!grsec_enable_chroot_shmat))
58123 + return 1;
58124 +
58125 + if (likely(!proc_is_chrooted(current)))
58126 + return 1;
58127 +
58128 + rcu_read_lock();
58129 + read_lock(&tasklist_lock);
58130 +
58131 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
58132 + starttime = p->start_time.tv_sec;
58133 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
58134 + if (have_same_root(current, p)) {
58135 + goto allow;
58136 + } else {
58137 + read_unlock(&tasklist_lock);
58138 + rcu_read_unlock();
58139 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
58140 + return 0;
58141 + }
58142 + }
58143 + /* creator exited, pid reuse, fall through to next check */
58144 + }
58145 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
58146 + if (unlikely(!have_same_root(current, p))) {
58147 + read_unlock(&tasklist_lock);
58148 + rcu_read_unlock();
58149 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
58150 + return 0;
58151 + }
58152 + }
58153 +
58154 +allow:
58155 + read_unlock(&tasklist_lock);
58156 + rcu_read_unlock();
58157 +#endif
58158 + return 1;
58159 +}
58160 +
58161 +void
58162 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
58163 +{
58164 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58165 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
58166 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
58167 +#endif
58168 + return;
58169 +}
58170 +
58171 +int
58172 +gr_handle_chroot_mknod(const struct dentry *dentry,
58173 + const struct vfsmount *mnt, const int mode)
58174 +{
58175 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58176 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
58177 + proc_is_chrooted(current)) {
58178 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
58179 + return -EPERM;
58180 + }
58181 +#endif
58182 + return 0;
58183 +}
58184 +
58185 +int
58186 +gr_handle_chroot_mount(const struct dentry *dentry,
58187 + const struct vfsmount *mnt, const char *dev_name)
58188 +{
58189 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58190 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
58191 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
58192 + return -EPERM;
58193 + }
58194 +#endif
58195 + return 0;
58196 +}
58197 +
58198 +int
58199 +gr_handle_chroot_pivot(void)
58200 +{
58201 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58202 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
58203 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
58204 + return -EPERM;
58205 + }
58206 +#endif
58207 + return 0;
58208 +}
58209 +
58210 +int
58211 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
58212 +{
58213 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58214 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
58215 + !gr_is_outside_chroot(dentry, mnt)) {
58216 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
58217 + return -EPERM;
58218 + }
58219 +#endif
58220 + return 0;
58221 +}
58222 +
58223 +extern const char *captab_log[];
58224 +extern int captab_log_entries;
58225 +
58226 +int
58227 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58228 +{
58229 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58230 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
58231 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58232 + if (cap_raised(chroot_caps, cap)) {
58233 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
58234 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
58235 + }
58236 + return 0;
58237 + }
58238 + }
58239 +#endif
58240 + return 1;
58241 +}
58242 +
58243 +int
58244 +gr_chroot_is_capable(const int cap)
58245 +{
58246 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58247 + return gr_task_chroot_is_capable(current, current_cred(), cap);
58248 +#endif
58249 + return 1;
58250 +}
58251 +
58252 +int
58253 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
58254 +{
58255 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58256 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
58257 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58258 + if (cap_raised(chroot_caps, cap)) {
58259 + return 0;
58260 + }
58261 + }
58262 +#endif
58263 + return 1;
58264 +}
58265 +
58266 +int
58267 +gr_chroot_is_capable_nolog(const int cap)
58268 +{
58269 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58270 + return gr_task_chroot_is_capable_nolog(current, cap);
58271 +#endif
58272 + return 1;
58273 +}
58274 +
58275 +int
58276 +gr_handle_chroot_sysctl(const int op)
58277 +{
58278 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58279 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
58280 + proc_is_chrooted(current))
58281 + return -EACCES;
58282 +#endif
58283 + return 0;
58284 +}
58285 +
58286 +void
58287 +gr_handle_chroot_chdir(struct path *path)
58288 +{
58289 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58290 + if (grsec_enable_chroot_chdir)
58291 + set_fs_pwd(current->fs, path);
58292 +#endif
58293 + return;
58294 +}
58295 +
58296 +int
58297 +gr_handle_chroot_chmod(const struct dentry *dentry,
58298 + const struct vfsmount *mnt, const int mode)
58299 +{
58300 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58301 + /* allow chmod +s on directories, but not files */
58302 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
58303 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
58304 + proc_is_chrooted(current)) {
58305 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
58306 + return -EPERM;
58307 + }
58308 +#endif
58309 + return 0;
58310 +}
58311 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
58312 new file mode 100644
58313 index 0000000..b79fe50
58314 --- /dev/null
58315 +++ b/grsecurity/grsec_disabled.c
58316 @@ -0,0 +1,442 @@
58317 +#include <linux/kernel.h>
58318 +#include <linux/module.h>
58319 +#include <linux/sched.h>
58320 +#include <linux/file.h>
58321 +#include <linux/fs.h>
58322 +#include <linux/kdev_t.h>
58323 +#include <linux/net.h>
58324 +#include <linux/in.h>
58325 +#include <linux/ip.h>
58326 +#include <linux/skbuff.h>
58327 +#include <linux/sysctl.h>
58328 +
58329 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58330 +void
58331 +pax_set_initial_flags(struct linux_binprm *bprm)
58332 +{
58333 + return;
58334 +}
58335 +#endif
58336 +
58337 +#ifdef CONFIG_SYSCTL
58338 +__u32
58339 +gr_handle_sysctl(const struct ctl_table * table, const int op)
58340 +{
58341 + return 0;
58342 +}
58343 +#endif
58344 +
58345 +#ifdef CONFIG_TASKSTATS
58346 +int gr_is_taskstats_denied(int pid)
58347 +{
58348 + return 0;
58349 +}
58350 +#endif
58351 +
58352 +int
58353 +gr_acl_is_enabled(void)
58354 +{
58355 + return 0;
58356 +}
58357 +
58358 +void
58359 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
58360 +{
58361 + return;
58362 +}
58363 +
58364 +int
58365 +gr_handle_rawio(const struct inode *inode)
58366 +{
58367 + return 0;
58368 +}
58369 +
58370 +void
58371 +gr_acl_handle_psacct(struct task_struct *task, const long code)
58372 +{
58373 + return;
58374 +}
58375 +
58376 +int
58377 +gr_handle_ptrace(struct task_struct *task, const long request)
58378 +{
58379 + return 0;
58380 +}
58381 +
58382 +int
58383 +gr_handle_proc_ptrace(struct task_struct *task)
58384 +{
58385 + return 0;
58386 +}
58387 +
58388 +void
58389 +gr_learn_resource(const struct task_struct *task,
58390 + const int res, const unsigned long wanted, const int gt)
58391 +{
58392 + return;
58393 +}
58394 +
58395 +int
58396 +gr_set_acls(const int type)
58397 +{
58398 + return 0;
58399 +}
58400 +
58401 +int
58402 +gr_check_hidden_task(const struct task_struct *tsk)
58403 +{
58404 + return 0;
58405 +}
58406 +
58407 +int
58408 +gr_check_protected_task(const struct task_struct *task)
58409 +{
58410 + return 0;
58411 +}
58412 +
58413 +int
58414 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58415 +{
58416 + return 0;
58417 +}
58418 +
58419 +void
58420 +gr_copy_label(struct task_struct *tsk)
58421 +{
58422 + return;
58423 +}
58424 +
58425 +void
58426 +gr_set_pax_flags(struct task_struct *task)
58427 +{
58428 + return;
58429 +}
58430 +
58431 +int
58432 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
58433 + const int unsafe_share)
58434 +{
58435 + return 0;
58436 +}
58437 +
58438 +void
58439 +gr_handle_delete(const ino_t ino, const dev_t dev)
58440 +{
58441 + return;
58442 +}
58443 +
58444 +void
58445 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58446 +{
58447 + return;
58448 +}
58449 +
58450 +void
58451 +gr_handle_crash(struct task_struct *task, const int sig)
58452 +{
58453 + return;
58454 +}
58455 +
58456 +int
58457 +gr_check_crash_exec(const struct file *filp)
58458 +{
58459 + return 0;
58460 +}
58461 +
58462 +int
58463 +gr_check_crash_uid(const uid_t uid)
58464 +{
58465 + return 0;
58466 +}
58467 +
58468 +void
58469 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58470 + struct dentry *old_dentry,
58471 + struct dentry *new_dentry,
58472 + struct vfsmount *mnt, const __u8 replace)
58473 +{
58474 + return;
58475 +}
58476 +
58477 +int
58478 +gr_search_socket(const int family, const int type, const int protocol)
58479 +{
58480 + return 1;
58481 +}
58482 +
58483 +int
58484 +gr_search_connectbind(const int mode, const struct socket *sock,
58485 + const struct sockaddr_in *addr)
58486 +{
58487 + return 0;
58488 +}
58489 +
58490 +void
58491 +gr_handle_alertkill(struct task_struct *task)
58492 +{
58493 + return;
58494 +}
58495 +
58496 +__u32
58497 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58498 +{
58499 + return 1;
58500 +}
58501 +
58502 +__u32
58503 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58504 + const struct vfsmount * mnt)
58505 +{
58506 + return 1;
58507 +}
58508 +
58509 +__u32
58510 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58511 + int acc_mode)
58512 +{
58513 + return 1;
58514 +}
58515 +
58516 +__u32
58517 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58518 +{
58519 + return 1;
58520 +}
58521 +
58522 +__u32
58523 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58524 +{
58525 + return 1;
58526 +}
58527 +
58528 +int
58529 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58530 + unsigned int *vm_flags)
58531 +{
58532 + return 1;
58533 +}
58534 +
58535 +__u32
58536 +gr_acl_handle_truncate(const struct dentry * dentry,
58537 + const struct vfsmount * mnt)
58538 +{
58539 + return 1;
58540 +}
58541 +
58542 +__u32
58543 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58544 +{
58545 + return 1;
58546 +}
58547 +
58548 +__u32
58549 +gr_acl_handle_access(const struct dentry * dentry,
58550 + const struct vfsmount * mnt, const int fmode)
58551 +{
58552 + return 1;
58553 +}
58554 +
58555 +__u32
58556 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58557 + umode_t *mode)
58558 +{
58559 + return 1;
58560 +}
58561 +
58562 +__u32
58563 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58564 +{
58565 + return 1;
58566 +}
58567 +
58568 +__u32
58569 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58570 +{
58571 + return 1;
58572 +}
58573 +
58574 +void
58575 +grsecurity_init(void)
58576 +{
58577 + return;
58578 +}
58579 +
58580 +umode_t gr_acl_umask(void)
58581 +{
58582 + return 0;
58583 +}
58584 +
58585 +__u32
58586 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58587 + const struct dentry * parent_dentry,
58588 + const struct vfsmount * parent_mnt,
58589 + const int mode)
58590 +{
58591 + return 1;
58592 +}
58593 +
58594 +__u32
58595 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58596 + const struct dentry * parent_dentry,
58597 + const struct vfsmount * parent_mnt)
58598 +{
58599 + return 1;
58600 +}
58601 +
58602 +__u32
58603 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58604 + const struct dentry * parent_dentry,
58605 + const struct vfsmount * parent_mnt, const char *from)
58606 +{
58607 + return 1;
58608 +}
58609 +
58610 +__u32
58611 +gr_acl_handle_link(const struct dentry * new_dentry,
58612 + const struct dentry * parent_dentry,
58613 + const struct vfsmount * parent_mnt,
58614 + const struct dentry * old_dentry,
58615 + const struct vfsmount * old_mnt, const char *to)
58616 +{
58617 + return 1;
58618 +}
58619 +
58620 +int
58621 +gr_acl_handle_rename(const struct dentry *new_dentry,
58622 + const struct dentry *parent_dentry,
58623 + const struct vfsmount *parent_mnt,
58624 + const struct dentry *old_dentry,
58625 + const struct inode *old_parent_inode,
58626 + const struct vfsmount *old_mnt, const char *newname)
58627 +{
58628 + return 0;
58629 +}
58630 +
58631 +int
58632 +gr_acl_handle_filldir(const struct file *file, const char *name,
58633 + const int namelen, const ino_t ino)
58634 +{
58635 + return 1;
58636 +}
58637 +
58638 +int
58639 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58640 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58641 +{
58642 + return 1;
58643 +}
58644 +
58645 +int
58646 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58647 +{
58648 + return 0;
58649 +}
58650 +
58651 +int
58652 +gr_search_accept(const struct socket *sock)
58653 +{
58654 + return 0;
58655 +}
58656 +
58657 +int
58658 +gr_search_listen(const struct socket *sock)
58659 +{
58660 + return 0;
58661 +}
58662 +
58663 +int
58664 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58665 +{
58666 + return 0;
58667 +}
58668 +
58669 +__u32
58670 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58671 +{
58672 + return 1;
58673 +}
58674 +
58675 +__u32
58676 +gr_acl_handle_creat(const struct dentry * dentry,
58677 + const struct dentry * p_dentry,
58678 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58679 + const int imode)
58680 +{
58681 + return 1;
58682 +}
58683 +
58684 +void
58685 +gr_acl_handle_exit(void)
58686 +{
58687 + return;
58688 +}
58689 +
58690 +int
58691 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58692 +{
58693 + return 1;
58694 +}
58695 +
58696 +void
58697 +gr_set_role_label(const uid_t uid, const gid_t gid)
58698 +{
58699 + return;
58700 +}
58701 +
58702 +int
58703 +gr_acl_handle_procpidmem(const struct task_struct *task)
58704 +{
58705 + return 0;
58706 +}
58707 +
58708 +int
58709 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58710 +{
58711 + return 0;
58712 +}
58713 +
58714 +int
58715 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58716 +{
58717 + return 0;
58718 +}
58719 +
58720 +void
58721 +gr_set_kernel_label(struct task_struct *task)
58722 +{
58723 + return;
58724 +}
58725 +
58726 +int
58727 +gr_check_user_change(int real, int effective, int fs)
58728 +{
58729 + return 0;
58730 +}
58731 +
58732 +int
58733 +gr_check_group_change(int real, int effective, int fs)
58734 +{
58735 + return 0;
58736 +}
58737 +
58738 +int gr_acl_enable_at_secure(void)
58739 +{
58740 + return 0;
58741 +}
58742 +
58743 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58744 +{
58745 + return dentry->d_inode->i_sb->s_dev;
58746 +}
58747 +
58748 +void gr_put_exec_file(struct task_struct *task)
58749 +{
58750 + return;
58751 +}
58752 +
58753 +EXPORT_SYMBOL(gr_learn_resource);
58754 +EXPORT_SYMBOL(gr_set_kernel_label);
58755 +#ifdef CONFIG_SECURITY
58756 +EXPORT_SYMBOL(gr_check_user_change);
58757 +EXPORT_SYMBOL(gr_check_group_change);
58758 +#endif
58759 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58760 new file mode 100644
58761 index 0000000..abfa971
58762 --- /dev/null
58763 +++ b/grsecurity/grsec_exec.c
58764 @@ -0,0 +1,174 @@
58765 +#include <linux/kernel.h>
58766 +#include <linux/sched.h>
58767 +#include <linux/file.h>
58768 +#include <linux/binfmts.h>
58769 +#include <linux/fs.h>
58770 +#include <linux/types.h>
58771 +#include <linux/grdefs.h>
58772 +#include <linux/grsecurity.h>
58773 +#include <linux/grinternal.h>
58774 +#include <linux/capability.h>
58775 +#include <linux/module.h>
58776 +
58777 +#include <asm/uaccess.h>
58778 +
58779 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58780 +static char gr_exec_arg_buf[132];
58781 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58782 +#endif
58783 +
58784 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58785 +
58786 +void
58787 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58788 +{
58789 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58790 + char *grarg = gr_exec_arg_buf;
58791 + unsigned int i, x, execlen = 0;
58792 + char c;
58793 +
58794 + if (!((grsec_enable_execlog && grsec_enable_group &&
58795 + in_group_p(grsec_audit_gid))
58796 + || (grsec_enable_execlog && !grsec_enable_group)))
58797 + return;
58798 +
58799 + mutex_lock(&gr_exec_arg_mutex);
58800 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58801 +
58802 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58803 + const char __user *p;
58804 + unsigned int len;
58805 +
58806 + p = get_user_arg_ptr(argv, i);
58807 + if (IS_ERR(p))
58808 + goto log;
58809 +
58810 + len = strnlen_user(p, 128 - execlen);
58811 + if (len > 128 - execlen)
58812 + len = 128 - execlen;
58813 + else if (len > 0)
58814 + len--;
58815 + if (copy_from_user(grarg + execlen, p, len))
58816 + goto log;
58817 +
58818 + /* rewrite unprintable characters */
58819 + for (x = 0; x < len; x++) {
58820 + c = *(grarg + execlen + x);
58821 + if (c < 32 || c > 126)
58822 + *(grarg + execlen + x) = ' ';
58823 + }
58824 +
58825 + execlen += len;
58826 + *(grarg + execlen) = ' ';
58827 + *(grarg + execlen + 1) = '\0';
58828 + execlen++;
58829 + }
58830 +
58831 + log:
58832 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58833 + bprm->file->f_path.mnt, grarg);
58834 + mutex_unlock(&gr_exec_arg_mutex);
58835 +#endif
58836 + return;
58837 +}
58838 +
58839 +#ifdef CONFIG_GRKERNSEC
58840 +extern int gr_acl_is_capable(const int cap);
58841 +extern int gr_acl_is_capable_nolog(const int cap);
58842 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58843 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58844 +extern int gr_chroot_is_capable(const int cap);
58845 +extern int gr_chroot_is_capable_nolog(const int cap);
58846 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58847 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58848 +#endif
58849 +
58850 +const char *captab_log[] = {
58851 + "CAP_CHOWN",
58852 + "CAP_DAC_OVERRIDE",
58853 + "CAP_DAC_READ_SEARCH",
58854 + "CAP_FOWNER",
58855 + "CAP_FSETID",
58856 + "CAP_KILL",
58857 + "CAP_SETGID",
58858 + "CAP_SETUID",
58859 + "CAP_SETPCAP",
58860 + "CAP_LINUX_IMMUTABLE",
58861 + "CAP_NET_BIND_SERVICE",
58862 + "CAP_NET_BROADCAST",
58863 + "CAP_NET_ADMIN",
58864 + "CAP_NET_RAW",
58865 + "CAP_IPC_LOCK",
58866 + "CAP_IPC_OWNER",
58867 + "CAP_SYS_MODULE",
58868 + "CAP_SYS_RAWIO",
58869 + "CAP_SYS_CHROOT",
58870 + "CAP_SYS_PTRACE",
58871 + "CAP_SYS_PACCT",
58872 + "CAP_SYS_ADMIN",
58873 + "CAP_SYS_BOOT",
58874 + "CAP_SYS_NICE",
58875 + "CAP_SYS_RESOURCE",
58876 + "CAP_SYS_TIME",
58877 + "CAP_SYS_TTY_CONFIG",
58878 + "CAP_MKNOD",
58879 + "CAP_LEASE",
58880 + "CAP_AUDIT_WRITE",
58881 + "CAP_AUDIT_CONTROL",
58882 + "CAP_SETFCAP",
58883 + "CAP_MAC_OVERRIDE",
58884 + "CAP_MAC_ADMIN",
58885 + "CAP_SYSLOG",
58886 + "CAP_WAKE_ALARM"
58887 +};
58888 +
58889 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58890 +
58891 +int gr_is_capable(const int cap)
58892 +{
58893 +#ifdef CONFIG_GRKERNSEC
58894 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58895 + return 1;
58896 + return 0;
58897 +#else
58898 + return 1;
58899 +#endif
58900 +}
58901 +
58902 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58903 +{
58904 +#ifdef CONFIG_GRKERNSEC
58905 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58906 + return 1;
58907 + return 0;
58908 +#else
58909 + return 1;
58910 +#endif
58911 +}
58912 +
58913 +int gr_is_capable_nolog(const int cap)
58914 +{
58915 +#ifdef CONFIG_GRKERNSEC
58916 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58917 + return 1;
58918 + return 0;
58919 +#else
58920 + return 1;
58921 +#endif
58922 +}
58923 +
58924 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58925 +{
58926 +#ifdef CONFIG_GRKERNSEC
58927 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58928 + return 1;
58929 + return 0;
58930 +#else
58931 + return 1;
58932 +#endif
58933 +}
58934 +
58935 +EXPORT_SYMBOL(gr_is_capable);
58936 +EXPORT_SYMBOL(gr_is_capable_nolog);
58937 +EXPORT_SYMBOL(gr_task_is_capable);
58938 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58939 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58940 new file mode 100644
58941 index 0000000..d3ee748
58942 --- /dev/null
58943 +++ b/grsecurity/grsec_fifo.c
58944 @@ -0,0 +1,24 @@
58945 +#include <linux/kernel.h>
58946 +#include <linux/sched.h>
58947 +#include <linux/fs.h>
58948 +#include <linux/file.h>
58949 +#include <linux/grinternal.h>
58950 +
58951 +int
58952 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58953 + const struct dentry *dir, const int flag, const int acc_mode)
58954 +{
58955 +#ifdef CONFIG_GRKERNSEC_FIFO
58956 + const struct cred *cred = current_cred();
58957 +
58958 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58959 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58960 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58961 + (cred->fsuid != dentry->d_inode->i_uid)) {
58962 + if (!inode_permission(dentry->d_inode, acc_mode))
58963 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58964 + return -EACCES;
58965 + }
58966 +#endif
58967 + return 0;
58968 +}
58969 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58970 new file mode 100644
58971 index 0000000..8ca18bf
58972 --- /dev/null
58973 +++ b/grsecurity/grsec_fork.c
58974 @@ -0,0 +1,23 @@
58975 +#include <linux/kernel.h>
58976 +#include <linux/sched.h>
58977 +#include <linux/grsecurity.h>
58978 +#include <linux/grinternal.h>
58979 +#include <linux/errno.h>
58980 +
58981 +void
58982 +gr_log_forkfail(const int retval)
58983 +{
58984 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58985 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58986 + switch (retval) {
58987 + case -EAGAIN:
58988 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58989 + break;
58990 + case -ENOMEM:
58991 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58992 + break;
58993 + }
58994 + }
58995 +#endif
58996 + return;
58997 +}
58998 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58999 new file mode 100644
59000 index 0000000..05a6015
59001 --- /dev/null
59002 +++ b/grsecurity/grsec_init.c
59003 @@ -0,0 +1,283 @@
59004 +#include <linux/kernel.h>
59005 +#include <linux/sched.h>
59006 +#include <linux/mm.h>
59007 +#include <linux/gracl.h>
59008 +#include <linux/slab.h>
59009 +#include <linux/vmalloc.h>
59010 +#include <linux/percpu.h>
59011 +#include <linux/module.h>
59012 +
59013 +int grsec_enable_ptrace_readexec;
59014 +int grsec_enable_setxid;
59015 +int grsec_enable_symlinkown;
59016 +int grsec_symlinkown_gid;
59017 +int grsec_enable_brute;
59018 +int grsec_enable_link;
59019 +int grsec_enable_dmesg;
59020 +int grsec_enable_harden_ptrace;
59021 +int grsec_enable_fifo;
59022 +int grsec_enable_execlog;
59023 +int grsec_enable_signal;
59024 +int grsec_enable_forkfail;
59025 +int grsec_enable_audit_ptrace;
59026 +int grsec_enable_time;
59027 +int grsec_enable_audit_textrel;
59028 +int grsec_enable_group;
59029 +int grsec_audit_gid;
59030 +int grsec_enable_chdir;
59031 +int grsec_enable_mount;
59032 +int grsec_enable_rofs;
59033 +int grsec_enable_chroot_findtask;
59034 +int grsec_enable_chroot_mount;
59035 +int grsec_enable_chroot_shmat;
59036 +int grsec_enable_chroot_fchdir;
59037 +int grsec_enable_chroot_double;
59038 +int grsec_enable_chroot_pivot;
59039 +int grsec_enable_chroot_chdir;
59040 +int grsec_enable_chroot_chmod;
59041 +int grsec_enable_chroot_mknod;
59042 +int grsec_enable_chroot_nice;
59043 +int grsec_enable_chroot_execlog;
59044 +int grsec_enable_chroot_caps;
59045 +int grsec_enable_chroot_sysctl;
59046 +int grsec_enable_chroot_unix;
59047 +int grsec_enable_tpe;
59048 +int grsec_tpe_gid;
59049 +int grsec_enable_blackhole;
59050 +#ifdef CONFIG_IPV6_MODULE
59051 +EXPORT_SYMBOL(grsec_enable_blackhole);
59052 +#endif
59053 +int grsec_lastack_retries;
59054 +int grsec_enable_tpe_all;
59055 +int grsec_enable_tpe_invert;
59056 +int grsec_enable_socket_all;
59057 +int grsec_socket_all_gid;
59058 +int grsec_enable_socket_client;
59059 +int grsec_socket_client_gid;
59060 +int grsec_enable_socket_server;
59061 +int grsec_socket_server_gid;
59062 +int grsec_resource_logging;
59063 +int grsec_disable_privio;
59064 +int grsec_enable_log_rwxmaps;
59065 +int grsec_lock;
59066 +
59067 +DEFINE_SPINLOCK(grsec_alert_lock);
59068 +unsigned long grsec_alert_wtime = 0;
59069 +unsigned long grsec_alert_fyet = 0;
59070 +
59071 +DEFINE_SPINLOCK(grsec_audit_lock);
59072 +
59073 +DEFINE_RWLOCK(grsec_exec_file_lock);
59074 +
59075 +char *gr_shared_page[4];
59076 +
59077 +char *gr_alert_log_fmt;
59078 +char *gr_audit_log_fmt;
59079 +char *gr_alert_log_buf;
59080 +char *gr_audit_log_buf;
59081 +
59082 +extern struct gr_arg *gr_usermode;
59083 +extern unsigned char *gr_system_salt;
59084 +extern unsigned char *gr_system_sum;
59085 +
59086 +void __init
59087 +grsecurity_init(void)
59088 +{
59089 + int j;
59090 + /* create the per-cpu shared pages */
59091 +
59092 +#ifdef CONFIG_X86
59093 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
59094 +#endif
59095 +
59096 + for (j = 0; j < 4; j++) {
59097 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
59098 + if (gr_shared_page[j] == NULL) {
59099 + panic("Unable to allocate grsecurity shared page");
59100 + return;
59101 + }
59102 + }
59103 +
59104 + /* allocate log buffers */
59105 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
59106 + if (!gr_alert_log_fmt) {
59107 + panic("Unable to allocate grsecurity alert log format buffer");
59108 + return;
59109 + }
59110 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
59111 + if (!gr_audit_log_fmt) {
59112 + panic("Unable to allocate grsecurity audit log format buffer");
59113 + return;
59114 + }
59115 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
59116 + if (!gr_alert_log_buf) {
59117 + panic("Unable to allocate grsecurity alert log buffer");
59118 + return;
59119 + }
59120 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
59121 + if (!gr_audit_log_buf) {
59122 + panic("Unable to allocate grsecurity audit log buffer");
59123 + return;
59124 + }
59125 +
59126 + /* allocate memory for authentication structure */
59127 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
59128 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
59129 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
59130 +
59131 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
59132 + panic("Unable to allocate grsecurity authentication structure");
59133 + return;
59134 + }
59135 +
59136 +
59137 +#ifdef CONFIG_GRKERNSEC_IO
59138 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
59139 + grsec_disable_privio = 1;
59140 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
59141 + grsec_disable_privio = 1;
59142 +#else
59143 + grsec_disable_privio = 0;
59144 +#endif
59145 +#endif
59146 +
59147 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59148 + /* for backward compatibility, tpe_invert always defaults to on if
59149 + enabled in the kernel
59150 + */
59151 + grsec_enable_tpe_invert = 1;
59152 +#endif
59153 +
59154 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
59155 +#ifndef CONFIG_GRKERNSEC_SYSCTL
59156 + grsec_lock = 1;
59157 +#endif
59158 +
59159 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59160 + grsec_enable_audit_textrel = 1;
59161 +#endif
59162 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59163 + grsec_enable_log_rwxmaps = 1;
59164 +#endif
59165 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59166 + grsec_enable_group = 1;
59167 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
59168 +#endif
59169 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59170 + grsec_enable_ptrace_readexec = 1;
59171 +#endif
59172 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59173 + grsec_enable_chdir = 1;
59174 +#endif
59175 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59176 + grsec_enable_harden_ptrace = 1;
59177 +#endif
59178 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59179 + grsec_enable_mount = 1;
59180 +#endif
59181 +#ifdef CONFIG_GRKERNSEC_LINK
59182 + grsec_enable_link = 1;
59183 +#endif
59184 +#ifdef CONFIG_GRKERNSEC_BRUTE
59185 + grsec_enable_brute = 1;
59186 +#endif
59187 +#ifdef CONFIG_GRKERNSEC_DMESG
59188 + grsec_enable_dmesg = 1;
59189 +#endif
59190 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59191 + grsec_enable_blackhole = 1;
59192 + grsec_lastack_retries = 4;
59193 +#endif
59194 +#ifdef CONFIG_GRKERNSEC_FIFO
59195 + grsec_enable_fifo = 1;
59196 +#endif
59197 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59198 + grsec_enable_execlog = 1;
59199 +#endif
59200 +#ifdef CONFIG_GRKERNSEC_SETXID
59201 + grsec_enable_setxid = 1;
59202 +#endif
59203 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59204 + grsec_enable_signal = 1;
59205 +#endif
59206 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59207 + grsec_enable_forkfail = 1;
59208 +#endif
59209 +#ifdef CONFIG_GRKERNSEC_TIME
59210 + grsec_enable_time = 1;
59211 +#endif
59212 +#ifdef CONFIG_GRKERNSEC_RESLOG
59213 + grsec_resource_logging = 1;
59214 +#endif
59215 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59216 + grsec_enable_chroot_findtask = 1;
59217 +#endif
59218 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59219 + grsec_enable_chroot_unix = 1;
59220 +#endif
59221 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59222 + grsec_enable_chroot_mount = 1;
59223 +#endif
59224 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59225 + grsec_enable_chroot_fchdir = 1;
59226 +#endif
59227 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59228 + grsec_enable_chroot_shmat = 1;
59229 +#endif
59230 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59231 + grsec_enable_audit_ptrace = 1;
59232 +#endif
59233 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59234 + grsec_enable_chroot_double = 1;
59235 +#endif
59236 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59237 + grsec_enable_chroot_pivot = 1;
59238 +#endif
59239 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59240 + grsec_enable_chroot_chdir = 1;
59241 +#endif
59242 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59243 + grsec_enable_chroot_chmod = 1;
59244 +#endif
59245 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59246 + grsec_enable_chroot_mknod = 1;
59247 +#endif
59248 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59249 + grsec_enable_chroot_nice = 1;
59250 +#endif
59251 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59252 + grsec_enable_chroot_execlog = 1;
59253 +#endif
59254 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59255 + grsec_enable_chroot_caps = 1;
59256 +#endif
59257 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59258 + grsec_enable_chroot_sysctl = 1;
59259 +#endif
59260 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59261 + grsec_enable_symlinkown = 1;
59262 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
59263 +#endif
59264 +#ifdef CONFIG_GRKERNSEC_TPE
59265 + grsec_enable_tpe = 1;
59266 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
59267 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59268 + grsec_enable_tpe_all = 1;
59269 +#endif
59270 +#endif
59271 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59272 + grsec_enable_socket_all = 1;
59273 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
59274 +#endif
59275 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59276 + grsec_enable_socket_client = 1;
59277 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
59278 +#endif
59279 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59280 + grsec_enable_socket_server = 1;
59281 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
59282 +#endif
59283 +#endif
59284 +
59285 + return;
59286 +}
59287 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
59288 new file mode 100644
59289 index 0000000..589481f
59290 --- /dev/null
59291 +++ b/grsecurity/grsec_link.c
59292 @@ -0,0 +1,58 @@
59293 +#include <linux/kernel.h>
59294 +#include <linux/sched.h>
59295 +#include <linux/fs.h>
59296 +#include <linux/file.h>
59297 +#include <linux/grinternal.h>
59298 +
59299 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
59300 +{
59301 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59302 + const struct inode *link_inode = link->dentry->d_inode;
59303 +
59304 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
59305 + /* ignore root-owned links, e.g. /proc/self */
59306 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
59307 + !uid_eq(link_inode->i_uid, target->i_uid)) {
59308 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
59309 + return 1;
59310 + }
59311 +#endif
59312 + return 0;
59313 +}
59314 +
59315 +int
59316 +gr_handle_follow_link(const struct inode *parent,
59317 + const struct inode *inode,
59318 + const struct dentry *dentry, const struct vfsmount *mnt)
59319 +{
59320 +#ifdef CONFIG_GRKERNSEC_LINK
59321 + const struct cred *cred = current_cred();
59322 +
59323 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
59324 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
59325 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
59326 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
59327 + return -EACCES;
59328 + }
59329 +#endif
59330 + return 0;
59331 +}
59332 +
59333 +int
59334 +gr_handle_hardlink(const struct dentry *dentry,
59335 + const struct vfsmount *mnt,
59336 + struct inode *inode, const int mode, const char *to)
59337 +{
59338 +#ifdef CONFIG_GRKERNSEC_LINK
59339 + const struct cred *cred = current_cred();
59340 +
59341 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
59342 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
59343 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
59344 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59345 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
59346 + return -EPERM;
59347 + }
59348 +#endif
59349 + return 0;
59350 +}
59351 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
59352 new file mode 100644
59353 index 0000000..a45d2e9
59354 --- /dev/null
59355 +++ b/grsecurity/grsec_log.c
59356 @@ -0,0 +1,322 @@
59357 +#include <linux/kernel.h>
59358 +#include <linux/sched.h>
59359 +#include <linux/file.h>
59360 +#include <linux/tty.h>
59361 +#include <linux/fs.h>
59362 +#include <linux/grinternal.h>
59363 +
59364 +#ifdef CONFIG_TREE_PREEMPT_RCU
59365 +#define DISABLE_PREEMPT() preempt_disable()
59366 +#define ENABLE_PREEMPT() preempt_enable()
59367 +#else
59368 +#define DISABLE_PREEMPT()
59369 +#define ENABLE_PREEMPT()
59370 +#endif
59371 +
59372 +#define BEGIN_LOCKS(x) \
59373 + DISABLE_PREEMPT(); \
59374 + rcu_read_lock(); \
59375 + read_lock(&tasklist_lock); \
59376 + read_lock(&grsec_exec_file_lock); \
59377 + if (x != GR_DO_AUDIT) \
59378 + spin_lock(&grsec_alert_lock); \
59379 + else \
59380 + spin_lock(&grsec_audit_lock)
59381 +
59382 +#define END_LOCKS(x) \
59383 + if (x != GR_DO_AUDIT) \
59384 + spin_unlock(&grsec_alert_lock); \
59385 + else \
59386 + spin_unlock(&grsec_audit_lock); \
59387 + read_unlock(&grsec_exec_file_lock); \
59388 + read_unlock(&tasklist_lock); \
59389 + rcu_read_unlock(); \
59390 + ENABLE_PREEMPT(); \
59391 + if (x == GR_DONT_AUDIT) \
59392 + gr_handle_alertkill(current)
59393 +
59394 +enum {
59395 + FLOODING,
59396 + NO_FLOODING
59397 +};
59398 +
59399 +extern char *gr_alert_log_fmt;
59400 +extern char *gr_audit_log_fmt;
59401 +extern char *gr_alert_log_buf;
59402 +extern char *gr_audit_log_buf;
59403 +
59404 +static int gr_log_start(int audit)
59405 +{
59406 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
59407 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
59408 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59409 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
59410 + unsigned long curr_secs = get_seconds();
59411 +
59412 + if (audit == GR_DO_AUDIT)
59413 + goto set_fmt;
59414 +
59415 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
59416 + grsec_alert_wtime = curr_secs;
59417 + grsec_alert_fyet = 0;
59418 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
59419 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
59420 + grsec_alert_fyet++;
59421 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
59422 + grsec_alert_wtime = curr_secs;
59423 + grsec_alert_fyet++;
59424 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
59425 + return FLOODING;
59426 + }
59427 + else return FLOODING;
59428 +
59429 +set_fmt:
59430 +#endif
59431 + memset(buf, 0, PAGE_SIZE);
59432 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
59433 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
59434 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59435 + } else if (current->signal->curr_ip) {
59436 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
59437 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
59438 + } else if (gr_acl_is_enabled()) {
59439 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
59440 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59441 + } else {
59442 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
59443 + strcpy(buf, fmt);
59444 + }
59445 +
59446 + return NO_FLOODING;
59447 +}
59448 +
59449 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59450 + __attribute__ ((format (printf, 2, 0)));
59451 +
59452 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59453 +{
59454 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59455 + unsigned int len = strlen(buf);
59456 +
59457 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59458 +
59459 + return;
59460 +}
59461 +
59462 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59463 + __attribute__ ((format (printf, 2, 3)));
59464 +
59465 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59466 +{
59467 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59468 + unsigned int len = strlen(buf);
59469 + va_list ap;
59470 +
59471 + va_start(ap, msg);
59472 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59473 + va_end(ap);
59474 +
59475 + return;
59476 +}
59477 +
59478 +static void gr_log_end(int audit, int append_default)
59479 +{
59480 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59481 +
59482 + if (append_default) {
59483 + unsigned int len = strlen(buf);
59484 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59485 + }
59486 +
59487 + printk("%s\n", buf);
59488 +
59489 + return;
59490 +}
59491 +
59492 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59493 +{
59494 + int logtype;
59495 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59496 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59497 + void *voidptr = NULL;
59498 + int num1 = 0, num2 = 0;
59499 + unsigned long ulong1 = 0, ulong2 = 0;
59500 + struct dentry *dentry = NULL;
59501 + struct vfsmount *mnt = NULL;
59502 + struct file *file = NULL;
59503 + struct task_struct *task = NULL;
59504 + const struct cred *cred, *pcred;
59505 + va_list ap;
59506 +
59507 + BEGIN_LOCKS(audit);
59508 + logtype = gr_log_start(audit);
59509 + if (logtype == FLOODING) {
59510 + END_LOCKS(audit);
59511 + return;
59512 + }
59513 + va_start(ap, argtypes);
59514 + switch (argtypes) {
59515 + case GR_TTYSNIFF:
59516 + task = va_arg(ap, struct task_struct *);
59517 + 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);
59518 + break;
59519 + case GR_SYSCTL_HIDDEN:
59520 + str1 = va_arg(ap, char *);
59521 + gr_log_middle_varargs(audit, msg, result, str1);
59522 + break;
59523 + case GR_RBAC:
59524 + dentry = va_arg(ap, struct dentry *);
59525 + mnt = va_arg(ap, struct vfsmount *);
59526 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59527 + break;
59528 + case GR_RBAC_STR:
59529 + dentry = va_arg(ap, struct dentry *);
59530 + mnt = va_arg(ap, struct vfsmount *);
59531 + str1 = va_arg(ap, char *);
59532 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59533 + break;
59534 + case GR_STR_RBAC:
59535 + str1 = va_arg(ap, char *);
59536 + dentry = va_arg(ap, struct dentry *);
59537 + mnt = va_arg(ap, struct vfsmount *);
59538 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59539 + break;
59540 + case GR_RBAC_MODE2:
59541 + dentry = va_arg(ap, struct dentry *);
59542 + mnt = va_arg(ap, struct vfsmount *);
59543 + str1 = va_arg(ap, char *);
59544 + str2 = va_arg(ap, char *);
59545 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59546 + break;
59547 + case GR_RBAC_MODE3:
59548 + dentry = va_arg(ap, struct dentry *);
59549 + mnt = va_arg(ap, struct vfsmount *);
59550 + str1 = va_arg(ap, char *);
59551 + str2 = va_arg(ap, char *);
59552 + str3 = va_arg(ap, char *);
59553 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59554 + break;
59555 + case GR_FILENAME:
59556 + dentry = va_arg(ap, struct dentry *);
59557 + mnt = va_arg(ap, struct vfsmount *);
59558 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59559 + break;
59560 + case GR_STR_FILENAME:
59561 + str1 = va_arg(ap, char *);
59562 + dentry = va_arg(ap, struct dentry *);
59563 + mnt = va_arg(ap, struct vfsmount *);
59564 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59565 + break;
59566 + case GR_FILENAME_STR:
59567 + dentry = va_arg(ap, struct dentry *);
59568 + mnt = va_arg(ap, struct vfsmount *);
59569 + str1 = va_arg(ap, char *);
59570 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59571 + break;
59572 + case GR_FILENAME_TWO_INT:
59573 + dentry = va_arg(ap, struct dentry *);
59574 + mnt = va_arg(ap, struct vfsmount *);
59575 + num1 = va_arg(ap, int);
59576 + num2 = va_arg(ap, int);
59577 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59578 + break;
59579 + case GR_FILENAME_TWO_INT_STR:
59580 + dentry = va_arg(ap, struct dentry *);
59581 + mnt = va_arg(ap, struct vfsmount *);
59582 + num1 = va_arg(ap, int);
59583 + num2 = va_arg(ap, int);
59584 + str1 = va_arg(ap, char *);
59585 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59586 + break;
59587 + case GR_TEXTREL:
59588 + file = va_arg(ap, struct file *);
59589 + ulong1 = va_arg(ap, unsigned long);
59590 + ulong2 = va_arg(ap, unsigned long);
59591 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59592 + break;
59593 + case GR_PTRACE:
59594 + task = va_arg(ap, struct task_struct *);
59595 + 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);
59596 + break;
59597 + case GR_RESOURCE:
59598 + task = va_arg(ap, struct task_struct *);
59599 + cred = __task_cred(task);
59600 + pcred = __task_cred(task->real_parent);
59601 + ulong1 = va_arg(ap, unsigned long);
59602 + str1 = va_arg(ap, char *);
59603 + ulong2 = va_arg(ap, unsigned long);
59604 + 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);
59605 + break;
59606 + case GR_CAP:
59607 + task = va_arg(ap, struct task_struct *);
59608 + cred = __task_cred(task);
59609 + pcred = __task_cred(task->real_parent);
59610 + str1 = va_arg(ap, char *);
59611 + 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);
59612 + break;
59613 + case GR_SIG:
59614 + str1 = va_arg(ap, char *);
59615 + voidptr = va_arg(ap, void *);
59616 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59617 + break;
59618 + case GR_SIG2:
59619 + task = va_arg(ap, struct task_struct *);
59620 + cred = __task_cred(task);
59621 + pcred = __task_cred(task->real_parent);
59622 + num1 = va_arg(ap, int);
59623 + 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);
59624 + break;
59625 + case GR_CRASH1:
59626 + task = va_arg(ap, struct task_struct *);
59627 + cred = __task_cred(task);
59628 + pcred = __task_cred(task->real_parent);
59629 + ulong1 = va_arg(ap, unsigned long);
59630 + 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);
59631 + break;
59632 + case GR_CRASH2:
59633 + task = va_arg(ap, struct task_struct *);
59634 + cred = __task_cred(task);
59635 + pcred = __task_cred(task->real_parent);
59636 + ulong1 = va_arg(ap, unsigned long);
59637 + 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);
59638 + break;
59639 + case GR_RWXMAP:
59640 + file = va_arg(ap, struct file *);
59641 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59642 + break;
59643 + case GR_PSACCT:
59644 + {
59645 + unsigned int wday, cday;
59646 + __u8 whr, chr;
59647 + __u8 wmin, cmin;
59648 + __u8 wsec, csec;
59649 + char cur_tty[64] = { 0 };
59650 + char parent_tty[64] = { 0 };
59651 +
59652 + task = va_arg(ap, struct task_struct *);
59653 + wday = va_arg(ap, unsigned int);
59654 + cday = va_arg(ap, unsigned int);
59655 + whr = va_arg(ap, int);
59656 + chr = va_arg(ap, int);
59657 + wmin = va_arg(ap, int);
59658 + cmin = va_arg(ap, int);
59659 + wsec = va_arg(ap, int);
59660 + csec = va_arg(ap, int);
59661 + ulong1 = va_arg(ap, unsigned long);
59662 + cred = __task_cred(task);
59663 + pcred = __task_cred(task->real_parent);
59664 +
59665 + 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);
59666 + }
59667 + break;
59668 + default:
59669 + gr_log_middle(audit, msg, ap);
59670 + }
59671 + va_end(ap);
59672 + // these don't need DEFAULTSECARGS printed on the end
59673 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59674 + gr_log_end(audit, 0);
59675 + else
59676 + gr_log_end(audit, 1);
59677 + END_LOCKS(audit);
59678 +}
59679 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59680 new file mode 100644
59681 index 0000000..f536303
59682 --- /dev/null
59683 +++ b/grsecurity/grsec_mem.c
59684 @@ -0,0 +1,40 @@
59685 +#include <linux/kernel.h>
59686 +#include <linux/sched.h>
59687 +#include <linux/mm.h>
59688 +#include <linux/mman.h>
59689 +#include <linux/grinternal.h>
59690 +
59691 +void
59692 +gr_handle_ioperm(void)
59693 +{
59694 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59695 + return;
59696 +}
59697 +
59698 +void
59699 +gr_handle_iopl(void)
59700 +{
59701 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59702 + return;
59703 +}
59704 +
59705 +void
59706 +gr_handle_mem_readwrite(u64 from, u64 to)
59707 +{
59708 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59709 + return;
59710 +}
59711 +
59712 +void
59713 +gr_handle_vm86(void)
59714 +{
59715 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59716 + return;
59717 +}
59718 +
59719 +void
59720 +gr_log_badprocpid(const char *entry)
59721 +{
59722 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59723 + return;
59724 +}
59725 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59726 new file mode 100644
59727 index 0000000..2131422
59728 --- /dev/null
59729 +++ b/grsecurity/grsec_mount.c
59730 @@ -0,0 +1,62 @@
59731 +#include <linux/kernel.h>
59732 +#include <linux/sched.h>
59733 +#include <linux/mount.h>
59734 +#include <linux/grsecurity.h>
59735 +#include <linux/grinternal.h>
59736 +
59737 +void
59738 +gr_log_remount(const char *devname, const int retval)
59739 +{
59740 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59741 + if (grsec_enable_mount && (retval >= 0))
59742 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59743 +#endif
59744 + return;
59745 +}
59746 +
59747 +void
59748 +gr_log_unmount(const char *devname, const int retval)
59749 +{
59750 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59751 + if (grsec_enable_mount && (retval >= 0))
59752 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59753 +#endif
59754 + return;
59755 +}
59756 +
59757 +void
59758 +gr_log_mount(const char *from, const char *to, const int retval)
59759 +{
59760 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59761 + if (grsec_enable_mount && (retval >= 0))
59762 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59763 +#endif
59764 + return;
59765 +}
59766 +
59767 +int
59768 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59769 +{
59770 +#ifdef CONFIG_GRKERNSEC_ROFS
59771 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59772 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59773 + return -EPERM;
59774 + } else
59775 + return 0;
59776 +#endif
59777 + return 0;
59778 +}
59779 +
59780 +int
59781 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59782 +{
59783 +#ifdef CONFIG_GRKERNSEC_ROFS
59784 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59785 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59786 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59787 + return -EPERM;
59788 + } else
59789 + return 0;
59790 +#endif
59791 + return 0;
59792 +}
59793 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59794 new file mode 100644
59795 index 0000000..a3b12a0
59796 --- /dev/null
59797 +++ b/grsecurity/grsec_pax.c
59798 @@ -0,0 +1,36 @@
59799 +#include <linux/kernel.h>
59800 +#include <linux/sched.h>
59801 +#include <linux/mm.h>
59802 +#include <linux/file.h>
59803 +#include <linux/grinternal.h>
59804 +#include <linux/grsecurity.h>
59805 +
59806 +void
59807 +gr_log_textrel(struct vm_area_struct * vma)
59808 +{
59809 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59810 + if (grsec_enable_audit_textrel)
59811 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59812 +#endif
59813 + return;
59814 +}
59815 +
59816 +void
59817 +gr_log_rwxmmap(struct file *file)
59818 +{
59819 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59820 + if (grsec_enable_log_rwxmaps)
59821 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59822 +#endif
59823 + return;
59824 +}
59825 +
59826 +void
59827 +gr_log_rwxmprotect(struct file *file)
59828 +{
59829 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59830 + if (grsec_enable_log_rwxmaps)
59831 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59832 +#endif
59833 + return;
59834 +}
59835 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59836 new file mode 100644
59837 index 0000000..f7f29aa
59838 --- /dev/null
59839 +++ b/grsecurity/grsec_ptrace.c
59840 @@ -0,0 +1,30 @@
59841 +#include <linux/kernel.h>
59842 +#include <linux/sched.h>
59843 +#include <linux/grinternal.h>
59844 +#include <linux/security.h>
59845 +
59846 +void
59847 +gr_audit_ptrace(struct task_struct *task)
59848 +{
59849 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59850 + if (grsec_enable_audit_ptrace)
59851 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59852 +#endif
59853 + return;
59854 +}
59855 +
59856 +int
59857 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59858 +{
59859 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59860 + const struct dentry *dentry = file->f_path.dentry;
59861 + const struct vfsmount *mnt = file->f_path.mnt;
59862 +
59863 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59864 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59865 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59866 + return -EACCES;
59867 + }
59868 +#endif
59869 + return 0;
59870 +}
59871 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59872 new file mode 100644
59873 index 0000000..5c00416
59874 --- /dev/null
59875 +++ b/grsecurity/grsec_sig.c
59876 @@ -0,0 +1,222 @@
59877 +#include <linux/kernel.h>
59878 +#include <linux/sched.h>
59879 +#include <linux/delay.h>
59880 +#include <linux/grsecurity.h>
59881 +#include <linux/grinternal.h>
59882 +#include <linux/hardirq.h>
59883 +
59884 +char *signames[] = {
59885 + [SIGSEGV] = "Segmentation fault",
59886 + [SIGILL] = "Illegal instruction",
59887 + [SIGABRT] = "Abort",
59888 + [SIGBUS] = "Invalid alignment/Bus error"
59889 +};
59890 +
59891 +void
59892 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59893 +{
59894 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59895 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59896 + (sig == SIGABRT) || (sig == SIGBUS))) {
59897 + if (t->pid == current->pid) {
59898 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59899 + } else {
59900 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59901 + }
59902 + }
59903 +#endif
59904 + return;
59905 +}
59906 +
59907 +int
59908 +gr_handle_signal(const struct task_struct *p, const int sig)
59909 +{
59910 +#ifdef CONFIG_GRKERNSEC
59911 + /* ignore the 0 signal for protected task checks */
59912 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59913 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59914 + return -EPERM;
59915 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59916 + return -EPERM;
59917 + }
59918 +#endif
59919 + return 0;
59920 +}
59921 +
59922 +#ifdef CONFIG_GRKERNSEC
59923 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59924 +
59925 +int gr_fake_force_sig(int sig, struct task_struct *t)
59926 +{
59927 + unsigned long int flags;
59928 + int ret, blocked, ignored;
59929 + struct k_sigaction *action;
59930 +
59931 + spin_lock_irqsave(&t->sighand->siglock, flags);
59932 + action = &t->sighand->action[sig-1];
59933 + ignored = action->sa.sa_handler == SIG_IGN;
59934 + blocked = sigismember(&t->blocked, sig);
59935 + if (blocked || ignored) {
59936 + action->sa.sa_handler = SIG_DFL;
59937 + if (blocked) {
59938 + sigdelset(&t->blocked, sig);
59939 + recalc_sigpending_and_wake(t);
59940 + }
59941 + }
59942 + if (action->sa.sa_handler == SIG_DFL)
59943 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59944 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59945 +
59946 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59947 +
59948 + return ret;
59949 +}
59950 +#endif
59951 +
59952 +#ifdef CONFIG_GRKERNSEC_BRUTE
59953 +#define GR_USER_BAN_TIME (15 * 60)
59954 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
59955 +
59956 +static int __get_dumpable(unsigned long mm_flags)
59957 +{
59958 + int ret;
59959 +
59960 + ret = mm_flags & MMF_DUMPABLE_MASK;
59961 + return (ret >= 2) ? 2 : ret;
59962 +}
59963 +#endif
59964 +
59965 +void gr_handle_brute_attach(unsigned long mm_flags)
59966 +{
59967 +#ifdef CONFIG_GRKERNSEC_BRUTE
59968 + struct task_struct *p = current;
59969 + kuid_t uid = GLOBAL_ROOT_UID;
59970 + int daemon = 0;
59971 +
59972 + if (!grsec_enable_brute)
59973 + return;
59974 +
59975 + rcu_read_lock();
59976 + read_lock(&tasklist_lock);
59977 + read_lock(&grsec_exec_file_lock);
59978 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
59979 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
59980 + p->real_parent->brute = 1;
59981 + daemon = 1;
59982 + } else {
59983 + const struct cred *cred = __task_cred(p), *cred2;
59984 + struct task_struct *tsk, *tsk2;
59985 +
59986 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59987 + struct user_struct *user;
59988 +
59989 + uid = cred->uid;
59990 +
59991 + /* this is put upon execution past expiration */
59992 + user = find_user(uid);
59993 + if (user == NULL)
59994 + goto unlock;
59995 + user->banned = 1;
59996 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59997 + if (user->ban_expires == ~0UL)
59998 + user->ban_expires--;
59999 +
60000 + do_each_thread(tsk2, tsk) {
60001 + cred2 = __task_cred(tsk);
60002 + if (tsk != p && uid_eq(cred2->uid, uid))
60003 + gr_fake_force_sig(SIGKILL, tsk);
60004 + } while_each_thread(tsk2, tsk);
60005 + }
60006 + }
60007 +unlock:
60008 + read_unlock(&grsec_exec_file_lock);
60009 + read_unlock(&tasklist_lock);
60010 + rcu_read_unlock();
60011 +
60012 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
60013 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
60014 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
60015 + else if (daemon)
60016 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
60017 +
60018 +#endif
60019 + return;
60020 +}
60021 +
60022 +void gr_handle_brute_check(void)
60023 +{
60024 +#ifdef CONFIG_GRKERNSEC_BRUTE
60025 + struct task_struct *p = current;
60026 +
60027 + if (unlikely(p->brute)) {
60028 + if (!grsec_enable_brute)
60029 + p->brute = 0;
60030 + else if (time_before(get_seconds(), p->brute_expires))
60031 + msleep(30 * 1000);
60032 + }
60033 +#endif
60034 + return;
60035 +}
60036 +
60037 +void gr_handle_kernel_exploit(void)
60038 +{
60039 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
60040 + const struct cred *cred;
60041 + struct task_struct *tsk, *tsk2;
60042 + struct user_struct *user;
60043 + kuid_t uid;
60044 +
60045 + if (in_irq() || in_serving_softirq() || in_nmi())
60046 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
60047 +
60048 + uid = current_uid();
60049 +
60050 + if (uid_eq(uid, GLOBAL_ROOT_UID))
60051 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
60052 + else {
60053 + /* kill all the processes of this user, hold a reference
60054 + to their creds struct, and prevent them from creating
60055 + another process until system reset
60056 + */
60057 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
60058 + from_kuid_munged(&init_user_ns, uid));
60059 + /* we intentionally leak this ref */
60060 + user = get_uid(current->cred->user);
60061 + if (user) {
60062 + user->banned = 1;
60063 + user->ban_expires = ~0UL;
60064 + }
60065 +
60066 + read_lock(&tasklist_lock);
60067 + do_each_thread(tsk2, tsk) {
60068 + cred = __task_cred(tsk);
60069 + if (uid_eq(cred->uid, uid))
60070 + gr_fake_force_sig(SIGKILL, tsk);
60071 + } while_each_thread(tsk2, tsk);
60072 + read_unlock(&tasklist_lock);
60073 + }
60074 +#endif
60075 +}
60076 +
60077 +int __gr_process_user_ban(struct user_struct *user)
60078 +{
60079 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60080 + if (unlikely(user->banned)) {
60081 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
60082 + user->banned = 0;
60083 + user->ban_expires = 0;
60084 + free_uid(user);
60085 + } else
60086 + return -EPERM;
60087 + }
60088 +#endif
60089 + return 0;
60090 +}
60091 +
60092 +int gr_process_user_ban(void)
60093 +{
60094 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60095 + return __gr_process_user_ban(current->cred->user);
60096 +#endif
60097 + return 0;
60098 +}
60099 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
60100 new file mode 100644
60101 index 0000000..4030d57
60102 --- /dev/null
60103 +++ b/grsecurity/grsec_sock.c
60104 @@ -0,0 +1,244 @@
60105 +#include <linux/kernel.h>
60106 +#include <linux/module.h>
60107 +#include <linux/sched.h>
60108 +#include <linux/file.h>
60109 +#include <linux/net.h>
60110 +#include <linux/in.h>
60111 +#include <linux/ip.h>
60112 +#include <net/sock.h>
60113 +#include <net/inet_sock.h>
60114 +#include <linux/grsecurity.h>
60115 +#include <linux/grinternal.h>
60116 +#include <linux/gracl.h>
60117 +
60118 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
60119 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
60120 +
60121 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
60122 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
60123 +
60124 +#ifdef CONFIG_UNIX_MODULE
60125 +EXPORT_SYMBOL(gr_acl_handle_unix);
60126 +EXPORT_SYMBOL(gr_acl_handle_mknod);
60127 +EXPORT_SYMBOL(gr_handle_chroot_unix);
60128 +EXPORT_SYMBOL(gr_handle_create);
60129 +#endif
60130 +
60131 +#ifdef CONFIG_GRKERNSEC
60132 +#define gr_conn_table_size 32749
60133 +struct conn_table_entry {
60134 + struct conn_table_entry *next;
60135 + struct signal_struct *sig;
60136 +};
60137 +
60138 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
60139 +DEFINE_SPINLOCK(gr_conn_table_lock);
60140 +
60141 +extern const char * gr_socktype_to_name(unsigned char type);
60142 +extern const char * gr_proto_to_name(unsigned char proto);
60143 +extern const char * gr_sockfamily_to_name(unsigned char family);
60144 +
60145 +static __inline__ int
60146 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
60147 +{
60148 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
60149 +}
60150 +
60151 +static __inline__ int
60152 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
60153 + __u16 sport, __u16 dport)
60154 +{
60155 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
60156 + sig->gr_sport == sport && sig->gr_dport == dport))
60157 + return 1;
60158 + else
60159 + return 0;
60160 +}
60161 +
60162 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
60163 +{
60164 + struct conn_table_entry **match;
60165 + unsigned int index;
60166 +
60167 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
60168 + sig->gr_sport, sig->gr_dport,
60169 + gr_conn_table_size);
60170 +
60171 + newent->sig = sig;
60172 +
60173 + match = &gr_conn_table[index];
60174 + newent->next = *match;
60175 + *match = newent;
60176 +
60177 + return;
60178 +}
60179 +
60180 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
60181 +{
60182 + struct conn_table_entry *match, *last = NULL;
60183 + unsigned int index;
60184 +
60185 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
60186 + sig->gr_sport, sig->gr_dport,
60187 + gr_conn_table_size);
60188 +
60189 + match = gr_conn_table[index];
60190 + while (match && !conn_match(match->sig,
60191 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
60192 + sig->gr_dport)) {
60193 + last = match;
60194 + match = match->next;
60195 + }
60196 +
60197 + if (match) {
60198 + if (last)
60199 + last->next = match->next;
60200 + else
60201 + gr_conn_table[index] = NULL;
60202 + kfree(match);
60203 + }
60204 +
60205 + return;
60206 +}
60207 +
60208 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
60209 + __u16 sport, __u16 dport)
60210 +{
60211 + struct conn_table_entry *match;
60212 + unsigned int index;
60213 +
60214 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
60215 +
60216 + match = gr_conn_table[index];
60217 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
60218 + match = match->next;
60219 +
60220 + if (match)
60221 + return match->sig;
60222 + else
60223 + return NULL;
60224 +}
60225 +
60226 +#endif
60227 +
60228 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
60229 +{
60230 +#ifdef CONFIG_GRKERNSEC
60231 + struct signal_struct *sig = task->signal;
60232 + struct conn_table_entry *newent;
60233 +
60234 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
60235 + if (newent == NULL)
60236 + return;
60237 + /* no bh lock needed since we are called with bh disabled */
60238 + spin_lock(&gr_conn_table_lock);
60239 + gr_del_task_from_ip_table_nolock(sig);
60240 + sig->gr_saddr = inet->inet_rcv_saddr;
60241 + sig->gr_daddr = inet->inet_daddr;
60242 + sig->gr_sport = inet->inet_sport;
60243 + sig->gr_dport = inet->inet_dport;
60244 + gr_add_to_task_ip_table_nolock(sig, newent);
60245 + spin_unlock(&gr_conn_table_lock);
60246 +#endif
60247 + return;
60248 +}
60249 +
60250 +void gr_del_task_from_ip_table(struct task_struct *task)
60251 +{
60252 +#ifdef CONFIG_GRKERNSEC
60253 + spin_lock_bh(&gr_conn_table_lock);
60254 + gr_del_task_from_ip_table_nolock(task->signal);
60255 + spin_unlock_bh(&gr_conn_table_lock);
60256 +#endif
60257 + return;
60258 +}
60259 +
60260 +void
60261 +gr_attach_curr_ip(const struct sock *sk)
60262 +{
60263 +#ifdef CONFIG_GRKERNSEC
60264 + struct signal_struct *p, *set;
60265 + const struct inet_sock *inet = inet_sk(sk);
60266 +
60267 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
60268 + return;
60269 +
60270 + set = current->signal;
60271 +
60272 + spin_lock_bh(&gr_conn_table_lock);
60273 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
60274 + inet->inet_dport, inet->inet_sport);
60275 + if (unlikely(p != NULL)) {
60276 + set->curr_ip = p->curr_ip;
60277 + set->used_accept = 1;
60278 + gr_del_task_from_ip_table_nolock(p);
60279 + spin_unlock_bh(&gr_conn_table_lock);
60280 + return;
60281 + }
60282 + spin_unlock_bh(&gr_conn_table_lock);
60283 +
60284 + set->curr_ip = inet->inet_daddr;
60285 + set->used_accept = 1;
60286 +#endif
60287 + return;
60288 +}
60289 +
60290 +int
60291 +gr_handle_sock_all(const int family, const int type, const int protocol)
60292 +{
60293 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60294 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
60295 + (family != AF_UNIX)) {
60296 + if (family == AF_INET)
60297 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
60298 + else
60299 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
60300 + return -EACCES;
60301 + }
60302 +#endif
60303 + return 0;
60304 +}
60305 +
60306 +int
60307 +gr_handle_sock_server(const struct sockaddr *sck)
60308 +{
60309 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60310 + if (grsec_enable_socket_server &&
60311 + in_group_p(grsec_socket_server_gid) &&
60312 + sck && (sck->sa_family != AF_UNIX) &&
60313 + (sck->sa_family != AF_LOCAL)) {
60314 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60315 + return -EACCES;
60316 + }
60317 +#endif
60318 + return 0;
60319 +}
60320 +
60321 +int
60322 +gr_handle_sock_server_other(const struct sock *sck)
60323 +{
60324 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60325 + if (grsec_enable_socket_server &&
60326 + in_group_p(grsec_socket_server_gid) &&
60327 + sck && (sck->sk_family != AF_UNIX) &&
60328 + (sck->sk_family != AF_LOCAL)) {
60329 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60330 + return -EACCES;
60331 + }
60332 +#endif
60333 + return 0;
60334 +}
60335 +
60336 +int
60337 +gr_handle_sock_client(const struct sockaddr *sck)
60338 +{
60339 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60340 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
60341 + sck && (sck->sa_family != AF_UNIX) &&
60342 + (sck->sa_family != AF_LOCAL)) {
60343 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
60344 + return -EACCES;
60345 + }
60346 +#endif
60347 + return 0;
60348 +}
60349 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
60350 new file mode 100644
60351 index 0000000..f55ef0f
60352 --- /dev/null
60353 +++ b/grsecurity/grsec_sysctl.c
60354 @@ -0,0 +1,469 @@
60355 +#include <linux/kernel.h>
60356 +#include <linux/sched.h>
60357 +#include <linux/sysctl.h>
60358 +#include <linux/grsecurity.h>
60359 +#include <linux/grinternal.h>
60360 +
60361 +int
60362 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
60363 +{
60364 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60365 + if (dirname == NULL || name == NULL)
60366 + return 0;
60367 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
60368 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
60369 + return -EACCES;
60370 + }
60371 +#endif
60372 + return 0;
60373 +}
60374 +
60375 +#ifdef CONFIG_GRKERNSEC_ROFS
60376 +static int __maybe_unused one = 1;
60377 +#endif
60378 +
60379 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
60380 +struct ctl_table grsecurity_table[] = {
60381 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60382 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
60383 +#ifdef CONFIG_GRKERNSEC_IO
60384 + {
60385 + .procname = "disable_priv_io",
60386 + .data = &grsec_disable_privio,
60387 + .maxlen = sizeof(int),
60388 + .mode = 0600,
60389 + .proc_handler = &proc_dointvec,
60390 + },
60391 +#endif
60392 +#endif
60393 +#ifdef CONFIG_GRKERNSEC_LINK
60394 + {
60395 + .procname = "linking_restrictions",
60396 + .data = &grsec_enable_link,
60397 + .maxlen = sizeof(int),
60398 + .mode = 0600,
60399 + .proc_handler = &proc_dointvec,
60400 + },
60401 +#endif
60402 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60403 + {
60404 + .procname = "enforce_symlinksifowner",
60405 + .data = &grsec_enable_symlinkown,
60406 + .maxlen = sizeof(int),
60407 + .mode = 0600,
60408 + .proc_handler = &proc_dointvec,
60409 + },
60410 + {
60411 + .procname = "symlinkown_gid",
60412 + .data = &grsec_symlinkown_gid,
60413 + .maxlen = sizeof(int),
60414 + .mode = 0600,
60415 + .proc_handler = &proc_dointvec,
60416 + },
60417 +#endif
60418 +#ifdef CONFIG_GRKERNSEC_BRUTE
60419 + {
60420 + .procname = "deter_bruteforce",
60421 + .data = &grsec_enable_brute,
60422 + .maxlen = sizeof(int),
60423 + .mode = 0600,
60424 + .proc_handler = &proc_dointvec,
60425 + },
60426 +#endif
60427 +#ifdef CONFIG_GRKERNSEC_FIFO
60428 + {
60429 + .procname = "fifo_restrictions",
60430 + .data = &grsec_enable_fifo,
60431 + .maxlen = sizeof(int),
60432 + .mode = 0600,
60433 + .proc_handler = &proc_dointvec,
60434 + },
60435 +#endif
60436 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60437 + {
60438 + .procname = "ptrace_readexec",
60439 + .data = &grsec_enable_ptrace_readexec,
60440 + .maxlen = sizeof(int),
60441 + .mode = 0600,
60442 + .proc_handler = &proc_dointvec,
60443 + },
60444 +#endif
60445 +#ifdef CONFIG_GRKERNSEC_SETXID
60446 + {
60447 + .procname = "consistent_setxid",
60448 + .data = &grsec_enable_setxid,
60449 + .maxlen = sizeof(int),
60450 + .mode = 0600,
60451 + .proc_handler = &proc_dointvec,
60452 + },
60453 +#endif
60454 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60455 + {
60456 + .procname = "ip_blackhole",
60457 + .data = &grsec_enable_blackhole,
60458 + .maxlen = sizeof(int),
60459 + .mode = 0600,
60460 + .proc_handler = &proc_dointvec,
60461 + },
60462 + {
60463 + .procname = "lastack_retries",
60464 + .data = &grsec_lastack_retries,
60465 + .maxlen = sizeof(int),
60466 + .mode = 0600,
60467 + .proc_handler = &proc_dointvec,
60468 + },
60469 +#endif
60470 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60471 + {
60472 + .procname = "exec_logging",
60473 + .data = &grsec_enable_execlog,
60474 + .maxlen = sizeof(int),
60475 + .mode = 0600,
60476 + .proc_handler = &proc_dointvec,
60477 + },
60478 +#endif
60479 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60480 + {
60481 + .procname = "rwxmap_logging",
60482 + .data = &grsec_enable_log_rwxmaps,
60483 + .maxlen = sizeof(int),
60484 + .mode = 0600,
60485 + .proc_handler = &proc_dointvec,
60486 + },
60487 +#endif
60488 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60489 + {
60490 + .procname = "signal_logging",
60491 + .data = &grsec_enable_signal,
60492 + .maxlen = sizeof(int),
60493 + .mode = 0600,
60494 + .proc_handler = &proc_dointvec,
60495 + },
60496 +#endif
60497 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60498 + {
60499 + .procname = "forkfail_logging",
60500 + .data = &grsec_enable_forkfail,
60501 + .maxlen = sizeof(int),
60502 + .mode = 0600,
60503 + .proc_handler = &proc_dointvec,
60504 + },
60505 +#endif
60506 +#ifdef CONFIG_GRKERNSEC_TIME
60507 + {
60508 + .procname = "timechange_logging",
60509 + .data = &grsec_enable_time,
60510 + .maxlen = sizeof(int),
60511 + .mode = 0600,
60512 + .proc_handler = &proc_dointvec,
60513 + },
60514 +#endif
60515 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60516 + {
60517 + .procname = "chroot_deny_shmat",
60518 + .data = &grsec_enable_chroot_shmat,
60519 + .maxlen = sizeof(int),
60520 + .mode = 0600,
60521 + .proc_handler = &proc_dointvec,
60522 + },
60523 +#endif
60524 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60525 + {
60526 + .procname = "chroot_deny_unix",
60527 + .data = &grsec_enable_chroot_unix,
60528 + .maxlen = sizeof(int),
60529 + .mode = 0600,
60530 + .proc_handler = &proc_dointvec,
60531 + },
60532 +#endif
60533 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60534 + {
60535 + .procname = "chroot_deny_mount",
60536 + .data = &grsec_enable_chroot_mount,
60537 + .maxlen = sizeof(int),
60538 + .mode = 0600,
60539 + .proc_handler = &proc_dointvec,
60540 + },
60541 +#endif
60542 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60543 + {
60544 + .procname = "chroot_deny_fchdir",
60545 + .data = &grsec_enable_chroot_fchdir,
60546 + .maxlen = sizeof(int),
60547 + .mode = 0600,
60548 + .proc_handler = &proc_dointvec,
60549 + },
60550 +#endif
60551 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60552 + {
60553 + .procname = "chroot_deny_chroot",
60554 + .data = &grsec_enable_chroot_double,
60555 + .maxlen = sizeof(int),
60556 + .mode = 0600,
60557 + .proc_handler = &proc_dointvec,
60558 + },
60559 +#endif
60560 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60561 + {
60562 + .procname = "chroot_deny_pivot",
60563 + .data = &grsec_enable_chroot_pivot,
60564 + .maxlen = sizeof(int),
60565 + .mode = 0600,
60566 + .proc_handler = &proc_dointvec,
60567 + },
60568 +#endif
60569 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60570 + {
60571 + .procname = "chroot_enforce_chdir",
60572 + .data = &grsec_enable_chroot_chdir,
60573 + .maxlen = sizeof(int),
60574 + .mode = 0600,
60575 + .proc_handler = &proc_dointvec,
60576 + },
60577 +#endif
60578 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60579 + {
60580 + .procname = "chroot_deny_chmod",
60581 + .data = &grsec_enable_chroot_chmod,
60582 + .maxlen = sizeof(int),
60583 + .mode = 0600,
60584 + .proc_handler = &proc_dointvec,
60585 + },
60586 +#endif
60587 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60588 + {
60589 + .procname = "chroot_deny_mknod",
60590 + .data = &grsec_enable_chroot_mknod,
60591 + .maxlen = sizeof(int),
60592 + .mode = 0600,
60593 + .proc_handler = &proc_dointvec,
60594 + },
60595 +#endif
60596 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60597 + {
60598 + .procname = "chroot_restrict_nice",
60599 + .data = &grsec_enable_chroot_nice,
60600 + .maxlen = sizeof(int),
60601 + .mode = 0600,
60602 + .proc_handler = &proc_dointvec,
60603 + },
60604 +#endif
60605 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60606 + {
60607 + .procname = "chroot_execlog",
60608 + .data = &grsec_enable_chroot_execlog,
60609 + .maxlen = sizeof(int),
60610 + .mode = 0600,
60611 + .proc_handler = &proc_dointvec,
60612 + },
60613 +#endif
60614 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60615 + {
60616 + .procname = "chroot_caps",
60617 + .data = &grsec_enable_chroot_caps,
60618 + .maxlen = sizeof(int),
60619 + .mode = 0600,
60620 + .proc_handler = &proc_dointvec,
60621 + },
60622 +#endif
60623 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60624 + {
60625 + .procname = "chroot_deny_sysctl",
60626 + .data = &grsec_enable_chroot_sysctl,
60627 + .maxlen = sizeof(int),
60628 + .mode = 0600,
60629 + .proc_handler = &proc_dointvec,
60630 + },
60631 +#endif
60632 +#ifdef CONFIG_GRKERNSEC_TPE
60633 + {
60634 + .procname = "tpe",
60635 + .data = &grsec_enable_tpe,
60636 + .maxlen = sizeof(int),
60637 + .mode = 0600,
60638 + .proc_handler = &proc_dointvec,
60639 + },
60640 + {
60641 + .procname = "tpe_gid",
60642 + .data = &grsec_tpe_gid,
60643 + .maxlen = sizeof(int),
60644 + .mode = 0600,
60645 + .proc_handler = &proc_dointvec,
60646 + },
60647 +#endif
60648 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60649 + {
60650 + .procname = "tpe_invert",
60651 + .data = &grsec_enable_tpe_invert,
60652 + .maxlen = sizeof(int),
60653 + .mode = 0600,
60654 + .proc_handler = &proc_dointvec,
60655 + },
60656 +#endif
60657 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60658 + {
60659 + .procname = "tpe_restrict_all",
60660 + .data = &grsec_enable_tpe_all,
60661 + .maxlen = sizeof(int),
60662 + .mode = 0600,
60663 + .proc_handler = &proc_dointvec,
60664 + },
60665 +#endif
60666 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60667 + {
60668 + .procname = "socket_all",
60669 + .data = &grsec_enable_socket_all,
60670 + .maxlen = sizeof(int),
60671 + .mode = 0600,
60672 + .proc_handler = &proc_dointvec,
60673 + },
60674 + {
60675 + .procname = "socket_all_gid",
60676 + .data = &grsec_socket_all_gid,
60677 + .maxlen = sizeof(int),
60678 + .mode = 0600,
60679 + .proc_handler = &proc_dointvec,
60680 + },
60681 +#endif
60682 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60683 + {
60684 + .procname = "socket_client",
60685 + .data = &grsec_enable_socket_client,
60686 + .maxlen = sizeof(int),
60687 + .mode = 0600,
60688 + .proc_handler = &proc_dointvec,
60689 + },
60690 + {
60691 + .procname = "socket_client_gid",
60692 + .data = &grsec_socket_client_gid,
60693 + .maxlen = sizeof(int),
60694 + .mode = 0600,
60695 + .proc_handler = &proc_dointvec,
60696 + },
60697 +#endif
60698 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60699 + {
60700 + .procname = "socket_server",
60701 + .data = &grsec_enable_socket_server,
60702 + .maxlen = sizeof(int),
60703 + .mode = 0600,
60704 + .proc_handler = &proc_dointvec,
60705 + },
60706 + {
60707 + .procname = "socket_server_gid",
60708 + .data = &grsec_socket_server_gid,
60709 + .maxlen = sizeof(int),
60710 + .mode = 0600,
60711 + .proc_handler = &proc_dointvec,
60712 + },
60713 +#endif
60714 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60715 + {
60716 + .procname = "audit_group",
60717 + .data = &grsec_enable_group,
60718 + .maxlen = sizeof(int),
60719 + .mode = 0600,
60720 + .proc_handler = &proc_dointvec,
60721 + },
60722 + {
60723 + .procname = "audit_gid",
60724 + .data = &grsec_audit_gid,
60725 + .maxlen = sizeof(int),
60726 + .mode = 0600,
60727 + .proc_handler = &proc_dointvec,
60728 + },
60729 +#endif
60730 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60731 + {
60732 + .procname = "audit_chdir",
60733 + .data = &grsec_enable_chdir,
60734 + .maxlen = sizeof(int),
60735 + .mode = 0600,
60736 + .proc_handler = &proc_dointvec,
60737 + },
60738 +#endif
60739 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60740 + {
60741 + .procname = "audit_mount",
60742 + .data = &grsec_enable_mount,
60743 + .maxlen = sizeof(int),
60744 + .mode = 0600,
60745 + .proc_handler = &proc_dointvec,
60746 + },
60747 +#endif
60748 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60749 + {
60750 + .procname = "audit_textrel",
60751 + .data = &grsec_enable_audit_textrel,
60752 + .maxlen = sizeof(int),
60753 + .mode = 0600,
60754 + .proc_handler = &proc_dointvec,
60755 + },
60756 +#endif
60757 +#ifdef CONFIG_GRKERNSEC_DMESG
60758 + {
60759 + .procname = "dmesg",
60760 + .data = &grsec_enable_dmesg,
60761 + .maxlen = sizeof(int),
60762 + .mode = 0600,
60763 + .proc_handler = &proc_dointvec,
60764 + },
60765 +#endif
60766 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60767 + {
60768 + .procname = "chroot_findtask",
60769 + .data = &grsec_enable_chroot_findtask,
60770 + .maxlen = sizeof(int),
60771 + .mode = 0600,
60772 + .proc_handler = &proc_dointvec,
60773 + },
60774 +#endif
60775 +#ifdef CONFIG_GRKERNSEC_RESLOG
60776 + {
60777 + .procname = "resource_logging",
60778 + .data = &grsec_resource_logging,
60779 + .maxlen = sizeof(int),
60780 + .mode = 0600,
60781 + .proc_handler = &proc_dointvec,
60782 + },
60783 +#endif
60784 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60785 + {
60786 + .procname = "audit_ptrace",
60787 + .data = &grsec_enable_audit_ptrace,
60788 + .maxlen = sizeof(int),
60789 + .mode = 0600,
60790 + .proc_handler = &proc_dointvec,
60791 + },
60792 +#endif
60793 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60794 + {
60795 + .procname = "harden_ptrace",
60796 + .data = &grsec_enable_harden_ptrace,
60797 + .maxlen = sizeof(int),
60798 + .mode = 0600,
60799 + .proc_handler = &proc_dointvec,
60800 + },
60801 +#endif
60802 + {
60803 + .procname = "grsec_lock",
60804 + .data = &grsec_lock,
60805 + .maxlen = sizeof(int),
60806 + .mode = 0600,
60807 + .proc_handler = &proc_dointvec,
60808 + },
60809 +#endif
60810 +#ifdef CONFIG_GRKERNSEC_ROFS
60811 + {
60812 + .procname = "romount_protect",
60813 + .data = &grsec_enable_rofs,
60814 + .maxlen = sizeof(int),
60815 + .mode = 0600,
60816 + .proc_handler = &proc_dointvec_minmax,
60817 + .extra1 = &one,
60818 + .extra2 = &one,
60819 + },
60820 +#endif
60821 + { }
60822 +};
60823 +#endif
60824 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60825 new file mode 100644
60826 index 0000000..0dc13c3
60827 --- /dev/null
60828 +++ b/grsecurity/grsec_time.c
60829 @@ -0,0 +1,16 @@
60830 +#include <linux/kernel.h>
60831 +#include <linux/sched.h>
60832 +#include <linux/grinternal.h>
60833 +#include <linux/module.h>
60834 +
60835 +void
60836 +gr_log_timechange(void)
60837 +{
60838 +#ifdef CONFIG_GRKERNSEC_TIME
60839 + if (grsec_enable_time)
60840 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60841 +#endif
60842 + return;
60843 +}
60844 +
60845 +EXPORT_SYMBOL(gr_log_timechange);
60846 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60847 new file mode 100644
60848 index 0000000..07e0dc0
60849 --- /dev/null
60850 +++ b/grsecurity/grsec_tpe.c
60851 @@ -0,0 +1,73 @@
60852 +#include <linux/kernel.h>
60853 +#include <linux/sched.h>
60854 +#include <linux/file.h>
60855 +#include <linux/fs.h>
60856 +#include <linux/grinternal.h>
60857 +
60858 +extern int gr_acl_tpe_check(void);
60859 +
60860 +int
60861 +gr_tpe_allow(const struct file *file)
60862 +{
60863 +#ifdef CONFIG_GRKERNSEC
60864 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60865 + const struct cred *cred = current_cred();
60866 + char *msg = NULL;
60867 + char *msg2 = NULL;
60868 +
60869 + // never restrict root
60870 + if (!cred->uid)
60871 + return 1;
60872 +
60873 + if (grsec_enable_tpe) {
60874 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60875 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60876 + msg = "not being in trusted group";
60877 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60878 + msg = "being in untrusted group";
60879 +#else
60880 + if (in_group_p(grsec_tpe_gid))
60881 + msg = "being in untrusted group";
60882 +#endif
60883 + }
60884 + if (!msg && gr_acl_tpe_check())
60885 + msg = "being in untrusted role";
60886 +
60887 + // not in any affected group/role
60888 + if (!msg)
60889 + goto next_check;
60890 +
60891 + if (inode->i_uid)
60892 + msg2 = "file in non-root-owned directory";
60893 + else if (inode->i_mode & S_IWOTH)
60894 + msg2 = "file in world-writable directory";
60895 + else if (inode->i_mode & S_IWGRP)
60896 + msg2 = "file in group-writable directory";
60897 +
60898 + if (msg && msg2) {
60899 + char fullmsg[70] = {0};
60900 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60901 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60902 + return 0;
60903 + }
60904 + msg = NULL;
60905 +next_check:
60906 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60907 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60908 + return 1;
60909 +
60910 + if (inode->i_uid && (inode->i_uid != cred->uid))
60911 + msg = "directory not owned by user";
60912 + else if (inode->i_mode & S_IWOTH)
60913 + msg = "file in world-writable directory";
60914 + else if (inode->i_mode & S_IWGRP)
60915 + msg = "file in group-writable directory";
60916 +
60917 + if (msg) {
60918 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60919 + return 0;
60920 + }
60921 +#endif
60922 +#endif
60923 + return 1;
60924 +}
60925 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60926 new file mode 100644
60927 index 0000000..9f7b1ac
60928 --- /dev/null
60929 +++ b/grsecurity/grsum.c
60930 @@ -0,0 +1,61 @@
60931 +#include <linux/err.h>
60932 +#include <linux/kernel.h>
60933 +#include <linux/sched.h>
60934 +#include <linux/mm.h>
60935 +#include <linux/scatterlist.h>
60936 +#include <linux/crypto.h>
60937 +#include <linux/gracl.h>
60938 +
60939 +
60940 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60941 +#error "crypto and sha256 must be built into the kernel"
60942 +#endif
60943 +
60944 +int
60945 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60946 +{
60947 + char *p;
60948 + struct crypto_hash *tfm;
60949 + struct hash_desc desc;
60950 + struct scatterlist sg;
60951 + unsigned char temp_sum[GR_SHA_LEN];
60952 + volatile int retval = 0;
60953 + volatile int dummy = 0;
60954 + unsigned int i;
60955 +
60956 + sg_init_table(&sg, 1);
60957 +
60958 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60959 + if (IS_ERR(tfm)) {
60960 + /* should never happen, since sha256 should be built in */
60961 + return 1;
60962 + }
60963 +
60964 + desc.tfm = tfm;
60965 + desc.flags = 0;
60966 +
60967 + crypto_hash_init(&desc);
60968 +
60969 + p = salt;
60970 + sg_set_buf(&sg, p, GR_SALT_LEN);
60971 + crypto_hash_update(&desc, &sg, sg.length);
60972 +
60973 + p = entry->pw;
60974 + sg_set_buf(&sg, p, strlen(p));
60975 +
60976 + crypto_hash_update(&desc, &sg, sg.length);
60977 +
60978 + crypto_hash_final(&desc, temp_sum);
60979 +
60980 + memset(entry->pw, 0, GR_PW_LEN);
60981 +
60982 + for (i = 0; i < GR_SHA_LEN; i++)
60983 + if (sum[i] != temp_sum[i])
60984 + retval = 1;
60985 + else
60986 + dummy = 1; // waste a cycle
60987 +
60988 + crypto_free_hash(tfm);
60989 +
60990 + return retval;
60991 +}
60992 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60993 index bde976e..a1cc32a 100644
60994 --- a/include/acpi/acpi_bus.h
60995 +++ b/include/acpi/acpi_bus.h
60996 @@ -136,7 +136,7 @@ struct acpi_device_ops {
60997 acpi_op_bind bind;
60998 acpi_op_unbind unbind;
60999 acpi_op_notify notify;
61000 -};
61001 +} __no_const;
61002
61003 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
61004
61005 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
61006 index 77ff547..181834f 100644
61007 --- a/include/asm-generic/4level-fixup.h
61008 +++ b/include/asm-generic/4level-fixup.h
61009 @@ -13,8 +13,10 @@
61010 #define pmd_alloc(mm, pud, address) \
61011 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
61012 NULL: pmd_offset(pud, address))
61013 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
61014
61015 #define pud_alloc(mm, pgd, address) (pgd)
61016 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
61017 #define pud_offset(pgd, start) (pgd)
61018 #define pud_none(pud) 0
61019 #define pud_bad(pud) 0
61020 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
61021 index b7babf0..3ba8aee 100644
61022 --- a/include/asm-generic/atomic-long.h
61023 +++ b/include/asm-generic/atomic-long.h
61024 @@ -22,6 +22,12 @@
61025
61026 typedef atomic64_t atomic_long_t;
61027
61028 +#ifdef CONFIG_PAX_REFCOUNT
61029 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
61030 +#else
61031 +typedef atomic64_t atomic_long_unchecked_t;
61032 +#endif
61033 +
61034 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
61035
61036 static inline long atomic_long_read(atomic_long_t *l)
61037 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
61038 return (long)atomic64_read(v);
61039 }
61040
61041 +#ifdef CONFIG_PAX_REFCOUNT
61042 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61043 +{
61044 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61045 +
61046 + return (long)atomic64_read_unchecked(v);
61047 +}
61048 +#endif
61049 +
61050 static inline void atomic_long_set(atomic_long_t *l, long i)
61051 {
61052 atomic64_t *v = (atomic64_t *)l;
61053 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
61054 atomic64_set(v, i);
61055 }
61056
61057 +#ifdef CONFIG_PAX_REFCOUNT
61058 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61059 +{
61060 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61061 +
61062 + atomic64_set_unchecked(v, i);
61063 +}
61064 +#endif
61065 +
61066 static inline void atomic_long_inc(atomic_long_t *l)
61067 {
61068 atomic64_t *v = (atomic64_t *)l;
61069 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
61070 atomic64_inc(v);
61071 }
61072
61073 +#ifdef CONFIG_PAX_REFCOUNT
61074 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61075 +{
61076 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61077 +
61078 + atomic64_inc_unchecked(v);
61079 +}
61080 +#endif
61081 +
61082 static inline void atomic_long_dec(atomic_long_t *l)
61083 {
61084 atomic64_t *v = (atomic64_t *)l;
61085 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
61086 atomic64_dec(v);
61087 }
61088
61089 +#ifdef CONFIG_PAX_REFCOUNT
61090 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61091 +{
61092 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61093 +
61094 + atomic64_dec_unchecked(v);
61095 +}
61096 +#endif
61097 +
61098 static inline void atomic_long_add(long i, atomic_long_t *l)
61099 {
61100 atomic64_t *v = (atomic64_t *)l;
61101 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
61102 atomic64_add(i, v);
61103 }
61104
61105 +#ifdef CONFIG_PAX_REFCOUNT
61106 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61107 +{
61108 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61109 +
61110 + atomic64_add_unchecked(i, v);
61111 +}
61112 +#endif
61113 +
61114 static inline void atomic_long_sub(long i, atomic_long_t *l)
61115 {
61116 atomic64_t *v = (atomic64_t *)l;
61117 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
61118 atomic64_sub(i, v);
61119 }
61120
61121 +#ifdef CONFIG_PAX_REFCOUNT
61122 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61123 +{
61124 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61125 +
61126 + atomic64_sub_unchecked(i, v);
61127 +}
61128 +#endif
61129 +
61130 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61131 {
61132 atomic64_t *v = (atomic64_t *)l;
61133 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
61134 return (long)atomic64_inc_return(v);
61135 }
61136
61137 +#ifdef CONFIG_PAX_REFCOUNT
61138 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61139 +{
61140 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61141 +
61142 + return (long)atomic64_inc_return_unchecked(v);
61143 +}
61144 +#endif
61145 +
61146 static inline long atomic_long_dec_return(atomic_long_t *l)
61147 {
61148 atomic64_t *v = (atomic64_t *)l;
61149 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
61150
61151 typedef atomic_t atomic_long_t;
61152
61153 +#ifdef CONFIG_PAX_REFCOUNT
61154 +typedef atomic_unchecked_t atomic_long_unchecked_t;
61155 +#else
61156 +typedef atomic_t atomic_long_unchecked_t;
61157 +#endif
61158 +
61159 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
61160 static inline long atomic_long_read(atomic_long_t *l)
61161 {
61162 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
61163 return (long)atomic_read(v);
61164 }
61165
61166 +#ifdef CONFIG_PAX_REFCOUNT
61167 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61168 +{
61169 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61170 +
61171 + return (long)atomic_read_unchecked(v);
61172 +}
61173 +#endif
61174 +
61175 static inline void atomic_long_set(atomic_long_t *l, long i)
61176 {
61177 atomic_t *v = (atomic_t *)l;
61178 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
61179 atomic_set(v, i);
61180 }
61181
61182 +#ifdef CONFIG_PAX_REFCOUNT
61183 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61184 +{
61185 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61186 +
61187 + atomic_set_unchecked(v, i);
61188 +}
61189 +#endif
61190 +
61191 static inline void atomic_long_inc(atomic_long_t *l)
61192 {
61193 atomic_t *v = (atomic_t *)l;
61194 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
61195 atomic_inc(v);
61196 }
61197
61198 +#ifdef CONFIG_PAX_REFCOUNT
61199 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61200 +{
61201 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61202 +
61203 + atomic_inc_unchecked(v);
61204 +}
61205 +#endif
61206 +
61207 static inline void atomic_long_dec(atomic_long_t *l)
61208 {
61209 atomic_t *v = (atomic_t *)l;
61210 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
61211 atomic_dec(v);
61212 }
61213
61214 +#ifdef CONFIG_PAX_REFCOUNT
61215 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61216 +{
61217 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61218 +
61219 + atomic_dec_unchecked(v);
61220 +}
61221 +#endif
61222 +
61223 static inline void atomic_long_add(long i, atomic_long_t *l)
61224 {
61225 atomic_t *v = (atomic_t *)l;
61226 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
61227 atomic_add(i, v);
61228 }
61229
61230 +#ifdef CONFIG_PAX_REFCOUNT
61231 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61232 +{
61233 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61234 +
61235 + atomic_add_unchecked(i, v);
61236 +}
61237 +#endif
61238 +
61239 static inline void atomic_long_sub(long i, atomic_long_t *l)
61240 {
61241 atomic_t *v = (atomic_t *)l;
61242 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
61243 atomic_sub(i, v);
61244 }
61245
61246 +#ifdef CONFIG_PAX_REFCOUNT
61247 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61248 +{
61249 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61250 +
61251 + atomic_sub_unchecked(i, v);
61252 +}
61253 +#endif
61254 +
61255 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61256 {
61257 atomic_t *v = (atomic_t *)l;
61258 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
61259 return (long)atomic_inc_return(v);
61260 }
61261
61262 +#ifdef CONFIG_PAX_REFCOUNT
61263 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61264 +{
61265 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61266 +
61267 + return (long)atomic_inc_return_unchecked(v);
61268 +}
61269 +#endif
61270 +
61271 static inline long atomic_long_dec_return(atomic_long_t *l)
61272 {
61273 atomic_t *v = (atomic_t *)l;
61274 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
61275
61276 #endif /* BITS_PER_LONG == 64 */
61277
61278 +#ifdef CONFIG_PAX_REFCOUNT
61279 +static inline void pax_refcount_needs_these_functions(void)
61280 +{
61281 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
61282 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
61283 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
61284 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
61285 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
61286 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
61287 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
61288 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
61289 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
61290 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
61291 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
61292 +#ifdef CONFIG_X86
61293 + atomic_clear_mask_unchecked(0, NULL);
61294 + atomic_set_mask_unchecked(0, NULL);
61295 +#endif
61296 +
61297 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
61298 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
61299 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
61300 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
61301 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
61302 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
61303 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
61304 +}
61305 +#else
61306 +#define atomic_read_unchecked(v) atomic_read(v)
61307 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
61308 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
61309 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
61310 +#define atomic_inc_unchecked(v) atomic_inc(v)
61311 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
61312 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
61313 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
61314 +#define atomic_dec_unchecked(v) atomic_dec(v)
61315 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
61316 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
61317 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
61318 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
61319 +
61320 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
61321 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
61322 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
61323 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
61324 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
61325 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
61326 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
61327 +#endif
61328 +
61329 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
61330 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
61331 index 1ced641..c896ee8 100644
61332 --- a/include/asm-generic/atomic.h
61333 +++ b/include/asm-generic/atomic.h
61334 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
61335 * Atomically clears the bits set in @mask from @v
61336 */
61337 #ifndef atomic_clear_mask
61338 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
61339 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
61340 {
61341 unsigned long flags;
61342
61343 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
61344 index b18ce4f..2ee2843 100644
61345 --- a/include/asm-generic/atomic64.h
61346 +++ b/include/asm-generic/atomic64.h
61347 @@ -16,6 +16,8 @@ typedef struct {
61348 long long counter;
61349 } atomic64_t;
61350
61351 +typedef atomic64_t atomic64_unchecked_t;
61352 +
61353 #define ATOMIC64_INIT(i) { (i) }
61354
61355 extern long long atomic64_read(const atomic64_t *v);
61356 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
61357 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
61358 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
61359
61360 +#define atomic64_read_unchecked(v) atomic64_read(v)
61361 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
61362 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
61363 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
61364 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
61365 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
61366 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
61367 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
61368 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
61369 +
61370 #endif /* _ASM_GENERIC_ATOMIC64_H */
61371 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
61372 index 1bfcfe5..e04c5c9 100644
61373 --- a/include/asm-generic/cache.h
61374 +++ b/include/asm-generic/cache.h
61375 @@ -6,7 +6,7 @@
61376 * cache lines need to provide their own cache.h.
61377 */
61378
61379 -#define L1_CACHE_SHIFT 5
61380 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61381 +#define L1_CACHE_SHIFT 5UL
61382 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
61383
61384 #endif /* __ASM_GENERIC_CACHE_H */
61385 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
61386 index 0d68a1e..b74a761 100644
61387 --- a/include/asm-generic/emergency-restart.h
61388 +++ b/include/asm-generic/emergency-restart.h
61389 @@ -1,7 +1,7 @@
61390 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
61391 #define _ASM_GENERIC_EMERGENCY_RESTART_H
61392
61393 -static inline void machine_emergency_restart(void)
61394 +static inline __noreturn void machine_emergency_restart(void)
61395 {
61396 machine_restart(NULL);
61397 }
61398 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
61399 index 90f99c7..00ce236 100644
61400 --- a/include/asm-generic/kmap_types.h
61401 +++ b/include/asm-generic/kmap_types.h
61402 @@ -2,9 +2,9 @@
61403 #define _ASM_GENERIC_KMAP_TYPES_H
61404
61405 #ifdef __WITH_KM_FENCE
61406 -# define KM_TYPE_NR 41
61407 +# define KM_TYPE_NR 42
61408 #else
61409 -# define KM_TYPE_NR 20
61410 +# define KM_TYPE_NR 21
61411 #endif
61412
61413 #endif
61414 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
61415 index 9ceb03b..2efbcbd 100644
61416 --- a/include/asm-generic/local.h
61417 +++ b/include/asm-generic/local.h
61418 @@ -39,6 +39,7 @@ typedef struct
61419 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
61420 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
61421 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
61422 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
61423
61424 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
61425 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
61426 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
61427 index 725612b..9cc513a 100644
61428 --- a/include/asm-generic/pgtable-nopmd.h
61429 +++ b/include/asm-generic/pgtable-nopmd.h
61430 @@ -1,14 +1,19 @@
61431 #ifndef _PGTABLE_NOPMD_H
61432 #define _PGTABLE_NOPMD_H
61433
61434 -#ifndef __ASSEMBLY__
61435 -
61436 #include <asm-generic/pgtable-nopud.h>
61437
61438 -struct mm_struct;
61439 -
61440 #define __PAGETABLE_PMD_FOLDED
61441
61442 +#define PMD_SHIFT PUD_SHIFT
61443 +#define PTRS_PER_PMD 1
61444 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61445 +#define PMD_MASK (~(PMD_SIZE-1))
61446 +
61447 +#ifndef __ASSEMBLY__
61448 +
61449 +struct mm_struct;
61450 +
61451 /*
61452 * Having the pmd type consist of a pud gets the size right, and allows
61453 * us to conceptually access the pud entry that this pmd is folded into
61454 @@ -16,11 +21,6 @@ struct mm_struct;
61455 */
61456 typedef struct { pud_t pud; } pmd_t;
61457
61458 -#define PMD_SHIFT PUD_SHIFT
61459 -#define PTRS_PER_PMD 1
61460 -#define PMD_SIZE (1UL << PMD_SHIFT)
61461 -#define PMD_MASK (~(PMD_SIZE-1))
61462 -
61463 /*
61464 * The "pud_xxx()" functions here are trivial for a folded two-level
61465 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61466 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
61467 index 810431d..0ec4804f 100644
61468 --- a/include/asm-generic/pgtable-nopud.h
61469 +++ b/include/asm-generic/pgtable-nopud.h
61470 @@ -1,10 +1,15 @@
61471 #ifndef _PGTABLE_NOPUD_H
61472 #define _PGTABLE_NOPUD_H
61473
61474 -#ifndef __ASSEMBLY__
61475 -
61476 #define __PAGETABLE_PUD_FOLDED
61477
61478 +#define PUD_SHIFT PGDIR_SHIFT
61479 +#define PTRS_PER_PUD 1
61480 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61481 +#define PUD_MASK (~(PUD_SIZE-1))
61482 +
61483 +#ifndef __ASSEMBLY__
61484 +
61485 /*
61486 * Having the pud type consist of a pgd gets the size right, and allows
61487 * us to conceptually access the pgd entry that this pud is folded into
61488 @@ -12,11 +17,6 @@
61489 */
61490 typedef struct { pgd_t pgd; } pud_t;
61491
61492 -#define PUD_SHIFT PGDIR_SHIFT
61493 -#define PTRS_PER_PUD 1
61494 -#define PUD_SIZE (1UL << PUD_SHIFT)
61495 -#define PUD_MASK (~(PUD_SIZE-1))
61496 -
61497 /*
61498 * The "pgd_xxx()" functions here are trivial for a folded two-level
61499 * setup: the pud is never bad, and a pud always exists (as it's folded
61500 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61501 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61502
61503 #define pgd_populate(mm, pgd, pud) do { } while (0)
61504 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61505 /*
61506 * (puds are folded into pgds so this doesn't get actually called,
61507 * but the define is needed for a generic inline function.)
61508 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61509 index ff4947b..f48183f 100644
61510 --- a/include/asm-generic/pgtable.h
61511 +++ b/include/asm-generic/pgtable.h
61512 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61513 #endif
61514 }
61515
61516 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61517 +static inline unsigned long pax_open_kernel(void) { return 0; }
61518 +#endif
61519 +
61520 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61521 +static inline unsigned long pax_close_kernel(void) { return 0; }
61522 +#endif
61523 +
61524 #endif /* CONFIG_MMU */
61525
61526 #endif /* !__ASSEMBLY__ */
61527 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61528 index 4e2e1cc..12c266b 100644
61529 --- a/include/asm-generic/vmlinux.lds.h
61530 +++ b/include/asm-generic/vmlinux.lds.h
61531 @@ -218,6 +218,7 @@
61532 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61533 VMLINUX_SYMBOL(__start_rodata) = .; \
61534 *(.rodata) *(.rodata.*) \
61535 + *(.data..read_only) \
61536 *(__vermagic) /* Kernel version magic */ \
61537 . = ALIGN(8); \
61538 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61539 @@ -716,17 +717,18 @@
61540 * section in the linker script will go there too. @phdr should have
61541 * a leading colon.
61542 *
61543 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61544 + * Note that this macros defines per_cpu_load as an absolute symbol.
61545 * If there is no need to put the percpu section at a predetermined
61546 * address, use PERCPU_SECTION.
61547 */
61548 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61549 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61550 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61551 + per_cpu_load = .; \
61552 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61553 - LOAD_OFFSET) { \
61554 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61555 PERCPU_INPUT(cacheline) \
61556 } phdr \
61557 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61558 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61559
61560 /**
61561 * PERCPU_SECTION - define output section for percpu area, simple version
61562 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61563 index d6b67bb..a272c29 100644
61564 --- a/include/drm/drmP.h
61565 +++ b/include/drm/drmP.h
61566 @@ -72,6 +72,7 @@
61567 #include <linux/workqueue.h>
61568 #include <linux/poll.h>
61569 #include <asm/pgalloc.h>
61570 +#include <asm/local.h>
61571 #include "drm.h"
61572
61573 #include <linux/idr.h>
61574 @@ -1067,7 +1068,7 @@ struct drm_device {
61575
61576 /** \name Usage Counters */
61577 /*@{ */
61578 - int open_count; /**< Outstanding files open */
61579 + local_t open_count; /**< Outstanding files open */
61580 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61581 atomic_t vma_count; /**< Outstanding vma areas open */
61582 int buf_use; /**< Buffers in use -- cannot alloc */
61583 @@ -1078,7 +1079,7 @@ struct drm_device {
61584 /*@{ */
61585 unsigned long counters;
61586 enum drm_stat_type types[15];
61587 - atomic_t counts[15];
61588 + atomic_unchecked_t counts[15];
61589 /*@} */
61590
61591 struct list_head filelist;
61592 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61593 index e01cc80..319855d 100644
61594 --- a/include/drm/drm_crtc_helper.h
61595 +++ b/include/drm/drm_crtc_helper.h
61596 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61597
61598 /* disable crtc when not in use - more explicit than dpms off */
61599 void (*disable)(struct drm_crtc *crtc);
61600 -};
61601 +} __no_const;
61602
61603 /**
61604 * drm_encoder_helper_funcs - helper operations for encoders
61605 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61606 struct drm_connector *connector);
61607 /* disable encoder when not in use - more explicit than dpms off */
61608 void (*disable)(struct drm_encoder *encoder);
61609 -};
61610 +} __no_const;
61611
61612 /**
61613 * drm_connector_helper_funcs - helper operations for connectors
61614 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61615 index d6d1da4..fdd1ac5 100644
61616 --- a/include/drm/ttm/ttm_memory.h
61617 +++ b/include/drm/ttm/ttm_memory.h
61618 @@ -48,7 +48,7 @@
61619
61620 struct ttm_mem_shrink {
61621 int (*do_shrink) (struct ttm_mem_shrink *);
61622 -};
61623 +} __no_const;
61624
61625 /**
61626 * struct ttm_mem_global - Global memory accounting structure.
61627 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61628 index e86dfca..40cc55f 100644
61629 --- a/include/linux/a.out.h
61630 +++ b/include/linux/a.out.h
61631 @@ -39,6 +39,14 @@ enum machine_type {
61632 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61633 };
61634
61635 +/* Constants for the N_FLAGS field */
61636 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61637 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61638 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61639 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61640 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61641 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61642 +
61643 #if !defined (N_MAGIC)
61644 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61645 #endif
61646 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61647 index 06fd4bb..1caec0d 100644
61648 --- a/include/linux/atmdev.h
61649 +++ b/include/linux/atmdev.h
61650 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61651 #endif
61652
61653 struct k_atm_aal_stats {
61654 -#define __HANDLE_ITEM(i) atomic_t i
61655 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61656 __AAL_STAT_ITEMS
61657 #undef __HANDLE_ITEM
61658 };
61659 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61660 index 366422b..1fa7f84 100644
61661 --- a/include/linux/binfmts.h
61662 +++ b/include/linux/binfmts.h
61663 @@ -89,6 +89,7 @@ struct linux_binfmt {
61664 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61665 int (*load_shlib)(struct file *);
61666 int (*core_dump)(struct coredump_params *cprm);
61667 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61668 unsigned long min_coredump; /* minimal dump size */
61669 };
61670
61671 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61672 index 4a2ab7c..a2de7a8 100644
61673 --- a/include/linux/blkdev.h
61674 +++ b/include/linux/blkdev.h
61675 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61676 /* this callback is with swap_lock and sometimes page table lock held */
61677 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61678 struct module *owner;
61679 -};
61680 +} __do_const;
61681
61682 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61683 unsigned long);
61684 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61685 index 4d1a074..88f929a 100644
61686 --- a/include/linux/blktrace_api.h
61687 +++ b/include/linux/blktrace_api.h
61688 @@ -162,7 +162,7 @@ struct blk_trace {
61689 struct dentry *dir;
61690 struct dentry *dropped_file;
61691 struct dentry *msg_file;
61692 - atomic_t dropped;
61693 + atomic_unchecked_t dropped;
61694 };
61695
61696 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61697 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61698 index 83195fb..0b0f77d 100644
61699 --- a/include/linux/byteorder/little_endian.h
61700 +++ b/include/linux/byteorder/little_endian.h
61701 @@ -42,51 +42,51 @@
61702
61703 static inline __le64 __cpu_to_le64p(const __u64 *p)
61704 {
61705 - return (__force __le64)*p;
61706 + return (__force const __le64)*p;
61707 }
61708 static inline __u64 __le64_to_cpup(const __le64 *p)
61709 {
61710 - return (__force __u64)*p;
61711 + return (__force const __u64)*p;
61712 }
61713 static inline __le32 __cpu_to_le32p(const __u32 *p)
61714 {
61715 - return (__force __le32)*p;
61716 + return (__force const __le32)*p;
61717 }
61718 static inline __u32 __le32_to_cpup(const __le32 *p)
61719 {
61720 - return (__force __u32)*p;
61721 + return (__force const __u32)*p;
61722 }
61723 static inline __le16 __cpu_to_le16p(const __u16 *p)
61724 {
61725 - return (__force __le16)*p;
61726 + return (__force const __le16)*p;
61727 }
61728 static inline __u16 __le16_to_cpup(const __le16 *p)
61729 {
61730 - return (__force __u16)*p;
61731 + return (__force const __u16)*p;
61732 }
61733 static inline __be64 __cpu_to_be64p(const __u64 *p)
61734 {
61735 - return (__force __be64)__swab64p(p);
61736 + return (__force const __be64)__swab64p(p);
61737 }
61738 static inline __u64 __be64_to_cpup(const __be64 *p)
61739 {
61740 - return __swab64p((__u64 *)p);
61741 + return __swab64p((const __u64 *)p);
61742 }
61743 static inline __be32 __cpu_to_be32p(const __u32 *p)
61744 {
61745 - return (__force __be32)__swab32p(p);
61746 + return (__force const __be32)__swab32p(p);
61747 }
61748 static inline __u32 __be32_to_cpup(const __be32 *p)
61749 {
61750 - return __swab32p((__u32 *)p);
61751 + return __swab32p((const __u32 *)p);
61752 }
61753 static inline __be16 __cpu_to_be16p(const __u16 *p)
61754 {
61755 - return (__force __be16)__swab16p(p);
61756 + return (__force const __be16)__swab16p(p);
61757 }
61758 static inline __u16 __be16_to_cpup(const __be16 *p)
61759 {
61760 - return __swab16p((__u16 *)p);
61761 + return __swab16p((const __u16 *)p);
61762 }
61763 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61764 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61765 diff --git a/include/linux/cache.h b/include/linux/cache.h
61766 index 4c57065..4307975 100644
61767 --- a/include/linux/cache.h
61768 +++ b/include/linux/cache.h
61769 @@ -16,6 +16,10 @@
61770 #define __read_mostly
61771 #endif
61772
61773 +#ifndef __read_only
61774 +#define __read_only __read_mostly
61775 +#endif
61776 +
61777 #ifndef ____cacheline_aligned
61778 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61779 #endif
61780 diff --git a/include/linux/capability.h b/include/linux/capability.h
61781 index d10b7ed..0288b79 100644
61782 --- a/include/linux/capability.h
61783 +++ b/include/linux/capability.h
61784 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61785 extern bool ns_capable(struct user_namespace *ns, int cap);
61786 extern bool nsown_capable(int cap);
61787 extern bool inode_capable(const struct inode *inode, int cap);
61788 +extern bool capable_nolog(int cap);
61789 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61790 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61791
61792 /* audit system wants to get cap info from files as well */
61793 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61794
61795 +extern int is_privileged_binary(const struct dentry *dentry);
61796 +
61797 #endif /* __KERNEL__ */
61798
61799 #endif /* !_LINUX_CAPABILITY_H */
61800 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61801 index 42e55de..1cd0e66 100644
61802 --- a/include/linux/cleancache.h
61803 +++ b/include/linux/cleancache.h
61804 @@ -31,7 +31,7 @@ struct cleancache_ops {
61805 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61806 void (*invalidate_inode)(int, struct cleancache_filekey);
61807 void (*invalidate_fs)(int);
61808 -};
61809 +} __no_const;
61810
61811 extern struct cleancache_ops
61812 cleancache_register_ops(struct cleancache_ops *ops);
61813 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61814 index 77335fa..6cbe7dd 100644
61815 --- a/include/linux/clk-provider.h
61816 +++ b/include/linux/clk-provider.h
61817 @@ -111,6 +111,7 @@ struct clk_ops {
61818 unsigned long);
61819 void (*init)(struct clk_hw *hw);
61820 };
61821 +typedef struct clk_ops __no_const clk_ops_no_const;
61822
61823 /**
61824 * struct clk_init_data - holds init data that's common to all clocks and is
61825 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61826 index 934bc34..1b47129 100644
61827 --- a/include/linux/compiler-gcc4.h
61828 +++ b/include/linux/compiler-gcc4.h
61829 @@ -32,6 +32,21 @@
61830 #define __linktime_error(message) __attribute__((__error__(message)))
61831
61832 #if __GNUC_MINOR__ >= 5
61833 +
61834 +#ifdef CONSTIFY_PLUGIN
61835 +#define __no_const __attribute__((no_const))
61836 +#define __do_const __attribute__((do_const))
61837 +#endif
61838 +
61839 +#ifdef SIZE_OVERFLOW_PLUGIN
61840 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61841 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61842 +#endif
61843 +
61844 +#ifdef LATENT_ENTROPY_PLUGIN
61845 +#define __latent_entropy __attribute__((latent_entropy))
61846 +#endif
61847 +
61848 /*
61849 * Mark a position in code as unreachable. This can be used to
61850 * suppress control flow warnings after asm blocks that transfer
61851 @@ -47,6 +62,11 @@
61852 #define __noclone __attribute__((__noclone__))
61853
61854 #endif
61855 +
61856 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61857 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61858 +#define __bos0(ptr) __bos((ptr), 0)
61859 +#define __bos1(ptr) __bos((ptr), 1)
61860 #endif
61861
61862 #if __GNUC_MINOR__ >= 6
61863 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61864 index f430e41..38be90f 100644
61865 --- a/include/linux/compiler.h
61866 +++ b/include/linux/compiler.h
61867 @@ -5,31 +5,62 @@
61868
61869 #ifdef __CHECKER__
61870 # define __user __attribute__((noderef, address_space(1)))
61871 +# define __force_user __force __user
61872 # define __kernel __attribute__((address_space(0)))
61873 +# define __force_kernel __force __kernel
61874 # define __safe __attribute__((safe))
61875 # define __force __attribute__((force))
61876 # define __nocast __attribute__((nocast))
61877 # define __iomem __attribute__((noderef, address_space(2)))
61878 +# define __force_iomem __force __iomem
61879 # define __acquires(x) __attribute__((context(x,0,1)))
61880 # define __releases(x) __attribute__((context(x,1,0)))
61881 # define __acquire(x) __context__(x,1)
61882 # define __release(x) __context__(x,-1)
61883 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61884 # define __percpu __attribute__((noderef, address_space(3)))
61885 +# define __force_percpu __force __percpu
61886 #ifdef CONFIG_SPARSE_RCU_POINTER
61887 # define __rcu __attribute__((noderef, address_space(4)))
61888 +# define __force_rcu __force __rcu
61889 #else
61890 # define __rcu
61891 +# define __force_rcu
61892 #endif
61893 extern void __chk_user_ptr(const volatile void __user *);
61894 extern void __chk_io_ptr(const volatile void __iomem *);
61895 +#elif defined(CHECKER_PLUGIN)
61896 +//# define __user
61897 +//# define __force_user
61898 +//# define __kernel
61899 +//# define __force_kernel
61900 +# define __safe
61901 +# define __force
61902 +# define __nocast
61903 +# define __iomem
61904 +# define __force_iomem
61905 +# define __chk_user_ptr(x) (void)0
61906 +# define __chk_io_ptr(x) (void)0
61907 +# define __builtin_warning(x, y...) (1)
61908 +# define __acquires(x)
61909 +# define __releases(x)
61910 +# define __acquire(x) (void)0
61911 +# define __release(x) (void)0
61912 +# define __cond_lock(x,c) (c)
61913 +# define __percpu
61914 +# define __force_percpu
61915 +# define __rcu
61916 +# define __force_rcu
61917 #else
61918 # define __user
61919 +# define __force_user
61920 # define __kernel
61921 +# define __force_kernel
61922 # define __safe
61923 # define __force
61924 # define __nocast
61925 # define __iomem
61926 +# define __force_iomem
61927 # define __chk_user_ptr(x) (void)0
61928 # define __chk_io_ptr(x) (void)0
61929 # define __builtin_warning(x, y...) (1)
61930 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61931 # define __release(x) (void)0
61932 # define __cond_lock(x,c) (c)
61933 # define __percpu
61934 +# define __force_percpu
61935 # define __rcu
61936 +# define __force_rcu
61937 #endif
61938
61939 #ifdef __KERNEL__
61940 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61941 # define __attribute_const__ /* unimplemented */
61942 #endif
61943
61944 +#ifndef __no_const
61945 +# define __no_const
61946 +#endif
61947 +
61948 +#ifndef __do_const
61949 +# define __do_const
61950 +#endif
61951 +
61952 +#ifndef __size_overflow
61953 +# define __size_overflow(...)
61954 +#endif
61955 +
61956 +#ifndef __intentional_overflow
61957 +# define __intentional_overflow(...)
61958 +#endif
61959 +
61960 +#ifndef __latent_entropy
61961 +# define __latent_entropy
61962 +#endif
61963 +
61964 /*
61965 * Tell gcc if a function is cold. The compiler will assume any path
61966 * directly leading to the call is unlikely.
61967 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61968 #define __cold
61969 #endif
61970
61971 +#ifndef __alloc_size
61972 +#define __alloc_size(...)
61973 +#endif
61974 +
61975 +#ifndef __bos
61976 +#define __bos(ptr, arg)
61977 +#endif
61978 +
61979 +#ifndef __bos0
61980 +#define __bos0(ptr)
61981 +#endif
61982 +
61983 +#ifndef __bos1
61984 +#define __bos1(ptr)
61985 +#endif
61986 +
61987 /* Simple shorthand for a section definition */
61988 #ifndef __section
61989 # define __section(S) __attribute__ ((__section__(#S)))
61990 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61991 * use is to mediate communication between process-level code and irq/NMI
61992 * handlers, all running on the same CPU.
61993 */
61994 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61995 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61996 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61997
61998 #endif /* __LINUX_COMPILER_H */
61999 diff --git a/include/linux/cred.h b/include/linux/cred.h
62000 index ebbed2c..908cc2c 100644
62001 --- a/include/linux/cred.h
62002 +++ b/include/linux/cred.h
62003 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
62004 static inline void validate_process_creds(void)
62005 {
62006 }
62007 +static inline void validate_task_creds(struct task_struct *task)
62008 +{
62009 +}
62010 #endif
62011
62012 /**
62013 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
62014 index b92eadf..b4ecdc1 100644
62015 --- a/include/linux/crypto.h
62016 +++ b/include/linux/crypto.h
62017 @@ -373,7 +373,7 @@ struct cipher_tfm {
62018 const u8 *key, unsigned int keylen);
62019 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
62020 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
62021 -};
62022 +} __no_const;
62023
62024 struct hash_tfm {
62025 int (*init)(struct hash_desc *desc);
62026 @@ -394,13 +394,13 @@ struct compress_tfm {
62027 int (*cot_decompress)(struct crypto_tfm *tfm,
62028 const u8 *src, unsigned int slen,
62029 u8 *dst, unsigned int *dlen);
62030 -};
62031 +} __no_const;
62032
62033 struct rng_tfm {
62034 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
62035 unsigned int dlen);
62036 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
62037 -};
62038 +} __no_const;
62039
62040 #define crt_ablkcipher crt_u.ablkcipher
62041 #define crt_aead crt_u.aead
62042 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
62043 index 7925bf0..d5143d2 100644
62044 --- a/include/linux/decompress/mm.h
62045 +++ b/include/linux/decompress/mm.h
62046 @@ -77,7 +77,7 @@ static void free(void *where)
62047 * warnings when not needed (indeed large_malloc / large_free are not
62048 * needed by inflate */
62049
62050 -#define malloc(a) kmalloc(a, GFP_KERNEL)
62051 +#define malloc(a) kmalloc((a), GFP_KERNEL)
62052 #define free(a) kfree(a)
62053
62054 #define large_malloc(a) vmalloc(a)
62055 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
62056 index 94af418..b1ca7a2 100644
62057 --- a/include/linux/dma-mapping.h
62058 +++ b/include/linux/dma-mapping.h
62059 @@ -54,7 +54,7 @@ struct dma_map_ops {
62060 u64 (*get_required_mask)(struct device *dev);
62061 #endif
62062 int is_phys;
62063 -};
62064 +} __do_const;
62065
62066 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
62067
62068 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
62069 index 9c02a45..89fdd73 100644
62070 --- a/include/linux/dmaengine.h
62071 +++ b/include/linux/dmaengine.h
62072 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
62073 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
62074 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
62075
62076 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
62077 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
62078 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
62079 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
62080 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
62081 struct dma_pinned_list *pinned_list, struct page *page,
62082 unsigned int offset, size_t len);
62083
62084 diff --git a/include/linux/efi.h b/include/linux/efi.h
62085 index 5782114..e9b1ba1 100644
62086 --- a/include/linux/efi.h
62087 +++ b/include/linux/efi.h
62088 @@ -640,7 +640,7 @@ struct efivar_operations {
62089 efi_get_variable_t *get_variable;
62090 efi_get_next_variable_t *get_next_variable;
62091 efi_set_variable_t *set_variable;
62092 -};
62093 +} __no_const;
62094
62095 struct efivars {
62096 /*
62097 diff --git a/include/linux/elf.h b/include/linux/elf.h
62098 index 999b4f5..57753b4 100644
62099 --- a/include/linux/elf.h
62100 +++ b/include/linux/elf.h
62101 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
62102 #define PT_GNU_EH_FRAME 0x6474e550
62103
62104 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
62105 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
62106 +
62107 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
62108 +
62109 +/* Constants for the e_flags field */
62110 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
62111 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
62112 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
62113 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
62114 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
62115 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
62116
62117 /*
62118 * Extended Numbering
62119 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
62120 #define DT_DEBUG 21
62121 #define DT_TEXTREL 22
62122 #define DT_JMPREL 23
62123 +#define DT_FLAGS 30
62124 + #define DF_TEXTREL 0x00000004
62125 #define DT_ENCODING 32
62126 #define OLD_DT_LOOS 0x60000000
62127 #define DT_LOOS 0x6000000d
62128 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
62129 #define PF_W 0x2
62130 #define PF_X 0x1
62131
62132 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
62133 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
62134 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
62135 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
62136 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
62137 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
62138 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
62139 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
62140 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
62141 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
62142 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
62143 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
62144 +
62145 typedef struct elf32_phdr{
62146 Elf32_Word p_type;
62147 Elf32_Off p_offset;
62148 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
62149 #define EI_OSABI 7
62150 #define EI_PAD 8
62151
62152 +#define EI_PAX 14
62153 +
62154 #define ELFMAG0 0x7f /* EI_MAG */
62155 #define ELFMAG1 'E'
62156 #define ELFMAG2 'L'
62157 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
62158 #define elf_note elf32_note
62159 #define elf_addr_t Elf32_Off
62160 #define Elf_Half Elf32_Half
62161 +#define elf_dyn Elf32_Dyn
62162
62163 #else
62164
62165 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
62166 #define elf_note elf64_note
62167 #define elf_addr_t Elf64_Off
62168 #define Elf_Half Elf64_Half
62169 +#define elf_dyn Elf64_Dyn
62170
62171 #endif
62172
62173 diff --git a/include/linux/filter.h b/include/linux/filter.h
62174 index 82b0135..917914d 100644
62175 --- a/include/linux/filter.h
62176 +++ b/include/linux/filter.h
62177 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
62178
62179 struct sk_buff;
62180 struct sock;
62181 +struct bpf_jit_work;
62182
62183 struct sk_filter
62184 {
62185 @@ -153,6 +154,9 @@ struct sk_filter
62186 unsigned int len; /* Number of filter blocks */
62187 unsigned int (*bpf_func)(const struct sk_buff *skb,
62188 const struct sock_filter *filter);
62189 +#ifdef CONFIG_BPF_JIT
62190 + struct bpf_jit_work *work;
62191 +#endif
62192 struct rcu_head rcu;
62193 struct sock_filter insns[0];
62194 };
62195 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
62196 index db04ec5..f6ed627 100644
62197 --- a/include/linux/firewire.h
62198 +++ b/include/linux/firewire.h
62199 @@ -430,7 +430,7 @@ struct fw_iso_context {
62200 union {
62201 fw_iso_callback_t sc;
62202 fw_iso_mc_callback_t mc;
62203 - } callback;
62204 + } __no_const callback;
62205 void *callback_data;
62206 };
62207
62208 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
62209 index 0e4e2ee..4ff4312 100644
62210 --- a/include/linux/frontswap.h
62211 +++ b/include/linux/frontswap.h
62212 @@ -11,7 +11,7 @@ struct frontswap_ops {
62213 int (*load)(unsigned, pgoff_t, struct page *);
62214 void (*invalidate_page)(unsigned, pgoff_t);
62215 void (*invalidate_area)(unsigned);
62216 -};
62217 +} __no_const;
62218
62219 extern bool frontswap_enabled;
62220 extern struct frontswap_ops
62221 diff --git a/include/linux/fs.h b/include/linux/fs.h
62222 index aa11047..7d046d0 100644
62223 --- a/include/linux/fs.h
62224 +++ b/include/linux/fs.h
62225 @@ -1802,7 +1802,8 @@ struct file_operations {
62226 int (*setlease)(struct file *, long, struct file_lock **);
62227 long (*fallocate)(struct file *file, int mode, loff_t offset,
62228 loff_t len);
62229 -};
62230 +} __do_const;
62231 +typedef struct file_operations __no_const file_operations_no_const;
62232
62233 struct inode_operations {
62234 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
62235 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
62236 index 003dc0f..3c4ea97 100644
62237 --- a/include/linux/fs_struct.h
62238 +++ b/include/linux/fs_struct.h
62239 @@ -6,7 +6,7 @@
62240 #include <linux/seqlock.h>
62241
62242 struct fs_struct {
62243 - int users;
62244 + atomic_t users;
62245 spinlock_t lock;
62246 seqcount_t seq;
62247 int umask;
62248 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
62249 index ce31408..b1ad003 100644
62250 --- a/include/linux/fscache-cache.h
62251 +++ b/include/linux/fscache-cache.h
62252 @@ -102,7 +102,7 @@ struct fscache_operation {
62253 fscache_operation_release_t release;
62254 };
62255
62256 -extern atomic_t fscache_op_debug_id;
62257 +extern atomic_unchecked_t fscache_op_debug_id;
62258 extern void fscache_op_work_func(struct work_struct *work);
62259
62260 extern void fscache_enqueue_operation(struct fscache_operation *);
62261 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
62262 {
62263 INIT_WORK(&op->work, fscache_op_work_func);
62264 atomic_set(&op->usage, 1);
62265 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62266 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62267 op->processor = processor;
62268 op->release = release;
62269 INIT_LIST_HEAD(&op->pend_link);
62270 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
62271 index a6dfe69..569586df 100644
62272 --- a/include/linux/fsnotify.h
62273 +++ b/include/linux/fsnotify.h
62274 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
62275 */
62276 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
62277 {
62278 - return kstrdup(name, GFP_KERNEL);
62279 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
62280 }
62281
62282 /*
62283 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
62284 index 63d966d..cdcb717 100644
62285 --- a/include/linux/fsnotify_backend.h
62286 +++ b/include/linux/fsnotify_backend.h
62287 @@ -105,6 +105,7 @@ struct fsnotify_ops {
62288 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
62289 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
62290 };
62291 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
62292
62293 /*
62294 * A group is a "thing" that wants to receive notification about filesystem
62295 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
62296 index 642928c..e6c83a7 100644
62297 --- a/include/linux/ftrace_event.h
62298 +++ b/include/linux/ftrace_event.h
62299 @@ -97,7 +97,7 @@ struct trace_event_functions {
62300 trace_print_func raw;
62301 trace_print_func hex;
62302 trace_print_func binary;
62303 -};
62304 +} __no_const;
62305
62306 struct trace_event {
62307 struct hlist_node node;
62308 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
62309 extern int trace_add_event_call(struct ftrace_event_call *call);
62310 extern void trace_remove_event_call(struct ftrace_event_call *call);
62311
62312 -#define is_signed_type(type) (((type)(-1)) < 0)
62313 +#define is_signed_type(type) (((type)(-1)) < (type)1)
62314
62315 int trace_set_clr_event(const char *system, const char *event, int set);
62316
62317 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
62318 index 4f440b3..342233a 100644
62319 --- a/include/linux/genhd.h
62320 +++ b/include/linux/genhd.h
62321 @@ -190,7 +190,7 @@ struct gendisk {
62322 struct kobject *slave_dir;
62323
62324 struct timer_rand_state *random;
62325 - atomic_t sync_io; /* RAID */
62326 + atomic_unchecked_t sync_io; /* RAID */
62327 struct disk_events *ev;
62328 #ifdef CONFIG_BLK_DEV_INTEGRITY
62329 struct blk_integrity *integrity;
62330 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
62331 index 4883f39..26688a8 100644
62332 --- a/include/linux/gfp.h
62333 +++ b/include/linux/gfp.h
62334 @@ -39,6 +39,12 @@ struct vm_area_struct;
62335 #define ___GFP_OTHER_NODE 0x800000u
62336 #define ___GFP_WRITE 0x1000000u
62337
62338 +#ifdef CONFIG_PAX_USERCOPY_SLABS
62339 +#define ___GFP_USERCOPY 0x2000000u
62340 +#else
62341 +#define ___GFP_USERCOPY 0
62342 +#endif
62343 +
62344 /*
62345 * GFP bitmasks..
62346 *
62347 @@ -93,6 +99,7 @@ struct vm_area_struct;
62348 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
62349 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
62350 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
62351 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
62352
62353 /*
62354 * This may seem redundant, but it's a way of annotating false positives vs.
62355 @@ -100,7 +107,7 @@ struct vm_area_struct;
62356 */
62357 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
62358
62359 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
62360 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
62361 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
62362
62363 /* This equals 0, but use constants in case they ever change */
62364 @@ -154,6 +161,8 @@ struct vm_area_struct;
62365 /* 4GB DMA on some platforms */
62366 #define GFP_DMA32 __GFP_DMA32
62367
62368 +#define GFP_USERCOPY __GFP_USERCOPY
62369 +
62370 /* Convert GFP flags to their corresponding migrate type */
62371 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
62372 {
62373 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
62374 new file mode 100644
62375 index 0000000..c938b1f
62376 --- /dev/null
62377 +++ b/include/linux/gracl.h
62378 @@ -0,0 +1,319 @@
62379 +#ifndef GR_ACL_H
62380 +#define GR_ACL_H
62381 +
62382 +#include <linux/grdefs.h>
62383 +#include <linux/resource.h>
62384 +#include <linux/capability.h>
62385 +#include <linux/dcache.h>
62386 +#include <asm/resource.h>
62387 +
62388 +/* Major status information */
62389 +
62390 +#define GR_VERSION "grsecurity 2.9.1"
62391 +#define GRSECURITY_VERSION 0x2901
62392 +
62393 +enum {
62394 + GR_SHUTDOWN = 0,
62395 + GR_ENABLE = 1,
62396 + GR_SPROLE = 2,
62397 + GR_RELOAD = 3,
62398 + GR_SEGVMOD = 4,
62399 + GR_STATUS = 5,
62400 + GR_UNSPROLE = 6,
62401 + GR_PASSSET = 7,
62402 + GR_SPROLEPAM = 8,
62403 +};
62404 +
62405 +/* Password setup definitions
62406 + * kernel/grhash.c */
62407 +enum {
62408 + GR_PW_LEN = 128,
62409 + GR_SALT_LEN = 16,
62410 + GR_SHA_LEN = 32,
62411 +};
62412 +
62413 +enum {
62414 + GR_SPROLE_LEN = 64,
62415 +};
62416 +
62417 +enum {
62418 + GR_NO_GLOB = 0,
62419 + GR_REG_GLOB,
62420 + GR_CREATE_GLOB
62421 +};
62422 +
62423 +#define GR_NLIMITS 32
62424 +
62425 +/* Begin Data Structures */
62426 +
62427 +struct sprole_pw {
62428 + unsigned char *rolename;
62429 + unsigned char salt[GR_SALT_LEN];
62430 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62431 +};
62432 +
62433 +struct name_entry {
62434 + __u32 key;
62435 + ino_t inode;
62436 + dev_t device;
62437 + char *name;
62438 + __u16 len;
62439 + __u8 deleted;
62440 + struct name_entry *prev;
62441 + struct name_entry *next;
62442 +};
62443 +
62444 +struct inodev_entry {
62445 + struct name_entry *nentry;
62446 + struct inodev_entry *prev;
62447 + struct inodev_entry *next;
62448 +};
62449 +
62450 +struct acl_role_db {
62451 + struct acl_role_label **r_hash;
62452 + __u32 r_size;
62453 +};
62454 +
62455 +struct inodev_db {
62456 + struct inodev_entry **i_hash;
62457 + __u32 i_size;
62458 +};
62459 +
62460 +struct name_db {
62461 + struct name_entry **n_hash;
62462 + __u32 n_size;
62463 +};
62464 +
62465 +struct crash_uid {
62466 + uid_t uid;
62467 + unsigned long expires;
62468 +};
62469 +
62470 +struct gr_hash_struct {
62471 + void **table;
62472 + void **nametable;
62473 + void *first;
62474 + __u32 table_size;
62475 + __u32 used_size;
62476 + int type;
62477 +};
62478 +
62479 +/* Userspace Grsecurity ACL data structures */
62480 +
62481 +struct acl_subject_label {
62482 + char *filename;
62483 + ino_t inode;
62484 + dev_t device;
62485 + __u32 mode;
62486 + kernel_cap_t cap_mask;
62487 + kernel_cap_t cap_lower;
62488 + kernel_cap_t cap_invert_audit;
62489 +
62490 + struct rlimit res[GR_NLIMITS];
62491 + __u32 resmask;
62492 +
62493 + __u8 user_trans_type;
62494 + __u8 group_trans_type;
62495 + uid_t *user_transitions;
62496 + gid_t *group_transitions;
62497 + __u16 user_trans_num;
62498 + __u16 group_trans_num;
62499 +
62500 + __u32 sock_families[2];
62501 + __u32 ip_proto[8];
62502 + __u32 ip_type;
62503 + struct acl_ip_label **ips;
62504 + __u32 ip_num;
62505 + __u32 inaddr_any_override;
62506 +
62507 + __u32 crashes;
62508 + unsigned long expires;
62509 +
62510 + struct acl_subject_label *parent_subject;
62511 + struct gr_hash_struct *hash;
62512 + struct acl_subject_label *prev;
62513 + struct acl_subject_label *next;
62514 +
62515 + struct acl_object_label **obj_hash;
62516 + __u32 obj_hash_size;
62517 + __u16 pax_flags;
62518 +};
62519 +
62520 +struct role_allowed_ip {
62521 + __u32 addr;
62522 + __u32 netmask;
62523 +
62524 + struct role_allowed_ip *prev;
62525 + struct role_allowed_ip *next;
62526 +};
62527 +
62528 +struct role_transition {
62529 + char *rolename;
62530 +
62531 + struct role_transition *prev;
62532 + struct role_transition *next;
62533 +};
62534 +
62535 +struct acl_role_label {
62536 + char *rolename;
62537 + uid_t uidgid;
62538 + __u16 roletype;
62539 +
62540 + __u16 auth_attempts;
62541 + unsigned long expires;
62542 +
62543 + struct acl_subject_label *root_label;
62544 + struct gr_hash_struct *hash;
62545 +
62546 + struct acl_role_label *prev;
62547 + struct acl_role_label *next;
62548 +
62549 + struct role_transition *transitions;
62550 + struct role_allowed_ip *allowed_ips;
62551 + uid_t *domain_children;
62552 + __u16 domain_child_num;
62553 +
62554 + umode_t umask;
62555 +
62556 + struct acl_subject_label **subj_hash;
62557 + __u32 subj_hash_size;
62558 +};
62559 +
62560 +struct user_acl_role_db {
62561 + struct acl_role_label **r_table;
62562 + __u32 num_pointers; /* Number of allocations to track */
62563 + __u32 num_roles; /* Number of roles */
62564 + __u32 num_domain_children; /* Number of domain children */
62565 + __u32 num_subjects; /* Number of subjects */
62566 + __u32 num_objects; /* Number of objects */
62567 +};
62568 +
62569 +struct acl_object_label {
62570 + char *filename;
62571 + ino_t inode;
62572 + dev_t device;
62573 + __u32 mode;
62574 +
62575 + struct acl_subject_label *nested;
62576 + struct acl_object_label *globbed;
62577 +
62578 + /* next two structures not used */
62579 +
62580 + struct acl_object_label *prev;
62581 + struct acl_object_label *next;
62582 +};
62583 +
62584 +struct acl_ip_label {
62585 + char *iface;
62586 + __u32 addr;
62587 + __u32 netmask;
62588 + __u16 low, high;
62589 + __u8 mode;
62590 + __u32 type;
62591 + __u32 proto[8];
62592 +
62593 + /* next two structures not used */
62594 +
62595 + struct acl_ip_label *prev;
62596 + struct acl_ip_label *next;
62597 +};
62598 +
62599 +struct gr_arg {
62600 + struct user_acl_role_db role_db;
62601 + unsigned char pw[GR_PW_LEN];
62602 + unsigned char salt[GR_SALT_LEN];
62603 + unsigned char sum[GR_SHA_LEN];
62604 + unsigned char sp_role[GR_SPROLE_LEN];
62605 + struct sprole_pw *sprole_pws;
62606 + dev_t segv_device;
62607 + ino_t segv_inode;
62608 + uid_t segv_uid;
62609 + __u16 num_sprole_pws;
62610 + __u16 mode;
62611 +};
62612 +
62613 +struct gr_arg_wrapper {
62614 + struct gr_arg *arg;
62615 + __u32 version;
62616 + __u32 size;
62617 +};
62618 +
62619 +struct subject_map {
62620 + struct acl_subject_label *user;
62621 + struct acl_subject_label *kernel;
62622 + struct subject_map *prev;
62623 + struct subject_map *next;
62624 +};
62625 +
62626 +struct acl_subj_map_db {
62627 + struct subject_map **s_hash;
62628 + __u32 s_size;
62629 +};
62630 +
62631 +/* End Data Structures Section */
62632 +
62633 +/* Hash functions generated by empirical testing by Brad Spengler
62634 + Makes good use of the low bits of the inode. Generally 0-1 times
62635 + in loop for successful match. 0-3 for unsuccessful match.
62636 + Shift/add algorithm with modulus of table size and an XOR*/
62637 +
62638 +static __inline__ unsigned int
62639 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62640 +{
62641 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62642 +}
62643 +
62644 + static __inline__ unsigned int
62645 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62646 +{
62647 + return ((const unsigned long)userp % sz);
62648 +}
62649 +
62650 +static __inline__ unsigned int
62651 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62652 +{
62653 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62654 +}
62655 +
62656 +static __inline__ unsigned int
62657 +nhash(const char *name, const __u16 len, const unsigned int sz)
62658 +{
62659 + return full_name_hash((const unsigned char *)name, len) % sz;
62660 +}
62661 +
62662 +#define FOR_EACH_ROLE_START(role) \
62663 + role = role_list; \
62664 + while (role) {
62665 +
62666 +#define FOR_EACH_ROLE_END(role) \
62667 + role = role->prev; \
62668 + }
62669 +
62670 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62671 + subj = NULL; \
62672 + iter = 0; \
62673 + while (iter < role->subj_hash_size) { \
62674 + if (subj == NULL) \
62675 + subj = role->subj_hash[iter]; \
62676 + if (subj == NULL) { \
62677 + iter++; \
62678 + continue; \
62679 + }
62680 +
62681 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62682 + subj = subj->next; \
62683 + if (subj == NULL) \
62684 + iter++; \
62685 + }
62686 +
62687 +
62688 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62689 + subj = role->hash->first; \
62690 + while (subj != NULL) {
62691 +
62692 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62693 + subj = subj->next; \
62694 + }
62695 +
62696 +#endif
62697 +
62698 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62699 new file mode 100644
62700 index 0000000..323ecf2
62701 --- /dev/null
62702 +++ b/include/linux/gralloc.h
62703 @@ -0,0 +1,9 @@
62704 +#ifndef __GRALLOC_H
62705 +#define __GRALLOC_H
62706 +
62707 +void acl_free_all(void);
62708 +int acl_alloc_stack_init(unsigned long size);
62709 +void *acl_alloc(unsigned long len);
62710 +void *acl_alloc_num(unsigned long num, unsigned long len);
62711 +
62712 +#endif
62713 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62714 new file mode 100644
62715 index 0000000..b30e9bc
62716 --- /dev/null
62717 +++ b/include/linux/grdefs.h
62718 @@ -0,0 +1,140 @@
62719 +#ifndef GRDEFS_H
62720 +#define GRDEFS_H
62721 +
62722 +/* Begin grsecurity status declarations */
62723 +
62724 +enum {
62725 + GR_READY = 0x01,
62726 + GR_STATUS_INIT = 0x00 // disabled state
62727 +};
62728 +
62729 +/* Begin ACL declarations */
62730 +
62731 +/* Role flags */
62732 +
62733 +enum {
62734 + GR_ROLE_USER = 0x0001,
62735 + GR_ROLE_GROUP = 0x0002,
62736 + GR_ROLE_DEFAULT = 0x0004,
62737 + GR_ROLE_SPECIAL = 0x0008,
62738 + GR_ROLE_AUTH = 0x0010,
62739 + GR_ROLE_NOPW = 0x0020,
62740 + GR_ROLE_GOD = 0x0040,
62741 + GR_ROLE_LEARN = 0x0080,
62742 + GR_ROLE_TPE = 0x0100,
62743 + GR_ROLE_DOMAIN = 0x0200,
62744 + GR_ROLE_PAM = 0x0400,
62745 + GR_ROLE_PERSIST = 0x0800
62746 +};
62747 +
62748 +/* ACL Subject and Object mode flags */
62749 +enum {
62750 + GR_DELETED = 0x80000000
62751 +};
62752 +
62753 +/* ACL Object-only mode flags */
62754 +enum {
62755 + GR_READ = 0x00000001,
62756 + GR_APPEND = 0x00000002,
62757 + GR_WRITE = 0x00000004,
62758 + GR_EXEC = 0x00000008,
62759 + GR_FIND = 0x00000010,
62760 + GR_INHERIT = 0x00000020,
62761 + GR_SETID = 0x00000040,
62762 + GR_CREATE = 0x00000080,
62763 + GR_DELETE = 0x00000100,
62764 + GR_LINK = 0x00000200,
62765 + GR_AUDIT_READ = 0x00000400,
62766 + GR_AUDIT_APPEND = 0x00000800,
62767 + GR_AUDIT_WRITE = 0x00001000,
62768 + GR_AUDIT_EXEC = 0x00002000,
62769 + GR_AUDIT_FIND = 0x00004000,
62770 + GR_AUDIT_INHERIT= 0x00008000,
62771 + GR_AUDIT_SETID = 0x00010000,
62772 + GR_AUDIT_CREATE = 0x00020000,
62773 + GR_AUDIT_DELETE = 0x00040000,
62774 + GR_AUDIT_LINK = 0x00080000,
62775 + GR_PTRACERD = 0x00100000,
62776 + GR_NOPTRACE = 0x00200000,
62777 + GR_SUPPRESS = 0x00400000,
62778 + GR_NOLEARN = 0x00800000,
62779 + GR_INIT_TRANSFER= 0x01000000
62780 +};
62781 +
62782 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62783 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62784 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62785 +
62786 +/* ACL subject-only mode flags */
62787 +enum {
62788 + GR_KILL = 0x00000001,
62789 + GR_VIEW = 0x00000002,
62790 + GR_PROTECTED = 0x00000004,
62791 + GR_LEARN = 0x00000008,
62792 + GR_OVERRIDE = 0x00000010,
62793 + /* just a placeholder, this mode is only used in userspace */
62794 + GR_DUMMY = 0x00000020,
62795 + GR_PROTSHM = 0x00000040,
62796 + GR_KILLPROC = 0x00000080,
62797 + GR_KILLIPPROC = 0x00000100,
62798 + /* just a placeholder, this mode is only used in userspace */
62799 + GR_NOTROJAN = 0x00000200,
62800 + GR_PROTPROCFD = 0x00000400,
62801 + GR_PROCACCT = 0x00000800,
62802 + GR_RELAXPTRACE = 0x00001000,
62803 + GR_NESTED = 0x00002000,
62804 + GR_INHERITLEARN = 0x00004000,
62805 + GR_PROCFIND = 0x00008000,
62806 + GR_POVERRIDE = 0x00010000,
62807 + GR_KERNELAUTH = 0x00020000,
62808 + GR_ATSECURE = 0x00040000,
62809 + GR_SHMEXEC = 0x00080000
62810 +};
62811 +
62812 +enum {
62813 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62814 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62815 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62816 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62817 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62818 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62819 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62820 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62821 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62822 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62823 +};
62824 +
62825 +enum {
62826 + GR_ID_USER = 0x01,
62827 + GR_ID_GROUP = 0x02,
62828 +};
62829 +
62830 +enum {
62831 + GR_ID_ALLOW = 0x01,
62832 + GR_ID_DENY = 0x02,
62833 +};
62834 +
62835 +#define GR_CRASH_RES 31
62836 +#define GR_UIDTABLE_MAX 500
62837 +
62838 +/* begin resource learning section */
62839 +enum {
62840 + GR_RLIM_CPU_BUMP = 60,
62841 + GR_RLIM_FSIZE_BUMP = 50000,
62842 + GR_RLIM_DATA_BUMP = 10000,
62843 + GR_RLIM_STACK_BUMP = 1000,
62844 + GR_RLIM_CORE_BUMP = 10000,
62845 + GR_RLIM_RSS_BUMP = 500000,
62846 + GR_RLIM_NPROC_BUMP = 1,
62847 + GR_RLIM_NOFILE_BUMP = 5,
62848 + GR_RLIM_MEMLOCK_BUMP = 50000,
62849 + GR_RLIM_AS_BUMP = 500000,
62850 + GR_RLIM_LOCKS_BUMP = 2,
62851 + GR_RLIM_SIGPENDING_BUMP = 5,
62852 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62853 + GR_RLIM_NICE_BUMP = 1,
62854 + GR_RLIM_RTPRIO_BUMP = 1,
62855 + GR_RLIM_RTTIME_BUMP = 1000000
62856 +};
62857 +
62858 +#endif
62859 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62860 new file mode 100644
62861 index 0000000..c9292f7
62862 --- /dev/null
62863 +++ b/include/linux/grinternal.h
62864 @@ -0,0 +1,223 @@
62865 +#ifndef __GRINTERNAL_H
62866 +#define __GRINTERNAL_H
62867 +
62868 +#ifdef CONFIG_GRKERNSEC
62869 +
62870 +#include <linux/fs.h>
62871 +#include <linux/mnt_namespace.h>
62872 +#include <linux/nsproxy.h>
62873 +#include <linux/gracl.h>
62874 +#include <linux/grdefs.h>
62875 +#include <linux/grmsg.h>
62876 +
62877 +void gr_add_learn_entry(const char *fmt, ...)
62878 + __attribute__ ((format (printf, 1, 2)));
62879 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62880 + const struct vfsmount *mnt);
62881 +__u32 gr_check_create(const struct dentry *new_dentry,
62882 + const struct dentry *parent,
62883 + const struct vfsmount *mnt, const __u32 mode);
62884 +int gr_check_protected_task(const struct task_struct *task);
62885 +__u32 to_gr_audit(const __u32 reqmode);
62886 +int gr_set_acls(const int type);
62887 +int gr_apply_subject_to_task(struct task_struct *task);
62888 +int gr_acl_is_enabled(void);
62889 +char gr_roletype_to_char(void);
62890 +
62891 +void gr_handle_alertkill(struct task_struct *task);
62892 +char *gr_to_filename(const struct dentry *dentry,
62893 + const struct vfsmount *mnt);
62894 +char *gr_to_filename1(const struct dentry *dentry,
62895 + const struct vfsmount *mnt);
62896 +char *gr_to_filename2(const struct dentry *dentry,
62897 + const struct vfsmount *mnt);
62898 +char *gr_to_filename3(const struct dentry *dentry,
62899 + const struct vfsmount *mnt);
62900 +
62901 +extern int grsec_enable_ptrace_readexec;
62902 +extern int grsec_enable_harden_ptrace;
62903 +extern int grsec_enable_link;
62904 +extern int grsec_enable_fifo;
62905 +extern int grsec_enable_execve;
62906 +extern int grsec_enable_shm;
62907 +extern int grsec_enable_execlog;
62908 +extern int grsec_enable_signal;
62909 +extern int grsec_enable_audit_ptrace;
62910 +extern int grsec_enable_forkfail;
62911 +extern int grsec_enable_time;
62912 +extern int grsec_enable_rofs;
62913 +extern int grsec_enable_chroot_shmat;
62914 +extern int grsec_enable_chroot_mount;
62915 +extern int grsec_enable_chroot_double;
62916 +extern int grsec_enable_chroot_pivot;
62917 +extern int grsec_enable_chroot_chdir;
62918 +extern int grsec_enable_chroot_chmod;
62919 +extern int grsec_enable_chroot_mknod;
62920 +extern int grsec_enable_chroot_fchdir;
62921 +extern int grsec_enable_chroot_nice;
62922 +extern int grsec_enable_chroot_execlog;
62923 +extern int grsec_enable_chroot_caps;
62924 +extern int grsec_enable_chroot_sysctl;
62925 +extern int grsec_enable_chroot_unix;
62926 +extern int grsec_enable_symlinkown;
62927 +extern int grsec_symlinkown_gid;
62928 +extern int grsec_enable_tpe;
62929 +extern int grsec_tpe_gid;
62930 +extern int grsec_enable_tpe_all;
62931 +extern int grsec_enable_tpe_invert;
62932 +extern int grsec_enable_socket_all;
62933 +extern int grsec_socket_all_gid;
62934 +extern int grsec_enable_socket_client;
62935 +extern int grsec_socket_client_gid;
62936 +extern int grsec_enable_socket_server;
62937 +extern int grsec_socket_server_gid;
62938 +extern int grsec_audit_gid;
62939 +extern int grsec_enable_group;
62940 +extern int grsec_enable_audit_textrel;
62941 +extern int grsec_enable_log_rwxmaps;
62942 +extern int grsec_enable_mount;
62943 +extern int grsec_enable_chdir;
62944 +extern int grsec_resource_logging;
62945 +extern int grsec_enable_blackhole;
62946 +extern int grsec_lastack_retries;
62947 +extern int grsec_enable_brute;
62948 +extern int grsec_lock;
62949 +
62950 +extern spinlock_t grsec_alert_lock;
62951 +extern unsigned long grsec_alert_wtime;
62952 +extern unsigned long grsec_alert_fyet;
62953 +
62954 +extern spinlock_t grsec_audit_lock;
62955 +
62956 +extern rwlock_t grsec_exec_file_lock;
62957 +
62958 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62959 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62960 + (tsk)->exec_file->f_vfsmnt) : "/")
62961 +
62962 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62963 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62964 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62965 +
62966 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62967 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62968 + (tsk)->exec_file->f_vfsmnt) : "/")
62969 +
62970 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62971 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62972 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62973 +
62974 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62975 +
62976 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62977 +
62978 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62979 + (task)->pid, (cred)->uid, \
62980 + (cred)->euid, (cred)->gid, (cred)->egid, \
62981 + gr_parent_task_fullpath(task), \
62982 + (task)->real_parent->comm, (task)->real_parent->pid, \
62983 + (pcred)->uid, (pcred)->euid, \
62984 + (pcred)->gid, (pcred)->egid
62985 +
62986 +#define GR_CHROOT_CAPS {{ \
62987 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62988 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62989 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62990 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62991 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62992 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62993 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62994 +
62995 +#define security_learn(normal_msg,args...) \
62996 +({ \
62997 + read_lock(&grsec_exec_file_lock); \
62998 + gr_add_learn_entry(normal_msg "\n", ## args); \
62999 + read_unlock(&grsec_exec_file_lock); \
63000 +})
63001 +
63002 +enum {
63003 + GR_DO_AUDIT,
63004 + GR_DONT_AUDIT,
63005 + /* used for non-audit messages that we shouldn't kill the task on */
63006 + GR_DONT_AUDIT_GOOD
63007 +};
63008 +
63009 +enum {
63010 + GR_TTYSNIFF,
63011 + GR_RBAC,
63012 + GR_RBAC_STR,
63013 + GR_STR_RBAC,
63014 + GR_RBAC_MODE2,
63015 + GR_RBAC_MODE3,
63016 + GR_FILENAME,
63017 + GR_SYSCTL_HIDDEN,
63018 + GR_NOARGS,
63019 + GR_ONE_INT,
63020 + GR_ONE_INT_TWO_STR,
63021 + GR_ONE_STR,
63022 + GR_STR_INT,
63023 + GR_TWO_STR_INT,
63024 + GR_TWO_INT,
63025 + GR_TWO_U64,
63026 + GR_THREE_INT,
63027 + GR_FIVE_INT_TWO_STR,
63028 + GR_TWO_STR,
63029 + GR_THREE_STR,
63030 + GR_FOUR_STR,
63031 + GR_STR_FILENAME,
63032 + GR_FILENAME_STR,
63033 + GR_FILENAME_TWO_INT,
63034 + GR_FILENAME_TWO_INT_STR,
63035 + GR_TEXTREL,
63036 + GR_PTRACE,
63037 + GR_RESOURCE,
63038 + GR_CAP,
63039 + GR_SIG,
63040 + GR_SIG2,
63041 + GR_CRASH1,
63042 + GR_CRASH2,
63043 + GR_PSACCT,
63044 + GR_RWXMAP
63045 +};
63046 +
63047 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
63048 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
63049 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
63050 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
63051 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
63052 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
63053 +#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)
63054 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
63055 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
63056 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
63057 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
63058 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
63059 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
63060 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
63061 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
63062 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
63063 +#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)
63064 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
63065 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
63066 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
63067 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
63068 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
63069 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
63070 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
63071 +#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)
63072 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
63073 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
63074 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
63075 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
63076 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
63077 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
63078 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
63079 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
63080 +#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)
63081 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
63082 +
63083 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
63084 +
63085 +#endif
63086 +
63087 +#endif
63088 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
63089 new file mode 100644
63090 index 0000000..2bd4c8d
63091 --- /dev/null
63092 +++ b/include/linux/grmsg.h
63093 @@ -0,0 +1,111 @@
63094 +#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"
63095 +#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"
63096 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
63097 +#define GR_STOPMOD_MSG "denied modification of module state by "
63098 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
63099 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
63100 +#define GR_IOPERM_MSG "denied use of ioperm() by "
63101 +#define GR_IOPL_MSG "denied use of iopl() by "
63102 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
63103 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
63104 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
63105 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
63106 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
63107 +#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"
63108 +#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"
63109 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
63110 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
63111 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
63112 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
63113 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
63114 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
63115 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
63116 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
63117 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
63118 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
63119 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
63120 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
63121 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
63122 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
63123 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
63124 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
63125 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
63126 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
63127 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
63128 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
63129 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
63130 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
63131 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
63132 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
63133 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
63134 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
63135 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
63136 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
63137 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
63138 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
63139 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
63140 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
63141 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
63142 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
63143 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
63144 +#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"
63145 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
63146 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
63147 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
63148 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
63149 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
63150 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
63151 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
63152 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
63153 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
63154 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
63155 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
63156 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
63157 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
63158 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
63159 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
63160 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
63161 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
63162 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
63163 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
63164 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
63165 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
63166 +#define GR_NICE_CHROOT_MSG "denied priority change by "
63167 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
63168 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
63169 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
63170 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
63171 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
63172 +#define GR_TIME_MSG "time set by "
63173 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
63174 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
63175 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
63176 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
63177 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
63178 +#define GR_BIND_MSG "denied bind() by "
63179 +#define GR_CONNECT_MSG "denied connect() by "
63180 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
63181 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
63182 +#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"
63183 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
63184 +#define GR_CAP_ACL_MSG "use of %s denied for "
63185 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
63186 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
63187 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
63188 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
63189 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
63190 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
63191 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
63192 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
63193 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
63194 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
63195 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
63196 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
63197 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
63198 +#define GR_VM86_MSG "denied use of vm86 by "
63199 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
63200 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
63201 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
63202 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
63203 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
63204 +#define GR_BRUTE_DAEMON_MSG "bruteforce prevention initiated for the next 30 minutes or until service restarted, stalling each fork 30 seconds. Please investigate the crash report for "
63205 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
63206 new file mode 100644
63207 index 0000000..28d8b19
63208 --- /dev/null
63209 +++ b/include/linux/grsecurity.h
63210 @@ -0,0 +1,239 @@
63211 +#ifndef GR_SECURITY_H
63212 +#define GR_SECURITY_H
63213 +#include <linux/fs.h>
63214 +#include <linux/fs_struct.h>
63215 +#include <linux/binfmts.h>
63216 +#include <linux/gracl.h>
63217 +
63218 +/* notify of brain-dead configs */
63219 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63220 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
63221 +#endif
63222 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
63223 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
63224 +#endif
63225 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
63226 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
63227 +#endif
63228 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
63229 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
63230 +#endif
63231 +
63232 +#include <linux/compat.h>
63233 +
63234 +struct user_arg_ptr {
63235 +#ifdef CONFIG_COMPAT
63236 + bool is_compat;
63237 +#endif
63238 + union {
63239 + const char __user *const __user *native;
63240 +#ifdef CONFIG_COMPAT
63241 + compat_uptr_t __user *compat;
63242 +#endif
63243 + } ptr;
63244 +};
63245 +
63246 +void gr_handle_brute_attach(unsigned long mm_flags);
63247 +void gr_handle_brute_check(void);
63248 +void gr_handle_kernel_exploit(void);
63249 +int gr_process_user_ban(void);
63250 +
63251 +char gr_roletype_to_char(void);
63252 +
63253 +int gr_acl_enable_at_secure(void);
63254 +
63255 +int gr_check_user_change(int real, int effective, int fs);
63256 +int gr_check_group_change(int real, int effective, int fs);
63257 +
63258 +void gr_del_task_from_ip_table(struct task_struct *p);
63259 +
63260 +int gr_pid_is_chrooted(struct task_struct *p);
63261 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
63262 +int gr_handle_chroot_nice(void);
63263 +int gr_handle_chroot_sysctl(const int op);
63264 +int gr_handle_chroot_setpriority(struct task_struct *p,
63265 + const int niceval);
63266 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
63267 +int gr_handle_chroot_chroot(const struct dentry *dentry,
63268 + const struct vfsmount *mnt);
63269 +void gr_handle_chroot_chdir(struct path *path);
63270 +int gr_handle_chroot_chmod(const struct dentry *dentry,
63271 + const struct vfsmount *mnt, const int mode);
63272 +int gr_handle_chroot_mknod(const struct dentry *dentry,
63273 + const struct vfsmount *mnt, const int mode);
63274 +int gr_handle_chroot_mount(const struct dentry *dentry,
63275 + const struct vfsmount *mnt,
63276 + const char *dev_name);
63277 +int gr_handle_chroot_pivot(void);
63278 +int gr_handle_chroot_unix(const pid_t pid);
63279 +
63280 +int gr_handle_rawio(const struct inode *inode);
63281 +
63282 +void gr_handle_ioperm(void);
63283 +void gr_handle_iopl(void);
63284 +
63285 +umode_t gr_acl_umask(void);
63286 +
63287 +int gr_tpe_allow(const struct file *file);
63288 +
63289 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
63290 +void gr_clear_chroot_entries(struct task_struct *task);
63291 +
63292 +void gr_log_forkfail(const int retval);
63293 +void gr_log_timechange(void);
63294 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
63295 +void gr_log_chdir(const struct dentry *dentry,
63296 + const struct vfsmount *mnt);
63297 +void gr_log_chroot_exec(const struct dentry *dentry,
63298 + const struct vfsmount *mnt);
63299 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
63300 +void gr_log_remount(const char *devname, const int retval);
63301 +void gr_log_unmount(const char *devname, const int retval);
63302 +void gr_log_mount(const char *from, const char *to, const int retval);
63303 +void gr_log_textrel(struct vm_area_struct *vma);
63304 +void gr_log_rwxmmap(struct file *file);
63305 +void gr_log_rwxmprotect(struct file *file);
63306 +
63307 +int gr_handle_follow_link(const struct inode *parent,
63308 + const struct inode *inode,
63309 + const struct dentry *dentry,
63310 + const struct vfsmount *mnt);
63311 +int gr_handle_fifo(const struct dentry *dentry,
63312 + const struct vfsmount *mnt,
63313 + const struct dentry *dir, const int flag,
63314 + const int acc_mode);
63315 +int gr_handle_hardlink(const struct dentry *dentry,
63316 + const struct vfsmount *mnt,
63317 + struct inode *inode,
63318 + const int mode, const char *to);
63319 +
63320 +int gr_is_capable(const int cap);
63321 +int gr_is_capable_nolog(const int cap);
63322 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63323 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
63324 +
63325 +void gr_learn_resource(const struct task_struct *task, const int limit,
63326 + const unsigned long wanted, const int gt);
63327 +void gr_copy_label(struct task_struct *tsk);
63328 +void gr_handle_crash(struct task_struct *task, const int sig);
63329 +int gr_handle_signal(const struct task_struct *p, const int sig);
63330 +int gr_check_crash_uid(const uid_t uid);
63331 +int gr_check_protected_task(const struct task_struct *task);
63332 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63333 +int gr_acl_handle_mmap(const struct file *file,
63334 + const unsigned long prot);
63335 +int gr_acl_handle_mprotect(const struct file *file,
63336 + const unsigned long prot);
63337 +int gr_check_hidden_task(const struct task_struct *tsk);
63338 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63339 + const struct vfsmount *mnt);
63340 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
63341 + const struct vfsmount *mnt);
63342 +__u32 gr_acl_handle_access(const struct dentry *dentry,
63343 + const struct vfsmount *mnt, const int fmode);
63344 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63345 + const struct vfsmount *mnt, umode_t *mode);
63346 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
63347 + const struct vfsmount *mnt);
63348 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63349 + const struct vfsmount *mnt);
63350 +int gr_handle_ptrace(struct task_struct *task, const long request);
63351 +int gr_handle_proc_ptrace(struct task_struct *task);
63352 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
63353 + const struct vfsmount *mnt);
63354 +int gr_check_crash_exec(const struct file *filp);
63355 +int gr_acl_is_enabled(void);
63356 +void gr_set_kernel_label(struct task_struct *task);
63357 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
63358 + const gid_t gid);
63359 +int gr_set_proc_label(const struct dentry *dentry,
63360 + const struct vfsmount *mnt,
63361 + const int unsafe_flags);
63362 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63363 + const struct vfsmount *mnt);
63364 +__u32 gr_acl_handle_open(const struct dentry *dentry,
63365 + const struct vfsmount *mnt, int acc_mode);
63366 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
63367 + const struct dentry *p_dentry,
63368 + const struct vfsmount *p_mnt,
63369 + int open_flags, int acc_mode, const int imode);
63370 +void gr_handle_create(const struct dentry *dentry,
63371 + const struct vfsmount *mnt);
63372 +void gr_handle_proc_create(const struct dentry *dentry,
63373 + const struct inode *inode);
63374 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63375 + const struct dentry *parent_dentry,
63376 + const struct vfsmount *parent_mnt,
63377 + const int mode);
63378 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63379 + const struct dentry *parent_dentry,
63380 + const struct vfsmount *parent_mnt);
63381 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63382 + const struct vfsmount *mnt);
63383 +void gr_handle_delete(const ino_t ino, const dev_t dev);
63384 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63385 + const struct vfsmount *mnt);
63386 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63387 + const struct dentry *parent_dentry,
63388 + const struct vfsmount *parent_mnt,
63389 + const char *from);
63390 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63391 + const struct dentry *parent_dentry,
63392 + const struct vfsmount *parent_mnt,
63393 + const struct dentry *old_dentry,
63394 + const struct vfsmount *old_mnt, const char *to);
63395 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
63396 +int gr_acl_handle_rename(struct dentry *new_dentry,
63397 + struct dentry *parent_dentry,
63398 + const struct vfsmount *parent_mnt,
63399 + struct dentry *old_dentry,
63400 + struct inode *old_parent_inode,
63401 + struct vfsmount *old_mnt, const char *newname);
63402 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63403 + struct dentry *old_dentry,
63404 + struct dentry *new_dentry,
63405 + struct vfsmount *mnt, const __u8 replace);
63406 +__u32 gr_check_link(const struct dentry *new_dentry,
63407 + const struct dentry *parent_dentry,
63408 + const struct vfsmount *parent_mnt,
63409 + const struct dentry *old_dentry,
63410 + const struct vfsmount *old_mnt);
63411 +int gr_acl_handle_filldir(const struct file *file, const char *name,
63412 + const unsigned int namelen, const ino_t ino);
63413 +
63414 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
63415 + const struct vfsmount *mnt);
63416 +void gr_acl_handle_exit(void);
63417 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
63418 +int gr_acl_handle_procpidmem(const struct task_struct *task);
63419 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63420 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63421 +void gr_audit_ptrace(struct task_struct *task);
63422 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63423 +void gr_put_exec_file(struct task_struct *task);
63424 +
63425 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
63426 +
63427 +#ifdef CONFIG_GRKERNSEC
63428 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63429 +void gr_handle_vm86(void);
63430 +void gr_handle_mem_readwrite(u64 from, u64 to);
63431 +
63432 +void gr_log_badprocpid(const char *entry);
63433 +
63434 +extern int grsec_enable_dmesg;
63435 +extern int grsec_disable_privio;
63436 +
63437 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63438 +extern int grsec_proc_gid;
63439 +#endif
63440 +
63441 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63442 +extern int grsec_enable_chroot_findtask;
63443 +#endif
63444 +#ifdef CONFIG_GRKERNSEC_SETXID
63445 +extern int grsec_enable_setxid;
63446 +#endif
63447 +#endif
63448 +
63449 +#endif
63450 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
63451 new file mode 100644
63452 index 0000000..e7ffaaf
63453 --- /dev/null
63454 +++ b/include/linux/grsock.h
63455 @@ -0,0 +1,19 @@
63456 +#ifndef __GRSOCK_H
63457 +#define __GRSOCK_H
63458 +
63459 +extern void gr_attach_curr_ip(const struct sock *sk);
63460 +extern int gr_handle_sock_all(const int family, const int type,
63461 + const int protocol);
63462 +extern int gr_handle_sock_server(const struct sockaddr *sck);
63463 +extern int gr_handle_sock_server_other(const struct sock *sck);
63464 +extern int gr_handle_sock_client(const struct sockaddr *sck);
63465 +extern int gr_search_connect(struct socket * sock,
63466 + struct sockaddr_in * addr);
63467 +extern int gr_search_bind(struct socket * sock,
63468 + struct sockaddr_in * addr);
63469 +extern int gr_search_listen(struct socket * sock);
63470 +extern int gr_search_accept(struct socket * sock);
63471 +extern int gr_search_socket(const int domain, const int type,
63472 + const int protocol);
63473 +
63474 +#endif
63475 diff --git a/include/linux/hid.h b/include/linux/hid.h
63476 index 42970de..5db3c92 100644
63477 --- a/include/linux/hid.h
63478 +++ b/include/linux/hid.h
63479 @@ -705,7 +705,7 @@ struct hid_ll_driver {
63480 unsigned int code, int value);
63481
63482 int (*parse)(struct hid_device *hdev);
63483 -};
63484 +} __no_const;
63485
63486 #define PM_HINT_FULLON 1<<5
63487 #define PM_HINT_NORMAL 1<<1
63488 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
63489 index ef788b5..ac41b7b 100644
63490 --- a/include/linux/highmem.h
63491 +++ b/include/linux/highmem.h
63492 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
63493 kunmap_atomic(kaddr);
63494 }
63495
63496 +static inline void sanitize_highpage(struct page *page)
63497 +{
63498 + void *kaddr;
63499 + unsigned long flags;
63500 +
63501 + local_irq_save(flags);
63502 + kaddr = kmap_atomic(page);
63503 + clear_page(kaddr);
63504 + kunmap_atomic(kaddr);
63505 + local_irq_restore(flags);
63506 +}
63507 +
63508 static inline void zero_user_segments(struct page *page,
63509 unsigned start1, unsigned end1,
63510 unsigned start2, unsigned end2)
63511 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
63512 index 5970266..1c48c3b 100644
63513 --- a/include/linux/i2c.h
63514 +++ b/include/linux/i2c.h
63515 @@ -369,6 +369,7 @@ struct i2c_algorithm {
63516 /* To determine what the adapter supports */
63517 u32 (*functionality) (struct i2c_adapter *);
63518 };
63519 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63520
63521 /*
63522 * i2c_adapter is the structure used to identify a physical i2c bus along
63523 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63524 index d23c3c2..eb63c81 100644
63525 --- a/include/linux/i2o.h
63526 +++ b/include/linux/i2o.h
63527 @@ -565,7 +565,7 @@ struct i2o_controller {
63528 struct i2o_device *exec; /* Executive */
63529 #if BITS_PER_LONG == 64
63530 spinlock_t context_list_lock; /* lock for context_list */
63531 - atomic_t context_list_counter; /* needed for unique contexts */
63532 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63533 struct list_head context_list; /* list of context id's
63534 and pointers */
63535 #endif
63536 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63537 index aa2e167..84024ce 100644
63538 --- a/include/linux/if_team.h
63539 +++ b/include/linux/if_team.h
63540 @@ -109,6 +109,7 @@ struct team_mode_ops {
63541 void (*port_enabled)(struct team *team, struct team_port *port);
63542 void (*port_disabled)(struct team *team, struct team_port *port);
63543 };
63544 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63545
63546 enum team_option_type {
63547 TEAM_OPTION_TYPE_U32,
63548 @@ -181,7 +182,7 @@ struct team {
63549 struct list_head option_inst_list; /* list of option instances */
63550
63551 const struct team_mode *mode;
63552 - struct team_mode_ops ops;
63553 + team_mode_ops_no_const ops;
63554 long mode_priv[TEAM_MODE_PRIV_LONGS];
63555 };
63556
63557 diff --git a/include/linux/init.h b/include/linux/init.h
63558 index 5e664f6..ba694f0 100644
63559 --- a/include/linux/init.h
63560 +++ b/include/linux/init.h
63561 @@ -39,9 +39,36 @@
63562 * Also note, that this data cannot be "const".
63563 */
63564
63565 +#ifdef MODULE
63566 +#define add_init_latent_entropy
63567 +#define add_devinit_latent_entropy
63568 +#define add_cpuinit_latent_entropy
63569 +#define add_meminit_latent_entropy
63570 +#else
63571 +#define add_init_latent_entropy __latent_entropy
63572 +
63573 +#ifdef CONFIG_HOTPLUG
63574 +#define add_devinit_latent_entropy
63575 +#else
63576 +#define add_devinit_latent_entropy __latent_entropy
63577 +#endif
63578 +
63579 +#ifdef CONFIG_HOTPLUG_CPU
63580 +#define add_cpuinit_latent_entropy
63581 +#else
63582 +#define add_cpuinit_latent_entropy __latent_entropy
63583 +#endif
63584 +
63585 +#ifdef CONFIG_MEMORY_HOTPLUG
63586 +#define add_meminit_latent_entropy
63587 +#else
63588 +#define add_meminit_latent_entropy __latent_entropy
63589 +#endif
63590 +#endif
63591 +
63592 /* These are for everybody (although not all archs will actually
63593 discard it in modules) */
63594 -#define __init __section(.init.text) __cold notrace
63595 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
63596 #define __initdata __section(.init.data)
63597 #define __initconst __section(.init.rodata)
63598 #define __exitdata __section(.exit.data)
63599 @@ -83,7 +110,7 @@
63600 #define __exit __section(.exit.text) __exitused __cold notrace
63601
63602 /* Used for HOTPLUG */
63603 -#define __devinit __section(.devinit.text) __cold notrace
63604 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
63605 #define __devinitdata __section(.devinit.data)
63606 #define __devinitconst __section(.devinit.rodata)
63607 #define __devexit __section(.devexit.text) __exitused __cold notrace
63608 @@ -91,7 +118,7 @@
63609 #define __devexitconst __section(.devexit.rodata)
63610
63611 /* Used for HOTPLUG_CPU */
63612 -#define __cpuinit __section(.cpuinit.text) __cold notrace
63613 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
63614 #define __cpuinitdata __section(.cpuinit.data)
63615 #define __cpuinitconst __section(.cpuinit.rodata)
63616 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63617 @@ -99,7 +126,7 @@
63618 #define __cpuexitconst __section(.cpuexit.rodata)
63619
63620 /* Used for MEMORY_HOTPLUG */
63621 -#define __meminit __section(.meminit.text) __cold notrace
63622 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
63623 #define __meminitdata __section(.meminit.data)
63624 #define __meminitconst __section(.meminit.rodata)
63625 #define __memexit __section(.memexit.text) __exitused __cold notrace
63626 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63627 index 89f1cb1..7986c0f 100644
63628 --- a/include/linux/init_task.h
63629 +++ b/include/linux/init_task.h
63630 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63631
63632 #define INIT_TASK_COMM "swapper"
63633
63634 +#ifdef CONFIG_X86
63635 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63636 +#else
63637 +#define INIT_TASK_THREAD_INFO
63638 +#endif
63639 +
63640 /*
63641 * INIT_TASK is used to set up the first task table, touch at
63642 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63643 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63644 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63645 .comm = INIT_TASK_COMM, \
63646 .thread = INIT_THREAD, \
63647 + INIT_TASK_THREAD_INFO \
63648 .fs = &init_fs, \
63649 .files = &init_files, \
63650 .signal = &init_signals, \
63651 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63652 index 78e2ada..745564d 100644
63653 --- a/include/linux/intel-iommu.h
63654 +++ b/include/linux/intel-iommu.h
63655 @@ -296,7 +296,7 @@ struct iommu_flush {
63656 u8 fm, u64 type);
63657 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63658 unsigned int size_order, u64 type);
63659 -};
63660 +} __no_const;
63661
63662 enum {
63663 SR_DMAR_FECTL_REG,
63664 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63665 index c5f856a..d29c117 100644
63666 --- a/include/linux/interrupt.h
63667 +++ b/include/linux/interrupt.h
63668 @@ -433,7 +433,7 @@ enum
63669 /* map softirq index to softirq name. update 'softirq_to_name' in
63670 * kernel/softirq.c when adding a new softirq.
63671 */
63672 -extern char *softirq_to_name[NR_SOFTIRQS];
63673 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63674
63675 /* softirq mask and active fields moved to irq_cpustat_t in
63676 * asm/hardirq.h to get better cache usage. KAO
63677 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63678
63679 struct softirq_action
63680 {
63681 - void (*action)(struct softirq_action *);
63682 + void (*action)(void);
63683 };
63684
63685 asmlinkage void do_softirq(void);
63686 asmlinkage void __do_softirq(void);
63687 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63688 +extern void open_softirq(int nr, void (*action)(void));
63689 extern void softirq_init(void);
63690 extern void __raise_softirq_irqoff(unsigned int nr);
63691
63692 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63693 index 6883e19..06992b1 100644
63694 --- a/include/linux/kallsyms.h
63695 +++ b/include/linux/kallsyms.h
63696 @@ -15,7 +15,8 @@
63697
63698 struct module;
63699
63700 -#ifdef CONFIG_KALLSYMS
63701 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63702 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63703 /* Lookup the address for a symbol. Returns 0 if not found. */
63704 unsigned long kallsyms_lookup_name(const char *name);
63705
63706 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63707 /* Stupid that this does nothing, but I didn't create this mess. */
63708 #define __print_symbol(fmt, addr)
63709 #endif /*CONFIG_KALLSYMS*/
63710 +#else /* when included by kallsyms.c, vsnprintf.c, or
63711 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63712 +extern void __print_symbol(const char *fmt, unsigned long address);
63713 +extern int sprint_backtrace(char *buffer, unsigned long address);
63714 +extern int sprint_symbol(char *buffer, unsigned long address);
63715 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63716 +const char *kallsyms_lookup(unsigned long addr,
63717 + unsigned long *symbolsize,
63718 + unsigned long *offset,
63719 + char **modname, char *namebuf);
63720 +#endif
63721
63722 /* This macro allows us to keep printk typechecking */
63723 static __printf(1, 2)
63724 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63725 index c4d2fc1..5df9c19 100644
63726 --- a/include/linux/kgdb.h
63727 +++ b/include/linux/kgdb.h
63728 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63729 extern int kgdb_io_module_registered;
63730
63731 extern atomic_t kgdb_setting_breakpoint;
63732 -extern atomic_t kgdb_cpu_doing_single_step;
63733 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63734
63735 extern struct task_struct *kgdb_usethread;
63736 extern struct task_struct *kgdb_contthread;
63737 @@ -252,7 +252,7 @@ struct kgdb_arch {
63738 void (*disable_hw_break)(struct pt_regs *regs);
63739 void (*remove_all_hw_break)(void);
63740 void (*correct_hw_break)(void);
63741 -};
63742 +} __do_const;
63743
63744 /**
63745 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63746 @@ -277,7 +277,7 @@ struct kgdb_io {
63747 void (*pre_exception) (void);
63748 void (*post_exception) (void);
63749 int is_console;
63750 -};
63751 +} __do_const;
63752
63753 extern struct kgdb_arch arch_kgdb_ops;
63754
63755 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63756 index 5398d58..5883a34 100644
63757 --- a/include/linux/kmod.h
63758 +++ b/include/linux/kmod.h
63759 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63760 * usually useless though. */
63761 extern __printf(2, 3)
63762 int __request_module(bool wait, const char *name, ...);
63763 +extern __printf(3, 4)
63764 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63765 #define request_module(mod...) __request_module(true, mod)
63766 #define request_module_nowait(mod...) __request_module(false, mod)
63767 #define try_then_request_module(x, mod...) \
63768 diff --git a/include/linux/kref.h b/include/linux/kref.h
63769 index 65af688..0592677 100644
63770 --- a/include/linux/kref.h
63771 +++ b/include/linux/kref.h
63772 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63773 static inline int kref_sub(struct kref *kref, unsigned int count,
63774 void (*release)(struct kref *kref))
63775 {
63776 - WARN_ON(release == NULL);
63777 + BUG_ON(release == NULL);
63778
63779 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63780 release(kref);
63781 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63782 index b70b48b..0d7153b 100644
63783 --- a/include/linux/kvm_host.h
63784 +++ b/include/linux/kvm_host.h
63785 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63786 void vcpu_load(struct kvm_vcpu *vcpu);
63787 void vcpu_put(struct kvm_vcpu *vcpu);
63788
63789 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63790 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63791 struct module *module);
63792 void kvm_exit(void);
63793
63794 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63795 struct kvm_guest_debug *dbg);
63796 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63797
63798 -int kvm_arch_init(void *opaque);
63799 +int kvm_arch_init(const void *opaque);
63800 void kvm_arch_exit(void);
63801
63802 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63803 diff --git a/include/linux/libata.h b/include/linux/libata.h
63804 index 64f90e1..32b945b 100644
63805 --- a/include/linux/libata.h
63806 +++ b/include/linux/libata.h
63807 @@ -909,7 +909,7 @@ struct ata_port_operations {
63808 * fields must be pointers.
63809 */
63810 const struct ata_port_operations *inherits;
63811 -};
63812 +} __do_const;
63813
63814 struct ata_port_info {
63815 unsigned long flags;
63816 diff --git a/include/linux/memory.h b/include/linux/memory.h
63817 index ff9a9f8..c715deb 100644
63818 --- a/include/linux/memory.h
63819 +++ b/include/linux/memory.h
63820 @@ -143,7 +143,7 @@ struct memory_accessor {
63821 size_t count);
63822 ssize_t (*write)(struct memory_accessor *, const char *buf,
63823 off_t offset, size_t count);
63824 -};
63825 +} __no_const;
63826
63827 /*
63828 * Kernel text modification mutex, used for code patching. Users of this lock
63829 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
63830 index df08254..5f6c835 100644
63831 --- a/include/linux/mempolicy.h
63832 +++ b/include/linux/mempolicy.h
63833 @@ -137,16 +137,6 @@ static inline void mpol_cond_put(struct mempolicy *pol)
63834 __mpol_put(pol);
63835 }
63836
63837 -extern struct mempolicy *__mpol_cond_copy(struct mempolicy *tompol,
63838 - struct mempolicy *frompol);
63839 -static inline struct mempolicy *mpol_cond_copy(struct mempolicy *tompol,
63840 - struct mempolicy *frompol)
63841 -{
63842 - if (!frompol)
63843 - return frompol;
63844 - return __mpol_cond_copy(tompol, frompol);
63845 -}
63846 -
63847 extern struct mempolicy *__mpol_dup(struct mempolicy *pol);
63848 static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
63849 {
63850 @@ -270,12 +260,6 @@ static inline void mpol_cond_put(struct mempolicy *pol)
63851 {
63852 }
63853
63854 -static inline struct mempolicy *mpol_cond_copy(struct mempolicy *to,
63855 - struct mempolicy *from)
63856 -{
63857 - return from;
63858 -}
63859 -
63860 static inline void mpol_get(struct mempolicy *pol)
63861 {
63862 }
63863 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63864 index 1318ca6..7521340 100644
63865 --- a/include/linux/mfd/abx500.h
63866 +++ b/include/linux/mfd/abx500.h
63867 @@ -452,6 +452,7 @@ struct abx500_ops {
63868 int (*event_registers_startup_state_get) (struct device *, u8 *);
63869 int (*startup_irq_enabled) (struct device *, unsigned int);
63870 };
63871 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63872
63873 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63874 void abx500_remove_ops(struct device *dev);
63875 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63876 index 9b07725..3d55001 100644
63877 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63878 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63879 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63880 int (*enable) (struct ux500_charger *, int, int, int);
63881 int (*kick_wd) (struct ux500_charger *);
63882 int (*update_curr) (struct ux500_charger *, int);
63883 -};
63884 +} __no_const;
63885
63886 /**
63887 * struct ux500_charger - power supply ux500 charger sub class
63888 diff --git a/include/linux/mm.h b/include/linux/mm.h
63889 index 311be90..5f1638c 100644
63890 --- a/include/linux/mm.h
63891 +++ b/include/linux/mm.h
63892 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63893
63894 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63895 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63896 +
63897 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63898 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63899 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63900 +#else
63901 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63902 +#endif
63903 +
63904 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63905 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63906
63907 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63908 int set_page_dirty_lock(struct page *page);
63909 int clear_page_dirty_for_io(struct page *page);
63910
63911 -/* Is the vma a continuation of the stack vma above it? */
63912 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63913 -{
63914 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63915 -}
63916 -
63917 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63918 - unsigned long addr)
63919 -{
63920 - return (vma->vm_flags & VM_GROWSDOWN) &&
63921 - (vma->vm_start == addr) &&
63922 - !vma_growsdown(vma->vm_prev, addr);
63923 -}
63924 -
63925 -/* Is the vma a continuation of the stack vma below it? */
63926 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63927 -{
63928 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63929 -}
63930 -
63931 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63932 - unsigned long addr)
63933 -{
63934 - return (vma->vm_flags & VM_GROWSUP) &&
63935 - (vma->vm_end == addr) &&
63936 - !vma_growsup(vma->vm_next, addr);
63937 -}
63938 -
63939 extern pid_t
63940 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63941
63942 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63943 }
63944 #endif
63945
63946 +#ifdef CONFIG_MMU
63947 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63948 +#else
63949 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63950 +{
63951 + return __pgprot(0);
63952 +}
63953 +#endif
63954 +
63955 int vma_wants_writenotify(struct vm_area_struct *vma);
63956
63957 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63958 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63959 {
63960 return 0;
63961 }
63962 +
63963 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63964 + unsigned long address)
63965 +{
63966 + return 0;
63967 +}
63968 #else
63969 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63970 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63971 #endif
63972
63973 #ifdef __PAGETABLE_PMD_FOLDED
63974 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63975 {
63976 return 0;
63977 }
63978 +
63979 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63980 + unsigned long address)
63981 +{
63982 + return 0;
63983 +}
63984 #else
63985 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63986 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63987 #endif
63988
63989 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63990 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63991 NULL: pud_offset(pgd, address);
63992 }
63993
63994 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63995 +{
63996 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63997 + NULL: pud_offset(pgd, address);
63998 +}
63999 +
64000 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
64001 {
64002 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
64003 NULL: pmd_offset(pud, address);
64004 }
64005 +
64006 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
64007 +{
64008 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
64009 + NULL: pmd_offset(pud, address);
64010 +}
64011 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
64012
64013 #if USE_SPLIT_PTLOCKS
64014 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
64015 unsigned long, unsigned long,
64016 unsigned long, unsigned long);
64017 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
64018 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
64019
64020 /* These take the mm semaphore themselves */
64021 extern unsigned long vm_brk(unsigned long, unsigned long);
64022 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
64023 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
64024 struct vm_area_struct **pprev);
64025
64026 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
64027 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
64028 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
64029 +
64030 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
64031 NULL if none. Assume start_addr < end_addr. */
64032 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
64033 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
64034 return vma;
64035 }
64036
64037 -#ifdef CONFIG_MMU
64038 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
64039 -#else
64040 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
64041 -{
64042 - return __pgprot(0);
64043 -}
64044 -#endif
64045 -
64046 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
64047 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
64048 unsigned long pfn, unsigned long size, pgprot_t);
64049 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
64050 extern int sysctl_memory_failure_early_kill;
64051 extern int sysctl_memory_failure_recovery;
64052 extern void shake_page(struct page *p, int access);
64053 -extern atomic_long_t mce_bad_pages;
64054 +extern atomic_long_unchecked_t mce_bad_pages;
64055 extern int soft_offline_page(struct page *page, int flags);
64056
64057 extern void dump_page(struct page *page);
64058 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
64059 static inline bool page_is_guard(struct page *page) { return false; }
64060 #endif /* CONFIG_DEBUG_PAGEALLOC */
64061
64062 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64063 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
64064 +#else
64065 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
64066 +#endif
64067 +
64068 #endif /* __KERNEL__ */
64069 #endif /* _LINUX_MM_H */
64070 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
64071 index bf78672..debc693 100644
64072 --- a/include/linux/mm_types.h
64073 +++ b/include/linux/mm_types.h
64074 @@ -279,6 +279,8 @@ struct vm_area_struct {
64075 #ifdef CONFIG_NUMA
64076 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
64077 #endif
64078 +
64079 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
64080 };
64081
64082 struct core_thread {
64083 @@ -353,7 +355,7 @@ struct mm_struct {
64084 unsigned long def_flags;
64085 unsigned long nr_ptes; /* Page table pages */
64086 unsigned long start_code, end_code, start_data, end_data;
64087 - unsigned long start_brk, brk, start_stack;
64088 + unsigned long brk_gap, start_brk, brk, start_stack;
64089 unsigned long arg_start, arg_end, env_start, env_end;
64090
64091 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
64092 @@ -405,6 +407,24 @@ struct mm_struct {
64093 struct cpumask cpumask_allocation;
64094 #endif
64095 struct uprobes_state uprobes_state;
64096 +
64097 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64098 + unsigned long pax_flags;
64099 +#endif
64100 +
64101 +#ifdef CONFIG_PAX_DLRESOLVE
64102 + unsigned long call_dl_resolve;
64103 +#endif
64104 +
64105 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
64106 + unsigned long call_syscall;
64107 +#endif
64108 +
64109 +#ifdef CONFIG_PAX_ASLR
64110 + unsigned long delta_mmap; /* randomized offset */
64111 + unsigned long delta_stack; /* randomized offset */
64112 +#endif
64113 +
64114 };
64115
64116 static inline void mm_init_cpumask(struct mm_struct *mm)
64117 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
64118 index 1d1b1e1..2a13c78 100644
64119 --- a/include/linux/mmu_notifier.h
64120 +++ b/include/linux/mmu_notifier.h
64121 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
64122 */
64123 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
64124 ({ \
64125 - pte_t __pte; \
64126 + pte_t ___pte; \
64127 struct vm_area_struct *___vma = __vma; \
64128 unsigned long ___address = __address; \
64129 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
64130 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
64131 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
64132 - __pte; \
64133 + ___pte; \
64134 })
64135
64136 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
64137 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
64138 index a16d929..860ae00 100644
64139 --- a/include/linux/mmzone.h
64140 +++ b/include/linux/mmzone.h
64141 @@ -414,7 +414,7 @@ struct zone {
64142 unsigned long flags; /* zone flags, see below */
64143
64144 /* Zone statistics */
64145 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64146 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64147
64148 /*
64149 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
64150 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
64151 index 6955045..ebdb7cd 100644
64152 --- a/include/linux/mod_devicetable.h
64153 +++ b/include/linux/mod_devicetable.h
64154 @@ -12,7 +12,7 @@
64155 typedef unsigned long kernel_ulong_t;
64156 #endif
64157
64158 -#define PCI_ANY_ID (~0)
64159 +#define PCI_ANY_ID ((__u16)~0)
64160
64161 struct pci_device_id {
64162 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
64163 @@ -139,7 +139,7 @@ struct usb_device_id {
64164 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
64165 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
64166
64167 -#define HID_ANY_ID (~0)
64168 +#define HID_ANY_ID (~0U)
64169 #define HID_BUS_ANY 0xffff
64170 #define HID_GROUP_ANY 0x0000
64171
64172 diff --git a/include/linux/module.h b/include/linux/module.h
64173 index fbcafe2..e5d9587 100644
64174 --- a/include/linux/module.h
64175 +++ b/include/linux/module.h
64176 @@ -17,6 +17,7 @@
64177 #include <linux/moduleparam.h>
64178 #include <linux/tracepoint.h>
64179 #include <linux/export.h>
64180 +#include <linux/fs.h>
64181
64182 #include <linux/percpu.h>
64183 #include <asm/module.h>
64184 @@ -273,19 +274,16 @@ struct module
64185 int (*init)(void);
64186
64187 /* If this is non-NULL, vfree after init() returns */
64188 - void *module_init;
64189 + void *module_init_rx, *module_init_rw;
64190
64191 /* Here is the actual code + data, vfree'd on unload. */
64192 - void *module_core;
64193 + void *module_core_rx, *module_core_rw;
64194
64195 /* Here are the sizes of the init and core sections */
64196 - unsigned int init_size, core_size;
64197 + unsigned int init_size_rw, core_size_rw;
64198
64199 /* The size of the executable code in each section. */
64200 - unsigned int init_text_size, core_text_size;
64201 -
64202 - /* Size of RO sections of the module (text+rodata) */
64203 - unsigned int init_ro_size, core_ro_size;
64204 + unsigned int init_size_rx, core_size_rx;
64205
64206 /* Arch-specific module values */
64207 struct mod_arch_specific arch;
64208 @@ -341,6 +339,10 @@ struct module
64209 #ifdef CONFIG_EVENT_TRACING
64210 struct ftrace_event_call **trace_events;
64211 unsigned int num_trace_events;
64212 + struct file_operations trace_id;
64213 + struct file_operations trace_enable;
64214 + struct file_operations trace_format;
64215 + struct file_operations trace_filter;
64216 #endif
64217 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
64218 unsigned int num_ftrace_callsites;
64219 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
64220 bool is_module_percpu_address(unsigned long addr);
64221 bool is_module_text_address(unsigned long addr);
64222
64223 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
64224 +{
64225 +
64226 +#ifdef CONFIG_PAX_KERNEXEC
64227 + if (ktla_ktva(addr) >= (unsigned long)start &&
64228 + ktla_ktva(addr) < (unsigned long)start + size)
64229 + return 1;
64230 +#endif
64231 +
64232 + return ((void *)addr >= start && (void *)addr < start + size);
64233 +}
64234 +
64235 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
64236 +{
64237 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
64238 +}
64239 +
64240 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
64241 +{
64242 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
64243 +}
64244 +
64245 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
64246 +{
64247 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
64248 +}
64249 +
64250 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
64251 +{
64252 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
64253 +}
64254 +
64255 static inline int within_module_core(unsigned long addr, struct module *mod)
64256 {
64257 - return (unsigned long)mod->module_core <= addr &&
64258 - addr < (unsigned long)mod->module_core + mod->core_size;
64259 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
64260 }
64261
64262 static inline int within_module_init(unsigned long addr, struct module *mod)
64263 {
64264 - return (unsigned long)mod->module_init <= addr &&
64265 - addr < (unsigned long)mod->module_init + mod->init_size;
64266 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
64267 }
64268
64269 /* Search for module by name: must hold module_mutex. */
64270 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
64271 index b2be02e..72d2f78 100644
64272 --- a/include/linux/moduleloader.h
64273 +++ b/include/linux/moduleloader.h
64274 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
64275
64276 /* Allocator used for allocating struct module, core sections and init
64277 sections. Returns NULL on failure. */
64278 -void *module_alloc(unsigned long size);
64279 +void *module_alloc(unsigned long size) __size_overflow(1);
64280 +
64281 +#ifdef CONFIG_PAX_KERNEXEC
64282 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
64283 +#else
64284 +#define module_alloc_exec(x) module_alloc(x)
64285 +#endif
64286
64287 /* Free memory returned from module_alloc. */
64288 void module_free(struct module *mod, void *module_region);
64289
64290 +#ifdef CONFIG_PAX_KERNEXEC
64291 +void module_free_exec(struct module *mod, void *module_region);
64292 +#else
64293 +#define module_free_exec(x, y) module_free((x), (y))
64294 +#endif
64295 +
64296 /* Apply the given relocation to the (simplified) ELF. Return -error
64297 or 0. */
64298 int apply_relocate(Elf_Shdr *sechdrs,
64299 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
64300 index d6a5806..7c13347 100644
64301 --- a/include/linux/moduleparam.h
64302 +++ b/include/linux/moduleparam.h
64303 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
64304 * @len is usually just sizeof(string).
64305 */
64306 #define module_param_string(name, string, len, perm) \
64307 - static const struct kparam_string __param_string_##name \
64308 + static const struct kparam_string __param_string_##name __used \
64309 = { len, string }; \
64310 __module_param_call(MODULE_PARAM_PREFIX, name, \
64311 &param_ops_string, \
64312 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
64313 */
64314 #define module_param_array_named(name, array, type, nump, perm) \
64315 param_check_##type(name, &(array)[0]); \
64316 - static const struct kparam_array __param_arr_##name \
64317 + static const struct kparam_array __param_arr_##name __used \
64318 = { .max = ARRAY_SIZE(array), .num = nump, \
64319 .ops = &param_ops_##type, \
64320 .elemsize = sizeof(array[0]), .elem = array }; \
64321 diff --git a/include/linux/namei.h b/include/linux/namei.h
64322 index 4bf19d8..5268cea 100644
64323 --- a/include/linux/namei.h
64324 +++ b/include/linux/namei.h
64325 @@ -18,7 +18,7 @@ struct nameidata {
64326 unsigned seq;
64327 int last_type;
64328 unsigned depth;
64329 - char *saved_names[MAX_NESTED_LINKS + 1];
64330 + const char *saved_names[MAX_NESTED_LINKS + 1];
64331 };
64332
64333 /*
64334 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
64335
64336 extern void nd_jump_link(struct nameidata *nd, struct path *path);
64337
64338 -static inline void nd_set_link(struct nameidata *nd, char *path)
64339 +static inline void nd_set_link(struct nameidata *nd, const char *path)
64340 {
64341 nd->saved_names[nd->depth] = path;
64342 }
64343
64344 -static inline char *nd_get_link(struct nameidata *nd)
64345 +static inline const char *nd_get_link(const struct nameidata *nd)
64346 {
64347 return nd->saved_names[nd->depth];
64348 }
64349 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
64350 index 59dc05f3..c905a34 100644
64351 --- a/include/linux/netdevice.h
64352 +++ b/include/linux/netdevice.h
64353 @@ -1027,6 +1027,7 @@ struct net_device_ops {
64354 struct net_device *dev,
64355 int idx);
64356 };
64357 +typedef struct net_device_ops __no_const net_device_ops_no_const;
64358
64359 /*
64360 * The DEVICE structure.
64361 @@ -1087,7 +1088,7 @@ struct net_device {
64362 int iflink;
64363
64364 struct net_device_stats stats;
64365 - atomic_long_t rx_dropped; /* dropped packets by core network
64366 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
64367 * Do not use this in drivers.
64368 */
64369
64370 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
64371 new file mode 100644
64372 index 0000000..33f4af8
64373 --- /dev/null
64374 +++ b/include/linux/netfilter/xt_gradm.h
64375 @@ -0,0 +1,9 @@
64376 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
64377 +#define _LINUX_NETFILTER_XT_GRADM_H 1
64378 +
64379 +struct xt_gradm_mtinfo {
64380 + __u16 flags;
64381 + __u16 invflags;
64382 +};
64383 +
64384 +#endif
64385 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
64386 index c65a18a..0c05f3a 100644
64387 --- a/include/linux/of_pdt.h
64388 +++ b/include/linux/of_pdt.h
64389 @@ -32,7 +32,7 @@ struct of_pdt_ops {
64390
64391 /* return 0 on success; fill in 'len' with number of bytes in path */
64392 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
64393 -};
64394 +} __no_const;
64395
64396 extern void *prom_early_alloc(unsigned long size);
64397
64398 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
64399 index a4c5624..79d6d88 100644
64400 --- a/include/linux/oprofile.h
64401 +++ b/include/linux/oprofile.h
64402 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
64403 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64404 char const * name, ulong * val);
64405
64406 -/** Create a file for read-only access to an atomic_t. */
64407 +/** Create a file for read-only access to an atomic_unchecked_t. */
64408 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64409 - char const * name, atomic_t * val);
64410 + char const * name, atomic_unchecked_t * val);
64411
64412 /** create a directory */
64413 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64414 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
64415 index bdb4161..f373d41 100644
64416 --- a/include/linux/perf_event.h
64417 +++ b/include/linux/perf_event.h
64418 @@ -882,8 +882,8 @@ struct perf_event {
64419
64420 enum perf_event_active_state state;
64421 unsigned int attach_state;
64422 - local64_t count;
64423 - atomic64_t child_count;
64424 + local64_t count; /* PaX: fix it one day */
64425 + atomic64_unchecked_t child_count;
64426
64427 /*
64428 * These are the total time in nanoseconds that the event
64429 @@ -934,8 +934,8 @@ struct perf_event {
64430 * These accumulate total time (in nanoseconds) that children
64431 * events have been enabled and running, respectively.
64432 */
64433 - atomic64_t child_total_time_enabled;
64434 - atomic64_t child_total_time_running;
64435 + atomic64_unchecked_t child_total_time_enabled;
64436 + atomic64_unchecked_t child_total_time_running;
64437
64438 /*
64439 * Protect attach/detach and child_list:
64440 diff --git a/include/linux/personality.h b/include/linux/personality.h
64441 index 8fc7dd1a..c19d89e 100644
64442 --- a/include/linux/personality.h
64443 +++ b/include/linux/personality.h
64444 @@ -44,6 +44,7 @@ enum {
64445 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
64446 ADDR_NO_RANDOMIZE | \
64447 ADDR_COMPAT_LAYOUT | \
64448 + ADDR_LIMIT_3GB | \
64449 MMAP_PAGE_ZERO)
64450
64451 /*
64452 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
64453 index ad1a427..6419649 100644
64454 --- a/include/linux/pipe_fs_i.h
64455 +++ b/include/linux/pipe_fs_i.h
64456 @@ -45,9 +45,9 @@ struct pipe_buffer {
64457 struct pipe_inode_info {
64458 wait_queue_head_t wait;
64459 unsigned int nrbufs, curbuf, buffers;
64460 - unsigned int readers;
64461 - unsigned int writers;
64462 - unsigned int waiting_writers;
64463 + atomic_t readers;
64464 + atomic_t writers;
64465 + atomic_t waiting_writers;
64466 unsigned int r_counter;
64467 unsigned int w_counter;
64468 struct page *tmp_page;
64469 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
64470 index f271860..6b3bec5 100644
64471 --- a/include/linux/pm_runtime.h
64472 +++ b/include/linux/pm_runtime.h
64473 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
64474
64475 static inline void pm_runtime_mark_last_busy(struct device *dev)
64476 {
64477 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
64478 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
64479 }
64480
64481 #else /* !CONFIG_PM_RUNTIME */
64482 diff --git a/include/linux/poison.h b/include/linux/poison.h
64483 index 2110a81..13a11bb 100644
64484 --- a/include/linux/poison.h
64485 +++ b/include/linux/poison.h
64486 @@ -19,8 +19,8 @@
64487 * under normal circumstances, used to verify that nobody uses
64488 * non-initialized list entries.
64489 */
64490 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64491 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64492 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64493 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64494
64495 /********** include/linux/timer.h **********/
64496 /*
64497 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
64498 index 5a710b9..0b0dab9 100644
64499 --- a/include/linux/preempt.h
64500 +++ b/include/linux/preempt.h
64501 @@ -126,7 +126,7 @@ struct preempt_ops {
64502 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
64503 void (*sched_out)(struct preempt_notifier *notifier,
64504 struct task_struct *next);
64505 -};
64506 +} __no_const;
64507
64508 /**
64509 * preempt_notifier - key for installing preemption notifiers
64510 diff --git a/include/linux/printk.h b/include/linux/printk.h
64511 index 9afc01e..92c32e8 100644
64512 --- a/include/linux/printk.h
64513 +++ b/include/linux/printk.h
64514 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
64515 extern int printk_needs_cpu(int cpu);
64516 extern void printk_tick(void);
64517
64518 +extern int kptr_restrict;
64519 +
64520 #ifdef CONFIG_PRINTK
64521 asmlinkage __printf(5, 0)
64522 int vprintk_emit(int facility, int level,
64523 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
64524
64525 extern int printk_delay_msec;
64526 extern int dmesg_restrict;
64527 -extern int kptr_restrict;
64528
64529 void log_buf_kexec_setup(void);
64530 void __init setup_log_buf(int early);
64531 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
64532 index 3fd2e87..d93a721 100644
64533 --- a/include/linux/proc_fs.h
64534 +++ b/include/linux/proc_fs.h
64535 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
64536 return proc_create_data(name, mode, parent, proc_fops, NULL);
64537 }
64538
64539 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
64540 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64541 +{
64542 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64543 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64544 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64545 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64546 +#else
64547 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64548 +#endif
64549 +}
64550 +
64551 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64552 umode_t mode, struct proc_dir_entry *base,
64553 read_proc_t *read_proc, void * data)
64554 @@ -258,7 +270,7 @@ union proc_op {
64555 int (*proc_show)(struct seq_file *m,
64556 struct pid_namespace *ns, struct pid *pid,
64557 struct task_struct *task);
64558 -};
64559 +} __no_const;
64560
64561 struct ctl_table_header;
64562 struct ctl_table;
64563 diff --git a/include/linux/random.h b/include/linux/random.h
64564 index ac621ce..c1215f3 100644
64565 --- a/include/linux/random.h
64566 +++ b/include/linux/random.h
64567 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
64568 unsigned int value);
64569 extern void add_interrupt_randomness(int irq, int irq_flags);
64570
64571 +#ifdef CONFIG_PAX_LATENT_ENTROPY
64572 +extern void transfer_latent_entropy(void);
64573 +#endif
64574 +
64575 extern void get_random_bytes(void *buf, int nbytes);
64576 extern void get_random_bytes_arch(void *buf, int nbytes);
64577 void generate_random_uuid(unsigned char uuid_out[16]);
64578 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
64579
64580 u32 prandom32(struct rnd_state *);
64581
64582 +static inline unsigned long pax_get_random_long(void)
64583 +{
64584 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64585 +}
64586 +
64587 /*
64588 * Handle minimum values for seeds
64589 */
64590 static inline u32 __seed(u32 x, u32 m)
64591 {
64592 - return (x < m) ? x + m : x;
64593 + return (x <= m) ? x + m + 1 : x;
64594 }
64595
64596 /**
64597 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64598 index e0879a7..a12f962 100644
64599 --- a/include/linux/reboot.h
64600 +++ b/include/linux/reboot.h
64601 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64602 * Architecture-specific implementations of sys_reboot commands.
64603 */
64604
64605 -extern void machine_restart(char *cmd);
64606 -extern void machine_halt(void);
64607 -extern void machine_power_off(void);
64608 +extern void machine_restart(char *cmd) __noreturn;
64609 +extern void machine_halt(void) __noreturn;
64610 +extern void machine_power_off(void) __noreturn;
64611
64612 extern void machine_shutdown(void);
64613 struct pt_regs;
64614 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64615 */
64616
64617 extern void kernel_restart_prepare(char *cmd);
64618 -extern void kernel_restart(char *cmd);
64619 -extern void kernel_halt(void);
64620 -extern void kernel_power_off(void);
64621 +extern void kernel_restart(char *cmd) __noreturn;
64622 +extern void kernel_halt(void) __noreturn;
64623 +extern void kernel_power_off(void) __noreturn;
64624
64625 extern int C_A_D; /* for sysctl */
64626 void ctrl_alt_del(void);
64627 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64628 * Emergency restart, callable from an interrupt handler.
64629 */
64630
64631 -extern void emergency_restart(void);
64632 +extern void emergency_restart(void) __noreturn;
64633 #include <asm/emergency-restart.h>
64634
64635 #endif
64636 diff --git a/include/linux/relay.h b/include/linux/relay.h
64637 index 91cacc3..b55ff74 100644
64638 --- a/include/linux/relay.h
64639 +++ b/include/linux/relay.h
64640 @@ -160,7 +160,7 @@ struct rchan_callbacks
64641 * The callback should return 0 if successful, negative if not.
64642 */
64643 int (*remove_buf_file)(struct dentry *dentry);
64644 -};
64645 +} __no_const;
64646
64647 /*
64648 * CONFIG_RELAY kernel API, kernel/relay.c
64649 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64650 index 6fdf027..ff72610 100644
64651 --- a/include/linux/rfkill.h
64652 +++ b/include/linux/rfkill.h
64653 @@ -147,6 +147,7 @@ struct rfkill_ops {
64654 void (*query)(struct rfkill *rfkill, void *data);
64655 int (*set_block)(void *data, bool blocked);
64656 };
64657 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64658
64659 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64660 /**
64661 diff --git a/include/linux/rio.h b/include/linux/rio.h
64662 index a90ebad..fd87b5d 100644
64663 --- a/include/linux/rio.h
64664 +++ b/include/linux/rio.h
64665 @@ -321,7 +321,7 @@ struct rio_ops {
64666 int mbox, void *buffer, size_t len);
64667 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64668 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64669 -};
64670 +} __no_const;
64671
64672 #define RIO_RESOURCE_MEM 0x00000100
64673 #define RIO_RESOURCE_DOORBELL 0x00000200
64674 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64675 index 3fce545..b4fed6e 100644
64676 --- a/include/linux/rmap.h
64677 +++ b/include/linux/rmap.h
64678 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64679 void anon_vma_init(void); /* create anon_vma_cachep */
64680 int anon_vma_prepare(struct vm_area_struct *);
64681 void unlink_anon_vmas(struct vm_area_struct *);
64682 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64683 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64684 void anon_vma_moveto_tail(struct vm_area_struct *);
64685 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64686 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64687
64688 static inline void anon_vma_merge(struct vm_area_struct *vma,
64689 struct vm_area_struct *next)
64690 diff --git a/include/linux/sched.h b/include/linux/sched.h
64691 index 23bddac..e08f087 100644
64692 --- a/include/linux/sched.h
64693 +++ b/include/linux/sched.h
64694 @@ -101,6 +101,7 @@ struct bio_list;
64695 struct fs_struct;
64696 struct perf_event_context;
64697 struct blk_plug;
64698 +struct linux_binprm;
64699
64700 /*
64701 * List of flags we want to share for kernel threads,
64702 @@ -384,10 +385,13 @@ struct user_namespace;
64703 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64704
64705 extern int sysctl_max_map_count;
64706 +extern unsigned long sysctl_heap_stack_gap;
64707
64708 #include <linux/aio.h>
64709
64710 #ifdef CONFIG_MMU
64711 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64712 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64713 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64714 extern unsigned long
64715 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64716 @@ -651,6 +655,17 @@ struct signal_struct {
64717 #ifdef CONFIG_TASKSTATS
64718 struct taskstats *stats;
64719 #endif
64720 +
64721 +#ifdef CONFIG_GRKERNSEC
64722 + u32 curr_ip;
64723 + u32 saved_ip;
64724 + u32 gr_saddr;
64725 + u32 gr_daddr;
64726 + u16 gr_sport;
64727 + u16 gr_dport;
64728 + u8 used_accept:1;
64729 +#endif
64730 +
64731 #ifdef CONFIG_AUDIT
64732 unsigned audit_tty;
64733 struct tty_audit_buf *tty_audit_buf;
64734 @@ -734,6 +749,11 @@ struct user_struct {
64735 struct key *session_keyring; /* UID's default session keyring */
64736 #endif
64737
64738 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64739 + unsigned int banned;
64740 + unsigned long ban_expires;
64741 +#endif
64742 +
64743 /* Hash table maintenance information */
64744 struct hlist_node uidhash_node;
64745 kuid_t uid;
64746 @@ -1356,8 +1376,8 @@ struct task_struct {
64747 struct list_head thread_group;
64748
64749 struct completion *vfork_done; /* for vfork() */
64750 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64751 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64752 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64753 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64754
64755 cputime_t utime, stime, utimescaled, stimescaled;
64756 cputime_t gtime;
64757 @@ -1373,11 +1393,6 @@ struct task_struct {
64758 struct task_cputime cputime_expires;
64759 struct list_head cpu_timers[3];
64760
64761 -/* process credentials */
64762 - const struct cred __rcu *real_cred; /* objective and real subjective task
64763 - * credentials (COW) */
64764 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64765 - * credentials (COW) */
64766 char comm[TASK_COMM_LEN]; /* executable name excluding path
64767 - access with [gs]et_task_comm (which lock
64768 it with task_lock())
64769 @@ -1394,6 +1409,10 @@ struct task_struct {
64770 #endif
64771 /* CPU-specific state of this task */
64772 struct thread_struct thread;
64773 +/* thread_info moved to task_struct */
64774 +#ifdef CONFIG_X86
64775 + struct thread_info tinfo;
64776 +#endif
64777 /* filesystem information */
64778 struct fs_struct *fs;
64779 /* open file information */
64780 @@ -1467,6 +1486,10 @@ struct task_struct {
64781 gfp_t lockdep_reclaim_gfp;
64782 #endif
64783
64784 +/* process credentials */
64785 + const struct cred __rcu *real_cred; /* objective and real subjective task
64786 + * credentials (COW) */
64787 +
64788 /* journalling filesystem info */
64789 void *journal_info;
64790
64791 @@ -1505,6 +1528,10 @@ struct task_struct {
64792 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64793 struct list_head cg_list;
64794 #endif
64795 +
64796 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64797 + * credentials (COW) */
64798 +
64799 #ifdef CONFIG_FUTEX
64800 struct robust_list_head __user *robust_list;
64801 #ifdef CONFIG_COMPAT
64802 @@ -1589,8 +1616,75 @@ struct task_struct {
64803 #ifdef CONFIG_UPROBES
64804 struct uprobe_task *utask;
64805 #endif
64806 +
64807 +#ifdef CONFIG_GRKERNSEC
64808 + /* grsecurity */
64809 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64810 + u64 exec_id;
64811 +#endif
64812 +#ifdef CONFIG_GRKERNSEC_SETXID
64813 + const struct cred *delayed_cred;
64814 +#endif
64815 + struct dentry *gr_chroot_dentry;
64816 + struct acl_subject_label *acl;
64817 + struct acl_role_label *role;
64818 + struct file *exec_file;
64819 + unsigned long brute_expires;
64820 + u16 acl_role_id;
64821 + /* is this the task that authenticated to the special role */
64822 + u8 acl_sp_role;
64823 + u8 is_writable;
64824 + u8 brute;
64825 + u8 gr_is_chrooted;
64826 +#endif
64827 +
64828 };
64829
64830 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64831 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64832 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64833 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64834 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64835 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64836 +
64837 +#ifdef CONFIG_PAX_SOFTMODE
64838 +extern int pax_softmode;
64839 +#endif
64840 +
64841 +extern int pax_check_flags(unsigned long *);
64842 +
64843 +/* if tsk != current then task_lock must be held on it */
64844 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64845 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64846 +{
64847 + if (likely(tsk->mm))
64848 + return tsk->mm->pax_flags;
64849 + else
64850 + return 0UL;
64851 +}
64852 +
64853 +/* if tsk != current then task_lock must be held on it */
64854 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64855 +{
64856 + if (likely(tsk->mm)) {
64857 + tsk->mm->pax_flags = flags;
64858 + return 0;
64859 + }
64860 + return -EINVAL;
64861 +}
64862 +#endif
64863 +
64864 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64865 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64866 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64867 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64868 +#endif
64869 +
64870 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64871 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64872 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64873 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64874 +
64875 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64876 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64877
64878 @@ -2125,7 +2219,9 @@ void yield(void);
64879 extern struct exec_domain default_exec_domain;
64880
64881 union thread_union {
64882 +#ifndef CONFIG_X86
64883 struct thread_info thread_info;
64884 +#endif
64885 unsigned long stack[THREAD_SIZE/sizeof(long)];
64886 };
64887
64888 @@ -2158,6 +2254,7 @@ extern struct pid_namespace init_pid_ns;
64889 */
64890
64891 extern struct task_struct *find_task_by_vpid(pid_t nr);
64892 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64893 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64894 struct pid_namespace *ns);
64895
64896 @@ -2314,7 +2411,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64897 extern void exit_itimers(struct signal_struct *);
64898 extern void flush_itimer_signals(void);
64899
64900 -extern void do_group_exit(int);
64901 +extern __noreturn void do_group_exit(int);
64902
64903 extern void daemonize(const char *, ...);
64904 extern int allow_signal(int);
64905 @@ -2515,9 +2612,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64906
64907 #endif
64908
64909 -static inline int object_is_on_stack(void *obj)
64910 +static inline int object_starts_on_stack(void *obj)
64911 {
64912 - void *stack = task_stack_page(current);
64913 + const void *stack = task_stack_page(current);
64914
64915 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64916 }
64917 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64918 index 899fbb4..1cb4138 100644
64919 --- a/include/linux/screen_info.h
64920 +++ b/include/linux/screen_info.h
64921 @@ -43,7 +43,8 @@ struct screen_info {
64922 __u16 pages; /* 0x32 */
64923 __u16 vesa_attributes; /* 0x34 */
64924 __u32 capabilities; /* 0x36 */
64925 - __u8 _reserved[6]; /* 0x3a */
64926 + __u16 vesapm_size; /* 0x3a */
64927 + __u8 _reserved[4]; /* 0x3c */
64928 } __attribute__((packed));
64929
64930 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64931 diff --git a/include/linux/security.h b/include/linux/security.h
64932 index d143b8e..9f27b95 100644
64933 --- a/include/linux/security.h
64934 +++ b/include/linux/security.h
64935 @@ -26,6 +26,7 @@
64936 #include <linux/capability.h>
64937 #include <linux/slab.h>
64938 #include <linux/err.h>
64939 +#include <linux/grsecurity.h>
64940
64941 struct linux_binprm;
64942 struct cred;
64943 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64944 index 83c44ee..e8a9eba 100644
64945 --- a/include/linux/seq_file.h
64946 +++ b/include/linux/seq_file.h
64947 @@ -25,6 +25,9 @@ struct seq_file {
64948 struct mutex lock;
64949 const struct seq_operations *op;
64950 int poll_event;
64951 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64952 + u64 exec_id;
64953 +#endif
64954 void *private;
64955 };
64956
64957 @@ -34,6 +37,7 @@ struct seq_operations {
64958 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64959 int (*show) (struct seq_file *m, void *v);
64960 };
64961 +typedef struct seq_operations __no_const seq_operations_no_const;
64962
64963 #define SEQ_SKIP 1
64964
64965 diff --git a/include/linux/shm.h b/include/linux/shm.h
64966 index edd0868..f98feee 100644
64967 --- a/include/linux/shm.h
64968 +++ b/include/linux/shm.h
64969 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64970
64971 /* The task created the shm object. NULL if the task is dead. */
64972 struct task_struct *shm_creator;
64973 +#ifdef CONFIG_GRKERNSEC
64974 + time_t shm_createtime;
64975 + pid_t shm_lapid;
64976 +#endif
64977 };
64978
64979 /* shm_mode upper byte flags */
64980 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64981 index f3165d2..2cb3cb7 100644
64982 --- a/include/linux/skbuff.h
64983 +++ b/include/linux/skbuff.h
64984 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64985 extern struct sk_buff *__alloc_skb(unsigned int size,
64986 gfp_t priority, int flags, int node);
64987 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64988 -static inline struct sk_buff *alloc_skb(unsigned int size,
64989 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64990 gfp_t priority)
64991 {
64992 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64993 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64994 */
64995 static inline int skb_queue_empty(const struct sk_buff_head *list)
64996 {
64997 - return list->next == (struct sk_buff *)list;
64998 + return list->next == (const struct sk_buff *)list;
64999 }
65000
65001 /**
65002 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
65003 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
65004 const struct sk_buff *skb)
65005 {
65006 - return skb->next == (struct sk_buff *)list;
65007 + return skb->next == (const struct sk_buff *)list;
65008 }
65009
65010 /**
65011 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
65012 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
65013 const struct sk_buff *skb)
65014 {
65015 - return skb->prev == (struct sk_buff *)list;
65016 + return skb->prev == (const struct sk_buff *)list;
65017 }
65018
65019 /**
65020 @@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
65021 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
65022 */
65023 #ifndef NET_SKB_PAD
65024 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
65025 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
65026 #endif
65027
65028 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
65029 @@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
65030 int noblock, int *err);
65031 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
65032 struct poll_table_struct *wait);
65033 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
65034 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
65035 int offset, struct iovec *to,
65036 int size);
65037 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
65038 diff --git a/include/linux/slab.h b/include/linux/slab.h
65039 index 0dd2dfa..2b8677c 100644
65040 --- a/include/linux/slab.h
65041 +++ b/include/linux/slab.h
65042 @@ -11,12 +11,20 @@
65043
65044 #include <linux/gfp.h>
65045 #include <linux/types.h>
65046 +#include <linux/err.h>
65047
65048 /*
65049 * Flags to pass to kmem_cache_create().
65050 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
65051 */
65052 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
65053 +
65054 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65055 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
65056 +#else
65057 +#define SLAB_USERCOPY 0x00000000UL
65058 +#endif
65059 +
65060 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
65061 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
65062 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
65063 @@ -87,10 +95,13 @@
65064 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
65065 * Both make kfree a no-op.
65066 */
65067 -#define ZERO_SIZE_PTR ((void *)16)
65068 +#define ZERO_SIZE_PTR \
65069 +({ \
65070 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
65071 + (void *)(-MAX_ERRNO-1L); \
65072 +})
65073
65074 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
65075 - (unsigned long)ZERO_SIZE_PTR)
65076 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
65077
65078 /*
65079 * Common fields provided in kmem_cache by all slab allocators
65080 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
65081 void kfree(const void *);
65082 void kzfree(const void *);
65083 size_t ksize(const void *);
65084 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
65085 +bool is_usercopy_object(const void *ptr);
65086
65087 /*
65088 * Allocator specific definitions. These are mainly used to establish optimized
65089 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
65090 */
65091 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
65092 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
65093 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
65094 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
65095 #define kmalloc_track_caller(size, flags) \
65096 __kmalloc_track_caller(size, flags, _RET_IP_)
65097 #else
65098 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
65099 */
65100 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
65101 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
65102 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
65103 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
65104 #define kmalloc_node_track_caller(size, flags, node) \
65105 __kmalloc_node_track_caller(size, flags, node, \
65106 _RET_IP_)
65107 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
65108 index 0c634fa..8616300 100644
65109 --- a/include/linux/slab_def.h
65110 +++ b/include/linux/slab_def.h
65111 @@ -69,10 +69,10 @@ struct kmem_cache {
65112 unsigned long node_allocs;
65113 unsigned long node_frees;
65114 unsigned long node_overflow;
65115 - atomic_t allochit;
65116 - atomic_t allocmiss;
65117 - atomic_t freehit;
65118 - atomic_t freemiss;
65119 + atomic_unchecked_t allochit;
65120 + atomic_unchecked_t allocmiss;
65121 + atomic_unchecked_t freehit;
65122 + atomic_unchecked_t freemiss;
65123
65124 /*
65125 * If debugging is enabled, then the allocator can add additional
65126 @@ -105,11 +105,16 @@ struct cache_sizes {
65127 #ifdef CONFIG_ZONE_DMA
65128 struct kmem_cache *cs_dmacachep;
65129 #endif
65130 +
65131 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65132 + struct kmem_cache *cs_usercopycachep;
65133 +#endif
65134 +
65135 };
65136 extern struct cache_sizes malloc_sizes[];
65137
65138 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
65139 -void *__kmalloc(size_t size, gfp_t flags);
65140 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
65141
65142 #ifdef CONFIG_TRACING
65143 extern void *kmem_cache_alloc_trace(size_t size,
65144 @@ -152,6 +157,13 @@ found:
65145 cachep = malloc_sizes[i].cs_dmacachep;
65146 else
65147 #endif
65148 +
65149 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65150 + if (flags & GFP_USERCOPY)
65151 + cachep = malloc_sizes[i].cs_usercopycachep;
65152 + else
65153 +#endif
65154 +
65155 cachep = malloc_sizes[i].cs_cachep;
65156
65157 ret = kmem_cache_alloc_trace(size, cachep, flags);
65158 @@ -162,7 +174,7 @@ found:
65159 }
65160
65161 #ifdef CONFIG_NUMA
65162 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
65163 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65164 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
65165
65166 #ifdef CONFIG_TRACING
65167 @@ -205,6 +217,13 @@ found:
65168 cachep = malloc_sizes[i].cs_dmacachep;
65169 else
65170 #endif
65171 +
65172 +#ifdef CONFIG_PAX_USERCOPY_SLABS
65173 + if (flags & GFP_USERCOPY)
65174 + cachep = malloc_sizes[i].cs_usercopycachep;
65175 + else
65176 +#endif
65177 +
65178 cachep = malloc_sizes[i].cs_cachep;
65179
65180 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
65181 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
65182 index 0ec00b3..22b4715 100644
65183 --- a/include/linux/slob_def.h
65184 +++ b/include/linux/slob_def.h
65185 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
65186 return kmem_cache_alloc_node(cachep, flags, -1);
65187 }
65188
65189 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
65190 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65191
65192 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
65193 {
65194 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
65195 return __kmalloc_node(size, flags, -1);
65196 }
65197
65198 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
65199 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
65200 {
65201 return kmalloc(size, flags);
65202 }
65203 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
65204 index df448ad..b99e7f6 100644
65205 --- a/include/linux/slub_def.h
65206 +++ b/include/linux/slub_def.h
65207 @@ -91,7 +91,7 @@ struct kmem_cache {
65208 struct kmem_cache_order_objects max;
65209 struct kmem_cache_order_objects min;
65210 gfp_t allocflags; /* gfp flags to use on each alloc */
65211 - int refcount; /* Refcount for slab cache destroy */
65212 + atomic_t refcount; /* Refcount for slab cache destroy */
65213 void (*ctor)(void *);
65214 int inuse; /* Offset to metadata */
65215 int align; /* Alignment */
65216 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
65217 * Sorry that the following has to be that ugly but some versions of GCC
65218 * have trouble with constant propagation and loops.
65219 */
65220 -static __always_inline int kmalloc_index(size_t size)
65221 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
65222 {
65223 if (!size)
65224 return 0;
65225 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
65226 }
65227
65228 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
65229 -void *__kmalloc(size_t size, gfp_t flags);
65230 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
65231
65232 static __always_inline void *
65233 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
65234 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
65235 }
65236 #endif
65237
65238 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
65239 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
65240 {
65241 unsigned int order = get_order(size);
65242 return kmalloc_order_trace(size, flags, order);
65243 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
65244 }
65245
65246 #ifdef CONFIG_NUMA
65247 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
65248 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65249 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
65250
65251 #ifdef CONFIG_TRACING
65252 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
65253 index de8832d..0147b46 100644
65254 --- a/include/linux/sonet.h
65255 +++ b/include/linux/sonet.h
65256 @@ -61,7 +61,7 @@ struct sonet_stats {
65257 #include <linux/atomic.h>
65258
65259 struct k_sonet_stats {
65260 -#define __HANDLE_ITEM(i) atomic_t i
65261 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
65262 __SONET_ITEMS
65263 #undef __HANDLE_ITEM
65264 };
65265 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
65266 index 523547e..2cb7140 100644
65267 --- a/include/linux/sunrpc/clnt.h
65268 +++ b/include/linux/sunrpc/clnt.h
65269 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
65270 {
65271 switch (sap->sa_family) {
65272 case AF_INET:
65273 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
65274 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
65275 case AF_INET6:
65276 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
65277 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
65278 }
65279 return 0;
65280 }
65281 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
65282 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
65283 const struct sockaddr *src)
65284 {
65285 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
65286 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
65287 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
65288
65289 dsin->sin_family = ssin->sin_family;
65290 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
65291 if (sa->sa_family != AF_INET6)
65292 return 0;
65293
65294 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
65295 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
65296 }
65297
65298 #endif /* __KERNEL__ */
65299 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
65300 index dc0c3cc..8503fb6 100644
65301 --- a/include/linux/sunrpc/sched.h
65302 +++ b/include/linux/sunrpc/sched.h
65303 @@ -106,6 +106,7 @@ struct rpc_call_ops {
65304 void (*rpc_count_stats)(struct rpc_task *, void *);
65305 void (*rpc_release)(void *);
65306 };
65307 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
65308
65309 struct rpc_task_setup {
65310 struct rpc_task *task;
65311 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
65312 index 0b8e3e6..33e0a01 100644
65313 --- a/include/linux/sunrpc/svc_rdma.h
65314 +++ b/include/linux/sunrpc/svc_rdma.h
65315 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
65316 extern unsigned int svcrdma_max_requests;
65317 extern unsigned int svcrdma_max_req_size;
65318
65319 -extern atomic_t rdma_stat_recv;
65320 -extern atomic_t rdma_stat_read;
65321 -extern atomic_t rdma_stat_write;
65322 -extern atomic_t rdma_stat_sq_starve;
65323 -extern atomic_t rdma_stat_rq_starve;
65324 -extern atomic_t rdma_stat_rq_poll;
65325 -extern atomic_t rdma_stat_rq_prod;
65326 -extern atomic_t rdma_stat_sq_poll;
65327 -extern atomic_t rdma_stat_sq_prod;
65328 +extern atomic_unchecked_t rdma_stat_recv;
65329 +extern atomic_unchecked_t rdma_stat_read;
65330 +extern atomic_unchecked_t rdma_stat_write;
65331 +extern atomic_unchecked_t rdma_stat_sq_starve;
65332 +extern atomic_unchecked_t rdma_stat_rq_starve;
65333 +extern atomic_unchecked_t rdma_stat_rq_poll;
65334 +extern atomic_unchecked_t rdma_stat_rq_prod;
65335 +extern atomic_unchecked_t rdma_stat_sq_poll;
65336 +extern atomic_unchecked_t rdma_stat_sq_prod;
65337
65338 #define RPCRDMA_VERSION 1
65339
65340 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
65341 index c34b4c8..a65b67d 100644
65342 --- a/include/linux/sysctl.h
65343 +++ b/include/linux/sysctl.h
65344 @@ -155,7 +155,11 @@ enum
65345 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
65346 };
65347
65348 -
65349 +#ifdef CONFIG_PAX_SOFTMODE
65350 +enum {
65351 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
65352 +};
65353 +#endif
65354
65355 /* CTL_VM names: */
65356 enum
65357 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
65358
65359 extern int proc_dostring(struct ctl_table *, int,
65360 void __user *, size_t *, loff_t *);
65361 +extern int proc_dostring_modpriv(struct ctl_table *, int,
65362 + void __user *, size_t *, loff_t *);
65363 extern int proc_dointvec(struct ctl_table *, int,
65364 void __user *, size_t *, loff_t *);
65365 extern int proc_dointvec_minmax(struct ctl_table *, int,
65366 diff --git a/include/linux/tty.h b/include/linux/tty.h
65367 index 9f47ab5..73da944 100644
65368 --- a/include/linux/tty.h
65369 +++ b/include/linux/tty.h
65370 @@ -225,7 +225,7 @@ struct tty_port {
65371 const struct tty_port_operations *ops; /* Port operations */
65372 spinlock_t lock; /* Lock protecting tty field */
65373 int blocked_open; /* Waiting to open */
65374 - int count; /* Usage count */
65375 + atomic_t count; /* Usage count */
65376 wait_queue_head_t open_wait; /* Open waiters */
65377 wait_queue_head_t close_wait; /* Close waiters */
65378 wait_queue_head_t delta_msr_wait; /* Modem status change */
65379 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
65380 struct tty_struct *tty, struct file *filp);
65381 static inline int tty_port_users(struct tty_port *port)
65382 {
65383 - return port->count + port->blocked_open;
65384 + return atomic_read(&port->count) + port->blocked_open;
65385 }
65386
65387 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
65388 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
65389 index fb79dd8d..07d4773 100644
65390 --- a/include/linux/tty_ldisc.h
65391 +++ b/include/linux/tty_ldisc.h
65392 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
65393
65394 struct module *owner;
65395
65396 - int refcount;
65397 + atomic_t refcount;
65398 };
65399
65400 struct tty_ldisc {
65401 diff --git a/include/linux/types.h b/include/linux/types.h
65402 index bf0dd75..a1f23aaa 100644
65403 --- a/include/linux/types.h
65404 +++ b/include/linux/types.h
65405 @@ -220,10 +220,26 @@ typedef struct {
65406 int counter;
65407 } atomic_t;
65408
65409 +#ifdef CONFIG_PAX_REFCOUNT
65410 +typedef struct {
65411 + int counter;
65412 +} atomic_unchecked_t;
65413 +#else
65414 +typedef atomic_t atomic_unchecked_t;
65415 +#endif
65416 +
65417 #ifdef CONFIG_64BIT
65418 typedef struct {
65419 long counter;
65420 } atomic64_t;
65421 +
65422 +#ifdef CONFIG_PAX_REFCOUNT
65423 +typedef struct {
65424 + long counter;
65425 +} atomic64_unchecked_t;
65426 +#else
65427 +typedef atomic64_t atomic64_unchecked_t;
65428 +#endif
65429 #endif
65430
65431 struct list_head {
65432 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
65433 index 5ca0951..ab496a5 100644
65434 --- a/include/linux/uaccess.h
65435 +++ b/include/linux/uaccess.h
65436 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
65437 long ret; \
65438 mm_segment_t old_fs = get_fs(); \
65439 \
65440 - set_fs(KERNEL_DS); \
65441 pagefault_disable(); \
65442 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65443 - pagefault_enable(); \
65444 + set_fs(KERNEL_DS); \
65445 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
65446 set_fs(old_fs); \
65447 + pagefault_enable(); \
65448 ret; \
65449 })
65450
65451 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
65452 index 99c1b4d..bb94261 100644
65453 --- a/include/linux/unaligned/access_ok.h
65454 +++ b/include/linux/unaligned/access_ok.h
65455 @@ -6,32 +6,32 @@
65456
65457 static inline u16 get_unaligned_le16(const void *p)
65458 {
65459 - return le16_to_cpup((__le16 *)p);
65460 + return le16_to_cpup((const __le16 *)p);
65461 }
65462
65463 static inline u32 get_unaligned_le32(const void *p)
65464 {
65465 - return le32_to_cpup((__le32 *)p);
65466 + return le32_to_cpup((const __le32 *)p);
65467 }
65468
65469 static inline u64 get_unaligned_le64(const void *p)
65470 {
65471 - return le64_to_cpup((__le64 *)p);
65472 + return le64_to_cpup((const __le64 *)p);
65473 }
65474
65475 static inline u16 get_unaligned_be16(const void *p)
65476 {
65477 - return be16_to_cpup((__be16 *)p);
65478 + return be16_to_cpup((const __be16 *)p);
65479 }
65480
65481 static inline u32 get_unaligned_be32(const void *p)
65482 {
65483 - return be32_to_cpup((__be32 *)p);
65484 + return be32_to_cpup((const __be32 *)p);
65485 }
65486
65487 static inline u64 get_unaligned_be64(const void *p)
65488 {
65489 - return be64_to_cpup((__be64 *)p);
65490 + return be64_to_cpup((const __be64 *)p);
65491 }
65492
65493 static inline void put_unaligned_le16(u16 val, void *p)
65494 diff --git a/include/linux/usb.h b/include/linux/usb.h
65495 index 30d1ae3..aecd07e 100644
65496 --- a/include/linux/usb.h
65497 +++ b/include/linux/usb.h
65498 @@ -546,7 +546,7 @@ struct usb_device {
65499 struct usb_device **children;
65500
65501 u32 quirks;
65502 - atomic_t urbnum;
65503 + atomic_unchecked_t urbnum;
65504
65505 unsigned long active_duration;
65506
65507 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
65508 index c5d36c6..8478c90 100644
65509 --- a/include/linux/usb/renesas_usbhs.h
65510 +++ b/include/linux/usb/renesas_usbhs.h
65511 @@ -39,7 +39,7 @@ enum {
65512 */
65513 struct renesas_usbhs_driver_callback {
65514 int (*notify_hotplug)(struct platform_device *pdev);
65515 -};
65516 +} __no_const;
65517
65518 /*
65519 * callback functions for platform
65520 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
65521 * VBUS control is needed for Host
65522 */
65523 int (*set_vbus)(struct platform_device *pdev, int enable);
65524 -};
65525 +} __no_const;
65526
65527 /*
65528 * parameters for renesas usbhs
65529 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
65530 index 6f8fbcf..8259001 100644
65531 --- a/include/linux/vermagic.h
65532 +++ b/include/linux/vermagic.h
65533 @@ -25,9 +25,35 @@
65534 #define MODULE_ARCH_VERMAGIC ""
65535 #endif
65536
65537 +#ifdef CONFIG_PAX_REFCOUNT
65538 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
65539 +#else
65540 +#define MODULE_PAX_REFCOUNT ""
65541 +#endif
65542 +
65543 +#ifdef CONSTIFY_PLUGIN
65544 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
65545 +#else
65546 +#define MODULE_CONSTIFY_PLUGIN ""
65547 +#endif
65548 +
65549 +#ifdef STACKLEAK_PLUGIN
65550 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
65551 +#else
65552 +#define MODULE_STACKLEAK_PLUGIN ""
65553 +#endif
65554 +
65555 +#ifdef CONFIG_GRKERNSEC
65556 +#define MODULE_GRSEC "GRSEC "
65557 +#else
65558 +#define MODULE_GRSEC ""
65559 +#endif
65560 +
65561 #define VERMAGIC_STRING \
65562 UTS_RELEASE " " \
65563 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65564 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65565 - MODULE_ARCH_VERMAGIC
65566 + MODULE_ARCH_VERMAGIC \
65567 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
65568 + MODULE_GRSEC
65569
65570 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65571 index 6071e91..ca6a489 100644
65572 --- a/include/linux/vmalloc.h
65573 +++ b/include/linux/vmalloc.h
65574 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65575 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65576 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65577 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65578 +
65579 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65580 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65581 +#endif
65582 +
65583 /* bits [20..32] reserved for arch specific ioremap internals */
65584
65585 /*
65586 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
65587 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65588 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65589 unsigned long start, unsigned long end, gfp_t gfp_mask,
65590 - pgprot_t prot, int node, const void *caller);
65591 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
65592 extern void vfree(const void *addr);
65593
65594 extern void *vmap(struct page **pages, unsigned int count,
65595 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65596 extern void free_vm_area(struct vm_struct *area);
65597
65598 /* for /dev/kmem */
65599 -extern long vread(char *buf, char *addr, unsigned long count);
65600 -extern long vwrite(char *buf, char *addr, unsigned long count);
65601 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65602 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65603
65604 /*
65605 * Internals. Dont't use..
65606 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65607 index ad2cfd5..74c94ad 100644
65608 --- a/include/linux/vmstat.h
65609 +++ b/include/linux/vmstat.h
65610 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65611 /*
65612 * Zone based page accounting with per cpu differentials.
65613 */
65614 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65615 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65616
65617 static inline void zone_page_state_add(long x, struct zone *zone,
65618 enum zone_stat_item item)
65619 {
65620 - atomic_long_add(x, &zone->vm_stat[item]);
65621 - atomic_long_add(x, &vm_stat[item]);
65622 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65623 + atomic_long_add_unchecked(x, &vm_stat[item]);
65624 }
65625
65626 static inline unsigned long global_page_state(enum zone_stat_item item)
65627 {
65628 - long x = atomic_long_read(&vm_stat[item]);
65629 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65630 #ifdef CONFIG_SMP
65631 if (x < 0)
65632 x = 0;
65633 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65634 static inline unsigned long zone_page_state(struct zone *zone,
65635 enum zone_stat_item item)
65636 {
65637 - long x = atomic_long_read(&zone->vm_stat[item]);
65638 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65639 #ifdef CONFIG_SMP
65640 if (x < 0)
65641 x = 0;
65642 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65643 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65644 enum zone_stat_item item)
65645 {
65646 - long x = atomic_long_read(&zone->vm_stat[item]);
65647 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65648
65649 #ifdef CONFIG_SMP
65650 int cpu;
65651 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65652
65653 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65654 {
65655 - atomic_long_inc(&zone->vm_stat[item]);
65656 - atomic_long_inc(&vm_stat[item]);
65657 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65658 + atomic_long_inc_unchecked(&vm_stat[item]);
65659 }
65660
65661 static inline void __inc_zone_page_state(struct page *page,
65662 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
65663
65664 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65665 {
65666 - atomic_long_dec(&zone->vm_stat[item]);
65667 - atomic_long_dec(&vm_stat[item]);
65668 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65669 + atomic_long_dec_unchecked(&vm_stat[item]);
65670 }
65671
65672 static inline void __dec_zone_page_state(struct page *page,
65673 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65674 index e5d1220..ef6e406 100644
65675 --- a/include/linux/xattr.h
65676 +++ b/include/linux/xattr.h
65677 @@ -57,6 +57,11 @@
65678 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65679 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65680
65681 +/* User namespace */
65682 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65683 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
65684 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65685 +
65686 #ifdef __KERNEL__
65687
65688 #include <linux/types.h>
65689 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65690 index 944ecdf..a3994fc 100644
65691 --- a/include/media/saa7146_vv.h
65692 +++ b/include/media/saa7146_vv.h
65693 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
65694 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65695
65696 /* the extension can override this */
65697 - struct v4l2_ioctl_ops vid_ops;
65698 - struct v4l2_ioctl_ops vbi_ops;
65699 + v4l2_ioctl_ops_no_const vid_ops;
65700 + v4l2_ioctl_ops_no_const vbi_ops;
65701 /* pointer to the saa7146 core ops */
65702 const struct v4l2_ioctl_ops *core_ops;
65703
65704 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65705 index 5c416cd..20021aa 100644
65706 --- a/include/media/v4l2-dev.h
65707 +++ b/include/media/v4l2-dev.h
65708 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
65709 int (*mmap) (struct file *, struct vm_area_struct *);
65710 int (*open) (struct file *);
65711 int (*release) (struct file *);
65712 -};
65713 +} __do_const;
65714 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65715
65716 /*
65717 * Newer version of video_device, handled by videodev2.c
65718 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65719 index e614c9c..20602b7 100644
65720 --- a/include/media/v4l2-ioctl.h
65721 +++ b/include/media/v4l2-ioctl.h
65722 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
65723 long (*vidioc_default) (struct file *file, void *fh,
65724 bool valid_prio, int cmd, void *arg);
65725 };
65726 -
65727 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65728
65729 /* v4l debugging and diagnostics */
65730
65731 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65732 index bcb9cc3..f4ec722e 100644
65733 --- a/include/net/caif/caif_hsi.h
65734 +++ b/include/net/caif/caif_hsi.h
65735 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65736 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65737 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65738 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65739 -};
65740 +} __no_const;
65741
65742 /* Structure implemented by HSI device. */
65743 struct cfhsi_ops {
65744 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65745 index 9e5425b..8136ffc 100644
65746 --- a/include/net/caif/cfctrl.h
65747 +++ b/include/net/caif/cfctrl.h
65748 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65749 void (*radioset_rsp)(void);
65750 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65751 struct cflayer *client_layer);
65752 -};
65753 +} __no_const;
65754
65755 /* Link Setup Parameters for CAIF-Links. */
65756 struct cfctrl_link_param {
65757 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65758 struct cfctrl {
65759 struct cfsrvl serv;
65760 struct cfctrl_rsp res;
65761 - atomic_t req_seq_no;
65762 - atomic_t rsp_seq_no;
65763 + atomic_unchecked_t req_seq_no;
65764 + atomic_unchecked_t rsp_seq_no;
65765 struct list_head list;
65766 /* Protects from simultaneous access to first_req list */
65767 spinlock_t info_list_lock;
65768 diff --git a/include/net/flow.h b/include/net/flow.h
65769 index 628e11b..4c475df 100644
65770 --- a/include/net/flow.h
65771 +++ b/include/net/flow.h
65772 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65773
65774 extern void flow_cache_flush(void);
65775 extern void flow_cache_flush_deferred(void);
65776 -extern atomic_t flow_cache_genid;
65777 +extern atomic_unchecked_t flow_cache_genid;
65778
65779 #endif
65780 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65781 index 53f464d..ba76aaa 100644
65782 --- a/include/net/inetpeer.h
65783 +++ b/include/net/inetpeer.h
65784 @@ -47,8 +47,8 @@ struct inet_peer {
65785 */
65786 union {
65787 struct {
65788 - atomic_t rid; /* Frag reception counter */
65789 - atomic_t ip_id_count; /* IP ID for the next packet */
65790 + atomic_unchecked_t rid; /* Frag reception counter */
65791 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65792 };
65793 struct rcu_head rcu;
65794 struct inet_peer *gc_next;
65795 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65796 more++;
65797 inet_peer_refcheck(p);
65798 do {
65799 - old = atomic_read(&p->ip_id_count);
65800 + old = atomic_read_unchecked(&p->ip_id_count);
65801 new = old + more;
65802 if (!new)
65803 new = 1;
65804 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65805 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65806 return new;
65807 }
65808
65809 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65810 index 9497be1..5a4fafe 100644
65811 --- a/include/net/ip_fib.h
65812 +++ b/include/net/ip_fib.h
65813 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65814
65815 #define FIB_RES_SADDR(net, res) \
65816 ((FIB_RES_NH(res).nh_saddr_genid == \
65817 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65818 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65819 FIB_RES_NH(res).nh_saddr : \
65820 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65821 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65822 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65823 index 95374d1..2300e36 100644
65824 --- a/include/net/ip_vs.h
65825 +++ b/include/net/ip_vs.h
65826 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65827 struct ip_vs_conn *control; /* Master control connection */
65828 atomic_t n_control; /* Number of controlled ones */
65829 struct ip_vs_dest *dest; /* real server */
65830 - atomic_t in_pkts; /* incoming packet counter */
65831 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65832
65833 /* packet transmitter for different forwarding methods. If it
65834 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65835 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65836 __be16 port; /* port number of the server */
65837 union nf_inet_addr addr; /* IP address of the server */
65838 volatile unsigned int flags; /* dest status flags */
65839 - atomic_t conn_flags; /* flags to copy to conn */
65840 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65841 atomic_t weight; /* server weight */
65842
65843 atomic_t refcnt; /* reference counter */
65844 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65845 index 69b610a..fe3962c 100644
65846 --- a/include/net/irda/ircomm_core.h
65847 +++ b/include/net/irda/ircomm_core.h
65848 @@ -51,7 +51,7 @@ typedef struct {
65849 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65850 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65851 struct ircomm_info *);
65852 -} call_t;
65853 +} __no_const call_t;
65854
65855 struct ircomm_cb {
65856 irda_queue_t queue;
65857 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65858 index 59ba38bc..d515662 100644
65859 --- a/include/net/irda/ircomm_tty.h
65860 +++ b/include/net/irda/ircomm_tty.h
65861 @@ -35,6 +35,7 @@
65862 #include <linux/termios.h>
65863 #include <linux/timer.h>
65864 #include <linux/tty.h> /* struct tty_struct */
65865 +#include <asm/local.h>
65866
65867 #include <net/irda/irias_object.h>
65868 #include <net/irda/ircomm_core.h>
65869 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65870 unsigned short close_delay;
65871 unsigned short closing_wait; /* time to wait before closing */
65872
65873 - int open_count;
65874 - int blocked_open; /* # of blocked opens */
65875 + local_t open_count;
65876 + local_t blocked_open; /* # of blocked opens */
65877
65878 /* Protect concurent access to :
65879 * o self->open_count
65880 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65881 index cc7c197..9f2da2a 100644
65882 --- a/include/net/iucv/af_iucv.h
65883 +++ b/include/net/iucv/af_iucv.h
65884 @@ -141,7 +141,7 @@ struct iucv_sock {
65885 struct iucv_sock_list {
65886 struct hlist_head head;
65887 rwlock_t lock;
65888 - atomic_t autobind_name;
65889 + atomic_unchecked_t autobind_name;
65890 };
65891
65892 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65893 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65894 index 344d898..2ae1302 100644
65895 --- a/include/net/neighbour.h
65896 +++ b/include/net/neighbour.h
65897 @@ -123,7 +123,7 @@ struct neigh_ops {
65898 void (*error_report)(struct neighbour *, struct sk_buff *);
65899 int (*output)(struct neighbour *, struct sk_buff *);
65900 int (*connected_output)(struct neighbour *, struct sk_buff *);
65901 -};
65902 +} __do_const;
65903
65904 struct pneigh_entry {
65905 struct pneigh_entry *next;
65906 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65907 index fd87963..312a11f 100644
65908 --- a/include/net/net_namespace.h
65909 +++ b/include/net/net_namespace.h
65910 @@ -102,7 +102,7 @@ struct net {
65911 #endif
65912 struct netns_ipvs *ipvs;
65913 struct sock *diag_nlsk;
65914 - atomic_t rt_genid;
65915 + atomic_unchecked_t rt_genid;
65916 };
65917
65918
65919 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65920
65921 static inline int rt_genid(struct net *net)
65922 {
65923 - return atomic_read(&net->rt_genid);
65924 + return atomic_read_unchecked(&net->rt_genid);
65925 }
65926
65927 static inline void rt_genid_bump(struct net *net)
65928 {
65929 - atomic_inc(&net->rt_genid);
65930 + atomic_inc_unchecked(&net->rt_genid);
65931 }
65932
65933 #endif /* __NET_NET_NAMESPACE_H */
65934 diff --git a/include/net/netdma.h b/include/net/netdma.h
65935 index 8ba8ce2..99b7fff 100644
65936 --- a/include/net/netdma.h
65937 +++ b/include/net/netdma.h
65938 @@ -24,7 +24,7 @@
65939 #include <linux/dmaengine.h>
65940 #include <linux/skbuff.h>
65941
65942 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65943 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65944 struct sk_buff *skb, int offset, struct iovec *to,
65945 size_t len, struct dma_pinned_list *pinned_list);
65946
65947 diff --git a/include/net/netlink.h b/include/net/netlink.h
65948 index 785f37a..c81dc0c 100644
65949 --- a/include/net/netlink.h
65950 +++ b/include/net/netlink.h
65951 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65952 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65953 {
65954 if (mark)
65955 - skb_trim(skb, (unsigned char *) mark - skb->data);
65956 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65957 }
65958
65959 /**
65960 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65961 index eb24dbc..567d6ed 100644
65962 --- a/include/net/netns/ipv4.h
65963 +++ b/include/net/netns/ipv4.h
65964 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65965 unsigned int sysctl_ping_group_range[2];
65966 long sysctl_tcp_mem[3];
65967
65968 - atomic_t dev_addr_genid;
65969 + atomic_unchecked_t dev_addr_genid;
65970
65971 #ifdef CONFIG_IP_MROUTE
65972 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65973 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65974 index ff49964..1411fee 100644
65975 --- a/include/net/sctp/sctp.h
65976 +++ b/include/net/sctp/sctp.h
65977 @@ -320,9 +320,9 @@ do { \
65978
65979 #else /* SCTP_DEBUG */
65980
65981 -#define SCTP_DEBUG_PRINTK(whatever...)
65982 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65983 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65984 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65985 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65986 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65987 #define SCTP_ENABLE_DEBUG
65988 #define SCTP_DISABLE_DEBUG
65989 #define SCTP_ASSERT(expr, str, func)
65990 diff --git a/include/net/sock.h b/include/net/sock.h
65991 index adb7da2..1100002 100644
65992 --- a/include/net/sock.h
65993 +++ b/include/net/sock.h
65994 @@ -305,7 +305,7 @@ struct sock {
65995 #ifdef CONFIG_RPS
65996 __u32 sk_rxhash;
65997 #endif
65998 - atomic_t sk_drops;
65999 + atomic_unchecked_t sk_drops;
66000 int sk_rcvbuf;
66001
66002 struct sk_filter __rcu *sk_filter;
66003 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
66004 }
66005
66006 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
66007 - char __user *from, char *to,
66008 + char __user *from, unsigned char *to,
66009 int copy, int offset)
66010 {
66011 if (skb->ip_summed == CHECKSUM_NONE) {
66012 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
66013 }
66014 }
66015
66016 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
66017 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
66018
66019 static inline struct page *sk_stream_alloc_page(struct sock *sk)
66020 {
66021 diff --git a/include/net/tcp.h b/include/net/tcp.h
66022 index 1f000ff..e5a8dfb 100644
66023 --- a/include/net/tcp.h
66024 +++ b/include/net/tcp.h
66025 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
66026 extern void tcp_xmit_retransmit_queue(struct sock *);
66027 extern void tcp_simple_retransmit(struct sock *);
66028 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
66029 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
66030 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
66031
66032 extern void tcp_send_probe0(struct sock *);
66033 extern void tcp_send_partial(struct sock *);
66034 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
66035 struct inet6_skb_parm h6;
66036 #endif
66037 } header; /* For incoming frames */
66038 - __u32 seq; /* Starting sequence number */
66039 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
66040 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
66041 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
66042 __u32 when; /* used to compute rtt's */
66043 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
66044
66045 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
66046
66047 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
66048 /* 1 byte hole */
66049 - __u32 ack_seq; /* Sequence number ACK'd */
66050 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
66051 };
66052
66053 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
66054 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
66055 char *name;
66056 sa_family_t family;
66057 const struct file_operations *seq_fops;
66058 - struct seq_operations seq_ops;
66059 + seq_operations_no_const seq_ops;
66060 };
66061
66062 struct tcp_iter_state {
66063 diff --git a/include/net/udp.h b/include/net/udp.h
66064 index 065f379..b661b40 100644
66065 --- a/include/net/udp.h
66066 +++ b/include/net/udp.h
66067 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
66068 sa_family_t family;
66069 struct udp_table *udp_table;
66070 const struct file_operations *seq_fops;
66071 - struct seq_operations seq_ops;
66072 + seq_operations_no_const seq_ops;
66073 };
66074
66075 struct udp_iter_state {
66076 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
66077 index 639dd13..15b206c 100644
66078 --- a/include/net/xfrm.h
66079 +++ b/include/net/xfrm.h
66080 @@ -514,7 +514,7 @@ struct xfrm_policy {
66081 struct timer_list timer;
66082
66083 struct flow_cache_object flo;
66084 - atomic_t genid;
66085 + atomic_unchecked_t genid;
66086 u32 priority;
66087 u32 index;
66088 struct xfrm_mark mark;
66089 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
66090 index 1a046b1..ee0bef0 100644
66091 --- a/include/rdma/iw_cm.h
66092 +++ b/include/rdma/iw_cm.h
66093 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
66094 int backlog);
66095
66096 int (*destroy_listen)(struct iw_cm_id *cm_id);
66097 -};
66098 +} __no_const;
66099
66100 /**
66101 * iw_create_cm_id - Create an IW CM identifier.
66102 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
66103 index 399162b..b337f1a 100644
66104 --- a/include/scsi/libfc.h
66105 +++ b/include/scsi/libfc.h
66106 @@ -762,6 +762,7 @@ struct libfc_function_template {
66107 */
66108 void (*disc_stop_final) (struct fc_lport *);
66109 };
66110 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
66111
66112 /**
66113 * struct fc_disc - Discovery context
66114 @@ -866,7 +867,7 @@ struct fc_lport {
66115 struct fc_vport *vport;
66116
66117 /* Operational Information */
66118 - struct libfc_function_template tt;
66119 + libfc_function_template_no_const tt;
66120 u8 link_up;
66121 u8 qfull;
66122 enum fc_lport_state state;
66123 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
66124 index 9895f69..f1418f0 100644
66125 --- a/include/scsi/scsi_device.h
66126 +++ b/include/scsi/scsi_device.h
66127 @@ -166,9 +166,9 @@ struct scsi_device {
66128 unsigned int max_device_blocked; /* what device_blocked counts down from */
66129 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
66130
66131 - atomic_t iorequest_cnt;
66132 - atomic_t iodone_cnt;
66133 - atomic_t ioerr_cnt;
66134 + atomic_unchecked_t iorequest_cnt;
66135 + atomic_unchecked_t iodone_cnt;
66136 + atomic_unchecked_t ioerr_cnt;
66137
66138 struct device sdev_gendev,
66139 sdev_dev;
66140 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
66141 index b797e8f..8e2c3aa 100644
66142 --- a/include/scsi/scsi_transport_fc.h
66143 +++ b/include/scsi/scsi_transport_fc.h
66144 @@ -751,7 +751,8 @@ struct fc_function_template {
66145 unsigned long show_host_system_hostname:1;
66146
66147 unsigned long disable_target_scan:1;
66148 -};
66149 +} __do_const;
66150 +typedef struct fc_function_template __no_const fc_function_template_no_const;
66151
66152
66153 /**
66154 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
66155 index 030b87c..98a6954 100644
66156 --- a/include/sound/ak4xxx-adda.h
66157 +++ b/include/sound/ak4xxx-adda.h
66158 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
66159 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
66160 unsigned char val);
66161 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
66162 -};
66163 +} __no_const;
66164
66165 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
66166
66167 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
66168 index 8c05e47..2b5df97 100644
66169 --- a/include/sound/hwdep.h
66170 +++ b/include/sound/hwdep.h
66171 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
66172 struct snd_hwdep_dsp_status *status);
66173 int (*dsp_load)(struct snd_hwdep *hw,
66174 struct snd_hwdep_dsp_image *image);
66175 -};
66176 +} __no_const;
66177
66178 struct snd_hwdep {
66179 struct snd_card *card;
66180 diff --git a/include/sound/info.h b/include/sound/info.h
66181 index 9ca1a49..aba1728 100644
66182 --- a/include/sound/info.h
66183 +++ b/include/sound/info.h
66184 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
66185 struct snd_info_buffer *buffer);
66186 void (*write)(struct snd_info_entry *entry,
66187 struct snd_info_buffer *buffer);
66188 -};
66189 +} __no_const;
66190
66191 struct snd_info_entry_ops {
66192 int (*open)(struct snd_info_entry *entry,
66193 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
66194 index cdca2ab..10bbe05 100644
66195 --- a/include/sound/pcm.h
66196 +++ b/include/sound/pcm.h
66197 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
66198 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
66199 int (*ack)(struct snd_pcm_substream *substream);
66200 };
66201 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
66202
66203 /*
66204 *
66205 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
66206 index af1b49e..a5d55a5 100644
66207 --- a/include/sound/sb16_csp.h
66208 +++ b/include/sound/sb16_csp.h
66209 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
66210 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
66211 int (*csp_stop) (struct snd_sb_csp * p);
66212 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
66213 -};
66214 +} __no_const;
66215
66216 /*
66217 * CSP private data
66218 diff --git a/include/sound/soc.h b/include/sound/soc.h
66219 index e063380..e8077d5 100644
66220 --- a/include/sound/soc.h
66221 +++ b/include/sound/soc.h
66222 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
66223 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
66224 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
66225 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
66226 -};
66227 +} __do_const;
66228
66229 struct snd_soc_platform {
66230 const char *name;
66231 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
66232 struct snd_soc_dai_link *dai_link;
66233 struct mutex pcm_mutex;
66234 enum snd_soc_pcm_subclass pcm_subclass;
66235 - struct snd_pcm_ops ops;
66236 + snd_pcm_ops_no_const ops;
66237
66238 unsigned int dev_registered:1;
66239
66240 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
66241 index fe8590c..aaed363 100644
66242 --- a/include/sound/tea575x-tuner.h
66243 +++ b/include/sound/tea575x-tuner.h
66244 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
66245
66246 struct snd_tea575x {
66247 struct v4l2_device *v4l2_dev;
66248 - struct v4l2_file_operations fops;
66249 + v4l2_file_operations_no_const fops;
66250 struct video_device vd; /* video device */
66251 int radio_nr; /* radio_nr */
66252 bool tea5759; /* 5759 chip is present */
66253 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
66254 index 5be8937..a8e46e9 100644
66255 --- a/include/target/target_core_base.h
66256 +++ b/include/target/target_core_base.h
66257 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
66258 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
66259 int (*t10_pr_register)(struct se_cmd *);
66260 int (*t10_pr_clear)(struct se_cmd *);
66261 -};
66262 +} __no_const;
66263
66264 struct t10_reservation {
66265 /* Reservation effects all target ports */
66266 @@ -758,7 +758,7 @@ struct se_device {
66267 spinlock_t stats_lock;
66268 /* Active commands on this virtual SE device */
66269 atomic_t simple_cmds;
66270 - atomic_t dev_ordered_id;
66271 + atomic_unchecked_t dev_ordered_id;
66272 atomic_t dev_ordered_sync;
66273 atomic_t dev_qf_count;
66274 struct se_obj dev_obj;
66275 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
66276 new file mode 100644
66277 index 0000000..2efe49d
66278 --- /dev/null
66279 +++ b/include/trace/events/fs.h
66280 @@ -0,0 +1,53 @@
66281 +#undef TRACE_SYSTEM
66282 +#define TRACE_SYSTEM fs
66283 +
66284 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
66285 +#define _TRACE_FS_H
66286 +
66287 +#include <linux/fs.h>
66288 +#include <linux/tracepoint.h>
66289 +
66290 +TRACE_EVENT(do_sys_open,
66291 +
66292 + TP_PROTO(char *filename, int flags, int mode),
66293 +
66294 + TP_ARGS(filename, flags, mode),
66295 +
66296 + TP_STRUCT__entry(
66297 + __string( filename, filename )
66298 + __field( int, flags )
66299 + __field( int, mode )
66300 + ),
66301 +
66302 + TP_fast_assign(
66303 + __assign_str(filename, filename);
66304 + __entry->flags = flags;
66305 + __entry->mode = mode;
66306 + ),
66307 +
66308 + TP_printk("\"%s\" %x %o",
66309 + __get_str(filename), __entry->flags, __entry->mode)
66310 +);
66311 +
66312 +TRACE_EVENT(open_exec,
66313 +
66314 + TP_PROTO(const char *filename),
66315 +
66316 + TP_ARGS(filename),
66317 +
66318 + TP_STRUCT__entry(
66319 + __string( filename, filename )
66320 + ),
66321 +
66322 + TP_fast_assign(
66323 + __assign_str(filename, filename);
66324 + ),
66325 +
66326 + TP_printk("\"%s\"",
66327 + __get_str(filename))
66328 +);
66329 +
66330 +#endif /* _TRACE_FS_H */
66331 +
66332 +/* This part must be outside protection */
66333 +#include <trace/define_trace.h>
66334 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
66335 index 1c09820..7f5ec79 100644
66336 --- a/include/trace/events/irq.h
66337 +++ b/include/trace/events/irq.h
66338 @@ -36,7 +36,7 @@ struct softirq_action;
66339 */
66340 TRACE_EVENT(irq_handler_entry,
66341
66342 - TP_PROTO(int irq, struct irqaction *action),
66343 + TP_PROTO(int irq, const struct irqaction *action),
66344
66345 TP_ARGS(irq, action),
66346
66347 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
66348 */
66349 TRACE_EVENT(irq_handler_exit,
66350
66351 - TP_PROTO(int irq, struct irqaction *action, int ret),
66352 + TP_PROTO(int irq, const struct irqaction *action, int ret),
66353
66354 TP_ARGS(irq, action, ret),
66355
66356 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
66357 index f9466fa..f4e2b81 100644
66358 --- a/include/video/udlfb.h
66359 +++ b/include/video/udlfb.h
66360 @@ -53,10 +53,10 @@ struct dlfb_data {
66361 u32 pseudo_palette[256];
66362 int blank_mode; /*one of FB_BLANK_ */
66363 /* blit-only rendering path metrics, exposed through sysfs */
66364 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66365 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
66366 - atomic_t bytes_sent; /* to usb, after compression including overhead */
66367 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
66368 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66369 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
66370 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
66371 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
66372 };
66373
66374 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
66375 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
66376 index 0993a22..32ba2fe 100644
66377 --- a/include/video/uvesafb.h
66378 +++ b/include/video/uvesafb.h
66379 @@ -177,6 +177,7 @@ struct uvesafb_par {
66380 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
66381 u8 pmi_setpal; /* PMI for palette changes */
66382 u16 *pmi_base; /* protected mode interface location */
66383 + u8 *pmi_code; /* protected mode code location */
66384 void *pmi_start;
66385 void *pmi_pal;
66386 u8 *vbe_state_orig; /*
66387 diff --git a/init/Kconfig b/init/Kconfig
66388 index af6c7f8..5c188f8 100644
66389 --- a/init/Kconfig
66390 +++ b/init/Kconfig
66391 @@ -850,6 +850,7 @@ endif # CGROUPS
66392
66393 config CHECKPOINT_RESTORE
66394 bool "Checkpoint/restore support" if EXPERT
66395 + depends on !GRKERNSEC
66396 default n
66397 help
66398 Enables additional kernel features in a sake of checkpoint/restore.
66399 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
66400 # Security modules
66401 depends on SECURITY_TOMOYO = n
66402 depends on SECURITY_APPARMOR = n
66403 + depends on GRKERNSEC = n
66404
66405 config UIDGID_STRICT_TYPE_CHECKS
66406 bool "Require conversions between uid/gids and their internal representation"
66407 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
66408
66409 config COMPAT_BRK
66410 bool "Disable heap randomization"
66411 - default y
66412 + default n
66413 help
66414 Randomizing heap placement makes heap exploits harder, but it
66415 also breaks ancient binaries (including anything libc5 based).
66416 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
66417 config STOP_MACHINE
66418 bool
66419 default y
66420 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
66421 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
66422 help
66423 Need stop_machine() primitive.
66424
66425 diff --git a/init/Makefile b/init/Makefile
66426 index 7bc47ee..6da2dc7 100644
66427 --- a/init/Makefile
66428 +++ b/init/Makefile
66429 @@ -2,6 +2,9 @@
66430 # Makefile for the linux kernel.
66431 #
66432
66433 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
66434 +asflags-y := $(GCC_PLUGINS_AFLAGS)
66435 +
66436 obj-y := main.o version.o mounts.o
66437 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
66438 obj-y += noinitramfs.o
66439 diff --git a/init/do_mounts.c b/init/do_mounts.c
66440 index d3f0aee..c9322f5 100644
66441 --- a/init/do_mounts.c
66442 +++ b/init/do_mounts.c
66443 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
66444 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66445 {
66446 struct super_block *s;
66447 - int err = sys_mount(name, "/root", fs, flags, data);
66448 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
66449 if (err)
66450 return err;
66451
66452 - sys_chdir("/root");
66453 + sys_chdir((const char __force_user *)"/root");
66454 s = current->fs->pwd.dentry->d_sb;
66455 ROOT_DEV = s->s_dev;
66456 printk(KERN_INFO
66457 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
66458 va_start(args, fmt);
66459 vsprintf(buf, fmt, args);
66460 va_end(args);
66461 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66462 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66463 if (fd >= 0) {
66464 sys_ioctl(fd, FDEJECT, 0);
66465 sys_close(fd);
66466 }
66467 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66468 - fd = sys_open("/dev/console", O_RDWR, 0);
66469 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66470 if (fd >= 0) {
66471 sys_ioctl(fd, TCGETS, (long)&termios);
66472 termios.c_lflag &= ~ICANON;
66473 sys_ioctl(fd, TCSETSF, (long)&termios);
66474 - sys_read(fd, &c, 1);
66475 + sys_read(fd, (char __user *)&c, 1);
66476 termios.c_lflag |= ICANON;
66477 sys_ioctl(fd, TCSETSF, (long)&termios);
66478 sys_close(fd);
66479 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
66480 mount_root();
66481 out:
66482 devtmpfs_mount("dev");
66483 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66484 - sys_chroot(".");
66485 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66486 + sys_chroot((const char __force_user *)".");
66487 }
66488 diff --git a/init/do_mounts.h b/init/do_mounts.h
66489 index f5b978a..69dbfe8 100644
66490 --- a/init/do_mounts.h
66491 +++ b/init/do_mounts.h
66492 @@ -15,15 +15,15 @@ extern int root_mountflags;
66493
66494 static inline int create_dev(char *name, dev_t dev)
66495 {
66496 - sys_unlink(name);
66497 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66498 + sys_unlink((char __force_user *)name);
66499 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
66500 }
66501
66502 #if BITS_PER_LONG == 32
66503 static inline u32 bstat(char *name)
66504 {
66505 struct stat64 stat;
66506 - if (sys_stat64(name, &stat) != 0)
66507 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
66508 return 0;
66509 if (!S_ISBLK(stat.st_mode))
66510 return 0;
66511 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
66512 static inline u32 bstat(char *name)
66513 {
66514 struct stat stat;
66515 - if (sys_newstat(name, &stat) != 0)
66516 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
66517 return 0;
66518 if (!S_ISBLK(stat.st_mode))
66519 return 0;
66520 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
66521 index 135959a2..28a3f43 100644
66522 --- a/init/do_mounts_initrd.c
66523 +++ b/init/do_mounts_initrd.c
66524 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
66525 create_dev("/dev/root.old", Root_RAM0);
66526 /* mount initrd on rootfs' /root */
66527 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66528 - sys_mkdir("/old", 0700);
66529 - root_fd = sys_open("/", 0, 0);
66530 - old_fd = sys_open("/old", 0, 0);
66531 + sys_mkdir((const char __force_user *)"/old", 0700);
66532 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
66533 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
66534 /* move initrd over / and chdir/chroot in initrd root */
66535 - sys_chdir("/root");
66536 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66537 - sys_chroot(".");
66538 + sys_chdir((const char __force_user *)"/root");
66539 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66540 + sys_chroot((const char __force_user *)".");
66541
66542 /*
66543 * In case that a resume from disk is carried out by linuxrc or one of
66544 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
66545
66546 /* move initrd to rootfs' /old */
66547 sys_fchdir(old_fd);
66548 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
66549 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
66550 /* switch root and cwd back to / of rootfs */
66551 sys_fchdir(root_fd);
66552 - sys_chroot(".");
66553 + sys_chroot((const char __force_user *)".");
66554 sys_close(old_fd);
66555 sys_close(root_fd);
66556
66557 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66558 - sys_chdir("/old");
66559 + sys_chdir((const char __force_user *)"/old");
66560 return;
66561 }
66562
66563 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
66564 mount_root();
66565
66566 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66567 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66568 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66569 if (!error)
66570 printk("okay\n");
66571 else {
66572 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66573 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66574 if (error == -ENOENT)
66575 printk("/initrd does not exist. Ignored.\n");
66576 else
66577 printk("failed\n");
66578 printk(KERN_NOTICE "Unmounting old root\n");
66579 - sys_umount("/old", MNT_DETACH);
66580 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66581 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66582 if (fd < 0) {
66583 error = fd;
66584 @@ -125,11 +125,11 @@ int __init initrd_load(void)
66585 * mounted in the normal path.
66586 */
66587 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66588 - sys_unlink("/initrd.image");
66589 + sys_unlink((const char __force_user *)"/initrd.image");
66590 handle_initrd();
66591 return 1;
66592 }
66593 }
66594 - sys_unlink("/initrd.image");
66595 + sys_unlink((const char __force_user *)"/initrd.image");
66596 return 0;
66597 }
66598 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66599 index 8cb6db5..d729f50 100644
66600 --- a/init/do_mounts_md.c
66601 +++ b/init/do_mounts_md.c
66602 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66603 partitioned ? "_d" : "", minor,
66604 md_setup_args[ent].device_names);
66605
66606 - fd = sys_open(name, 0, 0);
66607 + fd = sys_open((char __force_user *)name, 0, 0);
66608 if (fd < 0) {
66609 printk(KERN_ERR "md: open failed - cannot start "
66610 "array %s\n", name);
66611 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66612 * array without it
66613 */
66614 sys_close(fd);
66615 - fd = sys_open(name, 0, 0);
66616 + fd = sys_open((char __force_user *)name, 0, 0);
66617 sys_ioctl(fd, BLKRRPART, 0);
66618 }
66619 sys_close(fd);
66620 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66621
66622 wait_for_device_probe();
66623
66624 - fd = sys_open("/dev/md0", 0, 0);
66625 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66626 if (fd >= 0) {
66627 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66628 sys_close(fd);
66629 diff --git a/init/init_task.c b/init/init_task.c
66630 index 8b2f399..f0797c9 100644
66631 --- a/init/init_task.c
66632 +++ b/init/init_task.c
66633 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66634 * Initial thread structure. Alignment of this is handled by a special
66635 * linker map entry.
66636 */
66637 +#ifdef CONFIG_X86
66638 +union thread_union init_thread_union __init_task_data;
66639 +#else
66640 union thread_union init_thread_union __init_task_data =
66641 { INIT_THREAD_INFO(init_task) };
66642 +#endif
66643 diff --git a/init/initramfs.c b/init/initramfs.c
66644 index 84c6bf1..8899338 100644
66645 --- a/init/initramfs.c
66646 +++ b/init/initramfs.c
66647 @@ -84,7 +84,7 @@ static void __init free_hash(void)
66648 }
66649 }
66650
66651 -static long __init do_utime(char *filename, time_t mtime)
66652 +static long __init do_utime(char __force_user *filename, time_t mtime)
66653 {
66654 struct timespec t[2];
66655
66656 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
66657 struct dir_entry *de, *tmp;
66658 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66659 list_del(&de->list);
66660 - do_utime(de->name, de->mtime);
66661 + do_utime((char __force_user *)de->name, de->mtime);
66662 kfree(de->name);
66663 kfree(de);
66664 }
66665 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
66666 if (nlink >= 2) {
66667 char *old = find_link(major, minor, ino, mode, collected);
66668 if (old)
66669 - return (sys_link(old, collected) < 0) ? -1 : 1;
66670 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66671 }
66672 return 0;
66673 }
66674 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66675 {
66676 struct stat st;
66677
66678 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66679 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66680 if (S_ISDIR(st.st_mode))
66681 - sys_rmdir(path);
66682 + sys_rmdir((char __force_user *)path);
66683 else
66684 - sys_unlink(path);
66685 + sys_unlink((char __force_user *)path);
66686 }
66687 }
66688
66689 @@ -315,7 +315,7 @@ static int __init do_name(void)
66690 int openflags = O_WRONLY|O_CREAT;
66691 if (ml != 1)
66692 openflags |= O_TRUNC;
66693 - wfd = sys_open(collected, openflags, mode);
66694 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66695
66696 if (wfd >= 0) {
66697 sys_fchown(wfd, uid, gid);
66698 @@ -327,17 +327,17 @@ static int __init do_name(void)
66699 }
66700 }
66701 } else if (S_ISDIR(mode)) {
66702 - sys_mkdir(collected, mode);
66703 - sys_chown(collected, uid, gid);
66704 - sys_chmod(collected, mode);
66705 + sys_mkdir((char __force_user *)collected, mode);
66706 + sys_chown((char __force_user *)collected, uid, gid);
66707 + sys_chmod((char __force_user *)collected, mode);
66708 dir_add(collected, mtime);
66709 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66710 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66711 if (maybe_link() == 0) {
66712 - sys_mknod(collected, mode, rdev);
66713 - sys_chown(collected, uid, gid);
66714 - sys_chmod(collected, mode);
66715 - do_utime(collected, mtime);
66716 + sys_mknod((char __force_user *)collected, mode, rdev);
66717 + sys_chown((char __force_user *)collected, uid, gid);
66718 + sys_chmod((char __force_user *)collected, mode);
66719 + do_utime((char __force_user *)collected, mtime);
66720 }
66721 }
66722 return 0;
66723 @@ -346,15 +346,15 @@ static int __init do_name(void)
66724 static int __init do_copy(void)
66725 {
66726 if (count >= body_len) {
66727 - sys_write(wfd, victim, body_len);
66728 + sys_write(wfd, (char __force_user *)victim, body_len);
66729 sys_close(wfd);
66730 - do_utime(vcollected, mtime);
66731 + do_utime((char __force_user *)vcollected, mtime);
66732 kfree(vcollected);
66733 eat(body_len);
66734 state = SkipIt;
66735 return 0;
66736 } else {
66737 - sys_write(wfd, victim, count);
66738 + sys_write(wfd, (char __force_user *)victim, count);
66739 body_len -= count;
66740 eat(count);
66741 return 1;
66742 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66743 {
66744 collected[N_ALIGN(name_len) + body_len] = '\0';
66745 clean_path(collected, 0);
66746 - sys_symlink(collected + N_ALIGN(name_len), collected);
66747 - sys_lchown(collected, uid, gid);
66748 - do_utime(collected, mtime);
66749 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66750 + sys_lchown((char __force_user *)collected, uid, gid);
66751 + do_utime((char __force_user *)collected, mtime);
66752 state = SkipIt;
66753 next_state = Reset;
66754 return 0;
66755 diff --git a/init/main.c b/init/main.c
66756 index d61ec54..bd3144f 100644
66757 --- a/init/main.c
66758 +++ b/init/main.c
66759 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66760 extern void tc_init(void);
66761 #endif
66762
66763 +extern void grsecurity_init(void);
66764 +
66765 /*
66766 * Debug helper: via this flag we know that we are in 'early bootup code'
66767 * where only the boot processor is running with IRQ disabled. This means
66768 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66769
66770 __setup("reset_devices", set_reset_devices);
66771
66772 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66773 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66774 +static int __init setup_grsec_proc_gid(char *str)
66775 +{
66776 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66777 + return 1;
66778 +}
66779 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66780 +#endif
66781 +
66782 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66783 +extern char pax_enter_kernel_user[];
66784 +extern char pax_exit_kernel_user[];
66785 +extern pgdval_t clone_pgd_mask;
66786 +#endif
66787 +
66788 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66789 +static int __init setup_pax_nouderef(char *str)
66790 +{
66791 +#ifdef CONFIG_X86_32
66792 + unsigned int cpu;
66793 + struct desc_struct *gdt;
66794 +
66795 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66796 + gdt = get_cpu_gdt_table(cpu);
66797 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66798 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66799 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66800 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66801 + }
66802 + loadsegment(ds, __KERNEL_DS);
66803 + loadsegment(es, __KERNEL_DS);
66804 + loadsegment(ss, __KERNEL_DS);
66805 +#else
66806 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66807 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66808 + clone_pgd_mask = ~(pgdval_t)0UL;
66809 +#endif
66810 +
66811 + return 0;
66812 +}
66813 +early_param("pax_nouderef", setup_pax_nouderef);
66814 +#endif
66815 +
66816 +#ifdef CONFIG_PAX_SOFTMODE
66817 +int pax_softmode;
66818 +
66819 +static int __init setup_pax_softmode(char *str)
66820 +{
66821 + get_option(&str, &pax_softmode);
66822 + return 1;
66823 +}
66824 +__setup("pax_softmode=", setup_pax_softmode);
66825 +#endif
66826 +
66827 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66828 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66829 static const char *panic_later, *panic_param;
66830 @@ -678,6 +735,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66831 {
66832 int count = preempt_count();
66833 int ret;
66834 + const char *msg1 = "", *msg2 = "";
66835
66836 if (initcall_debug)
66837 ret = do_one_initcall_debug(fn);
66838 @@ -690,15 +748,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66839 sprintf(msgbuf, "error code %d ", ret);
66840
66841 if (preempt_count() != count) {
66842 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66843 + msg1 = " preemption imbalance";
66844 preempt_count() = count;
66845 }
66846 if (irqs_disabled()) {
66847 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66848 + msg2 = " disabled interrupts";
66849 local_irq_enable();
66850 }
66851 - if (msgbuf[0]) {
66852 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66853 + if (msgbuf[0] || *msg1 || *msg2) {
66854 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66855 }
66856
66857 return ret;
66858 @@ -752,8 +810,14 @@ static void __init do_initcall_level(int level)
66859 level, level,
66860 &repair_env_string);
66861
66862 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66863 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66864 do_one_initcall(*fn);
66865 +
66866 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66867 + transfer_latent_entropy();
66868 +#endif
66869 +
66870 + }
66871 }
66872
66873 static void __init do_initcalls(void)
66874 @@ -787,8 +851,14 @@ static void __init do_pre_smp_initcalls(void)
66875 {
66876 initcall_t *fn;
66877
66878 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66879 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66880 do_one_initcall(*fn);
66881 +
66882 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66883 + transfer_latent_entropy();
66884 +#endif
66885 +
66886 + }
66887 }
66888
66889 static void run_init_process(const char *init_filename)
66890 @@ -870,7 +940,7 @@ static int __init kernel_init(void * unused)
66891 do_basic_setup();
66892
66893 /* Open the /dev/console on the rootfs, this should never fail */
66894 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66895 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66896 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66897
66898 (void) sys_dup(0);
66899 @@ -883,11 +953,13 @@ static int __init kernel_init(void * unused)
66900 if (!ramdisk_execute_command)
66901 ramdisk_execute_command = "/init";
66902
66903 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66904 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66905 ramdisk_execute_command = NULL;
66906 prepare_namespace();
66907 }
66908
66909 + grsecurity_init();
66910 +
66911 /*
66912 * Ok, we have completed the initial bootup, and
66913 * we're essentially up and running. Get rid of the
66914 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66915 index 9a08acc..e65ebe7 100644
66916 --- a/ipc/mqueue.c
66917 +++ b/ipc/mqueue.c
66918 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66919 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66920 info->attr.mq_msgsize);
66921
66922 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66923 spin_lock(&mq_lock);
66924 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66925 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66926 diff --git a/ipc/msg.c b/ipc/msg.c
66927 index 7385de2..a8180e08 100644
66928 --- a/ipc/msg.c
66929 +++ b/ipc/msg.c
66930 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66931 return security_msg_queue_associate(msq, msgflg);
66932 }
66933
66934 +static struct ipc_ops msg_ops = {
66935 + .getnew = newque,
66936 + .associate = msg_security,
66937 + .more_checks = NULL
66938 +};
66939 +
66940 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66941 {
66942 struct ipc_namespace *ns;
66943 - struct ipc_ops msg_ops;
66944 struct ipc_params msg_params;
66945
66946 ns = current->nsproxy->ipc_ns;
66947
66948 - msg_ops.getnew = newque;
66949 - msg_ops.associate = msg_security;
66950 - msg_ops.more_checks = NULL;
66951 -
66952 msg_params.key = key;
66953 msg_params.flg = msgflg;
66954
66955 diff --git a/ipc/sem.c b/ipc/sem.c
66956 index 5215a81..cfc0cac 100644
66957 --- a/ipc/sem.c
66958 +++ b/ipc/sem.c
66959 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66960 return 0;
66961 }
66962
66963 +static struct ipc_ops sem_ops = {
66964 + .getnew = newary,
66965 + .associate = sem_security,
66966 + .more_checks = sem_more_checks
66967 +};
66968 +
66969 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66970 {
66971 struct ipc_namespace *ns;
66972 - struct ipc_ops sem_ops;
66973 struct ipc_params sem_params;
66974
66975 ns = current->nsproxy->ipc_ns;
66976 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66977 if (nsems < 0 || nsems > ns->sc_semmsl)
66978 return -EINVAL;
66979
66980 - sem_ops.getnew = newary;
66981 - sem_ops.associate = sem_security;
66982 - sem_ops.more_checks = sem_more_checks;
66983 -
66984 sem_params.key = key;
66985 sem_params.flg = semflg;
66986 sem_params.u.nsems = nsems;
66987 diff --git a/ipc/shm.c b/ipc/shm.c
66988 index 00faa05..7040960 100644
66989 --- a/ipc/shm.c
66990 +++ b/ipc/shm.c
66991 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66992 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66993 #endif
66994
66995 +#ifdef CONFIG_GRKERNSEC
66996 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66997 + const time_t shm_createtime, const uid_t cuid,
66998 + const int shmid);
66999 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
67000 + const time_t shm_createtime);
67001 +#endif
67002 +
67003 void shm_init_ns(struct ipc_namespace *ns)
67004 {
67005 ns->shm_ctlmax = SHMMAX;
67006 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
67007 shp->shm_lprid = 0;
67008 shp->shm_atim = shp->shm_dtim = 0;
67009 shp->shm_ctim = get_seconds();
67010 +#ifdef CONFIG_GRKERNSEC
67011 + {
67012 + struct timespec timeval;
67013 + do_posix_clock_monotonic_gettime(&timeval);
67014 +
67015 + shp->shm_createtime = timeval.tv_sec;
67016 + }
67017 +#endif
67018 shp->shm_segsz = size;
67019 shp->shm_nattch = 0;
67020 shp->shm_file = file;
67021 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
67022 return 0;
67023 }
67024
67025 +static struct ipc_ops shm_ops = {
67026 + .getnew = newseg,
67027 + .associate = shm_security,
67028 + .more_checks = shm_more_checks
67029 +};
67030 +
67031 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
67032 {
67033 struct ipc_namespace *ns;
67034 - struct ipc_ops shm_ops;
67035 struct ipc_params shm_params;
67036
67037 ns = current->nsproxy->ipc_ns;
67038
67039 - shm_ops.getnew = newseg;
67040 - shm_ops.associate = shm_security;
67041 - shm_ops.more_checks = shm_more_checks;
67042 -
67043 shm_params.key = key;
67044 shm_params.flg = shmflg;
67045 shm_params.u.size = size;
67046 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
67047 f_mode = FMODE_READ | FMODE_WRITE;
67048 }
67049 if (shmflg & SHM_EXEC) {
67050 +
67051 +#ifdef CONFIG_PAX_MPROTECT
67052 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
67053 + goto out;
67054 +#endif
67055 +
67056 prot |= PROT_EXEC;
67057 acc_mode |= S_IXUGO;
67058 }
67059 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
67060 if (err)
67061 goto out_unlock;
67062
67063 +#ifdef CONFIG_GRKERNSEC
67064 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
67065 + shp->shm_perm.cuid, shmid) ||
67066 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
67067 + err = -EACCES;
67068 + goto out_unlock;
67069 + }
67070 +#endif
67071 +
67072 path = shp->shm_file->f_path;
67073 path_get(&path);
67074 shp->shm_nattch++;
67075 +#ifdef CONFIG_GRKERNSEC
67076 + shp->shm_lapid = current->pid;
67077 +#endif
67078 size = i_size_read(path.dentry->d_inode);
67079 shm_unlock(shp);
67080
67081 diff --git a/kernel/acct.c b/kernel/acct.c
67082 index 02e6167..54824f7 100644
67083 --- a/kernel/acct.c
67084 +++ b/kernel/acct.c
67085 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
67086 */
67087 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
67088 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
67089 - file->f_op->write(file, (char *)&ac,
67090 + file->f_op->write(file, (char __force_user *)&ac,
67091 sizeof(acct_t), &file->f_pos);
67092 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
67093 set_fs(fs);
67094 diff --git a/kernel/audit.c b/kernel/audit.c
67095 index a8c84be..8bd034c 100644
67096 --- a/kernel/audit.c
67097 +++ b/kernel/audit.c
67098 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
67099 3) suppressed due to audit_rate_limit
67100 4) suppressed due to audit_backlog_limit
67101 */
67102 -static atomic_t audit_lost = ATOMIC_INIT(0);
67103 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
67104
67105 /* The netlink socket. */
67106 static struct sock *audit_sock;
67107 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
67108 unsigned long now;
67109 int print;
67110
67111 - atomic_inc(&audit_lost);
67112 + atomic_inc_unchecked(&audit_lost);
67113
67114 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
67115
67116 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
67117 printk(KERN_WARNING
67118 "audit: audit_lost=%d audit_rate_limit=%d "
67119 "audit_backlog_limit=%d\n",
67120 - atomic_read(&audit_lost),
67121 + atomic_read_unchecked(&audit_lost),
67122 audit_rate_limit,
67123 audit_backlog_limit);
67124 audit_panic(message);
67125 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
67126 status_set.pid = audit_pid;
67127 status_set.rate_limit = audit_rate_limit;
67128 status_set.backlog_limit = audit_backlog_limit;
67129 - status_set.lost = atomic_read(&audit_lost);
67130 + status_set.lost = atomic_read_unchecked(&audit_lost);
67131 status_set.backlog = skb_queue_len(&audit_skb_queue);
67132 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
67133 &status_set, sizeof(status_set));
67134 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
67135 index 4b96415..d8c16ee 100644
67136 --- a/kernel/auditsc.c
67137 +++ b/kernel/auditsc.c
67138 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
67139 }
67140
67141 /* global counter which is incremented every time something logs in */
67142 -static atomic_t session_id = ATOMIC_INIT(0);
67143 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
67144
67145 /**
67146 * audit_set_loginuid - set current task's audit_context loginuid
67147 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
67148 return -EPERM;
67149 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
67150
67151 - sessionid = atomic_inc_return(&session_id);
67152 + sessionid = atomic_inc_return_unchecked(&session_id);
67153 if (context && context->in_syscall) {
67154 struct audit_buffer *ab;
67155
67156 diff --git a/kernel/capability.c b/kernel/capability.c
67157 index 493d972..ea17248 100644
67158 --- a/kernel/capability.c
67159 +++ b/kernel/capability.c
67160 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
67161 * before modification is attempted and the application
67162 * fails.
67163 */
67164 + if (tocopy > ARRAY_SIZE(kdata))
67165 + return -EFAULT;
67166 +
67167 if (copy_to_user(dataptr, kdata, tocopy
67168 * sizeof(struct __user_cap_data_struct))) {
67169 return -EFAULT;
67170 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
67171 int ret;
67172
67173 rcu_read_lock();
67174 - ret = security_capable(__task_cred(t), ns, cap);
67175 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
67176 + gr_task_is_capable(t, __task_cred(t), cap);
67177 rcu_read_unlock();
67178
67179 - return (ret == 0);
67180 + return ret;
67181 }
67182
67183 /**
67184 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
67185 int ret;
67186
67187 rcu_read_lock();
67188 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
67189 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
67190 rcu_read_unlock();
67191
67192 - return (ret == 0);
67193 + return ret;
67194 }
67195
67196 /**
67197 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
67198 BUG();
67199 }
67200
67201 - if (security_capable(current_cred(), ns, cap) == 0) {
67202 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
67203 current->flags |= PF_SUPERPRIV;
67204 return true;
67205 }
67206 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
67207 }
67208 EXPORT_SYMBOL(ns_capable);
67209
67210 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
67211 +{
67212 + if (unlikely(!cap_valid(cap))) {
67213 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
67214 + BUG();
67215 + }
67216 +
67217 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
67218 + current->flags |= PF_SUPERPRIV;
67219 + return true;
67220 + }
67221 + return false;
67222 +}
67223 +EXPORT_SYMBOL(ns_capable_nolog);
67224 +
67225 /**
67226 * capable - Determine if the current task has a superior capability in effect
67227 * @cap: The capability to be tested for
67228 @@ -408,6 +427,12 @@ bool capable(int cap)
67229 }
67230 EXPORT_SYMBOL(capable);
67231
67232 +bool capable_nolog(int cap)
67233 +{
67234 + return ns_capable_nolog(&init_user_ns, cap);
67235 +}
67236 +EXPORT_SYMBOL(capable_nolog);
67237 +
67238 /**
67239 * nsown_capable - Check superior capability to one's own user_ns
67240 * @cap: The capability in question
67241 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
67242
67243 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
67244 }
67245 +
67246 +bool inode_capable_nolog(const struct inode *inode, int cap)
67247 +{
67248 + struct user_namespace *ns = current_user_ns();
67249 +
67250 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
67251 +}
67252 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
67253 index ff2bce5..a41e8f9 100644
67254 --- a/kernel/cgroup.c
67255 +++ b/kernel/cgroup.c
67256 @@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
67257 struct css_set *cg = link->cg;
67258 struct task_struct *task;
67259 int count = 0;
67260 - seq_printf(seq, "css_set %p\n", cg);
67261 + seq_printf(seq, "css_set %pK\n", cg);
67262 list_for_each_entry(task, &cg->tasks, cg_list) {
67263 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
67264 seq_puts(seq, " ...\n");
67265 diff --git a/kernel/compat.c b/kernel/compat.c
67266 index c28a306..b4d0cf3 100644
67267 --- a/kernel/compat.c
67268 +++ b/kernel/compat.c
67269 @@ -13,6 +13,7 @@
67270
67271 #include <linux/linkage.h>
67272 #include <linux/compat.h>
67273 +#include <linux/module.h>
67274 #include <linux/errno.h>
67275 #include <linux/time.h>
67276 #include <linux/signal.h>
67277 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
67278 mm_segment_t oldfs;
67279 long ret;
67280
67281 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
67282 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
67283 oldfs = get_fs();
67284 set_fs(KERNEL_DS);
67285 ret = hrtimer_nanosleep_restart(restart);
67286 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
67287 oldfs = get_fs();
67288 set_fs(KERNEL_DS);
67289 ret = hrtimer_nanosleep(&tu,
67290 - rmtp ? (struct timespec __user *)&rmt : NULL,
67291 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
67292 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
67293 set_fs(oldfs);
67294
67295 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
67296 mm_segment_t old_fs = get_fs();
67297
67298 set_fs(KERNEL_DS);
67299 - ret = sys_sigpending((old_sigset_t __user *) &s);
67300 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
67301 set_fs(old_fs);
67302 if (ret == 0)
67303 ret = put_user(s, set);
67304 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
67305 mm_segment_t old_fs = get_fs();
67306
67307 set_fs(KERNEL_DS);
67308 - ret = sys_old_getrlimit(resource, &r);
67309 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
67310 set_fs(old_fs);
67311
67312 if (!ret) {
67313 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
67314 mm_segment_t old_fs = get_fs();
67315
67316 set_fs(KERNEL_DS);
67317 - ret = sys_getrusage(who, (struct rusage __user *) &r);
67318 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
67319 set_fs(old_fs);
67320
67321 if (ret)
67322 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
67323 set_fs (KERNEL_DS);
67324 ret = sys_wait4(pid,
67325 (stat_addr ?
67326 - (unsigned int __user *) &status : NULL),
67327 - options, (struct rusage __user *) &r);
67328 + (unsigned int __force_user *) &status : NULL),
67329 + options, (struct rusage __force_user *) &r);
67330 set_fs (old_fs);
67331
67332 if (ret > 0) {
67333 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
67334 memset(&info, 0, sizeof(info));
67335
67336 set_fs(KERNEL_DS);
67337 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
67338 - uru ? (struct rusage __user *)&ru : NULL);
67339 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
67340 + uru ? (struct rusage __force_user *)&ru : NULL);
67341 set_fs(old_fs);
67342
67343 if ((ret < 0) || (info.si_signo == 0))
67344 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
67345 oldfs = get_fs();
67346 set_fs(KERNEL_DS);
67347 err = sys_timer_settime(timer_id, flags,
67348 - (struct itimerspec __user *) &newts,
67349 - (struct itimerspec __user *) &oldts);
67350 + (struct itimerspec __force_user *) &newts,
67351 + (struct itimerspec __force_user *) &oldts);
67352 set_fs(oldfs);
67353 if (!err && old && put_compat_itimerspec(old, &oldts))
67354 return -EFAULT;
67355 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
67356 oldfs = get_fs();
67357 set_fs(KERNEL_DS);
67358 err = sys_timer_gettime(timer_id,
67359 - (struct itimerspec __user *) &ts);
67360 + (struct itimerspec __force_user *) &ts);
67361 set_fs(oldfs);
67362 if (!err && put_compat_itimerspec(setting, &ts))
67363 return -EFAULT;
67364 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
67365 oldfs = get_fs();
67366 set_fs(KERNEL_DS);
67367 err = sys_clock_settime(which_clock,
67368 - (struct timespec __user *) &ts);
67369 + (struct timespec __force_user *) &ts);
67370 set_fs(oldfs);
67371 return err;
67372 }
67373 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
67374 oldfs = get_fs();
67375 set_fs(KERNEL_DS);
67376 err = sys_clock_gettime(which_clock,
67377 - (struct timespec __user *) &ts);
67378 + (struct timespec __force_user *) &ts);
67379 set_fs(oldfs);
67380 if (!err && put_compat_timespec(&ts, tp))
67381 return -EFAULT;
67382 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
67383
67384 oldfs = get_fs();
67385 set_fs(KERNEL_DS);
67386 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
67387 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
67388 set_fs(oldfs);
67389
67390 err = compat_put_timex(utp, &txc);
67391 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
67392 oldfs = get_fs();
67393 set_fs(KERNEL_DS);
67394 err = sys_clock_getres(which_clock,
67395 - (struct timespec __user *) &ts);
67396 + (struct timespec __force_user *) &ts);
67397 set_fs(oldfs);
67398 if (!err && tp && put_compat_timespec(&ts, tp))
67399 return -EFAULT;
67400 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
67401 long err;
67402 mm_segment_t oldfs;
67403 struct timespec tu;
67404 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
67405 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
67406
67407 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
67408 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
67409 oldfs = get_fs();
67410 set_fs(KERNEL_DS);
67411 err = clock_nanosleep_restart(restart);
67412 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
67413 oldfs = get_fs();
67414 set_fs(KERNEL_DS);
67415 err = sys_clock_nanosleep(which_clock, flags,
67416 - (struct timespec __user *) &in,
67417 - (struct timespec __user *) &out);
67418 + (struct timespec __force_user *) &in,
67419 + (struct timespec __force_user *) &out);
67420 set_fs(oldfs);
67421
67422 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
67423 diff --git a/kernel/configs.c b/kernel/configs.c
67424 index 42e8fa0..9e7406b 100644
67425 --- a/kernel/configs.c
67426 +++ b/kernel/configs.c
67427 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
67428 struct proc_dir_entry *entry;
67429
67430 /* create the current config file */
67431 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67432 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
67433 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
67434 + &ikconfig_file_ops);
67435 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67436 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
67437 + &ikconfig_file_ops);
67438 +#endif
67439 +#else
67440 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
67441 &ikconfig_file_ops);
67442 +#endif
67443 +
67444 if (!entry)
67445 return -ENOMEM;
67446
67447 diff --git a/kernel/cred.c b/kernel/cred.c
67448 index de728ac..e3c267c 100644
67449 --- a/kernel/cred.c
67450 +++ b/kernel/cred.c
67451 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
67452 validate_creds(cred);
67453 alter_cred_subscribers(cred, -1);
67454 put_cred(cred);
67455 +
67456 +#ifdef CONFIG_GRKERNSEC_SETXID
67457 + cred = (struct cred *) tsk->delayed_cred;
67458 + if (cred != NULL) {
67459 + tsk->delayed_cred = NULL;
67460 + validate_creds(cred);
67461 + alter_cred_subscribers(cred, -1);
67462 + put_cred(cred);
67463 + }
67464 +#endif
67465 }
67466
67467 /**
67468 @@ -469,7 +479,7 @@ error_put:
67469 * Always returns 0 thus allowing this function to be tail-called at the end
67470 * of, say, sys_setgid().
67471 */
67472 -int commit_creds(struct cred *new)
67473 +static int __commit_creds(struct cred *new)
67474 {
67475 struct task_struct *task = current;
67476 const struct cred *old = task->real_cred;
67477 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
67478
67479 get_cred(new); /* we will require a ref for the subj creds too */
67480
67481 + gr_set_role_label(task, new->uid, new->gid);
67482 +
67483 /* dumpability changes */
67484 if (!uid_eq(old->euid, new->euid) ||
67485 !gid_eq(old->egid, new->egid) ||
67486 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
67487 put_cred(old);
67488 return 0;
67489 }
67490 +#ifdef CONFIG_GRKERNSEC_SETXID
67491 +extern int set_user(struct cred *new);
67492 +
67493 +void gr_delayed_cred_worker(void)
67494 +{
67495 + const struct cred *new = current->delayed_cred;
67496 + struct cred *ncred;
67497 +
67498 + current->delayed_cred = NULL;
67499 +
67500 + if (current_uid() && new != NULL) {
67501 + // from doing get_cred on it when queueing this
67502 + put_cred(new);
67503 + return;
67504 + } else if (new == NULL)
67505 + return;
67506 +
67507 + ncred = prepare_creds();
67508 + if (!ncred)
67509 + goto die;
67510 + // uids
67511 + ncred->uid = new->uid;
67512 + ncred->euid = new->euid;
67513 + ncred->suid = new->suid;
67514 + ncred->fsuid = new->fsuid;
67515 + // gids
67516 + ncred->gid = new->gid;
67517 + ncred->egid = new->egid;
67518 + ncred->sgid = new->sgid;
67519 + ncred->fsgid = new->fsgid;
67520 + // groups
67521 + if (set_groups(ncred, new->group_info) < 0) {
67522 + abort_creds(ncred);
67523 + goto die;
67524 + }
67525 + // caps
67526 + ncred->securebits = new->securebits;
67527 + ncred->cap_inheritable = new->cap_inheritable;
67528 + ncred->cap_permitted = new->cap_permitted;
67529 + ncred->cap_effective = new->cap_effective;
67530 + ncred->cap_bset = new->cap_bset;
67531 +
67532 + if (set_user(ncred)) {
67533 + abort_creds(ncred);
67534 + goto die;
67535 + }
67536 +
67537 + // from doing get_cred on it when queueing this
67538 + put_cred(new);
67539 +
67540 + __commit_creds(ncred);
67541 + return;
67542 +die:
67543 + // from doing get_cred on it when queueing this
67544 + put_cred(new);
67545 + do_group_exit(SIGKILL);
67546 +}
67547 +#endif
67548 +
67549 +int commit_creds(struct cred *new)
67550 +{
67551 +#ifdef CONFIG_GRKERNSEC_SETXID
67552 + int ret;
67553 + int schedule_it = 0;
67554 + struct task_struct *t;
67555 +
67556 + /* we won't get called with tasklist_lock held for writing
67557 + and interrupts disabled as the cred struct in that case is
67558 + init_cred
67559 + */
67560 + if (grsec_enable_setxid && !current_is_single_threaded() &&
67561 + !current_uid() && new->uid) {
67562 + schedule_it = 1;
67563 + }
67564 + ret = __commit_creds(new);
67565 + if (schedule_it) {
67566 + rcu_read_lock();
67567 + read_lock(&tasklist_lock);
67568 + for (t = next_thread(current); t != current;
67569 + t = next_thread(t)) {
67570 + if (t->delayed_cred == NULL) {
67571 + t->delayed_cred = get_cred(new);
67572 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67573 + set_tsk_need_resched(t);
67574 + }
67575 + }
67576 + read_unlock(&tasklist_lock);
67577 + rcu_read_unlock();
67578 + }
67579 + return ret;
67580 +#else
67581 + return __commit_creds(new);
67582 +#endif
67583 +}
67584 +
67585 EXPORT_SYMBOL(commit_creds);
67586
67587 /**
67588 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67589 index 0557f24..1a00d9a 100644
67590 --- a/kernel/debug/debug_core.c
67591 +++ b/kernel/debug/debug_core.c
67592 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67593 */
67594 static atomic_t masters_in_kgdb;
67595 static atomic_t slaves_in_kgdb;
67596 -static atomic_t kgdb_break_tasklet_var;
67597 +static atomic_unchecked_t kgdb_break_tasklet_var;
67598 atomic_t kgdb_setting_breakpoint;
67599
67600 struct task_struct *kgdb_usethread;
67601 @@ -132,7 +132,7 @@ int kgdb_single_step;
67602 static pid_t kgdb_sstep_pid;
67603
67604 /* to keep track of the CPU which is doing the single stepping*/
67605 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67606 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67607
67608 /*
67609 * If you are debugging a problem where roundup (the collection of
67610 @@ -540,7 +540,7 @@ return_normal:
67611 * kernel will only try for the value of sstep_tries before
67612 * giving up and continuing on.
67613 */
67614 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67615 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67616 (kgdb_info[cpu].task &&
67617 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67618 atomic_set(&kgdb_active, -1);
67619 @@ -634,8 +634,8 @@ cpu_master_loop:
67620 }
67621
67622 kgdb_restore:
67623 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67624 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67625 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67626 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67627 if (kgdb_info[sstep_cpu].task)
67628 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67629 else
67630 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
67631 static void kgdb_tasklet_bpt(unsigned long ing)
67632 {
67633 kgdb_breakpoint();
67634 - atomic_set(&kgdb_break_tasklet_var, 0);
67635 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67636 }
67637
67638 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67639
67640 void kgdb_schedule_breakpoint(void)
67641 {
67642 - if (atomic_read(&kgdb_break_tasklet_var) ||
67643 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67644 atomic_read(&kgdb_active) != -1 ||
67645 atomic_read(&kgdb_setting_breakpoint))
67646 return;
67647 - atomic_inc(&kgdb_break_tasklet_var);
67648 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67649 tasklet_schedule(&kgdb_tasklet_breakpoint);
67650 }
67651 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67652 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67653 index 31df170..bc98840 100644
67654 --- a/kernel/debug/kdb/kdb_main.c
67655 +++ b/kernel/debug/kdb/kdb_main.c
67656 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
67657 list_for_each_entry(mod, kdb_modules, list) {
67658
67659 kdb_printf("%-20s%8u 0x%p ", mod->name,
67660 - mod->core_size, (void *)mod);
67661 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67662 #ifdef CONFIG_MODULE_UNLOAD
67663 kdb_printf("%4ld ", module_refcount(mod));
67664 #endif
67665 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
67666 kdb_printf(" (Loading)");
67667 else
67668 kdb_printf(" (Live)");
67669 - kdb_printf(" 0x%p", mod->module_core);
67670 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67671
67672 #ifdef CONFIG_MODULE_UNLOAD
67673 {
67674 diff --git a/kernel/events/core.c b/kernel/events/core.c
67675 index 7fee567..8affa2c 100644
67676 --- a/kernel/events/core.c
67677 +++ b/kernel/events/core.c
67678 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67679 return 0;
67680 }
67681
67682 -static atomic64_t perf_event_id;
67683 +static atomic64_unchecked_t perf_event_id;
67684
67685 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67686 enum event_type_t event_type);
67687 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
67688
67689 static inline u64 perf_event_count(struct perf_event *event)
67690 {
67691 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67692 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67693 }
67694
67695 static u64 perf_event_read(struct perf_event *event)
67696 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67697 mutex_lock(&event->child_mutex);
67698 total += perf_event_read(event);
67699 *enabled += event->total_time_enabled +
67700 - atomic64_read(&event->child_total_time_enabled);
67701 + atomic64_read_unchecked(&event->child_total_time_enabled);
67702 *running += event->total_time_running +
67703 - atomic64_read(&event->child_total_time_running);
67704 + atomic64_read_unchecked(&event->child_total_time_running);
67705
67706 list_for_each_entry(child, &event->child_list, child_list) {
67707 total += perf_event_read(child);
67708 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
67709 userpg->offset -= local64_read(&event->hw.prev_count);
67710
67711 userpg->time_enabled = enabled +
67712 - atomic64_read(&event->child_total_time_enabled);
67713 + atomic64_read_unchecked(&event->child_total_time_enabled);
67714
67715 userpg->time_running = running +
67716 - atomic64_read(&event->child_total_time_running);
67717 + atomic64_read_unchecked(&event->child_total_time_running);
67718
67719 arch_perf_update_userpage(userpg, now);
67720
67721 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67722 values[n++] = perf_event_count(event);
67723 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67724 values[n++] = enabled +
67725 - atomic64_read(&event->child_total_time_enabled);
67726 + atomic64_read_unchecked(&event->child_total_time_enabled);
67727 }
67728 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67729 values[n++] = running +
67730 - atomic64_read(&event->child_total_time_running);
67731 + atomic64_read_unchecked(&event->child_total_time_running);
67732 }
67733 if (read_format & PERF_FORMAT_ID)
67734 values[n++] = primary_event_id(event);
67735 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67736 * need to add enough zero bytes after the string to handle
67737 * the 64bit alignment we do later.
67738 */
67739 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67740 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67741 if (!buf) {
67742 name = strncpy(tmp, "//enomem", sizeof(tmp));
67743 goto got_name;
67744 }
67745 - name = d_path(&file->f_path, buf, PATH_MAX);
67746 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67747 if (IS_ERR(name)) {
67748 name = strncpy(tmp, "//toolong", sizeof(tmp));
67749 goto got_name;
67750 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67751 event->parent = parent_event;
67752
67753 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67754 - event->id = atomic64_inc_return(&perf_event_id);
67755 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67756
67757 event->state = PERF_EVENT_STATE_INACTIVE;
67758
67759 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67760 /*
67761 * Add back the child's count to the parent's count:
67762 */
67763 - atomic64_add(child_val, &parent_event->child_count);
67764 - atomic64_add(child_event->total_time_enabled,
67765 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67766 + atomic64_add_unchecked(child_event->total_time_enabled,
67767 &parent_event->child_total_time_enabled);
67768 - atomic64_add(child_event->total_time_running,
67769 + atomic64_add_unchecked(child_event->total_time_running,
67770 &parent_event->child_total_time_running);
67771
67772 /*
67773 diff --git a/kernel/exit.c b/kernel/exit.c
67774 index f65345f9..1423231 100644
67775 --- a/kernel/exit.c
67776 +++ b/kernel/exit.c
67777 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
67778 struct task_struct *leader;
67779 int zap_leader;
67780 repeat:
67781 +#ifdef CONFIG_NET
67782 + gr_del_task_from_ip_table(p);
67783 +#endif
67784 +
67785 /* don't need to get the RCU readlock here - the process is dead and
67786 * can't be modifying its own credentials. But shut RCU-lockdep up */
67787 rcu_read_lock();
67788 @@ -394,7 +398,7 @@ int allow_signal(int sig)
67789 * know it'll be handled, so that they don't get converted to
67790 * SIGKILL or just silently dropped.
67791 */
67792 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67793 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67794 recalc_sigpending();
67795 spin_unlock_irq(&current->sighand->siglock);
67796 return 0;
67797 @@ -430,6 +434,8 @@ void daemonize(const char *name, ...)
67798 vsnprintf(current->comm, sizeof(current->comm), name, args);
67799 va_end(args);
67800
67801 + gr_set_kernel_label(current);
67802 +
67803 /*
67804 * If we were started as result of loading a module, close all of the
67805 * user space pages. We don't need them, and if we didn't close them
67806 @@ -907,6 +913,8 @@ void do_exit(long code)
67807 struct task_struct *tsk = current;
67808 int group_dead;
67809
67810 + set_fs(USER_DS);
67811 +
67812 profile_task_exit(tsk);
67813
67814 WARN_ON(blk_needs_flush_plug(tsk));
67815 @@ -923,7 +931,6 @@ void do_exit(long code)
67816 * mm_release()->clear_child_tid() from writing to a user-controlled
67817 * kernel address.
67818 */
67819 - set_fs(USER_DS);
67820
67821 ptrace_event(PTRACE_EVENT_EXIT, code);
67822
67823 @@ -982,6 +989,9 @@ void do_exit(long code)
67824 tsk->exit_code = code;
67825 taskstats_exit(tsk, group_dead);
67826
67827 + gr_acl_handle_psacct(tsk, code);
67828 + gr_acl_handle_exit();
67829 +
67830 exit_mm(tsk);
67831
67832 if (group_dead)
67833 @@ -1099,7 +1109,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67834 * Take down every thread in the group. This is called by fatal signals
67835 * as well as by sys_exit_group (below).
67836 */
67837 -void
67838 +__noreturn void
67839 do_group_exit(int exit_code)
67840 {
67841 struct signal_struct *sig = current->signal;
67842 diff --git a/kernel/fork.c b/kernel/fork.c
67843 index 2c8857e..288c9c7 100644
67844 --- a/kernel/fork.c
67845 +++ b/kernel/fork.c
67846 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67847 *stackend = STACK_END_MAGIC; /* for overflow detection */
67848
67849 #ifdef CONFIG_CC_STACKPROTECTOR
67850 - tsk->stack_canary = get_random_int();
67851 + tsk->stack_canary = pax_get_random_long();
67852 #endif
67853
67854 /*
67855 @@ -343,13 +343,78 @@ free_tsk:
67856 }
67857
67858 #ifdef CONFIG_MMU
67859 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67860 +{
67861 + struct vm_area_struct *tmp;
67862 + unsigned long charge;
67863 + struct mempolicy *pol;
67864 + struct file *file;
67865 +
67866 + charge = 0;
67867 + if (mpnt->vm_flags & VM_ACCOUNT) {
67868 + unsigned long len = vma_pages(mpnt);
67869 +
67870 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67871 + goto fail_nomem;
67872 + charge = len;
67873 + }
67874 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67875 + if (!tmp)
67876 + goto fail_nomem;
67877 + *tmp = *mpnt;
67878 + tmp->vm_mm = mm;
67879 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67880 + pol = mpol_dup(vma_policy(mpnt));
67881 + if (IS_ERR(pol))
67882 + goto fail_nomem_policy;
67883 + vma_set_policy(tmp, pol);
67884 + if (anon_vma_fork(tmp, mpnt))
67885 + goto fail_nomem_anon_vma_fork;
67886 + tmp->vm_flags &= ~VM_LOCKED;
67887 + tmp->vm_next = tmp->vm_prev = NULL;
67888 + tmp->vm_mirror = NULL;
67889 + file = tmp->vm_file;
67890 + if (file) {
67891 + struct inode *inode = file->f_path.dentry->d_inode;
67892 + struct address_space *mapping = file->f_mapping;
67893 +
67894 + get_file(file);
67895 + if (tmp->vm_flags & VM_DENYWRITE)
67896 + atomic_dec(&inode->i_writecount);
67897 + mutex_lock(&mapping->i_mmap_mutex);
67898 + if (tmp->vm_flags & VM_SHARED)
67899 + mapping->i_mmap_writable++;
67900 + flush_dcache_mmap_lock(mapping);
67901 + /* insert tmp into the share list, just after mpnt */
67902 + vma_prio_tree_add(tmp, mpnt);
67903 + flush_dcache_mmap_unlock(mapping);
67904 + mutex_unlock(&mapping->i_mmap_mutex);
67905 + }
67906 +
67907 + /*
67908 + * Clear hugetlb-related page reserves for children. This only
67909 + * affects MAP_PRIVATE mappings. Faults generated by the child
67910 + * are not guaranteed to succeed, even if read-only
67911 + */
67912 + if (is_vm_hugetlb_page(tmp))
67913 + reset_vma_resv_huge_pages(tmp);
67914 +
67915 + return tmp;
67916 +
67917 +fail_nomem_anon_vma_fork:
67918 + mpol_put(pol);
67919 +fail_nomem_policy:
67920 + kmem_cache_free(vm_area_cachep, tmp);
67921 +fail_nomem:
67922 + vm_unacct_memory(charge);
67923 + return NULL;
67924 +}
67925 +
67926 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67927 {
67928 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67929 struct rb_node **rb_link, *rb_parent;
67930 int retval;
67931 - unsigned long charge;
67932 - struct mempolicy *pol;
67933
67934 down_write(&oldmm->mmap_sem);
67935 flush_cache_dup_mm(oldmm);
67936 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67937 mm->locked_vm = 0;
67938 mm->mmap = NULL;
67939 mm->mmap_cache = NULL;
67940 - mm->free_area_cache = oldmm->mmap_base;
67941 - mm->cached_hole_size = ~0UL;
67942 + mm->free_area_cache = oldmm->free_area_cache;
67943 + mm->cached_hole_size = oldmm->cached_hole_size;
67944 mm->map_count = 0;
67945 cpumask_clear(mm_cpumask(mm));
67946 mm->mm_rb = RB_ROOT;
67947 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67948
67949 prev = NULL;
67950 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67951 - struct file *file;
67952 -
67953 if (mpnt->vm_flags & VM_DONTCOPY) {
67954 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67955 -vma_pages(mpnt));
67956 continue;
67957 }
67958 - charge = 0;
67959 - if (mpnt->vm_flags & VM_ACCOUNT) {
67960 - unsigned long len = vma_pages(mpnt);
67961 -
67962 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67963 - goto fail_nomem;
67964 - charge = len;
67965 - }
67966 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67967 - if (!tmp)
67968 - goto fail_nomem;
67969 - *tmp = *mpnt;
67970 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67971 - pol = mpol_dup(vma_policy(mpnt));
67972 - retval = PTR_ERR(pol);
67973 - if (IS_ERR(pol))
67974 - goto fail_nomem_policy;
67975 - vma_set_policy(tmp, pol);
67976 - tmp->vm_mm = mm;
67977 - if (anon_vma_fork(tmp, mpnt))
67978 - goto fail_nomem_anon_vma_fork;
67979 - tmp->vm_flags &= ~VM_LOCKED;
67980 - tmp->vm_next = tmp->vm_prev = NULL;
67981 - file = tmp->vm_file;
67982 - if (file) {
67983 - struct inode *inode = file->f_path.dentry->d_inode;
67984 - struct address_space *mapping = file->f_mapping;
67985 -
67986 - get_file(file);
67987 - if (tmp->vm_flags & VM_DENYWRITE)
67988 - atomic_dec(&inode->i_writecount);
67989 - mutex_lock(&mapping->i_mmap_mutex);
67990 - if (tmp->vm_flags & VM_SHARED)
67991 - mapping->i_mmap_writable++;
67992 - flush_dcache_mmap_lock(mapping);
67993 - /* insert tmp into the share list, just after mpnt */
67994 - vma_prio_tree_add(tmp, mpnt);
67995 - flush_dcache_mmap_unlock(mapping);
67996 - mutex_unlock(&mapping->i_mmap_mutex);
67997 + tmp = dup_vma(mm, oldmm, mpnt);
67998 + if (!tmp) {
67999 + retval = -ENOMEM;
68000 + goto out;
68001 }
68002
68003 /*
68004 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
68005 if (retval)
68006 goto out;
68007
68008 - if (file)
68009 + if (tmp->vm_file)
68010 uprobe_mmap(tmp);
68011 }
68012 +
68013 +#ifdef CONFIG_PAX_SEGMEXEC
68014 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
68015 + struct vm_area_struct *mpnt_m;
68016 +
68017 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
68018 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
68019 +
68020 + if (!mpnt->vm_mirror)
68021 + continue;
68022 +
68023 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
68024 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
68025 + mpnt->vm_mirror = mpnt_m;
68026 + } else {
68027 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
68028 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
68029 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
68030 + mpnt->vm_mirror->vm_mirror = mpnt;
68031 + }
68032 + }
68033 + BUG_ON(mpnt_m);
68034 + }
68035 +#endif
68036 +
68037 /* a new mm has just been created */
68038 arch_dup_mmap(oldmm, mm);
68039 retval = 0;
68040 @@ -466,14 +519,6 @@ out:
68041 flush_tlb_mm(oldmm);
68042 up_write(&oldmm->mmap_sem);
68043 return retval;
68044 -fail_nomem_anon_vma_fork:
68045 - mpol_put(pol);
68046 -fail_nomem_policy:
68047 - kmem_cache_free(vm_area_cachep, tmp);
68048 -fail_nomem:
68049 - retval = -ENOMEM;
68050 - vm_unacct_memory(charge);
68051 - goto out;
68052 }
68053
68054 static inline int mm_alloc_pgd(struct mm_struct *mm)
68055 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
68056 return ERR_PTR(err);
68057
68058 mm = get_task_mm(task);
68059 - if (mm && mm != current->mm &&
68060 - !ptrace_may_access(task, mode)) {
68061 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
68062 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
68063 mmput(mm);
68064 mm = ERR_PTR(-EACCES);
68065 }
68066 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
68067 spin_unlock(&fs->lock);
68068 return -EAGAIN;
68069 }
68070 - fs->users++;
68071 + atomic_inc(&fs->users);
68072 spin_unlock(&fs->lock);
68073 return 0;
68074 }
68075 tsk->fs = copy_fs_struct(fs);
68076 if (!tsk->fs)
68077 return -ENOMEM;
68078 + /* Carry through gr_chroot_dentry and is_chrooted instead
68079 + of recomputing it here. Already copied when the task struct
68080 + is duplicated. This allows pivot_root to not be treated as
68081 + a chroot
68082 + */
68083 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
68084 +
68085 return 0;
68086 }
68087
68088 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
68089 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
68090 #endif
68091 retval = -EAGAIN;
68092 +
68093 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
68094 +
68095 if (atomic_read(&p->real_cred->user->processes) >=
68096 task_rlimit(p, RLIMIT_NPROC)) {
68097 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
68098 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
68099 /* Need tasklist lock for parent etc handling! */
68100 write_lock_irq(&tasklist_lock);
68101
68102 + /* synchronizes with gr_set_acls() */
68103 + gr_copy_label(p);
68104 +
68105 /* CLONE_PARENT re-uses the old parent */
68106 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
68107 p->real_parent = current->real_parent;
68108 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
68109 bad_fork_free:
68110 free_task(p);
68111 fork_out:
68112 + gr_log_forkfail(retval);
68113 +
68114 return ERR_PTR(retval);
68115 }
68116
68117 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
68118 if (clone_flags & CLONE_PARENT_SETTID)
68119 put_user(nr, parent_tidptr);
68120
68121 + gr_handle_brute_check();
68122 +
68123 if (clone_flags & CLONE_VFORK) {
68124 p->vfork_done = &vfork;
68125 init_completion(&vfork);
68126 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
68127 return 0;
68128
68129 /* don't need lock here; in the worst case we'll do useless copy */
68130 - if (fs->users == 1)
68131 + if (atomic_read(&fs->users) == 1)
68132 return 0;
68133
68134 *new_fsp = copy_fs_struct(fs);
68135 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
68136 fs = current->fs;
68137 spin_lock(&fs->lock);
68138 current->fs = new_fs;
68139 - if (--fs->users)
68140 + gr_set_chroot_entries(current, &current->fs->root);
68141 + if (atomic_dec_return(&fs->users))
68142 new_fs = NULL;
68143 else
68144 new_fs = fs;
68145 diff --git a/kernel/futex.c b/kernel/futex.c
68146 index 19eb089..b8c65ea 100644
68147 --- a/kernel/futex.c
68148 +++ b/kernel/futex.c
68149 @@ -54,6 +54,7 @@
68150 #include <linux/mount.h>
68151 #include <linux/pagemap.h>
68152 #include <linux/syscalls.h>
68153 +#include <linux/ptrace.h>
68154 #include <linux/signal.h>
68155 #include <linux/export.h>
68156 #include <linux/magic.h>
68157 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
68158 struct page *page, *page_head;
68159 int err, ro = 0;
68160
68161 +#ifdef CONFIG_PAX_SEGMEXEC
68162 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
68163 + return -EFAULT;
68164 +#endif
68165 +
68166 /*
68167 * The futex address must be "naturally" aligned.
68168 */
68169 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
68170 {
68171 u32 curval;
68172 int i;
68173 + mm_segment_t oldfs;
68174
68175 /*
68176 * This will fail and we want it. Some arch implementations do
68177 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
68178 * implementation, the non-functional ones will return
68179 * -ENOSYS.
68180 */
68181 + oldfs = get_fs();
68182 + set_fs(USER_DS);
68183 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
68184 futex_cmpxchg_enabled = 1;
68185 + set_fs(oldfs);
68186
68187 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
68188 plist_head_init(&futex_queues[i].chain);
68189 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
68190 index 9b22d03..6295b62 100644
68191 --- a/kernel/gcov/base.c
68192 +++ b/kernel/gcov/base.c
68193 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
68194 }
68195
68196 #ifdef CONFIG_MODULES
68197 -static inline int within(void *addr, void *start, unsigned long size)
68198 -{
68199 - return ((addr >= start) && (addr < start + size));
68200 -}
68201 -
68202 /* Update list and generate events when modules are unloaded. */
68203 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
68204 void *data)
68205 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
68206 prev = NULL;
68207 /* Remove entries located in module from linked list. */
68208 for (info = gcov_info_head; info; info = info->next) {
68209 - if (within(info, mod->module_core, mod->core_size)) {
68210 + if (within_module_core_rw((unsigned long)info, mod)) {
68211 if (prev)
68212 prev->next = info->next;
68213 else
68214 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
68215 index 6db7a5e..25b6648 100644
68216 --- a/kernel/hrtimer.c
68217 +++ b/kernel/hrtimer.c
68218 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
68219 local_irq_restore(flags);
68220 }
68221
68222 -static void run_hrtimer_softirq(struct softirq_action *h)
68223 +static void run_hrtimer_softirq(void)
68224 {
68225 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
68226
68227 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
68228 index 4304919..408c4c0 100644
68229 --- a/kernel/jump_label.c
68230 +++ b/kernel/jump_label.c
68231 @@ -13,6 +13,7 @@
68232 #include <linux/sort.h>
68233 #include <linux/err.h>
68234 #include <linux/static_key.h>
68235 +#include <linux/mm.h>
68236
68237 #ifdef HAVE_JUMP_LABEL
68238
68239 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
68240
68241 size = (((unsigned long)stop - (unsigned long)start)
68242 / sizeof(struct jump_entry));
68243 + pax_open_kernel();
68244 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
68245 + pax_close_kernel();
68246 }
68247
68248 static void jump_label_update(struct static_key *key, int enable);
68249 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
68250 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
68251 struct jump_entry *iter;
68252
68253 + pax_open_kernel();
68254 for (iter = iter_start; iter < iter_stop; iter++) {
68255 if (within_module_init(iter->code, mod))
68256 iter->code = 0;
68257 }
68258 + pax_close_kernel();
68259 }
68260
68261 static int
68262 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
68263 index 2169fee..45c017a 100644
68264 --- a/kernel/kallsyms.c
68265 +++ b/kernel/kallsyms.c
68266 @@ -11,6 +11,9 @@
68267 * Changed the compression method from stem compression to "table lookup"
68268 * compression (see scripts/kallsyms.c for a more complete description)
68269 */
68270 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68271 +#define __INCLUDED_BY_HIDESYM 1
68272 +#endif
68273 #include <linux/kallsyms.h>
68274 #include <linux/module.h>
68275 #include <linux/init.h>
68276 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
68277
68278 static inline int is_kernel_inittext(unsigned long addr)
68279 {
68280 + if (system_state != SYSTEM_BOOTING)
68281 + return 0;
68282 +
68283 if (addr >= (unsigned long)_sinittext
68284 && addr <= (unsigned long)_einittext)
68285 return 1;
68286 return 0;
68287 }
68288
68289 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68290 +#ifdef CONFIG_MODULES
68291 +static inline int is_module_text(unsigned long addr)
68292 +{
68293 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
68294 + return 1;
68295 +
68296 + addr = ktla_ktva(addr);
68297 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
68298 +}
68299 +#else
68300 +static inline int is_module_text(unsigned long addr)
68301 +{
68302 + return 0;
68303 +}
68304 +#endif
68305 +#endif
68306 +
68307 static inline int is_kernel_text(unsigned long addr)
68308 {
68309 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
68310 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
68311
68312 static inline int is_kernel(unsigned long addr)
68313 {
68314 +
68315 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68316 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
68317 + return 1;
68318 +
68319 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
68320 +#else
68321 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
68322 +#endif
68323 +
68324 return 1;
68325 return in_gate_area_no_mm(addr);
68326 }
68327
68328 static int is_ksym_addr(unsigned long addr)
68329 {
68330 +
68331 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68332 + if (is_module_text(addr))
68333 + return 0;
68334 +#endif
68335 +
68336 if (all_var)
68337 return is_kernel(addr);
68338
68339 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
68340
68341 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
68342 {
68343 - iter->name[0] = '\0';
68344 iter->nameoff = get_symbol_offset(new_pos);
68345 iter->pos = new_pos;
68346 }
68347 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
68348 {
68349 struct kallsym_iter *iter = m->private;
68350
68351 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68352 + if (current_uid())
68353 + return 0;
68354 +#endif
68355 +
68356 /* Some debugging symbols have no name. Ignore them. */
68357 if (!iter->name[0])
68358 return 0;
68359 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
68360 */
68361 type = iter->exported ? toupper(iter->type) :
68362 tolower(iter->type);
68363 +
68364 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
68365 type, iter->name, iter->module_name);
68366 } else
68367 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
68368 struct kallsym_iter *iter;
68369 int ret;
68370
68371 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
68372 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
68373 if (!iter)
68374 return -ENOMEM;
68375 reset_iter(iter, 0);
68376 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
68377 index 30b7b22..c726387 100644
68378 --- a/kernel/kcmp.c
68379 +++ b/kernel/kcmp.c
68380 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
68381 struct task_struct *task1, *task2;
68382 int ret;
68383
68384 +#ifdef CONFIG_GRKERNSEC
68385 + return -ENOSYS;
68386 +#endif
68387 +
68388 rcu_read_lock();
68389
68390 /*
68391 diff --git a/kernel/kexec.c b/kernel/kexec.c
68392 index 0668d58..591b6fc 100644
68393 --- a/kernel/kexec.c
68394 +++ b/kernel/kexec.c
68395 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
68396 unsigned long flags)
68397 {
68398 struct compat_kexec_segment in;
68399 - struct kexec_segment out, __user *ksegments;
68400 + struct kexec_segment out;
68401 + struct kexec_segment __user *ksegments;
68402 unsigned long i, result;
68403
68404 /* Don't allow clients that don't understand the native
68405 diff --git a/kernel/kmod.c b/kernel/kmod.c
68406 index 6f99aea..eb6e3a0 100644
68407 --- a/kernel/kmod.c
68408 +++ b/kernel/kmod.c
68409 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
68410 kfree(info->argv);
68411 }
68412
68413 -static int call_modprobe(char *module_name, int wait)
68414 +static int call_modprobe(char *module_name, char *module_param, int wait)
68415 {
68416 static char *envp[] = {
68417 "HOME=/",
68418 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
68419 NULL
68420 };
68421
68422 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
68423 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
68424 if (!argv)
68425 goto out;
68426
68427 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
68428 argv[1] = "-q";
68429 argv[2] = "--";
68430 argv[3] = module_name; /* check free_modprobe_argv() */
68431 - argv[4] = NULL;
68432 + argv[4] = module_param;
68433 + argv[5] = NULL;
68434
68435 return call_usermodehelper_fns(modprobe_path, argv, envp,
68436 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
68437 @@ -119,9 +120,8 @@ out:
68438 * If module auto-loading support is disabled then this function
68439 * becomes a no-operation.
68440 */
68441 -int __request_module(bool wait, const char *fmt, ...)
68442 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
68443 {
68444 - va_list args;
68445 char module_name[MODULE_NAME_LEN];
68446 unsigned int max_modprobes;
68447 int ret;
68448 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
68449 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
68450 static int kmod_loop_msg;
68451
68452 - va_start(args, fmt);
68453 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
68454 - va_end(args);
68455 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
68456 if (ret >= MODULE_NAME_LEN)
68457 return -ENAMETOOLONG;
68458
68459 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
68460 if (ret)
68461 return ret;
68462
68463 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68464 + if (!current_uid()) {
68465 + /* hack to workaround consolekit/udisks stupidity */
68466 + read_lock(&tasklist_lock);
68467 + if (!strcmp(current->comm, "mount") &&
68468 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
68469 + read_unlock(&tasklist_lock);
68470 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
68471 + return -EPERM;
68472 + }
68473 + read_unlock(&tasklist_lock);
68474 + }
68475 +#endif
68476 +
68477 /* If modprobe needs a service that is in a module, we get a recursive
68478 * loop. Limit the number of running kmod threads to max_threads/2 or
68479 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
68480 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
68481
68482 trace_module_request(module_name, wait, _RET_IP_);
68483
68484 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68485 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68486
68487 atomic_dec(&kmod_concurrent);
68488 return ret;
68489 }
68490 +
68491 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68492 +{
68493 + va_list args;
68494 + int ret;
68495 +
68496 + va_start(args, fmt);
68497 + ret = ____request_module(wait, module_param, fmt, args);
68498 + va_end(args);
68499 +
68500 + return ret;
68501 +}
68502 +
68503 +int __request_module(bool wait, const char *fmt, ...)
68504 +{
68505 + va_list args;
68506 + int ret;
68507 +
68508 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68509 + if (current_uid()) {
68510 + char module_param[MODULE_NAME_LEN];
68511 +
68512 + memset(module_param, 0, sizeof(module_param));
68513 +
68514 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68515 +
68516 + va_start(args, fmt);
68517 + ret = ____request_module(wait, module_param, fmt, args);
68518 + va_end(args);
68519 +
68520 + return ret;
68521 + }
68522 +#endif
68523 +
68524 + va_start(args, fmt);
68525 + ret = ____request_module(wait, NULL, fmt, args);
68526 + va_end(args);
68527 +
68528 + return ret;
68529 +}
68530 +
68531 EXPORT_SYMBOL(__request_module);
68532 #endif /* CONFIG_MODULES */
68533
68534 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
68535 *
68536 * Thus the __user pointer cast is valid here.
68537 */
68538 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
68539 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68540
68541 /*
68542 * If ret is 0, either ____call_usermodehelper failed and the
68543 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68544 index c62b854..6fc810d 100644
68545 --- a/kernel/kprobes.c
68546 +++ b/kernel/kprobes.c
68547 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68548 * kernel image and loaded module images reside. This is required
68549 * so x86_64 can correctly handle the %rip-relative fixups.
68550 */
68551 - kip->insns = module_alloc(PAGE_SIZE);
68552 + kip->insns = module_alloc_exec(PAGE_SIZE);
68553 if (!kip->insns) {
68554 kfree(kip);
68555 return NULL;
68556 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68557 */
68558 if (!list_is_singular(&kip->list)) {
68559 list_del(&kip->list);
68560 - module_free(NULL, kip->insns);
68561 + module_free_exec(NULL, kip->insns);
68562 kfree(kip);
68563 }
68564 return 1;
68565 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
68566 {
68567 int i, err = 0;
68568 unsigned long offset = 0, size = 0;
68569 - char *modname, namebuf[128];
68570 + char *modname, namebuf[KSYM_NAME_LEN];
68571 const char *symbol_name;
68572 void *addr;
68573 struct kprobe_blackpoint *kb;
68574 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68575 kprobe_type = "k";
68576
68577 if (sym)
68578 - seq_printf(pi, "%p %s %s+0x%x %s ",
68579 + seq_printf(pi, "%pK %s %s+0x%x %s ",
68580 p->addr, kprobe_type, sym, offset,
68581 (modname ? modname : " "));
68582 else
68583 - seq_printf(pi, "%p %s %p ",
68584 + seq_printf(pi, "%pK %s %pK ",
68585 p->addr, kprobe_type, p->addr);
68586
68587 if (!pp)
68588 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68589 const char *sym = NULL;
68590 unsigned int i = *(loff_t *) v;
68591 unsigned long offset = 0;
68592 - char *modname, namebuf[128];
68593 + char *modname, namebuf[KSYM_NAME_LEN];
68594
68595 head = &kprobe_table[i];
68596 preempt_disable();
68597 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68598 index 4e316e1..5501eef 100644
68599 --- a/kernel/ksysfs.c
68600 +++ b/kernel/ksysfs.c
68601 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68602 {
68603 if (count+1 > UEVENT_HELPER_PATH_LEN)
68604 return -ENOENT;
68605 + if (!capable(CAP_SYS_ADMIN))
68606 + return -EPERM;
68607 memcpy(uevent_helper, buf, count);
68608 uevent_helper[count] = '\0';
68609 if (count && uevent_helper[count-1] == '\n')
68610 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68611 index ea9ee45..67ebc8f 100644
68612 --- a/kernel/lockdep.c
68613 +++ b/kernel/lockdep.c
68614 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
68615 end = (unsigned long) &_end,
68616 addr = (unsigned long) obj;
68617
68618 +#ifdef CONFIG_PAX_KERNEXEC
68619 + start = ktla_ktva(start);
68620 +#endif
68621 +
68622 /*
68623 * static variable?
68624 */
68625 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68626 if (!static_obj(lock->key)) {
68627 debug_locks_off();
68628 printk("INFO: trying to register non-static key.\n");
68629 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68630 printk("the code is fine but needs lockdep annotation.\n");
68631 printk("turning off the locking correctness validator.\n");
68632 dump_stack();
68633 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68634 if (!class)
68635 return 0;
68636 }
68637 - atomic_inc((atomic_t *)&class->ops);
68638 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68639 if (very_verbose(class)) {
68640 printk("\nacquire class [%p] %s", class->key, class->name);
68641 if (class->name_version > 1)
68642 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68643 index 91c32a0..7b88d63 100644
68644 --- a/kernel/lockdep_proc.c
68645 +++ b/kernel/lockdep_proc.c
68646 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68647
68648 static void print_name(struct seq_file *m, struct lock_class *class)
68649 {
68650 - char str[128];
68651 + char str[KSYM_NAME_LEN];
68652 const char *name = class->name;
68653
68654 if (!name) {
68655 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68656 return 0;
68657 }
68658
68659 - seq_printf(m, "%p", class->key);
68660 + seq_printf(m, "%pK", class->key);
68661 #ifdef CONFIG_DEBUG_LOCKDEP
68662 seq_printf(m, " OPS:%8ld", class->ops);
68663 #endif
68664 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68665
68666 list_for_each_entry(entry, &class->locks_after, entry) {
68667 if (entry->distance == 1) {
68668 - seq_printf(m, " -> [%p] ", entry->class->key);
68669 + seq_printf(m, " -> [%pK] ", entry->class->key);
68670 print_name(m, entry->class);
68671 seq_puts(m, "\n");
68672 }
68673 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68674 if (!class->key)
68675 continue;
68676
68677 - seq_printf(m, "[%p] ", class->key);
68678 + seq_printf(m, "[%pK] ", class->key);
68679 print_name(m, class);
68680 seq_puts(m, "\n");
68681 }
68682 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68683 if (!i)
68684 seq_line(m, '-', 40-namelen, namelen);
68685
68686 - snprintf(ip, sizeof(ip), "[<%p>]",
68687 + snprintf(ip, sizeof(ip), "[<%pK>]",
68688 (void *)class->contention_point[i]);
68689 seq_printf(m, "%40s %14lu %29s %pS\n",
68690 name, stats->contention_point[i],
68691 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68692 if (!i)
68693 seq_line(m, '-', 40-namelen, namelen);
68694
68695 - snprintf(ip, sizeof(ip), "[<%p>]",
68696 + snprintf(ip, sizeof(ip), "[<%pK>]",
68697 (void *)class->contending_point[i]);
68698 seq_printf(m, "%40s %14lu %29s %pS\n",
68699 name, stats->contending_point[i],
68700 diff --git a/kernel/module.c b/kernel/module.c
68701 index 2a15c59..731c128 100644
68702 --- a/kernel/module.c
68703 +++ b/kernel/module.c
68704 @@ -58,6 +58,7 @@
68705 #include <linux/jump_label.h>
68706 #include <linux/pfn.h>
68707 #include <linux/bsearch.h>
68708 +#include <linux/grsecurity.h>
68709
68710 #define CREATE_TRACE_POINTS
68711 #include <trace/events/module.h>
68712 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68713
68714 /* Bounds of module allocation, for speeding __module_address.
68715 * Protected by module_mutex. */
68716 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68717 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68718 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68719
68720 int register_module_notifier(struct notifier_block * nb)
68721 {
68722 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68723 return true;
68724
68725 list_for_each_entry_rcu(mod, &modules, list) {
68726 - struct symsearch arr[] = {
68727 + struct symsearch modarr[] = {
68728 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68729 NOT_GPL_ONLY, false },
68730 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68731 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68732 #endif
68733 };
68734
68735 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68736 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68737 return true;
68738 }
68739 return false;
68740 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68741 static int percpu_modalloc(struct module *mod,
68742 unsigned long size, unsigned long align)
68743 {
68744 - if (align > PAGE_SIZE) {
68745 + if (align-1 >= PAGE_SIZE) {
68746 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68747 mod->name, align, PAGE_SIZE);
68748 align = PAGE_SIZE;
68749 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68750 static ssize_t show_coresize(struct module_attribute *mattr,
68751 struct module_kobject *mk, char *buffer)
68752 {
68753 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68754 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68755 }
68756
68757 static struct module_attribute modinfo_coresize =
68758 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68759 static ssize_t show_initsize(struct module_attribute *mattr,
68760 struct module_kobject *mk, char *buffer)
68761 {
68762 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68763 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68764 }
68765
68766 static struct module_attribute modinfo_initsize =
68767 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68768 */
68769 #ifdef CONFIG_SYSFS
68770
68771 -#ifdef CONFIG_KALLSYMS
68772 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68773 static inline bool sect_empty(const Elf_Shdr *sect)
68774 {
68775 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68776 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68777
68778 static void unset_module_core_ro_nx(struct module *mod)
68779 {
68780 - set_page_attributes(mod->module_core + mod->core_text_size,
68781 - mod->module_core + mod->core_size,
68782 + set_page_attributes(mod->module_core_rw,
68783 + mod->module_core_rw + mod->core_size_rw,
68784 set_memory_x);
68785 - set_page_attributes(mod->module_core,
68786 - mod->module_core + mod->core_ro_size,
68787 + set_page_attributes(mod->module_core_rx,
68788 + mod->module_core_rx + mod->core_size_rx,
68789 set_memory_rw);
68790 }
68791
68792 static void unset_module_init_ro_nx(struct module *mod)
68793 {
68794 - set_page_attributes(mod->module_init + mod->init_text_size,
68795 - mod->module_init + mod->init_size,
68796 + set_page_attributes(mod->module_init_rw,
68797 + mod->module_init_rw + mod->init_size_rw,
68798 set_memory_x);
68799 - set_page_attributes(mod->module_init,
68800 - mod->module_init + mod->init_ro_size,
68801 + set_page_attributes(mod->module_init_rx,
68802 + mod->module_init_rx + mod->init_size_rx,
68803 set_memory_rw);
68804 }
68805
68806 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68807
68808 mutex_lock(&module_mutex);
68809 list_for_each_entry_rcu(mod, &modules, list) {
68810 - if ((mod->module_core) && (mod->core_text_size)) {
68811 - set_page_attributes(mod->module_core,
68812 - mod->module_core + mod->core_text_size,
68813 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68814 + set_page_attributes(mod->module_core_rx,
68815 + mod->module_core_rx + mod->core_size_rx,
68816 set_memory_rw);
68817 }
68818 - if ((mod->module_init) && (mod->init_text_size)) {
68819 - set_page_attributes(mod->module_init,
68820 - mod->module_init + mod->init_text_size,
68821 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68822 + set_page_attributes(mod->module_init_rx,
68823 + mod->module_init_rx + mod->init_size_rx,
68824 set_memory_rw);
68825 }
68826 }
68827 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68828
68829 mutex_lock(&module_mutex);
68830 list_for_each_entry_rcu(mod, &modules, list) {
68831 - if ((mod->module_core) && (mod->core_text_size)) {
68832 - set_page_attributes(mod->module_core,
68833 - mod->module_core + mod->core_text_size,
68834 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68835 + set_page_attributes(mod->module_core_rx,
68836 + mod->module_core_rx + mod->core_size_rx,
68837 set_memory_ro);
68838 }
68839 - if ((mod->module_init) && (mod->init_text_size)) {
68840 - set_page_attributes(mod->module_init,
68841 - mod->module_init + mod->init_text_size,
68842 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68843 + set_page_attributes(mod->module_init_rx,
68844 + mod->module_init_rx + mod->init_size_rx,
68845 set_memory_ro);
68846 }
68847 }
68848 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68849
68850 /* This may be NULL, but that's OK */
68851 unset_module_init_ro_nx(mod);
68852 - module_free(mod, mod->module_init);
68853 + module_free(mod, mod->module_init_rw);
68854 + module_free_exec(mod, mod->module_init_rx);
68855 kfree(mod->args);
68856 percpu_modfree(mod);
68857
68858 /* Free lock-classes: */
68859 - lockdep_free_key_range(mod->module_core, mod->core_size);
68860 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68861 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68862
68863 /* Finally, free the core (containing the module structure) */
68864 unset_module_core_ro_nx(mod);
68865 - module_free(mod, mod->module_core);
68866 + module_free_exec(mod, mod->module_core_rx);
68867 + module_free(mod, mod->module_core_rw);
68868
68869 #ifdef CONFIG_MPU
68870 update_protections(current->mm);
68871 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68872 int ret = 0;
68873 const struct kernel_symbol *ksym;
68874
68875 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68876 + int is_fs_load = 0;
68877 + int register_filesystem_found = 0;
68878 + char *p;
68879 +
68880 + p = strstr(mod->args, "grsec_modharden_fs");
68881 + if (p) {
68882 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
68883 + /* copy \0 as well */
68884 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68885 + is_fs_load = 1;
68886 + }
68887 +#endif
68888 +
68889 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68890 const char *name = info->strtab + sym[i].st_name;
68891
68892 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68893 + /* it's a real shame this will never get ripped and copied
68894 + upstream! ;(
68895 + */
68896 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68897 + register_filesystem_found = 1;
68898 +#endif
68899 +
68900 switch (sym[i].st_shndx) {
68901 case SHN_COMMON:
68902 /* We compiled with -fno-common. These are not
68903 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68904 ksym = resolve_symbol_wait(mod, info, name);
68905 /* Ok if resolved. */
68906 if (ksym && !IS_ERR(ksym)) {
68907 + pax_open_kernel();
68908 sym[i].st_value = ksym->value;
68909 + pax_close_kernel();
68910 break;
68911 }
68912
68913 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68914 secbase = (unsigned long)mod_percpu(mod);
68915 else
68916 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68917 + pax_open_kernel();
68918 sym[i].st_value += secbase;
68919 + pax_close_kernel();
68920 break;
68921 }
68922 }
68923
68924 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68925 + if (is_fs_load && !register_filesystem_found) {
68926 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68927 + ret = -EPERM;
68928 + }
68929 +#endif
68930 +
68931 return ret;
68932 }
68933
68934 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68935 || s->sh_entsize != ~0UL
68936 || strstarts(sname, ".init"))
68937 continue;
68938 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68939 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68940 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68941 + else
68942 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68943 pr_debug("\t%s\n", sname);
68944 }
68945 - switch (m) {
68946 - case 0: /* executable */
68947 - mod->core_size = debug_align(mod->core_size);
68948 - mod->core_text_size = mod->core_size;
68949 - break;
68950 - case 1: /* RO: text and ro-data */
68951 - mod->core_size = debug_align(mod->core_size);
68952 - mod->core_ro_size = mod->core_size;
68953 - break;
68954 - case 3: /* whole core */
68955 - mod->core_size = debug_align(mod->core_size);
68956 - break;
68957 - }
68958 }
68959
68960 pr_debug("Init section allocation order:\n");
68961 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68962 || s->sh_entsize != ~0UL
68963 || !strstarts(sname, ".init"))
68964 continue;
68965 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68966 - | INIT_OFFSET_MASK);
68967 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68968 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68969 + else
68970 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68971 + s->sh_entsize |= INIT_OFFSET_MASK;
68972 pr_debug("\t%s\n", sname);
68973 }
68974 - switch (m) {
68975 - case 0: /* executable */
68976 - mod->init_size = debug_align(mod->init_size);
68977 - mod->init_text_size = mod->init_size;
68978 - break;
68979 - case 1: /* RO: text and ro-data */
68980 - mod->init_size = debug_align(mod->init_size);
68981 - mod->init_ro_size = mod->init_size;
68982 - break;
68983 - case 3: /* whole init */
68984 - mod->init_size = debug_align(mod->init_size);
68985 - break;
68986 - }
68987 }
68988 }
68989
68990 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68991
68992 /* Put symbol section at end of init part of module. */
68993 symsect->sh_flags |= SHF_ALLOC;
68994 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68995 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68996 info->index.sym) | INIT_OFFSET_MASK;
68997 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68998
68999 @@ -2286,13 +2304,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
69000 }
69001
69002 /* Append room for core symbols at end of core part. */
69003 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
69004 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
69005 - mod->core_size += strtab_size;
69006 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
69007 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
69008 + mod->core_size_rx += strtab_size;
69009
69010 /* Put string table section at end of init part of module. */
69011 strsect->sh_flags |= SHF_ALLOC;
69012 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
69013 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
69014 info->index.str) | INIT_OFFSET_MASK;
69015 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
69016 }
69017 @@ -2310,12 +2328,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
69018 /* Make sure we get permanent strtab: don't use info->strtab. */
69019 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
69020
69021 + pax_open_kernel();
69022 +
69023 /* Set types up while we still have access to sections. */
69024 for (i = 0; i < mod->num_symtab; i++)
69025 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
69026
69027 - mod->core_symtab = dst = mod->module_core + info->symoffs;
69028 - mod->core_strtab = s = mod->module_core + info->stroffs;
69029 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
69030 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
69031 src = mod->symtab;
69032 *s++ = 0;
69033 for (ndst = i = 0; i < mod->num_symtab; i++) {
69034 @@ -2328,6 +2348,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
69035 }
69036 }
69037 mod->core_num_syms = ndst;
69038 +
69039 + pax_close_kernel();
69040 }
69041 #else
69042 static inline void layout_symtab(struct module *mod, struct load_info *info)
69043 @@ -2361,17 +2383,33 @@ void * __weak module_alloc(unsigned long size)
69044 return size == 0 ? NULL : vmalloc_exec(size);
69045 }
69046
69047 -static void *module_alloc_update_bounds(unsigned long size)
69048 +static void *module_alloc_update_bounds_rw(unsigned long size)
69049 {
69050 void *ret = module_alloc(size);
69051
69052 if (ret) {
69053 mutex_lock(&module_mutex);
69054 /* Update module bounds. */
69055 - if ((unsigned long)ret < module_addr_min)
69056 - module_addr_min = (unsigned long)ret;
69057 - if ((unsigned long)ret + size > module_addr_max)
69058 - module_addr_max = (unsigned long)ret + size;
69059 + if ((unsigned long)ret < module_addr_min_rw)
69060 + module_addr_min_rw = (unsigned long)ret;
69061 + if ((unsigned long)ret + size > module_addr_max_rw)
69062 + module_addr_max_rw = (unsigned long)ret + size;
69063 + mutex_unlock(&module_mutex);
69064 + }
69065 + return ret;
69066 +}
69067 +
69068 +static void *module_alloc_update_bounds_rx(unsigned long size)
69069 +{
69070 + void *ret = module_alloc_exec(size);
69071 +
69072 + if (ret) {
69073 + mutex_lock(&module_mutex);
69074 + /* Update module bounds. */
69075 + if ((unsigned long)ret < module_addr_min_rx)
69076 + module_addr_min_rx = (unsigned long)ret;
69077 + if ((unsigned long)ret + size > module_addr_max_rx)
69078 + module_addr_max_rx = (unsigned long)ret + size;
69079 mutex_unlock(&module_mutex);
69080 }
69081 return ret;
69082 @@ -2549,8 +2587,14 @@ static struct module *setup_load_info(struct load_info *info)
69083 static int check_modinfo(struct module *mod, struct load_info *info)
69084 {
69085 const char *modmagic = get_modinfo(info, "vermagic");
69086 + const char *license = get_modinfo(info, "license");
69087 int err;
69088
69089 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
69090 + if (!license || !license_is_gpl_compatible(license))
69091 + return -ENOEXEC;
69092 +#endif
69093 +
69094 /* This is allowed: modprobe --force will invalidate it. */
69095 if (!modmagic) {
69096 err = try_to_force_load(mod, "bad vermagic");
69097 @@ -2573,7 +2617,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
69098 }
69099
69100 /* Set up license info based on the info section */
69101 - set_license(mod, get_modinfo(info, "license"));
69102 + set_license(mod, license);
69103
69104 return 0;
69105 }
69106 @@ -2667,7 +2711,7 @@ static int move_module(struct module *mod, struct load_info *info)
69107 void *ptr;
69108
69109 /* Do the allocs. */
69110 - ptr = module_alloc_update_bounds(mod->core_size);
69111 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
69112 /*
69113 * The pointer to this block is stored in the module structure
69114 * which is inside the block. Just mark it as not being a
69115 @@ -2677,23 +2721,50 @@ static int move_module(struct module *mod, struct load_info *info)
69116 if (!ptr)
69117 return -ENOMEM;
69118
69119 - memset(ptr, 0, mod->core_size);
69120 - mod->module_core = ptr;
69121 + memset(ptr, 0, mod->core_size_rw);
69122 + mod->module_core_rw = ptr;
69123
69124 - ptr = module_alloc_update_bounds(mod->init_size);
69125 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
69126 /*
69127 * The pointer to this block is stored in the module structure
69128 * which is inside the block. This block doesn't need to be
69129 * scanned as it contains data and code that will be freed
69130 * after the module is initialized.
69131 */
69132 - kmemleak_ignore(ptr);
69133 - if (!ptr && mod->init_size) {
69134 - module_free(mod, mod->module_core);
69135 + kmemleak_not_leak(ptr);
69136 + if (!ptr && mod->init_size_rw) {
69137 + module_free(mod, mod->module_core_rw);
69138 return -ENOMEM;
69139 }
69140 - memset(ptr, 0, mod->init_size);
69141 - mod->module_init = ptr;
69142 + memset(ptr, 0, mod->init_size_rw);
69143 + mod->module_init_rw = ptr;
69144 +
69145 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
69146 + kmemleak_not_leak(ptr);
69147 + if (!ptr) {
69148 + module_free(mod, mod->module_init_rw);
69149 + module_free(mod, mod->module_core_rw);
69150 + return -ENOMEM;
69151 + }
69152 +
69153 + pax_open_kernel();
69154 + memset(ptr, 0, mod->core_size_rx);
69155 + pax_close_kernel();
69156 + mod->module_core_rx = ptr;
69157 +
69158 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
69159 + kmemleak_not_leak(ptr);
69160 + if (!ptr && mod->init_size_rx) {
69161 + module_free_exec(mod, mod->module_core_rx);
69162 + module_free(mod, mod->module_init_rw);
69163 + module_free(mod, mod->module_core_rw);
69164 + return -ENOMEM;
69165 + }
69166 +
69167 + pax_open_kernel();
69168 + memset(ptr, 0, mod->init_size_rx);
69169 + pax_close_kernel();
69170 + mod->module_init_rx = ptr;
69171
69172 /* Transfer each section which specifies SHF_ALLOC */
69173 pr_debug("final section addresses:\n");
69174 @@ -2704,16 +2775,45 @@ static int move_module(struct module *mod, struct load_info *info)
69175 if (!(shdr->sh_flags & SHF_ALLOC))
69176 continue;
69177
69178 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
69179 - dest = mod->module_init
69180 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69181 - else
69182 - dest = mod->module_core + shdr->sh_entsize;
69183 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
69184 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
69185 + dest = mod->module_init_rw
69186 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69187 + else
69188 + dest = mod->module_init_rx
69189 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69190 + } else {
69191 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
69192 + dest = mod->module_core_rw + shdr->sh_entsize;
69193 + else
69194 + dest = mod->module_core_rx + shdr->sh_entsize;
69195 + }
69196 +
69197 + if (shdr->sh_type != SHT_NOBITS) {
69198 +
69199 +#ifdef CONFIG_PAX_KERNEXEC
69200 +#ifdef CONFIG_X86_64
69201 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
69202 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
69203 +#endif
69204 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
69205 + pax_open_kernel();
69206 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
69207 + pax_close_kernel();
69208 + } else
69209 +#endif
69210
69211 - if (shdr->sh_type != SHT_NOBITS)
69212 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
69213 + }
69214 /* Update sh_addr to point to copy in image. */
69215 - shdr->sh_addr = (unsigned long)dest;
69216 +
69217 +#ifdef CONFIG_PAX_KERNEXEC
69218 + if (shdr->sh_flags & SHF_EXECINSTR)
69219 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
69220 + else
69221 +#endif
69222 +
69223 + shdr->sh_addr = (unsigned long)dest;
69224 pr_debug("\t0x%lx %s\n",
69225 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
69226 }
69227 @@ -2768,12 +2868,12 @@ static void flush_module_icache(const struct module *mod)
69228 * Do it before processing of module parameters, so the module
69229 * can provide parameter accessor functions of its own.
69230 */
69231 - if (mod->module_init)
69232 - flush_icache_range((unsigned long)mod->module_init,
69233 - (unsigned long)mod->module_init
69234 - + mod->init_size);
69235 - flush_icache_range((unsigned long)mod->module_core,
69236 - (unsigned long)mod->module_core + mod->core_size);
69237 + if (mod->module_init_rx)
69238 + flush_icache_range((unsigned long)mod->module_init_rx,
69239 + (unsigned long)mod->module_init_rx
69240 + + mod->init_size_rx);
69241 + flush_icache_range((unsigned long)mod->module_core_rx,
69242 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
69243
69244 set_fs(old_fs);
69245 }
69246 @@ -2843,8 +2943,10 @@ out:
69247 static void module_deallocate(struct module *mod, struct load_info *info)
69248 {
69249 percpu_modfree(mod);
69250 - module_free(mod, mod->module_init);
69251 - module_free(mod, mod->module_core);
69252 + module_free_exec(mod, mod->module_init_rx);
69253 + module_free_exec(mod, mod->module_core_rx);
69254 + module_free(mod, mod->module_init_rw);
69255 + module_free(mod, mod->module_core_rw);
69256 }
69257
69258 int __weak module_finalize(const Elf_Ehdr *hdr,
69259 @@ -2857,7 +2959,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
69260 static int post_relocation(struct module *mod, const struct load_info *info)
69261 {
69262 /* Sort exception table now relocations are done. */
69263 + pax_open_kernel();
69264 sort_extable(mod->extable, mod->extable + mod->num_exentries);
69265 + pax_close_kernel();
69266
69267 /* Copy relocated percpu area over. */
69268 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
69269 @@ -2908,9 +3012,38 @@ static struct module *load_module(void __user *umod,
69270 if (err)
69271 goto free_unload;
69272
69273 + /* Now copy in args */
69274 + mod->args = strndup_user(uargs, ~0UL >> 1);
69275 + if (IS_ERR(mod->args)) {
69276 + err = PTR_ERR(mod->args);
69277 + goto free_unload;
69278 + }
69279 +
69280 /* Set up MODINFO_ATTR fields */
69281 setup_modinfo(mod, &info);
69282
69283 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69284 + {
69285 + char *p, *p2;
69286 +
69287 + if (strstr(mod->args, "grsec_modharden_netdev")) {
69288 + 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);
69289 + err = -EPERM;
69290 + goto free_modinfo;
69291 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
69292 + p += sizeof("grsec_modharden_normal") - 1;
69293 + p2 = strstr(p, "_");
69294 + if (p2) {
69295 + *p2 = '\0';
69296 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
69297 + *p2 = '_';
69298 + }
69299 + err = -EPERM;
69300 + goto free_modinfo;
69301 + }
69302 + }
69303 +#endif
69304 +
69305 /* Fix up syms, so that st_value is a pointer to location. */
69306 err = simplify_symbols(mod, &info);
69307 if (err < 0)
69308 @@ -2926,13 +3059,6 @@ static struct module *load_module(void __user *umod,
69309
69310 flush_module_icache(mod);
69311
69312 - /* Now copy in args */
69313 - mod->args = strndup_user(uargs, ~0UL >> 1);
69314 - if (IS_ERR(mod->args)) {
69315 - err = PTR_ERR(mod->args);
69316 - goto free_arch_cleanup;
69317 - }
69318 -
69319 /* Mark state as coming so strong_try_module_get() ignores us. */
69320 mod->state = MODULE_STATE_COMING;
69321
69322 @@ -2990,11 +3116,10 @@ static struct module *load_module(void __user *umod,
69323 unlock:
69324 mutex_unlock(&module_mutex);
69325 synchronize_sched();
69326 - kfree(mod->args);
69327 - free_arch_cleanup:
69328 module_arch_cleanup(mod);
69329 free_modinfo:
69330 free_modinfo(mod);
69331 + kfree(mod->args);
69332 free_unload:
69333 module_unload_free(mod);
69334 free_module:
69335 @@ -3035,16 +3160,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69336 MODULE_STATE_COMING, mod);
69337
69338 /* Set RO and NX regions for core */
69339 - set_section_ro_nx(mod->module_core,
69340 - mod->core_text_size,
69341 - mod->core_ro_size,
69342 - mod->core_size);
69343 + set_section_ro_nx(mod->module_core_rx,
69344 + mod->core_size_rx,
69345 + mod->core_size_rx,
69346 + mod->core_size_rx);
69347
69348 /* Set RO and NX regions for init */
69349 - set_section_ro_nx(mod->module_init,
69350 - mod->init_text_size,
69351 - mod->init_ro_size,
69352 - mod->init_size);
69353 + set_section_ro_nx(mod->module_init_rx,
69354 + mod->init_size_rx,
69355 + mod->init_size_rx,
69356 + mod->init_size_rx);
69357
69358 do_mod_ctors(mod);
69359 /* Start the module */
69360 @@ -3090,11 +3215,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69361 mod->strtab = mod->core_strtab;
69362 #endif
69363 unset_module_init_ro_nx(mod);
69364 - module_free(mod, mod->module_init);
69365 - mod->module_init = NULL;
69366 - mod->init_size = 0;
69367 - mod->init_ro_size = 0;
69368 - mod->init_text_size = 0;
69369 + module_free(mod, mod->module_init_rw);
69370 + module_free_exec(mod, mod->module_init_rx);
69371 + mod->module_init_rw = NULL;
69372 + mod->module_init_rx = NULL;
69373 + mod->init_size_rw = 0;
69374 + mod->init_size_rx = 0;
69375 mutex_unlock(&module_mutex);
69376
69377 return 0;
69378 @@ -3125,10 +3251,16 @@ static const char *get_ksymbol(struct module *mod,
69379 unsigned long nextval;
69380
69381 /* At worse, next value is at end of module */
69382 - if (within_module_init(addr, mod))
69383 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
69384 + if (within_module_init_rx(addr, mod))
69385 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
69386 + else if (within_module_init_rw(addr, mod))
69387 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
69388 + else if (within_module_core_rx(addr, mod))
69389 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
69390 + else if (within_module_core_rw(addr, mod))
69391 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
69392 else
69393 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
69394 + return NULL;
69395
69396 /* Scan for closest preceding symbol, and next symbol. (ELF
69397 starts real symbols at 1). */
69398 @@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
69399 char buf[8];
69400
69401 seq_printf(m, "%s %u",
69402 - mod->name, mod->init_size + mod->core_size);
69403 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
69404 print_unload_info(m, mod);
69405
69406 /* Informative for users. */
69407 @@ -3372,7 +3504,7 @@ static int m_show(struct seq_file *m, void *p)
69408 mod->state == MODULE_STATE_COMING ? "Loading":
69409 "Live");
69410 /* Used by oprofile and other similar tools. */
69411 - seq_printf(m, " 0x%pK", mod->module_core);
69412 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
69413
69414 /* Taints info */
69415 if (mod->taints)
69416 @@ -3408,7 +3540,17 @@ static const struct file_operations proc_modules_operations = {
69417
69418 static int __init proc_modules_init(void)
69419 {
69420 +#ifndef CONFIG_GRKERNSEC_HIDESYM
69421 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69422 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69423 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69424 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
69425 +#else
69426 proc_create("modules", 0, NULL, &proc_modules_operations);
69427 +#endif
69428 +#else
69429 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69430 +#endif
69431 return 0;
69432 }
69433 module_init(proc_modules_init);
69434 @@ -3467,12 +3609,12 @@ struct module *__module_address(unsigned long addr)
69435 {
69436 struct module *mod;
69437
69438 - if (addr < module_addr_min || addr > module_addr_max)
69439 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
69440 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
69441 return NULL;
69442
69443 list_for_each_entry_rcu(mod, &modules, list)
69444 - if (within_module_core(addr, mod)
69445 - || within_module_init(addr, mod))
69446 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
69447 return mod;
69448 return NULL;
69449 }
69450 @@ -3506,11 +3648,20 @@ bool is_module_text_address(unsigned long addr)
69451 */
69452 struct module *__module_text_address(unsigned long addr)
69453 {
69454 - struct module *mod = __module_address(addr);
69455 + struct module *mod;
69456 +
69457 +#ifdef CONFIG_X86_32
69458 + addr = ktla_ktva(addr);
69459 +#endif
69460 +
69461 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
69462 + return NULL;
69463 +
69464 + mod = __module_address(addr);
69465 +
69466 if (mod) {
69467 /* Make sure it's within the text section. */
69468 - if (!within(addr, mod->module_init, mod->init_text_size)
69469 - && !within(addr, mod->module_core, mod->core_text_size))
69470 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
69471 mod = NULL;
69472 }
69473 return mod;
69474 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
69475 index 7e3443f..b2a1e6b 100644
69476 --- a/kernel/mutex-debug.c
69477 +++ b/kernel/mutex-debug.c
69478 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
69479 }
69480
69481 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69482 - struct thread_info *ti)
69483 + struct task_struct *task)
69484 {
69485 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
69486
69487 /* Mark the current thread as blocked on the lock: */
69488 - ti->task->blocked_on = waiter;
69489 + task->blocked_on = waiter;
69490 }
69491
69492 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69493 - struct thread_info *ti)
69494 + struct task_struct *task)
69495 {
69496 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
69497 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
69498 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
69499 - ti->task->blocked_on = NULL;
69500 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
69501 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
69502 + task->blocked_on = NULL;
69503
69504 list_del_init(&waiter->list);
69505 waiter->task = NULL;
69506 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
69507 index 0799fd3..d06ae3b 100644
69508 --- a/kernel/mutex-debug.h
69509 +++ b/kernel/mutex-debug.h
69510 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
69511 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
69512 extern void debug_mutex_add_waiter(struct mutex *lock,
69513 struct mutex_waiter *waiter,
69514 - struct thread_info *ti);
69515 + struct task_struct *task);
69516 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69517 - struct thread_info *ti);
69518 + struct task_struct *task);
69519 extern void debug_mutex_unlock(struct mutex *lock);
69520 extern void debug_mutex_init(struct mutex *lock, const char *name,
69521 struct lock_class_key *key);
69522 diff --git a/kernel/mutex.c b/kernel/mutex.c
69523 index a307cc9..27fd2e9 100644
69524 --- a/kernel/mutex.c
69525 +++ b/kernel/mutex.c
69526 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69527 spin_lock_mutex(&lock->wait_lock, flags);
69528
69529 debug_mutex_lock_common(lock, &waiter);
69530 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69531 + debug_mutex_add_waiter(lock, &waiter, task);
69532
69533 /* add waiting tasks to the end of the waitqueue (FIFO): */
69534 list_add_tail(&waiter.list, &lock->wait_list);
69535 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69536 * TASK_UNINTERRUPTIBLE case.)
69537 */
69538 if (unlikely(signal_pending_state(state, task))) {
69539 - mutex_remove_waiter(lock, &waiter,
69540 - task_thread_info(task));
69541 + mutex_remove_waiter(lock, &waiter, task);
69542 mutex_release(&lock->dep_map, 1, ip);
69543 spin_unlock_mutex(&lock->wait_lock, flags);
69544
69545 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69546 done:
69547 lock_acquired(&lock->dep_map, ip);
69548 /* got the lock - rejoice! */
69549 - mutex_remove_waiter(lock, &waiter, current_thread_info());
69550 + mutex_remove_waiter(lock, &waiter, task);
69551 mutex_set_owner(lock);
69552
69553 /* set it to 0 if there are no waiters left: */
69554 diff --git a/kernel/panic.c b/kernel/panic.c
69555 index e1b2822..5edc1d9 100644
69556 --- a/kernel/panic.c
69557 +++ b/kernel/panic.c
69558 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69559 const char *board;
69560
69561 printk(KERN_WARNING "------------[ cut here ]------------\n");
69562 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69563 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69564 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69565 if (board)
69566 printk(KERN_WARNING "Hardware name: %s\n", board);
69567 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69568 */
69569 void __stack_chk_fail(void)
69570 {
69571 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
69572 + dump_stack();
69573 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69574 __builtin_return_address(0));
69575 }
69576 EXPORT_SYMBOL(__stack_chk_fail);
69577 diff --git a/kernel/pid.c b/kernel/pid.c
69578 index e86b291a..e8b0fb5 100644
69579 --- a/kernel/pid.c
69580 +++ b/kernel/pid.c
69581 @@ -33,6 +33,7 @@
69582 #include <linux/rculist.h>
69583 #include <linux/bootmem.h>
69584 #include <linux/hash.h>
69585 +#include <linux/security.h>
69586 #include <linux/pid_namespace.h>
69587 #include <linux/init_task.h>
69588 #include <linux/syscalls.h>
69589 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69590
69591 int pid_max = PID_MAX_DEFAULT;
69592
69593 -#define RESERVED_PIDS 300
69594 +#define RESERVED_PIDS 500
69595
69596 int pid_max_min = RESERVED_PIDS + 1;
69597 int pid_max_max = PID_MAX_LIMIT;
69598 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69599 */
69600 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69601 {
69602 + struct task_struct *task;
69603 +
69604 rcu_lockdep_assert(rcu_read_lock_held(),
69605 "find_task_by_pid_ns() needs rcu_read_lock()"
69606 " protection");
69607 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69608 +
69609 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69610 +
69611 + if (gr_pid_is_chrooted(task))
69612 + return NULL;
69613 +
69614 + return task;
69615 }
69616
69617 struct task_struct *find_task_by_vpid(pid_t vnr)
69618 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69619 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69620 }
69621
69622 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69623 +{
69624 + rcu_lockdep_assert(rcu_read_lock_held(),
69625 + "find_task_by_pid_ns() needs rcu_read_lock()"
69626 + " protection");
69627 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69628 +}
69629 +
69630 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69631 {
69632 struct pid *pid;
69633 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69634 index 125cb67..a4d1c30 100644
69635 --- a/kernel/posix-cpu-timers.c
69636 +++ b/kernel/posix-cpu-timers.c
69637 @@ -6,6 +6,7 @@
69638 #include <linux/posix-timers.h>
69639 #include <linux/errno.h>
69640 #include <linux/math64.h>
69641 +#include <linux/security.h>
69642 #include <asm/uaccess.h>
69643 #include <linux/kernel_stat.h>
69644 #include <trace/events/timer.h>
69645 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69646
69647 static __init int init_posix_cpu_timers(void)
69648 {
69649 - struct k_clock process = {
69650 + static struct k_clock process = {
69651 .clock_getres = process_cpu_clock_getres,
69652 .clock_get = process_cpu_clock_get,
69653 .timer_create = process_cpu_timer_create,
69654 .nsleep = process_cpu_nsleep,
69655 .nsleep_restart = process_cpu_nsleep_restart,
69656 };
69657 - struct k_clock thread = {
69658 + static struct k_clock thread = {
69659 .clock_getres = thread_cpu_clock_getres,
69660 .clock_get = thread_cpu_clock_get,
69661 .timer_create = thread_cpu_timer_create,
69662 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69663 index 69185ae..cc2847a 100644
69664 --- a/kernel/posix-timers.c
69665 +++ b/kernel/posix-timers.c
69666 @@ -43,6 +43,7 @@
69667 #include <linux/idr.h>
69668 #include <linux/posix-clock.h>
69669 #include <linux/posix-timers.h>
69670 +#include <linux/grsecurity.h>
69671 #include <linux/syscalls.h>
69672 #include <linux/wait.h>
69673 #include <linux/workqueue.h>
69674 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69675 * which we beg off on and pass to do_sys_settimeofday().
69676 */
69677
69678 -static struct k_clock posix_clocks[MAX_CLOCKS];
69679 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69680
69681 /*
69682 * These ones are defined below.
69683 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69684 */
69685 static __init int init_posix_timers(void)
69686 {
69687 - struct k_clock clock_realtime = {
69688 + static struct k_clock clock_realtime = {
69689 .clock_getres = hrtimer_get_res,
69690 .clock_get = posix_clock_realtime_get,
69691 .clock_set = posix_clock_realtime_set,
69692 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69693 .timer_get = common_timer_get,
69694 .timer_del = common_timer_del,
69695 };
69696 - struct k_clock clock_monotonic = {
69697 + static struct k_clock clock_monotonic = {
69698 .clock_getres = hrtimer_get_res,
69699 .clock_get = posix_ktime_get_ts,
69700 .nsleep = common_nsleep,
69701 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69702 .timer_get = common_timer_get,
69703 .timer_del = common_timer_del,
69704 };
69705 - struct k_clock clock_monotonic_raw = {
69706 + static struct k_clock clock_monotonic_raw = {
69707 .clock_getres = hrtimer_get_res,
69708 .clock_get = posix_get_monotonic_raw,
69709 };
69710 - struct k_clock clock_realtime_coarse = {
69711 + static struct k_clock clock_realtime_coarse = {
69712 .clock_getres = posix_get_coarse_res,
69713 .clock_get = posix_get_realtime_coarse,
69714 };
69715 - struct k_clock clock_monotonic_coarse = {
69716 + static struct k_clock clock_monotonic_coarse = {
69717 .clock_getres = posix_get_coarse_res,
69718 .clock_get = posix_get_monotonic_coarse,
69719 };
69720 - struct k_clock clock_boottime = {
69721 + static struct k_clock clock_boottime = {
69722 .clock_getres = hrtimer_get_res,
69723 .clock_get = posix_get_boottime,
69724 .nsleep = common_nsleep,
69725 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69726 return;
69727 }
69728
69729 - posix_clocks[clock_id] = *new_clock;
69730 + posix_clocks[clock_id] = new_clock;
69731 }
69732 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69733
69734 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69735 return (id & CLOCKFD_MASK) == CLOCKFD ?
69736 &clock_posix_dynamic : &clock_posix_cpu;
69737
69738 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69739 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69740 return NULL;
69741 - return &posix_clocks[id];
69742 + return posix_clocks[id];
69743 }
69744
69745 static int common_timer_create(struct k_itimer *new_timer)
69746 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69747 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69748 return -EFAULT;
69749
69750 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69751 + have their clock_set fptr set to a nosettime dummy function
69752 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69753 + call common_clock_set, which calls do_sys_settimeofday, which
69754 + we hook
69755 + */
69756 +
69757 return kc->clock_set(which_clock, &new_tp);
69758 }
69759
69760 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69761 index d523593..68197a4 100644
69762 --- a/kernel/power/poweroff.c
69763 +++ b/kernel/power/poweroff.c
69764 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69765 .enable_mask = SYSRQ_ENABLE_BOOT,
69766 };
69767
69768 -static int pm_sysrq_init(void)
69769 +static int __init pm_sysrq_init(void)
69770 {
69771 register_sysrq_key('o', &sysrq_poweroff_op);
69772 return 0;
69773 diff --git a/kernel/power/process.c b/kernel/power/process.c
69774 index 19db29f..33b52b6 100644
69775 --- a/kernel/power/process.c
69776 +++ b/kernel/power/process.c
69777 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69778 u64 elapsed_csecs64;
69779 unsigned int elapsed_csecs;
69780 bool wakeup = false;
69781 + bool timedout = false;
69782
69783 do_gettimeofday(&start);
69784
69785 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69786
69787 while (true) {
69788 todo = 0;
69789 + if (time_after(jiffies, end_time))
69790 + timedout = true;
69791 read_lock(&tasklist_lock);
69792 do_each_thread(g, p) {
69793 if (p == current || !freeze_task(p))
69794 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69795 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69796 * transition can't race with task state testing here.
69797 */
69798 - if (!task_is_stopped_or_traced(p) &&
69799 - !freezer_should_skip(p))
69800 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69801 todo++;
69802 + if (timedout) {
69803 + printk(KERN_ERR "Task refusing to freeze:\n");
69804 + sched_show_task(p);
69805 + }
69806 + }
69807 } while_each_thread(g, p);
69808 read_unlock(&tasklist_lock);
69809
69810 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69811 todo += wq_busy;
69812 }
69813
69814 - if (!todo || time_after(jiffies, end_time))
69815 + if (!todo || timedout)
69816 break;
69817
69818 if (pm_wakeup_pending()) {
69819 diff --git a/kernel/printk.c b/kernel/printk.c
69820 index 66a2ea3..10f3a01 100644
69821 --- a/kernel/printk.c
69822 +++ b/kernel/printk.c
69823 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69824 if (from_file && type != SYSLOG_ACTION_OPEN)
69825 return 0;
69826
69827 +#ifdef CONFIG_GRKERNSEC_DMESG
69828 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69829 + return -EPERM;
69830 +#endif
69831 +
69832 if (syslog_action_restricted(type)) {
69833 if (capable(CAP_SYSLOG))
69834 return 0;
69835 diff --git a/kernel/profile.c b/kernel/profile.c
69836 index 76b8e77..a2930e8 100644
69837 --- a/kernel/profile.c
69838 +++ b/kernel/profile.c
69839 @@ -39,7 +39,7 @@ struct profile_hit {
69840 /* Oprofile timer tick hook */
69841 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69842
69843 -static atomic_t *prof_buffer;
69844 +static atomic_unchecked_t *prof_buffer;
69845 static unsigned long prof_len, prof_shift;
69846
69847 int prof_on __read_mostly;
69848 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69849 hits[i].pc = 0;
69850 continue;
69851 }
69852 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69853 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69854 hits[i].hits = hits[i].pc = 0;
69855 }
69856 }
69857 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69858 * Add the current hit(s) and flush the write-queue out
69859 * to the global buffer:
69860 */
69861 - atomic_add(nr_hits, &prof_buffer[pc]);
69862 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69863 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69864 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69865 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69866 hits[i].pc = hits[i].hits = 0;
69867 }
69868 out:
69869 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69870 {
69871 unsigned long pc;
69872 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69873 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69874 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69875 }
69876 #endif /* !CONFIG_SMP */
69877
69878 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69879 return -EFAULT;
69880 buf++; p++; count--; read++;
69881 }
69882 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69883 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69884 if (copy_to_user(buf, (void *)pnt, count))
69885 return -EFAULT;
69886 read += count;
69887 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69888 }
69889 #endif
69890 profile_discard_flip_buffers();
69891 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69892 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69893 return count;
69894 }
69895
69896 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69897 index a232bb5..2a65ef9 100644
69898 --- a/kernel/ptrace.c
69899 +++ b/kernel/ptrace.c
69900 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69901
69902 if (seize)
69903 flags |= PT_SEIZED;
69904 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69905 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69906 flags |= PT_PTRACE_CAP;
69907 task->ptrace = flags;
69908
69909 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69910 break;
69911 return -EIO;
69912 }
69913 - if (copy_to_user(dst, buf, retval))
69914 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69915 return -EFAULT;
69916 copied += retval;
69917 src += retval;
69918 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69919 bool seized = child->ptrace & PT_SEIZED;
69920 int ret = -EIO;
69921 siginfo_t siginfo, *si;
69922 - void __user *datavp = (void __user *) data;
69923 + void __user *datavp = (__force void __user *) data;
69924 unsigned long __user *datalp = datavp;
69925 unsigned long flags;
69926
69927 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69928 goto out;
69929 }
69930
69931 + if (gr_handle_ptrace(child, request)) {
69932 + ret = -EPERM;
69933 + goto out_put_task_struct;
69934 + }
69935 +
69936 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69937 ret = ptrace_attach(child, request, addr, data);
69938 /*
69939 * Some architectures need to do book-keeping after
69940 * a ptrace attach.
69941 */
69942 - if (!ret)
69943 + if (!ret) {
69944 arch_ptrace_attach(child);
69945 + gr_audit_ptrace(child);
69946 + }
69947 goto out_put_task_struct;
69948 }
69949
69950 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69951 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69952 if (copied != sizeof(tmp))
69953 return -EIO;
69954 - return put_user(tmp, (unsigned long __user *)data);
69955 + return put_user(tmp, (__force unsigned long __user *)data);
69956 }
69957
69958 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69959 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69960 goto out;
69961 }
69962
69963 + if (gr_handle_ptrace(child, request)) {
69964 + ret = -EPERM;
69965 + goto out_put_task_struct;
69966 + }
69967 +
69968 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69969 ret = ptrace_attach(child, request, addr, data);
69970 /*
69971 * Some architectures need to do book-keeping after
69972 * a ptrace attach.
69973 */
69974 - if (!ret)
69975 + if (!ret) {
69976 arch_ptrace_attach(child);
69977 + gr_audit_ptrace(child);
69978 + }
69979 goto out_put_task_struct;
69980 }
69981
69982 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69983 index 547b1fe..65e874e 100644
69984 --- a/kernel/rcutiny.c
69985 +++ b/kernel/rcutiny.c
69986 @@ -46,7 +46,7 @@
69987 struct rcu_ctrlblk;
69988 static void invoke_rcu_callbacks(void);
69989 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69990 -static void rcu_process_callbacks(struct softirq_action *unused);
69991 +static void rcu_process_callbacks(void);
69992 static void __call_rcu(struct rcu_head *head,
69993 void (*func)(struct rcu_head *rcu),
69994 struct rcu_ctrlblk *rcp);
69995 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69996 rcu_is_callbacks_kthread()));
69997 }
69998
69999 -static void rcu_process_callbacks(struct softirq_action *unused)
70000 +static void rcu_process_callbacks(void)
70001 {
70002 __rcu_process_callbacks(&rcu_sched_ctrlblk);
70003 __rcu_process_callbacks(&rcu_bh_ctrlblk);
70004 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
70005 index 918fd1e..85089bb 100644
70006 --- a/kernel/rcutiny_plugin.h
70007 +++ b/kernel/rcutiny_plugin.h
70008 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
70009 have_rcu_kthread_work = morework;
70010 local_irq_restore(flags);
70011 if (work)
70012 - rcu_process_callbacks(NULL);
70013 + rcu_process_callbacks();
70014 schedule_timeout_interruptible(1); /* Leave CPU for others. */
70015 }
70016
70017 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
70018 index 25b1503..1988a74 100644
70019 --- a/kernel/rcutorture.c
70020 +++ b/kernel/rcutorture.c
70021 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
70022 { 0 };
70023 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
70024 { 0 };
70025 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
70026 -static atomic_t n_rcu_torture_alloc;
70027 -static atomic_t n_rcu_torture_alloc_fail;
70028 -static atomic_t n_rcu_torture_free;
70029 -static atomic_t n_rcu_torture_mberror;
70030 -static atomic_t n_rcu_torture_error;
70031 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
70032 +static atomic_unchecked_t n_rcu_torture_alloc;
70033 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
70034 +static atomic_unchecked_t n_rcu_torture_free;
70035 +static atomic_unchecked_t n_rcu_torture_mberror;
70036 +static atomic_unchecked_t n_rcu_torture_error;
70037 static long n_rcu_torture_barrier_error;
70038 static long n_rcu_torture_boost_ktrerror;
70039 static long n_rcu_torture_boost_rterror;
70040 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
70041
70042 spin_lock_bh(&rcu_torture_lock);
70043 if (list_empty(&rcu_torture_freelist)) {
70044 - atomic_inc(&n_rcu_torture_alloc_fail);
70045 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
70046 spin_unlock_bh(&rcu_torture_lock);
70047 return NULL;
70048 }
70049 - atomic_inc(&n_rcu_torture_alloc);
70050 + atomic_inc_unchecked(&n_rcu_torture_alloc);
70051 p = rcu_torture_freelist.next;
70052 list_del_init(p);
70053 spin_unlock_bh(&rcu_torture_lock);
70054 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
70055 static void
70056 rcu_torture_free(struct rcu_torture *p)
70057 {
70058 - atomic_inc(&n_rcu_torture_free);
70059 + atomic_inc_unchecked(&n_rcu_torture_free);
70060 spin_lock_bh(&rcu_torture_lock);
70061 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
70062 spin_unlock_bh(&rcu_torture_lock);
70063 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
70064 i = rp->rtort_pipe_count;
70065 if (i > RCU_TORTURE_PIPE_LEN)
70066 i = RCU_TORTURE_PIPE_LEN;
70067 - atomic_inc(&rcu_torture_wcount[i]);
70068 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
70069 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
70070 rp->rtort_mbtest = 0;
70071 rcu_torture_free(rp);
70072 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
70073 i = rp->rtort_pipe_count;
70074 if (i > RCU_TORTURE_PIPE_LEN)
70075 i = RCU_TORTURE_PIPE_LEN;
70076 - atomic_inc(&rcu_torture_wcount[i]);
70077 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
70078 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
70079 rp->rtort_mbtest = 0;
70080 list_del(&rp->rtort_free);
70081 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
70082 i = old_rp->rtort_pipe_count;
70083 if (i > RCU_TORTURE_PIPE_LEN)
70084 i = RCU_TORTURE_PIPE_LEN;
70085 - atomic_inc(&rcu_torture_wcount[i]);
70086 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
70087 old_rp->rtort_pipe_count++;
70088 cur_ops->deferred_free(old_rp);
70089 }
70090 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
70091 }
70092 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
70093 if (p->rtort_mbtest == 0)
70094 - atomic_inc(&n_rcu_torture_mberror);
70095 + atomic_inc_unchecked(&n_rcu_torture_mberror);
70096 spin_lock(&rand_lock);
70097 cur_ops->read_delay(&rand);
70098 n_rcu_torture_timers++;
70099 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
70100 }
70101 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
70102 if (p->rtort_mbtest == 0)
70103 - atomic_inc(&n_rcu_torture_mberror);
70104 + atomic_inc_unchecked(&n_rcu_torture_mberror);
70105 cur_ops->read_delay(&rand);
70106 preempt_disable();
70107 pipe_count = p->rtort_pipe_count;
70108 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
70109 rcu_torture_current,
70110 rcu_torture_current_version,
70111 list_empty(&rcu_torture_freelist),
70112 - atomic_read(&n_rcu_torture_alloc),
70113 - atomic_read(&n_rcu_torture_alloc_fail),
70114 - atomic_read(&n_rcu_torture_free));
70115 + atomic_read_unchecked(&n_rcu_torture_alloc),
70116 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
70117 + atomic_read_unchecked(&n_rcu_torture_free));
70118 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
70119 - atomic_read(&n_rcu_torture_mberror),
70120 + atomic_read_unchecked(&n_rcu_torture_mberror),
70121 n_rcu_torture_boost_ktrerror,
70122 n_rcu_torture_boost_rterror);
70123 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
70124 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
70125 n_barrier_attempts,
70126 n_rcu_torture_barrier_error);
70127 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
70128 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
70129 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
70130 n_rcu_torture_barrier_error != 0 ||
70131 n_rcu_torture_boost_ktrerror != 0 ||
70132 n_rcu_torture_boost_rterror != 0 ||
70133 n_rcu_torture_boost_failure != 0 ||
70134 i > 1) {
70135 cnt += sprintf(&page[cnt], "!!! ");
70136 - atomic_inc(&n_rcu_torture_error);
70137 + atomic_inc_unchecked(&n_rcu_torture_error);
70138 WARN_ON_ONCE(1);
70139 }
70140 cnt += sprintf(&page[cnt], "Reader Pipe: ");
70141 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
70142 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
70143 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
70144 cnt += sprintf(&page[cnt], " %d",
70145 - atomic_read(&rcu_torture_wcount[i]));
70146 + atomic_read_unchecked(&rcu_torture_wcount[i]));
70147 }
70148 cnt += sprintf(&page[cnt], "\n");
70149 if (cur_ops->stats)
70150 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
70151
70152 if (cur_ops->cleanup)
70153 cur_ops->cleanup();
70154 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
70155 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
70156 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
70157 else if (n_online_successes != n_online_attempts ||
70158 n_offline_successes != n_offline_attempts)
70159 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
70160
70161 rcu_torture_current = NULL;
70162 rcu_torture_current_version = 0;
70163 - atomic_set(&n_rcu_torture_alloc, 0);
70164 - atomic_set(&n_rcu_torture_alloc_fail, 0);
70165 - atomic_set(&n_rcu_torture_free, 0);
70166 - atomic_set(&n_rcu_torture_mberror, 0);
70167 - atomic_set(&n_rcu_torture_error, 0);
70168 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
70169 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
70170 + atomic_set_unchecked(&n_rcu_torture_free, 0);
70171 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
70172 + atomic_set_unchecked(&n_rcu_torture_error, 0);
70173 n_rcu_torture_barrier_error = 0;
70174 n_rcu_torture_boost_ktrerror = 0;
70175 n_rcu_torture_boost_rterror = 0;
70176 n_rcu_torture_boost_failure = 0;
70177 n_rcu_torture_boosts = 0;
70178 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
70179 - atomic_set(&rcu_torture_wcount[i], 0);
70180 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
70181 for_each_possible_cpu(cpu) {
70182 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
70183 per_cpu(rcu_torture_count, cpu)[i] = 0;
70184 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
70185 index f7bcd9e..8973e14 100644
70186 --- a/kernel/rcutree.c
70187 +++ b/kernel/rcutree.c
70188 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
70189 rcu_prepare_for_idle(smp_processor_id());
70190 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
70191 smp_mb__before_atomic_inc(); /* See above. */
70192 - atomic_inc(&rdtp->dynticks);
70193 + atomic_inc_unchecked(&rdtp->dynticks);
70194 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
70195 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
70196 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
70197
70198 /*
70199 * The idle task is not permitted to enter the idle loop while
70200 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
70201 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
70202 {
70203 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
70204 - atomic_inc(&rdtp->dynticks);
70205 + atomic_inc_unchecked(&rdtp->dynticks);
70206 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
70207 smp_mb__after_atomic_inc(); /* See above. */
70208 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
70209 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
70210 rcu_cleanup_after_idle(smp_processor_id());
70211 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
70212 if (!is_idle_task(current)) {
70213 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
70214 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
70215
70216 if (rdtp->dynticks_nmi_nesting == 0 &&
70217 - (atomic_read(&rdtp->dynticks) & 0x1))
70218 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
70219 return;
70220 rdtp->dynticks_nmi_nesting++;
70221 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
70222 - atomic_inc(&rdtp->dynticks);
70223 + atomic_inc_unchecked(&rdtp->dynticks);
70224 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
70225 smp_mb__after_atomic_inc(); /* See above. */
70226 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
70227 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
70228 }
70229
70230 /**
70231 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
70232 return;
70233 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
70234 smp_mb__before_atomic_inc(); /* See above. */
70235 - atomic_inc(&rdtp->dynticks);
70236 + atomic_inc_unchecked(&rdtp->dynticks);
70237 smp_mb__after_atomic_inc(); /* Force delay to next write. */
70238 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
70239 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
70240 }
70241
70242 /**
70243 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
70244 int ret;
70245
70246 preempt_disable();
70247 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
70248 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
70249 preempt_enable();
70250 return ret;
70251 }
70252 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
70253 */
70254 static int dyntick_save_progress_counter(struct rcu_data *rdp)
70255 {
70256 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
70257 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
70258 return (rdp->dynticks_snap & 0x1) == 0;
70259 }
70260
70261 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
70262 unsigned int curr;
70263 unsigned int snap;
70264
70265 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
70266 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
70267 snap = (unsigned int)rdp->dynticks_snap;
70268
70269 /*
70270 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
70271 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
70272 */
70273 if (till_stall_check < 3) {
70274 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
70275 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
70276 till_stall_check = 3;
70277 } else if (till_stall_check > 300) {
70278 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
70279 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
70280 till_stall_check = 300;
70281 }
70282 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
70283 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
70284 rsp->qlen += rdp->qlen;
70285 rdp->n_cbs_orphaned += rdp->qlen;
70286 rdp->qlen_lazy = 0;
70287 - ACCESS_ONCE(rdp->qlen) = 0;
70288 + ACCESS_ONCE_RW(rdp->qlen) = 0;
70289 }
70290
70291 /*
70292 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
70293 }
70294 smp_mb(); /* List handling before counting for rcu_barrier(). */
70295 rdp->qlen_lazy -= count_lazy;
70296 - ACCESS_ONCE(rdp->qlen) -= count;
70297 + ACCESS_ONCE_RW(rdp->qlen) -= count;
70298 rdp->n_cbs_invoked += count;
70299
70300 /* Reinstate batch limit if we have worked down the excess. */
70301 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
70302 /*
70303 * Do RCU core processing for the current CPU.
70304 */
70305 -static void rcu_process_callbacks(struct softirq_action *unused)
70306 +static void rcu_process_callbacks(void)
70307 {
70308 struct rcu_state *rsp;
70309
70310 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
70311 rdp = this_cpu_ptr(rsp->rda);
70312
70313 /* Add the callback to our list. */
70314 - ACCESS_ONCE(rdp->qlen)++;
70315 + ACCESS_ONCE_RW(rdp->qlen)++;
70316 if (lazy)
70317 rdp->qlen_lazy++;
70318 else
70319 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
70320 }
70321 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
70322
70323 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
70324 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
70325 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
70326 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
70327
70328 static int synchronize_sched_expedited_cpu_stop(void *data)
70329 {
70330 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
70331 int firstsnap, s, snap, trycount = 0;
70332
70333 /* Note that atomic_inc_return() implies full memory barrier. */
70334 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
70335 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
70336 get_online_cpus();
70337 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
70338
70339 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
70340 }
70341
70342 /* Check to see if someone else did our work for us. */
70343 - s = atomic_read(&sync_sched_expedited_done);
70344 + s = atomic_read_unchecked(&sync_sched_expedited_done);
70345 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
70346 smp_mb(); /* ensure test happens before caller kfree */
70347 return;
70348 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
70349 * grace period works for us.
70350 */
70351 get_online_cpus();
70352 - snap = atomic_read(&sync_sched_expedited_started);
70353 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
70354 smp_mb(); /* ensure read is before try_stop_cpus(). */
70355 }
70356
70357 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
70358 * than we did beat us to the punch.
70359 */
70360 do {
70361 - s = atomic_read(&sync_sched_expedited_done);
70362 + s = atomic_read_unchecked(&sync_sched_expedited_done);
70363 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
70364 smp_mb(); /* ensure test happens before caller kfree */
70365 break;
70366 }
70367 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
70368 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
70369
70370 put_online_cpus();
70371 }
70372 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70373 * ACCESS_ONCE() to prevent the compiler from speculating
70374 * the increment to precede the early-exit check.
70375 */
70376 - ACCESS_ONCE(rsp->n_barrier_done)++;
70377 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70378 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
70379 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
70380 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
70381 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70382
70383 /* Increment ->n_barrier_done to prevent duplicate work. */
70384 smp_mb(); /* Keep increment after above mechanism. */
70385 - ACCESS_ONCE(rsp->n_barrier_done)++;
70386 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70387 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
70388 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
70389 smp_mb(); /* Keep increment before caller's subsequent code. */
70390 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
70391 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
70392 init_callback_list(rdp);
70393 rdp->qlen_lazy = 0;
70394 - ACCESS_ONCE(rdp->qlen) = 0;
70395 + ACCESS_ONCE_RW(rdp->qlen) = 0;
70396 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
70397 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
70398 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
70399 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
70400 rdp->cpu = cpu;
70401 rdp->rsp = rsp;
70402 raw_spin_unlock_irqrestore(&rnp->lock, flags);
70403 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
70404 rdp->n_force_qs_snap = rsp->n_force_qs;
70405 rdp->blimit = blimit;
70406 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
70407 - atomic_set(&rdp->dynticks->dynticks,
70408 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
70409 + atomic_set_unchecked(&rdp->dynticks->dynticks,
70410 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
70411 rcu_prepare_for_idle_init(cpu);
70412 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
70413
70414 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
70415 index 4d29169..d104a3c 100644
70416 --- a/kernel/rcutree.h
70417 +++ b/kernel/rcutree.h
70418 @@ -86,7 +86,7 @@ struct rcu_dynticks {
70419 long long dynticks_nesting; /* Track irq/process nesting level. */
70420 /* Process level is worth LLONG_MAX/2. */
70421 int dynticks_nmi_nesting; /* Track NMI nesting level. */
70422 - atomic_t dynticks; /* Even value for idle, else odd. */
70423 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
70424 #ifdef CONFIG_RCU_FAST_NO_HZ
70425 int dyntick_drain; /* Prepare-for-idle state variable. */
70426 unsigned long dyntick_holdoff;
70427 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
70428 index 7f3244c..417d606 100644
70429 --- a/kernel/rcutree_plugin.h
70430 +++ b/kernel/rcutree_plugin.h
70431 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
70432
70433 /* Clean up and exit. */
70434 smp_mb(); /* ensure expedited GP seen before counter increment. */
70435 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
70436 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
70437 unlock_mb_ret:
70438 mutex_unlock(&sync_rcu_preempt_exp_mutex);
70439 mb_ret:
70440 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
70441 index abffb48..cbfa6d3 100644
70442 --- a/kernel/rcutree_trace.c
70443 +++ b/kernel/rcutree_trace.c
70444 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
70445 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70446 rdp->qs_pending);
70447 seq_printf(m, " dt=%d/%llx/%d df=%lu",
70448 - atomic_read(&rdp->dynticks->dynticks),
70449 + atomic_read_unchecked(&rdp->dynticks->dynticks),
70450 rdp->dynticks->dynticks_nesting,
70451 rdp->dynticks->dynticks_nmi_nesting,
70452 rdp->dynticks_fqs);
70453 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
70454 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70455 rdp->qs_pending);
70456 seq_printf(m, ",%d,%llx,%d,%lu",
70457 - atomic_read(&rdp->dynticks->dynticks),
70458 + atomic_read_unchecked(&rdp->dynticks->dynticks),
70459 rdp->dynticks->dynticks_nesting,
70460 rdp->dynticks->dynticks_nmi_nesting,
70461 rdp->dynticks_fqs);
70462 diff --git a/kernel/resource.c b/kernel/resource.c
70463 index 34d4588..10baa6a 100644
70464 --- a/kernel/resource.c
70465 +++ b/kernel/resource.c
70466 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
70467
70468 static int __init ioresources_init(void)
70469 {
70470 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70471 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70472 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
70473 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
70474 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70475 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
70476 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
70477 +#endif
70478 +#else
70479 proc_create("ioports", 0, NULL, &proc_ioports_operations);
70480 proc_create("iomem", 0, NULL, &proc_iomem_operations);
70481 +#endif
70482 return 0;
70483 }
70484 __initcall(ioresources_init);
70485 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
70486 index 98ec494..4241d6d 100644
70487 --- a/kernel/rtmutex-tester.c
70488 +++ b/kernel/rtmutex-tester.c
70489 @@ -20,7 +20,7 @@
70490 #define MAX_RT_TEST_MUTEXES 8
70491
70492 static spinlock_t rttest_lock;
70493 -static atomic_t rttest_event;
70494 +static atomic_unchecked_t rttest_event;
70495
70496 struct test_thread_data {
70497 int opcode;
70498 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70499
70500 case RTTEST_LOCKCONT:
70501 td->mutexes[td->opdata] = 1;
70502 - td->event = atomic_add_return(1, &rttest_event);
70503 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70504 return 0;
70505
70506 case RTTEST_RESET:
70507 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70508 return 0;
70509
70510 case RTTEST_RESETEVENT:
70511 - atomic_set(&rttest_event, 0);
70512 + atomic_set_unchecked(&rttest_event, 0);
70513 return 0;
70514
70515 default:
70516 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70517 return ret;
70518
70519 td->mutexes[id] = 1;
70520 - td->event = atomic_add_return(1, &rttest_event);
70521 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70522 rt_mutex_lock(&mutexes[id]);
70523 - td->event = atomic_add_return(1, &rttest_event);
70524 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70525 td->mutexes[id] = 4;
70526 return 0;
70527
70528 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70529 return ret;
70530
70531 td->mutexes[id] = 1;
70532 - td->event = atomic_add_return(1, &rttest_event);
70533 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70534 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70535 - td->event = atomic_add_return(1, &rttest_event);
70536 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70537 td->mutexes[id] = ret ? 0 : 4;
70538 return ret ? -EINTR : 0;
70539
70540 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70541 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70542 return ret;
70543
70544 - td->event = atomic_add_return(1, &rttest_event);
70545 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70546 rt_mutex_unlock(&mutexes[id]);
70547 - td->event = atomic_add_return(1, &rttest_event);
70548 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70549 td->mutexes[id] = 0;
70550 return 0;
70551
70552 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70553 break;
70554
70555 td->mutexes[dat] = 2;
70556 - td->event = atomic_add_return(1, &rttest_event);
70557 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70558 break;
70559
70560 default:
70561 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70562 return;
70563
70564 td->mutexes[dat] = 3;
70565 - td->event = atomic_add_return(1, &rttest_event);
70566 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70567 break;
70568
70569 case RTTEST_LOCKNOWAIT:
70570 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70571 return;
70572
70573 td->mutexes[dat] = 1;
70574 - td->event = atomic_add_return(1, &rttest_event);
70575 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70576 return;
70577
70578 default:
70579 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70580 index 15f60d0..7e50319 100644
70581 --- a/kernel/sched/auto_group.c
70582 +++ b/kernel/sched/auto_group.c
70583 @@ -11,7 +11,7 @@
70584
70585 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70586 static struct autogroup autogroup_default;
70587 -static atomic_t autogroup_seq_nr;
70588 +static atomic_unchecked_t autogroup_seq_nr;
70589
70590 void __init autogroup_init(struct task_struct *init_task)
70591 {
70592 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70593
70594 kref_init(&ag->kref);
70595 init_rwsem(&ag->lock);
70596 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70597 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70598 ag->tg = tg;
70599 #ifdef CONFIG_RT_GROUP_SCHED
70600 /*
70601 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70602 index 1a48cdb..d3949ff 100644
70603 --- a/kernel/sched/core.c
70604 +++ b/kernel/sched/core.c
70605 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
70606 /* convert nice value [19,-20] to rlimit style value [1,40] */
70607 int nice_rlim = 20 - nice;
70608
70609 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70610 +
70611 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70612 capable(CAP_SYS_NICE));
70613 }
70614 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70615 if (nice > 19)
70616 nice = 19;
70617
70618 - if (increment < 0 && !can_nice(current, nice))
70619 + if (increment < 0 && (!can_nice(current, nice) ||
70620 + gr_handle_chroot_nice()))
70621 return -EPERM;
70622
70623 retval = security_task_setnice(current, nice);
70624 @@ -4290,6 +4293,7 @@ recheck:
70625 unsigned long rlim_rtprio =
70626 task_rlimit(p, RLIMIT_RTPRIO);
70627
70628 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70629 /* can't set/change the rt policy */
70630 if (policy != p->policy && !rlim_rtprio)
70631 return -EPERM;
70632 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70633 index 96e2b18..bb31eec 100644
70634 --- a/kernel/sched/fair.c
70635 +++ b/kernel/sched/fair.c
70636 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70637 * run_rebalance_domains is triggered when needed from the scheduler tick.
70638 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70639 */
70640 -static void run_rebalance_domains(struct softirq_action *h)
70641 +static void run_rebalance_domains(void)
70642 {
70643 int this_cpu = smp_processor_id();
70644 struct rq *this_rq = cpu_rq(this_cpu);
70645 diff --git a/kernel/signal.c b/kernel/signal.c
70646 index be4f856..453401c 100644
70647 --- a/kernel/signal.c
70648 +++ b/kernel/signal.c
70649 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
70650
70651 int print_fatal_signals __read_mostly;
70652
70653 -static void __user *sig_handler(struct task_struct *t, int sig)
70654 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70655 {
70656 return t->sighand->action[sig - 1].sa.sa_handler;
70657 }
70658
70659 -static int sig_handler_ignored(void __user *handler, int sig)
70660 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70661 {
70662 /* Is it explicitly or implicitly ignored? */
70663 return handler == SIG_IGN ||
70664 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70665
70666 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70667 {
70668 - void __user *handler;
70669 + __sighandler_t handler;
70670
70671 handler = sig_handler(t, sig);
70672
70673 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70674 atomic_inc(&user->sigpending);
70675 rcu_read_unlock();
70676
70677 + if (!override_rlimit)
70678 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70679 +
70680 if (override_rlimit ||
70681 atomic_read(&user->sigpending) <=
70682 task_rlimit(t, RLIMIT_SIGPENDING)) {
70683 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70684
70685 int unhandled_signal(struct task_struct *tsk, int sig)
70686 {
70687 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70688 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70689 if (is_global_init(tsk))
70690 return 1;
70691 if (handler != SIG_IGN && handler != SIG_DFL)
70692 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70693 }
70694 }
70695
70696 + /* allow glibc communication via tgkill to other threads in our
70697 + thread group */
70698 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70699 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70700 + && gr_handle_signal(t, sig))
70701 + return -EPERM;
70702 +
70703 return security_task_kill(t, info, sig, 0);
70704 }
70705
70706 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70707 return send_signal(sig, info, p, 1);
70708 }
70709
70710 -static int
70711 +int
70712 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70713 {
70714 return send_signal(sig, info, t, 0);
70715 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70716 unsigned long int flags;
70717 int ret, blocked, ignored;
70718 struct k_sigaction *action;
70719 + int is_unhandled = 0;
70720
70721 spin_lock_irqsave(&t->sighand->siglock, flags);
70722 action = &t->sighand->action[sig-1];
70723 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70724 }
70725 if (action->sa.sa_handler == SIG_DFL)
70726 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70727 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70728 + is_unhandled = 1;
70729 ret = specific_send_sig_info(sig, info, t);
70730 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70731
70732 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70733 + normal operation */
70734 + if (is_unhandled) {
70735 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70736 + gr_handle_crash(t, sig);
70737 + }
70738 +
70739 return ret;
70740 }
70741
70742 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70743 ret = check_kill_permission(sig, info, p);
70744 rcu_read_unlock();
70745
70746 - if (!ret && sig)
70747 + if (!ret && sig) {
70748 ret = do_send_sig_info(sig, info, p, true);
70749 + if (!ret)
70750 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70751 + }
70752
70753 return ret;
70754 }
70755 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70756 int error = -ESRCH;
70757
70758 rcu_read_lock();
70759 - p = find_task_by_vpid(pid);
70760 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70761 + /* allow glibc communication via tgkill to other threads in our
70762 + thread group */
70763 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70764 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70765 + p = find_task_by_vpid_unrestricted(pid);
70766 + else
70767 +#endif
70768 + p = find_task_by_vpid(pid);
70769 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70770 error = check_kill_permission(sig, info, p);
70771 /*
70772 diff --git a/kernel/softirq.c b/kernel/softirq.c
70773 index b73e681..645ab62 100644
70774 --- a/kernel/softirq.c
70775 +++ b/kernel/softirq.c
70776 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70777
70778 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70779
70780 -char *softirq_to_name[NR_SOFTIRQS] = {
70781 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70782 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70783 "TASKLET", "SCHED", "HRTIMER", "RCU"
70784 };
70785 @@ -243,7 +243,7 @@ restart:
70786 kstat_incr_softirqs_this_cpu(vec_nr);
70787
70788 trace_softirq_entry(vec_nr);
70789 - h->action(h);
70790 + h->action();
70791 trace_softirq_exit(vec_nr);
70792 if (unlikely(prev_count != preempt_count())) {
70793 printk(KERN_ERR "huh, entered softirq %u %s %p"
70794 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70795 or_softirq_pending(1UL << nr);
70796 }
70797
70798 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70799 +void open_softirq(int nr, void (*action)(void))
70800 {
70801 - softirq_vec[nr].action = action;
70802 + pax_open_kernel();
70803 + *(void **)&softirq_vec[nr].action = action;
70804 + pax_close_kernel();
70805 }
70806
70807 /*
70808 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70809
70810 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70811
70812 -static void tasklet_action(struct softirq_action *a)
70813 +static void tasklet_action(void)
70814 {
70815 struct tasklet_struct *list;
70816
70817 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70818 }
70819 }
70820
70821 -static void tasklet_hi_action(struct softirq_action *a)
70822 +static void tasklet_hi_action(void)
70823 {
70824 struct tasklet_struct *list;
70825
70826 diff --git a/kernel/srcu.c b/kernel/srcu.c
70827 index 2095be3..9a5b89d 100644
70828 --- a/kernel/srcu.c
70829 +++ b/kernel/srcu.c
70830 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70831 preempt_disable();
70832 idx = rcu_dereference_index_check(sp->completed,
70833 rcu_read_lock_sched_held()) & 0x1;
70834 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70835 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70836 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70837 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70838 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70839 preempt_enable();
70840 return idx;
70841 }
70842 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70843 {
70844 preempt_disable();
70845 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70846 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70847 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70848 preempt_enable();
70849 }
70850 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70851 diff --git a/kernel/sys.c b/kernel/sys.c
70852 index 909148a..cd51acf 100644
70853 --- a/kernel/sys.c
70854 +++ b/kernel/sys.c
70855 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70856 error = -EACCES;
70857 goto out;
70858 }
70859 +
70860 + if (gr_handle_chroot_setpriority(p, niceval)) {
70861 + error = -EACCES;
70862 + goto out;
70863 + }
70864 +
70865 no_nice = security_task_setnice(p, niceval);
70866 if (no_nice) {
70867 error = no_nice;
70868 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70869 goto error;
70870 }
70871
70872 + if (gr_check_group_change(new->gid, new->egid, -1))
70873 + goto error;
70874 +
70875 if (rgid != (gid_t) -1 ||
70876 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70877 new->sgid = new->egid;
70878 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70879 old = current_cred();
70880
70881 retval = -EPERM;
70882 +
70883 + if (gr_check_group_change(kgid, kgid, kgid))
70884 + goto error;
70885 +
70886 if (nsown_capable(CAP_SETGID))
70887 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70888 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70889 @@ -647,7 +660,7 @@ error:
70890 /*
70891 * change the user struct in a credentials set to match the new UID
70892 */
70893 -static int set_user(struct cred *new)
70894 +int set_user(struct cred *new)
70895 {
70896 struct user_struct *new_user;
70897
70898 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70899 goto error;
70900 }
70901
70902 + if (gr_check_user_change(new->uid, new->euid, -1))
70903 + goto error;
70904 +
70905 if (!uid_eq(new->uid, old->uid)) {
70906 retval = set_user(new);
70907 if (retval < 0)
70908 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70909 old = current_cred();
70910
70911 retval = -EPERM;
70912 +
70913 + if (gr_check_crash_uid(kuid))
70914 + goto error;
70915 + if (gr_check_user_change(kuid, kuid, kuid))
70916 + goto error;
70917 +
70918 if (nsown_capable(CAP_SETUID)) {
70919 new->suid = new->uid = kuid;
70920 if (!uid_eq(kuid, old->uid)) {
70921 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70922 goto error;
70923 }
70924
70925 + if (gr_check_user_change(kruid, keuid, -1))
70926 + goto error;
70927 +
70928 if (ruid != (uid_t) -1) {
70929 new->uid = kruid;
70930 if (!uid_eq(kruid, old->uid)) {
70931 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70932 goto error;
70933 }
70934
70935 + if (gr_check_group_change(krgid, kegid, -1))
70936 + goto error;
70937 +
70938 if (rgid != (gid_t) -1)
70939 new->gid = krgid;
70940 if (egid != (gid_t) -1)
70941 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70942 if (!uid_valid(kuid))
70943 return old_fsuid;
70944
70945 + if (gr_check_user_change(-1, -1, kuid))
70946 + goto error;
70947 +
70948 new = prepare_creds();
70949 if (!new)
70950 return old_fsuid;
70951 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70952 }
70953 }
70954
70955 +error:
70956 abort_creds(new);
70957 return old_fsuid;
70958
70959 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70960 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70961 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70962 nsown_capable(CAP_SETGID)) {
70963 + if (gr_check_group_change(-1, -1, kgid))
70964 + goto error;
70965 +
70966 if (!gid_eq(kgid, old->fsgid)) {
70967 new->fsgid = kgid;
70968 goto change_okay;
70969 }
70970 }
70971
70972 +error:
70973 abort_creds(new);
70974 return old_fsgid;
70975
70976 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70977 return -EFAULT;
70978
70979 down_read(&uts_sem);
70980 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70981 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70982 __OLD_UTS_LEN);
70983 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70984 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70985 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70986 __OLD_UTS_LEN);
70987 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70988 - error |= __copy_to_user(&name->release, &utsname()->release,
70989 + error |= __copy_to_user(name->release, &utsname()->release,
70990 __OLD_UTS_LEN);
70991 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70992 - error |= __copy_to_user(&name->version, &utsname()->version,
70993 + error |= __copy_to_user(name->version, &utsname()->version,
70994 __OLD_UTS_LEN);
70995 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70996 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70997 + error |= __copy_to_user(name->machine, &utsname()->machine,
70998 __OLD_UTS_LEN);
70999 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
71000 up_read(&uts_sem);
71001 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
71002 error = get_dumpable(me->mm);
71003 break;
71004 case PR_SET_DUMPABLE:
71005 - if (arg2 < 0 || arg2 > 1) {
71006 + if (arg2 > 1) {
71007 error = -EINVAL;
71008 break;
71009 }
71010 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
71011 index 87174ef..68cbb82 100644
71012 --- a/kernel/sysctl.c
71013 +++ b/kernel/sysctl.c
71014 @@ -92,7 +92,6 @@
71015
71016
71017 #if defined(CONFIG_SYSCTL)
71018 -
71019 /* External variables not in a header file. */
71020 extern int sysctl_overcommit_memory;
71021 extern int sysctl_overcommit_ratio;
71022 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
71023 void __user *buffer, size_t *lenp, loff_t *ppos);
71024 #endif
71025
71026 -#ifdef CONFIG_PRINTK
71027 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71028 void __user *buffer, size_t *lenp, loff_t *ppos);
71029 -#endif
71030
71031 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
71032 void __user *buffer, size_t *lenp, loff_t *ppos);
71033 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
71034
71035 #endif
71036
71037 +extern struct ctl_table grsecurity_table[];
71038 +
71039 static struct ctl_table kern_table[];
71040 static struct ctl_table vm_table[];
71041 static struct ctl_table fs_table[];
71042 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
71043 int sysctl_legacy_va_layout;
71044 #endif
71045
71046 +#ifdef CONFIG_PAX_SOFTMODE
71047 +static ctl_table pax_table[] = {
71048 + {
71049 + .procname = "softmode",
71050 + .data = &pax_softmode,
71051 + .maxlen = sizeof(unsigned int),
71052 + .mode = 0600,
71053 + .proc_handler = &proc_dointvec,
71054 + },
71055 +
71056 + { }
71057 +};
71058 +#endif
71059 +
71060 /* The default sysctl tables: */
71061
71062 static struct ctl_table sysctl_base_table[] = {
71063 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
71064 #endif
71065
71066 static struct ctl_table kern_table[] = {
71067 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
71068 + {
71069 + .procname = "grsecurity",
71070 + .mode = 0500,
71071 + .child = grsecurity_table,
71072 + },
71073 +#endif
71074 +
71075 +#ifdef CONFIG_PAX_SOFTMODE
71076 + {
71077 + .procname = "pax",
71078 + .mode = 0500,
71079 + .child = pax_table,
71080 + },
71081 +#endif
71082 +
71083 {
71084 .procname = "sched_child_runs_first",
71085 .data = &sysctl_sched_child_runs_first,
71086 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
71087 .data = &modprobe_path,
71088 .maxlen = KMOD_PATH_LEN,
71089 .mode = 0644,
71090 - .proc_handler = proc_dostring,
71091 + .proc_handler = proc_dostring_modpriv,
71092 },
71093 {
71094 .procname = "modules_disabled",
71095 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
71096 .extra1 = &zero,
71097 .extra2 = &one,
71098 },
71099 +#endif
71100 {
71101 .procname = "kptr_restrict",
71102 .data = &kptr_restrict,
71103 .maxlen = sizeof(int),
71104 .mode = 0644,
71105 .proc_handler = proc_dointvec_minmax_sysadmin,
71106 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71107 + .extra1 = &two,
71108 +#else
71109 .extra1 = &zero,
71110 +#endif
71111 .extra2 = &two,
71112 },
71113 -#endif
71114 {
71115 .procname = "ngroups_max",
71116 .data = &ngroups_max,
71117 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
71118 .proc_handler = proc_dointvec_minmax,
71119 .extra1 = &zero,
71120 },
71121 + {
71122 + .procname = "heap_stack_gap",
71123 + .data = &sysctl_heap_stack_gap,
71124 + .maxlen = sizeof(sysctl_heap_stack_gap),
71125 + .mode = 0644,
71126 + .proc_handler = proc_doulongvec_minmax,
71127 + },
71128 #else
71129 {
71130 .procname = "nr_trim_pages",
71131 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
71132 buffer, lenp, ppos);
71133 }
71134
71135 +int proc_dostring_modpriv(struct ctl_table *table, int write,
71136 + void __user *buffer, size_t *lenp, loff_t *ppos)
71137 +{
71138 + if (write && !capable(CAP_SYS_MODULE))
71139 + return -EPERM;
71140 +
71141 + return _proc_do_string(table->data, table->maxlen, write,
71142 + buffer, lenp, ppos);
71143 +}
71144 +
71145 static size_t proc_skip_spaces(char **buf)
71146 {
71147 size_t ret;
71148 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
71149 len = strlen(tmp);
71150 if (len > *size)
71151 len = *size;
71152 + if (len > sizeof(tmp))
71153 + len = sizeof(tmp);
71154 if (copy_to_user(*buf, tmp, len))
71155 return -EFAULT;
71156 *size -= len;
71157 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
71158 return err;
71159 }
71160
71161 -#ifdef CONFIG_PRINTK
71162 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71163 void __user *buffer, size_t *lenp, loff_t *ppos)
71164 {
71165 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71166
71167 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
71168 }
71169 -#endif
71170
71171 struct do_proc_dointvec_minmax_conv_param {
71172 int *min;
71173 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
71174 *i = val;
71175 } else {
71176 val = convdiv * (*i) / convmul;
71177 - if (!first)
71178 + if (!first) {
71179 err = proc_put_char(&buffer, &left, '\t');
71180 + if (err)
71181 + break;
71182 + }
71183 err = proc_put_long(&buffer, &left, val, false);
71184 if (err)
71185 break;
71186 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
71187 return -ENOSYS;
71188 }
71189
71190 +int proc_dostring_modpriv(struct ctl_table *table, int write,
71191 + void __user *buffer, size_t *lenp, loff_t *ppos)
71192 +{
71193 + return -ENOSYS;
71194 +}
71195 +
71196 int proc_dointvec(struct ctl_table *table, int write,
71197 void __user *buffer, size_t *lenp, loff_t *ppos)
71198 {
71199 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
71200 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
71201 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
71202 EXPORT_SYMBOL(proc_dostring);
71203 +EXPORT_SYMBOL(proc_dostring_modpriv);
71204 EXPORT_SYMBOL(proc_doulongvec_minmax);
71205 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
71206 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
71207 index 65bdcf1..21eb831 100644
71208 --- a/kernel/sysctl_binary.c
71209 +++ b/kernel/sysctl_binary.c
71210 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
71211 int i;
71212
71213 set_fs(KERNEL_DS);
71214 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
71215 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
71216 set_fs(old_fs);
71217 if (result < 0)
71218 goto out_kfree;
71219 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
71220 }
71221
71222 set_fs(KERNEL_DS);
71223 - result = vfs_write(file, buffer, str - buffer, &pos);
71224 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
71225 set_fs(old_fs);
71226 if (result < 0)
71227 goto out_kfree;
71228 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
71229 int i;
71230
71231 set_fs(KERNEL_DS);
71232 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
71233 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
71234 set_fs(old_fs);
71235 if (result < 0)
71236 goto out_kfree;
71237 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
71238 }
71239
71240 set_fs(KERNEL_DS);
71241 - result = vfs_write(file, buffer, str - buffer, &pos);
71242 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
71243 set_fs(old_fs);
71244 if (result < 0)
71245 goto out_kfree;
71246 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
71247 int i;
71248
71249 set_fs(KERNEL_DS);
71250 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
71251 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
71252 set_fs(old_fs);
71253 if (result < 0)
71254 goto out;
71255 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
71256 __le16 dnaddr;
71257
71258 set_fs(KERNEL_DS);
71259 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
71260 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
71261 set_fs(old_fs);
71262 if (result < 0)
71263 goto out;
71264 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
71265 le16_to_cpu(dnaddr) & 0x3ff);
71266
71267 set_fs(KERNEL_DS);
71268 - result = vfs_write(file, buf, len, &pos);
71269 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
71270 set_fs(old_fs);
71271 if (result < 0)
71272 goto out;
71273 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
71274 index d0a3279..db0ad99 100644
71275 --- a/kernel/taskstats.c
71276 +++ b/kernel/taskstats.c
71277 @@ -27,9 +27,12 @@
71278 #include <linux/cgroup.h>
71279 #include <linux/fs.h>
71280 #include <linux/file.h>
71281 +#include <linux/grsecurity.h>
71282 #include <net/genetlink.h>
71283 #include <linux/atomic.h>
71284
71285 +extern int gr_is_taskstats_denied(int pid);
71286 +
71287 /*
71288 * Maximum length of a cpumask that can be specified in
71289 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
71290 @@ -561,6 +564,9 @@ err:
71291
71292 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
71293 {
71294 + if (gr_is_taskstats_denied(current->pid))
71295 + return -EACCES;
71296 +
71297 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
71298 return cmd_attr_register_cpumask(info);
71299 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
71300 diff --git a/kernel/time.c b/kernel/time.c
71301 index ba744cf..267b7c5 100644
71302 --- a/kernel/time.c
71303 +++ b/kernel/time.c
71304 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
71305 return error;
71306
71307 if (tz) {
71308 + /* we log in do_settimeofday called below, so don't log twice
71309 + */
71310 + if (!tv)
71311 + gr_log_timechange();
71312 +
71313 sys_tz = *tz;
71314 update_vsyscall_tz();
71315 if (firsttime) {
71316 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
71317 index aa27d39..34d221c 100644
71318 --- a/kernel/time/alarmtimer.c
71319 +++ b/kernel/time/alarmtimer.c
71320 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
71321 struct platform_device *pdev;
71322 int error = 0;
71323 int i;
71324 - struct k_clock alarm_clock = {
71325 + static struct k_clock alarm_clock = {
71326 .clock_getres = alarm_clock_getres,
71327 .clock_get = alarm_clock_get,
71328 .timer_create = alarm_timer_create,
71329 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
71330 index f113755..ec24223 100644
71331 --- a/kernel/time/tick-broadcast.c
71332 +++ b/kernel/time/tick-broadcast.c
71333 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
71334 * then clear the broadcast bit.
71335 */
71336 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
71337 - int cpu = smp_processor_id();
71338 + cpu = smp_processor_id();
71339
71340 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
71341 tick_broadcast_clear_oneshot(cpu);
71342 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
71343 index f791637..00051de 100644
71344 --- a/kernel/time/timekeeping.c
71345 +++ b/kernel/time/timekeeping.c
71346 @@ -14,6 +14,7 @@
71347 #include <linux/init.h>
71348 #include <linux/mm.h>
71349 #include <linux/sched.h>
71350 +#include <linux/grsecurity.h>
71351 #include <linux/syscore_ops.h>
71352 #include <linux/clocksource.h>
71353 #include <linux/jiffies.h>
71354 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
71355 if (!timespec_valid_strict(tv))
71356 return -EINVAL;
71357
71358 + gr_log_timechange();
71359 +
71360 write_seqlock_irqsave(&tk->lock, flags);
71361
71362 timekeeping_forward_now(tk);
71363 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
71364 index af5a7e9..715611a 100644
71365 --- a/kernel/time/timer_list.c
71366 +++ b/kernel/time/timer_list.c
71367 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
71368
71369 static void print_name_offset(struct seq_file *m, void *sym)
71370 {
71371 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71372 + SEQ_printf(m, "<%p>", NULL);
71373 +#else
71374 char symname[KSYM_NAME_LEN];
71375
71376 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
71377 SEQ_printf(m, "<%pK>", sym);
71378 else
71379 SEQ_printf(m, "%s", symname);
71380 +#endif
71381 }
71382
71383 static void
71384 @@ -112,7 +116,11 @@ next_one:
71385 static void
71386 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
71387 {
71388 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71389 + SEQ_printf(m, " .base: %p\n", NULL);
71390 +#else
71391 SEQ_printf(m, " .base: %pK\n", base);
71392 +#endif
71393 SEQ_printf(m, " .index: %d\n",
71394 base->index);
71395 SEQ_printf(m, " .resolution: %Lu nsecs\n",
71396 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
71397 {
71398 struct proc_dir_entry *pe;
71399
71400 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71401 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
71402 +#else
71403 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
71404 +#endif
71405 if (!pe)
71406 return -ENOMEM;
71407 return 0;
71408 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
71409 index 0b537f2..40d6c20 100644
71410 --- a/kernel/time/timer_stats.c
71411 +++ b/kernel/time/timer_stats.c
71412 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
71413 static unsigned long nr_entries;
71414 static struct entry entries[MAX_ENTRIES];
71415
71416 -static atomic_t overflow_count;
71417 +static atomic_unchecked_t overflow_count;
71418
71419 /*
71420 * The entries are in a hash-table, for fast lookup:
71421 @@ -140,7 +140,7 @@ static void reset_entries(void)
71422 nr_entries = 0;
71423 memset(entries, 0, sizeof(entries));
71424 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
71425 - atomic_set(&overflow_count, 0);
71426 + atomic_set_unchecked(&overflow_count, 0);
71427 }
71428
71429 static struct entry *alloc_entry(void)
71430 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71431 if (likely(entry))
71432 entry->count++;
71433 else
71434 - atomic_inc(&overflow_count);
71435 + atomic_inc_unchecked(&overflow_count);
71436
71437 out_unlock:
71438 raw_spin_unlock_irqrestore(lock, flags);
71439 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71440
71441 static void print_name_offset(struct seq_file *m, unsigned long addr)
71442 {
71443 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71444 + seq_printf(m, "<%p>", NULL);
71445 +#else
71446 char symname[KSYM_NAME_LEN];
71447
71448 if (lookup_symbol_name(addr, symname) < 0)
71449 - seq_printf(m, "<%p>", (void *)addr);
71450 + seq_printf(m, "<%pK>", (void *)addr);
71451 else
71452 seq_printf(m, "%s", symname);
71453 +#endif
71454 }
71455
71456 static int tstats_show(struct seq_file *m, void *v)
71457 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
71458
71459 seq_puts(m, "Timer Stats Version: v0.2\n");
71460 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
71461 - if (atomic_read(&overflow_count))
71462 + if (atomic_read_unchecked(&overflow_count))
71463 seq_printf(m, "Overflow: %d entries\n",
71464 - atomic_read(&overflow_count));
71465 + atomic_read_unchecked(&overflow_count));
71466
71467 for (i = 0; i < nr_entries; i++) {
71468 entry = entries + i;
71469 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
71470 {
71471 struct proc_dir_entry *pe;
71472
71473 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71474 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
71475 +#else
71476 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
71477 +#endif
71478 if (!pe)
71479 return -ENOMEM;
71480 return 0;
71481 diff --git a/kernel/timer.c b/kernel/timer.c
71482 index 46ef2b1..ad081f144 100644
71483 --- a/kernel/timer.c
71484 +++ b/kernel/timer.c
71485 @@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
71486 /*
71487 * This function runs timers and the timer-tq in bottom half context.
71488 */
71489 -static void run_timer_softirq(struct softirq_action *h)
71490 +static void run_timer_softirq(void)
71491 {
71492 struct tvec_base *base = __this_cpu_read(tvec_bases);
71493
71494 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
71495 index c0bd030..62a1927 100644
71496 --- a/kernel/trace/blktrace.c
71497 +++ b/kernel/trace/blktrace.c
71498 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
71499 struct blk_trace *bt = filp->private_data;
71500 char buf[16];
71501
71502 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
71503 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
71504
71505 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
71506 }
71507 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
71508 return 1;
71509
71510 bt = buf->chan->private_data;
71511 - atomic_inc(&bt->dropped);
71512 + atomic_inc_unchecked(&bt->dropped);
71513 return 0;
71514 }
71515
71516 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71517
71518 bt->dir = dir;
71519 bt->dev = dev;
71520 - atomic_set(&bt->dropped, 0);
71521 + atomic_set_unchecked(&bt->dropped, 0);
71522
71523 ret = -EIO;
71524 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71525 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71526 index b4f20fb..483c5fa 100644
71527 --- a/kernel/trace/ftrace.c
71528 +++ b/kernel/trace/ftrace.c
71529 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71530 if (unlikely(ftrace_disabled))
71531 return 0;
71532
71533 + ret = ftrace_arch_code_modify_prepare();
71534 + FTRACE_WARN_ON(ret);
71535 + if (ret)
71536 + return 0;
71537 +
71538 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71539 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71540 if (ret) {
71541 ftrace_bug(ret, ip);
71542 - return 0;
71543 }
71544 - return 1;
71545 + return ret ? 0 : 1;
71546 }
71547
71548 /*
71549 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71550
71551 int
71552 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71553 - void *data)
71554 + void *data)
71555 {
71556 struct ftrace_func_probe *entry;
71557 struct ftrace_page *pg;
71558 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
71559 if (!count)
71560 return 0;
71561
71562 + pax_open_kernel();
71563 sort(start, count, sizeof(*start),
71564 ftrace_cmp_ips, ftrace_swap_ips);
71565 + pax_close_kernel();
71566
71567 start_pg = ftrace_allocate_pages(count);
71568 if (!start_pg)
71569 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71570 index 5c38c81..88012af 100644
71571 --- a/kernel/trace/trace.c
71572 +++ b/kernel/trace/trace.c
71573 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71574 };
71575 #endif
71576
71577 -static struct dentry *d_tracer;
71578 -
71579 struct dentry *tracing_init_dentry(void)
71580 {
71581 + static struct dentry *d_tracer;
71582 static int once;
71583
71584 if (d_tracer)
71585 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
71586 return d_tracer;
71587 }
71588
71589 -static struct dentry *d_percpu;
71590 -
71591 struct dentry *tracing_dentry_percpu(void)
71592 {
71593 + static struct dentry *d_percpu;
71594 static int once;
71595 struct dentry *d_tracer;
71596
71597 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71598 index 29111da..d190fe2 100644
71599 --- a/kernel/trace/trace_events.c
71600 +++ b/kernel/trace/trace_events.c
71601 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
71602 struct ftrace_module_file_ops {
71603 struct list_head list;
71604 struct module *mod;
71605 - struct file_operations id;
71606 - struct file_operations enable;
71607 - struct file_operations format;
71608 - struct file_operations filter;
71609 };
71610
71611 static struct ftrace_module_file_ops *
71612 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
71613
71614 file_ops->mod = mod;
71615
71616 - file_ops->id = ftrace_event_id_fops;
71617 - file_ops->id.owner = mod;
71618 -
71619 - file_ops->enable = ftrace_enable_fops;
71620 - file_ops->enable.owner = mod;
71621 -
71622 - file_ops->filter = ftrace_event_filter_fops;
71623 - file_ops->filter.owner = mod;
71624 -
71625 - file_ops->format = ftrace_event_format_fops;
71626 - file_ops->format.owner = mod;
71627 + pax_open_kernel();
71628 + *(void **)&mod->trace_id.owner = mod;
71629 + *(void **)&mod->trace_enable.owner = mod;
71630 + *(void **)&mod->trace_filter.owner = mod;
71631 + *(void **)&mod->trace_format.owner = mod;
71632 + pax_close_kernel();
71633
71634 list_add(&file_ops->list, &ftrace_module_file_list);
71635
71636 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
71637
71638 for_each_event(call, start, end) {
71639 __trace_add_event_call(*call, mod,
71640 - &file_ops->id, &file_ops->enable,
71641 - &file_ops->filter, &file_ops->format);
71642 + &mod->trace_id, &mod->trace_enable,
71643 + &mod->trace_filter, &mod->trace_format);
71644 }
71645 }
71646
71647 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71648 index fd3c8aa..5f324a6 100644
71649 --- a/kernel/trace/trace_mmiotrace.c
71650 +++ b/kernel/trace/trace_mmiotrace.c
71651 @@ -24,7 +24,7 @@ struct header_iter {
71652 static struct trace_array *mmio_trace_array;
71653 static bool overrun_detected;
71654 static unsigned long prev_overruns;
71655 -static atomic_t dropped_count;
71656 +static atomic_unchecked_t dropped_count;
71657
71658 static void mmio_reset_data(struct trace_array *tr)
71659 {
71660 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71661
71662 static unsigned long count_overruns(struct trace_iterator *iter)
71663 {
71664 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71665 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71666 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71667
71668 if (over > prev_overruns)
71669 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71670 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71671 sizeof(*entry), 0, pc);
71672 if (!event) {
71673 - atomic_inc(&dropped_count);
71674 + atomic_inc_unchecked(&dropped_count);
71675 return;
71676 }
71677 entry = ring_buffer_event_data(event);
71678 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71679 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71680 sizeof(*entry), 0, pc);
71681 if (!event) {
71682 - atomic_inc(&dropped_count);
71683 + atomic_inc_unchecked(&dropped_count);
71684 return;
71685 }
71686 entry = ring_buffer_event_data(event);
71687 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71688 index 123b189..97b81f5 100644
71689 --- a/kernel/trace/trace_output.c
71690 +++ b/kernel/trace/trace_output.c
71691 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71692
71693 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71694 if (!IS_ERR(p)) {
71695 - p = mangle_path(s->buffer + s->len, p, "\n");
71696 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71697 if (p) {
71698 s->len = p - s->buffer;
71699 return 1;
71700 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71701 index d4545f4..a9010a1 100644
71702 --- a/kernel/trace/trace_stack.c
71703 +++ b/kernel/trace/trace_stack.c
71704 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71705 return;
71706
71707 /* we do not handle interrupt stacks yet */
71708 - if (!object_is_on_stack(&this_size))
71709 + if (!object_starts_on_stack(&this_size))
71710 return;
71711
71712 local_irq_save(flags);
71713 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71714 index 6d42247..b727b3a 100644
71715 --- a/kernel/workqueue.c
71716 +++ b/kernel/workqueue.c
71717 @@ -1422,7 +1422,7 @@ retry:
71718 /* morph UNBOUND to REBIND atomically */
71719 worker_flags &= ~WORKER_UNBOUND;
71720 worker_flags |= WORKER_REBIND;
71721 - ACCESS_ONCE(worker->flags) = worker_flags;
71722 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71723
71724 idle_rebind.cnt++;
71725 worker->idle_rebind = &idle_rebind;
71726 @@ -1448,7 +1448,7 @@ retry:
71727 /* morph UNBOUND to REBIND atomically */
71728 worker_flags &= ~WORKER_UNBOUND;
71729 worker_flags |= WORKER_REBIND;
71730 - ACCESS_ONCE(worker->flags) = worker_flags;
71731 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71732
71733 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71734 work_data_bits(rebind_work)))
71735 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71736 index 2403a63..5c4be4c 100644
71737 --- a/lib/Kconfig.debug
71738 +++ b/lib/Kconfig.debug
71739 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71740 depends on DEBUG_KERNEL
71741 depends on STACKTRACE_SUPPORT
71742 depends on PROC_FS
71743 + depends on !GRKERNSEC_HIDESYM
71744 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71745 select KALLSYMS
71746 select KALLSYMS_ALL
71747 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71748
71749 config PROVIDE_OHCI1394_DMA_INIT
71750 bool "Remote debugging over FireWire early on boot"
71751 - depends on PCI && X86
71752 + depends on PCI && X86 && !GRKERNSEC
71753 help
71754 If you want to debug problems which hang or crash the kernel early
71755 on boot and the crashing machine has a FireWire port, you can use
71756 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71757
71758 config FIREWIRE_OHCI_REMOTE_DMA
71759 bool "Remote debugging over FireWire with firewire-ohci"
71760 - depends on FIREWIRE_OHCI
71761 + depends on FIREWIRE_OHCI && !GRKERNSEC
71762 help
71763 This option lets you use the FireWire bus for remote debugging
71764 with help of the firewire-ohci driver. It enables unfiltered
71765 diff --git a/lib/bitmap.c b/lib/bitmap.c
71766 index 06fdfa1..97c5c7d 100644
71767 --- a/lib/bitmap.c
71768 +++ b/lib/bitmap.c
71769 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71770 {
71771 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71772 u32 chunk;
71773 - const char __user __force *ubuf = (const char __user __force *)buf;
71774 + const char __user *ubuf = (const char __force_user *)buf;
71775
71776 bitmap_zero(maskp, nmaskbits);
71777
71778 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71779 {
71780 if (!access_ok(VERIFY_READ, ubuf, ulen))
71781 return -EFAULT;
71782 - return __bitmap_parse((const char __force *)ubuf,
71783 + return __bitmap_parse((const char __force_kernel *)ubuf,
71784 ulen, 1, maskp, nmaskbits);
71785
71786 }
71787 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71788 {
71789 unsigned a, b;
71790 int c, old_c, totaldigits;
71791 - const char __user __force *ubuf = (const char __user __force *)buf;
71792 + const char __user *ubuf = (const char __force_user *)buf;
71793 int exp_digit, in_range;
71794
71795 totaldigits = c = 0;
71796 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71797 {
71798 if (!access_ok(VERIFY_READ, ubuf, ulen))
71799 return -EFAULT;
71800 - return __bitmap_parselist((const char __force *)ubuf,
71801 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71802 ulen, 1, maskp, nmaskbits);
71803 }
71804 EXPORT_SYMBOL(bitmap_parselist_user);
71805 diff --git a/lib/bug.c b/lib/bug.c
71806 index a28c141..2bd3d95 100644
71807 --- a/lib/bug.c
71808 +++ b/lib/bug.c
71809 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71810 return BUG_TRAP_TYPE_NONE;
71811
71812 bug = find_bug(bugaddr);
71813 + if (!bug)
71814 + return BUG_TRAP_TYPE_NONE;
71815
71816 file = NULL;
71817 line = 0;
71818 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71819 index d11808c..dc2d6f8 100644
71820 --- a/lib/debugobjects.c
71821 +++ b/lib/debugobjects.c
71822 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71823 if (limit > 4)
71824 return;
71825
71826 - is_on_stack = object_is_on_stack(addr);
71827 + is_on_stack = object_starts_on_stack(addr);
71828 if (is_on_stack == onstack)
71829 return;
71830
71831 diff --git a/lib/devres.c b/lib/devres.c
71832 index 80b9c76..9e32279 100644
71833 --- a/lib/devres.c
71834 +++ b/lib/devres.c
71835 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71836 void devm_iounmap(struct device *dev, void __iomem *addr)
71837 {
71838 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71839 - (void *)addr));
71840 + (void __force *)addr));
71841 iounmap(addr);
71842 }
71843 EXPORT_SYMBOL(devm_iounmap);
71844 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71845 {
71846 ioport_unmap(addr);
71847 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71848 - devm_ioport_map_match, (void *)addr));
71849 + devm_ioport_map_match, (void __force *)addr));
71850 }
71851 EXPORT_SYMBOL(devm_ioport_unmap);
71852
71853 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71854 index 66ce414..6f0a0dd 100644
71855 --- a/lib/dma-debug.c
71856 +++ b/lib/dma-debug.c
71857 @@ -924,7 +924,7 @@ out:
71858
71859 static void check_for_stack(struct device *dev, void *addr)
71860 {
71861 - if (object_is_on_stack(addr))
71862 + if (object_starts_on_stack(addr))
71863 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71864 "stack [addr=%p]\n", addr);
71865 }
71866 diff --git a/lib/inflate.c b/lib/inflate.c
71867 index 013a761..c28f3fc 100644
71868 --- a/lib/inflate.c
71869 +++ b/lib/inflate.c
71870 @@ -269,7 +269,7 @@ static void free(void *where)
71871 malloc_ptr = free_mem_ptr;
71872 }
71873 #else
71874 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71875 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71876 #define free(a) kfree(a)
71877 #endif
71878
71879 diff --git a/lib/ioremap.c b/lib/ioremap.c
71880 index 0c9216c..863bd89 100644
71881 --- a/lib/ioremap.c
71882 +++ b/lib/ioremap.c
71883 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71884 unsigned long next;
71885
71886 phys_addr -= addr;
71887 - pmd = pmd_alloc(&init_mm, pud, addr);
71888 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71889 if (!pmd)
71890 return -ENOMEM;
71891 do {
71892 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71893 unsigned long next;
71894
71895 phys_addr -= addr;
71896 - pud = pud_alloc(&init_mm, pgd, addr);
71897 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71898 if (!pud)
71899 return -ENOMEM;
71900 do {
71901 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71902 index bd2bea9..6b3c95e 100644
71903 --- a/lib/is_single_threaded.c
71904 +++ b/lib/is_single_threaded.c
71905 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71906 struct task_struct *p, *t;
71907 bool ret;
71908
71909 + if (!mm)
71910 + return true;
71911 +
71912 if (atomic_read(&task->signal->live) != 1)
71913 return false;
71914
71915 diff --git a/lib/list_debug.c b/lib/list_debug.c
71916 index c24c2f7..bef49ee 100644
71917 --- a/lib/list_debug.c
71918 +++ b/lib/list_debug.c
71919 @@ -23,17 +23,19 @@ void __list_add(struct list_head *new,
71920 struct list_head *prev,
71921 struct list_head *next)
71922 {
71923 - WARN(next->prev != prev,
71924 + if (WARN(next->prev != prev,
71925 "list_add corruption. next->prev should be "
71926 "prev (%p), but was %p. (next=%p).\n",
71927 - prev, next->prev, next);
71928 - WARN(prev->next != next,
71929 + prev, next->prev, next) ||
71930 + WARN(prev->next != next,
71931 "list_add corruption. prev->next should be "
71932 "next (%p), but was %p. (prev=%p).\n",
71933 - next, prev->next, prev);
71934 - WARN(new == prev || new == next,
71935 + next, prev->next, prev) ||
71936 + WARN(new == prev || new == next,
71937 "list_add double add: new=%p, prev=%p, next=%p.\n",
71938 - new, prev, next);
71939 + new, prev, next))
71940 + return;
71941 +
71942 next->prev = new;
71943 new->next = next;
71944 new->prev = prev;
71945 @@ -86,12 +88,14 @@ EXPORT_SYMBOL(list_del);
71946 void __list_add_rcu(struct list_head *new,
71947 struct list_head *prev, struct list_head *next)
71948 {
71949 - WARN(next->prev != prev,
71950 + if (WARN(next->prev != prev,
71951 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
71952 - prev, next->prev, next);
71953 - WARN(prev->next != next,
71954 + prev, next->prev, next) ||
71955 + WARN(prev->next != next,
71956 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
71957 - next, prev->next, prev);
71958 + next, prev->next, prev))
71959 + return;
71960 +
71961 new->next = next;
71962 new->prev = prev;
71963 rcu_assign_pointer(list_next_rcu(prev), new);
71964 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71965 index e796429..6e38f9f 100644
71966 --- a/lib/radix-tree.c
71967 +++ b/lib/radix-tree.c
71968 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71969 int nr;
71970 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71971 };
71972 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71973 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71974
71975 static inline void *ptr_to_indirect(void *ptr)
71976 {
71977 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
71978 index bb2b201..46abaf9 100644
71979 --- a/lib/strncpy_from_user.c
71980 +++ b/lib/strncpy_from_user.c
71981 @@ -21,7 +21,7 @@
71982 */
71983 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
71984 {
71985 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71986 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71987 long res = 0;
71988
71989 /*
71990 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
71991 index a28df52..3d55877 100644
71992 --- a/lib/strnlen_user.c
71993 +++ b/lib/strnlen_user.c
71994 @@ -26,7 +26,7 @@
71995 */
71996 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
71997 {
71998 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71999 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
72000 long align, res = 0;
72001 unsigned long c;
72002
72003 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
72004 index 0e33754..50a0e63 100644
72005 --- a/lib/vsprintf.c
72006 +++ b/lib/vsprintf.c
72007 @@ -16,6 +16,9 @@
72008 * - scnprintf and vscnprintf
72009 */
72010
72011 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72012 +#define __INCLUDED_BY_HIDESYM 1
72013 +#endif
72014 #include <stdarg.h>
72015 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
72016 #include <linux/types.h>
72017 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
72018 char sym[KSYM_SYMBOL_LEN];
72019 if (ext == 'B')
72020 sprint_backtrace(sym, value);
72021 - else if (ext != 'f' && ext != 's')
72022 + else if (ext != 'f' && ext != 's' && ext != 'a')
72023 sprint_symbol(sym, value);
72024 else
72025 sprint_symbol_no_offset(sym, value);
72026 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
72027 return number(buf, end, *(const netdev_features_t *)addr, spec);
72028 }
72029
72030 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72031 +int kptr_restrict __read_mostly = 2;
72032 +#else
72033 int kptr_restrict __read_mostly;
72034 +#endif
72035
72036 /*
72037 * Show a '%p' thing. A kernel extension is that the '%p' is followed
72038 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
72039 * - 'S' For symbolic direct pointers with offset
72040 * - 's' For symbolic direct pointers without offset
72041 * - 'B' For backtraced symbolic direct pointers with offset
72042 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
72043 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
72044 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
72045 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
72046 * - 'M' For a 6-byte MAC address, it prints the address in the
72047 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72048
72049 if (!ptr && *fmt != 'K') {
72050 /*
72051 - * Print (null) with the same width as a pointer so it makes
72052 + * Print (nil) with the same width as a pointer so it makes
72053 * tabular output look nice.
72054 */
72055 if (spec.field_width == -1)
72056 spec.field_width = default_width;
72057 - return string(buf, end, "(null)", spec);
72058 + return string(buf, end, "(nil)", spec);
72059 }
72060
72061 switch (*fmt) {
72062 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72063 /* Fallthrough */
72064 case 'S':
72065 case 's':
72066 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72067 + break;
72068 +#else
72069 + return symbol_string(buf, end, ptr, spec, *fmt);
72070 +#endif
72071 + case 'A':
72072 + case 'a':
72073 case 'B':
72074 return symbol_string(buf, end, ptr, spec, *fmt);
72075 case 'R':
72076 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72077 va_end(va);
72078 return buf;
72079 }
72080 + case 'P':
72081 + break;
72082 case 'K':
72083 /*
72084 * %pK cannot be used in IRQ context because its test
72085 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72086 }
72087 break;
72088 }
72089 +
72090 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72091 + /* 'P' = approved pointers to copy to userland,
72092 + as in the /proc/kallsyms case, as we make it display nothing
72093 + for non-root users, and the real contents for root users
72094 + Also ignore 'K' pointers, since we force their NULLing for non-root users
72095 + above
72096 + */
72097 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
72098 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
72099 + dump_stack();
72100 + ptr = NULL;
72101 + }
72102 +#endif
72103 +
72104 spec.flags |= SMALL;
72105 if (spec.field_width == -1) {
72106 spec.field_width = default_width;
72107 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
72108 typeof(type) value; \
72109 if (sizeof(type) == 8) { \
72110 args = PTR_ALIGN(args, sizeof(u32)); \
72111 - *(u32 *)&value = *(u32 *)args; \
72112 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
72113 + *(u32 *)&value = *(const u32 *)args; \
72114 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
72115 } else { \
72116 args = PTR_ALIGN(args, sizeof(type)); \
72117 - value = *(typeof(type) *)args; \
72118 + value = *(const typeof(type) *)args; \
72119 } \
72120 args += sizeof(type); \
72121 value; \
72122 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
72123 case FORMAT_TYPE_STR: {
72124 const char *str_arg = args;
72125 args += strlen(str_arg) + 1;
72126 - str = string(str, end, (char *)str_arg, spec);
72127 + str = string(str, end, str_arg, spec);
72128 break;
72129 }
72130
72131 diff --git a/localversion-grsec b/localversion-grsec
72132 new file mode 100644
72133 index 0000000..7cd6065
72134 --- /dev/null
72135 +++ b/localversion-grsec
72136 @@ -0,0 +1 @@
72137 +-grsec
72138 diff --git a/mm/Kconfig b/mm/Kconfig
72139 index d5c8019..f513038 100644
72140 --- a/mm/Kconfig
72141 +++ b/mm/Kconfig
72142 @@ -251,10 +251,10 @@ config KSM
72143 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
72144
72145 config DEFAULT_MMAP_MIN_ADDR
72146 - int "Low address space to protect from user allocation"
72147 + int "Low address space to protect from user allocation"
72148 depends on MMU
72149 - default 4096
72150 - help
72151 + default 65536
72152 + help
72153 This is the portion of low virtual memory which should be protected
72154 from userspace allocation. Keeping a user from writing to low pages
72155 can help reduce the impact of kernel NULL pointer bugs.
72156 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
72157
72158 config HWPOISON_INJECT
72159 tristate "HWPoison pages injector"
72160 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
72161 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
72162 select PROC_PAGE_MONITOR
72163
72164 config NOMMU_INITIAL_TRIM_EXCESS
72165 diff --git a/mm/filemap.c b/mm/filemap.c
72166 index 3843445..4fe6833 100644
72167 --- a/mm/filemap.c
72168 +++ b/mm/filemap.c
72169 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
72170 struct address_space *mapping = file->f_mapping;
72171
72172 if (!mapping->a_ops->readpage)
72173 - return -ENOEXEC;
72174 + return -ENODEV;
72175 file_accessed(file);
72176 vma->vm_ops = &generic_file_vm_ops;
72177 vma->vm_flags |= VM_CAN_NONLINEAR;
72178 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
72179 *pos = i_size_read(inode);
72180
72181 if (limit != RLIM_INFINITY) {
72182 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
72183 if (*pos >= limit) {
72184 send_sig(SIGXFSZ, current, 0);
72185 return -EFBIG;
72186 diff --git a/mm/fremap.c b/mm/fremap.c
72187 index 9ed4fd4..c42648d 100644
72188 --- a/mm/fremap.c
72189 +++ b/mm/fremap.c
72190 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
72191 retry:
72192 vma = find_vma(mm, start);
72193
72194 +#ifdef CONFIG_PAX_SEGMEXEC
72195 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
72196 + goto out;
72197 +#endif
72198 +
72199 /*
72200 * Make sure the vma is shared, that it supports prefaulting,
72201 * and that the remapped range is valid and fully within
72202 diff --git a/mm/highmem.c b/mm/highmem.c
72203 index d517cd1..9568fec 100644
72204 --- a/mm/highmem.c
72205 +++ b/mm/highmem.c
72206 @@ -98,7 +98,7 @@ struct page *kmap_to_page(void *vaddr)
72207 {
72208 unsigned long addr = (unsigned long)vaddr;
72209
72210 - if (addr >= PKMAP_ADDR(0) && addr <= PKMAP_ADDR(LAST_PKMAP)) {
72211 + if (addr >= PKMAP_ADDR(0) && addr < PKMAP_ADDR(LAST_PKMAP)) {
72212 int i = (addr - PKMAP_ADDR(0)) >> PAGE_SHIFT;
72213 return pte_page(pkmap_page_table[i]);
72214 }
72215 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
72216 * So no dangers, even with speculative execution.
72217 */
72218 page = pte_page(pkmap_page_table[i]);
72219 + pax_open_kernel();
72220 pte_clear(&init_mm, (unsigned long)page_address(page),
72221 &pkmap_page_table[i]);
72222 -
72223 + pax_close_kernel();
72224 set_page_address(page, NULL);
72225 need_flush = 1;
72226 }
72227 @@ -198,9 +199,11 @@ start:
72228 }
72229 }
72230 vaddr = PKMAP_ADDR(last_pkmap_nr);
72231 +
72232 + pax_open_kernel();
72233 set_pte_at(&init_mm, vaddr,
72234 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
72235 -
72236 + pax_close_kernel();
72237 pkmap_count[last_pkmap_nr] = 1;
72238 set_page_address(page, (void *)vaddr);
72239
72240 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
72241 index 141dbb6..ebff057 100644
72242 --- a/mm/huge_memory.c
72243 +++ b/mm/huge_memory.c
72244 @@ -735,7 +735,7 @@ out:
72245 * run pte_offset_map on the pmd, if an huge pmd could
72246 * materialize from under us from a different thread.
72247 */
72248 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
72249 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72250 return VM_FAULT_OOM;
72251 /* if an huge pmd materialized from under us just retry later */
72252 if (unlikely(pmd_trans_huge(*pmd)))
72253 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
72254 index 3adceaf..dccfea3 100644
72255 --- a/mm/hugetlb.c
72256 +++ b/mm/hugetlb.c
72257 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
72258 return 1;
72259 }
72260
72261 +#ifdef CONFIG_PAX_SEGMEXEC
72262 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
72263 +{
72264 + struct mm_struct *mm = vma->vm_mm;
72265 + struct vm_area_struct *vma_m;
72266 + unsigned long address_m;
72267 + pte_t *ptep_m;
72268 +
72269 + vma_m = pax_find_mirror_vma(vma);
72270 + if (!vma_m)
72271 + return;
72272 +
72273 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72274 + address_m = address + SEGMEXEC_TASK_SIZE;
72275 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
72276 + get_page(page_m);
72277 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
72278 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
72279 +}
72280 +#endif
72281 +
72282 /*
72283 * Hugetlb_cow() should be called with page lock of the original hugepage held.
72284 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
72285 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
72286 make_huge_pte(vma, new_page, 1));
72287 page_remove_rmap(old_page);
72288 hugepage_add_new_anon_rmap(new_page, vma, address);
72289 +
72290 +#ifdef CONFIG_PAX_SEGMEXEC
72291 + pax_mirror_huge_pte(vma, address, new_page);
72292 +#endif
72293 +
72294 /* Make the old page be freed below */
72295 new_page = old_page;
72296 mmu_notifier_invalidate_range_end(mm,
72297 @@ -2786,6 +2812,10 @@ retry:
72298 && (vma->vm_flags & VM_SHARED)));
72299 set_huge_pte_at(mm, address, ptep, new_pte);
72300
72301 +#ifdef CONFIG_PAX_SEGMEXEC
72302 + pax_mirror_huge_pte(vma, address, page);
72303 +#endif
72304 +
72305 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
72306 /* Optimization, do the COW without a second fault */
72307 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
72308 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72309 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
72310 struct hstate *h = hstate_vma(vma);
72311
72312 +#ifdef CONFIG_PAX_SEGMEXEC
72313 + struct vm_area_struct *vma_m;
72314 +#endif
72315 +
72316 address &= huge_page_mask(h);
72317
72318 ptep = huge_pte_offset(mm, address);
72319 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72320 VM_FAULT_SET_HINDEX(hstate_index(h));
72321 }
72322
72323 +#ifdef CONFIG_PAX_SEGMEXEC
72324 + vma_m = pax_find_mirror_vma(vma);
72325 + if (vma_m) {
72326 + unsigned long address_m;
72327 +
72328 + if (vma->vm_start > vma_m->vm_start) {
72329 + address_m = address;
72330 + address -= SEGMEXEC_TASK_SIZE;
72331 + vma = vma_m;
72332 + h = hstate_vma(vma);
72333 + } else
72334 + address_m = address + SEGMEXEC_TASK_SIZE;
72335 +
72336 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
72337 + return VM_FAULT_OOM;
72338 + address_m &= HPAGE_MASK;
72339 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
72340 + }
72341 +#endif
72342 +
72343 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
72344 if (!ptep)
72345 return VM_FAULT_OOM;
72346 diff --git a/mm/internal.h b/mm/internal.h
72347 index b8c91b3..93e95a3 100644
72348 --- a/mm/internal.h
72349 +++ b/mm/internal.h
72350 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
72351 * in mm/page_alloc.c
72352 */
72353 extern void __free_pages_bootmem(struct page *page, unsigned int order);
72354 +extern void free_compound_page(struct page *page);
72355 extern void prep_compound_page(struct page *page, unsigned long order);
72356 #ifdef CONFIG_MEMORY_FAILURE
72357 extern bool is_free_buddy_page(struct page *page);
72358 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
72359 index 45eb621..6ccd8ea 100644
72360 --- a/mm/kmemleak.c
72361 +++ b/mm/kmemleak.c
72362 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
72363
72364 for (i = 0; i < object->trace_len; i++) {
72365 void *ptr = (void *)object->trace[i];
72366 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
72367 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
72368 }
72369 }
72370
72371 diff --git a/mm/maccess.c b/mm/maccess.c
72372 index d53adf9..03a24bf 100644
72373 --- a/mm/maccess.c
72374 +++ b/mm/maccess.c
72375 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
72376 set_fs(KERNEL_DS);
72377 pagefault_disable();
72378 ret = __copy_from_user_inatomic(dst,
72379 - (__force const void __user *)src, size);
72380 + (const void __force_user *)src, size);
72381 pagefault_enable();
72382 set_fs(old_fs);
72383
72384 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
72385
72386 set_fs(KERNEL_DS);
72387 pagefault_disable();
72388 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
72389 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
72390 pagefault_enable();
72391 set_fs(old_fs);
72392
72393 diff --git a/mm/madvise.c b/mm/madvise.c
72394 index 14d260f..b2a80fd 100644
72395 --- a/mm/madvise.c
72396 +++ b/mm/madvise.c
72397 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
72398 pgoff_t pgoff;
72399 unsigned long new_flags = vma->vm_flags;
72400
72401 +#ifdef CONFIG_PAX_SEGMEXEC
72402 + struct vm_area_struct *vma_m;
72403 +#endif
72404 +
72405 switch (behavior) {
72406 case MADV_NORMAL:
72407 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
72408 @@ -119,6 +123,13 @@ success:
72409 /*
72410 * vm_flags is protected by the mmap_sem held in write mode.
72411 */
72412 +
72413 +#ifdef CONFIG_PAX_SEGMEXEC
72414 + vma_m = pax_find_mirror_vma(vma);
72415 + if (vma_m)
72416 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
72417 +#endif
72418 +
72419 vma->vm_flags = new_flags;
72420
72421 out:
72422 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72423 struct vm_area_struct ** prev,
72424 unsigned long start, unsigned long end)
72425 {
72426 +
72427 +#ifdef CONFIG_PAX_SEGMEXEC
72428 + struct vm_area_struct *vma_m;
72429 +#endif
72430 +
72431 *prev = vma;
72432 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
72433 return -EINVAL;
72434 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72435 zap_page_range(vma, start, end - start, &details);
72436 } else
72437 zap_page_range(vma, start, end - start, NULL);
72438 +
72439 +#ifdef CONFIG_PAX_SEGMEXEC
72440 + vma_m = pax_find_mirror_vma(vma);
72441 + if (vma_m) {
72442 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
72443 + struct zap_details details = {
72444 + .nonlinear_vma = vma_m,
72445 + .last_index = ULONG_MAX,
72446 + };
72447 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
72448 + } else
72449 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
72450 + }
72451 +#endif
72452 +
72453 return 0;
72454 }
72455
72456 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
72457 if (end < start)
72458 goto out;
72459
72460 +#ifdef CONFIG_PAX_SEGMEXEC
72461 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72462 + if (end > SEGMEXEC_TASK_SIZE)
72463 + goto out;
72464 + } else
72465 +#endif
72466 +
72467 + if (end > TASK_SIZE)
72468 + goto out;
72469 +
72470 error = 0;
72471 if (end == start)
72472 goto out;
72473 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
72474 index 3dd21e2..0e32042 100644
72475 --- a/mm/memory-failure.c
72476 +++ b/mm/memory-failure.c
72477 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
72478
72479 int sysctl_memory_failure_recovery __read_mostly = 1;
72480
72481 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72482 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72483
72484 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72485
72486 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
72487 pfn, t->comm, t->pid);
72488 si.si_signo = SIGBUS;
72489 si.si_errno = 0;
72490 - si.si_addr = (void *)addr;
72491 + si.si_addr = (void __user *)addr;
72492 #ifdef __ARCH_SI_TRAPNO
72493 si.si_trapno = trapno;
72494 #endif
72495 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72496 }
72497
72498 nr_pages = 1 << compound_trans_order(hpage);
72499 - atomic_long_add(nr_pages, &mce_bad_pages);
72500 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72501
72502 /*
72503 * We need/can do nothing about count=0 pages.
72504 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72505 if (!PageHWPoison(hpage)
72506 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72507 || (p != hpage && TestSetPageHWPoison(hpage))) {
72508 - atomic_long_sub(nr_pages, &mce_bad_pages);
72509 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72510 return 0;
72511 }
72512 set_page_hwpoison_huge_page(hpage);
72513 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72514 }
72515 if (hwpoison_filter(p)) {
72516 if (TestClearPageHWPoison(p))
72517 - atomic_long_sub(nr_pages, &mce_bad_pages);
72518 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72519 unlock_page(hpage);
72520 put_page(hpage);
72521 return 0;
72522 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
72523 return 0;
72524 }
72525 if (TestClearPageHWPoison(p))
72526 - atomic_long_sub(nr_pages, &mce_bad_pages);
72527 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72528 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72529 return 0;
72530 }
72531 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
72532 */
72533 if (TestClearPageHWPoison(page)) {
72534 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72535 - atomic_long_sub(nr_pages, &mce_bad_pages);
72536 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72537 freeit = 1;
72538 if (PageHuge(page))
72539 clear_page_hwpoison_huge_page(page);
72540 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
72541 }
72542 done:
72543 if (!PageHWPoison(hpage))
72544 - atomic_long_add(1 << compound_trans_order(hpage),
72545 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
72546 &mce_bad_pages);
72547 set_page_hwpoison_huge_page(hpage);
72548 dequeue_hwpoisoned_huge_page(hpage);
72549 @@ -1580,7 +1580,7 @@ int soft_offline_page(struct page *page, int flags)
72550 return ret;
72551
72552 done:
72553 - atomic_long_add(1, &mce_bad_pages);
72554 + atomic_long_add_unchecked(1, &mce_bad_pages);
72555 SetPageHWPoison(page);
72556 /* keep elevated page count for bad page */
72557 return ret;
72558 diff --git a/mm/memory.c b/mm/memory.c
72559 index 5736170..8e04800 100644
72560 --- a/mm/memory.c
72561 +++ b/mm/memory.c
72562 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72563 free_pte_range(tlb, pmd, addr);
72564 } while (pmd++, addr = next, addr != end);
72565
72566 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
72567 start &= PUD_MASK;
72568 if (start < floor)
72569 return;
72570 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72571 pmd = pmd_offset(pud, start);
72572 pud_clear(pud);
72573 pmd_free_tlb(tlb, pmd, start);
72574 +#endif
72575 +
72576 }
72577
72578 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72579 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72580 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72581 } while (pud++, addr = next, addr != end);
72582
72583 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72584 start &= PGDIR_MASK;
72585 if (start < floor)
72586 return;
72587 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72588 pud = pud_offset(pgd, start);
72589 pgd_clear(pgd);
72590 pud_free_tlb(tlb, pud, start);
72591 +#endif
72592 +
72593 }
72594
72595 /*
72596 @@ -1614,12 +1620,6 @@ no_page_table:
72597 return page;
72598 }
72599
72600 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72601 -{
72602 - return stack_guard_page_start(vma, addr) ||
72603 - stack_guard_page_end(vma, addr+PAGE_SIZE);
72604 -}
72605 -
72606 /**
72607 * __get_user_pages() - pin user pages in memory
72608 * @tsk: task_struct of target task
72609 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72610 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72611 i = 0;
72612
72613 - do {
72614 + while (nr_pages) {
72615 struct vm_area_struct *vma;
72616
72617 - vma = find_extend_vma(mm, start);
72618 + vma = find_vma(mm, start);
72619 if (!vma && in_gate_area(mm, start)) {
72620 unsigned long pg = start & PAGE_MASK;
72621 pgd_t *pgd;
72622 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72623 goto next_page;
72624 }
72625
72626 - if (!vma ||
72627 + if (!vma || start < vma->vm_start ||
72628 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72629 !(vm_flags & vma->vm_flags))
72630 return i ? : -EFAULT;
72631 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72632 int ret;
72633 unsigned int fault_flags = 0;
72634
72635 - /* For mlock, just skip the stack guard page. */
72636 - if (foll_flags & FOLL_MLOCK) {
72637 - if (stack_guard_page(vma, start))
72638 - goto next_page;
72639 - }
72640 if (foll_flags & FOLL_WRITE)
72641 fault_flags |= FAULT_FLAG_WRITE;
72642 if (nonblocking)
72643 @@ -1848,7 +1843,7 @@ next_page:
72644 start += PAGE_SIZE;
72645 nr_pages--;
72646 } while (nr_pages && start < vma->vm_end);
72647 - } while (nr_pages);
72648 + }
72649 return i;
72650 }
72651 EXPORT_SYMBOL(__get_user_pages);
72652 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72653 page_add_file_rmap(page);
72654 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72655
72656 +#ifdef CONFIG_PAX_SEGMEXEC
72657 + pax_mirror_file_pte(vma, addr, page, ptl);
72658 +#endif
72659 +
72660 retval = 0;
72661 pte_unmap_unlock(pte, ptl);
72662 return retval;
72663 @@ -2089,10 +2088,22 @@ out:
72664 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72665 struct page *page)
72666 {
72667 +
72668 +#ifdef CONFIG_PAX_SEGMEXEC
72669 + struct vm_area_struct *vma_m;
72670 +#endif
72671 +
72672 if (addr < vma->vm_start || addr >= vma->vm_end)
72673 return -EFAULT;
72674 if (!page_count(page))
72675 return -EINVAL;
72676 +
72677 +#ifdef CONFIG_PAX_SEGMEXEC
72678 + vma_m = pax_find_mirror_vma(vma);
72679 + if (vma_m)
72680 + vma_m->vm_flags |= VM_INSERTPAGE;
72681 +#endif
72682 +
72683 vma->vm_flags |= VM_INSERTPAGE;
72684 return insert_page(vma, addr, page, vma->vm_page_prot);
72685 }
72686 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72687 unsigned long pfn)
72688 {
72689 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72690 + BUG_ON(vma->vm_mirror);
72691
72692 if (addr < vma->vm_start || addr >= vma->vm_end)
72693 return -EFAULT;
72694 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72695
72696 BUG_ON(pud_huge(*pud));
72697
72698 - pmd = pmd_alloc(mm, pud, addr);
72699 + pmd = (mm == &init_mm) ?
72700 + pmd_alloc_kernel(mm, pud, addr) :
72701 + pmd_alloc(mm, pud, addr);
72702 if (!pmd)
72703 return -ENOMEM;
72704 do {
72705 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72706 unsigned long next;
72707 int err;
72708
72709 - pud = pud_alloc(mm, pgd, addr);
72710 + pud = (mm == &init_mm) ?
72711 + pud_alloc_kernel(mm, pgd, addr) :
72712 + pud_alloc(mm, pgd, addr);
72713 if (!pud)
72714 return -ENOMEM;
72715 do {
72716 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72717 copy_user_highpage(dst, src, va, vma);
72718 }
72719
72720 +#ifdef CONFIG_PAX_SEGMEXEC
72721 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72722 +{
72723 + struct mm_struct *mm = vma->vm_mm;
72724 + spinlock_t *ptl;
72725 + pte_t *pte, entry;
72726 +
72727 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72728 + entry = *pte;
72729 + if (!pte_present(entry)) {
72730 + if (!pte_none(entry)) {
72731 + BUG_ON(pte_file(entry));
72732 + free_swap_and_cache(pte_to_swp_entry(entry));
72733 + pte_clear_not_present_full(mm, address, pte, 0);
72734 + }
72735 + } else {
72736 + struct page *page;
72737 +
72738 + flush_cache_page(vma, address, pte_pfn(entry));
72739 + entry = ptep_clear_flush(vma, address, pte);
72740 + BUG_ON(pte_dirty(entry));
72741 + page = vm_normal_page(vma, address, entry);
72742 + if (page) {
72743 + update_hiwater_rss(mm);
72744 + if (PageAnon(page))
72745 + dec_mm_counter_fast(mm, MM_ANONPAGES);
72746 + else
72747 + dec_mm_counter_fast(mm, MM_FILEPAGES);
72748 + page_remove_rmap(page);
72749 + page_cache_release(page);
72750 + }
72751 + }
72752 + pte_unmap_unlock(pte, ptl);
72753 +}
72754 +
72755 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
72756 + *
72757 + * the ptl of the lower mapped page is held on entry and is not released on exit
72758 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72759 + */
72760 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72761 +{
72762 + struct mm_struct *mm = vma->vm_mm;
72763 + unsigned long address_m;
72764 + spinlock_t *ptl_m;
72765 + struct vm_area_struct *vma_m;
72766 + pmd_t *pmd_m;
72767 + pte_t *pte_m, entry_m;
72768 +
72769 + BUG_ON(!page_m || !PageAnon(page_m));
72770 +
72771 + vma_m = pax_find_mirror_vma(vma);
72772 + if (!vma_m)
72773 + return;
72774 +
72775 + BUG_ON(!PageLocked(page_m));
72776 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72777 + address_m = address + SEGMEXEC_TASK_SIZE;
72778 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72779 + pte_m = pte_offset_map(pmd_m, address_m);
72780 + ptl_m = pte_lockptr(mm, pmd_m);
72781 + if (ptl != ptl_m) {
72782 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72783 + if (!pte_none(*pte_m))
72784 + goto out;
72785 + }
72786 +
72787 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72788 + page_cache_get(page_m);
72789 + page_add_anon_rmap(page_m, vma_m, address_m);
72790 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72791 + set_pte_at(mm, address_m, pte_m, entry_m);
72792 + update_mmu_cache(vma_m, address_m, entry_m);
72793 +out:
72794 + if (ptl != ptl_m)
72795 + spin_unlock(ptl_m);
72796 + pte_unmap(pte_m);
72797 + unlock_page(page_m);
72798 +}
72799 +
72800 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72801 +{
72802 + struct mm_struct *mm = vma->vm_mm;
72803 + unsigned long address_m;
72804 + spinlock_t *ptl_m;
72805 + struct vm_area_struct *vma_m;
72806 + pmd_t *pmd_m;
72807 + pte_t *pte_m, entry_m;
72808 +
72809 + BUG_ON(!page_m || PageAnon(page_m));
72810 +
72811 + vma_m = pax_find_mirror_vma(vma);
72812 + if (!vma_m)
72813 + return;
72814 +
72815 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72816 + address_m = address + SEGMEXEC_TASK_SIZE;
72817 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72818 + pte_m = pte_offset_map(pmd_m, address_m);
72819 + ptl_m = pte_lockptr(mm, pmd_m);
72820 + if (ptl != ptl_m) {
72821 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72822 + if (!pte_none(*pte_m))
72823 + goto out;
72824 + }
72825 +
72826 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72827 + page_cache_get(page_m);
72828 + page_add_file_rmap(page_m);
72829 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72830 + set_pte_at(mm, address_m, pte_m, entry_m);
72831 + update_mmu_cache(vma_m, address_m, entry_m);
72832 +out:
72833 + if (ptl != ptl_m)
72834 + spin_unlock(ptl_m);
72835 + pte_unmap(pte_m);
72836 +}
72837 +
72838 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72839 +{
72840 + struct mm_struct *mm = vma->vm_mm;
72841 + unsigned long address_m;
72842 + spinlock_t *ptl_m;
72843 + struct vm_area_struct *vma_m;
72844 + pmd_t *pmd_m;
72845 + pte_t *pte_m, entry_m;
72846 +
72847 + vma_m = pax_find_mirror_vma(vma);
72848 + if (!vma_m)
72849 + return;
72850 +
72851 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72852 + address_m = address + SEGMEXEC_TASK_SIZE;
72853 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72854 + pte_m = pte_offset_map(pmd_m, address_m);
72855 + ptl_m = pte_lockptr(mm, pmd_m);
72856 + if (ptl != ptl_m) {
72857 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72858 + if (!pte_none(*pte_m))
72859 + goto out;
72860 + }
72861 +
72862 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72863 + set_pte_at(mm, address_m, pte_m, entry_m);
72864 +out:
72865 + if (ptl != ptl_m)
72866 + spin_unlock(ptl_m);
72867 + pte_unmap(pte_m);
72868 +}
72869 +
72870 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72871 +{
72872 + struct page *page_m;
72873 + pte_t entry;
72874 +
72875 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72876 + goto out;
72877 +
72878 + entry = *pte;
72879 + page_m = vm_normal_page(vma, address, entry);
72880 + if (!page_m)
72881 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72882 + else if (PageAnon(page_m)) {
72883 + if (pax_find_mirror_vma(vma)) {
72884 + pte_unmap_unlock(pte, ptl);
72885 + lock_page(page_m);
72886 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72887 + if (pte_same(entry, *pte))
72888 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72889 + else
72890 + unlock_page(page_m);
72891 + }
72892 + } else
72893 + pax_mirror_file_pte(vma, address, page_m, ptl);
72894 +
72895 +out:
72896 + pte_unmap_unlock(pte, ptl);
72897 +}
72898 +#endif
72899 +
72900 /*
72901 * This routine handles present pages, when users try to write
72902 * to a shared page. It is done by copying the page to a new address
72903 @@ -2703,6 +2899,12 @@ gotten:
72904 */
72905 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72906 if (likely(pte_same(*page_table, orig_pte))) {
72907 +
72908 +#ifdef CONFIG_PAX_SEGMEXEC
72909 + if (pax_find_mirror_vma(vma))
72910 + BUG_ON(!trylock_page(new_page));
72911 +#endif
72912 +
72913 if (old_page) {
72914 if (!PageAnon(old_page)) {
72915 dec_mm_counter_fast(mm, MM_FILEPAGES);
72916 @@ -2754,6 +2956,10 @@ gotten:
72917 page_remove_rmap(old_page);
72918 }
72919
72920 +#ifdef CONFIG_PAX_SEGMEXEC
72921 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72922 +#endif
72923 +
72924 /* Free the old page.. */
72925 new_page = old_page;
72926 ret |= VM_FAULT_WRITE;
72927 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72928 swap_free(entry);
72929 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72930 try_to_free_swap(page);
72931 +
72932 +#ifdef CONFIG_PAX_SEGMEXEC
72933 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72934 +#endif
72935 +
72936 unlock_page(page);
72937 if (swapcache) {
72938 /*
72939 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72940
72941 /* No need to invalidate - it was non-present before */
72942 update_mmu_cache(vma, address, page_table);
72943 +
72944 +#ifdef CONFIG_PAX_SEGMEXEC
72945 + pax_mirror_anon_pte(vma, address, page, ptl);
72946 +#endif
72947 +
72948 unlock:
72949 pte_unmap_unlock(page_table, ptl);
72950 out:
72951 @@ -3075,40 +3291,6 @@ out_release:
72952 }
72953
72954 /*
72955 - * This is like a special single-page "expand_{down|up}wards()",
72956 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72957 - * doesn't hit another vma.
72958 - */
72959 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72960 -{
72961 - address &= PAGE_MASK;
72962 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72963 - struct vm_area_struct *prev = vma->vm_prev;
72964 -
72965 - /*
72966 - * Is there a mapping abutting this one below?
72967 - *
72968 - * That's only ok if it's the same stack mapping
72969 - * that has gotten split..
72970 - */
72971 - if (prev && prev->vm_end == address)
72972 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72973 -
72974 - expand_downwards(vma, address - PAGE_SIZE);
72975 - }
72976 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72977 - struct vm_area_struct *next = vma->vm_next;
72978 -
72979 - /* As VM_GROWSDOWN but s/below/above/ */
72980 - if (next && next->vm_start == address + PAGE_SIZE)
72981 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72982 -
72983 - expand_upwards(vma, address + PAGE_SIZE);
72984 - }
72985 - return 0;
72986 -}
72987 -
72988 -/*
72989 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72990 * but allow concurrent faults), and pte mapped but not yet locked.
72991 * We return with mmap_sem still held, but pte unmapped and unlocked.
72992 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72993 unsigned long address, pte_t *page_table, pmd_t *pmd,
72994 unsigned int flags)
72995 {
72996 - struct page *page;
72997 + struct page *page = NULL;
72998 spinlock_t *ptl;
72999 pte_t entry;
73000
73001 - pte_unmap(page_table);
73002 -
73003 - /* Check if we need to add a guard page to the stack */
73004 - if (check_stack_guard_page(vma, address) < 0)
73005 - return VM_FAULT_SIGBUS;
73006 -
73007 - /* Use the zero-page for reads */
73008 if (!(flags & FAULT_FLAG_WRITE)) {
73009 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
73010 vma->vm_page_prot));
73011 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
73012 + ptl = pte_lockptr(mm, pmd);
73013 + spin_lock(ptl);
73014 if (!pte_none(*page_table))
73015 goto unlock;
73016 goto setpte;
73017 }
73018
73019 /* Allocate our own private page. */
73020 + pte_unmap(page_table);
73021 +
73022 if (unlikely(anon_vma_prepare(vma)))
73023 goto oom;
73024 page = alloc_zeroed_user_highpage_movable(vma, address);
73025 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
73026 if (!pte_none(*page_table))
73027 goto release;
73028
73029 +#ifdef CONFIG_PAX_SEGMEXEC
73030 + if (pax_find_mirror_vma(vma))
73031 + BUG_ON(!trylock_page(page));
73032 +#endif
73033 +
73034 inc_mm_counter_fast(mm, MM_ANONPAGES);
73035 page_add_new_anon_rmap(page, vma, address);
73036 setpte:
73037 @@ -3163,6 +3346,12 @@ setpte:
73038
73039 /* No need to invalidate - it was non-present before */
73040 update_mmu_cache(vma, address, page_table);
73041 +
73042 +#ifdef CONFIG_PAX_SEGMEXEC
73043 + if (page)
73044 + pax_mirror_anon_pte(vma, address, page, ptl);
73045 +#endif
73046 +
73047 unlock:
73048 pte_unmap_unlock(page_table, ptl);
73049 return 0;
73050 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73051 */
73052 /* Only go through if we didn't race with anybody else... */
73053 if (likely(pte_same(*page_table, orig_pte))) {
73054 +
73055 +#ifdef CONFIG_PAX_SEGMEXEC
73056 + if (anon && pax_find_mirror_vma(vma))
73057 + BUG_ON(!trylock_page(page));
73058 +#endif
73059 +
73060 flush_icache_page(vma, page);
73061 entry = mk_pte(page, vma->vm_page_prot);
73062 if (flags & FAULT_FLAG_WRITE)
73063 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73064
73065 /* no need to invalidate: a not-present page won't be cached */
73066 update_mmu_cache(vma, address, page_table);
73067 +
73068 +#ifdef CONFIG_PAX_SEGMEXEC
73069 + if (anon)
73070 + pax_mirror_anon_pte(vma, address, page, ptl);
73071 + else
73072 + pax_mirror_file_pte(vma, address, page, ptl);
73073 +#endif
73074 +
73075 } else {
73076 if (cow_page)
73077 mem_cgroup_uncharge_page(cow_page);
73078 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
73079 if (flags & FAULT_FLAG_WRITE)
73080 flush_tlb_fix_spurious_fault(vma, address);
73081 }
73082 +
73083 +#ifdef CONFIG_PAX_SEGMEXEC
73084 + pax_mirror_pte(vma, address, pte, pmd, ptl);
73085 + return 0;
73086 +#endif
73087 +
73088 unlock:
73089 pte_unmap_unlock(pte, ptl);
73090 return 0;
73091 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73092 pmd_t *pmd;
73093 pte_t *pte;
73094
73095 +#ifdef CONFIG_PAX_SEGMEXEC
73096 + struct vm_area_struct *vma_m;
73097 +#endif
73098 +
73099 __set_current_state(TASK_RUNNING);
73100
73101 count_vm_event(PGFAULT);
73102 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73103 if (unlikely(is_vm_hugetlb_page(vma)))
73104 return hugetlb_fault(mm, vma, address, flags);
73105
73106 +#ifdef CONFIG_PAX_SEGMEXEC
73107 + vma_m = pax_find_mirror_vma(vma);
73108 + if (vma_m) {
73109 + unsigned long address_m;
73110 + pgd_t *pgd_m;
73111 + pud_t *pud_m;
73112 + pmd_t *pmd_m;
73113 +
73114 + if (vma->vm_start > vma_m->vm_start) {
73115 + address_m = address;
73116 + address -= SEGMEXEC_TASK_SIZE;
73117 + vma = vma_m;
73118 + } else
73119 + address_m = address + SEGMEXEC_TASK_SIZE;
73120 +
73121 + pgd_m = pgd_offset(mm, address_m);
73122 + pud_m = pud_alloc(mm, pgd_m, address_m);
73123 + if (!pud_m)
73124 + return VM_FAULT_OOM;
73125 + pmd_m = pmd_alloc(mm, pud_m, address_m);
73126 + if (!pmd_m)
73127 + return VM_FAULT_OOM;
73128 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
73129 + return VM_FAULT_OOM;
73130 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
73131 + }
73132 +#endif
73133 +
73134 retry:
73135 pgd = pgd_offset(mm, address);
73136 pud = pud_alloc(mm, pgd, address);
73137 @@ -3547,7 +3788,7 @@ retry:
73138 * run pte_offset_map on the pmd, if an huge pmd could
73139 * materialize from under us from a different thread.
73140 */
73141 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
73142 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
73143 return VM_FAULT_OOM;
73144 /* if an huge pmd materialized from under us just retry later */
73145 if (unlikely(pmd_trans_huge(*pmd)))
73146 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73147 spin_unlock(&mm->page_table_lock);
73148 return 0;
73149 }
73150 +
73151 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73152 +{
73153 + pud_t *new = pud_alloc_one(mm, address);
73154 + if (!new)
73155 + return -ENOMEM;
73156 +
73157 + smp_wmb(); /* See comment in __pte_alloc */
73158 +
73159 + spin_lock(&mm->page_table_lock);
73160 + if (pgd_present(*pgd)) /* Another has populated it */
73161 + pud_free(mm, new);
73162 + else
73163 + pgd_populate_kernel(mm, pgd, new);
73164 + spin_unlock(&mm->page_table_lock);
73165 + return 0;
73166 +}
73167 #endif /* __PAGETABLE_PUD_FOLDED */
73168
73169 #ifndef __PAGETABLE_PMD_FOLDED
73170 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
73171 spin_unlock(&mm->page_table_lock);
73172 return 0;
73173 }
73174 +
73175 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
73176 +{
73177 + pmd_t *new = pmd_alloc_one(mm, address);
73178 + if (!new)
73179 + return -ENOMEM;
73180 +
73181 + smp_wmb(); /* See comment in __pte_alloc */
73182 +
73183 + spin_lock(&mm->page_table_lock);
73184 +#ifndef __ARCH_HAS_4LEVEL_HACK
73185 + if (pud_present(*pud)) /* Another has populated it */
73186 + pmd_free(mm, new);
73187 + else
73188 + pud_populate_kernel(mm, pud, new);
73189 +#else
73190 + if (pgd_present(*pud)) /* Another has populated it */
73191 + pmd_free(mm, new);
73192 + else
73193 + pgd_populate_kernel(mm, pud, new);
73194 +#endif /* __ARCH_HAS_4LEVEL_HACK */
73195 + spin_unlock(&mm->page_table_lock);
73196 + return 0;
73197 +}
73198 #endif /* __PAGETABLE_PMD_FOLDED */
73199
73200 int make_pages_present(unsigned long addr, unsigned long end)
73201 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
73202 gate_vma.vm_start = FIXADDR_USER_START;
73203 gate_vma.vm_end = FIXADDR_USER_END;
73204 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
73205 - gate_vma.vm_page_prot = __P101;
73206 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
73207
73208 return 0;
73209 }
73210 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
73211 index 3d64b36..5c2d5d3 100644
73212 --- a/mm/mempolicy.c
73213 +++ b/mm/mempolicy.c
73214 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
73215 unsigned long vmstart;
73216 unsigned long vmend;
73217
73218 +#ifdef CONFIG_PAX_SEGMEXEC
73219 + struct vm_area_struct *vma_m;
73220 +#endif
73221 +
73222 vma = find_vma(mm, start);
73223 if (!vma || vma->vm_start > start)
73224 return -EFAULT;
73225 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
73226 if (err)
73227 goto out;
73228 }
73229 +
73230 err = vma_replace_policy(vma, new_pol);
73231 if (err)
73232 goto out;
73233 +
73234 +#ifdef CONFIG_PAX_SEGMEXEC
73235 + vma_m = pax_find_mirror_vma(vma);
73236 + if (vma_m) {
73237 + err = vma_replace_policy(vma_m, new_pol);
73238 + if (err)
73239 + goto out;
73240 + }
73241 +#endif
73242 +
73243 }
73244
73245 out:
73246 @@ -1147,6 +1162,17 @@ static long do_mbind(unsigned long start, unsigned long len,
73247
73248 if (end < start)
73249 return -EINVAL;
73250 +
73251 +#ifdef CONFIG_PAX_SEGMEXEC
73252 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73253 + if (end > SEGMEXEC_TASK_SIZE)
73254 + return -EINVAL;
73255 + } else
73256 +#endif
73257 +
73258 + if (end > TASK_SIZE)
73259 + return -EINVAL;
73260 +
73261 if (end == start)
73262 return 0;
73263
73264 @@ -1370,8 +1396,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73265 */
73266 tcred = __task_cred(task);
73267 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73268 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73269 - !capable(CAP_SYS_NICE)) {
73270 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73271 rcu_read_unlock();
73272 err = -EPERM;
73273 goto out_put;
73274 @@ -1402,6 +1427,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73275 goto out;
73276 }
73277
73278 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
73279 + if (mm != current->mm &&
73280 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
73281 + mmput(mm);
73282 + err = -EPERM;
73283 + goto out;
73284 + }
73285 +#endif
73286 +
73287 err = do_migrate_pages(mm, old, new,
73288 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
73289
73290 @@ -2035,28 +2069,6 @@ struct mempolicy *__mpol_dup(struct mempolicy *old)
73291 return new;
73292 }
73293
73294 -/*
73295 - * If *frompol needs [has] an extra ref, copy *frompol to *tompol ,
73296 - * eliminate the * MPOL_F_* flags that require conditional ref and
73297 - * [NOTE!!!] drop the extra ref. Not safe to reference *frompol directly
73298 - * after return. Use the returned value.
73299 - *
73300 - * Allows use of a mempolicy for, e.g., multiple allocations with a single
73301 - * policy lookup, even if the policy needs/has extra ref on lookup.
73302 - * shmem_readahead needs this.
73303 - */
73304 -struct mempolicy *__mpol_cond_copy(struct mempolicy *tompol,
73305 - struct mempolicy *frompol)
73306 -{
73307 - if (!mpol_needs_cond_ref(frompol))
73308 - return frompol;
73309 -
73310 - *tompol = *frompol;
73311 - tompol->flags &= ~MPOL_F_SHARED; /* copy doesn't need unref */
73312 - __mpol_put(frompol);
73313 - return tompol;
73314 -}
73315 -
73316 /* Slow path of a mempolicy comparison */
73317 bool __mpol_equal(struct mempolicy *a, struct mempolicy *b)
73318 {
73319 diff --git a/mm/migrate.c b/mm/migrate.c
73320 index 77ed2d7..317d528 100644
73321 --- a/mm/migrate.c
73322 +++ b/mm/migrate.c
73323 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
73324 */
73325 tcred = __task_cred(task);
73326 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73327 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73328 - !capable(CAP_SYS_NICE)) {
73329 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73330 rcu_read_unlock();
73331 err = -EPERM;
73332 goto out;
73333 diff --git a/mm/mlock.c b/mm/mlock.c
73334 index ef726e8..cd7f1ec 100644
73335 --- a/mm/mlock.c
73336 +++ b/mm/mlock.c
73337 @@ -13,6 +13,7 @@
73338 #include <linux/pagemap.h>
73339 #include <linux/mempolicy.h>
73340 #include <linux/syscalls.h>
73341 +#include <linux/security.h>
73342 #include <linux/sched.h>
73343 #include <linux/export.h>
73344 #include <linux/rmap.h>
73345 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
73346 {
73347 unsigned long nstart, end, tmp;
73348 struct vm_area_struct * vma, * prev;
73349 - int error;
73350 + int error = 0;
73351
73352 VM_BUG_ON(start & ~PAGE_MASK);
73353 VM_BUG_ON(len != PAGE_ALIGN(len));
73354 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
73355 return -EINVAL;
73356 if (end == start)
73357 return 0;
73358 + if (end > TASK_SIZE)
73359 + return -EINVAL;
73360 +
73361 vma = find_vma(current->mm, start);
73362 if (!vma || vma->vm_start > start)
73363 return -ENOMEM;
73364 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
73365 for (nstart = start ; ; ) {
73366 vm_flags_t newflags;
73367
73368 +#ifdef CONFIG_PAX_SEGMEXEC
73369 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73370 + break;
73371 +#endif
73372 +
73373 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
73374
73375 newflags = vma->vm_flags | VM_LOCKED;
73376 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
73377 lock_limit >>= PAGE_SHIFT;
73378
73379 /* check against resource limits */
73380 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
73381 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
73382 error = do_mlock(start, len, 1);
73383 up_write(&current->mm->mmap_sem);
73384 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
73385 static int do_mlockall(int flags)
73386 {
73387 struct vm_area_struct * vma, * prev = NULL;
73388 - unsigned int def_flags = 0;
73389
73390 if (flags & MCL_FUTURE)
73391 - def_flags = VM_LOCKED;
73392 - current->mm->def_flags = def_flags;
73393 + current->mm->def_flags |= VM_LOCKED;
73394 + else
73395 + current->mm->def_flags &= ~VM_LOCKED;
73396 if (flags == MCL_FUTURE)
73397 goto out;
73398
73399 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
73400 vm_flags_t newflags;
73401
73402 +#ifdef CONFIG_PAX_SEGMEXEC
73403 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73404 + break;
73405 +#endif
73406 +
73407 + BUG_ON(vma->vm_end > TASK_SIZE);
73408 newflags = vma->vm_flags | VM_LOCKED;
73409 if (!(flags & MCL_CURRENT))
73410 newflags &= ~VM_LOCKED;
73411 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
73412 lock_limit >>= PAGE_SHIFT;
73413
73414 ret = -ENOMEM;
73415 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
73416 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
73417 capable(CAP_IPC_LOCK))
73418 ret = do_mlockall(flags);
73419 diff --git a/mm/mmap.c b/mm/mmap.c
73420 index ae18a48..86cf99e 100644
73421 --- a/mm/mmap.c
73422 +++ b/mm/mmap.c
73423 @@ -47,6 +47,16 @@
73424 #define arch_rebalance_pgtables(addr, len) (addr)
73425 #endif
73426
73427 +static inline void verify_mm_writelocked(struct mm_struct *mm)
73428 +{
73429 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
73430 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73431 + up_read(&mm->mmap_sem);
73432 + BUG();
73433 + }
73434 +#endif
73435 +}
73436 +
73437 static void unmap_region(struct mm_struct *mm,
73438 struct vm_area_struct *vma, struct vm_area_struct *prev,
73439 unsigned long start, unsigned long end);
73440 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
73441 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
73442 *
73443 */
73444 -pgprot_t protection_map[16] = {
73445 +pgprot_t protection_map[16] __read_only = {
73446 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
73447 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
73448 };
73449
73450 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
73451 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
73452 {
73453 - return __pgprot(pgprot_val(protection_map[vm_flags &
73454 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
73455 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
73456 pgprot_val(arch_vm_get_page_prot(vm_flags)));
73457 +
73458 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73459 + if (!(__supported_pte_mask & _PAGE_NX) &&
73460 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
73461 + (vm_flags & (VM_READ | VM_WRITE)))
73462 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
73463 +#endif
73464 +
73465 + return prot;
73466 }
73467 EXPORT_SYMBOL(vm_get_page_prot);
73468
73469 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
73470 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
73471 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
73472 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
73473 /*
73474 * Make sure vm_committed_as in one cacheline and not cacheline shared with
73475 * other variables. It can be updated by several CPUs frequently.
73476 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
73477 struct vm_area_struct *next = vma->vm_next;
73478
73479 might_sleep();
73480 + BUG_ON(vma->vm_mirror);
73481 if (vma->vm_ops && vma->vm_ops->close)
73482 vma->vm_ops->close(vma);
73483 if (vma->vm_file) {
73484 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
73485 * not page aligned -Ram Gupta
73486 */
73487 rlim = rlimit(RLIMIT_DATA);
73488 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
73489 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
73490 (mm->end_data - mm->start_data) > rlim)
73491 goto out;
73492 @@ -708,6 +730,12 @@ static int
73493 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
73494 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73495 {
73496 +
73497 +#ifdef CONFIG_PAX_SEGMEXEC
73498 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
73499 + return 0;
73500 +#endif
73501 +
73502 if (is_mergeable_vma(vma, file, vm_flags) &&
73503 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73504 if (vma->vm_pgoff == vm_pgoff)
73505 @@ -727,6 +755,12 @@ static int
73506 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73507 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73508 {
73509 +
73510 +#ifdef CONFIG_PAX_SEGMEXEC
73511 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
73512 + return 0;
73513 +#endif
73514 +
73515 if (is_mergeable_vma(vma, file, vm_flags) &&
73516 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73517 pgoff_t vm_pglen;
73518 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73519 struct vm_area_struct *vma_merge(struct mm_struct *mm,
73520 struct vm_area_struct *prev, unsigned long addr,
73521 unsigned long end, unsigned long vm_flags,
73522 - struct anon_vma *anon_vma, struct file *file,
73523 + struct anon_vma *anon_vma, struct file *file,
73524 pgoff_t pgoff, struct mempolicy *policy)
73525 {
73526 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
73527 struct vm_area_struct *area, *next;
73528 int err;
73529
73530 +#ifdef CONFIG_PAX_SEGMEXEC
73531 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
73532 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
73533 +
73534 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
73535 +#endif
73536 +
73537 /*
73538 * We later require that vma->vm_flags == vm_flags,
73539 * so this tests vma->vm_flags & VM_SPECIAL, too.
73540 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73541 if (next && next->vm_end == end) /* cases 6, 7, 8 */
73542 next = next->vm_next;
73543
73544 +#ifdef CONFIG_PAX_SEGMEXEC
73545 + if (prev)
73546 + prev_m = pax_find_mirror_vma(prev);
73547 + if (area)
73548 + area_m = pax_find_mirror_vma(area);
73549 + if (next)
73550 + next_m = pax_find_mirror_vma(next);
73551 +#endif
73552 +
73553 /*
73554 * Can it merge with the predecessor?
73555 */
73556 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73557 /* cases 1, 6 */
73558 err = vma_adjust(prev, prev->vm_start,
73559 next->vm_end, prev->vm_pgoff, NULL);
73560 - } else /* cases 2, 5, 7 */
73561 +
73562 +#ifdef CONFIG_PAX_SEGMEXEC
73563 + if (!err && prev_m)
73564 + err = vma_adjust(prev_m, prev_m->vm_start,
73565 + next_m->vm_end, prev_m->vm_pgoff, NULL);
73566 +#endif
73567 +
73568 + } else { /* cases 2, 5, 7 */
73569 err = vma_adjust(prev, prev->vm_start,
73570 end, prev->vm_pgoff, NULL);
73571 +
73572 +#ifdef CONFIG_PAX_SEGMEXEC
73573 + if (!err && prev_m)
73574 + err = vma_adjust(prev_m, prev_m->vm_start,
73575 + end_m, prev_m->vm_pgoff, NULL);
73576 +#endif
73577 +
73578 + }
73579 if (err)
73580 return NULL;
73581 khugepaged_enter_vma_merge(prev);
73582 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73583 mpol_equal(policy, vma_policy(next)) &&
73584 can_vma_merge_before(next, vm_flags,
73585 anon_vma, file, pgoff+pglen)) {
73586 - if (prev && addr < prev->vm_end) /* case 4 */
73587 + if (prev && addr < prev->vm_end) { /* case 4 */
73588 err = vma_adjust(prev, prev->vm_start,
73589 addr, prev->vm_pgoff, NULL);
73590 - else /* cases 3, 8 */
73591 +
73592 +#ifdef CONFIG_PAX_SEGMEXEC
73593 + if (!err && prev_m)
73594 + err = vma_adjust(prev_m, prev_m->vm_start,
73595 + addr_m, prev_m->vm_pgoff, NULL);
73596 +#endif
73597 +
73598 + } else { /* cases 3, 8 */
73599 err = vma_adjust(area, addr, next->vm_end,
73600 next->vm_pgoff - pglen, NULL);
73601 +
73602 +#ifdef CONFIG_PAX_SEGMEXEC
73603 + if (!err && area_m)
73604 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
73605 + next_m->vm_pgoff - pglen, NULL);
73606 +#endif
73607 +
73608 + }
73609 if (err)
73610 return NULL;
73611 khugepaged_enter_vma_merge(area);
73612 @@ -940,16 +1020,13 @@ none:
73613 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73614 struct file *file, long pages)
73615 {
73616 - const unsigned long stack_flags
73617 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73618 -
73619 mm->total_vm += pages;
73620
73621 if (file) {
73622 mm->shared_vm += pages;
73623 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73624 mm->exec_vm += pages;
73625 - } else if (flags & stack_flags)
73626 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73627 mm->stack_vm += pages;
73628 if (flags & (VM_RESERVED|VM_IO))
73629 mm->reserved_vm += pages;
73630 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73631 * (the exception is when the underlying filesystem is noexec
73632 * mounted, in which case we dont add PROT_EXEC.)
73633 */
73634 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73635 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73636 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73637 prot |= PROT_EXEC;
73638
73639 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73640 /* Obtain the address to map to. we verify (or select) it and ensure
73641 * that it represents a valid section of the address space.
73642 */
73643 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
73644 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73645 if (addr & ~PAGE_MASK)
73646 return addr;
73647
73648 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73649 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73650 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73651
73652 +#ifdef CONFIG_PAX_MPROTECT
73653 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73654 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73655 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73656 + gr_log_rwxmmap(file);
73657 +
73658 +#ifdef CONFIG_PAX_EMUPLT
73659 + vm_flags &= ~VM_EXEC;
73660 +#else
73661 + return -EPERM;
73662 +#endif
73663 +
73664 + }
73665 +
73666 + if (!(vm_flags & VM_EXEC))
73667 + vm_flags &= ~VM_MAYEXEC;
73668 +#else
73669 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73670 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73671 +#endif
73672 + else
73673 + vm_flags &= ~VM_MAYWRITE;
73674 + }
73675 +#endif
73676 +
73677 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73678 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73679 + vm_flags &= ~VM_PAGEEXEC;
73680 +#endif
73681 +
73682 if (flags & MAP_LOCKED)
73683 if (!can_do_mlock())
73684 return -EPERM;
73685 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73686 locked += mm->locked_vm;
73687 lock_limit = rlimit(RLIMIT_MEMLOCK);
73688 lock_limit >>= PAGE_SHIFT;
73689 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73690 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73691 return -EAGAIN;
73692 }
73693 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73694 }
73695 }
73696
73697 + if (!gr_acl_handle_mmap(file, prot))
73698 + return -EACCES;
73699 +
73700 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73701 }
73702
73703 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73704 vm_flags_t vm_flags = vma->vm_flags;
73705
73706 /* If it was private or non-writable, the write bit is already clear */
73707 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73708 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73709 return 0;
73710
73711 /* The backer wishes to know when pages are first written to? */
73712 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73713 unsigned long charged = 0;
73714 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73715
73716 +#ifdef CONFIG_PAX_SEGMEXEC
73717 + struct vm_area_struct *vma_m = NULL;
73718 +#endif
73719 +
73720 + /*
73721 + * mm->mmap_sem is required to protect against another thread
73722 + * changing the mappings in case we sleep.
73723 + */
73724 + verify_mm_writelocked(mm);
73725 +
73726 /* Clear old maps */
73727 error = -ENOMEM;
73728 -munmap_back:
73729 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73730 if (vma && vma->vm_start < addr + len) {
73731 if (do_munmap(mm, addr, len))
73732 return -ENOMEM;
73733 - goto munmap_back;
73734 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73735 + BUG_ON(vma && vma->vm_start < addr + len);
73736 }
73737
73738 /* Check against address space limit. */
73739 @@ -1282,6 +1403,16 @@ munmap_back:
73740 goto unacct_error;
73741 }
73742
73743 +#ifdef CONFIG_PAX_SEGMEXEC
73744 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73745 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73746 + if (!vma_m) {
73747 + error = -ENOMEM;
73748 + goto free_vma;
73749 + }
73750 + }
73751 +#endif
73752 +
73753 vma->vm_mm = mm;
73754 vma->vm_start = addr;
73755 vma->vm_end = addr + len;
73756 @@ -1306,6 +1437,19 @@ munmap_back:
73757 error = file->f_op->mmap(file, vma);
73758 if (error)
73759 goto unmap_and_free_vma;
73760 +
73761 +#ifdef CONFIG_PAX_SEGMEXEC
73762 + if (vma_m && (vm_flags & VM_EXECUTABLE))
73763 + added_exe_file_vma(mm);
73764 +#endif
73765 +
73766 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73767 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73768 + vma->vm_flags |= VM_PAGEEXEC;
73769 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73770 + }
73771 +#endif
73772 +
73773 if (vm_flags & VM_EXECUTABLE)
73774 added_exe_file_vma(mm);
73775
73776 @@ -1343,6 +1487,11 @@ munmap_back:
73777 vma_link(mm, vma, prev, rb_link, rb_parent);
73778 file = vma->vm_file;
73779
73780 +#ifdef CONFIG_PAX_SEGMEXEC
73781 + if (vma_m)
73782 + BUG_ON(pax_mirror_vma(vma_m, vma));
73783 +#endif
73784 +
73785 /* Once vma denies write, undo our temporary denial count */
73786 if (correct_wcount)
73787 atomic_inc(&inode->i_writecount);
73788 @@ -1350,6 +1499,7 @@ out:
73789 perf_event_mmap(vma);
73790
73791 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73792 + track_exec_limit(mm, addr, addr + len, vm_flags);
73793 if (vm_flags & VM_LOCKED) {
73794 if (!mlock_vma_pages_range(vma, addr, addr + len))
73795 mm->locked_vm += (len >> PAGE_SHIFT);
73796 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
73797 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73798 charged = 0;
73799 free_vma:
73800 +
73801 +#ifdef CONFIG_PAX_SEGMEXEC
73802 + if (vma_m)
73803 + kmem_cache_free(vm_area_cachep, vma_m);
73804 +#endif
73805 +
73806 kmem_cache_free(vm_area_cachep, vma);
73807 unacct_error:
73808 if (charged)
73809 @@ -1378,6 +1534,44 @@ unacct_error:
73810 return error;
73811 }
73812
73813 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73814 +{
73815 + if (!vma) {
73816 +#ifdef CONFIG_STACK_GROWSUP
73817 + if (addr > sysctl_heap_stack_gap)
73818 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73819 + else
73820 + vma = find_vma(current->mm, 0);
73821 + if (vma && (vma->vm_flags & VM_GROWSUP))
73822 + return false;
73823 +#endif
73824 + return true;
73825 + }
73826 +
73827 + if (addr + len > vma->vm_start)
73828 + return false;
73829 +
73830 + if (vma->vm_flags & VM_GROWSDOWN)
73831 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73832 +#ifdef CONFIG_STACK_GROWSUP
73833 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73834 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73835 +#endif
73836 +
73837 + return true;
73838 +}
73839 +
73840 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73841 +{
73842 + if (vma->vm_start < len)
73843 + return -ENOMEM;
73844 + if (!(vma->vm_flags & VM_GROWSDOWN))
73845 + return vma->vm_start - len;
73846 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73847 + return vma->vm_start - len - sysctl_heap_stack_gap;
73848 + return -ENOMEM;
73849 +}
73850 +
73851 /* Get an address range which is currently unmapped.
73852 * For shmat() with addr=0.
73853 *
73854 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73855 if (flags & MAP_FIXED)
73856 return addr;
73857
73858 +#ifdef CONFIG_PAX_RANDMMAP
73859 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73860 +#endif
73861 +
73862 if (addr) {
73863 addr = PAGE_ALIGN(addr);
73864 - vma = find_vma(mm, addr);
73865 - if (TASK_SIZE - len >= addr &&
73866 - (!vma || addr + len <= vma->vm_start))
73867 - return addr;
73868 + if (TASK_SIZE - len >= addr) {
73869 + vma = find_vma(mm, addr);
73870 + if (check_heap_stack_gap(vma, addr, len))
73871 + return addr;
73872 + }
73873 }
73874 if (len > mm->cached_hole_size) {
73875 - start_addr = addr = mm->free_area_cache;
73876 + start_addr = addr = mm->free_area_cache;
73877 } else {
73878 - start_addr = addr = TASK_UNMAPPED_BASE;
73879 - mm->cached_hole_size = 0;
73880 + start_addr = addr = mm->mmap_base;
73881 + mm->cached_hole_size = 0;
73882 }
73883
73884 full_search:
73885 @@ -1426,34 +1625,40 @@ full_search:
73886 * Start a new search - just in case we missed
73887 * some holes.
73888 */
73889 - if (start_addr != TASK_UNMAPPED_BASE) {
73890 - addr = TASK_UNMAPPED_BASE;
73891 - start_addr = addr;
73892 + if (start_addr != mm->mmap_base) {
73893 + start_addr = addr = mm->mmap_base;
73894 mm->cached_hole_size = 0;
73895 goto full_search;
73896 }
73897 return -ENOMEM;
73898 }
73899 - if (!vma || addr + len <= vma->vm_start) {
73900 - /*
73901 - * Remember the place where we stopped the search:
73902 - */
73903 - mm->free_area_cache = addr + len;
73904 - return addr;
73905 - }
73906 + if (check_heap_stack_gap(vma, addr, len))
73907 + break;
73908 if (addr + mm->cached_hole_size < vma->vm_start)
73909 mm->cached_hole_size = vma->vm_start - addr;
73910 addr = vma->vm_end;
73911 }
73912 +
73913 + /*
73914 + * Remember the place where we stopped the search:
73915 + */
73916 + mm->free_area_cache = addr + len;
73917 + return addr;
73918 }
73919 #endif
73920
73921 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73922 {
73923 +
73924 +#ifdef CONFIG_PAX_SEGMEXEC
73925 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73926 + return;
73927 +#endif
73928 +
73929 /*
73930 * Is this a new hole at the lowest possible address?
73931 */
73932 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73933 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73934 mm->free_area_cache = addr;
73935 }
73936
73937 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73938 {
73939 struct vm_area_struct *vma;
73940 struct mm_struct *mm = current->mm;
73941 - unsigned long addr = addr0, start_addr;
73942 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73943
73944 /* requested length too big for entire address space */
73945 if (len > TASK_SIZE)
73946 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73947 if (flags & MAP_FIXED)
73948 return addr;
73949
73950 +#ifdef CONFIG_PAX_RANDMMAP
73951 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73952 +#endif
73953 +
73954 /* requesting a specific address */
73955 if (addr) {
73956 addr = PAGE_ALIGN(addr);
73957 - vma = find_vma(mm, addr);
73958 - if (TASK_SIZE - len >= addr &&
73959 - (!vma || addr + len <= vma->vm_start))
73960 - return addr;
73961 + if (TASK_SIZE - len >= addr) {
73962 + vma = find_vma(mm, addr);
73963 + if (check_heap_stack_gap(vma, addr, len))
73964 + return addr;
73965 + }
73966 }
73967
73968 /* check if free_area_cache is useful for us */
73969 @@ -1508,7 +1718,7 @@ try_again:
73970 * return with success:
73971 */
73972 vma = find_vma(mm, addr);
73973 - if (!vma || addr+len <= vma->vm_start)
73974 + if (check_heap_stack_gap(vma, addr, len))
73975 /* remember the address as a hint for next time */
73976 return (mm->free_area_cache = addr);
73977
73978 @@ -1517,8 +1727,8 @@ try_again:
73979 mm->cached_hole_size = vma->vm_start - addr;
73980
73981 /* try just below the current vma->vm_start */
73982 - addr = vma->vm_start-len;
73983 - } while (len < vma->vm_start);
73984 + addr = skip_heap_stack_gap(vma, len);
73985 + } while (!IS_ERR_VALUE(addr));
73986
73987 fail:
73988 /*
73989 @@ -1541,13 +1751,21 @@ fail:
73990 * can happen with large stack limits and large mmap()
73991 * allocations.
73992 */
73993 + mm->mmap_base = TASK_UNMAPPED_BASE;
73994 +
73995 +#ifdef CONFIG_PAX_RANDMMAP
73996 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73997 + mm->mmap_base += mm->delta_mmap;
73998 +#endif
73999 +
74000 + mm->free_area_cache = mm->mmap_base;
74001 mm->cached_hole_size = ~0UL;
74002 - mm->free_area_cache = TASK_UNMAPPED_BASE;
74003 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
74004 /*
74005 * Restore the topdown base:
74006 */
74007 - mm->free_area_cache = mm->mmap_base;
74008 + mm->mmap_base = base;
74009 + mm->free_area_cache = base;
74010 mm->cached_hole_size = ~0UL;
74011
74012 return addr;
74013 @@ -1556,6 +1774,12 @@ fail:
74014
74015 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
74016 {
74017 +
74018 +#ifdef CONFIG_PAX_SEGMEXEC
74019 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
74020 + return;
74021 +#endif
74022 +
74023 /*
74024 * Is this a new hole at the highest possible address?
74025 */
74026 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
74027 mm->free_area_cache = addr;
74028
74029 /* dont allow allocations above current base */
74030 - if (mm->free_area_cache > mm->mmap_base)
74031 + if (mm->free_area_cache > mm->mmap_base) {
74032 mm->free_area_cache = mm->mmap_base;
74033 + mm->cached_hole_size = ~0UL;
74034 + }
74035 }
74036
74037 unsigned long
74038 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
74039 return vma;
74040 }
74041
74042 +#ifdef CONFIG_PAX_SEGMEXEC
74043 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
74044 +{
74045 + struct vm_area_struct *vma_m;
74046 +
74047 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
74048 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
74049 + BUG_ON(vma->vm_mirror);
74050 + return NULL;
74051 + }
74052 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
74053 + vma_m = vma->vm_mirror;
74054 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
74055 + BUG_ON(vma->vm_file != vma_m->vm_file);
74056 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
74057 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
74058 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
74059 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
74060 + return vma_m;
74061 +}
74062 +#endif
74063 +
74064 /*
74065 * Verify that the stack growth is acceptable and
74066 * update accounting. This is shared with both the
74067 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
74068 return -ENOMEM;
74069
74070 /* Stack limit test */
74071 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
74072 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
74073 return -ENOMEM;
74074
74075 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
74076 locked = mm->locked_vm + grow;
74077 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
74078 limit >>= PAGE_SHIFT;
74079 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
74080 if (locked > limit && !capable(CAP_IPC_LOCK))
74081 return -ENOMEM;
74082 }
74083 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
74084 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
74085 * vma is the last one with address > vma->vm_end. Have to extend vma.
74086 */
74087 +#ifndef CONFIG_IA64
74088 +static
74089 +#endif
74090 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
74091 {
74092 int error;
74093 + bool locknext;
74094
74095 if (!(vma->vm_flags & VM_GROWSUP))
74096 return -EFAULT;
74097
74098 + /* Also guard against wrapping around to address 0. */
74099 + if (address < PAGE_ALIGN(address+1))
74100 + address = PAGE_ALIGN(address+1);
74101 + else
74102 + return -ENOMEM;
74103 +
74104 /*
74105 * We must make sure the anon_vma is allocated
74106 * so that the anon_vma locking is not a noop.
74107 */
74108 if (unlikely(anon_vma_prepare(vma)))
74109 return -ENOMEM;
74110 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
74111 + if (locknext && anon_vma_prepare(vma->vm_next))
74112 + return -ENOMEM;
74113 vma_lock_anon_vma(vma);
74114 + if (locknext)
74115 + vma_lock_anon_vma(vma->vm_next);
74116
74117 /*
74118 * vma->vm_start/vm_end cannot change under us because the caller
74119 * is required to hold the mmap_sem in read mode. We need the
74120 - * anon_vma lock to serialize against concurrent expand_stacks.
74121 - * Also guard against wrapping around to address 0.
74122 + * anon_vma locks to serialize against concurrent expand_stacks
74123 + * and expand_upwards.
74124 */
74125 - if (address < PAGE_ALIGN(address+4))
74126 - address = PAGE_ALIGN(address+4);
74127 - else {
74128 - vma_unlock_anon_vma(vma);
74129 - return -ENOMEM;
74130 - }
74131 error = 0;
74132
74133 /* Somebody else might have raced and expanded it already */
74134 - if (address > vma->vm_end) {
74135 + 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)
74136 + error = -ENOMEM;
74137 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
74138 unsigned long size, grow;
74139
74140 size = address - vma->vm_start;
74141 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
74142 }
74143 }
74144 }
74145 + if (locknext)
74146 + vma_unlock_anon_vma(vma->vm_next);
74147 vma_unlock_anon_vma(vma);
74148 khugepaged_enter_vma_merge(vma);
74149 return error;
74150 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
74151 unsigned long address)
74152 {
74153 int error;
74154 + bool lockprev = false;
74155 + struct vm_area_struct *prev;
74156
74157 /*
74158 * We must make sure the anon_vma is allocated
74159 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
74160 if (error)
74161 return error;
74162
74163 + prev = vma->vm_prev;
74164 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
74165 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
74166 +#endif
74167 + if (lockprev && anon_vma_prepare(prev))
74168 + return -ENOMEM;
74169 + if (lockprev)
74170 + vma_lock_anon_vma(prev);
74171 +
74172 vma_lock_anon_vma(vma);
74173
74174 /*
74175 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
74176 */
74177
74178 /* Somebody else might have raced and expanded it already */
74179 - if (address < vma->vm_start) {
74180 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
74181 + error = -ENOMEM;
74182 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
74183 unsigned long size, grow;
74184
74185 +#ifdef CONFIG_PAX_SEGMEXEC
74186 + struct vm_area_struct *vma_m;
74187 +
74188 + vma_m = pax_find_mirror_vma(vma);
74189 +#endif
74190 +
74191 size = vma->vm_end - address;
74192 grow = (vma->vm_start - address) >> PAGE_SHIFT;
74193
74194 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
74195 if (!error) {
74196 vma->vm_start = address;
74197 vma->vm_pgoff -= grow;
74198 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
74199 +
74200 +#ifdef CONFIG_PAX_SEGMEXEC
74201 + if (vma_m) {
74202 + vma_m->vm_start -= grow << PAGE_SHIFT;
74203 + vma_m->vm_pgoff -= grow;
74204 + }
74205 +#endif
74206 +
74207 perf_event_mmap(vma);
74208 }
74209 }
74210 }
74211 vma_unlock_anon_vma(vma);
74212 + if (lockprev)
74213 + vma_unlock_anon_vma(prev);
74214 khugepaged_enter_vma_merge(vma);
74215 return error;
74216 }
74217 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
74218 do {
74219 long nrpages = vma_pages(vma);
74220
74221 +#ifdef CONFIG_PAX_SEGMEXEC
74222 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
74223 + vma = remove_vma(vma);
74224 + continue;
74225 + }
74226 +#endif
74227 +
74228 if (vma->vm_flags & VM_ACCOUNT)
74229 nr_accounted += nrpages;
74230 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
74231 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
74232 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
74233 vma->vm_prev = NULL;
74234 do {
74235 +
74236 +#ifdef CONFIG_PAX_SEGMEXEC
74237 + if (vma->vm_mirror) {
74238 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
74239 + vma->vm_mirror->vm_mirror = NULL;
74240 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
74241 + vma->vm_mirror = NULL;
74242 + }
74243 +#endif
74244 +
74245 rb_erase(&vma->vm_rb, &mm->mm_rb);
74246 mm->map_count--;
74247 tail_vma = vma;
74248 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74249 struct vm_area_struct *new;
74250 int err = -ENOMEM;
74251
74252 +#ifdef CONFIG_PAX_SEGMEXEC
74253 + struct vm_area_struct *vma_m, *new_m = NULL;
74254 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
74255 +#endif
74256 +
74257 if (is_vm_hugetlb_page(vma) && (addr &
74258 ~(huge_page_mask(hstate_vma(vma)))))
74259 return -EINVAL;
74260
74261 +#ifdef CONFIG_PAX_SEGMEXEC
74262 + vma_m = pax_find_mirror_vma(vma);
74263 +#endif
74264 +
74265 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74266 if (!new)
74267 goto out_err;
74268
74269 +#ifdef CONFIG_PAX_SEGMEXEC
74270 + if (vma_m) {
74271 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74272 + if (!new_m) {
74273 + kmem_cache_free(vm_area_cachep, new);
74274 + goto out_err;
74275 + }
74276 + }
74277 +#endif
74278 +
74279 /* most fields are the same, copy all, and then fixup */
74280 *new = *vma;
74281
74282 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74283 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
74284 }
74285
74286 +#ifdef CONFIG_PAX_SEGMEXEC
74287 + if (vma_m) {
74288 + *new_m = *vma_m;
74289 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
74290 + new_m->vm_mirror = new;
74291 + new->vm_mirror = new_m;
74292 +
74293 + if (new_below)
74294 + new_m->vm_end = addr_m;
74295 + else {
74296 + new_m->vm_start = addr_m;
74297 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
74298 + }
74299 + }
74300 +#endif
74301 +
74302 pol = mpol_dup(vma_policy(vma));
74303 if (IS_ERR(pol)) {
74304 err = PTR_ERR(pol);
74305 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74306 else
74307 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
74308
74309 +#ifdef CONFIG_PAX_SEGMEXEC
74310 + if (!err && vma_m) {
74311 + if (anon_vma_clone(new_m, vma_m))
74312 + goto out_free_mpol;
74313 +
74314 + mpol_get(pol);
74315 + vma_set_policy(new_m, pol);
74316 +
74317 + if (new_m->vm_file) {
74318 + get_file(new_m->vm_file);
74319 + if (vma_m->vm_flags & VM_EXECUTABLE)
74320 + added_exe_file_vma(mm);
74321 + }
74322 +
74323 + if (new_m->vm_ops && new_m->vm_ops->open)
74324 + new_m->vm_ops->open(new_m);
74325 +
74326 + if (new_below)
74327 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
74328 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
74329 + else
74330 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
74331 +
74332 + if (err) {
74333 + if (new_m->vm_ops && new_m->vm_ops->close)
74334 + new_m->vm_ops->close(new_m);
74335 + if (new_m->vm_file) {
74336 + if (vma_m->vm_flags & VM_EXECUTABLE)
74337 + removed_exe_file_vma(mm);
74338 + fput(new_m->vm_file);
74339 + }
74340 + mpol_put(pol);
74341 + }
74342 + }
74343 +#endif
74344 +
74345 /* Success. */
74346 if (!err)
74347 return 0;
74348 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74349 removed_exe_file_vma(mm);
74350 fput(new->vm_file);
74351 }
74352 - unlink_anon_vmas(new);
74353 out_free_mpol:
74354 mpol_put(pol);
74355 out_free_vma:
74356 +
74357 +#ifdef CONFIG_PAX_SEGMEXEC
74358 + if (new_m) {
74359 + unlink_anon_vmas(new_m);
74360 + kmem_cache_free(vm_area_cachep, new_m);
74361 + }
74362 +#endif
74363 +
74364 + unlink_anon_vmas(new);
74365 kmem_cache_free(vm_area_cachep, new);
74366 out_err:
74367 return err;
74368 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74369 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74370 unsigned long addr, int new_below)
74371 {
74372 +
74373 +#ifdef CONFIG_PAX_SEGMEXEC
74374 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
74375 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
74376 + if (mm->map_count >= sysctl_max_map_count-1)
74377 + return -ENOMEM;
74378 + } else
74379 +#endif
74380 +
74381 if (mm->map_count >= sysctl_max_map_count)
74382 return -ENOMEM;
74383
74384 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74385 * work. This now handles partial unmappings.
74386 * Jeremy Fitzhardinge <jeremy@goop.org>
74387 */
74388 +#ifdef CONFIG_PAX_SEGMEXEC
74389 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74390 {
74391 + int ret = __do_munmap(mm, start, len);
74392 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
74393 + return ret;
74394 +
74395 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
74396 +}
74397 +
74398 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74399 +#else
74400 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74401 +#endif
74402 +{
74403 unsigned long end;
74404 struct vm_area_struct *vma, *prev, *last;
74405
74406 + /*
74407 + * mm->mmap_sem is required to protect against another thread
74408 + * changing the mappings in case we sleep.
74409 + */
74410 + verify_mm_writelocked(mm);
74411 +
74412 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
74413 return -EINVAL;
74414
74415 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74416 /* Fix up all other VM information */
74417 remove_vma_list(mm, vma);
74418
74419 + track_exec_limit(mm, start, end, 0UL);
74420 +
74421 return 0;
74422 }
74423
74424 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
74425 int ret;
74426 struct mm_struct *mm = current->mm;
74427
74428 +
74429 +#ifdef CONFIG_PAX_SEGMEXEC
74430 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
74431 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
74432 + return -EINVAL;
74433 +#endif
74434 +
74435 down_write(&mm->mmap_sem);
74436 ret = do_munmap(mm, start, len);
74437 up_write(&mm->mmap_sem);
74438 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
74439 return vm_munmap(addr, len);
74440 }
74441
74442 -static inline void verify_mm_writelocked(struct mm_struct *mm)
74443 -{
74444 -#ifdef CONFIG_DEBUG_VM
74445 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
74446 - WARN_ON(1);
74447 - up_read(&mm->mmap_sem);
74448 - }
74449 -#endif
74450 -}
74451 -
74452 /*
74453 * this is really a simplified "do_mmap". it only handles
74454 * anonymous maps. eventually we may be able to do some
74455 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74456 struct rb_node ** rb_link, * rb_parent;
74457 pgoff_t pgoff = addr >> PAGE_SHIFT;
74458 int error;
74459 + unsigned long charged;
74460
74461 len = PAGE_ALIGN(len);
74462 if (!len)
74463 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74464
74465 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
74466
74467 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
74468 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
74469 + flags &= ~VM_EXEC;
74470 +
74471 +#ifdef CONFIG_PAX_MPROTECT
74472 + if (mm->pax_flags & MF_PAX_MPROTECT)
74473 + flags &= ~VM_MAYEXEC;
74474 +#endif
74475 +
74476 + }
74477 +#endif
74478 +
74479 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
74480 if (error & ~PAGE_MASK)
74481 return error;
74482
74483 + charged = len >> PAGE_SHIFT;
74484 +
74485 /*
74486 * mlock MCL_FUTURE?
74487 */
74488 if (mm->def_flags & VM_LOCKED) {
74489 unsigned long locked, lock_limit;
74490 - locked = len >> PAGE_SHIFT;
74491 + locked = charged;
74492 locked += mm->locked_vm;
74493 lock_limit = rlimit(RLIMIT_MEMLOCK);
74494 lock_limit >>= PAGE_SHIFT;
74495 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74496 /*
74497 * Clear old maps. this also does some error checking for us
74498 */
74499 - munmap_back:
74500 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74501 if (vma && vma->vm_start < addr + len) {
74502 if (do_munmap(mm, addr, len))
74503 return -ENOMEM;
74504 - goto munmap_back;
74505 - }
74506 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74507 + BUG_ON(vma && vma->vm_start < addr + len);
74508 + }
74509
74510 /* Check against address space limits *after* clearing old maps... */
74511 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
74512 + if (!may_expand_vm(mm, charged))
74513 return -ENOMEM;
74514
74515 if (mm->map_count > sysctl_max_map_count)
74516 return -ENOMEM;
74517
74518 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
74519 + if (security_vm_enough_memory_mm(mm, charged))
74520 return -ENOMEM;
74521
74522 /* Can we just expand an old private anonymous mapping? */
74523 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74524 */
74525 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74526 if (!vma) {
74527 - vm_unacct_memory(len >> PAGE_SHIFT);
74528 + vm_unacct_memory(charged);
74529 return -ENOMEM;
74530 }
74531
74532 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74533 vma_link(mm, vma, prev, rb_link, rb_parent);
74534 out:
74535 perf_event_mmap(vma);
74536 - mm->total_vm += len >> PAGE_SHIFT;
74537 + mm->total_vm += charged;
74538 if (flags & VM_LOCKED) {
74539 if (!mlock_vma_pages_range(vma, addr, addr + len))
74540 - mm->locked_vm += (len >> PAGE_SHIFT);
74541 + mm->locked_vm += charged;
74542 }
74543 + track_exec_limit(mm, addr, addr + len, flags);
74544 return addr;
74545 }
74546
74547 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
74548 while (vma) {
74549 if (vma->vm_flags & VM_ACCOUNT)
74550 nr_accounted += vma_pages(vma);
74551 + vma->vm_mirror = NULL;
74552 vma = remove_vma(vma);
74553 }
74554 vm_unacct_memory(nr_accounted);
74555 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74556 struct vm_area_struct * __vma, * prev;
74557 struct rb_node ** rb_link, * rb_parent;
74558
74559 +#ifdef CONFIG_PAX_SEGMEXEC
74560 + struct vm_area_struct *vma_m = NULL;
74561 +#endif
74562 +
74563 + if (security_mmap_addr(vma->vm_start))
74564 + return -EPERM;
74565 +
74566 /*
74567 * The vm_pgoff of a purely anonymous vma should be irrelevant
74568 * until its first write fault, when page's anon_vma and index
74569 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74570 security_vm_enough_memory_mm(mm, vma_pages(vma)))
74571 return -ENOMEM;
74572
74573 +#ifdef CONFIG_PAX_SEGMEXEC
74574 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
74575 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74576 + if (!vma_m)
74577 + return -ENOMEM;
74578 + }
74579 +#endif
74580 +
74581 vma_link(mm, vma, prev, rb_link, rb_parent);
74582 +
74583 +#ifdef CONFIG_PAX_SEGMEXEC
74584 + if (vma_m)
74585 + BUG_ON(pax_mirror_vma(vma_m, vma));
74586 +#endif
74587 +
74588 return 0;
74589 }
74590
74591 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74592 struct mempolicy *pol;
74593 bool faulted_in_anon_vma = true;
74594
74595 + BUG_ON(vma->vm_mirror);
74596 +
74597 /*
74598 * If anonymous vma has not yet been faulted, update new pgoff
74599 * to match new location, to increase its chance of merging.
74600 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74601 return NULL;
74602 }
74603
74604 +#ifdef CONFIG_PAX_SEGMEXEC
74605 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74606 +{
74607 + struct vm_area_struct *prev_m;
74608 + struct rb_node **rb_link_m, *rb_parent_m;
74609 + struct mempolicy *pol_m;
74610 +
74611 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74612 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74613 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74614 + *vma_m = *vma;
74615 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74616 + if (anon_vma_clone(vma_m, vma))
74617 + return -ENOMEM;
74618 + pol_m = vma_policy(vma_m);
74619 + mpol_get(pol_m);
74620 + vma_set_policy(vma_m, pol_m);
74621 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74622 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74623 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74624 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74625 + if (vma_m->vm_file)
74626 + get_file(vma_m->vm_file);
74627 + if (vma_m->vm_ops && vma_m->vm_ops->open)
74628 + vma_m->vm_ops->open(vma_m);
74629 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
74630 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74631 + vma_m->vm_mirror = vma;
74632 + vma->vm_mirror = vma_m;
74633 + return 0;
74634 +}
74635 +#endif
74636 +
74637 /*
74638 * Return true if the calling process may expand its vm space by the passed
74639 * number of pages
74640 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74641
74642 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74643
74644 +#ifdef CONFIG_PAX_RANDMMAP
74645 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74646 + cur -= mm->brk_gap;
74647 +#endif
74648 +
74649 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74650 if (cur + npages > lim)
74651 return 0;
74652 return 1;
74653 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
74654 vma->vm_start = addr;
74655 vma->vm_end = addr + len;
74656
74657 +#ifdef CONFIG_PAX_MPROTECT
74658 + if (mm->pax_flags & MF_PAX_MPROTECT) {
74659 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
74660 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74661 + return -EPERM;
74662 + if (!(vm_flags & VM_EXEC))
74663 + vm_flags &= ~VM_MAYEXEC;
74664 +#else
74665 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74666 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74667 +#endif
74668 + else
74669 + vm_flags &= ~VM_MAYWRITE;
74670 + }
74671 +#endif
74672 +
74673 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74674 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74675
74676 diff --git a/mm/mprotect.c b/mm/mprotect.c
74677 index a409926..8b32e6d 100644
74678 --- a/mm/mprotect.c
74679 +++ b/mm/mprotect.c
74680 @@ -23,10 +23,17 @@
74681 #include <linux/mmu_notifier.h>
74682 #include <linux/migrate.h>
74683 #include <linux/perf_event.h>
74684 +
74685 +#ifdef CONFIG_PAX_MPROTECT
74686 +#include <linux/elf.h>
74687 +#include <linux/binfmts.h>
74688 +#endif
74689 +
74690 #include <asm/uaccess.h>
74691 #include <asm/pgtable.h>
74692 #include <asm/cacheflush.h>
74693 #include <asm/tlbflush.h>
74694 +#include <asm/mmu_context.h>
74695
74696 #ifndef pgprot_modify
74697 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74698 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74699 flush_tlb_range(vma, start, end);
74700 }
74701
74702 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74703 +/* called while holding the mmap semaphor for writing except stack expansion */
74704 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74705 +{
74706 + unsigned long oldlimit, newlimit = 0UL;
74707 +
74708 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74709 + return;
74710 +
74711 + spin_lock(&mm->page_table_lock);
74712 + oldlimit = mm->context.user_cs_limit;
74713 + if ((prot & VM_EXEC) && oldlimit < end)
74714 + /* USER_CS limit moved up */
74715 + newlimit = end;
74716 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74717 + /* USER_CS limit moved down */
74718 + newlimit = start;
74719 +
74720 + if (newlimit) {
74721 + mm->context.user_cs_limit = newlimit;
74722 +
74723 +#ifdef CONFIG_SMP
74724 + wmb();
74725 + cpus_clear(mm->context.cpu_user_cs_mask);
74726 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74727 +#endif
74728 +
74729 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74730 + }
74731 + spin_unlock(&mm->page_table_lock);
74732 + if (newlimit == end) {
74733 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
74734 +
74735 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
74736 + if (is_vm_hugetlb_page(vma))
74737 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74738 + else
74739 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74740 + }
74741 +}
74742 +#endif
74743 +
74744 int
74745 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74746 unsigned long start, unsigned long end, unsigned long newflags)
74747 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74748 int error;
74749 int dirty_accountable = 0;
74750
74751 +#ifdef CONFIG_PAX_SEGMEXEC
74752 + struct vm_area_struct *vma_m = NULL;
74753 + unsigned long start_m, end_m;
74754 +
74755 + start_m = start + SEGMEXEC_TASK_SIZE;
74756 + end_m = end + SEGMEXEC_TASK_SIZE;
74757 +#endif
74758 +
74759 if (newflags == oldflags) {
74760 *pprev = vma;
74761 return 0;
74762 }
74763
74764 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74765 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74766 +
74767 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74768 + return -ENOMEM;
74769 +
74770 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74771 + return -ENOMEM;
74772 + }
74773 +
74774 /*
74775 * If we make a private mapping writable we increase our commit;
74776 * but (without finer accounting) cannot reduce our commit if we
74777 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74778 }
74779 }
74780
74781 +#ifdef CONFIG_PAX_SEGMEXEC
74782 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74783 + if (start != vma->vm_start) {
74784 + error = split_vma(mm, vma, start, 1);
74785 + if (error)
74786 + goto fail;
74787 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74788 + *pprev = (*pprev)->vm_next;
74789 + }
74790 +
74791 + if (end != vma->vm_end) {
74792 + error = split_vma(mm, vma, end, 0);
74793 + if (error)
74794 + goto fail;
74795 + }
74796 +
74797 + if (pax_find_mirror_vma(vma)) {
74798 + error = __do_munmap(mm, start_m, end_m - start_m);
74799 + if (error)
74800 + goto fail;
74801 + } else {
74802 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74803 + if (!vma_m) {
74804 + error = -ENOMEM;
74805 + goto fail;
74806 + }
74807 + vma->vm_flags = newflags;
74808 + error = pax_mirror_vma(vma_m, vma);
74809 + if (error) {
74810 + vma->vm_flags = oldflags;
74811 + goto fail;
74812 + }
74813 + }
74814 + }
74815 +#endif
74816 +
74817 /*
74818 * First try to merge with previous and/or next vma.
74819 */
74820 @@ -204,9 +307,21 @@ success:
74821 * vm_flags and vm_page_prot are protected by the mmap_sem
74822 * held in write mode.
74823 */
74824 +
74825 +#ifdef CONFIG_PAX_SEGMEXEC
74826 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74827 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74828 +#endif
74829 +
74830 vma->vm_flags = newflags;
74831 +
74832 +#ifdef CONFIG_PAX_MPROTECT
74833 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74834 + mm->binfmt->handle_mprotect(vma, newflags);
74835 +#endif
74836 +
74837 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74838 - vm_get_page_prot(newflags));
74839 + vm_get_page_prot(vma->vm_flags));
74840
74841 if (vma_wants_writenotify(vma)) {
74842 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74843 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74844 end = start + len;
74845 if (end <= start)
74846 return -ENOMEM;
74847 +
74848 +#ifdef CONFIG_PAX_SEGMEXEC
74849 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74850 + if (end > SEGMEXEC_TASK_SIZE)
74851 + return -EINVAL;
74852 + } else
74853 +#endif
74854 +
74855 + if (end > TASK_SIZE)
74856 + return -EINVAL;
74857 +
74858 if (!arch_validate_prot(prot))
74859 return -EINVAL;
74860
74861 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74862 /*
74863 * Does the application expect PROT_READ to imply PROT_EXEC:
74864 */
74865 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74866 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74867 prot |= PROT_EXEC;
74868
74869 vm_flags = calc_vm_prot_bits(prot);
74870 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74871 if (start > vma->vm_start)
74872 prev = vma;
74873
74874 +#ifdef CONFIG_PAX_MPROTECT
74875 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74876 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74877 +#endif
74878 +
74879 for (nstart = start ; ; ) {
74880 unsigned long newflags;
74881
74882 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74883
74884 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74885 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74886 + if (prot & (PROT_WRITE | PROT_EXEC))
74887 + gr_log_rwxmprotect(vma->vm_file);
74888 +
74889 + error = -EACCES;
74890 + goto out;
74891 + }
74892 +
74893 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74894 error = -EACCES;
74895 goto out;
74896 }
74897 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74898 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74899 if (error)
74900 goto out;
74901 +
74902 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74903 +
74904 nstart = tmp;
74905
74906 if (nstart < prev->vm_end)
74907 diff --git a/mm/mremap.c b/mm/mremap.c
74908 index cc06d0e..40b5d18 100644
74909 --- a/mm/mremap.c
74910 +++ b/mm/mremap.c
74911 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74912 continue;
74913 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74914 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74915 +
74916 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74917 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74918 + pte = pte_exprotect(pte);
74919 +#endif
74920 +
74921 set_pte_at(mm, new_addr, new_pte, pte);
74922 }
74923
74924 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74925 if (is_vm_hugetlb_page(vma))
74926 goto Einval;
74927
74928 +#ifdef CONFIG_PAX_SEGMEXEC
74929 + if (pax_find_mirror_vma(vma))
74930 + goto Einval;
74931 +#endif
74932 +
74933 /* We can't remap across vm area boundaries */
74934 if (old_len > vma->vm_end - addr)
74935 goto Efault;
74936 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74937 unsigned long ret = -EINVAL;
74938 unsigned long charged = 0;
74939 unsigned long map_flags;
74940 + unsigned long pax_task_size = TASK_SIZE;
74941
74942 if (new_addr & ~PAGE_MASK)
74943 goto out;
74944
74945 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74946 +#ifdef CONFIG_PAX_SEGMEXEC
74947 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74948 + pax_task_size = SEGMEXEC_TASK_SIZE;
74949 +#endif
74950 +
74951 + pax_task_size -= PAGE_SIZE;
74952 +
74953 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74954 goto out;
74955
74956 /* Check if the location we're moving into overlaps the
74957 * old location at all, and fail if it does.
74958 */
74959 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74960 - goto out;
74961 -
74962 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74963 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74964 goto out;
74965
74966 ret = do_munmap(mm, new_addr, new_len);
74967 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74968 struct vm_area_struct *vma;
74969 unsigned long ret = -EINVAL;
74970 unsigned long charged = 0;
74971 + unsigned long pax_task_size = TASK_SIZE;
74972
74973 down_write(&current->mm->mmap_sem);
74974
74975 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74976 if (!new_len)
74977 goto out;
74978
74979 +#ifdef CONFIG_PAX_SEGMEXEC
74980 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74981 + pax_task_size = SEGMEXEC_TASK_SIZE;
74982 +#endif
74983 +
74984 + pax_task_size -= PAGE_SIZE;
74985 +
74986 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74987 + old_len > pax_task_size || addr > pax_task_size-old_len)
74988 + goto out;
74989 +
74990 if (flags & MREMAP_FIXED) {
74991 if (flags & MREMAP_MAYMOVE)
74992 ret = mremap_to(addr, old_len, new_addr, new_len);
74993 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74994 addr + new_len);
74995 }
74996 ret = addr;
74997 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74998 goto out;
74999 }
75000 }
75001 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
75002 goto out;
75003 }
75004
75005 + map_flags = vma->vm_flags;
75006 ret = move_vma(vma, addr, old_len, new_len, new_addr);
75007 + if (!(ret & ~PAGE_MASK)) {
75008 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
75009 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
75010 + }
75011 }
75012 out:
75013 if (ret & ~PAGE_MASK)
75014 diff --git a/mm/nommu.c b/mm/nommu.c
75015 index d4b0c10..ed421b5 100644
75016 --- a/mm/nommu.c
75017 +++ b/mm/nommu.c
75018 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
75019 int sysctl_overcommit_ratio = 50; /* default is 50% */
75020 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
75021 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
75022 -int heap_stack_gap = 0;
75023
75024 atomic_long_t mmap_pages_allocated;
75025
75026 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
75027 EXPORT_SYMBOL(find_vma);
75028
75029 /*
75030 - * find a VMA
75031 - * - we don't extend stack VMAs under NOMMU conditions
75032 - */
75033 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
75034 -{
75035 - return find_vma(mm, addr);
75036 -}
75037 -
75038 -/*
75039 * expand a stack to a given address
75040 * - not supported under NOMMU conditions
75041 */
75042 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
75043
75044 /* most fields are the same, copy all, and then fixup */
75045 *new = *vma;
75046 + INIT_LIST_HEAD(&new->anon_vma_chain);
75047 *region = *vma->vm_region;
75048 new->vm_region = region;
75049
75050 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
75051 index d2d8f54..be2a87c 100644
75052 --- a/mm/page_alloc.c
75053 +++ b/mm/page_alloc.c
75054 @@ -340,7 +340,7 @@ out:
75055 * This usage means that zero-order pages may not be compound.
75056 */
75057
75058 -static void free_compound_page(struct page *page)
75059 +void free_compound_page(struct page *page)
75060 {
75061 __free_pages_ok(page, compound_order(page));
75062 }
75063 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
75064 int i;
75065 int bad = 0;
75066
75067 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
75068 + unsigned long index = 1UL << order;
75069 +#endif
75070 +
75071 trace_mm_page_free(page, order);
75072 kmemcheck_free_shadow(page, order);
75073
75074 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
75075 debug_check_no_obj_freed(page_address(page),
75076 PAGE_SIZE << order);
75077 }
75078 +
75079 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
75080 + for (; index; --index)
75081 + sanitize_highpage(page + index - 1);
75082 +#endif
75083 +
75084 arch_free_page(page, order);
75085 kernel_map_pages(page, 1 << order, 0);
75086
75087 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
75088 arch_alloc_page(page, order);
75089 kernel_map_pages(page, 1 << order, 1);
75090
75091 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
75092 if (gfp_flags & __GFP_ZERO)
75093 prep_zero_page(page, order, gfp_flags);
75094 +#endif
75095
75096 if (order && (gfp_flags & __GFP_COMP))
75097 prep_compound_page(page, order);
75098 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
75099 unsigned long pfn;
75100
75101 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
75102 +#ifdef CONFIG_X86_32
75103 + /* boot failures in VMware 8 on 32bit vanilla since
75104 + this change */
75105 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
75106 +#else
75107 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
75108 +#endif
75109 return 1;
75110 }
75111 return 0;
75112 diff --git a/mm/percpu.c b/mm/percpu.c
75113 index bb4be74..a43ea85 100644
75114 --- a/mm/percpu.c
75115 +++ b/mm/percpu.c
75116 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
75117 static unsigned int pcpu_high_unit_cpu __read_mostly;
75118
75119 /* the address of the first chunk which starts with the kernel static area */
75120 -void *pcpu_base_addr __read_mostly;
75121 +void *pcpu_base_addr __read_only;
75122 EXPORT_SYMBOL_GPL(pcpu_base_addr);
75123
75124 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
75125 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
75126 index 926b466..b23df53 100644
75127 --- a/mm/process_vm_access.c
75128 +++ b/mm/process_vm_access.c
75129 @@ -13,6 +13,7 @@
75130 #include <linux/uio.h>
75131 #include <linux/sched.h>
75132 #include <linux/highmem.h>
75133 +#include <linux/security.h>
75134 #include <linux/ptrace.h>
75135 #include <linux/slab.h>
75136 #include <linux/syscalls.h>
75137 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
75138 size_t iov_l_curr_offset = 0;
75139 ssize_t iov_len;
75140
75141 + return -ENOSYS; // PaX: until properly audited
75142 +
75143 /*
75144 * Work out how many pages of struct pages we're going to need
75145 * when eventually calling get_user_pages
75146 */
75147 for (i = 0; i < riovcnt; i++) {
75148 iov_len = rvec[i].iov_len;
75149 - if (iov_len > 0) {
75150 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
75151 - + iov_len)
75152 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
75153 - / PAGE_SIZE + 1;
75154 - nr_pages = max(nr_pages, nr_pages_iov);
75155 - }
75156 + if (iov_len <= 0)
75157 + continue;
75158 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
75159 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
75160 + nr_pages = max(nr_pages, nr_pages_iov);
75161 }
75162
75163 if (nr_pages == 0)
75164 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
75165 goto free_proc_pages;
75166 }
75167
75168 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
75169 + rc = -EPERM;
75170 + goto put_task_struct;
75171 + }
75172 +
75173 mm = mm_access(task, PTRACE_MODE_ATTACH);
75174 if (!mm || IS_ERR(mm)) {
75175 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
75176 diff --git a/mm/rmap.c b/mm/rmap.c
75177 index aa95e59..b681a63 100644
75178 --- a/mm/rmap.c
75179 +++ b/mm/rmap.c
75180 @@ -168,6 +168,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75181 struct anon_vma *anon_vma = vma->anon_vma;
75182 struct anon_vma_chain *avc;
75183
75184 +#ifdef CONFIG_PAX_SEGMEXEC
75185 + struct anon_vma_chain *avc_m = NULL;
75186 +#endif
75187 +
75188 might_sleep();
75189 if (unlikely(!anon_vma)) {
75190 struct mm_struct *mm = vma->vm_mm;
75191 @@ -177,6 +181,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75192 if (!avc)
75193 goto out_enomem;
75194
75195 +#ifdef CONFIG_PAX_SEGMEXEC
75196 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
75197 + if (!avc_m)
75198 + goto out_enomem_free_avc;
75199 +#endif
75200 +
75201 anon_vma = find_mergeable_anon_vma(vma);
75202 allocated = NULL;
75203 if (!anon_vma) {
75204 @@ -190,6 +200,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75205 /* page_table_lock to protect against threads */
75206 spin_lock(&mm->page_table_lock);
75207 if (likely(!vma->anon_vma)) {
75208 +
75209 +#ifdef CONFIG_PAX_SEGMEXEC
75210 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
75211 +
75212 + if (vma_m) {
75213 + BUG_ON(vma_m->anon_vma);
75214 + vma_m->anon_vma = anon_vma;
75215 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
75216 + avc_m = NULL;
75217 + }
75218 +#endif
75219 +
75220 vma->anon_vma = anon_vma;
75221 anon_vma_chain_link(vma, avc, anon_vma);
75222 allocated = NULL;
75223 @@ -200,12 +222,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75224
75225 if (unlikely(allocated))
75226 put_anon_vma(allocated);
75227 +
75228 +#ifdef CONFIG_PAX_SEGMEXEC
75229 + if (unlikely(avc_m))
75230 + anon_vma_chain_free(avc_m);
75231 +#endif
75232 +
75233 if (unlikely(avc))
75234 anon_vma_chain_free(avc);
75235 }
75236 return 0;
75237
75238 out_enomem_free_avc:
75239 +
75240 +#ifdef CONFIG_PAX_SEGMEXEC
75241 + if (avc_m)
75242 + anon_vma_chain_free(avc_m);
75243 +#endif
75244 +
75245 anon_vma_chain_free(avc);
75246 out_enomem:
75247 return -ENOMEM;
75248 @@ -241,7 +275,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
75249 * Attach the anon_vmas from src to dst.
75250 * Returns 0 on success, -ENOMEM on failure.
75251 */
75252 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
75253 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
75254 {
75255 struct anon_vma_chain *avc, *pavc;
75256 struct anon_vma *root = NULL;
75257 @@ -319,7 +353,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
75258 * the corresponding VMA in the parent process is attached to.
75259 * Returns 0 on success, non-zero on failure.
75260 */
75261 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
75262 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
75263 {
75264 struct anon_vma_chain *avc;
75265 struct anon_vma *anon_vma;
75266 diff --git a/mm/shmem.c b/mm/shmem.c
75267 index 31e1506..7b42549 100644
75268 --- a/mm/shmem.c
75269 +++ b/mm/shmem.c
75270 @@ -31,7 +31,7 @@
75271 #include <linux/export.h>
75272 #include <linux/swap.h>
75273
75274 -static struct vfsmount *shm_mnt;
75275 +struct vfsmount *shm_mnt;
75276
75277 #ifdef CONFIG_SHMEM
75278 /*
75279 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
75280 #define BOGO_DIRENT_SIZE 20
75281
75282 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
75283 -#define SHORT_SYMLINK_LEN 128
75284 +#define SHORT_SYMLINK_LEN 64
75285
75286 struct shmem_xattr {
75287 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
75288 @@ -921,25 +921,29 @@ static struct mempolicy *shmem_get_sbmpol(struct shmem_sb_info *sbinfo)
75289 static struct page *shmem_swapin(swp_entry_t swap, gfp_t gfp,
75290 struct shmem_inode_info *info, pgoff_t index)
75291 {
75292 - struct mempolicy mpol, *spol;
75293 struct vm_area_struct pvma;
75294 -
75295 - spol = mpol_cond_copy(&mpol,
75296 - mpol_shared_policy_lookup(&info->policy, index));
75297 + struct page *page;
75298
75299 /* Create a pseudo vma that just contains the policy */
75300 pvma.vm_start = 0;
75301 /* Bias interleave by inode number to distribute better across nodes */
75302 pvma.vm_pgoff = index + info->vfs_inode.i_ino;
75303 pvma.vm_ops = NULL;
75304 - pvma.vm_policy = spol;
75305 - return swapin_readahead(swap, gfp, &pvma, 0);
75306 + pvma.vm_policy = mpol_shared_policy_lookup(&info->policy, index);
75307 +
75308 + page = swapin_readahead(swap, gfp, &pvma, 0);
75309 +
75310 + /* Drop reference taken by mpol_shared_policy_lookup() */
75311 + mpol_cond_put(pvma.vm_policy);
75312 +
75313 + return page;
75314 }
75315
75316 static struct page *shmem_alloc_page(gfp_t gfp,
75317 struct shmem_inode_info *info, pgoff_t index)
75318 {
75319 struct vm_area_struct pvma;
75320 + struct page *page;
75321
75322 /* Create a pseudo vma that just contains the policy */
75323 pvma.vm_start = 0;
75324 @@ -948,10 +952,12 @@ static struct page *shmem_alloc_page(gfp_t gfp,
75325 pvma.vm_ops = NULL;
75326 pvma.vm_policy = mpol_shared_policy_lookup(&info->policy, index);
75327
75328 - /*
75329 - * alloc_page_vma() will drop the shared policy reference
75330 - */
75331 - return alloc_page_vma(gfp, &pvma, 0);
75332 + page = alloc_page_vma(gfp, &pvma, 0);
75333 +
75334 + /* Drop reference taken by mpol_shared_policy_lookup() */
75335 + mpol_cond_put(pvma.vm_policy);
75336 +
75337 + return page;
75338 }
75339 #else /* !CONFIG_NUMA */
75340 #ifdef CONFIG_TMPFS
75341 @@ -2219,6 +2225,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
75342 static int shmem_xattr_validate(const char *name)
75343 {
75344 struct { const char *prefix; size_t len; } arr[] = {
75345 +
75346 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75347 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
75348 +#endif
75349 +
75350 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
75351 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
75352 };
75353 @@ -2272,6 +2283,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
75354 if (err)
75355 return err;
75356
75357 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75358 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
75359 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
75360 + return -EOPNOTSUPP;
75361 + if (size > 8)
75362 + return -EINVAL;
75363 + }
75364 +#endif
75365 +
75366 if (size == 0)
75367 value = ""; /* empty EA, do not remove */
75368
75369 @@ -2606,8 +2626,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
75370 int err = -ENOMEM;
75371
75372 /* Round up to L1_CACHE_BYTES to resist false sharing */
75373 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
75374 - L1_CACHE_BYTES), GFP_KERNEL);
75375 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
75376 if (!sbinfo)
75377 return -ENOMEM;
75378
75379 diff --git a/mm/slab.c b/mm/slab.c
75380 index d066037..5bb78d9 100644
75381 --- a/mm/slab.c
75382 +++ b/mm/slab.c
75383 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
75384
75385 /* Legal flag mask for kmem_cache_create(). */
75386 #if DEBUG
75387 -# define CREATE_MASK (SLAB_RED_ZONE | \
75388 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
75389 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
75390 SLAB_CACHE_DMA | \
75391 SLAB_STORE_USER | \
75392 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
75393 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75394 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
75395 #else
75396 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
75397 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
75398 SLAB_CACHE_DMA | \
75399 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
75400 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75401 @@ -322,7 +322,7 @@ struct kmem_list3 {
75402 * Need this for bootstrapping a per node allocator.
75403 */
75404 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
75405 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
75406 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
75407 #define CACHE_CACHE 0
75408 #define SIZE_AC MAX_NUMNODES
75409 #define SIZE_L3 (2 * MAX_NUMNODES)
75410 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
75411 if ((x)->max_freeable < i) \
75412 (x)->max_freeable = i; \
75413 } while (0)
75414 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
75415 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
75416 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
75417 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
75418 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
75419 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
75420 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
75421 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
75422 #else
75423 #define STATS_INC_ACTIVE(x) do { } while (0)
75424 #define STATS_DEC_ACTIVE(x) do { } while (0)
75425 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
75426 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
75427 */
75428 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
75429 - const struct slab *slab, void *obj)
75430 + const struct slab *slab, const void *obj)
75431 {
75432 u32 offset = (obj - slab->s_mem);
75433 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
75434 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
75435 struct cache_names {
75436 char *name;
75437 char *name_dma;
75438 + char *name_usercopy;
75439 };
75440
75441 static struct cache_names __initdata cache_names[] = {
75442 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
75443 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
75444 #include <linux/kmalloc_sizes.h>
75445 - {NULL,}
75446 + {NULL}
75447 #undef CACHE
75448 };
75449
75450 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
75451 if (unlikely(gfpflags & GFP_DMA))
75452 return csizep->cs_dmacachep;
75453 #endif
75454 +
75455 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75456 + if (unlikely(gfpflags & GFP_USERCOPY))
75457 + return csizep->cs_usercopycachep;
75458 +#endif
75459 +
75460 return csizep->cs_cachep;
75461 }
75462
75463 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
75464 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
75465 sizes[INDEX_AC].cs_size,
75466 ARCH_KMALLOC_MINALIGN,
75467 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75468 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75469 NULL);
75470
75471 if (INDEX_AC != INDEX_L3) {
75472 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
75473 __kmem_cache_create(names[INDEX_L3].name,
75474 sizes[INDEX_L3].cs_size,
75475 ARCH_KMALLOC_MINALIGN,
75476 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75477 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75478 NULL);
75479 }
75480
75481 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
75482 sizes->cs_cachep = __kmem_cache_create(names->name,
75483 sizes->cs_size,
75484 ARCH_KMALLOC_MINALIGN,
75485 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75486 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75487 NULL);
75488 }
75489 #ifdef CONFIG_ZONE_DMA
75490 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
75491 SLAB_PANIC,
75492 NULL);
75493 #endif
75494 +
75495 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75496 + sizes->cs_usercopycachep = kmem_cache_create(
75497 + names->name_usercopy,
75498 + sizes->cs_size,
75499 + ARCH_KMALLOC_MINALIGN,
75500 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75501 + NULL);
75502 +#endif
75503 +
75504 sizes++;
75505 names++;
75506 }
75507 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
75508 }
75509 /* cpu stats */
75510 {
75511 - unsigned long allochit = atomic_read(&cachep->allochit);
75512 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
75513 - unsigned long freehit = atomic_read(&cachep->freehit);
75514 - unsigned long freemiss = atomic_read(&cachep->freemiss);
75515 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
75516 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
75517 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
75518 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
75519
75520 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
75521 allochit, allocmiss, freehit, freemiss);
75522 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
75523 {
75524 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
75525 #ifdef CONFIG_DEBUG_SLAB_LEAK
75526 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
75527 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
75528 #endif
75529 return 0;
75530 }
75531 module_init(slab_proc_init);
75532 #endif
75533
75534 +bool is_usercopy_object(const void *ptr)
75535 +{
75536 + struct page *page;
75537 + struct kmem_cache *cachep;
75538 +
75539 + if (ZERO_OR_NULL_PTR(ptr))
75540 + return false;
75541 +
75542 + if (!slab_is_available())
75543 + return false;
75544 +
75545 + if (!virt_addr_valid(ptr))
75546 + return false;
75547 +
75548 + page = virt_to_head_page(ptr);
75549 +
75550 + if (!PageSlab(page))
75551 + return false;
75552 +
75553 + cachep = page_get_cache(page);
75554 + return cachep->flags & SLAB_USERCOPY;
75555 +}
75556 +
75557 +#ifdef CONFIG_PAX_USERCOPY
75558 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75559 +{
75560 + struct page *page;
75561 + struct kmem_cache *cachep;
75562 + struct slab *slabp;
75563 + unsigned int objnr;
75564 + unsigned long offset;
75565 +
75566 + if (ZERO_OR_NULL_PTR(ptr))
75567 + return "<null>";
75568 +
75569 + if (!virt_addr_valid(ptr))
75570 + return NULL;
75571 +
75572 + page = virt_to_head_page(ptr);
75573 +
75574 + if (!PageSlab(page))
75575 + return NULL;
75576 +
75577 + cachep = page_get_cache(page);
75578 + if (!(cachep->flags & SLAB_USERCOPY))
75579 + return cachep->name;
75580 +
75581 + slabp = page->slab_page;
75582 + objnr = obj_to_index(cachep, slabp, ptr);
75583 + BUG_ON(objnr >= cachep->num);
75584 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
75585 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
75586 + return NULL;
75587 +
75588 + return cachep->name;
75589 +}
75590 +#endif
75591 +
75592 /**
75593 * ksize - get the actual amount of memory allocated for a given object
75594 * @objp: Pointer to the object
75595 diff --git a/mm/slob.c b/mm/slob.c
75596 index 45d4ca7..88943c1 100644
75597 --- a/mm/slob.c
75598 +++ b/mm/slob.c
75599 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
75600 /*
75601 * Return the size of a slob block.
75602 */
75603 -static slobidx_t slob_units(slob_t *s)
75604 +static slobidx_t slob_units(const slob_t *s)
75605 {
75606 if (s->units > 0)
75607 return s->units;
75608 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
75609 /*
75610 * Return the next free slob block pointer after this one.
75611 */
75612 -static slob_t *slob_next(slob_t *s)
75613 +static slob_t *slob_next(const slob_t *s)
75614 {
75615 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
75616 slobidx_t next;
75617 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
75618 /*
75619 * Returns true if s is the last free block in its page.
75620 */
75621 -static int slob_last(slob_t *s)
75622 +static int slob_last(const slob_t *s)
75623 {
75624 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
75625 }
75626
75627 -static void *slob_new_pages(gfp_t gfp, int order, int node)
75628 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
75629 {
75630 - void *page;
75631 + struct page *page;
75632
75633 #ifdef CONFIG_NUMA
75634 if (node != -1)
75635 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
75636 if (!page)
75637 return NULL;
75638
75639 - return page_address(page);
75640 + __SetPageSlab(page);
75641 + return page;
75642 }
75643
75644 -static void slob_free_pages(void *b, int order)
75645 +static void slob_free_pages(struct page *sp, int order)
75646 {
75647 if (current->reclaim_state)
75648 current->reclaim_state->reclaimed_slab += 1 << order;
75649 - free_pages((unsigned long)b, order);
75650 + __ClearPageSlab(sp);
75651 + reset_page_mapcount(sp);
75652 + sp->private = 0;
75653 + __free_pages(sp, order);
75654 }
75655
75656 /*
75657 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
75658
75659 /* Not enough space: must allocate a new page */
75660 if (!b) {
75661 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75662 - if (!b)
75663 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75664 + if (!sp)
75665 return NULL;
75666 - sp = virt_to_page(b);
75667 - __SetPageSlab(sp);
75668 + b = page_address(sp);
75669
75670 spin_lock_irqsave(&slob_lock, flags);
75671 sp->units = SLOB_UNITS(PAGE_SIZE);
75672 sp->freelist = b;
75673 + sp->private = 0;
75674 INIT_LIST_HEAD(&sp->list);
75675 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
75676 set_slob_page_free(sp, slob_list);
75677 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
75678 if (slob_page_free(sp))
75679 clear_slob_page_free(sp);
75680 spin_unlock_irqrestore(&slob_lock, flags);
75681 - __ClearPageSlab(sp);
75682 - reset_page_mapcount(sp);
75683 - slob_free_pages(b, 0);
75684 + slob_free_pages(sp, 0);
75685 return;
75686 }
75687
75688 @@ -425,11 +427,10 @@ out:
75689 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
75690 */
75691
75692 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75693 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
75694 {
75695 - unsigned int *m;
75696 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75697 - void *ret;
75698 + slob_t *m;
75699 + void *ret = NULL;
75700
75701 gfp &= gfp_allowed_mask;
75702
75703 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75704
75705 if (!m)
75706 return NULL;
75707 - *m = size;
75708 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75709 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75710 + m[0].units = size;
75711 + m[1].units = align;
75712 ret = (void *)m + align;
75713
75714 trace_kmalloc_node(_RET_IP_, ret,
75715 size, size + align, gfp, node);
75716 } else {
75717 unsigned int order = get_order(size);
75718 + struct page *page;
75719
75720 if (likely(order))
75721 gfp |= __GFP_COMP;
75722 - ret = slob_new_pages(gfp, order, node);
75723 - if (ret) {
75724 - struct page *page;
75725 - page = virt_to_page(ret);
75726 + page = slob_new_pages(gfp, order, node);
75727 + if (page) {
75728 + ret = page_address(page);
75729 page->private = size;
75730 }
75731
75732 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75733 size, PAGE_SIZE << order, gfp, node);
75734 }
75735
75736 - kmemleak_alloc(ret, size, 1, gfp);
75737 + return ret;
75738 +}
75739 +
75740 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75741 +{
75742 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75743 + void *ret = __kmalloc_node_align(size, gfp, node, align);
75744 +
75745 + if (!ZERO_OR_NULL_PTR(ret))
75746 + kmemleak_alloc(ret, size, 1, gfp);
75747 return ret;
75748 }
75749 EXPORT_SYMBOL(__kmalloc_node);
75750 @@ -480,15 +493,91 @@ void kfree(const void *block)
75751 kmemleak_free(block);
75752
75753 sp = virt_to_page(block);
75754 - if (PageSlab(sp)) {
75755 + VM_BUG_ON(!PageSlab(sp));
75756 + if (!sp->private) {
75757 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75758 - unsigned int *m = (unsigned int *)(block - align);
75759 - slob_free(m, *m + align);
75760 - } else
75761 + slob_t *m = (slob_t *)(block - align);
75762 + slob_free(m, m[0].units + align);
75763 + } else {
75764 + __ClearPageSlab(sp);
75765 + reset_page_mapcount(sp);
75766 + sp->private = 0;
75767 put_page(sp);
75768 + }
75769 }
75770 EXPORT_SYMBOL(kfree);
75771
75772 +bool is_usercopy_object(const void *ptr)
75773 +{
75774 + if (!slab_is_available())
75775 + return false;
75776 +
75777 + // PAX: TODO
75778 +
75779 + return false;
75780 +}
75781 +
75782 +#ifdef CONFIG_PAX_USERCOPY
75783 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75784 +{
75785 + struct page *page;
75786 + const slob_t *free;
75787 + const void *base;
75788 + unsigned long flags;
75789 +
75790 + if (ZERO_OR_NULL_PTR(ptr))
75791 + return "<null>";
75792 +
75793 + if (!virt_addr_valid(ptr))
75794 + return NULL;
75795 +
75796 + page = virt_to_head_page(ptr);
75797 + if (!PageSlab(page))
75798 + return NULL;
75799 +
75800 + if (page->private) {
75801 + base = page;
75802 + if (base <= ptr && n <= page->private - (ptr - base))
75803 + return NULL;
75804 + return "<slob>";
75805 + }
75806 +
75807 + /* some tricky double walking to find the chunk */
75808 + spin_lock_irqsave(&slob_lock, flags);
75809 + base = (void *)((unsigned long)ptr & PAGE_MASK);
75810 + free = page->freelist;
75811 +
75812 + while (!slob_last(free) && (void *)free <= ptr) {
75813 + base = free + slob_units(free);
75814 + free = slob_next(free);
75815 + }
75816 +
75817 + while (base < (void *)free) {
75818 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75819 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
75820 + int offset;
75821 +
75822 + if (ptr < base + align)
75823 + break;
75824 +
75825 + offset = ptr - base - align;
75826 + if (offset >= m) {
75827 + base += size;
75828 + continue;
75829 + }
75830 +
75831 + if (n > m - offset)
75832 + break;
75833 +
75834 + spin_unlock_irqrestore(&slob_lock, flags);
75835 + return NULL;
75836 + }
75837 +
75838 + spin_unlock_irqrestore(&slob_lock, flags);
75839 + return "<slob>";
75840 +}
75841 +#endif
75842 +
75843 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75844 size_t ksize(const void *block)
75845 {
75846 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
75847 return 0;
75848
75849 sp = virt_to_page(block);
75850 - if (PageSlab(sp)) {
75851 + VM_BUG_ON(!PageSlab(sp));
75852 + if (!sp->private) {
75853 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75854 - unsigned int *m = (unsigned int *)(block - align);
75855 - return SLOB_UNITS(*m) * SLOB_UNIT;
75856 + slob_t *m = (slob_t *)(block - align);
75857 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75858 } else
75859 return sp->private;
75860 }
75861 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75862 {
75863 struct kmem_cache *c;
75864
75865 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75866 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
75867 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
75868 +#else
75869 c = slob_alloc(sizeof(struct kmem_cache),
75870 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
75871 +#endif
75872
75873 if (c) {
75874 c->name = name;
75875 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
75876
75877 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75878 {
75879 - void *b;
75880 + void *b = NULL;
75881
75882 flags &= gfp_allowed_mask;
75883
75884 lockdep_trace_alloc(flags);
75885
75886 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75887 + b = __kmalloc_node_align(c->size, flags, node, c->align);
75888 +#else
75889 if (c->size < PAGE_SIZE) {
75890 b = slob_alloc(c->size, flags, c->align, node);
75891 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75892 SLOB_UNITS(c->size) * SLOB_UNIT,
75893 flags, node);
75894 } else {
75895 - b = slob_new_pages(flags, get_order(c->size), node);
75896 + struct page *sp;
75897 +
75898 + sp = slob_new_pages(flags, get_order(c->size), node);
75899 + if (sp) {
75900 + b = page_address(sp);
75901 + sp->private = c->size;
75902 + }
75903 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75904 PAGE_SIZE << get_order(c->size),
75905 flags, node);
75906 }
75907 +#endif
75908
75909 if (c->ctor)
75910 c->ctor(b);
75911 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75912
75913 static void __kmem_cache_free(void *b, int size)
75914 {
75915 - if (size < PAGE_SIZE)
75916 + struct page *sp;
75917 +
75918 + sp = virt_to_page(b);
75919 + BUG_ON(!PageSlab(sp));
75920 + if (!sp->private)
75921 slob_free(b, size);
75922 else
75923 - slob_free_pages(b, get_order(size));
75924 + slob_free_pages(sp, get_order(size));
75925 }
75926
75927 static void kmem_rcu_free(struct rcu_head *head)
75928 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75929
75930 void kmem_cache_free(struct kmem_cache *c, void *b)
75931 {
75932 + int size = c->size;
75933 +
75934 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75935 + if (size + c->align < PAGE_SIZE) {
75936 + size += c->align;
75937 + b -= c->align;
75938 + }
75939 +#endif
75940 +
75941 kmemleak_free_recursive(b, c->flags);
75942 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75943 struct slob_rcu *slob_rcu;
75944 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75945 - slob_rcu->size = c->size;
75946 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75947 + slob_rcu->size = size;
75948 call_rcu(&slob_rcu->head, kmem_rcu_free);
75949 } else {
75950 - __kmem_cache_free(b, c->size);
75951 + __kmem_cache_free(b, size);
75952 }
75953
75954 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75955 + trace_kfree(_RET_IP_, b);
75956 +#else
75957 trace_kmem_cache_free(_RET_IP_, b);
75958 +#endif
75959 +
75960 }
75961 EXPORT_SYMBOL(kmem_cache_free);
75962
75963 diff --git a/mm/slub.c b/mm/slub.c
75964 index 2fdd96f..1e2f893 100644
75965 --- a/mm/slub.c
75966 +++ b/mm/slub.c
75967 @@ -201,7 +201,7 @@ struct track {
75968
75969 enum track_item { TRACK_ALLOC, TRACK_FREE };
75970
75971 -#ifdef CONFIG_SYSFS
75972 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75973 static int sysfs_slab_add(struct kmem_cache *);
75974 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75975 static void sysfs_slab_remove(struct kmem_cache *);
75976 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75977 if (!t->addr)
75978 return;
75979
75980 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75981 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75982 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75983 #ifdef CONFIG_STACKTRACE
75984 {
75985 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75986
75987 page = virt_to_head_page(x);
75988
75989 + BUG_ON(!PageSlab(page));
75990 +
75991 slab_free(s, page, x, _RET_IP_);
75992
75993 trace_kmem_cache_free(_RET_IP_, x);
75994 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75995 * Merge control. If this is set then no merging of slab caches will occur.
75996 * (Could be removed. This was introduced to pacify the merge skeptics.)
75997 */
75998 -static int slub_nomerge;
75999 +static int slub_nomerge = 1;
76000
76001 /*
76002 * Calculate the order of allocation given an slab object size.
76003 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
76004 else
76005 s->cpu_partial = 30;
76006
76007 - s->refcount = 1;
76008 + atomic_set(&s->refcount, 1);
76009 #ifdef CONFIG_NUMA
76010 s->remote_node_defrag_ratio = 1000;
76011 #endif
76012 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
76013 void kmem_cache_destroy(struct kmem_cache *s)
76014 {
76015 mutex_lock(&slab_mutex);
76016 - s->refcount--;
76017 - if (!s->refcount) {
76018 + if (atomic_dec_and_test(&s->refcount)) {
76019 list_del(&s->list);
76020 mutex_unlock(&slab_mutex);
76021 if (kmem_cache_close(s)) {
76022 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
76023 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
76024 #endif
76025
76026 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76027 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
76028 +#endif
76029 +
76030 static int __init setup_slub_min_order(char *str)
76031 {
76032 get_option(&str, &slub_min_order);
76033 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
76034 return kmalloc_dma_caches[index];
76035
76036 #endif
76037 +
76038 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76039 + if (flags & SLAB_USERCOPY)
76040 + return kmalloc_usercopy_caches[index];
76041 +
76042 +#endif
76043 +
76044 return kmalloc_caches[index];
76045 }
76046
76047 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
76048 EXPORT_SYMBOL(__kmalloc_node);
76049 #endif
76050
76051 +bool is_usercopy_object(const void *ptr)
76052 +{
76053 + struct page *page;
76054 + struct kmem_cache *s;
76055 +
76056 + if (ZERO_OR_NULL_PTR(ptr))
76057 + return false;
76058 +
76059 + if (!slab_is_available())
76060 + return false;
76061 +
76062 + if (!virt_addr_valid(ptr))
76063 + return false;
76064 +
76065 + page = virt_to_head_page(ptr);
76066 +
76067 + if (!PageSlab(page))
76068 + return false;
76069 +
76070 + s = page->slab;
76071 + return s->flags & SLAB_USERCOPY;
76072 +}
76073 +
76074 +#ifdef CONFIG_PAX_USERCOPY
76075 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
76076 +{
76077 + struct page *page;
76078 + struct kmem_cache *s;
76079 + unsigned long offset;
76080 +
76081 + if (ZERO_OR_NULL_PTR(ptr))
76082 + return "<null>";
76083 +
76084 + if (!virt_addr_valid(ptr))
76085 + return NULL;
76086 +
76087 + page = virt_to_head_page(ptr);
76088 +
76089 + if (!PageSlab(page))
76090 + return NULL;
76091 +
76092 + s = page->slab;
76093 + if (!(s->flags & SLAB_USERCOPY))
76094 + return s->name;
76095 +
76096 + offset = (ptr - page_address(page)) % s->size;
76097 + if (offset <= s->object_size && n <= s->object_size - offset)
76098 + return NULL;
76099 +
76100 + return s->name;
76101 +}
76102 +#endif
76103 +
76104 size_t ksize(const void *object)
76105 {
76106 struct page *page;
76107 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
76108 int node;
76109
76110 list_add(&s->list, &slab_caches);
76111 - s->refcount = -1;
76112 + atomic_set(&s->refcount, -1);
76113
76114 for_each_node_state(node, N_NORMAL_MEMORY) {
76115 struct kmem_cache_node *n = get_node(s, node);
76116 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
76117
76118 /* Caches that are not of the two-to-the-power-of size */
76119 if (KMALLOC_MIN_SIZE <= 32) {
76120 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
76121 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
76122 caches++;
76123 }
76124
76125 if (KMALLOC_MIN_SIZE <= 64) {
76126 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
76127 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
76128 caches++;
76129 }
76130
76131 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
76132 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
76133 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
76134 caches++;
76135 }
76136
76137 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
76138 }
76139 }
76140 #endif
76141 +
76142 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76143 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
76144 + struct kmem_cache *s = kmalloc_caches[i];
76145 +
76146 + if (s && s->size) {
76147 + char *name = kasprintf(GFP_NOWAIT,
76148 + "usercopy-kmalloc-%d", s->object_size);
76149 +
76150 + BUG_ON(!name);
76151 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
76152 + s->object_size, SLAB_USERCOPY);
76153 + }
76154 + }
76155 +#endif
76156 +
76157 printk(KERN_INFO
76158 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
76159 " CPUs=%d, Nodes=%d\n",
76160 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
76161 /*
76162 * We may have set a slab to be unmergeable during bootstrap.
76163 */
76164 - if (s->refcount < 0)
76165 + if (atomic_read(&s->refcount) < 0)
76166 return 1;
76167
76168 return 0;
76169 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
76170
76171 s = find_mergeable(size, align, flags, name, ctor);
76172 if (s) {
76173 - s->refcount++;
76174 + atomic_inc(&s->refcount);
76175 /*
76176 * Adjust the object sizes so that we clear
76177 * the complete object on kzalloc.
76178 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
76179 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
76180
76181 if (sysfs_slab_alias(s, name)) {
76182 - s->refcount--;
76183 + atomic_dec(&s->refcount);
76184 return NULL;
76185 }
76186 return s;
76187 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
76188 }
76189 #endif
76190
76191 -#ifdef CONFIG_SYSFS
76192 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76193 static int count_inuse(struct page *page)
76194 {
76195 return page->inuse;
76196 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
76197 validate_slab_cache(kmalloc_caches[9]);
76198 }
76199 #else
76200 -#ifdef CONFIG_SYSFS
76201 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76202 static void resiliency_test(void) {};
76203 #endif
76204 #endif
76205
76206 -#ifdef CONFIG_SYSFS
76207 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76208 enum slab_stat_type {
76209 SL_ALL, /* All slabs */
76210 SL_PARTIAL, /* Only partially allocated slabs */
76211 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
76212
76213 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
76214 {
76215 - return sprintf(buf, "%d\n", s->refcount - 1);
76216 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
76217 }
76218 SLAB_ATTR_RO(aliases);
76219
76220 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
76221 return name;
76222 }
76223
76224 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76225 static int sysfs_slab_add(struct kmem_cache *s)
76226 {
76227 int err;
76228 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
76229 kobject_del(&s->kobj);
76230 kobject_put(&s->kobj);
76231 }
76232 +#endif
76233
76234 /*
76235 * Need to buffer aliases during bootup until sysfs becomes
76236 @@ -5354,6 +5437,7 @@ struct saved_alias {
76237
76238 static struct saved_alias *alias_list;
76239
76240 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76241 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
76242 {
76243 struct saved_alias *al;
76244 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
76245 alias_list = al;
76246 return 0;
76247 }
76248 +#endif
76249
76250 static int __init slab_sysfs_init(void)
76251 {
76252 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
76253 index 1b7e22a..3fcd4f3 100644
76254 --- a/mm/sparse-vmemmap.c
76255 +++ b/mm/sparse-vmemmap.c
76256 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
76257 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
76258 if (!p)
76259 return NULL;
76260 - pud_populate(&init_mm, pud, p);
76261 + pud_populate_kernel(&init_mm, pud, p);
76262 }
76263 return pud;
76264 }
76265 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
76266 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
76267 if (!p)
76268 return NULL;
76269 - pgd_populate(&init_mm, pgd, p);
76270 + pgd_populate_kernel(&init_mm, pgd, p);
76271 }
76272 return pgd;
76273 }
76274 diff --git a/mm/swap.c b/mm/swap.c
76275 index 7782588..228c784 100644
76276 --- a/mm/swap.c
76277 +++ b/mm/swap.c
76278 @@ -30,6 +30,7 @@
76279 #include <linux/backing-dev.h>
76280 #include <linux/memcontrol.h>
76281 #include <linux/gfp.h>
76282 +#include <linux/hugetlb.h>
76283
76284 #include "internal.h"
76285
76286 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
76287
76288 __page_cache_release(page);
76289 dtor = get_compound_page_dtor(page);
76290 + if (!PageHuge(page))
76291 + BUG_ON(dtor != free_compound_page);
76292 (*dtor)(page);
76293 }
76294
76295 diff --git a/mm/swapfile.c b/mm/swapfile.c
76296 index 14e254c..a6af32c 100644
76297 --- a/mm/swapfile.c
76298 +++ b/mm/swapfile.c
76299 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
76300
76301 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
76302 /* Activity counter to indicate that a swapon or swapoff has occurred */
76303 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
76304 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
76305
76306 static inline unsigned char swap_count(unsigned char ent)
76307 {
76308 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
76309 }
76310 filp_close(swap_file, NULL);
76311 err = 0;
76312 - atomic_inc(&proc_poll_event);
76313 + atomic_inc_unchecked(&proc_poll_event);
76314 wake_up_interruptible(&proc_poll_wait);
76315
76316 out_dput:
76317 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
76318
76319 poll_wait(file, &proc_poll_wait, wait);
76320
76321 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
76322 - seq->poll_event = atomic_read(&proc_poll_event);
76323 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
76324 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
76325 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
76326 }
76327
76328 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
76329 return ret;
76330
76331 seq = file->private_data;
76332 - seq->poll_event = atomic_read(&proc_poll_event);
76333 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
76334 return 0;
76335 }
76336
76337 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
76338 (frontswap_map) ? "FS" : "");
76339
76340 mutex_unlock(&swapon_mutex);
76341 - atomic_inc(&proc_poll_event);
76342 + atomic_inc_unchecked(&proc_poll_event);
76343 wake_up_interruptible(&proc_poll_wait);
76344
76345 if (S_ISREG(inode->i_mode))
76346 diff --git a/mm/util.c b/mm/util.c
76347 index 8c7265a..c96d884 100644
76348 --- a/mm/util.c
76349 +++ b/mm/util.c
76350 @@ -285,6 +285,12 @@ done:
76351 void arch_pick_mmap_layout(struct mm_struct *mm)
76352 {
76353 mm->mmap_base = TASK_UNMAPPED_BASE;
76354 +
76355 +#ifdef CONFIG_PAX_RANDMMAP
76356 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76357 + mm->mmap_base += mm->delta_mmap;
76358 +#endif
76359 +
76360 mm->get_unmapped_area = arch_get_unmapped_area;
76361 mm->unmap_area = arch_unmap_area;
76362 }
76363 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
76364 index 2bb90b1..3795e47 100644
76365 --- a/mm/vmalloc.c
76366 +++ b/mm/vmalloc.c
76367 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
76368
76369 pte = pte_offset_kernel(pmd, addr);
76370 do {
76371 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76372 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76373 +
76374 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76375 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
76376 + BUG_ON(!pte_exec(*pte));
76377 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
76378 + continue;
76379 + }
76380 +#endif
76381 +
76382 + {
76383 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76384 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76385 + }
76386 } while (pte++, addr += PAGE_SIZE, addr != end);
76387 }
76388
76389 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
76390 pte = pte_alloc_kernel(pmd, addr);
76391 if (!pte)
76392 return -ENOMEM;
76393 +
76394 + pax_open_kernel();
76395 do {
76396 struct page *page = pages[*nr];
76397
76398 - if (WARN_ON(!pte_none(*pte)))
76399 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76400 + if (pgprot_val(prot) & _PAGE_NX)
76401 +#endif
76402 +
76403 + if (!pte_none(*pte)) {
76404 + pax_close_kernel();
76405 + WARN_ON(1);
76406 return -EBUSY;
76407 - if (WARN_ON(!page))
76408 + }
76409 + if (!page) {
76410 + pax_close_kernel();
76411 + WARN_ON(1);
76412 return -ENOMEM;
76413 + }
76414 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
76415 (*nr)++;
76416 } while (pte++, addr += PAGE_SIZE, addr != end);
76417 + pax_close_kernel();
76418 return 0;
76419 }
76420
76421 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
76422 pmd_t *pmd;
76423 unsigned long next;
76424
76425 - pmd = pmd_alloc(&init_mm, pud, addr);
76426 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
76427 if (!pmd)
76428 return -ENOMEM;
76429 do {
76430 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
76431 pud_t *pud;
76432 unsigned long next;
76433
76434 - pud = pud_alloc(&init_mm, pgd, addr);
76435 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
76436 if (!pud)
76437 return -ENOMEM;
76438 do {
76439 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
76440 * and fall back on vmalloc() if that fails. Others
76441 * just put it in the vmalloc space.
76442 */
76443 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
76444 +#ifdef CONFIG_MODULES
76445 +#ifdef MODULES_VADDR
76446 unsigned long addr = (unsigned long)x;
76447 if (addr >= MODULES_VADDR && addr < MODULES_END)
76448 return 1;
76449 #endif
76450 +
76451 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76452 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
76453 + return 1;
76454 +#endif
76455 +
76456 +#endif
76457 +
76458 return is_vmalloc_addr(x);
76459 }
76460
76461 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
76462
76463 if (!pgd_none(*pgd)) {
76464 pud_t *pud = pud_offset(pgd, addr);
76465 +#ifdef CONFIG_X86
76466 + if (!pud_large(*pud))
76467 +#endif
76468 if (!pud_none(*pud)) {
76469 pmd_t *pmd = pmd_offset(pud, addr);
76470 +#ifdef CONFIG_X86
76471 + if (!pmd_large(*pmd))
76472 +#endif
76473 if (!pmd_none(*pmd)) {
76474 pte_t *ptep, pte;
76475
76476 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
76477 * Allocate a region of KVA of the specified size and alignment, within the
76478 * vstart and vend.
76479 */
76480 -static struct vmap_area *alloc_vmap_area(unsigned long size,
76481 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
76482 unsigned long align,
76483 unsigned long vstart, unsigned long vend,
76484 int node, gfp_t gfp_mask)
76485 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
76486 struct vm_struct *area;
76487
76488 BUG_ON(in_interrupt());
76489 +
76490 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76491 + if (flags & VM_KERNEXEC) {
76492 + if (start != VMALLOC_START || end != VMALLOC_END)
76493 + return NULL;
76494 + start = (unsigned long)MODULES_EXEC_VADDR;
76495 + end = (unsigned long)MODULES_EXEC_END;
76496 + }
76497 +#endif
76498 +
76499 if (flags & VM_IOREMAP) {
76500 int bit = fls(size);
76501
76502 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
76503 if (count > totalram_pages)
76504 return NULL;
76505
76506 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76507 + if (!(pgprot_val(prot) & _PAGE_NX))
76508 + flags |= VM_KERNEXEC;
76509 +#endif
76510 +
76511 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
76512 __builtin_return_address(0));
76513 if (!area)
76514 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
76515 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
76516 goto fail;
76517
76518 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76519 + if (!(pgprot_val(prot) & _PAGE_NX))
76520 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
76521 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
76522 + else
76523 +#endif
76524 +
76525 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
76526 start, end, node, gfp_mask, caller);
76527 if (!area)
76528 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
76529 * For tight control over page level allocator and protection flags
76530 * use __vmalloc() instead.
76531 */
76532 -
76533 void *vmalloc_exec(unsigned long size)
76534 {
76535 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
76536 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
76537 -1, __builtin_return_address(0));
76538 }
76539
76540 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
76541 unsigned long uaddr = vma->vm_start;
76542 unsigned long usize = vma->vm_end - vma->vm_start;
76543
76544 + BUG_ON(vma->vm_mirror);
76545 +
76546 if ((PAGE_SIZE-1) & (unsigned long)addr)
76547 return -EINVAL;
76548
76549 @@ -2572,7 +2634,7 @@ static int s_show(struct seq_file *m, void *p)
76550 {
76551 struct vm_struct *v = p;
76552
76553 - seq_printf(m, "0x%p-0x%p %7ld",
76554 + seq_printf(m, "0x%pK-0x%pK %7ld",
76555 v->addr, v->addr + v->size, v->size);
76556
76557 if (v->caller)
76558 diff --git a/mm/vmstat.c b/mm/vmstat.c
76559 index df7a674..8b4a4f3 100644
76560 --- a/mm/vmstat.c
76561 +++ b/mm/vmstat.c
76562 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
76563 *
76564 * vm_stat contains the global counters
76565 */
76566 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76567 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76568 EXPORT_SYMBOL(vm_stat);
76569
76570 #ifdef CONFIG_SMP
76571 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
76572 v = p->vm_stat_diff[i];
76573 p->vm_stat_diff[i] = 0;
76574 local_irq_restore(flags);
76575 - atomic_long_add(v, &zone->vm_stat[i]);
76576 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76577 global_diff[i] += v;
76578 #ifdef CONFIG_NUMA
76579 /* 3 seconds idle till flush */
76580 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
76581
76582 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
76583 if (global_diff[i])
76584 - atomic_long_add(global_diff[i], &vm_stat[i]);
76585 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
76586 }
76587
76588 #endif
76589 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
76590 start_cpu_timer(cpu);
76591 #endif
76592 #ifdef CONFIG_PROC_FS
76593 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
76594 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
76595 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
76596 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
76597 + {
76598 + mode_t gr_mode = S_IRUGO;
76599 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
76600 + gr_mode = S_IRUSR;
76601 +#endif
76602 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
76603 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
76604 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
76605 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
76606 +#else
76607 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
76608 +#endif
76609 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
76610 + }
76611 #endif
76612 return 0;
76613 }
76614 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
76615 index 9096bcb..43ed7bb 100644
76616 --- a/net/8021q/vlan.c
76617 +++ b/net/8021q/vlan.c
76618 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
76619 err = -EPERM;
76620 if (!capable(CAP_NET_ADMIN))
76621 break;
76622 - if ((args.u.name_type >= 0) &&
76623 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
76624 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
76625 struct vlan_net *vn;
76626
76627 vn = net_generic(net, vlan_net_id);
76628 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
76629 index 6449bae..8c1f454 100644
76630 --- a/net/9p/trans_fd.c
76631 +++ b/net/9p/trans_fd.c
76632 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
76633 oldfs = get_fs();
76634 set_fs(get_ds());
76635 /* The cast to a user pointer is valid due to the set_fs() */
76636 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
76637 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
76638 set_fs(oldfs);
76639
76640 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
76641 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
76642 index 876fbe8..8bbea9f 100644
76643 --- a/net/atm/atm_misc.c
76644 +++ b/net/atm/atm_misc.c
76645 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
76646 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
76647 return 1;
76648 atm_return(vcc, truesize);
76649 - atomic_inc(&vcc->stats->rx_drop);
76650 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76651 return 0;
76652 }
76653 EXPORT_SYMBOL(atm_charge);
76654 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
76655 }
76656 }
76657 atm_return(vcc, guess);
76658 - atomic_inc(&vcc->stats->rx_drop);
76659 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76660 return NULL;
76661 }
76662 EXPORT_SYMBOL(atm_alloc_charge);
76663 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
76664
76665 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76666 {
76667 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76668 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76669 __SONET_ITEMS
76670 #undef __HANDLE_ITEM
76671 }
76672 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76673
76674 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76675 {
76676 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76677 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76678 __SONET_ITEMS
76679 #undef __HANDLE_ITEM
76680 }
76681 diff --git a/net/atm/lec.h b/net/atm/lec.h
76682 index a86aff9..3a0d6f6 100644
76683 --- a/net/atm/lec.h
76684 +++ b/net/atm/lec.h
76685 @@ -48,7 +48,7 @@ struct lane2_ops {
76686 const u8 *tlvs, u32 sizeoftlvs);
76687 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76688 const u8 *tlvs, u32 sizeoftlvs);
76689 -};
76690 +} __no_const;
76691
76692 /*
76693 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76694 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76695 index 0919a88..a23d54e 100644
76696 --- a/net/atm/mpc.h
76697 +++ b/net/atm/mpc.h
76698 @@ -33,7 +33,7 @@ struct mpoa_client {
76699 struct mpc_parameters parameters; /* parameters for this client */
76700
76701 const struct net_device_ops *old_ops;
76702 - struct net_device_ops new_ops;
76703 + net_device_ops_no_const new_ops;
76704 };
76705
76706
76707 diff --git a/net/atm/proc.c b/net/atm/proc.c
76708 index 0d020de..011c7bb 100644
76709 --- a/net/atm/proc.c
76710 +++ b/net/atm/proc.c
76711 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76712 const struct k_atm_aal_stats *stats)
76713 {
76714 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76715 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76716 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76717 - atomic_read(&stats->rx_drop));
76718 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76719 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76720 + atomic_read_unchecked(&stats->rx_drop));
76721 }
76722
76723 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76724 diff --git a/net/atm/resources.c b/net/atm/resources.c
76725 index 23f45ce..c748f1a 100644
76726 --- a/net/atm/resources.c
76727 +++ b/net/atm/resources.c
76728 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76729 static void copy_aal_stats(struct k_atm_aal_stats *from,
76730 struct atm_aal_stats *to)
76731 {
76732 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76733 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76734 __AAL_STAT_ITEMS
76735 #undef __HANDLE_ITEM
76736 }
76737 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76738 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76739 struct atm_aal_stats *to)
76740 {
76741 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76742 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76743 __AAL_STAT_ITEMS
76744 #undef __HANDLE_ITEM
76745 }
76746 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76747 index 469daab..262851c 100644
76748 --- a/net/batman-adv/bat_iv_ogm.c
76749 +++ b/net/batman-adv/bat_iv_ogm.c
76750 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76751
76752 /* randomize initial seqno to avoid collision */
76753 get_random_bytes(&random_seqno, sizeof(random_seqno));
76754 - atomic_set(&hard_iface->seqno, random_seqno);
76755 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76756
76757 hard_iface->packet_len = BATADV_OGM_HLEN;
76758 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76759 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76760
76761 /* change sequence number to network order */
76762 batadv_ogm_packet->seqno =
76763 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
76764 - atomic_inc(&hard_iface->seqno);
76765 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
76766 + atomic_inc_unchecked(&hard_iface->seqno);
76767
76768 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
76769 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
76770 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76771 return;
76772
76773 /* could be changed by schedule_own_packet() */
76774 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
76775 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76776
76777 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76778 has_directlink_flag = 1;
76779 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76780 index 282bf6e..4b2603d 100644
76781 --- a/net/batman-adv/hard-interface.c
76782 +++ b/net/batman-adv/hard-interface.c
76783 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76784 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76785 dev_add_pack(&hard_iface->batman_adv_ptype);
76786
76787 - atomic_set(&hard_iface->frag_seqno, 1);
76788 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76789 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76790 hard_iface->net_dev->name);
76791
76792 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76793 /* This can't be called via a bat_priv callback because
76794 * we have no bat_priv yet.
76795 */
76796 - atomic_set(&hard_iface->seqno, 1);
76797 + atomic_set_unchecked(&hard_iface->seqno, 1);
76798 hard_iface->packet_buff = NULL;
76799
76800 return hard_iface;
76801 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76802 index 21c5357..768be1a 100644
76803 --- a/net/batman-adv/soft-interface.c
76804 +++ b/net/batman-adv/soft-interface.c
76805 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76806
76807 /* set broadcast sequence number */
76808 bcast_packet->seqno =
76809 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
76810 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
76811
76812 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76813
76814 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
76815 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76816
76817 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76818 - atomic_set(&bat_priv->bcast_seqno, 1);
76819 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76820 atomic_set(&bat_priv->ttvn, 0);
76821 atomic_set(&bat_priv->tt_local_changes, 0);
76822 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
76823 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76824 index 12635fd..d99d837 100644
76825 --- a/net/batman-adv/types.h
76826 +++ b/net/batman-adv/types.h
76827 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
76828 int16_t if_num;
76829 char if_status;
76830 struct net_device *net_dev;
76831 - atomic_t seqno;
76832 - atomic_t frag_seqno;
76833 + atomic_unchecked_t seqno;
76834 + atomic_unchecked_t frag_seqno;
76835 unsigned char *packet_buff;
76836 int packet_len;
76837 struct kobject *hardif_obj;
76838 @@ -176,7 +176,7 @@ struct batadv_priv {
76839 atomic_t orig_interval; /* uint */
76840 atomic_t hop_penalty; /* uint */
76841 atomic_t log_level; /* uint */
76842 - atomic_t bcast_seqno;
76843 + atomic_unchecked_t bcast_seqno;
76844 atomic_t bcast_queue_left;
76845 atomic_t batman_queue_left;
76846 atomic_t ttvn; /* translation table version number */
76847 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76848 index 0016464..0ef3e53 100644
76849 --- a/net/batman-adv/unicast.c
76850 +++ b/net/batman-adv/unicast.c
76851 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76852 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76853 frag2->flags = large_tail;
76854
76855 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76856 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76857 frag1->seqno = htons(seqno - 1);
76858 frag2->seqno = htons(seqno);
76859
76860 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76861 index d5ace1e..231c4bf 100644
76862 --- a/net/bluetooth/hci_sock.c
76863 +++ b/net/bluetooth/hci_sock.c
76864 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76865 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76866 }
76867
76868 - len = min_t(unsigned int, len, sizeof(uf));
76869 + len = min((size_t)len, sizeof(uf));
76870 if (copy_from_user(&uf, optval, len)) {
76871 err = -EFAULT;
76872 break;
76873 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76874 index 38c00f1..e9d566e 100644
76875 --- a/net/bluetooth/l2cap_core.c
76876 +++ b/net/bluetooth/l2cap_core.c
76877 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76878 break;
76879
76880 case L2CAP_CONF_RFC:
76881 - if (olen == sizeof(rfc))
76882 - memcpy(&rfc, (void *)val, olen);
76883 + if (olen != sizeof(rfc))
76884 + break;
76885 +
76886 + memcpy(&rfc, (void *)val, olen);
76887
76888 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76889 rfc.mode != chan->mode)
76890 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76891 index 34bbe1c..451c19b 100644
76892 --- a/net/bluetooth/l2cap_sock.c
76893 +++ b/net/bluetooth/l2cap_sock.c
76894 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76895 struct sock *sk = sock->sk;
76896 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76897 struct l2cap_options opts;
76898 - int len, err = 0;
76899 + int err = 0;
76900 + size_t len = optlen;
76901 u32 opt;
76902
76903 BT_DBG("sk %p", sk);
76904 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76905 opts.max_tx = chan->max_tx;
76906 opts.txwin_size = chan->tx_win;
76907
76908 - len = min_t(unsigned int, sizeof(opts), optlen);
76909 + len = min(sizeof(opts), len);
76910 if (copy_from_user((char *) &opts, optval, len)) {
76911 err = -EFAULT;
76912 break;
76913 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76914 struct bt_security sec;
76915 struct bt_power pwr;
76916 struct l2cap_conn *conn;
76917 - int len, err = 0;
76918 + int err = 0;
76919 + size_t len = optlen;
76920 u32 opt;
76921
76922 BT_DBG("sk %p", sk);
76923 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76924
76925 sec.level = BT_SECURITY_LOW;
76926
76927 - len = min_t(unsigned int, sizeof(sec), optlen);
76928 + len = min(sizeof(sec), len);
76929 if (copy_from_user((char *) &sec, optval, len)) {
76930 err = -EFAULT;
76931 break;
76932 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76933
76934 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76935
76936 - len = min_t(unsigned int, sizeof(pwr), optlen);
76937 + len = min(sizeof(pwr), len);
76938 if (copy_from_user((char *) &pwr, optval, len)) {
76939 err = -EFAULT;
76940 break;
76941 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76942 index 1a17850..65a3129 100644
76943 --- a/net/bluetooth/rfcomm/sock.c
76944 +++ b/net/bluetooth/rfcomm/sock.c
76945 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76946 struct sock *sk = sock->sk;
76947 struct bt_security sec;
76948 int err = 0;
76949 - size_t len;
76950 + size_t len = optlen;
76951 u32 opt;
76952
76953 BT_DBG("sk %p", sk);
76954 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76955
76956 sec.level = BT_SECURITY_LOW;
76957
76958 - len = min_t(unsigned int, sizeof(sec), optlen);
76959 + len = min(sizeof(sec), len);
76960 if (copy_from_user((char *) &sec, optval, len)) {
76961 err = -EFAULT;
76962 break;
76963 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76964 index 56f1823..da44330 100644
76965 --- a/net/bluetooth/rfcomm/tty.c
76966 +++ b/net/bluetooth/rfcomm/tty.c
76967 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76968 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76969
76970 spin_lock_irqsave(&dev->port.lock, flags);
76971 - if (dev->port.count > 0) {
76972 + if (atomic_read(&dev->port.count) > 0) {
76973 spin_unlock_irqrestore(&dev->port.lock, flags);
76974 return;
76975 }
76976 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76977 return -ENODEV;
76978
76979 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76980 - dev->channel, dev->port.count);
76981 + dev->channel, atomic_read(&dev->port.count));
76982
76983 spin_lock_irqsave(&dev->port.lock, flags);
76984 - if (++dev->port.count > 1) {
76985 + if (atomic_inc_return(&dev->port.count) > 1) {
76986 spin_unlock_irqrestore(&dev->port.lock, flags);
76987 return 0;
76988 }
76989 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76990 return;
76991
76992 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76993 - dev->port.count);
76994 + atomic_read(&dev->port.count));
76995
76996 spin_lock_irqsave(&dev->port.lock, flags);
76997 - if (!--dev->port.count) {
76998 + if (!atomic_dec_return(&dev->port.count)) {
76999 spin_unlock_irqrestore(&dev->port.lock, flags);
77000 if (dev->tty_dev->parent)
77001 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
77002 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
77003 index 5fe2ff3..121d696 100644
77004 --- a/net/bridge/netfilter/ebtables.c
77005 +++ b/net/bridge/netfilter/ebtables.c
77006 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77007 tmp.valid_hooks = t->table->valid_hooks;
77008 }
77009 mutex_unlock(&ebt_mutex);
77010 - if (copy_to_user(user, &tmp, *len) != 0){
77011 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
77012 BUGPRINT("c2u Didn't work\n");
77013 ret = -EFAULT;
77014 break;
77015 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
77016 goto out;
77017 tmp.valid_hooks = t->valid_hooks;
77018
77019 - if (copy_to_user(user, &tmp, *len) != 0) {
77020 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
77021 ret = -EFAULT;
77022 break;
77023 }
77024 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
77025 tmp.entries_size = t->table->entries_size;
77026 tmp.valid_hooks = t->table->valid_hooks;
77027
77028 - if (copy_to_user(user, &tmp, *len) != 0) {
77029 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
77030 ret = -EFAULT;
77031 break;
77032 }
77033 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
77034 index 44f270f..1f5602d 100644
77035 --- a/net/caif/cfctrl.c
77036 +++ b/net/caif/cfctrl.c
77037 @@ -10,6 +10,7 @@
77038 #include <linux/spinlock.h>
77039 #include <linux/slab.h>
77040 #include <linux/pkt_sched.h>
77041 +#include <linux/sched.h>
77042 #include <net/caif/caif_layer.h>
77043 #include <net/caif/cfpkt.h>
77044 #include <net/caif/cfctrl.h>
77045 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
77046 memset(&dev_info, 0, sizeof(dev_info));
77047 dev_info.id = 0xff;
77048 cfsrvl_init(&this->serv, 0, &dev_info, false);
77049 - atomic_set(&this->req_seq_no, 1);
77050 - atomic_set(&this->rsp_seq_no, 1);
77051 + atomic_set_unchecked(&this->req_seq_no, 1);
77052 + atomic_set_unchecked(&this->rsp_seq_no, 1);
77053 this->serv.layer.receive = cfctrl_recv;
77054 sprintf(this->serv.layer.name, "ctrl");
77055 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
77056 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
77057 struct cfctrl_request_info *req)
77058 {
77059 spin_lock_bh(&ctrl->info_list_lock);
77060 - atomic_inc(&ctrl->req_seq_no);
77061 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
77062 + atomic_inc_unchecked(&ctrl->req_seq_no);
77063 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
77064 list_add_tail(&req->list, &ctrl->list);
77065 spin_unlock_bh(&ctrl->info_list_lock);
77066 }
77067 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
77068 if (p != first)
77069 pr_warn("Requests are not received in order\n");
77070
77071 - atomic_set(&ctrl->rsp_seq_no,
77072 + atomic_set_unchecked(&ctrl->rsp_seq_no,
77073 p->sequence_no);
77074 list_del(&p->list);
77075 goto out;
77076 diff --git a/net/can/gw.c b/net/can/gw.c
77077 index b54d5e6..91c3b25 100644
77078 --- a/net/can/gw.c
77079 +++ b/net/can/gw.c
77080 @@ -96,7 +96,7 @@ struct cf_mod {
77081 struct {
77082 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
77083 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
77084 - } csumfunc;
77085 + } __no_const csumfunc;
77086 };
77087
77088
77089 diff --git a/net/compat.c b/net/compat.c
77090 index 74ed1d7..3695bd9 100644
77091 --- a/net/compat.c
77092 +++ b/net/compat.c
77093 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
77094 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
77095 __get_user(kmsg->msg_flags, &umsg->msg_flags))
77096 return -EFAULT;
77097 - kmsg->msg_name = compat_ptr(tmp1);
77098 - kmsg->msg_iov = compat_ptr(tmp2);
77099 - kmsg->msg_control = compat_ptr(tmp3);
77100 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
77101 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
77102 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
77103 return 0;
77104 }
77105
77106 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
77107
77108 if (kern_msg->msg_namelen) {
77109 if (mode == VERIFY_READ) {
77110 - int err = move_addr_to_kernel(kern_msg->msg_name,
77111 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
77112 kern_msg->msg_namelen,
77113 kern_address);
77114 if (err < 0)
77115 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
77116 kern_msg->msg_name = NULL;
77117
77118 tot_len = iov_from_user_compat_to_kern(kern_iov,
77119 - (struct compat_iovec __user *)kern_msg->msg_iov,
77120 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
77121 kern_msg->msg_iovlen);
77122 if (tot_len >= 0)
77123 kern_msg->msg_iov = kern_iov;
77124 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
77125
77126 #define CMSG_COMPAT_FIRSTHDR(msg) \
77127 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
77128 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
77129 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
77130 (struct compat_cmsghdr __user *)NULL)
77131
77132 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
77133 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
77134 (ucmlen) <= (unsigned long) \
77135 ((mhdr)->msg_controllen - \
77136 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
77137 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
77138
77139 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
77140 struct compat_cmsghdr __user *cmsg, int cmsg_len)
77141 {
77142 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
77143 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
77144 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
77145 msg->msg_controllen)
77146 return NULL;
77147 return (struct compat_cmsghdr __user *)ptr;
77148 @@ -219,7 +219,7 @@ Efault:
77149
77150 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
77151 {
77152 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
77153 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
77154 struct compat_cmsghdr cmhdr;
77155 struct compat_timeval ctv;
77156 struct compat_timespec cts[3];
77157 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
77158
77159 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
77160 {
77161 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
77162 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
77163 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
77164 int fdnum = scm->fp->count;
77165 struct file **fp = scm->fp->fp;
77166 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
77167 return -EFAULT;
77168 old_fs = get_fs();
77169 set_fs(KERNEL_DS);
77170 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
77171 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
77172 set_fs(old_fs);
77173
77174 return err;
77175 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
77176 len = sizeof(ktime);
77177 old_fs = get_fs();
77178 set_fs(KERNEL_DS);
77179 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
77180 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
77181 set_fs(old_fs);
77182
77183 if (!err) {
77184 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77185 case MCAST_JOIN_GROUP:
77186 case MCAST_LEAVE_GROUP:
77187 {
77188 - struct compat_group_req __user *gr32 = (void *)optval;
77189 + struct compat_group_req __user *gr32 = (void __user *)optval;
77190 struct group_req __user *kgr =
77191 compat_alloc_user_space(sizeof(struct group_req));
77192 u32 interface;
77193 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77194 case MCAST_BLOCK_SOURCE:
77195 case MCAST_UNBLOCK_SOURCE:
77196 {
77197 - struct compat_group_source_req __user *gsr32 = (void *)optval;
77198 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
77199 struct group_source_req __user *kgsr = compat_alloc_user_space(
77200 sizeof(struct group_source_req));
77201 u32 interface;
77202 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77203 }
77204 case MCAST_MSFILTER:
77205 {
77206 - struct compat_group_filter __user *gf32 = (void *)optval;
77207 + struct compat_group_filter __user *gf32 = (void __user *)optval;
77208 struct group_filter __user *kgf;
77209 u32 interface, fmode, numsrc;
77210
77211 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
77212 char __user *optval, int __user *optlen,
77213 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
77214 {
77215 - struct compat_group_filter __user *gf32 = (void *)optval;
77216 + struct compat_group_filter __user *gf32 = (void __user *)optval;
77217 struct group_filter __user *kgf;
77218 int __user *koptlen;
77219 u32 interface, fmode, numsrc;
77220 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
77221
77222 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
77223 return -EINVAL;
77224 - if (copy_from_user(a, args, nas[call]))
77225 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
77226 return -EFAULT;
77227 a0 = a[0];
77228 a1 = a[1];
77229 diff --git a/net/core/datagram.c b/net/core/datagram.c
77230 index 0337e2b..47914a0 100644
77231 --- a/net/core/datagram.c
77232 +++ b/net/core/datagram.c
77233 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
77234 }
77235
77236 kfree_skb(skb);
77237 - atomic_inc(&sk->sk_drops);
77238 + atomic_inc_unchecked(&sk->sk_drops);
77239 sk_mem_reclaim_partial(sk);
77240
77241 return err;
77242 diff --git a/net/core/dev.c b/net/core/dev.c
77243 index 1dce5b5..363a522 100644
77244 --- a/net/core/dev.c
77245 +++ b/net/core/dev.c
77246 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
77247 if (no_module && capable(CAP_NET_ADMIN))
77248 no_module = request_module("netdev-%s", name);
77249 if (no_module && capable(CAP_SYS_MODULE)) {
77250 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
77251 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
77252 +#else
77253 if (!request_module("%s", name))
77254 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
77255 name);
77256 +#endif
77257 }
77258 }
77259 EXPORT_SYMBOL(dev_load);
77260 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
77261 {
77262 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
77263 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
77264 - atomic_long_inc(&dev->rx_dropped);
77265 + atomic_long_inc_unchecked(&dev->rx_dropped);
77266 kfree_skb(skb);
77267 return NET_RX_DROP;
77268 }
77269 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
77270 nf_reset(skb);
77271
77272 if (unlikely(!is_skb_forwardable(dev, skb))) {
77273 - atomic_long_inc(&dev->rx_dropped);
77274 + atomic_long_inc_unchecked(&dev->rx_dropped);
77275 kfree_skb(skb);
77276 return NET_RX_DROP;
77277 }
77278 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
77279
77280 struct dev_gso_cb {
77281 void (*destructor)(struct sk_buff *skb);
77282 -};
77283 +} __no_const;
77284
77285 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
77286
77287 @@ -2930,7 +2934,7 @@ enqueue:
77288
77289 local_irq_restore(flags);
77290
77291 - atomic_long_inc(&skb->dev->rx_dropped);
77292 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
77293 kfree_skb(skb);
77294 return NET_RX_DROP;
77295 }
77296 @@ -3002,7 +3006,7 @@ int netif_rx_ni(struct sk_buff *skb)
77297 }
77298 EXPORT_SYMBOL(netif_rx_ni);
77299
77300 -static void net_tx_action(struct softirq_action *h)
77301 +static void net_tx_action(void)
77302 {
77303 struct softnet_data *sd = &__get_cpu_var(softnet_data);
77304
77305 @@ -3333,7 +3337,7 @@ ncls:
77306 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
77307 } else {
77308 drop:
77309 - atomic_long_inc(&skb->dev->rx_dropped);
77310 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
77311 kfree_skb(skb);
77312 /* Jamal, now you will not able to escape explaining
77313 * me how you were going to use this. :-)
77314 @@ -3900,7 +3904,7 @@ void netif_napi_del(struct napi_struct *napi)
77315 }
77316 EXPORT_SYMBOL(netif_napi_del);
77317
77318 -static void net_rx_action(struct softirq_action *h)
77319 +static void net_rx_action(void)
77320 {
77321 struct softnet_data *sd = &__get_cpu_var(softnet_data);
77322 unsigned long time_limit = jiffies + 2;
77323 @@ -4370,8 +4374,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
77324 else
77325 seq_printf(seq, "%04x", ntohs(pt->type));
77326
77327 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77328 + seq_printf(seq, " %-8s %p\n",
77329 + pt->dev ? pt->dev->name : "", NULL);
77330 +#else
77331 seq_printf(seq, " %-8s %pF\n",
77332 pt->dev ? pt->dev->name : "", pt->func);
77333 +#endif
77334 }
77335
77336 return 0;
77337 @@ -5924,7 +5933,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
77338 } else {
77339 netdev_stats_to_stats64(storage, &dev->stats);
77340 }
77341 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
77342 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
77343 return storage;
77344 }
77345 EXPORT_SYMBOL(dev_get_stats);
77346 diff --git a/net/core/flow.c b/net/core/flow.c
77347 index e318c7e..168b1d0 100644
77348 --- a/net/core/flow.c
77349 +++ b/net/core/flow.c
77350 @@ -61,7 +61,7 @@ struct flow_cache {
77351 struct timer_list rnd_timer;
77352 };
77353
77354 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
77355 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
77356 EXPORT_SYMBOL(flow_cache_genid);
77357 static struct flow_cache flow_cache_global;
77358 static struct kmem_cache *flow_cachep __read_mostly;
77359 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
77360
77361 static int flow_entry_valid(struct flow_cache_entry *fle)
77362 {
77363 - if (atomic_read(&flow_cache_genid) != fle->genid)
77364 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
77365 return 0;
77366 if (fle->object && !fle->object->ops->check(fle->object))
77367 return 0;
77368 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
77369 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
77370 fcp->hash_count++;
77371 }
77372 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
77373 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
77374 flo = fle->object;
77375 if (!flo)
77376 goto ret_object;
77377 @@ -280,7 +280,7 @@ nocache:
77378 }
77379 flo = resolver(net, key, family, dir, flo, ctx);
77380 if (fle) {
77381 - fle->genid = atomic_read(&flow_cache_genid);
77382 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
77383 if (!IS_ERR(flo))
77384 fle->object = flo;
77385 else
77386 diff --git a/net/core/iovec.c b/net/core/iovec.c
77387 index 7e7aeb0..2a998cb 100644
77388 --- a/net/core/iovec.c
77389 +++ b/net/core/iovec.c
77390 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77391 if (m->msg_namelen) {
77392 if (mode == VERIFY_READ) {
77393 void __user *namep;
77394 - namep = (void __user __force *) m->msg_name;
77395 + namep = (void __force_user *) m->msg_name;
77396 err = move_addr_to_kernel(namep, m->msg_namelen,
77397 address);
77398 if (err < 0)
77399 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77400 }
77401
77402 size = m->msg_iovlen * sizeof(struct iovec);
77403 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
77404 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
77405 return -EFAULT;
77406
77407 m->msg_iov = iov;
77408 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
77409 index 2c5a0a0..a45f90c 100644
77410 --- a/net/core/rtnetlink.c
77411 +++ b/net/core/rtnetlink.c
77412 @@ -58,7 +58,7 @@ struct rtnl_link {
77413 rtnl_doit_func doit;
77414 rtnl_dumpit_func dumpit;
77415 rtnl_calcit_func calcit;
77416 -};
77417 +} __no_const;
77418
77419 static DEFINE_MUTEX(rtnl_mutex);
77420
77421 diff --git a/net/core/scm.c b/net/core/scm.c
77422 index 040cebe..5b1e312 100644
77423 --- a/net/core/scm.c
77424 +++ b/net/core/scm.c
77425 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
77426 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77427 {
77428 struct cmsghdr __user *cm
77429 - = (__force struct cmsghdr __user *)msg->msg_control;
77430 + = (struct cmsghdr __force_user *)msg->msg_control;
77431 struct cmsghdr cmhdr;
77432 int cmlen = CMSG_LEN(len);
77433 int err;
77434 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77435 err = -EFAULT;
77436 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
77437 goto out;
77438 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
77439 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
77440 goto out;
77441 cmlen = CMSG_SPACE(len);
77442 if (msg->msg_controllen < cmlen)
77443 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
77444 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77445 {
77446 struct cmsghdr __user *cm
77447 - = (__force struct cmsghdr __user*)msg->msg_control;
77448 + = (struct cmsghdr __force_user *)msg->msg_control;
77449
77450 int fdmax = 0;
77451 int fdnum = scm->fp->count;
77452 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77453 if (fdnum < fdmax)
77454 fdmax = fdnum;
77455
77456 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
77457 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
77458 i++, cmfptr++)
77459 {
77460 struct socket *sock;
77461 diff --git a/net/core/sock.c b/net/core/sock.c
77462 index a6000fb..d4aee72 100644
77463 --- a/net/core/sock.c
77464 +++ b/net/core/sock.c
77465 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77466 struct sk_buff_head *list = &sk->sk_receive_queue;
77467
77468 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
77469 - atomic_inc(&sk->sk_drops);
77470 + atomic_inc_unchecked(&sk->sk_drops);
77471 trace_sock_rcvqueue_full(sk, skb);
77472 return -ENOMEM;
77473 }
77474 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77475 return err;
77476
77477 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
77478 - atomic_inc(&sk->sk_drops);
77479 + atomic_inc_unchecked(&sk->sk_drops);
77480 return -ENOBUFS;
77481 }
77482
77483 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77484 skb_dst_force(skb);
77485
77486 spin_lock_irqsave(&list->lock, flags);
77487 - skb->dropcount = atomic_read(&sk->sk_drops);
77488 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77489 __skb_queue_tail(list, skb);
77490 spin_unlock_irqrestore(&list->lock, flags);
77491
77492 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77493 skb->dev = NULL;
77494
77495 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
77496 - atomic_inc(&sk->sk_drops);
77497 + atomic_inc_unchecked(&sk->sk_drops);
77498 goto discard_and_relse;
77499 }
77500 if (nested)
77501 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77502 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
77503 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
77504 bh_unlock_sock(sk);
77505 - atomic_inc(&sk->sk_drops);
77506 + atomic_inc_unchecked(&sk->sk_drops);
77507 goto discard_and_relse;
77508 }
77509
77510 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77511 struct timeval tm;
77512 } v;
77513
77514 - int lv = sizeof(int);
77515 - int len;
77516 + unsigned int lv = sizeof(int);
77517 + unsigned int len;
77518
77519 if (get_user(len, optlen))
77520 return -EFAULT;
77521 - if (len < 0)
77522 + if (len > INT_MAX)
77523 return -EINVAL;
77524
77525 memset(&v, 0, sizeof(v));
77526 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77527
77528 case SO_PEERNAME:
77529 {
77530 - char address[128];
77531 + char address[_K_SS_MAXSIZE];
77532
77533 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
77534 return -ENOTCONN;
77535 - if (lv < len)
77536 + if (lv < len || sizeof address < len)
77537 return -EINVAL;
77538 if (copy_to_user(optval, address, len))
77539 return -EFAULT;
77540 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77541
77542 if (len > lv)
77543 len = lv;
77544 - if (copy_to_user(optval, &v, len))
77545 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
77546 return -EFAULT;
77547 lenout:
77548 if (put_user(len, optlen))
77549 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
77550 */
77551 smp_wmb();
77552 atomic_set(&sk->sk_refcnt, 1);
77553 - atomic_set(&sk->sk_drops, 0);
77554 + atomic_set_unchecked(&sk->sk_drops, 0);
77555 }
77556 EXPORT_SYMBOL(sock_init_data);
77557
77558 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
77559 index 9d8755e..26de8bc 100644
77560 --- a/net/core/sock_diag.c
77561 +++ b/net/core/sock_diag.c
77562 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
77563
77564 int sock_diag_check_cookie(void *sk, __u32 *cookie)
77565 {
77566 +#ifndef CONFIG_GRKERNSEC_HIDESYM
77567 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
77568 cookie[1] != INET_DIAG_NOCOOKIE) &&
77569 ((u32)(unsigned long)sk != cookie[0] ||
77570 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
77571 return -ESTALE;
77572 else
77573 +#endif
77574 return 0;
77575 }
77576 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
77577
77578 void sock_diag_save_cookie(void *sk, __u32 *cookie)
77579 {
77580 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77581 + cookie[0] = 0;
77582 + cookie[1] = 0;
77583 +#else
77584 cookie[0] = (u32)(unsigned long)sk;
77585 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
77586 +#endif
77587 }
77588 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
77589
77590 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
77591 index a55eecc..dd8428c 100644
77592 --- a/net/decnet/sysctl_net_decnet.c
77593 +++ b/net/decnet/sysctl_net_decnet.c
77594 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
77595
77596 if (len > *lenp) len = *lenp;
77597
77598 - if (copy_to_user(buffer, addr, len))
77599 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
77600 return -EFAULT;
77601
77602 *lenp = len;
77603 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
77604
77605 if (len > *lenp) len = *lenp;
77606
77607 - if (copy_to_user(buffer, devname, len))
77608 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
77609 return -EFAULT;
77610
77611 *lenp = len;
77612 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
77613 index f444ac7..b7bdda9 100644
77614 --- a/net/ipv4/fib_frontend.c
77615 +++ b/net/ipv4/fib_frontend.c
77616 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
77617 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77618 fib_sync_up(dev);
77619 #endif
77620 - atomic_inc(&net->ipv4.dev_addr_genid);
77621 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77622 rt_cache_flush(dev_net(dev));
77623 break;
77624 case NETDEV_DOWN:
77625 fib_del_ifaddr(ifa, NULL);
77626 - atomic_inc(&net->ipv4.dev_addr_genid);
77627 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77628 if (ifa->ifa_dev->ifa_list == NULL) {
77629 /* Last address was deleted from this interface.
77630 * Disable IP.
77631 @@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
77632 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77633 fib_sync_up(dev);
77634 #endif
77635 - atomic_inc(&net->ipv4.dev_addr_genid);
77636 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77637 rt_cache_flush(dev_net(dev));
77638 break;
77639 case NETDEV_DOWN:
77640 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
77641 index 9633661..4e0bc08 100644
77642 --- a/net/ipv4/fib_semantics.c
77643 +++ b/net/ipv4/fib_semantics.c
77644 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
77645 nh->nh_saddr = inet_select_addr(nh->nh_dev,
77646 nh->nh_gw,
77647 nh->nh_parent->fib_scope);
77648 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
77649 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
77650
77651 return nh->nh_saddr;
77652 }
77653 diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
77654 index f2eccd5..17ff9fd 100644
77655 --- a/net/ipv4/icmp.c
77656 +++ b/net/ipv4/icmp.c
77657 @@ -257,7 +257,8 @@ static inline bool icmpv4_xrlim_allow(struct net *net, struct rtable *rt,
77658 struct inet_peer *peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, 1);
77659 rc = inet_peer_xrlim_allow(peer,
77660 net->ipv4.sysctl_icmp_ratelimit);
77661 - inet_putpeer(peer);
77662 + if (peer)
77663 + inet_putpeer(peer);
77664 }
77665 out:
77666 return rc;
77667 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
77668 index 7880af9..70f92a3 100644
77669 --- a/net/ipv4/inet_hashtables.c
77670 +++ b/net/ipv4/inet_hashtables.c
77671 @@ -18,12 +18,15 @@
77672 #include <linux/sched.h>
77673 #include <linux/slab.h>
77674 #include <linux/wait.h>
77675 +#include <linux/security.h>
77676
77677 #include <net/inet_connection_sock.h>
77678 #include <net/inet_hashtables.h>
77679 #include <net/secure_seq.h>
77680 #include <net/ip.h>
77681
77682 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
77683 +
77684 /*
77685 * Allocate and initialize a new local port bind bucket.
77686 * The bindhash mutex for snum's hash chain must be held here.
77687 @@ -530,6 +533,8 @@ ok:
77688 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77689 spin_unlock(&head->lock);
77690
77691 + gr_update_task_in_ip_table(current, inet_sk(sk));
77692 +
77693 if (tw) {
77694 inet_twsk_deschedule(tw, death_row);
77695 while (twrefcnt) {
77696 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77697 index c7527f6..d8bba61 100644
77698 --- a/net/ipv4/inetpeer.c
77699 +++ b/net/ipv4/inetpeer.c
77700 @@ -503,8 +503,8 @@ relookup:
77701 if (p) {
77702 p->daddr = *daddr;
77703 atomic_set(&p->refcnt, 1);
77704 - atomic_set(&p->rid, 0);
77705 - atomic_set(&p->ip_id_count,
77706 + atomic_set_unchecked(&p->rid, 0);
77707 + atomic_set_unchecked(&p->ip_id_count,
77708 (daddr->family == AF_INET) ?
77709 secure_ip_id(daddr->addr.a4) :
77710 secure_ipv6_id(daddr->addr.a6));
77711 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77712 index 8d07c97..d0812ef 100644
77713 --- a/net/ipv4/ip_fragment.c
77714 +++ b/net/ipv4/ip_fragment.c
77715 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77716 return 0;
77717
77718 start = qp->rid;
77719 - end = atomic_inc_return(&peer->rid);
77720 + end = atomic_inc_return_unchecked(&peer->rid);
77721 qp->rid = end;
77722
77723 rc = qp->q.fragments && (end - start) > max;
77724 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77725 index 14bbfcf..644f472 100644
77726 --- a/net/ipv4/ip_sockglue.c
77727 +++ b/net/ipv4/ip_sockglue.c
77728 @@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77729 len = min_t(unsigned int, len, opt->optlen);
77730 if (put_user(len, optlen))
77731 return -EFAULT;
77732 - if (copy_to_user(optval, opt->__data, len))
77733 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77734 + copy_to_user(optval, opt->__data, len))
77735 return -EFAULT;
77736 return 0;
77737 }
77738 @@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77739 if (sk->sk_type != SOCK_STREAM)
77740 return -ENOPROTOOPT;
77741
77742 - msg.msg_control = optval;
77743 + msg.msg_control = (void __force_kernel *)optval;
77744 msg.msg_controllen = len;
77745 msg.msg_flags = flags;
77746
77747 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77748 index 67e8a6b..386764d 100644
77749 --- a/net/ipv4/ipconfig.c
77750 +++ b/net/ipv4/ipconfig.c
77751 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77752
77753 mm_segment_t oldfs = get_fs();
77754 set_fs(get_ds());
77755 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77756 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77757 set_fs(oldfs);
77758 return res;
77759 }
77760 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77761
77762 mm_segment_t oldfs = get_fs();
77763 set_fs(get_ds());
77764 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77765 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77766 set_fs(oldfs);
77767 return res;
77768 }
77769 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77770
77771 mm_segment_t oldfs = get_fs();
77772 set_fs(get_ds());
77773 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77774 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77775 set_fs(oldfs);
77776 return res;
77777 }
77778 diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
77779 index ebdf06f..f797f59 100644
77780 --- a/net/ipv4/ipmr.c
77781 +++ b/net/ipv4/ipmr.c
77782 @@ -1318,6 +1318,10 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
77783 if (get_user(v, (u32 __user *)optval))
77784 return -EFAULT;
77785
77786 + /* "pimreg%u" should not exceed 16 bytes (IFNAMSIZ) */
77787 + if (v != RT_TABLE_DEFAULT && v >= 1000000000)
77788 + return -EINVAL;
77789 +
77790 rtnl_lock();
77791 ret = 0;
77792 if (sk == rtnl_dereference(mrt->mroute_sk)) {
77793 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77794 index 97e61ea..cac1bbb 100644
77795 --- a/net/ipv4/netfilter/arp_tables.c
77796 +++ b/net/ipv4/netfilter/arp_tables.c
77797 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77798 #endif
77799
77800 static int get_info(struct net *net, void __user *user,
77801 - const int *len, int compat)
77802 + int len, int compat)
77803 {
77804 char name[XT_TABLE_MAXNAMELEN];
77805 struct xt_table *t;
77806 int ret;
77807
77808 - if (*len != sizeof(struct arpt_getinfo)) {
77809 - duprintf("length %u != %Zu\n", *len,
77810 + if (len != sizeof(struct arpt_getinfo)) {
77811 + duprintf("length %u != %Zu\n", len,
77812 sizeof(struct arpt_getinfo));
77813 return -EINVAL;
77814 }
77815 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77816 info.size = private->size;
77817 strcpy(info.name, name);
77818
77819 - if (copy_to_user(user, &info, *len) != 0)
77820 + if (copy_to_user(user, &info, len) != 0)
77821 ret = -EFAULT;
77822 else
77823 ret = 0;
77824 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77825
77826 switch (cmd) {
77827 case ARPT_SO_GET_INFO:
77828 - ret = get_info(sock_net(sk), user, len, 1);
77829 + ret = get_info(sock_net(sk), user, *len, 1);
77830 break;
77831 case ARPT_SO_GET_ENTRIES:
77832 ret = compat_get_entries(sock_net(sk), user, len);
77833 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77834
77835 switch (cmd) {
77836 case ARPT_SO_GET_INFO:
77837 - ret = get_info(sock_net(sk), user, len, 0);
77838 + ret = get_info(sock_net(sk), user, *len, 0);
77839 break;
77840
77841 case ARPT_SO_GET_ENTRIES:
77842 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77843 index 170b1fd..6105b91 100644
77844 --- a/net/ipv4/netfilter/ip_tables.c
77845 +++ b/net/ipv4/netfilter/ip_tables.c
77846 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77847 #endif
77848
77849 static int get_info(struct net *net, void __user *user,
77850 - const int *len, int compat)
77851 + int len, int compat)
77852 {
77853 char name[XT_TABLE_MAXNAMELEN];
77854 struct xt_table *t;
77855 int ret;
77856
77857 - if (*len != sizeof(struct ipt_getinfo)) {
77858 - duprintf("length %u != %zu\n", *len,
77859 + if (len != sizeof(struct ipt_getinfo)) {
77860 + duprintf("length %u != %zu\n", len,
77861 sizeof(struct ipt_getinfo));
77862 return -EINVAL;
77863 }
77864 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77865 info.size = private->size;
77866 strcpy(info.name, name);
77867
77868 - if (copy_to_user(user, &info, *len) != 0)
77869 + if (copy_to_user(user, &info, len) != 0)
77870 ret = -EFAULT;
77871 else
77872 ret = 0;
77873 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77874
77875 switch (cmd) {
77876 case IPT_SO_GET_INFO:
77877 - ret = get_info(sock_net(sk), user, len, 1);
77878 + ret = get_info(sock_net(sk), user, *len, 1);
77879 break;
77880 case IPT_SO_GET_ENTRIES:
77881 ret = compat_get_entries(sock_net(sk), user, len);
77882 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77883
77884 switch (cmd) {
77885 case IPT_SO_GET_INFO:
77886 - ret = get_info(sock_net(sk), user, len, 0);
77887 + ret = get_info(sock_net(sk), user, *len, 0);
77888 break;
77889
77890 case IPT_SO_GET_ENTRIES:
77891 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77892 index 6232d47..6b88607 100644
77893 --- a/net/ipv4/ping.c
77894 +++ b/net/ipv4/ping.c
77895 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77896 sk_rmem_alloc_get(sp),
77897 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77898 atomic_read(&sp->sk_refcnt), sp,
77899 - atomic_read(&sp->sk_drops), len);
77900 + atomic_read_unchecked(&sp->sk_drops), len);
77901 }
77902
77903 static int ping_seq_show(struct seq_file *seq, void *v)
77904 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77905 index d23c657..cb69cc2 100644
77906 --- a/net/ipv4/raw.c
77907 +++ b/net/ipv4/raw.c
77908 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77909 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77910 {
77911 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77912 - atomic_inc(&sk->sk_drops);
77913 + atomic_inc_unchecked(&sk->sk_drops);
77914 kfree_skb(skb);
77915 return NET_RX_DROP;
77916 }
77917 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77918
77919 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77920 {
77921 + struct icmp_filter filter;
77922 +
77923 if (optlen > sizeof(struct icmp_filter))
77924 optlen = sizeof(struct icmp_filter);
77925 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77926 + if (copy_from_user(&filter, optval, optlen))
77927 return -EFAULT;
77928 + raw_sk(sk)->filter = filter;
77929 return 0;
77930 }
77931
77932 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77933 {
77934 int len, ret = -EFAULT;
77935 + struct icmp_filter filter;
77936
77937 if (get_user(len, optlen))
77938 goto out;
77939 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77940 if (len > sizeof(struct icmp_filter))
77941 len = sizeof(struct icmp_filter);
77942 ret = -EFAULT;
77943 - if (put_user(len, optlen) ||
77944 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77945 + filter = raw_sk(sk)->filter;
77946 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77947 goto out;
77948 ret = 0;
77949 out: return ret;
77950 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77951 sk_wmem_alloc_get(sp),
77952 sk_rmem_alloc_get(sp),
77953 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77954 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77955 + atomic_read(&sp->sk_refcnt),
77956 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77957 + NULL,
77958 +#else
77959 + sp,
77960 +#endif
77961 + atomic_read_unchecked(&sp->sk_drops));
77962 }
77963
77964 static int raw_seq_show(struct seq_file *seq, void *v)
77965 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77966 index c017cb1..9eb15b7d 100644
77967 --- a/net/ipv4/route.c
77968 +++ b/net/ipv4/route.c
77969 @@ -2526,7 +2526,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77970
77971 static __net_init int rt_genid_init(struct net *net)
77972 {
77973 - atomic_set(&net->rt_genid, 0);
77974 + atomic_set_unchecked(&net->rt_genid, 0);
77975 get_random_bytes(&net->ipv4.dev_addr_genid,
77976 sizeof(net->ipv4.dev_addr_genid));
77977 return 0;
77978 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77979 index c92c4da..f19e3ec 100644
77980 --- a/net/ipv4/tcp_input.c
77981 +++ b/net/ipv4/tcp_input.c
77982 @@ -4731,7 +4731,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77983 * simplifies code)
77984 */
77985 static void
77986 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77987 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77988 struct sk_buff *head, struct sk_buff *tail,
77989 u32 start, u32 end)
77990 {
77991 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77992 index db7bfad..bfea796 100644
77993 --- a/net/ipv4/tcp_ipv4.c
77994 +++ b/net/ipv4/tcp_ipv4.c
77995 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77996 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77997
77998
77999 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78000 +extern int grsec_enable_blackhole;
78001 +#endif
78002 +
78003 #ifdef CONFIG_TCP_MD5SIG
78004 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
78005 __be32 daddr, __be32 saddr, const struct tcphdr *th);
78006 @@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
78007 return 0;
78008
78009 reset:
78010 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78011 + if (!grsec_enable_blackhole)
78012 +#endif
78013 tcp_v4_send_reset(rsk, skb);
78014 discard:
78015 kfree_skb(skb);
78016 @@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
78017 TCP_SKB_CB(skb)->sacked = 0;
78018
78019 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
78020 - if (!sk)
78021 + if (!sk) {
78022 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78023 + ret = 1;
78024 +#endif
78025 goto no_tcp_socket;
78026 -
78027 + }
78028 process:
78029 - if (sk->sk_state == TCP_TIME_WAIT)
78030 + if (sk->sk_state == TCP_TIME_WAIT) {
78031 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78032 + ret = 2;
78033 +#endif
78034 goto do_time_wait;
78035 + }
78036
78037 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
78038 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
78039 @@ -1820,6 +1834,10 @@ no_tcp_socket:
78040 bad_packet:
78041 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
78042 } else {
78043 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78044 + if (!grsec_enable_blackhole || (ret == 1 &&
78045 + (skb->dev->flags & IFF_LOOPBACK)))
78046 +#endif
78047 tcp_v4_send_reset(NULL, skb);
78048 }
78049
78050 @@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
78051 0, /* non standard timer */
78052 0, /* open_requests have no inode */
78053 atomic_read(&sk->sk_refcnt),
78054 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78055 + NULL,
78056 +#else
78057 req,
78058 +#endif
78059 len);
78060 }
78061
78062 @@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
78063 sock_i_uid(sk),
78064 icsk->icsk_probes_out,
78065 sock_i_ino(sk),
78066 - atomic_read(&sk->sk_refcnt), sk,
78067 + atomic_read(&sk->sk_refcnt),
78068 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78069 + NULL,
78070 +#else
78071 + sk,
78072 +#endif
78073 jiffies_to_clock_t(icsk->icsk_rto),
78074 jiffies_to_clock_t(icsk->icsk_ack.ato),
78075 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
78076 @@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
78077 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
78078 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
78079 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
78080 - atomic_read(&tw->tw_refcnt), tw, len);
78081 + atomic_read(&tw->tw_refcnt),
78082 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78083 + NULL,
78084 +#else
78085 + tw,
78086 +#endif
78087 + len);
78088 }
78089
78090 #define TMPSZ 150
78091 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
78092 index 6ff7f10..38de56e 100644
78093 --- a/net/ipv4/tcp_minisocks.c
78094 +++ b/net/ipv4/tcp_minisocks.c
78095 @@ -27,6 +27,10 @@
78096 #include <net/inet_common.h>
78097 #include <net/xfrm.h>
78098
78099 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78100 +extern int grsec_enable_blackhole;
78101 +#endif
78102 +
78103 int sysctl_tcp_syncookies __read_mostly = 1;
78104 EXPORT_SYMBOL(sysctl_tcp_syncookies);
78105
78106 @@ -707,6 +711,10 @@ listen_overflow:
78107
78108 embryonic_reset:
78109 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
78110 +
78111 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78112 + if (!grsec_enable_blackhole)
78113 +#endif
78114 if (!(flg & TCP_FLAG_RST))
78115 req->rsk_ops->send_reset(sk, skb);
78116
78117 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
78118 index 4526fe6..1a34e43 100644
78119 --- a/net/ipv4/tcp_probe.c
78120 +++ b/net/ipv4/tcp_probe.c
78121 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
78122 if (cnt + width >= len)
78123 break;
78124
78125 - if (copy_to_user(buf + cnt, tbuf, width))
78126 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
78127 return -EFAULT;
78128 cnt += width;
78129 }
78130 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
78131 index b774a03..3873efe 100644
78132 --- a/net/ipv4/tcp_timer.c
78133 +++ b/net/ipv4/tcp_timer.c
78134 @@ -22,6 +22,10 @@
78135 #include <linux/gfp.h>
78136 #include <net/tcp.h>
78137
78138 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78139 +extern int grsec_lastack_retries;
78140 +#endif
78141 +
78142 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
78143 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
78144 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
78145 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
78146 }
78147 }
78148
78149 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78150 + if ((sk->sk_state == TCP_LAST_ACK) &&
78151 + (grsec_lastack_retries > 0) &&
78152 + (grsec_lastack_retries < retry_until))
78153 + retry_until = grsec_lastack_retries;
78154 +#endif
78155 +
78156 if (retransmits_timed_out(sk, retry_until,
78157 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
78158 /* Has it gone just too far? */
78159 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
78160 index 2814f66..fa2b223 100644
78161 --- a/net/ipv4/udp.c
78162 +++ b/net/ipv4/udp.c
78163 @@ -87,6 +87,7 @@
78164 #include <linux/types.h>
78165 #include <linux/fcntl.h>
78166 #include <linux/module.h>
78167 +#include <linux/security.h>
78168 #include <linux/socket.h>
78169 #include <linux/sockios.h>
78170 #include <linux/igmp.h>
78171 @@ -111,6 +112,10 @@
78172 #include <trace/events/skb.h>
78173 #include "udp_impl.h"
78174
78175 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78176 +extern int grsec_enable_blackhole;
78177 +#endif
78178 +
78179 struct udp_table udp_table __read_mostly;
78180 EXPORT_SYMBOL(udp_table);
78181
78182 @@ -569,6 +574,9 @@ found:
78183 return s;
78184 }
78185
78186 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
78187 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
78188 +
78189 /*
78190 * This routine is called by the ICMP module when it gets some
78191 * sort of error condition. If err < 0 then the socket should
78192 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
78193 dport = usin->sin_port;
78194 if (dport == 0)
78195 return -EINVAL;
78196 +
78197 + err = gr_search_udp_sendmsg(sk, usin);
78198 + if (err)
78199 + return err;
78200 } else {
78201 if (sk->sk_state != TCP_ESTABLISHED)
78202 return -EDESTADDRREQ;
78203 +
78204 + err = gr_search_udp_sendmsg(sk, NULL);
78205 + if (err)
78206 + return err;
78207 +
78208 daddr = inet->inet_daddr;
78209 dport = inet->inet_dport;
78210 /* Open fast path for connected socket.
78211 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
78212 udp_lib_checksum_complete(skb)) {
78213 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78214 IS_UDPLITE(sk));
78215 - atomic_inc(&sk->sk_drops);
78216 + atomic_inc_unchecked(&sk->sk_drops);
78217 __skb_unlink(skb, rcvq);
78218 __skb_queue_tail(&list_kill, skb);
78219 }
78220 @@ -1194,6 +1211,10 @@ try_again:
78221 if (!skb)
78222 goto out;
78223
78224 + err = gr_search_udp_recvmsg(sk, skb);
78225 + if (err)
78226 + goto out_free;
78227 +
78228 ulen = skb->len - sizeof(struct udphdr);
78229 copied = len;
78230 if (copied > ulen)
78231 @@ -1227,7 +1248,7 @@ try_again:
78232 if (unlikely(err)) {
78233 trace_kfree_skb(skb, udp_recvmsg);
78234 if (!peeked) {
78235 - atomic_inc(&sk->sk_drops);
78236 + atomic_inc_unchecked(&sk->sk_drops);
78237 UDP_INC_STATS_USER(sock_net(sk),
78238 UDP_MIB_INERRORS, is_udplite);
78239 }
78240 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78241
78242 drop:
78243 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78244 - atomic_inc(&sk->sk_drops);
78245 + atomic_inc_unchecked(&sk->sk_drops);
78246 kfree_skb(skb);
78247 return -1;
78248 }
78249 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78250 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78251
78252 if (!skb1) {
78253 - atomic_inc(&sk->sk_drops);
78254 + atomic_inc_unchecked(&sk->sk_drops);
78255 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78256 IS_UDPLITE(sk));
78257 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78258 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78259 goto csum_error;
78260
78261 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78262 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78263 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78264 +#endif
78265 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
78266
78267 /*
78268 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
78269 sk_wmem_alloc_get(sp),
78270 sk_rmem_alloc_get(sp),
78271 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
78272 - atomic_read(&sp->sk_refcnt), sp,
78273 - atomic_read(&sp->sk_drops), len);
78274 + atomic_read(&sp->sk_refcnt),
78275 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78276 + NULL,
78277 +#else
78278 + sp,
78279 +#endif
78280 + atomic_read_unchecked(&sp->sk_drops), len);
78281 }
78282
78283 int udp4_seq_show(struct seq_file *seq, void *v)
78284 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
78285 index b10374d..0baa1f9 100644
78286 --- a/net/ipv6/addrconf.c
78287 +++ b/net/ipv6/addrconf.c
78288 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
78289 p.iph.ihl = 5;
78290 p.iph.protocol = IPPROTO_IPV6;
78291 p.iph.ttl = 64;
78292 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
78293 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
78294
78295 if (ops->ndo_do_ioctl) {
78296 mm_segment_t oldfs = get_fs();
78297 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
78298 index e02faed..9780f28 100644
78299 --- a/net/ipv6/ipv6_sockglue.c
78300 +++ b/net/ipv6/ipv6_sockglue.c
78301 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
78302 if (sk->sk_type != SOCK_STREAM)
78303 return -ENOPROTOOPT;
78304
78305 - msg.msg_control = optval;
78306 + msg.msg_control = (void __force_kernel *)optval;
78307 msg.msg_controllen = len;
78308 msg.msg_flags = flags;
78309
78310 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
78311 index d7cb045..8c0ded6 100644
78312 --- a/net/ipv6/netfilter/ip6_tables.c
78313 +++ b/net/ipv6/netfilter/ip6_tables.c
78314 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
78315 #endif
78316
78317 static int get_info(struct net *net, void __user *user,
78318 - const int *len, int compat)
78319 + int len, int compat)
78320 {
78321 char name[XT_TABLE_MAXNAMELEN];
78322 struct xt_table *t;
78323 int ret;
78324
78325 - if (*len != sizeof(struct ip6t_getinfo)) {
78326 - duprintf("length %u != %zu\n", *len,
78327 + if (len != sizeof(struct ip6t_getinfo)) {
78328 + duprintf("length %u != %zu\n", len,
78329 sizeof(struct ip6t_getinfo));
78330 return -EINVAL;
78331 }
78332 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
78333 info.size = private->size;
78334 strcpy(info.name, name);
78335
78336 - if (copy_to_user(user, &info, *len) != 0)
78337 + if (copy_to_user(user, &info, len) != 0)
78338 ret = -EFAULT;
78339 else
78340 ret = 0;
78341 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78342
78343 switch (cmd) {
78344 case IP6T_SO_GET_INFO:
78345 - ret = get_info(sock_net(sk), user, len, 1);
78346 + ret = get_info(sock_net(sk), user, *len, 1);
78347 break;
78348 case IP6T_SO_GET_ENTRIES:
78349 ret = compat_get_entries(sock_net(sk), user, len);
78350 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78351
78352 switch (cmd) {
78353 case IP6T_SO_GET_INFO:
78354 - ret = get_info(sock_net(sk), user, len, 0);
78355 + ret = get_info(sock_net(sk), user, *len, 0);
78356 break;
78357
78358 case IP6T_SO_GET_ENTRIES:
78359 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
78360 index 4a5f78b..3f22ebe 100644
78361 --- a/net/ipv6/raw.c
78362 +++ b/net/ipv6/raw.c
78363 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
78364 {
78365 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
78366 skb_checksum_complete(skb)) {
78367 - atomic_inc(&sk->sk_drops);
78368 + atomic_inc_unchecked(&sk->sk_drops);
78369 kfree_skb(skb);
78370 return NET_RX_DROP;
78371 }
78372 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
78373 struct raw6_sock *rp = raw6_sk(sk);
78374
78375 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
78376 - atomic_inc(&sk->sk_drops);
78377 + atomic_inc_unchecked(&sk->sk_drops);
78378 kfree_skb(skb);
78379 return NET_RX_DROP;
78380 }
78381 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
78382
78383 if (inet->hdrincl) {
78384 if (skb_checksum_complete(skb)) {
78385 - atomic_inc(&sk->sk_drops);
78386 + atomic_inc_unchecked(&sk->sk_drops);
78387 kfree_skb(skb);
78388 return NET_RX_DROP;
78389 }
78390 @@ -604,7 +604,7 @@ out:
78391 return err;
78392 }
78393
78394 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
78395 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
78396 struct flowi6 *fl6, struct dst_entry **dstp,
78397 unsigned int flags)
78398 {
78399 @@ -916,12 +916,15 @@ do_confirm:
78400 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
78401 char __user *optval, int optlen)
78402 {
78403 + struct icmp6_filter filter;
78404 +
78405 switch (optname) {
78406 case ICMPV6_FILTER:
78407 if (optlen > sizeof(struct icmp6_filter))
78408 optlen = sizeof(struct icmp6_filter);
78409 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
78410 + if (copy_from_user(&filter, optval, optlen))
78411 return -EFAULT;
78412 + raw6_sk(sk)->filter = filter;
78413 return 0;
78414 default:
78415 return -ENOPROTOOPT;
78416 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
78417 char __user *optval, int __user *optlen)
78418 {
78419 int len;
78420 + struct icmp6_filter filter;
78421
78422 switch (optname) {
78423 case ICMPV6_FILTER:
78424 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
78425 len = sizeof(struct icmp6_filter);
78426 if (put_user(len, optlen))
78427 return -EFAULT;
78428 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
78429 + filter = raw6_sk(sk)->filter;
78430 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
78431 return -EFAULT;
78432 return 0;
78433 default:
78434 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
78435 0, 0L, 0,
78436 sock_i_uid(sp), 0,
78437 sock_i_ino(sp),
78438 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
78439 + atomic_read(&sp->sk_refcnt),
78440 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78441 + NULL,
78442 +#else
78443 + sp,
78444 +#endif
78445 + atomic_read_unchecked(&sp->sk_drops));
78446 }
78447
78448 static int raw6_seq_show(struct seq_file *seq, void *v)
78449 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
78450 index 7e32d42..5d975ba 100644
78451 --- a/net/ipv6/tcp_ipv6.c
78452 +++ b/net/ipv6/tcp_ipv6.c
78453 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
78454 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
78455 }
78456
78457 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78458 +extern int grsec_enable_blackhole;
78459 +#endif
78460 +
78461 static void tcp_v6_hash(struct sock *sk)
78462 {
78463 if (sk->sk_state != TCP_CLOSE) {
78464 @@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
78465 return 0;
78466
78467 reset:
78468 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78469 + if (!grsec_enable_blackhole)
78470 +#endif
78471 tcp_v6_send_reset(sk, skb);
78472 discard:
78473 if (opt_skb)
78474 @@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
78475 TCP_SKB_CB(skb)->sacked = 0;
78476
78477 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
78478 - if (!sk)
78479 + if (!sk) {
78480 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78481 + ret = 1;
78482 +#endif
78483 goto no_tcp_socket;
78484 + }
78485
78486 process:
78487 - if (sk->sk_state == TCP_TIME_WAIT)
78488 + if (sk->sk_state == TCP_TIME_WAIT) {
78489 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78490 + ret = 2;
78491 +#endif
78492 goto do_time_wait;
78493 + }
78494
78495 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
78496 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
78497 @@ -1646,6 +1661,10 @@ no_tcp_socket:
78498 bad_packet:
78499 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
78500 } else {
78501 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78502 + if (!grsec_enable_blackhole || (ret == 1 &&
78503 + (skb->dev->flags & IFF_LOOPBACK)))
78504 +#endif
78505 tcp_v6_send_reset(NULL, skb);
78506 }
78507
78508 @@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
78509 uid,
78510 0, /* non standard timer */
78511 0, /* open_requests have no inode */
78512 - 0, req);
78513 + 0,
78514 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78515 + NULL
78516 +#else
78517 + req
78518 +#endif
78519 + );
78520 }
78521
78522 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78523 @@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78524 sock_i_uid(sp),
78525 icsk->icsk_probes_out,
78526 sock_i_ino(sp),
78527 - atomic_read(&sp->sk_refcnt), sp,
78528 + atomic_read(&sp->sk_refcnt),
78529 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78530 + NULL,
78531 +#else
78532 + sp,
78533 +#endif
78534 jiffies_to_clock_t(icsk->icsk_rto),
78535 jiffies_to_clock_t(icsk->icsk_ack.ato),
78536 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
78537 @@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
78538 dest->s6_addr32[2], dest->s6_addr32[3], destp,
78539 tw->tw_substate, 0, 0,
78540 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
78541 - atomic_read(&tw->tw_refcnt), tw);
78542 + atomic_read(&tw->tw_refcnt),
78543 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78544 + NULL
78545 +#else
78546 + tw
78547 +#endif
78548 + );
78549 }
78550
78551 static int tcp6_seq_show(struct seq_file *seq, void *v)
78552 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
78553 index 07e2bfe..328dae8 100644
78554 --- a/net/ipv6/udp.c
78555 +++ b/net/ipv6/udp.c
78556 @@ -51,6 +51,10 @@
78557 #include <trace/events/skb.h>
78558 #include "udp_impl.h"
78559
78560 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78561 +extern int grsec_enable_blackhole;
78562 +#endif
78563 +
78564 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
78565 {
78566 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
78567 @@ -395,7 +399,7 @@ try_again:
78568 if (unlikely(err)) {
78569 trace_kfree_skb(skb, udpv6_recvmsg);
78570 if (!peeked) {
78571 - atomic_inc(&sk->sk_drops);
78572 + atomic_inc_unchecked(&sk->sk_drops);
78573 if (is_udp4)
78574 UDP_INC_STATS_USER(sock_net(sk),
78575 UDP_MIB_INERRORS,
78576 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78577 return rc;
78578 drop:
78579 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78580 - atomic_inc(&sk->sk_drops);
78581 + atomic_inc_unchecked(&sk->sk_drops);
78582 kfree_skb(skb);
78583 return -1;
78584 }
78585 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78586 if (likely(skb1 == NULL))
78587 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78588 if (!skb1) {
78589 - atomic_inc(&sk->sk_drops);
78590 + atomic_inc_unchecked(&sk->sk_drops);
78591 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78592 IS_UDPLITE(sk));
78593 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78594 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78595 goto discard;
78596
78597 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78598 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78599 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78600 +#endif
78601 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
78602
78603 kfree_skb(skb);
78604 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
78605 0, 0L, 0,
78606 sock_i_uid(sp), 0,
78607 sock_i_ino(sp),
78608 - atomic_read(&sp->sk_refcnt), sp,
78609 - atomic_read(&sp->sk_drops));
78610 + atomic_read(&sp->sk_refcnt),
78611 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78612 + NULL,
78613 +#else
78614 + sp,
78615 +#endif
78616 + atomic_read_unchecked(&sp->sk_drops));
78617 }
78618
78619 int udp6_seq_show(struct seq_file *seq, void *v)
78620 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
78621 index 6b9d5a0..4dffaf1 100644
78622 --- a/net/irda/ircomm/ircomm_tty.c
78623 +++ b/net/irda/ircomm/ircomm_tty.c
78624 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78625 add_wait_queue(&self->open_wait, &wait);
78626
78627 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
78628 - __FILE__,__LINE__, tty->driver->name, self->open_count );
78629 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78630
78631 /* As far as I can see, we protect open_count - Jean II */
78632 spin_lock_irqsave(&self->spinlock, flags);
78633 if (!tty_hung_up_p(filp)) {
78634 extra_count = 1;
78635 - self->open_count--;
78636 + local_dec(&self->open_count);
78637 }
78638 spin_unlock_irqrestore(&self->spinlock, flags);
78639 - self->blocked_open++;
78640 + local_inc(&self->blocked_open);
78641
78642 while (1) {
78643 if (tty->termios->c_cflag & CBAUD) {
78644 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78645 }
78646
78647 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
78648 - __FILE__,__LINE__, tty->driver->name, self->open_count );
78649 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78650
78651 schedule();
78652 }
78653 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78654 if (extra_count) {
78655 /* ++ is not atomic, so this should be protected - Jean II */
78656 spin_lock_irqsave(&self->spinlock, flags);
78657 - self->open_count++;
78658 + local_inc(&self->open_count);
78659 spin_unlock_irqrestore(&self->spinlock, flags);
78660 }
78661 - self->blocked_open--;
78662 + local_dec(&self->blocked_open);
78663
78664 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
78665 - __FILE__,__LINE__, tty->driver->name, self->open_count);
78666 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
78667
78668 if (!retval)
78669 self->flags |= ASYNC_NORMAL_ACTIVE;
78670 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78671 }
78672 /* ++ is not atomic, so this should be protected - Jean II */
78673 spin_lock_irqsave(&self->spinlock, flags);
78674 - self->open_count++;
78675 + local_inc(&self->open_count);
78676
78677 tty->driver_data = self;
78678 self->tty = tty;
78679 spin_unlock_irqrestore(&self->spinlock, flags);
78680
78681 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78682 - self->line, self->open_count);
78683 + self->line, local_read(&self->open_count));
78684
78685 /* Not really used by us, but lets do it anyway */
78686 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78687 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78688 return;
78689 }
78690
78691 - if ((tty->count == 1) && (self->open_count != 1)) {
78692 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
78693 /*
78694 * Uh, oh. tty->count is 1, which means that the tty
78695 * structure will be freed. state->count should always
78696 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78697 */
78698 IRDA_DEBUG(0, "%s(), bad serial port count; "
78699 "tty->count is 1, state->count is %d\n", __func__ ,
78700 - self->open_count);
78701 - self->open_count = 1;
78702 + local_read(&self->open_count));
78703 + local_set(&self->open_count, 1);
78704 }
78705
78706 - if (--self->open_count < 0) {
78707 + if (local_dec_return(&self->open_count) < 0) {
78708 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
78709 - __func__, self->line, self->open_count);
78710 - self->open_count = 0;
78711 + __func__, self->line, local_read(&self->open_count));
78712 + local_set(&self->open_count, 0);
78713 }
78714 - if (self->open_count) {
78715 + if (local_read(&self->open_count)) {
78716 spin_unlock_irqrestore(&self->spinlock, flags);
78717
78718 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
78719 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78720 tty->closing = 0;
78721 self->tty = NULL;
78722
78723 - if (self->blocked_open) {
78724 + if (local_read(&self->blocked_open)) {
78725 if (self->close_delay)
78726 schedule_timeout_interruptible(self->close_delay);
78727 wake_up_interruptible(&self->open_wait);
78728 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78729 spin_lock_irqsave(&self->spinlock, flags);
78730 self->flags &= ~ASYNC_NORMAL_ACTIVE;
78731 self->tty = NULL;
78732 - self->open_count = 0;
78733 + local_set(&self->open_count, 0);
78734 spin_unlock_irqrestore(&self->spinlock, flags);
78735
78736 wake_up_interruptible(&self->open_wait);
78737 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78738 seq_putc(m, '\n');
78739
78740 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78741 - seq_printf(m, "Open count: %d\n", self->open_count);
78742 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
78743 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78744 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78745
78746 diff --git a/net/irda/irttp.c b/net/irda/irttp.c
78747 index 5c93f29..71498f0 100644
78748 --- a/net/irda/irttp.c
78749 +++ b/net/irda/irttp.c
78750 @@ -441,6 +441,7 @@ struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify)
78751 lsap = irlmp_open_lsap(stsap_sel, &ttp_notify, 0);
78752 if (lsap == NULL) {
78753 IRDA_WARNING("%s: unable to allocate LSAP!!\n", __func__);
78754 + __irttp_close_tsap(self);
78755 return NULL;
78756 }
78757
78758 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78759 index cd6f7a9..e63fe89 100644
78760 --- a/net/iucv/af_iucv.c
78761 +++ b/net/iucv/af_iucv.c
78762 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78763
78764 write_lock_bh(&iucv_sk_list.lock);
78765
78766 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78767 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78768 while (__iucv_get_sock_by_name(name)) {
78769 sprintf(name, "%08x",
78770 - atomic_inc_return(&iucv_sk_list.autobind_name));
78771 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78772 }
78773
78774 write_unlock_bh(&iucv_sk_list.lock);
78775 diff --git a/net/key/af_key.c b/net/key/af_key.c
78776 index 34e4185..8823368 100644
78777 --- a/net/key/af_key.c
78778 +++ b/net/key/af_key.c
78779 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78780 static u32 get_acqseq(void)
78781 {
78782 u32 res;
78783 - static atomic_t acqseq;
78784 + static atomic_unchecked_t acqseq;
78785
78786 do {
78787 - res = atomic_inc_return(&acqseq);
78788 + res = atomic_inc_return_unchecked(&acqseq);
78789 } while (!res);
78790 return res;
78791 }
78792 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78793 index 642a2a3..9dcc3dd 100644
78794 --- a/net/mac80211/ieee80211_i.h
78795 +++ b/net/mac80211/ieee80211_i.h
78796 @@ -28,6 +28,7 @@
78797 #include <net/ieee80211_radiotap.h>
78798 #include <net/cfg80211.h>
78799 #include <net/mac80211.h>
78800 +#include <asm/local.h>
78801 #include "key.h"
78802 #include "sta_info.h"
78803 #include "debug.h"
78804 @@ -840,7 +841,7 @@ struct ieee80211_local {
78805 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78806 spinlock_t queue_stop_reason_lock;
78807
78808 - int open_count;
78809 + local_t open_count;
78810 int monitors, cooked_mntrs;
78811 /* number of interfaces with corresponding FIF_ flags */
78812 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78813 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78814 index c93d395..a305570 100644
78815 --- a/net/mac80211/iface.c
78816 +++ b/net/mac80211/iface.c
78817 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78818 break;
78819 }
78820
78821 - if (local->open_count == 0) {
78822 + if (local_read(&local->open_count) == 0) {
78823 res = drv_start(local);
78824 if (res)
78825 goto err_del_bss;
78826 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78827 break;
78828 }
78829
78830 - if (local->monitors == 0 && local->open_count == 0) {
78831 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78832 res = ieee80211_add_virtual_monitor(local);
78833 if (res)
78834 goto err_stop;
78835 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78836 mutex_unlock(&local->mtx);
78837
78838 if (coming_up)
78839 - local->open_count++;
78840 + local_inc(&local->open_count);
78841
78842 if (hw_reconf_flags)
78843 ieee80211_hw_config(local, hw_reconf_flags);
78844 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78845 err_del_interface:
78846 drv_remove_interface(local, sdata);
78847 err_stop:
78848 - if (!local->open_count)
78849 + if (!local_read(&local->open_count))
78850 drv_stop(local);
78851 err_del_bss:
78852 sdata->bss = NULL;
78853 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78854 }
78855
78856 if (going_down)
78857 - local->open_count--;
78858 + local_dec(&local->open_count);
78859
78860 switch (sdata->vif.type) {
78861 case NL80211_IFTYPE_AP_VLAN:
78862 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78863
78864 ieee80211_recalc_ps(local, -1);
78865
78866 - if (local->open_count == 0) {
78867 + if (local_read(&local->open_count) == 0) {
78868 if (local->ops->napi_poll)
78869 napi_disable(&local->napi);
78870 ieee80211_clear_tx_pending(local);
78871 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78872 }
78873 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78874
78875 - if (local->monitors == local->open_count && local->monitors > 0)
78876 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78877 ieee80211_add_virtual_monitor(local);
78878 }
78879
78880 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78881 index c26e231..8916637 100644
78882 --- a/net/mac80211/main.c
78883 +++ b/net/mac80211/main.c
78884 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78885 local->hw.conf.power_level = power;
78886 }
78887
78888 - if (changed && local->open_count) {
78889 + if (changed && local_read(&local->open_count)) {
78890 ret = drv_config(local, changed);
78891 /*
78892 * Goal:
78893 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78894 index 5c572e7..ecf75ce 100644
78895 --- a/net/mac80211/pm.c
78896 +++ b/net/mac80211/pm.c
78897 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78898 struct ieee80211_sub_if_data *sdata;
78899 struct sta_info *sta;
78900
78901 - if (!local->open_count)
78902 + if (!local_read(&local->open_count))
78903 goto suspend;
78904
78905 ieee80211_scan_cancel(local);
78906 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78907 cancel_work_sync(&local->dynamic_ps_enable_work);
78908 del_timer_sync(&local->dynamic_ps_timer);
78909
78910 - local->wowlan = wowlan && local->open_count;
78911 + local->wowlan = wowlan && local_read(&local->open_count);
78912 if (local->wowlan) {
78913 int err = drv_suspend(local, wowlan);
78914 if (err < 0) {
78915 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78916 drv_remove_interface(local, sdata);
78917
78918 /* stop hardware - this must stop RX */
78919 - if (local->open_count)
78920 + if (local_read(&local->open_count))
78921 ieee80211_stop_device(local);
78922
78923 suspend:
78924 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78925 index 3313c11..bec9f17 100644
78926 --- a/net/mac80211/rate.c
78927 +++ b/net/mac80211/rate.c
78928 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78929
78930 ASSERT_RTNL();
78931
78932 - if (local->open_count)
78933 + if (local_read(&local->open_count))
78934 return -EBUSY;
78935
78936 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78937 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78938 index c97a065..ff61928 100644
78939 --- a/net/mac80211/rc80211_pid_debugfs.c
78940 +++ b/net/mac80211/rc80211_pid_debugfs.c
78941 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78942
78943 spin_unlock_irqrestore(&events->lock, status);
78944
78945 - if (copy_to_user(buf, pb, p))
78946 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78947 return -EFAULT;
78948
78949 return p;
78950 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78951 index 7883449..17c6a9a 100644
78952 --- a/net/mac80211/util.c
78953 +++ b/net/mac80211/util.c
78954 @@ -1279,7 +1279,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78955 }
78956 #endif
78957 /* everything else happens only if HW was up & running */
78958 - if (!local->open_count)
78959 + if (!local_read(&local->open_count))
78960 goto wake_up;
78961
78962 /*
78963 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78964 index c19b214..471fad1 100644
78965 --- a/net/netfilter/Kconfig
78966 +++ b/net/netfilter/Kconfig
78967 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78968
78969 To compile it as a module, choose M here. If unsure, say N.
78970
78971 +config NETFILTER_XT_MATCH_GRADM
78972 + tristate '"gradm" match support'
78973 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78974 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78975 + ---help---
78976 + The gradm match allows to match on grsecurity RBAC being enabled.
78977 + It is useful when iptables rules are applied early on bootup to
78978 + prevent connections to the machine (except from a trusted host)
78979 + while the RBAC system is disabled.
78980 +
78981 config NETFILTER_XT_MATCH_HASHLIMIT
78982 tristate '"hashlimit" match support'
78983 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78984 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78985 index 1c5160f..145ae21 100644
78986 --- a/net/netfilter/Makefile
78987 +++ b/net/netfilter/Makefile
78988 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78989 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78990 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78991 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78992 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78993 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78994 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78995 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78996 diff --git a/net/netfilter/ipset/ip_set_hash_netiface.c b/net/netfilter/ipset/ip_set_hash_netiface.c
78997 index d5d3607..1b6fa7b 100644
78998 --- a/net/netfilter/ipset/ip_set_hash_netiface.c
78999 +++ b/net/netfilter/ipset/ip_set_hash_netiface.c
79000 @@ -791,7 +791,7 @@ static struct ip_set_type hash_netiface_type __read_mostly = {
79001 [IPSET_ATTR_IP] = { .type = NLA_NESTED },
79002 [IPSET_ATTR_IP_TO] = { .type = NLA_NESTED },
79003 [IPSET_ATTR_IFACE] = { .type = NLA_NUL_STRING,
79004 - .len = IPSET_MAXNAMELEN - 1 },
79005 + .len = IFNAMSIZ - 1 },
79006 [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
79007 [IPSET_ATTR_CIDR] = { .type = NLA_U8 },
79008 [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
79009 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
79010 index 1548df9..98ad9b4 100644
79011 --- a/net/netfilter/ipvs/ip_vs_conn.c
79012 +++ b/net/netfilter/ipvs/ip_vs_conn.c
79013 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
79014 /* Increase the refcnt counter of the dest */
79015 atomic_inc(&dest->refcnt);
79016
79017 - conn_flags = atomic_read(&dest->conn_flags);
79018 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
79019 if (cp->protocol != IPPROTO_UDP)
79020 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
79021 flags = cp->flags;
79022 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
79023 atomic_set(&cp->refcnt, 1);
79024
79025 atomic_set(&cp->n_control, 0);
79026 - atomic_set(&cp->in_pkts, 0);
79027 + atomic_set_unchecked(&cp->in_pkts, 0);
79028
79029 atomic_inc(&ipvs->conn_count);
79030 if (flags & IP_VS_CONN_F_NO_CPORT)
79031 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
79032
79033 /* Don't drop the entry if its number of incoming packets is not
79034 located in [0, 8] */
79035 - i = atomic_read(&cp->in_pkts);
79036 + i = atomic_read_unchecked(&cp->in_pkts);
79037 if (i > 8 || i < 0) return 0;
79038
79039 if (!todrop_rate[i]) return 0;
79040 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
79041 index b54ecce..fc5f6cf 100644
79042 --- a/net/netfilter/ipvs/ip_vs_core.c
79043 +++ b/net/netfilter/ipvs/ip_vs_core.c
79044 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
79045 ret = cp->packet_xmit(skb, cp, pd->pp);
79046 /* do not touch skb anymore */
79047
79048 - atomic_inc(&cp->in_pkts);
79049 + atomic_inc_unchecked(&cp->in_pkts);
79050 ip_vs_conn_put(cp);
79051 return ret;
79052 }
79053 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
79054 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
79055 pkts = sysctl_sync_threshold(ipvs);
79056 else
79057 - pkts = atomic_add_return(1, &cp->in_pkts);
79058 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
79059
79060 if (ipvs->sync_state & IP_VS_STATE_MASTER)
79061 ip_vs_sync_conn(net, cp, pkts);
79062 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
79063 index f51013c..c99ee52 100644
79064 --- a/net/netfilter/ipvs/ip_vs_ctl.c
79065 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
79066 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
79067 ip_vs_rs_hash(ipvs, dest);
79068 write_unlock_bh(&ipvs->rs_lock);
79069 }
79070 - atomic_set(&dest->conn_flags, conn_flags);
79071 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
79072
79073 /* bind the service */
79074 if (!dest->svc) {
79075 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
79076 " %-7s %-6d %-10d %-10d\n",
79077 &dest->addr.in6,
79078 ntohs(dest->port),
79079 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
79080 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
79081 atomic_read(&dest->weight),
79082 atomic_read(&dest->activeconns),
79083 atomic_read(&dest->inactconns));
79084 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
79085 "%-7s %-6d %-10d %-10d\n",
79086 ntohl(dest->addr.ip),
79087 ntohs(dest->port),
79088 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
79089 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
79090 atomic_read(&dest->weight),
79091 atomic_read(&dest->activeconns),
79092 atomic_read(&dest->inactconns));
79093 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
79094
79095 entry.addr = dest->addr.ip;
79096 entry.port = dest->port;
79097 - entry.conn_flags = atomic_read(&dest->conn_flags);
79098 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
79099 entry.weight = atomic_read(&dest->weight);
79100 entry.u_threshold = dest->u_threshold;
79101 entry.l_threshold = dest->l_threshold;
79102 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
79103 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
79104 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
79105 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
79106 - (atomic_read(&dest->conn_flags) &
79107 + (atomic_read_unchecked(&dest->conn_flags) &
79108 IP_VS_CONN_F_FWD_MASK)) ||
79109 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
79110 atomic_read(&dest->weight)) ||
79111 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
79112 index effa10c..9058928 100644
79113 --- a/net/netfilter/ipvs/ip_vs_sync.c
79114 +++ b/net/netfilter/ipvs/ip_vs_sync.c
79115 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
79116 cp = cp->control;
79117 if (cp) {
79118 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
79119 - pkts = atomic_add_return(1, &cp->in_pkts);
79120 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
79121 else
79122 pkts = sysctl_sync_threshold(ipvs);
79123 ip_vs_sync_conn(net, cp->control, pkts);
79124 @@ -758,7 +758,7 @@ control:
79125 if (!cp)
79126 return;
79127 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
79128 - pkts = atomic_add_return(1, &cp->in_pkts);
79129 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
79130 else
79131 pkts = sysctl_sync_threshold(ipvs);
79132 goto sloop;
79133 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
79134
79135 if (opt)
79136 memcpy(&cp->in_seq, opt, sizeof(*opt));
79137 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
79138 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
79139 cp->state = state;
79140 cp->old_state = cp->state;
79141 /*
79142 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
79143 index c3c6291..3376d73 100644
79144 --- a/net/netfilter/ipvs/ip_vs_xmit.c
79145 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
79146 @@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
79147 else
79148 rc = NF_ACCEPT;
79149 /* do not touch skb anymore */
79150 - atomic_inc(&cp->in_pkts);
79151 + atomic_inc_unchecked(&cp->in_pkts);
79152 goto out;
79153 }
79154
79155 @@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
79156 else
79157 rc = NF_ACCEPT;
79158 /* do not touch skb anymore */
79159 - atomic_inc(&cp->in_pkts);
79160 + atomic_inc_unchecked(&cp->in_pkts);
79161 goto out;
79162 }
79163
79164 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
79165 index 2ceec64..a5b8a61 100644
79166 --- a/net/netfilter/nf_conntrack_core.c
79167 +++ b/net/netfilter/nf_conntrack_core.c
79168 @@ -1529,6 +1529,10 @@ err_extend:
79169 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
79170 #define DYING_NULLS_VAL ((1<<30)+1)
79171
79172 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79173 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
79174 +#endif
79175 +
79176 static int nf_conntrack_init_net(struct net *net)
79177 {
79178 int ret;
79179 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
79180 goto err_stat;
79181 }
79182
79183 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79184 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
79185 +#else
79186 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
79187 +#endif
79188 if (!net->ct.slabname) {
79189 ret = -ENOMEM;
79190 goto err_slabname;
79191 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
79192 index 5cfb5be..217c6d8 100644
79193 --- a/net/netfilter/nfnetlink_log.c
79194 +++ b/net/netfilter/nfnetlink_log.c
79195 @@ -70,7 +70,7 @@ struct nfulnl_instance {
79196 };
79197
79198 static DEFINE_SPINLOCK(instances_lock);
79199 -static atomic_t global_seq;
79200 +static atomic_unchecked_t global_seq;
79201
79202 #define INSTANCE_BUCKETS 16
79203 static struct hlist_head instance_table[INSTANCE_BUCKETS];
79204 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
79205 /* global sequence number */
79206 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
79207 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
79208 - htonl(atomic_inc_return(&global_seq))))
79209 + htonl(atomic_inc_return_unchecked(&global_seq))))
79210 goto nla_put_failure;
79211
79212 if (data_len) {
79213 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
79214 new file mode 100644
79215 index 0000000..c566332
79216 --- /dev/null
79217 +++ b/net/netfilter/xt_gradm.c
79218 @@ -0,0 +1,51 @@
79219 +/*
79220 + * gradm match for netfilter
79221 + * Copyright © Zbigniew Krzystolik, 2010
79222 + *
79223 + * This program is free software; you can redistribute it and/or modify
79224 + * it under the terms of the GNU General Public License; either version
79225 + * 2 or 3 as published by the Free Software Foundation.
79226 + */
79227 +#include <linux/module.h>
79228 +#include <linux/moduleparam.h>
79229 +#include <linux/skbuff.h>
79230 +#include <linux/netfilter/x_tables.h>
79231 +#include <linux/grsecurity.h>
79232 +#include <linux/netfilter/xt_gradm.h>
79233 +
79234 +static bool
79235 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
79236 +{
79237 + const struct xt_gradm_mtinfo *info = par->matchinfo;
79238 + bool retval = false;
79239 + if (gr_acl_is_enabled())
79240 + retval = true;
79241 + return retval ^ info->invflags;
79242 +}
79243 +
79244 +static struct xt_match gradm_mt_reg __read_mostly = {
79245 + .name = "gradm",
79246 + .revision = 0,
79247 + .family = NFPROTO_UNSPEC,
79248 + .match = gradm_mt,
79249 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
79250 + .me = THIS_MODULE,
79251 +};
79252 +
79253 +static int __init gradm_mt_init(void)
79254 +{
79255 + return xt_register_match(&gradm_mt_reg);
79256 +}
79257 +
79258 +static void __exit gradm_mt_exit(void)
79259 +{
79260 + xt_unregister_match(&gradm_mt_reg);
79261 +}
79262 +
79263 +module_init(gradm_mt_init);
79264 +module_exit(gradm_mt_exit);
79265 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
79266 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
79267 +MODULE_LICENSE("GPL");
79268 +MODULE_ALIAS("ipt_gradm");
79269 +MODULE_ALIAS("ip6t_gradm");
79270 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
79271 index 4fe4fb4..87a89e5 100644
79272 --- a/net/netfilter/xt_statistic.c
79273 +++ b/net/netfilter/xt_statistic.c
79274 @@ -19,7 +19,7 @@
79275 #include <linux/module.h>
79276
79277 struct xt_statistic_priv {
79278 - atomic_t count;
79279 + atomic_unchecked_t count;
79280 } ____cacheline_aligned_in_smp;
79281
79282 MODULE_LICENSE("GPL");
79283 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
79284 break;
79285 case XT_STATISTIC_MODE_NTH:
79286 do {
79287 - oval = atomic_read(&info->master->count);
79288 + oval = atomic_read_unchecked(&info->master->count);
79289 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
79290 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
79291 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
79292 if (nval == 0)
79293 ret = !ret;
79294 break;
79295 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
79296 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
79297 if (info->master == NULL)
79298 return -ENOMEM;
79299 - atomic_set(&info->master->count, info->u.nth.count);
79300 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
79301
79302 return 0;
79303 }
79304 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
79305 index 0426b67..d6ddaca 100644
79306 --- a/net/netlink/af_netlink.c
79307 +++ b/net/netlink/af_netlink.c
79308 @@ -780,7 +780,7 @@ static void netlink_overrun(struct sock *sk)
79309 sk->sk_error_report(sk);
79310 }
79311 }
79312 - atomic_inc(&sk->sk_drops);
79313 + atomic_inc_unchecked(&sk->sk_drops);
79314 }
79315
79316 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
79317 @@ -2070,7 +2070,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
79318 sk_wmem_alloc_get(s),
79319 nlk->cb,
79320 atomic_read(&s->sk_refcnt),
79321 - atomic_read(&s->sk_drops),
79322 + atomic_read_unchecked(&s->sk_drops),
79323 sock_i_ino(s)
79324 );
79325
79326 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
79327 index 7261eb8..44e8ac6 100644
79328 --- a/net/netrom/af_netrom.c
79329 +++ b/net/netrom/af_netrom.c
79330 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
79331 struct sock *sk = sock->sk;
79332 struct nr_sock *nr = nr_sk(sk);
79333
79334 + memset(sax, 0, sizeof(*sax));
79335 lock_sock(sk);
79336 if (peer != 0) {
79337 if (sk->sk_state != TCP_ESTABLISHED) {
79338 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
79339 *uaddr_len = sizeof(struct full_sockaddr_ax25);
79340 } else {
79341 sax->fsa_ax25.sax25_family = AF_NETROM;
79342 - sax->fsa_ax25.sax25_ndigis = 0;
79343 sax->fsa_ax25.sax25_call = nr->source_addr;
79344 *uaddr_len = sizeof(struct sockaddr_ax25);
79345 }
79346 diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
79347 index ddeb9aa..e18fffd 100644
79348 --- a/net/nfc/llcp/sock.c
79349 +++ b/net/nfc/llcp/sock.c
79350 @@ -443,15 +443,11 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
79351 pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
79352
79353 if (!addr || len < sizeof(struct sockaddr_nfc) ||
79354 - addr->sa_family != AF_NFC) {
79355 - pr_err("Invalid socket\n");
79356 + addr->sa_family != AF_NFC)
79357 return -EINVAL;
79358 - }
79359
79360 - if (addr->service_name_len == 0 && addr->dsap == 0) {
79361 - pr_err("Missing service name or dsap\n");
79362 + if (addr->service_name_len == 0 && addr->dsap == 0)
79363 return -EINVAL;
79364 - }
79365
79366 pr_debug("addr dev_idx=%u target_idx=%u protocol=%u\n", addr->dev_idx,
79367 addr->target_idx, addr->nfc_protocol);
79368 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
79369 index c5c9e2a..4814ab1 100644
79370 --- a/net/packet/af_packet.c
79371 +++ b/net/packet/af_packet.c
79372 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
79373
79374 spin_lock(&sk->sk_receive_queue.lock);
79375 po->stats.tp_packets++;
79376 - skb->dropcount = atomic_read(&sk->sk_drops);
79377 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79378 __skb_queue_tail(&sk->sk_receive_queue, skb);
79379 spin_unlock(&sk->sk_receive_queue.lock);
79380 sk->sk_data_ready(sk, skb->len);
79381 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
79382 drop_n_acct:
79383 spin_lock(&sk->sk_receive_queue.lock);
79384 po->stats.tp_drops++;
79385 - atomic_inc(&sk->sk_drops);
79386 + atomic_inc_unchecked(&sk->sk_drops);
79387 spin_unlock(&sk->sk_receive_queue.lock);
79388
79389 drop_n_restore:
79390 @@ -2642,6 +2642,7 @@ out:
79391
79392 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
79393 {
79394 + struct sock_extended_err ee;
79395 struct sock_exterr_skb *serr;
79396 struct sk_buff *skb, *skb2;
79397 int copied, err;
79398 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
79399 sock_recv_timestamp(msg, sk, skb);
79400
79401 serr = SKB_EXT_ERR(skb);
79402 + ee = serr->ee;
79403 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
79404 - sizeof(serr->ee), &serr->ee);
79405 + sizeof ee, &ee);
79406
79407 msg->msg_flags |= MSG_ERRQUEUE;
79408 err = copied;
79409 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
79410 case PACKET_HDRLEN:
79411 if (len > sizeof(int))
79412 len = sizeof(int);
79413 - if (copy_from_user(&val, optval, len))
79414 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
79415 return -EFAULT;
79416 switch (val) {
79417 case TPACKET_V1:
79418 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
79419 len = lv;
79420 if (put_user(len, optlen))
79421 return -EFAULT;
79422 - if (copy_to_user(optval, data, len))
79423 + if (len > sizeof(st) || copy_to_user(optval, data, len))
79424 return -EFAULT;
79425 return 0;
79426 }
79427 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
79428 index 5a940db..f0b9c12 100644
79429 --- a/net/phonet/af_phonet.c
79430 +++ b/net/phonet/af_phonet.c
79431 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
79432 {
79433 struct phonet_protocol *pp;
79434
79435 - if (protocol >= PHONET_NPROTO)
79436 + if (protocol < 0 || protocol >= PHONET_NPROTO)
79437 return NULL;
79438
79439 rcu_read_lock();
79440 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
79441 {
79442 int err = 0;
79443
79444 - if (protocol >= PHONET_NPROTO)
79445 + if (protocol < 0 || protocol >= PHONET_NPROTO)
79446 return -EINVAL;
79447
79448 err = proto_register(pp->prot, 1);
79449 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
79450 index 576f22c..bc7a71b 100644
79451 --- a/net/phonet/pep.c
79452 +++ b/net/phonet/pep.c
79453 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
79454
79455 case PNS_PEP_CTRL_REQ:
79456 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
79457 - atomic_inc(&sk->sk_drops);
79458 + atomic_inc_unchecked(&sk->sk_drops);
79459 break;
79460 }
79461 __skb_pull(skb, 4);
79462 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
79463 }
79464
79465 if (pn->rx_credits == 0) {
79466 - atomic_inc(&sk->sk_drops);
79467 + atomic_inc_unchecked(&sk->sk_drops);
79468 err = -ENOBUFS;
79469 break;
79470 }
79471 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
79472 }
79473
79474 if (pn->rx_credits == 0) {
79475 - atomic_inc(&sk->sk_drops);
79476 + atomic_inc_unchecked(&sk->sk_drops);
79477 err = NET_RX_DROP;
79478 break;
79479 }
79480 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
79481 index 0acc943..c727611 100644
79482 --- a/net/phonet/socket.c
79483 +++ b/net/phonet/socket.c
79484 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
79485 pn->resource, sk->sk_state,
79486 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
79487 sock_i_uid(sk), sock_i_ino(sk),
79488 - atomic_read(&sk->sk_refcnt), sk,
79489 - atomic_read(&sk->sk_drops), &len);
79490 + atomic_read(&sk->sk_refcnt),
79491 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79492 + NULL,
79493 +#else
79494 + sk,
79495 +#endif
79496 + atomic_read_unchecked(&sk->sk_drops), &len);
79497 }
79498 seq_printf(seq, "%*s\n", 127 - len, "");
79499 return 0;
79500 diff --git a/net/rds/cong.c b/net/rds/cong.c
79501 index e5b65ac..f3b6fb7 100644
79502 --- a/net/rds/cong.c
79503 +++ b/net/rds/cong.c
79504 @@ -78,7 +78,7 @@
79505 * finds that the saved generation number is smaller than the global generation
79506 * number, it wakes up the process.
79507 */
79508 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
79509 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
79510
79511 /*
79512 * Congestion monitoring
79513 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
79514 rdsdebug("waking map %p for %pI4\n",
79515 map, &map->m_addr);
79516 rds_stats_inc(s_cong_update_received);
79517 - atomic_inc(&rds_cong_generation);
79518 + atomic_inc_unchecked(&rds_cong_generation);
79519 if (waitqueue_active(&map->m_waitq))
79520 wake_up(&map->m_waitq);
79521 if (waitqueue_active(&rds_poll_waitq))
79522 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
79523
79524 int rds_cong_updated_since(unsigned long *recent)
79525 {
79526 - unsigned long gen = atomic_read(&rds_cong_generation);
79527 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
79528
79529 if (likely(*recent == gen))
79530 return 0;
79531 diff --git a/net/rds/ib.h b/net/rds/ib.h
79532 index 8d2b3d5..227ec5b 100644
79533 --- a/net/rds/ib.h
79534 +++ b/net/rds/ib.h
79535 @@ -128,7 +128,7 @@ struct rds_ib_connection {
79536 /* sending acks */
79537 unsigned long i_ack_flags;
79538 #ifdef KERNEL_HAS_ATOMIC64
79539 - atomic64_t i_ack_next; /* next ACK to send */
79540 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79541 #else
79542 spinlock_t i_ack_lock; /* protect i_ack_next */
79543 u64 i_ack_next; /* next ACK to send */
79544 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
79545 index a1e1162..265e129 100644
79546 --- a/net/rds/ib_cm.c
79547 +++ b/net/rds/ib_cm.c
79548 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
79549 /* Clear the ACK state */
79550 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79551 #ifdef KERNEL_HAS_ATOMIC64
79552 - atomic64_set(&ic->i_ack_next, 0);
79553 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79554 #else
79555 ic->i_ack_next = 0;
79556 #endif
79557 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
79558 index 8d19491..05a3e65 100644
79559 --- a/net/rds/ib_recv.c
79560 +++ b/net/rds/ib_recv.c
79561 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79562 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
79563 int ack_required)
79564 {
79565 - atomic64_set(&ic->i_ack_next, seq);
79566 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79567 if (ack_required) {
79568 smp_mb__before_clear_bit();
79569 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79570 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79571 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79572 smp_mb__after_clear_bit();
79573
79574 - return atomic64_read(&ic->i_ack_next);
79575 + return atomic64_read_unchecked(&ic->i_ack_next);
79576 }
79577 #endif
79578
79579 diff --git a/net/rds/iw.h b/net/rds/iw.h
79580 index 04ce3b1..48119a6 100644
79581 --- a/net/rds/iw.h
79582 +++ b/net/rds/iw.h
79583 @@ -134,7 +134,7 @@ struct rds_iw_connection {
79584 /* sending acks */
79585 unsigned long i_ack_flags;
79586 #ifdef KERNEL_HAS_ATOMIC64
79587 - atomic64_t i_ack_next; /* next ACK to send */
79588 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79589 #else
79590 spinlock_t i_ack_lock; /* protect i_ack_next */
79591 u64 i_ack_next; /* next ACK to send */
79592 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
79593 index a91e1db..cf3053f 100644
79594 --- a/net/rds/iw_cm.c
79595 +++ b/net/rds/iw_cm.c
79596 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
79597 /* Clear the ACK state */
79598 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79599 #ifdef KERNEL_HAS_ATOMIC64
79600 - atomic64_set(&ic->i_ack_next, 0);
79601 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79602 #else
79603 ic->i_ack_next = 0;
79604 #endif
79605 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
79606 index 4503335..db566b4 100644
79607 --- a/net/rds/iw_recv.c
79608 +++ b/net/rds/iw_recv.c
79609 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79610 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
79611 int ack_required)
79612 {
79613 - atomic64_set(&ic->i_ack_next, seq);
79614 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79615 if (ack_required) {
79616 smp_mb__before_clear_bit();
79617 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79618 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79619 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79620 smp_mb__after_clear_bit();
79621
79622 - return atomic64_read(&ic->i_ack_next);
79623 + return atomic64_read_unchecked(&ic->i_ack_next);
79624 }
79625 #endif
79626
79627 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
79628 index edac9ef..16bcb98 100644
79629 --- a/net/rds/tcp.c
79630 +++ b/net/rds/tcp.c
79631 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
79632 int val = 1;
79633
79634 set_fs(KERNEL_DS);
79635 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
79636 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
79637 sizeof(val));
79638 set_fs(oldfs);
79639 }
79640 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
79641 index 1b4fd68..2234175 100644
79642 --- a/net/rds/tcp_send.c
79643 +++ b/net/rds/tcp_send.c
79644 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
79645
79646 oldfs = get_fs();
79647 set_fs(KERNEL_DS);
79648 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
79649 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
79650 sizeof(val));
79651 set_fs(oldfs);
79652 }
79653 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
79654 index 05996d0..5a1dfe0 100644
79655 --- a/net/rxrpc/af_rxrpc.c
79656 +++ b/net/rxrpc/af_rxrpc.c
79657 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
79658 __be32 rxrpc_epoch;
79659
79660 /* current debugging ID */
79661 -atomic_t rxrpc_debug_id;
79662 +atomic_unchecked_t rxrpc_debug_id;
79663
79664 /* count of skbs currently in use */
79665 atomic_t rxrpc_n_skbs;
79666 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
79667 index e4d9cbc..b229649 100644
79668 --- a/net/rxrpc/ar-ack.c
79669 +++ b/net/rxrpc/ar-ack.c
79670 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79671
79672 _enter("{%d,%d,%d,%d},",
79673 call->acks_hard, call->acks_unacked,
79674 - atomic_read(&call->sequence),
79675 + atomic_read_unchecked(&call->sequence),
79676 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
79677
79678 stop = 0;
79679 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79680
79681 /* each Tx packet has a new serial number */
79682 sp->hdr.serial =
79683 - htonl(atomic_inc_return(&call->conn->serial));
79684 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
79685
79686 hdr = (struct rxrpc_header *) txb->head;
79687 hdr->serial = sp->hdr.serial;
79688 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
79689 */
79690 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
79691 {
79692 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
79693 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
79694 }
79695
79696 /*
79697 @@ -629,7 +629,7 @@ process_further:
79698
79699 latest = ntohl(sp->hdr.serial);
79700 hard = ntohl(ack.firstPacket);
79701 - tx = atomic_read(&call->sequence);
79702 + tx = atomic_read_unchecked(&call->sequence);
79703
79704 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79705 latest,
79706 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
79707 goto maybe_reschedule;
79708
79709 send_ACK_with_skew:
79710 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
79711 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
79712 ntohl(ack.serial));
79713 send_ACK:
79714 mtu = call->conn->trans->peer->if_mtu;
79715 @@ -1173,7 +1173,7 @@ send_ACK:
79716 ackinfo.rxMTU = htonl(5692);
79717 ackinfo.jumbo_max = htonl(4);
79718
79719 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79720 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79721 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79722 ntohl(hdr.serial),
79723 ntohs(ack.maxSkew),
79724 @@ -1191,7 +1191,7 @@ send_ACK:
79725 send_message:
79726 _debug("send message");
79727
79728 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79729 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79730 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
79731 send_message_2:
79732
79733 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
79734 index a3bbb36..3341fb9 100644
79735 --- a/net/rxrpc/ar-call.c
79736 +++ b/net/rxrpc/ar-call.c
79737 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
79738 spin_lock_init(&call->lock);
79739 rwlock_init(&call->state_lock);
79740 atomic_set(&call->usage, 1);
79741 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
79742 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79743 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
79744
79745 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
79746 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
79747 index 4106ca9..a338d7a 100644
79748 --- a/net/rxrpc/ar-connection.c
79749 +++ b/net/rxrpc/ar-connection.c
79750 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
79751 rwlock_init(&conn->lock);
79752 spin_lock_init(&conn->state_lock);
79753 atomic_set(&conn->usage, 1);
79754 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
79755 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79756 conn->avail_calls = RXRPC_MAXCALLS;
79757 conn->size_align = 4;
79758 conn->header_size = sizeof(struct rxrpc_header);
79759 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
79760 index e7ed43a..6afa140 100644
79761 --- a/net/rxrpc/ar-connevent.c
79762 +++ b/net/rxrpc/ar-connevent.c
79763 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
79764
79765 len = iov[0].iov_len + iov[1].iov_len;
79766
79767 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79768 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79769 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
79770
79771 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79772 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
79773 index 529572f..c758ca7 100644
79774 --- a/net/rxrpc/ar-input.c
79775 +++ b/net/rxrpc/ar-input.c
79776 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
79777 /* track the latest serial number on this connection for ACK packet
79778 * information */
79779 serial = ntohl(sp->hdr.serial);
79780 - hi_serial = atomic_read(&call->conn->hi_serial);
79781 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
79782 while (serial > hi_serial)
79783 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
79784 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
79785 serial);
79786
79787 /* request ACK generation for any ACK or DATA packet that requests
79788 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
79789 index a693aca..81e7293 100644
79790 --- a/net/rxrpc/ar-internal.h
79791 +++ b/net/rxrpc/ar-internal.h
79792 @@ -272,8 +272,8 @@ struct rxrpc_connection {
79793 int error; /* error code for local abort */
79794 int debug_id; /* debug ID for printks */
79795 unsigned int call_counter; /* call ID counter */
79796 - atomic_t serial; /* packet serial number counter */
79797 - atomic_t hi_serial; /* highest serial number received */
79798 + atomic_unchecked_t serial; /* packet serial number counter */
79799 + atomic_unchecked_t hi_serial; /* highest serial number received */
79800 u8 avail_calls; /* number of calls available */
79801 u8 size_align; /* data size alignment (for security) */
79802 u8 header_size; /* rxrpc + security header size */
79803 @@ -346,7 +346,7 @@ struct rxrpc_call {
79804 spinlock_t lock;
79805 rwlock_t state_lock; /* lock for state transition */
79806 atomic_t usage;
79807 - atomic_t sequence; /* Tx data packet sequence counter */
79808 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
79809 u32 abort_code; /* local/remote abort code */
79810 enum { /* current state of call */
79811 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
79812 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
79813 */
79814 extern atomic_t rxrpc_n_skbs;
79815 extern __be32 rxrpc_epoch;
79816 -extern atomic_t rxrpc_debug_id;
79817 +extern atomic_unchecked_t rxrpc_debug_id;
79818 extern struct workqueue_struct *rxrpc_workqueue;
79819
79820 /*
79821 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
79822 index 87f7135..74d3703 100644
79823 --- a/net/rxrpc/ar-local.c
79824 +++ b/net/rxrpc/ar-local.c
79825 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
79826 spin_lock_init(&local->lock);
79827 rwlock_init(&local->services_lock);
79828 atomic_set(&local->usage, 1);
79829 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
79830 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79831 memcpy(&local->srx, srx, sizeof(*srx));
79832 }
79833
79834 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
79835 index e1ac183..b43e10e 100644
79836 --- a/net/rxrpc/ar-output.c
79837 +++ b/net/rxrpc/ar-output.c
79838 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
79839 sp->hdr.cid = call->cid;
79840 sp->hdr.callNumber = call->call_id;
79841 sp->hdr.seq =
79842 - htonl(atomic_inc_return(&call->sequence));
79843 + htonl(atomic_inc_return_unchecked(&call->sequence));
79844 sp->hdr.serial =
79845 - htonl(atomic_inc_return(&conn->serial));
79846 + htonl(atomic_inc_return_unchecked(&conn->serial));
79847 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
79848 sp->hdr.userStatus = 0;
79849 sp->hdr.securityIndex = conn->security_ix;
79850 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
79851 index bebaa43..2644591 100644
79852 --- a/net/rxrpc/ar-peer.c
79853 +++ b/net/rxrpc/ar-peer.c
79854 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
79855 INIT_LIST_HEAD(&peer->error_targets);
79856 spin_lock_init(&peer->lock);
79857 atomic_set(&peer->usage, 1);
79858 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
79859 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79860 memcpy(&peer->srx, srx, sizeof(*srx));
79861
79862 rxrpc_assess_MTU_size(peer);
79863 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
79864 index 38047f7..9f48511 100644
79865 --- a/net/rxrpc/ar-proc.c
79866 +++ b/net/rxrpc/ar-proc.c
79867 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
79868 atomic_read(&conn->usage),
79869 rxrpc_conn_states[conn->state],
79870 key_serial(conn->key),
79871 - atomic_read(&conn->serial),
79872 - atomic_read(&conn->hi_serial));
79873 + atomic_read_unchecked(&conn->serial),
79874 + atomic_read_unchecked(&conn->hi_serial));
79875
79876 return 0;
79877 }
79878 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
79879 index 92df566..87ec1bf 100644
79880 --- a/net/rxrpc/ar-transport.c
79881 +++ b/net/rxrpc/ar-transport.c
79882 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
79883 spin_lock_init(&trans->client_lock);
79884 rwlock_init(&trans->conn_lock);
79885 atomic_set(&trans->usage, 1);
79886 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
79887 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79888
79889 if (peer->srx.transport.family == AF_INET) {
79890 switch (peer->srx.transport_type) {
79891 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
79892 index f226709..0e735a8 100644
79893 --- a/net/rxrpc/rxkad.c
79894 +++ b/net/rxrpc/rxkad.c
79895 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
79896
79897 len = iov[0].iov_len + iov[1].iov_len;
79898
79899 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79900 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79901 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
79902
79903 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79904 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
79905
79906 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
79907
79908 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
79909 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79910 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
79911
79912 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
79913 diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
79914 index 6c85564..9534bf9 100644
79915 --- a/net/sctp/chunk.c
79916 +++ b/net/sctp/chunk.c
79917 @@ -284,7 +284,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
79918 goto errout;
79919 err = sctp_user_addto_chunk(chunk, offset, len, msgh->msg_iov);
79920 if (err < 0)
79921 - goto errout;
79922 + goto errout_chunk_free;
79923
79924 offset += len;
79925
79926 @@ -324,7 +324,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
79927 __skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr
79928 - (__u8 *)chunk->skb->data);
79929 if (err < 0)
79930 - goto errout;
79931 + goto errout_chunk_free;
79932
79933 sctp_datamsg_assign(msg, chunk);
79934 list_add_tail(&chunk->frag_list, &msg->chunks);
79935 @@ -332,6 +332,9 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
79936
79937 return msg;
79938
79939 +errout_chunk_free:
79940 + sctp_chunk_free(chunk);
79941 +
79942 errout:
79943 list_for_each_safe(pos, temp, &msg->chunks) {
79944 list_del_init(pos);
79945 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
79946 index 1e2eee8..ce3967e 100644
79947 --- a/net/sctp/proc.c
79948 +++ b/net/sctp/proc.c
79949 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
79950 seq_printf(seq,
79951 "%8pK %8pK %-3d %-3d %-2d %-4d "
79952 "%4d %8d %8d %7d %5lu %-5d %5d ",
79953 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
79954 + assoc, sk,
79955 + sctp_sk(sk)->type, sk->sk_state,
79956 assoc->state, hash,
79957 assoc->assoc_id,
79958 assoc->sndbuf_used,
79959 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
79960 index 5e25981..dbda919 100644
79961 --- a/net/sctp/socket.c
79962 +++ b/net/sctp/socket.c
79963 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79964 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79965 if (space_left < addrlen)
79966 return -ENOMEM;
79967 + if (addrlen > sizeof(temp) || addrlen < 0)
79968 + return -EFAULT;
79969 if (copy_to_user(to, &temp, addrlen))
79970 return -EFAULT;
79971 to += addrlen;
79972 diff --git a/net/sctp/transport.c b/net/sctp/transport.c
79973 index c97472b..3f7c94b 100644
79974 --- a/net/sctp/transport.c
79975 +++ b/net/sctp/transport.c
79976 @@ -328,7 +328,7 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
79977 * 1/8, rto_alpha would be expressed as 3.
79978 */
79979 tp->rttvar = tp->rttvar - (tp->rttvar >> sctp_rto_beta)
79980 - + ((abs(tp->srtt - rtt)) >> sctp_rto_beta);
79981 + + (((__u32)abs64((__s64)tp->srtt - (__s64)rtt)) >> sctp_rto_beta);
79982 tp->srtt = tp->srtt - (tp->srtt >> sctp_rto_alpha)
79983 + (rtt >> sctp_rto_alpha);
79984 } else {
79985 diff --git a/net/socket.c b/net/socket.c
79986 index edc3c4a..4b4e4a8 100644
79987 --- a/net/socket.c
79988 +++ b/net/socket.c
79989 @@ -88,6 +88,7 @@
79990 #include <linux/nsproxy.h>
79991 #include <linux/magic.h>
79992 #include <linux/slab.h>
79993 +#include <linux/in.h>
79994
79995 #include <asm/uaccess.h>
79996 #include <asm/unistd.h>
79997 @@ -105,6 +106,8 @@
79998 #include <linux/sockios.h>
79999 #include <linux/atalk.h>
80000
80001 +#include <linux/grsock.h>
80002 +
80003 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
80004 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
80005 unsigned long nr_segs, loff_t pos);
80006 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
80007 &sockfs_dentry_operations, SOCKFS_MAGIC);
80008 }
80009
80010 -static struct vfsmount *sock_mnt __read_mostly;
80011 +struct vfsmount *sock_mnt __read_mostly;
80012
80013 static struct file_system_type sock_fs_type = {
80014 .name = "sockfs",
80015 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
80016 return -EAFNOSUPPORT;
80017 if (type < 0 || type >= SOCK_MAX)
80018 return -EINVAL;
80019 + if (protocol < 0)
80020 + return -EINVAL;
80021
80022 /* Compatibility.
80023
80024 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
80025 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
80026 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
80027
80028 + if(!gr_search_socket(family, type, protocol)) {
80029 + retval = -EACCES;
80030 + goto out;
80031 + }
80032 +
80033 + if (gr_handle_sock_all(family, type, protocol)) {
80034 + retval = -EACCES;
80035 + goto out;
80036 + }
80037 +
80038 retval = sock_create(family, type, protocol, &sock);
80039 if (retval < 0)
80040 goto out;
80041 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
80042 if (sock) {
80043 err = move_addr_to_kernel(umyaddr, addrlen, &address);
80044 if (err >= 0) {
80045 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
80046 + err = -EACCES;
80047 + goto error;
80048 + }
80049 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
80050 + if (err)
80051 + goto error;
80052 +
80053 err = security_socket_bind(sock,
80054 (struct sockaddr *)&address,
80055 addrlen);
80056 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
80057 (struct sockaddr *)
80058 &address, addrlen);
80059 }
80060 +error:
80061 fput_light(sock->file, fput_needed);
80062 }
80063 return err;
80064 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
80065 if ((unsigned int)backlog > somaxconn)
80066 backlog = somaxconn;
80067
80068 + if (gr_handle_sock_server_other(sock->sk)) {
80069 + err = -EPERM;
80070 + goto error;
80071 + }
80072 +
80073 + err = gr_search_listen(sock);
80074 + if (err)
80075 + goto error;
80076 +
80077 err = security_socket_listen(sock, backlog);
80078 if (!err)
80079 err = sock->ops->listen(sock, backlog);
80080
80081 +error:
80082 fput_light(sock->file, fput_needed);
80083 }
80084 return err;
80085 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
80086 newsock->type = sock->type;
80087 newsock->ops = sock->ops;
80088
80089 + if (gr_handle_sock_server_other(sock->sk)) {
80090 + err = -EPERM;
80091 + sock_release(newsock);
80092 + goto out_put;
80093 + }
80094 +
80095 + err = gr_search_accept(sock);
80096 + if (err) {
80097 + sock_release(newsock);
80098 + goto out_put;
80099 + }
80100 +
80101 /*
80102 * We don't need try_module_get here, as the listening socket (sock)
80103 * has the protocol module (sock->ops->owner) held.
80104 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
80105 fd_install(newfd, newfile);
80106 err = newfd;
80107
80108 + gr_attach_curr_ip(newsock->sk);
80109 +
80110 out_put:
80111 fput_light(sock->file, fput_needed);
80112 out:
80113 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
80114 int, addrlen)
80115 {
80116 struct socket *sock;
80117 + struct sockaddr *sck;
80118 struct sockaddr_storage address;
80119 int err, fput_needed;
80120
80121 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
80122 if (err < 0)
80123 goto out_put;
80124
80125 + sck = (struct sockaddr *)&address;
80126 +
80127 + if (gr_handle_sock_client(sck)) {
80128 + err = -EACCES;
80129 + goto out_put;
80130 + }
80131 +
80132 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
80133 + if (err)
80134 + goto out_put;
80135 +
80136 err =
80137 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
80138 if (err)
80139 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
80140 * checking falls down on this.
80141 */
80142 if (copy_from_user(ctl_buf,
80143 - (void __user __force *)msg_sys->msg_control,
80144 + (void __force_user *)msg_sys->msg_control,
80145 ctl_len))
80146 goto out_freectl;
80147 msg_sys->msg_control = ctl_buf;
80148 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
80149 * kernel msghdr to use the kernel address space)
80150 */
80151
80152 - uaddr = (__force void __user *)msg_sys->msg_name;
80153 + uaddr = (void __force_user *)msg_sys->msg_name;
80154 uaddr_len = COMPAT_NAMELEN(msg);
80155 if (MSG_CMSG_COMPAT & flags) {
80156 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
80157 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
80158 }
80159
80160 ifr = compat_alloc_user_space(buf_size);
80161 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
80162 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
80163
80164 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
80165 return -EFAULT;
80166 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
80167 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
80168
80169 if (copy_in_user(rxnfc, compat_rxnfc,
80170 - (void *)(&rxnfc->fs.m_ext + 1) -
80171 - (void *)rxnfc) ||
80172 + (void __user *)(&rxnfc->fs.m_ext + 1) -
80173 + (void __user *)rxnfc) ||
80174 copy_in_user(&rxnfc->fs.ring_cookie,
80175 &compat_rxnfc->fs.ring_cookie,
80176 - (void *)(&rxnfc->fs.location + 1) -
80177 - (void *)&rxnfc->fs.ring_cookie) ||
80178 + (void __user *)(&rxnfc->fs.location + 1) -
80179 + (void __user *)&rxnfc->fs.ring_cookie) ||
80180 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
80181 sizeof(rxnfc->rule_cnt)))
80182 return -EFAULT;
80183 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
80184
80185 if (convert_out) {
80186 if (copy_in_user(compat_rxnfc, rxnfc,
80187 - (const void *)(&rxnfc->fs.m_ext + 1) -
80188 - (const void *)rxnfc) ||
80189 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
80190 + (const void __user *)rxnfc) ||
80191 copy_in_user(&compat_rxnfc->fs.ring_cookie,
80192 &rxnfc->fs.ring_cookie,
80193 - (const void *)(&rxnfc->fs.location + 1) -
80194 - (const void *)&rxnfc->fs.ring_cookie) ||
80195 + (const void __user *)(&rxnfc->fs.location + 1) -
80196 + (const void __user *)&rxnfc->fs.ring_cookie) ||
80197 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
80198 sizeof(rxnfc->rule_cnt)))
80199 return -EFAULT;
80200 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
80201 old_fs = get_fs();
80202 set_fs(KERNEL_DS);
80203 err = dev_ioctl(net, cmd,
80204 - (struct ifreq __user __force *) &kifr);
80205 + (struct ifreq __force_user *) &kifr);
80206 set_fs(old_fs);
80207
80208 return err;
80209 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
80210
80211 old_fs = get_fs();
80212 set_fs(KERNEL_DS);
80213 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
80214 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
80215 set_fs(old_fs);
80216
80217 if (cmd == SIOCGIFMAP && !err) {
80218 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
80219 ret |= __get_user(rtdev, &(ur4->rt_dev));
80220 if (rtdev) {
80221 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
80222 - r4.rt_dev = (char __user __force *)devname;
80223 + r4.rt_dev = (char __force_user *)devname;
80224 devname[15] = 0;
80225 } else
80226 r4.rt_dev = NULL;
80227 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
80228 int __user *uoptlen;
80229 int err;
80230
80231 - uoptval = (char __user __force *) optval;
80232 - uoptlen = (int __user __force *) optlen;
80233 + uoptval = (char __force_user *) optval;
80234 + uoptlen = (int __force_user *) optlen;
80235
80236 set_fs(KERNEL_DS);
80237 if (level == SOL_SOCKET)
80238 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
80239 char __user *uoptval;
80240 int err;
80241
80242 - uoptval = (char __user __force *) optval;
80243 + uoptval = (char __force_user *) optval;
80244
80245 set_fs(KERNEL_DS);
80246 if (level == SOL_SOCKET)
80247 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
80248 index 128494e..775d0e0 100644
80249 --- a/net/sunrpc/sched.c
80250 +++ b/net/sunrpc/sched.c
80251 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
80252 #ifdef RPC_DEBUG
80253 static void rpc_task_set_debuginfo(struct rpc_task *task)
80254 {
80255 - static atomic_t rpc_pid;
80256 + static atomic_unchecked_t rpc_pid;
80257
80258 - task->tk_pid = atomic_inc_return(&rpc_pid);
80259 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
80260 }
80261 #else
80262 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
80263 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
80264 index 8343737..677025e 100644
80265 --- a/net/sunrpc/xprtrdma/svc_rdma.c
80266 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
80267 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
80268 static unsigned int min_max_inline = 4096;
80269 static unsigned int max_max_inline = 65536;
80270
80271 -atomic_t rdma_stat_recv;
80272 -atomic_t rdma_stat_read;
80273 -atomic_t rdma_stat_write;
80274 -atomic_t rdma_stat_sq_starve;
80275 -atomic_t rdma_stat_rq_starve;
80276 -atomic_t rdma_stat_rq_poll;
80277 -atomic_t rdma_stat_rq_prod;
80278 -atomic_t rdma_stat_sq_poll;
80279 -atomic_t rdma_stat_sq_prod;
80280 +atomic_unchecked_t rdma_stat_recv;
80281 +atomic_unchecked_t rdma_stat_read;
80282 +atomic_unchecked_t rdma_stat_write;
80283 +atomic_unchecked_t rdma_stat_sq_starve;
80284 +atomic_unchecked_t rdma_stat_rq_starve;
80285 +atomic_unchecked_t rdma_stat_rq_poll;
80286 +atomic_unchecked_t rdma_stat_rq_prod;
80287 +atomic_unchecked_t rdma_stat_sq_poll;
80288 +atomic_unchecked_t rdma_stat_sq_prod;
80289
80290 /* Temporary NFS request map and context caches */
80291 struct kmem_cache *svc_rdma_map_cachep;
80292 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
80293 len -= *ppos;
80294 if (len > *lenp)
80295 len = *lenp;
80296 - if (len && copy_to_user(buffer, str_buf, len))
80297 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
80298 return -EFAULT;
80299 *lenp = len;
80300 *ppos += len;
80301 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
80302 {
80303 .procname = "rdma_stat_read",
80304 .data = &rdma_stat_read,
80305 - .maxlen = sizeof(atomic_t),
80306 + .maxlen = sizeof(atomic_unchecked_t),
80307 .mode = 0644,
80308 .proc_handler = read_reset_stat,
80309 },
80310 {
80311 .procname = "rdma_stat_recv",
80312 .data = &rdma_stat_recv,
80313 - .maxlen = sizeof(atomic_t),
80314 + .maxlen = sizeof(atomic_unchecked_t),
80315 .mode = 0644,
80316 .proc_handler = read_reset_stat,
80317 },
80318 {
80319 .procname = "rdma_stat_write",
80320 .data = &rdma_stat_write,
80321 - .maxlen = sizeof(atomic_t),
80322 + .maxlen = sizeof(atomic_unchecked_t),
80323 .mode = 0644,
80324 .proc_handler = read_reset_stat,
80325 },
80326 {
80327 .procname = "rdma_stat_sq_starve",
80328 .data = &rdma_stat_sq_starve,
80329 - .maxlen = sizeof(atomic_t),
80330 + .maxlen = sizeof(atomic_unchecked_t),
80331 .mode = 0644,
80332 .proc_handler = read_reset_stat,
80333 },
80334 {
80335 .procname = "rdma_stat_rq_starve",
80336 .data = &rdma_stat_rq_starve,
80337 - .maxlen = sizeof(atomic_t),
80338 + .maxlen = sizeof(atomic_unchecked_t),
80339 .mode = 0644,
80340 .proc_handler = read_reset_stat,
80341 },
80342 {
80343 .procname = "rdma_stat_rq_poll",
80344 .data = &rdma_stat_rq_poll,
80345 - .maxlen = sizeof(atomic_t),
80346 + .maxlen = sizeof(atomic_unchecked_t),
80347 .mode = 0644,
80348 .proc_handler = read_reset_stat,
80349 },
80350 {
80351 .procname = "rdma_stat_rq_prod",
80352 .data = &rdma_stat_rq_prod,
80353 - .maxlen = sizeof(atomic_t),
80354 + .maxlen = sizeof(atomic_unchecked_t),
80355 .mode = 0644,
80356 .proc_handler = read_reset_stat,
80357 },
80358 {
80359 .procname = "rdma_stat_sq_poll",
80360 .data = &rdma_stat_sq_poll,
80361 - .maxlen = sizeof(atomic_t),
80362 + .maxlen = sizeof(atomic_unchecked_t),
80363 .mode = 0644,
80364 .proc_handler = read_reset_stat,
80365 },
80366 {
80367 .procname = "rdma_stat_sq_prod",
80368 .data = &rdma_stat_sq_prod,
80369 - .maxlen = sizeof(atomic_t),
80370 + .maxlen = sizeof(atomic_unchecked_t),
80371 .mode = 0644,
80372 .proc_handler = read_reset_stat,
80373 },
80374 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
80375 index 41cb63b..c4a1489 100644
80376 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
80377 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
80378 @@ -501,7 +501,7 @@ next_sge:
80379 svc_rdma_put_context(ctxt, 0);
80380 goto out;
80381 }
80382 - atomic_inc(&rdma_stat_read);
80383 + atomic_inc_unchecked(&rdma_stat_read);
80384
80385 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
80386 chl_map->ch[ch_no].count -= read_wr.num_sge;
80387 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
80388 dto_q);
80389 list_del_init(&ctxt->dto_q);
80390 } else {
80391 - atomic_inc(&rdma_stat_rq_starve);
80392 + atomic_inc_unchecked(&rdma_stat_rq_starve);
80393 clear_bit(XPT_DATA, &xprt->xpt_flags);
80394 ctxt = NULL;
80395 }
80396 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
80397 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
80398 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
80399 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
80400 - atomic_inc(&rdma_stat_recv);
80401 + atomic_inc_unchecked(&rdma_stat_recv);
80402
80403 /* Build up the XDR from the receive buffers. */
80404 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
80405 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
80406 index 42eb7ba..c887c45 100644
80407 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
80408 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
80409 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
80410 write_wr.wr.rdma.remote_addr = to;
80411
80412 /* Post It */
80413 - atomic_inc(&rdma_stat_write);
80414 + atomic_inc_unchecked(&rdma_stat_write);
80415 if (svc_rdma_send(xprt, &write_wr))
80416 goto err;
80417 return 0;
80418 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
80419 index 73b428b..5f3f8f3 100644
80420 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
80421 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
80422 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
80423 return;
80424
80425 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
80426 - atomic_inc(&rdma_stat_rq_poll);
80427 + atomic_inc_unchecked(&rdma_stat_rq_poll);
80428
80429 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
80430 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
80431 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
80432 }
80433
80434 if (ctxt)
80435 - atomic_inc(&rdma_stat_rq_prod);
80436 + atomic_inc_unchecked(&rdma_stat_rq_prod);
80437
80438 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
80439 /*
80440 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
80441 return;
80442
80443 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
80444 - atomic_inc(&rdma_stat_sq_poll);
80445 + atomic_inc_unchecked(&rdma_stat_sq_poll);
80446 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
80447 if (wc.status != IB_WC_SUCCESS)
80448 /* Close the transport */
80449 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
80450 }
80451
80452 if (ctxt)
80453 - atomic_inc(&rdma_stat_sq_prod);
80454 + atomic_inc_unchecked(&rdma_stat_sq_prod);
80455 }
80456
80457 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
80458 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
80459 spin_lock_bh(&xprt->sc_lock);
80460 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
80461 spin_unlock_bh(&xprt->sc_lock);
80462 - atomic_inc(&rdma_stat_sq_starve);
80463 + atomic_inc_unchecked(&rdma_stat_sq_starve);
80464
80465 /* See if we can opportunistically reap SQ WR to make room */
80466 sq_cq_reap(xprt);
80467 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
80468 index e3a6e37..be2ea77 100644
80469 --- a/net/sysctl_net.c
80470 +++ b/net/sysctl_net.c
80471 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
80472 struct ctl_table *table)
80473 {
80474 /* Allow network administrator to have same access as root. */
80475 - if (capable(CAP_NET_ADMIN)) {
80476 + if (capable_nolog(CAP_NET_ADMIN)) {
80477 int mode = (table->mode >> 6) & 7;
80478 return (mode << 6) | (mode << 3) | mode;
80479 }
80480 diff --git a/net/tipc/link.c b/net/tipc/link.c
80481 index 1c1e615..113e0ae 100644
80482 --- a/net/tipc/link.c
80483 +++ b/net/tipc/link.c
80484 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
80485 struct tipc_msg fragm_hdr;
80486 struct sk_buff *buf, *buf_chain, *prev;
80487 u32 fragm_crs, fragm_rest, hsz, sect_rest;
80488 - const unchar *sect_crs;
80489 + const unchar __user *sect_crs;
80490 int curr_sect;
80491 u32 fragm_no;
80492
80493 @@ -1212,7 +1212,7 @@ again:
80494
80495 if (!sect_rest) {
80496 sect_rest = msg_sect[++curr_sect].iov_len;
80497 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
80498 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
80499 }
80500
80501 if (sect_rest < fragm_rest)
80502 @@ -1231,7 +1231,7 @@ error:
80503 }
80504 } else
80505 skb_copy_to_linear_data_offset(buf, fragm_crs,
80506 - sect_crs, sz);
80507 + (const void __force_kernel *)sect_crs, sz);
80508 sect_crs += sz;
80509 sect_rest -= sz;
80510 fragm_crs += sz;
80511 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
80512 index f2db8a8..9245aa4 100644
80513 --- a/net/tipc/msg.c
80514 +++ b/net/tipc/msg.c
80515 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
80516 msg_sect[cnt].iov_len);
80517 else
80518 skb_copy_to_linear_data_offset(*buf, pos,
80519 - msg_sect[cnt].iov_base,
80520 + (const void __force_kernel *)msg_sect[cnt].iov_base,
80521 msg_sect[cnt].iov_len);
80522 pos += msg_sect[cnt].iov_len;
80523 }
80524 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
80525 index 5ed5965..90abe34 100644
80526 --- a/net/tipc/subscr.c
80527 +++ b/net/tipc/subscr.c
80528 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
80529 {
80530 struct iovec msg_sect;
80531
80532 - msg_sect.iov_base = (void *)&sub->evt;
80533 + msg_sect.iov_base = (void __force_user *)&sub->evt;
80534 msg_sect.iov_len = sizeof(struct tipc_event);
80535
80536 sub->evt.event = htohl(event, sub->swap);
80537 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
80538 index c5ee4ff..e905948 100644
80539 --- a/net/unix/af_unix.c
80540 +++ b/net/unix/af_unix.c
80541 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
80542 err = -ECONNREFUSED;
80543 if (!S_ISSOCK(inode->i_mode))
80544 goto put_fail;
80545 +
80546 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
80547 + err = -EACCES;
80548 + goto put_fail;
80549 + }
80550 +
80551 u = unix_find_socket_byinode(inode);
80552 if (!u)
80553 goto put_fail;
80554 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
80555 if (u) {
80556 struct dentry *dentry;
80557 dentry = unix_sk(u)->path.dentry;
80558 +
80559 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
80560 + err = -EPERM;
80561 + sock_put(u);
80562 + goto fail;
80563 + }
80564 +
80565 if (dentry)
80566 touch_atime(&unix_sk(u)->path);
80567 } else
80568 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
80569 */
80570 err = security_path_mknod(&path, dentry, mode, 0);
80571 if (!err) {
80572 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
80573 + err = -EACCES;
80574 + goto out;
80575 + }
80576 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
80577 if (!err) {
80578 res->mnt = mntget(path.mnt);
80579 res->dentry = dget(dentry);
80580 + gr_handle_create(dentry, path.mnt);
80581 }
80582 }
80583 +out:
80584 done_path_create(&path, dentry);
80585 return err;
80586 }
80587 diff --git a/net/wireless/core.h b/net/wireless/core.h
80588 index bc7430b..35349de 100644
80589 --- a/net/wireless/core.h
80590 +++ b/net/wireless/core.h
80591 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
80592 struct mutex mtx;
80593
80594 /* rfkill support */
80595 - struct rfkill_ops rfkill_ops;
80596 + rfkill_ops_no_const rfkill_ops;
80597 struct rfkill *rfkill;
80598 struct work_struct rfkill_sync;
80599
80600 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
80601 index b0eb7aa..7d73e82 100644
80602 --- a/net/wireless/wext-core.c
80603 +++ b/net/wireless/wext-core.c
80604 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80605 */
80606
80607 /* Support for very large requests */
80608 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
80609 - (user_length > descr->max_tokens)) {
80610 + if (user_length > descr->max_tokens) {
80611 /* Allow userspace to GET more than max so
80612 * we can support any size GET requests.
80613 * There is still a limit : -ENOMEM.
80614 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80615 }
80616 }
80617
80618 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
80619 - /*
80620 - * If this is a GET, but not NOMAX, it means that the extra
80621 - * data is not bounded by userspace, but by max_tokens. Thus
80622 - * set the length to max_tokens. This matches the extra data
80623 - * allocation.
80624 - * The driver should fill it with the number of tokens it
80625 - * provided, and it may check iwp->length rather than having
80626 - * knowledge of max_tokens. If the driver doesn't change the
80627 - * iwp->length, this ioctl just copies back max_token tokens
80628 - * filled with zeroes. Hopefully the driver isn't claiming
80629 - * them to be valid data.
80630 - */
80631 - iwp->length = descr->max_tokens;
80632 - }
80633 -
80634 err = handler(dev, info, (union iwreq_data *) iwp, extra);
80635
80636 iwp->length += essid_compat;
80637 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
80638 index 387848e..a6667a2 100644
80639 --- a/net/xfrm/xfrm_policy.c
80640 +++ b/net/xfrm/xfrm_policy.c
80641 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
80642 {
80643 policy->walk.dead = 1;
80644
80645 - atomic_inc(&policy->genid);
80646 + atomic_inc_unchecked(&policy->genid);
80647
80648 if (del_timer(&policy->timer))
80649 xfrm_pol_put(policy);
80650 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
80651 hlist_add_head(&policy->bydst, chain);
80652 xfrm_pol_hold(policy);
80653 net->xfrm.policy_count[dir]++;
80654 - atomic_inc(&flow_cache_genid);
80655 + atomic_inc_unchecked(&flow_cache_genid);
80656 rt_genid_bump(net);
80657 if (delpol)
80658 __xfrm_policy_unlink(delpol, dir);
80659 @@ -1533,7 +1533,7 @@ free_dst:
80660 goto out;
80661 }
80662
80663 -static int inline
80664 +static inline int
80665 xfrm_dst_alloc_copy(void **target, const void *src, int size)
80666 {
80667 if (!*target) {
80668 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
80669 return 0;
80670 }
80671
80672 -static int inline
80673 +static inline int
80674 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80675 {
80676 #ifdef CONFIG_XFRM_SUB_POLICY
80677 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80678 #endif
80679 }
80680
80681 -static int inline
80682 +static inline int
80683 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
80684 {
80685 #ifdef CONFIG_XFRM_SUB_POLICY
80686 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
80687
80688 xdst->num_pols = num_pols;
80689 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
80690 - xdst->policy_genid = atomic_read(&pols[0]->genid);
80691 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
80692
80693 return xdst;
80694 }
80695 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
80696 if (xdst->xfrm_genid != dst->xfrm->genid)
80697 return 0;
80698 if (xdst->num_pols > 0 &&
80699 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
80700 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
80701 return 0;
80702
80703 mtu = dst_mtu(dst->child);
80704 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
80705 sizeof(pol->xfrm_vec[i].saddr));
80706 pol->xfrm_vec[i].encap_family = mp->new_family;
80707 /* flush bundles */
80708 - atomic_inc(&pol->genid);
80709 + atomic_inc_unchecked(&pol->genid);
80710 }
80711 }
80712
80713 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
80714 index ff1720d..ed8475e 100644
80715 --- a/scripts/Makefile.build
80716 +++ b/scripts/Makefile.build
80717 @@ -111,7 +111,7 @@ endif
80718 endif
80719
80720 # Do not include host rules unless needed
80721 -ifneq ($(hostprogs-y)$(hostprogs-m),)
80722 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
80723 include scripts/Makefile.host
80724 endif
80725
80726 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
80727 index 686cb0d..9d653bf 100644
80728 --- a/scripts/Makefile.clean
80729 +++ b/scripts/Makefile.clean
80730 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
80731 __clean-files := $(extra-y) $(always) \
80732 $(targets) $(clean-files) \
80733 $(host-progs) \
80734 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
80735 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
80736 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
80737
80738 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
80739
80740 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
80741 index 1ac414f..38575f7 100644
80742 --- a/scripts/Makefile.host
80743 +++ b/scripts/Makefile.host
80744 @@ -31,6 +31,8 @@
80745 # Note: Shared libraries consisting of C++ files are not supported
80746
80747 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
80748 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
80749 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
80750
80751 # C code
80752 # Executables compiled from a single .c file
80753 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
80754 # Shared libaries (only .c supported)
80755 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
80756 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
80757 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
80758 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
80759 # Remove .so files from "xxx-objs"
80760 host-cobjs := $(filter-out %.so,$(host-cobjs))
80761 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
80762
80763 -#Object (.o) files used by the shared libaries
80764 +# Object (.o) files used by the shared libaries
80765 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
80766 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
80767
80768 # output directory for programs/.o files
80769 # hostprogs-y := tools/build may have been specified. Retrieve directory
80770 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
80771 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
80772 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
80773 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
80774 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
80775 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
80776 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
80777 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
80778
80779 obj-dirs += $(host-objdirs)
80780 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
80781 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
80782 $(call if_changed_dep,host-cshobjs)
80783
80784 +# Compile .c file, create position independent .o file
80785 +# host-cxxshobjs -> .o
80786 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
80787 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
80788 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
80789 + $(call if_changed_dep,host-cxxshobjs)
80790 +
80791 # Link a shared library, based on position independent .o files
80792 # *.o -> .so shared library (host-cshlib)
80793 quiet_cmd_host-cshlib = HOSTLLD -shared $@
80794 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
80795 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
80796 $(call if_changed,host-cshlib)
80797
80798 +# Link a shared library, based on position independent .o files
80799 +# *.o -> .so shared library (host-cxxshlib)
80800 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
80801 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
80802 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
80803 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
80804 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
80805 + $(call if_changed,host-cxxshlib)
80806 +
80807 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
80808 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
80809 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
80810
80811 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
80812 index cb1f50c..cef2a7c 100644
80813 --- a/scripts/basic/fixdep.c
80814 +++ b/scripts/basic/fixdep.c
80815 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
80816 /*
80817 * Lookup a value in the configuration string.
80818 */
80819 -static int is_defined_config(const char *name, int len, unsigned int hash)
80820 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
80821 {
80822 struct item *aux;
80823
80824 @@ -211,10 +211,10 @@ static void clear_config(void)
80825 /*
80826 * Record the use of a CONFIG_* word.
80827 */
80828 -static void use_config(const char *m, int slen)
80829 +static void use_config(const char *m, unsigned int slen)
80830 {
80831 unsigned int hash = strhash(m, slen);
80832 - int c, i;
80833 + unsigned int c, i;
80834
80835 if (is_defined_config(m, slen, hash))
80836 return;
80837 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
80838
80839 static void parse_config_file(const char *map, size_t len)
80840 {
80841 - const int *end = (const int *) (map + len);
80842 + const unsigned int *end = (const unsigned int *) (map + len);
80843 /* start at +1, so that p can never be < map */
80844 - const int *m = (const int *) map + 1;
80845 + const unsigned int *m = (const unsigned int *) map + 1;
80846 const char *p, *q;
80847
80848 for (; m < end; m++) {
80849 @@ -406,7 +406,7 @@ static void print_deps(void)
80850 static void traps(void)
80851 {
80852 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
80853 - int *p = (int *)test;
80854 + unsigned int *p = (unsigned int *)test;
80855
80856 if (*p != INT_CONF) {
80857 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
80858 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
80859 new file mode 100644
80860 index 0000000..008ac1a
80861 --- /dev/null
80862 +++ b/scripts/gcc-plugin.sh
80863 @@ -0,0 +1,17 @@
80864 +#!/bin/bash
80865 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
80866 +#include "gcc-plugin.h"
80867 +#include "tree.h"
80868 +#include "tm.h"
80869 +#include "rtl.h"
80870 +#ifdef ENABLE_BUILD_WITH_CXX
80871 +#warning $2
80872 +#else
80873 +#warning $1
80874 +#endif
80875 +EOF`
80876 +if [ $? -eq 0 ]
80877 +then
80878 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
80879 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
80880 +fi
80881 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
80882 index b3d907e..a4782ab 100644
80883 --- a/scripts/link-vmlinux.sh
80884 +++ b/scripts/link-vmlinux.sh
80885 @@ -152,7 +152,7 @@ else
80886 fi;
80887
80888 # final build of init/
80889 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
80890 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
80891
80892 kallsymso=""
80893 kallsyms_vmlinux=""
80894 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
80895 index 7ed6864..b6e90e6 100644
80896 --- a/scripts/mod/file2alias.c
80897 +++ b/scripts/mod/file2alias.c
80898 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
80899 unsigned long size, unsigned long id_size,
80900 void *symval)
80901 {
80902 - int i;
80903 + unsigned int i;
80904
80905 if (size % id_size || size < id_size) {
80906 if (cross_build != 0)
80907 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
80908 /* USB is special because the bcdDevice can be matched against a numeric range */
80909 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
80910 static void do_usb_entry(struct usb_device_id *id,
80911 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
80912 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
80913 unsigned char range_lo, unsigned char range_hi,
80914 unsigned char max, struct module *mod)
80915 {
80916 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
80917 {
80918 unsigned int devlo, devhi;
80919 unsigned char chi, clo, max;
80920 - int ndigits;
80921 + unsigned int ndigits;
80922
80923 id->match_flags = TO_NATIVE(id->match_flags);
80924 id->idVendor = TO_NATIVE(id->idVendor);
80925 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
80926 for (i = 0; i < count; i++) {
80927 const char *id = (char *)devs[i].id;
80928 char acpi_id[sizeof(devs[0].id)];
80929 - int j;
80930 + unsigned int j;
80931
80932 buf_printf(&mod->dev_table_buf,
80933 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80934 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80935
80936 for (j = 0; j < PNP_MAX_DEVICES; j++) {
80937 const char *id = (char *)card->devs[j].id;
80938 - int i2, j2;
80939 + unsigned int i2, j2;
80940 int dup = 0;
80941
80942 if (!id[0])
80943 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80944 /* add an individual alias for every device entry */
80945 if (!dup) {
80946 char acpi_id[sizeof(card->devs[0].id)];
80947 - int k;
80948 + unsigned int k;
80949
80950 buf_printf(&mod->dev_table_buf,
80951 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80952 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
80953 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
80954 char *alias)
80955 {
80956 - int i, j;
80957 + unsigned int i, j;
80958
80959 sprintf(alias, "dmi*");
80960
80961 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
80962 index 68e9f5e..ac7759b 100644
80963 --- a/scripts/mod/modpost.c
80964 +++ b/scripts/mod/modpost.c
80965 @@ -930,6 +930,7 @@ enum mismatch {
80966 ANY_INIT_TO_ANY_EXIT,
80967 ANY_EXIT_TO_ANY_INIT,
80968 EXPORT_TO_INIT_EXIT,
80969 + DATA_TO_TEXT
80970 };
80971
80972 struct sectioncheck {
80973 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
80974 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
80975 .mismatch = EXPORT_TO_INIT_EXIT,
80976 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80977 +},
80978 +/* Do not reference code from writable data */
80979 +{
80980 + .fromsec = { DATA_SECTIONS, NULL },
80981 + .tosec = { TEXT_SECTIONS, NULL },
80982 + .mismatch = DATA_TO_TEXT
80983 }
80984 };
80985
80986 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80987 continue;
80988 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80989 continue;
80990 - if (sym->st_value == addr)
80991 - return sym;
80992 /* Find a symbol nearby - addr are maybe negative */
80993 d = sym->st_value - addr;
80994 + if (d == 0)
80995 + return sym;
80996 if (d < 0)
80997 d = addr - sym->st_value;
80998 if (d < distance) {
80999 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
81000 tosym, prl_to, prl_to, tosym);
81001 free(prl_to);
81002 break;
81003 + case DATA_TO_TEXT:
81004 +#if 0
81005 + fprintf(stderr,
81006 + "The %s %s:%s references\n"
81007 + "the %s %s:%s%s\n",
81008 + from, fromsec, fromsym, to, tosec, tosym, to_p);
81009 +#endif
81010 + break;
81011 }
81012 fprintf(stderr, "\n");
81013 }
81014 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
81015 static void check_sec_ref(struct module *mod, const char *modname,
81016 struct elf_info *elf)
81017 {
81018 - int i;
81019 + unsigned int i;
81020 Elf_Shdr *sechdrs = elf->sechdrs;
81021
81022 /* Walk through all sections */
81023 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
81024 va_end(ap);
81025 }
81026
81027 -void buf_write(struct buffer *buf, const char *s, int len)
81028 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
81029 {
81030 if (buf->size - buf->pos < len) {
81031 buf->size += len + SZ;
81032 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
81033 if (fstat(fileno(file), &st) < 0)
81034 goto close_write;
81035
81036 - if (st.st_size != b->pos)
81037 + if (st.st_size != (off_t)b->pos)
81038 goto close_write;
81039
81040 tmp = NOFAIL(malloc(b->pos));
81041 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
81042 index 51207e4..f7d603d 100644
81043 --- a/scripts/mod/modpost.h
81044 +++ b/scripts/mod/modpost.h
81045 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
81046
81047 struct buffer {
81048 char *p;
81049 - int pos;
81050 - int size;
81051 + unsigned int pos;
81052 + unsigned int size;
81053 };
81054
81055 void __attribute__((format(printf, 2, 3)))
81056 buf_printf(struct buffer *buf, const char *fmt, ...);
81057
81058 void
81059 -buf_write(struct buffer *buf, const char *s, int len);
81060 +buf_write(struct buffer *buf, const char *s, unsigned int len);
81061
81062 struct module {
81063 struct module *next;
81064 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
81065 index 9dfcd6d..099068e 100644
81066 --- a/scripts/mod/sumversion.c
81067 +++ b/scripts/mod/sumversion.c
81068 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
81069 goto out;
81070 }
81071
81072 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
81073 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
81074 warn("writing sum in %s failed: %s\n",
81075 filename, strerror(errno));
81076 goto out;
81077 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
81078 index 5c11312..72742b5 100644
81079 --- a/scripts/pnmtologo.c
81080 +++ b/scripts/pnmtologo.c
81081 @@ -237,14 +237,14 @@ static void write_header(void)
81082 fprintf(out, " * Linux logo %s\n", logoname);
81083 fputs(" */\n\n", out);
81084 fputs("#include <linux/linux_logo.h>\n\n", out);
81085 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
81086 + fprintf(out, "static unsigned char %s_data[] = {\n",
81087 logoname);
81088 }
81089
81090 static void write_footer(void)
81091 {
81092 fputs("\n};\n\n", out);
81093 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
81094 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
81095 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
81096 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
81097 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
81098 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
81099 fputs("\n};\n\n", out);
81100
81101 /* write logo clut */
81102 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
81103 + fprintf(out, "static unsigned char %s_clut[] = {\n",
81104 logoname);
81105 write_hex_cnt = 0;
81106 for (i = 0; i < logo_clutsize; i++) {
81107 diff --git a/security/Kconfig b/security/Kconfig
81108 index e9c6ac7..152c2e3 100644
81109 --- a/security/Kconfig
81110 +++ b/security/Kconfig
81111 @@ -4,6 +4,896 @@
81112
81113 menu "Security options"
81114
81115 +menu "Grsecurity"
81116 +
81117 + config ARCH_TRACK_EXEC_LIMIT
81118 + bool
81119 +
81120 + config PAX_KERNEXEC_PLUGIN
81121 + bool
81122 +
81123 + config PAX_PER_CPU_PGD
81124 + bool
81125 +
81126 + config TASK_SIZE_MAX_SHIFT
81127 + int
81128 + depends on X86_64
81129 + default 47 if !PAX_PER_CPU_PGD
81130 + default 42 if PAX_PER_CPU_PGD
81131 +
81132 + config PAX_ENABLE_PAE
81133 + bool
81134 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
81135 +
81136 + config PAX_USERCOPY_SLABS
81137 + bool
81138 +
81139 +config GRKERNSEC
81140 + bool "Grsecurity"
81141 + select CRYPTO
81142 + select CRYPTO_SHA256
81143 + select PROC_FS
81144 + select STOP_MACHINE
81145 + help
81146 + If you say Y here, you will be able to configure many features
81147 + that will enhance the security of your system. It is highly
81148 + recommended that you say Y here and read through the help
81149 + for each option so that you fully understand the features and
81150 + can evaluate their usefulness for your machine.
81151 +
81152 +choice
81153 + prompt "Configuration Method"
81154 + depends on GRKERNSEC
81155 + default GRKERNSEC_CONFIG_CUSTOM
81156 + help
81157 +
81158 +config GRKERNSEC_CONFIG_AUTO
81159 + bool "Automatic"
81160 + help
81161 + If you choose this configuration method, you'll be able to answer a small
81162 + number of simple questions about how you plan to use this kernel.
81163 + The settings of grsecurity and PaX will be automatically configured for
81164 + the highest commonly-used settings within the provided constraints.
81165 +
81166 + If you require additional configuration, custom changes can still be made
81167 + from the "custom configuration" menu.
81168 +
81169 +config GRKERNSEC_CONFIG_CUSTOM
81170 + bool "Custom"
81171 + help
81172 + If you choose this configuration method, you'll be able to configure all
81173 + grsecurity and PaX settings manually. Via this method, no options are
81174 + automatically enabled.
81175 +
81176 +endchoice
81177 +
81178 +choice
81179 + prompt "Usage Type"
81180 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
81181 + default GRKERNSEC_CONFIG_SERVER
81182 + help
81183 +
81184 +config GRKERNSEC_CONFIG_SERVER
81185 + bool "Server"
81186 + help
81187 + Choose this option if you plan to use this kernel on a server.
81188 +
81189 +config GRKERNSEC_CONFIG_DESKTOP
81190 + bool "Desktop"
81191 + help
81192 + Choose this option if you plan to use this kernel on a desktop.
81193 +
81194 +endchoice
81195 +
81196 +choice
81197 + prompt "Virtualization Type"
81198 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
81199 + default GRKERNSEC_CONFIG_VIRT_NONE
81200 + help
81201 +
81202 +config GRKERNSEC_CONFIG_VIRT_NONE
81203 + bool "None"
81204 + help
81205 + Choose this option if this kernel will be run on bare metal.
81206 +
81207 +config GRKERNSEC_CONFIG_VIRT_GUEST
81208 + bool "Guest"
81209 + help
81210 + Choose this option if this kernel will be run as a VM guest.
81211 +
81212 +config GRKERNSEC_CONFIG_VIRT_HOST
81213 + bool "Host"
81214 + help
81215 + Choose this option if this kernel will be run as a VM host.
81216 +
81217 +endchoice
81218 +
81219 +choice
81220 + prompt "Virtualization Hardware"
81221 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
81222 + help
81223 +
81224 +config GRKERNSEC_CONFIG_VIRT_EPT
81225 + bool "EPT/RVI Processor Support"
81226 + depends on X86
81227 + help
81228 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
81229 + hardware virtualization. This allows for additional kernel hardening protections
81230 + to operate without additional performance impact.
81231 +
81232 + To see if your Intel processor supports EPT, see:
81233 + http://ark.intel.com/Products/VirtualizationTechnology
81234 + (Most Core i3/5/7 support EPT)
81235 +
81236 + To see if your AMD processor supports RVI, see:
81237 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
81238 +
81239 +config GRKERNSEC_CONFIG_VIRT_SOFT
81240 + bool "First-gen/No Hardware Virtualization"
81241 + help
81242 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
81243 + support hardware virtualization or doesn't support the EPT/RVI extensions.
81244 +
81245 +endchoice
81246 +
81247 +choice
81248 + prompt "Virtualization Software"
81249 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
81250 + help
81251 +
81252 +config GRKERNSEC_CONFIG_VIRT_XEN
81253 + bool "Xen"
81254 + help
81255 + Choose this option if this kernel is running as a Xen guest or host.
81256 +
81257 +config GRKERNSEC_CONFIG_VIRT_VMWARE
81258 + bool "VMWare"
81259 + help
81260 + Choose this option if this kernel is running as a VMWare guest or host.
81261 +
81262 +config GRKERNSEC_CONFIG_VIRT_KVM
81263 + bool "KVM"
81264 + help
81265 + Choose this option if this kernel is running as a KVM guest or host.
81266 +
81267 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
81268 + bool "VirtualBox"
81269 + help
81270 + Choose this option if this kernel is running as a VirtualBox guest or host.
81271 +
81272 +endchoice
81273 +
81274 +choice
81275 + prompt "Required Priorities"
81276 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
81277 + default GRKERNSEC_CONFIG_PRIORITY_PERF
81278 + help
81279 +
81280 +config GRKERNSEC_CONFIG_PRIORITY_PERF
81281 + bool "Performance"
81282 + help
81283 + Choose this option if performance is of highest priority for this deployment
81284 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
81285 + and freed memory sanitizing will be disabled.
81286 +
81287 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
81288 + bool "Security"
81289 + help
81290 + Choose this option if security is of highest priority for this deployment of
81291 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
81292 + be enabled for this kernel. In a worst-case scenario, these features can
81293 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
81294 +
81295 +endchoice
81296 +
81297 +menu "Default Special Groups"
81298 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
81299 +
81300 +config GRKERNSEC_PROC_GID
81301 + int "GID exempted from /proc restrictions"
81302 + default 1001
81303 + help
81304 + Setting this GID determines which group will be exempted from
81305 + grsecurity's /proc restrictions, allowing users of the specified
81306 + group to view network statistics and the existence of other users'
81307 + processes on the system. This GID may also be chosen at boot time
81308 + via "grsec_proc_gid=" on the kernel commandline.
81309 +
81310 +config GRKERNSEC_TPE_UNTRUSTED_GID
81311 + int "GID for TPE-untrusted users"
81312 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
81313 + default 1005
81314 + help
81315 + Setting this GID determines which group untrusted users should
81316 + be added to. These users will be placed under grsecurity's Trusted Path
81317 + Execution mechanism, preventing them from executing their own binaries.
81318 + The users will only be able to execute binaries in directories owned and
81319 + writable only by the root user. If the sysctl option is enabled, a sysctl
81320 + option with name "tpe_gid" is created.
81321 +
81322 +config GRKERNSEC_TPE_TRUSTED_GID
81323 + int "GID for TPE-trusted users"
81324 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
81325 + default 1005
81326 + help
81327 + Setting this GID determines what group TPE restrictions will be
81328 + *disabled* for. If the sysctl option is enabled, a sysctl option
81329 + with name "tpe_gid" is created.
81330 +
81331 +config GRKERNSEC_SYMLINKOWN_GID
81332 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
81333 + depends on GRKERNSEC_CONFIG_SERVER
81334 + default 1006
81335 + help
81336 + Setting this GID determines what group kernel-enforced
81337 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
81338 + is enabled, a sysctl option with name "symlinkown_gid" is created.
81339 +
81340 +
81341 +endmenu
81342 +
81343 +menu "Customize Configuration"
81344 +depends on GRKERNSEC
81345 +
81346 +menu "PaX"
81347 +
81348 +config PAX
81349 + bool "Enable various PaX features"
81350 + default y if GRKERNSEC_CONFIG_AUTO
81351 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
81352 + help
81353 + This allows you to enable various PaX features. PaX adds
81354 + intrusion prevention mechanisms to the kernel that reduce
81355 + the risks posed by exploitable memory corruption bugs.
81356 +
81357 +menu "PaX Control"
81358 + depends on PAX
81359 +
81360 +config PAX_SOFTMODE
81361 + bool 'Support soft mode'
81362 + help
81363 + Enabling this option will allow you to run PaX in soft mode, that
81364 + is, PaX features will not be enforced by default, only on executables
81365 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
81366 + support as they are the only way to mark executables for soft mode use.
81367 +
81368 + Soft mode can be activated by using the "pax_softmode=1" kernel command
81369 + line option on boot. Furthermore you can control various PaX features
81370 + at runtime via the entries in /proc/sys/kernel/pax.
81371 +
81372 +config PAX_EI_PAX
81373 + bool 'Use legacy ELF header marking'
81374 + default y if GRKERNSEC_CONFIG_AUTO
81375 + help
81376 + Enabling this option will allow you to control PaX features on
81377 + a per executable basis via the 'chpax' utility available at
81378 + http://pax.grsecurity.net/. The control flags will be read from
81379 + an otherwise reserved part of the ELF header. This marking has
81380 + numerous drawbacks (no support for soft-mode, toolchain does not
81381 + know about the non-standard use of the ELF header) therefore it
81382 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
81383 + support.
81384 +
81385 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
81386 + support as well, they will override the legacy EI_PAX marks.
81387 +
81388 + If you enable none of the marking options then all applications
81389 + will run with PaX enabled on them by default.
81390 +
81391 +config PAX_PT_PAX_FLAGS
81392 + bool 'Use ELF program header marking'
81393 + default y if GRKERNSEC_CONFIG_AUTO
81394 + help
81395 + Enabling this option will allow you to control PaX features on
81396 + a per executable basis via the 'paxctl' utility available at
81397 + http://pax.grsecurity.net/. The control flags will be read from
81398 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
81399 + has the benefits of supporting both soft mode and being fully
81400 + integrated into the toolchain (the binutils patch is available
81401 + from http://pax.grsecurity.net).
81402 +
81403 + Note that if you enable the legacy EI_PAX marking support as well,
81404 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
81405 +
81406 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
81407 + must make sure that the marks are the same if a binary has both marks.
81408 +
81409 + If you enable none of the marking options then all applications
81410 + will run with PaX enabled on them by default.
81411 +
81412 +config PAX_XATTR_PAX_FLAGS
81413 + bool 'Use filesystem extended attributes marking'
81414 + default y if GRKERNSEC_CONFIG_AUTO
81415 + select CIFS_XATTR if CIFS
81416 + select EXT2_FS_XATTR if EXT2_FS
81417 + select EXT3_FS_XATTR if EXT3_FS
81418 + select EXT4_FS_XATTR if EXT4_FS
81419 + select JFFS2_FS_XATTR if JFFS2_FS
81420 + select REISERFS_FS_XATTR if REISERFS_FS
81421 + select SQUASHFS_XATTR if SQUASHFS
81422 + select TMPFS_XATTR if TMPFS
81423 + select UBIFS_FS_XATTR if UBIFS_FS
81424 + help
81425 + Enabling this option will allow you to control PaX features on
81426 + a per executable basis via the 'setfattr' utility. The control
81427 + flags will be read from the user.pax.flags extended attribute of
81428 + the file. This marking has the benefit of supporting binary-only
81429 + applications that self-check themselves (e.g., skype) and would
81430 + not tolerate chpax/paxctl changes. The main drawback is that
81431 + extended attributes are not supported by some filesystems (e.g.,
81432 + isofs, udf, vfat) so copying files through such filesystems will
81433 + lose the extended attributes and these PaX markings.
81434 +
81435 + Note that if you enable the legacy EI_PAX marking support as well,
81436 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
81437 +
81438 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
81439 + must make sure that the marks are the same if a binary has both marks.
81440 +
81441 + If you enable none of the marking options then all applications
81442 + will run with PaX enabled on them by default.
81443 +
81444 +choice
81445 + prompt 'MAC system integration'
81446 + default PAX_HAVE_ACL_FLAGS
81447 + help
81448 + Mandatory Access Control systems have the option of controlling
81449 + PaX flags on a per executable basis, choose the method supported
81450 + by your particular system.
81451 +
81452 + - "none": if your MAC system does not interact with PaX,
81453 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
81454 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
81455 +
81456 + NOTE: this option is for developers/integrators only.
81457 +
81458 + config PAX_NO_ACL_FLAGS
81459 + bool 'none'
81460 +
81461 + config PAX_HAVE_ACL_FLAGS
81462 + bool 'direct'
81463 +
81464 + config PAX_HOOK_ACL_FLAGS
81465 + bool 'hook'
81466 +endchoice
81467 +
81468 +endmenu
81469 +
81470 +menu "Non-executable pages"
81471 + depends on PAX
81472 +
81473 +config PAX_NOEXEC
81474 + bool "Enforce non-executable pages"
81475 + default y if GRKERNSEC_CONFIG_AUTO
81476 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
81477 + help
81478 + By design some architectures do not allow for protecting memory
81479 + pages against execution or even if they do, Linux does not make
81480 + use of this feature. In practice this means that if a page is
81481 + readable (such as the stack or heap) it is also executable.
81482 +
81483 + There is a well known exploit technique that makes use of this
81484 + fact and a common programming mistake where an attacker can
81485 + introduce code of his choice somewhere in the attacked program's
81486 + memory (typically the stack or the heap) and then execute it.
81487 +
81488 + If the attacked program was running with different (typically
81489 + higher) privileges than that of the attacker, then he can elevate
81490 + his own privilege level (e.g. get a root shell, write to files for
81491 + which he does not have write access to, etc).
81492 +
81493 + Enabling this option will let you choose from various features
81494 + that prevent the injection and execution of 'foreign' code in
81495 + a program.
81496 +
81497 + This will also break programs that rely on the old behaviour and
81498 + expect that dynamically allocated memory via the malloc() family
81499 + of functions is executable (which it is not). Notable examples
81500 + are the XFree86 4.x server, the java runtime and wine.
81501 +
81502 +config PAX_PAGEEXEC
81503 + bool "Paging based non-executable pages"
81504 + default y if GRKERNSEC_CONFIG_AUTO
81505 + 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)
81506 + select S390_SWITCH_AMODE if S390
81507 + select S390_EXEC_PROTECT if S390
81508 + select ARCH_TRACK_EXEC_LIMIT if X86_32
81509 + help
81510 + This implementation is based on the paging feature of the CPU.
81511 + On i386 without hardware non-executable bit support there is a
81512 + variable but usually low performance impact, however on Intel's
81513 + P4 core based CPUs it is very high so you should not enable this
81514 + for kernels meant to be used on such CPUs.
81515 +
81516 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
81517 + with hardware non-executable bit support there is no performance
81518 + impact, on ppc the impact is negligible.
81519 +
81520 + Note that several architectures require various emulations due to
81521 + badly designed userland ABIs, this will cause a performance impact
81522 + but will disappear as soon as userland is fixed. For example, ppc
81523 + userland MUST have been built with secure-plt by a recent toolchain.
81524 +
81525 +config PAX_SEGMEXEC
81526 + bool "Segmentation based non-executable pages"
81527 + default y if GRKERNSEC_CONFIG_AUTO
81528 + depends on PAX_NOEXEC && X86_32
81529 + help
81530 + This implementation is based on the segmentation feature of the
81531 + CPU and has a very small performance impact, however applications
81532 + will be limited to a 1.5 GB address space instead of the normal
81533 + 3 GB.
81534 +
81535 +config PAX_EMUTRAMP
81536 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
81537 + default y if PARISC
81538 + help
81539 + There are some programs and libraries that for one reason or
81540 + another attempt to execute special small code snippets from
81541 + non-executable memory pages. Most notable examples are the
81542 + signal handler return code generated by the kernel itself and
81543 + the GCC trampolines.
81544 +
81545 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
81546 + such programs will no longer work under your kernel.
81547 +
81548 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
81549 + utilities to enable trampoline emulation for the affected programs
81550 + yet still have the protection provided by the non-executable pages.
81551 +
81552 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
81553 + your system will not even boot.
81554 +
81555 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
81556 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
81557 + for the affected files.
81558 +
81559 + NOTE: enabling this feature *may* open up a loophole in the
81560 + protection provided by non-executable pages that an attacker
81561 + could abuse. Therefore the best solution is to not have any
81562 + files on your system that would require this option. This can
81563 + be achieved by not using libc5 (which relies on the kernel
81564 + signal handler return code) and not using or rewriting programs
81565 + that make use of the nested function implementation of GCC.
81566 + Skilled users can just fix GCC itself so that it implements
81567 + nested function calls in a way that does not interfere with PaX.
81568 +
81569 +config PAX_EMUSIGRT
81570 + bool "Automatically emulate sigreturn trampolines"
81571 + depends on PAX_EMUTRAMP && PARISC
81572 + default y
81573 + help
81574 + Enabling this option will have the kernel automatically detect
81575 + and emulate signal return trampolines executing on the stack
81576 + that would otherwise lead to task termination.
81577 +
81578 + This solution is intended as a temporary one for users with
81579 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
81580 + Modula-3 runtime, etc) or executables linked to such, basically
81581 + everything that does not specify its own SA_RESTORER function in
81582 + normal executable memory like glibc 2.1+ does.
81583 +
81584 + On parisc you MUST enable this option, otherwise your system will
81585 + not even boot.
81586 +
81587 + NOTE: this feature cannot be disabled on a per executable basis
81588 + and since it *does* open up a loophole in the protection provided
81589 + by non-executable pages, the best solution is to not have any
81590 + files on your system that would require this option.
81591 +
81592 +config PAX_MPROTECT
81593 + bool "Restrict mprotect()"
81594 + default y if GRKERNSEC_CONFIG_AUTO
81595 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
81596 + help
81597 + Enabling this option will prevent programs from
81598 + - changing the executable status of memory pages that were
81599 + not originally created as executable,
81600 + - making read-only executable pages writable again,
81601 + - creating executable pages from anonymous memory,
81602 + - making read-only-after-relocations (RELRO) data pages writable again.
81603 +
81604 + You should say Y here to complete the protection provided by
81605 + the enforcement of non-executable pages.
81606 +
81607 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81608 + this feature on a per file basis.
81609 +
81610 +config PAX_MPROTECT_COMPAT
81611 + bool "Use legacy/compat protection demoting (read help)"
81612 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81613 + depends on PAX_MPROTECT
81614 + help
81615 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
81616 + by sending the proper error code to the application. For some broken
81617 + userland, this can cause problems with Python or other applications. The
81618 + current implementation however allows for applications like clamav to
81619 + detect if JIT compilation/execution is allowed and to fall back gracefully
81620 + to an interpreter-based mode if it does not. While we encourage everyone
81621 + to use the current implementation as-is and push upstream to fix broken
81622 + userland (note that the RWX logging option can assist with this), in some
81623 + environments this may not be possible. Having to disable MPROTECT
81624 + completely on certain binaries reduces the security benefit of PaX,
81625 + so this option is provided for those environments to revert to the old
81626 + behavior.
81627 +
81628 +config PAX_ELFRELOCS
81629 + bool "Allow ELF text relocations (read help)"
81630 + depends on PAX_MPROTECT
81631 + default n
81632 + help
81633 + Non-executable pages and mprotect() restrictions are effective
81634 + in preventing the introduction of new executable code into an
81635 + attacked task's address space. There remain only two venues
81636 + for this kind of attack: if the attacker can execute already
81637 + existing code in the attacked task then he can either have it
81638 + create and mmap() a file containing his code or have it mmap()
81639 + an already existing ELF library that does not have position
81640 + independent code in it and use mprotect() on it to make it
81641 + writable and copy his code there. While protecting against
81642 + the former approach is beyond PaX, the latter can be prevented
81643 + by having only PIC ELF libraries on one's system (which do not
81644 + need to relocate their code). If you are sure this is your case,
81645 + as is the case with all modern Linux distributions, then leave
81646 + this option disabled. You should say 'n' here.
81647 +
81648 +config PAX_ETEXECRELOCS
81649 + bool "Allow ELF ET_EXEC text relocations"
81650 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
81651 + select PAX_ELFRELOCS
81652 + default y
81653 + help
81654 + On some architectures there are incorrectly created applications
81655 + that require text relocations and would not work without enabling
81656 + this option. If you are an alpha, ia64 or parisc user, you should
81657 + enable this option and disable it once you have made sure that
81658 + none of your applications need it.
81659 +
81660 +config PAX_EMUPLT
81661 + bool "Automatically emulate ELF PLT"
81662 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
81663 + default y
81664 + help
81665 + Enabling this option will have the kernel automatically detect
81666 + and emulate the Procedure Linkage Table entries in ELF files.
81667 + On some architectures such entries are in writable memory, and
81668 + become non-executable leading to task termination. Therefore
81669 + it is mandatory that you enable this option on alpha, parisc,
81670 + sparc and sparc64, otherwise your system would not even boot.
81671 +
81672 + NOTE: this feature *does* open up a loophole in the protection
81673 + provided by the non-executable pages, therefore the proper
81674 + solution is to modify the toolchain to produce a PLT that does
81675 + not need to be writable.
81676 +
81677 +config PAX_DLRESOLVE
81678 + bool 'Emulate old glibc resolver stub'
81679 + depends on PAX_EMUPLT && SPARC
81680 + default n
81681 + help
81682 + This option is needed if userland has an old glibc (before 2.4)
81683 + that puts a 'save' instruction into the runtime generated resolver
81684 + stub that needs special emulation.
81685 +
81686 +config PAX_KERNEXEC
81687 + bool "Enforce non-executable kernel pages"
81688 + 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))
81689 + depends on X86 && (!X86_32 || X86_WP_WORKS_OK) && !XEN
81690 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
81691 + select PAX_KERNEXEC_PLUGIN if X86_64
81692 + help
81693 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
81694 + that is, enabling this option will make it harder to inject
81695 + and execute 'foreign' code in kernel memory itself.
81696 +
81697 +choice
81698 + prompt "Return Address Instrumentation Method"
81699 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
81700 + depends on PAX_KERNEXEC_PLUGIN
81701 + help
81702 + Select the method used to instrument function pointer dereferences.
81703 + Note that binary modules cannot be instrumented by this approach.
81704 +
81705 + Note that the implementation requires a gcc with plugin support,
81706 + i.e., gcc 4.5 or newer. You may need to install the supporting
81707 + headers explicitly in addition to the normal gcc package.
81708 +
81709 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
81710 + bool "bts"
81711 + help
81712 + This method is compatible with binary only modules but has
81713 + a higher runtime overhead.
81714 +
81715 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
81716 + bool "or"
81717 + depends on !PARAVIRT
81718 + help
81719 + This method is incompatible with binary only modules but has
81720 + a lower runtime overhead.
81721 +endchoice
81722 +
81723 +config PAX_KERNEXEC_PLUGIN_METHOD
81724 + string
81725 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
81726 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
81727 + default ""
81728 +
81729 +config PAX_KERNEXEC_MODULE_TEXT
81730 + int "Minimum amount of memory reserved for module code"
81731 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
81732 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81733 + depends on PAX_KERNEXEC && X86_32 && MODULES
81734 + help
81735 + Due to implementation details the kernel must reserve a fixed
81736 + amount of memory for module code at compile time that cannot be
81737 + changed at runtime. Here you can specify the minimum amount
81738 + in MB that will be reserved. Due to the same implementation
81739 + details this size will always be rounded up to the next 2/4 MB
81740 + boundary (depends on PAE) so the actually available memory for
81741 + module code will usually be more than this minimum.
81742 +
81743 + The default 4 MB should be enough for most users but if you have
81744 + an excessive number of modules (e.g., most distribution configs
81745 + compile many drivers as modules) or use huge modules such as
81746 + nvidia's kernel driver, you will need to adjust this amount.
81747 + A good rule of thumb is to look at your currently loaded kernel
81748 + modules and add up their sizes.
81749 +
81750 +endmenu
81751 +
81752 +menu "Address Space Layout Randomization"
81753 + depends on PAX
81754 +
81755 +config PAX_ASLR
81756 + bool "Address Space Layout Randomization"
81757 + default y if GRKERNSEC_CONFIG_AUTO
81758 + help
81759 + Many if not most exploit techniques rely on the knowledge of
81760 + certain addresses in the attacked program. The following options
81761 + will allow the kernel to apply a certain amount of randomization
81762 + to specific parts of the program thereby forcing an attacker to
81763 + guess them in most cases. Any failed guess will most likely crash
81764 + the attacked program which allows the kernel to detect such attempts
81765 + and react on them. PaX itself provides no reaction mechanisms,
81766 + instead it is strongly encouraged that you make use of Nergal's
81767 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
81768 + (http://www.grsecurity.net/) built-in crash detection features or
81769 + develop one yourself.
81770 +
81771 + By saying Y here you can choose to randomize the following areas:
81772 + - top of the task's kernel stack
81773 + - top of the task's userland stack
81774 + - base address for mmap() requests that do not specify one
81775 + (this includes all libraries)
81776 + - base address of the main executable
81777 +
81778 + It is strongly recommended to say Y here as address space layout
81779 + randomization has negligible impact on performance yet it provides
81780 + a very effective protection.
81781 +
81782 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81783 + this feature on a per file basis.
81784 +
81785 +config PAX_RANDKSTACK
81786 + bool "Randomize kernel stack base"
81787 + default y if GRKERNSEC_CONFIG_AUTO
81788 + depends on X86_TSC && X86
81789 + help
81790 + By saying Y here the kernel will randomize every task's kernel
81791 + stack on every system call. This will not only force an attacker
81792 + to guess it but also prevent him from making use of possible
81793 + leaked information about it.
81794 +
81795 + Since the kernel stack is a rather scarce resource, randomization
81796 + may cause unexpected stack overflows, therefore you should very
81797 + carefully test your system. Note that once enabled in the kernel
81798 + configuration, this feature cannot be disabled on a per file basis.
81799 +
81800 +config PAX_RANDUSTACK
81801 + bool "Randomize user stack base"
81802 + default y if GRKERNSEC_CONFIG_AUTO
81803 + depends on PAX_ASLR
81804 + help
81805 + By saying Y here the kernel will randomize every task's userland
81806 + stack. The randomization is done in two steps where the second
81807 + one may apply a big amount of shift to the top of the stack and
81808 + cause problems for programs that want to use lots of memory (more
81809 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
81810 + For this reason the second step can be controlled by 'chpax' or
81811 + 'paxctl' on a per file basis.
81812 +
81813 +config PAX_RANDMMAP
81814 + bool "Randomize mmap() base"
81815 + default y if GRKERNSEC_CONFIG_AUTO
81816 + depends on PAX_ASLR
81817 + help
81818 + By saying Y here the kernel will use a randomized base address for
81819 + mmap() requests that do not specify one themselves. As a result
81820 + all dynamically loaded libraries will appear at random addresses
81821 + and therefore be harder to exploit by a technique where an attacker
81822 + attempts to execute library code for his purposes (e.g. spawn a
81823 + shell from an exploited program that is running at an elevated
81824 + privilege level).
81825 +
81826 + Furthermore, if a program is relinked as a dynamic ELF file, its
81827 + base address will be randomized as well, completing the full
81828 + randomization of the address space layout. Attacking such programs
81829 + becomes a guess game. You can find an example of doing this at
81830 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
81831 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
81832 +
81833 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
81834 + feature on a per file basis.
81835 +
81836 +endmenu
81837 +
81838 +menu "Miscellaneous hardening features"
81839 +
81840 +config PAX_MEMORY_SANITIZE
81841 + bool "Sanitize all freed memory"
81842 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81843 + depends on !HIBERNATION
81844 + help
81845 + By saying Y here the kernel will erase memory pages as soon as they
81846 + are freed. This in turn reduces the lifetime of data stored in the
81847 + pages, making it less likely that sensitive information such as
81848 + passwords, cryptographic secrets, etc stay in memory for too long.
81849 +
81850 + This is especially useful for programs whose runtime is short, long
81851 + lived processes and the kernel itself benefit from this as long as
81852 + they operate on whole memory pages and ensure timely freeing of pages
81853 + that may hold sensitive information.
81854 +
81855 + The tradeoff is performance impact, on a single CPU system kernel
81856 + compilation sees a 3% slowdown, other systems and workloads may vary
81857 + and you are advised to test this feature on your expected workload
81858 + before deploying it.
81859 +
81860 + Note that this feature does not protect data stored in live pages,
81861 + e.g., process memory swapped to disk may stay there for a long time.
81862 +
81863 +config PAX_MEMORY_STACKLEAK
81864 + bool "Sanitize kernel stack"
81865 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81866 + depends on X86
81867 + help
81868 + By saying Y here the kernel will erase the kernel stack before it
81869 + returns from a system call. This in turn reduces the information
81870 + that a kernel stack leak bug can reveal.
81871 +
81872 + Note that such a bug can still leak information that was put on
81873 + the stack by the current system call (the one eventually triggering
81874 + the bug) but traces of earlier system calls on the kernel stack
81875 + cannot leak anymore.
81876 +
81877 + The tradeoff is performance impact: on a single CPU system kernel
81878 + compilation sees a 1% slowdown, other systems and workloads may vary
81879 + and you are advised to test this feature on your expected workload
81880 + before deploying it.
81881 +
81882 + Note that the full feature requires a gcc with plugin support,
81883 + i.e., gcc 4.5 or newer. You may need to install the supporting
81884 + headers explicitly in addition to the normal gcc package. Using
81885 + older gcc versions means that functions with large enough stack
81886 + frames may leave uninitialized memory behind that may be exposed
81887 + to a later syscall leaking the stack.
81888 +
81889 +config PAX_MEMORY_UDEREF
81890 + bool "Prevent invalid userland pointer dereference"
81891 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
81892 + depends on X86 && !UML_X86 && !XEN
81893 + select PAX_PER_CPU_PGD if X86_64
81894 + help
81895 + By saying Y here the kernel will be prevented from dereferencing
81896 + userland pointers in contexts where the kernel expects only kernel
81897 + pointers. This is both a useful runtime debugging feature and a
81898 + security measure that prevents exploiting a class of kernel bugs.
81899 +
81900 + The tradeoff is that some virtualization solutions may experience
81901 + a huge slowdown and therefore you should not enable this feature
81902 + for kernels meant to run in such environments. Whether a given VM
81903 + solution is affected or not is best determined by simply trying it
81904 + out, the performance impact will be obvious right on boot as this
81905 + mechanism engages from very early on. A good rule of thumb is that
81906 + VMs running on CPUs without hardware virtualization support (i.e.,
81907 + the majority of IA-32 CPUs) will likely experience the slowdown.
81908 +
81909 +config PAX_REFCOUNT
81910 + bool "Prevent various kernel object reference counter overflows"
81911 + default y if GRKERNSEC_CONFIG_AUTO
81912 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
81913 + help
81914 + By saying Y here the kernel will detect and prevent overflowing
81915 + various (but not all) kinds of object reference counters. Such
81916 + overflows can normally occur due to bugs only and are often, if
81917 + not always, exploitable.
81918 +
81919 + The tradeoff is that data structures protected by an overflowed
81920 + refcount will never be freed and therefore will leak memory. Note
81921 + that this leak also happens even without this protection but in
81922 + that case the overflow can eventually trigger the freeing of the
81923 + data structure while it is still being used elsewhere, resulting
81924 + in the exploitable situation that this feature prevents.
81925 +
81926 + Since this has a negligible performance impact, you should enable
81927 + this feature.
81928 +
81929 +config PAX_USERCOPY
81930 + bool "Harden heap object copies between kernel and userland"
81931 + default y if GRKERNSEC_CONFIG_AUTO
81932 + depends on X86 || PPC || SPARC || ARM
81933 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
81934 + select PAX_USERCOPY_SLABS
81935 + help
81936 + By saying Y here the kernel will enforce the size of heap objects
81937 + when they are copied in either direction between the kernel and
81938 + userland, even if only a part of the heap object is copied.
81939 +
81940 + Specifically, this checking prevents information leaking from the
81941 + kernel heap during kernel to userland copies (if the kernel heap
81942 + object is otherwise fully initialized) and prevents kernel heap
81943 + overflows during userland to kernel copies.
81944 +
81945 + Note that the current implementation provides the strictest bounds
81946 + checks for the SLUB allocator.
81947 +
81948 + Enabling this option also enables per-slab cache protection against
81949 + data in a given cache being copied into/out of via userland
81950 + accessors. Though the whitelist of regions will be reduced over
81951 + time, it notably protects important data structures like task structs.
81952 +
81953 + If frame pointers are enabled on x86, this option will also restrict
81954 + copies into and out of the kernel stack to local variables within a
81955 + single frame.
81956 +
81957 + Since this has a negligible performance impact, you should enable
81958 + this feature.
81959 +
81960 +config PAX_SIZE_OVERFLOW
81961 + bool "Prevent various integer overflows in function size parameters"
81962 + default y if GRKERNSEC_CONFIG_AUTO
81963 + depends on X86
81964 + help
81965 + By saying Y here the kernel recomputes expressions of function
81966 + arguments marked by a size_overflow attribute with double integer
81967 + precision (DImode/TImode for 32/64 bit integer types).
81968 +
81969 + The recomputed argument is checked against TYPE_MAX and an event
81970 + is logged on overflow and the triggering process is killed.
81971 +
81972 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
81973 +
81974 + Note that the implementation requires a gcc with plugin support,
81975 + i.e., gcc 4.5 or newer. You may need to install the supporting
81976 + headers explicitly in addition to the normal gcc package.
81977 +
81978 +config PAX_LATENT_ENTROPY
81979 + bool "Generate some entropy during boot"
81980 + default y if GRKERNSEC_CONFIG_AUTO
81981 + help
81982 + By saying Y here the kernel will instrument early boot code to
81983 + extract some entropy from both original and artificially created
81984 + program state. This will help especially embedded systems where
81985 + there is little 'natural' source of entropy normally. The cost
81986 + is some slowdown of the boot process.
81987 +
81988 + Note that the implementation requires a gcc with plugin support,
81989 + i.e., gcc 4.5 or newer. You may need to install the supporting
81990 + headers explicitly in addition to the normal gcc package.
81991 +
81992 + Note that entropy extracted this way is not cryptographically
81993 + secure!
81994 +
81995 +endmenu
81996 +
81997 +endmenu
81998 +
81999 +source grsecurity/Kconfig
82000 +
82001 +endmenu
82002 +
82003 +endmenu
82004 +
82005 source security/keys/Kconfig
82006
82007 config SECURITY_DMESG_RESTRICT
82008 @@ -103,7 +993,7 @@ config INTEL_TXT
82009 config LSM_MMAP_MIN_ADDR
82010 int "Low address space for LSM to protect from user allocation"
82011 depends on SECURITY && SECURITY_SELINUX
82012 - default 32768 if ARM
82013 + default 32768 if ALPHA || ARM || PARISC || SPARC32
82014 default 65536
82015 help
82016 This is the portion of low virtual memory which should be protected
82017 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
82018 index 8ea39aa..8569ac5 100644
82019 --- a/security/apparmor/lsm.c
82020 +++ b/security/apparmor/lsm.c
82021 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
82022 return error;
82023 }
82024
82025 -static struct security_operations apparmor_ops = {
82026 +static struct security_operations apparmor_ops __read_only = {
82027 .name = "apparmor",
82028
82029 .ptrace_access_check = apparmor_ptrace_access_check,
82030 diff --git a/security/commoncap.c b/security/commoncap.c
82031 index 6dbae46..d5611fd 100644
82032 --- a/security/commoncap.c
82033 +++ b/security/commoncap.c
82034 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
82035 return 0;
82036 }
82037
82038 +/* returns:
82039 + 1 for suid privilege
82040 + 2 for sgid privilege
82041 + 3 for fscap privilege
82042 +*/
82043 +int is_privileged_binary(const struct dentry *dentry)
82044 +{
82045 + struct cpu_vfs_cap_data capdata;
82046 + struct inode *inode = dentry->d_inode;
82047 +
82048 + if (!inode || S_ISDIR(inode->i_mode))
82049 + return 0;
82050 +
82051 + if (inode->i_mode & S_ISUID)
82052 + return 1;
82053 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
82054 + return 2;
82055 +
82056 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
82057 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
82058 + return 3;
82059 + }
82060 +
82061 + return 0;
82062 +}
82063 +
82064 /*
82065 * Attempt to get the on-exec apply capability sets for an executable file from
82066 * its xattrs and, if present, apply them to the proposed credentials being
82067 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
82068 const struct cred *cred = current_cred();
82069 kuid_t root_uid = make_kuid(cred->user_ns, 0);
82070
82071 + if (gr_acl_enable_at_secure())
82072 + return 1;
82073 +
82074 if (!uid_eq(cred->uid, root_uid)) {
82075 if (bprm->cap_effective)
82076 return 1;
82077 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
82078 index e7c99fd..5b2fa24 100644
82079 --- a/security/integrity/ima/ima.h
82080 +++ b/security/integrity/ima/ima.h
82081 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
82082 extern spinlock_t ima_queue_lock;
82083
82084 struct ima_h_table {
82085 - atomic_long_t len; /* number of stored measurements in the list */
82086 - atomic_long_t violations;
82087 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
82088 + atomic_long_unchecked_t violations;
82089 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
82090 };
82091 extern struct ima_h_table ima_htable;
82092 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
82093 index 032ff03..c428a74 100644
82094 --- a/security/integrity/ima/ima_api.c
82095 +++ b/security/integrity/ima/ima_api.c
82096 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
82097 int result;
82098
82099 /* can overflow, only indicator */
82100 - atomic_long_inc(&ima_htable.violations);
82101 + atomic_long_inc_unchecked(&ima_htable.violations);
82102
82103 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
82104 if (!entry) {
82105 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
82106 index 38477c9..87a60c7 100644
82107 --- a/security/integrity/ima/ima_fs.c
82108 +++ b/security/integrity/ima/ima_fs.c
82109 @@ -28,12 +28,12 @@
82110 static int valid_policy = 1;
82111 #define TMPBUFLEN 12
82112 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
82113 - loff_t *ppos, atomic_long_t *val)
82114 + loff_t *ppos, atomic_long_unchecked_t *val)
82115 {
82116 char tmpbuf[TMPBUFLEN];
82117 ssize_t len;
82118
82119 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
82120 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
82121 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
82122 }
82123
82124 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
82125 index 55a6271..ad829c3 100644
82126 --- a/security/integrity/ima/ima_queue.c
82127 +++ b/security/integrity/ima/ima_queue.c
82128 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
82129 INIT_LIST_HEAD(&qe->later);
82130 list_add_tail_rcu(&qe->later, &ima_measurements);
82131
82132 - atomic_long_inc(&ima_htable.len);
82133 + atomic_long_inc_unchecked(&ima_htable.len);
82134 key = ima_hash_key(entry->digest);
82135 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
82136 return 0;
82137 diff --git a/security/keys/compat.c b/security/keys/compat.c
82138 index 1c26176..64a1ba2 100644
82139 --- a/security/keys/compat.c
82140 +++ b/security/keys/compat.c
82141 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
82142 if (ret == 0)
82143 goto no_payload_free;
82144
82145 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
82146 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
82147
82148 if (iov != iovstack)
82149 kfree(iov);
82150 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
82151 index 3364fbf..1f10f31 100644
82152 --- a/security/keys/keyctl.c
82153 +++ b/security/keys/keyctl.c
82154 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
82155 /*
82156 * Copy the iovec data from userspace
82157 */
82158 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
82159 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
82160 unsigned ioc)
82161 {
82162 for (; ioc > 0; ioc--) {
82163 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
82164 * If successful, 0 will be returned.
82165 */
82166 long keyctl_instantiate_key_common(key_serial_t id,
82167 - const struct iovec *payload_iov,
82168 + const struct iovec __user *payload_iov,
82169 unsigned ioc,
82170 size_t plen,
82171 key_serial_t ringid)
82172 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
82173 [0].iov_len = plen
82174 };
82175
82176 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
82177 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
82178 }
82179
82180 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
82181 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
82182 if (ret == 0)
82183 goto no_payload_free;
82184
82185 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
82186 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
82187
82188 if (iov != iovstack)
82189 kfree(iov);
82190 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
82191 index 81e7852..2b2ecc3 100644
82192 --- a/security/keys/keyring.c
82193 +++ b/security/keys/keyring.c
82194 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
82195 ret = -EFAULT;
82196
82197 for (loop = 0; loop < klist->nkeys; loop++) {
82198 + key_serial_t serial;
82199 key = rcu_deref_link_locked(klist, loop,
82200 keyring);
82201 + serial = key->serial;
82202
82203 tmp = sizeof(key_serial_t);
82204 if (tmp > buflen)
82205 tmp = buflen;
82206
82207 - if (copy_to_user(buffer,
82208 - &key->serial,
82209 - tmp) != 0)
82210 + if (copy_to_user(buffer, &serial, tmp))
82211 goto error;
82212
82213 buflen -= tmp;
82214 diff --git a/security/min_addr.c b/security/min_addr.c
82215 index f728728..6457a0c 100644
82216 --- a/security/min_addr.c
82217 +++ b/security/min_addr.c
82218 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
82219 */
82220 static void update_mmap_min_addr(void)
82221 {
82222 +#ifndef SPARC
82223 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
82224 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
82225 mmap_min_addr = dac_mmap_min_addr;
82226 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
82227 #else
82228 mmap_min_addr = dac_mmap_min_addr;
82229 #endif
82230 +#endif
82231 }
82232
82233 /*
82234 diff --git a/security/security.c b/security/security.c
82235 index 860aeb3..45765c0 100644
82236 --- a/security/security.c
82237 +++ b/security/security.c
82238 @@ -20,6 +20,7 @@
82239 #include <linux/ima.h>
82240 #include <linux/evm.h>
82241 #include <linux/fsnotify.h>
82242 +#include <linux/mm.h>
82243 #include <linux/mman.h>
82244 #include <linux/mount.h>
82245 #include <linux/personality.h>
82246 @@ -32,8 +33,8 @@
82247 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
82248 CONFIG_DEFAULT_SECURITY;
82249
82250 -static struct security_operations *security_ops;
82251 -static struct security_operations default_security_ops = {
82252 +static struct security_operations *security_ops __read_only;
82253 +static struct security_operations default_security_ops __read_only = {
82254 .name = "default",
82255 };
82256
82257 @@ -74,7 +75,9 @@ int __init security_init(void)
82258
82259 void reset_security_ops(void)
82260 {
82261 + pax_open_kernel();
82262 security_ops = &default_security_ops;
82263 + pax_close_kernel();
82264 }
82265
82266 /* Save user chosen LSM */
82267 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
82268 index 6c77f63..7496c76 100644
82269 --- a/security/selinux/hooks.c
82270 +++ b/security/selinux/hooks.c
82271 @@ -95,8 +95,6 @@
82272
82273 #define NUM_SEL_MNT_OPTS 5
82274
82275 -extern struct security_operations *security_ops;
82276 -
82277 /* SECMARK reference count */
82278 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
82279
82280 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
82281
82282 #endif
82283
82284 -static struct security_operations selinux_ops = {
82285 +static struct security_operations selinux_ops __read_only = {
82286 .name = "selinux",
82287
82288 .ptrace_access_check = selinux_ptrace_access_check,
82289 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
82290 index 65f67cb..3f141ef 100644
82291 --- a/security/selinux/include/xfrm.h
82292 +++ b/security/selinux/include/xfrm.h
82293 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
82294
82295 static inline void selinux_xfrm_notify_policyload(void)
82296 {
82297 - atomic_inc(&flow_cache_genid);
82298 + atomic_inc_unchecked(&flow_cache_genid);
82299 rt_genid_bump(&init_net);
82300 }
82301 #else
82302 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
82303 index 8221514..5c4775f 100644
82304 --- a/security/smack/smack_lsm.c
82305 +++ b/security/smack/smack_lsm.c
82306 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
82307 return 0;
82308 }
82309
82310 -struct security_operations smack_ops = {
82311 +struct security_operations smack_ops __read_only = {
82312 .name = "smack",
82313
82314 .ptrace_access_check = smack_ptrace_access_check,
82315 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
82316 index c2d04a5..e6a1aeb 100644
82317 --- a/security/tomoyo/tomoyo.c
82318 +++ b/security/tomoyo/tomoyo.c
82319 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
82320 * tomoyo_security_ops is a "struct security_operations" which is used for
82321 * registering TOMOYO.
82322 */
82323 -static struct security_operations tomoyo_security_ops = {
82324 +static struct security_operations tomoyo_security_ops __read_only = {
82325 .name = "tomoyo",
82326 .cred_alloc_blank = tomoyo_cred_alloc_blank,
82327 .cred_prepare = tomoyo_cred_prepare,
82328 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
82329 index 51d6709..1f3dbe2 100644
82330 --- a/security/yama/Kconfig
82331 +++ b/security/yama/Kconfig
82332 @@ -1,6 +1,6 @@
82333 config SECURITY_YAMA
82334 bool "Yama support"
82335 - depends on SECURITY
82336 + depends on SECURITY && !GRKERNSEC
82337 select SECURITYFS
82338 select SECURITY_PATH
82339 default n
82340 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
82341 index 4cedc69..e59d8a3 100644
82342 --- a/sound/aoa/codecs/onyx.c
82343 +++ b/sound/aoa/codecs/onyx.c
82344 @@ -54,7 +54,7 @@ struct onyx {
82345 spdif_locked:1,
82346 analog_locked:1,
82347 original_mute:2;
82348 - int open_count;
82349 + local_t open_count;
82350 struct codec_info *codec_info;
82351
82352 /* mutex serializes concurrent access to the device
82353 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
82354 struct onyx *onyx = cii->codec_data;
82355
82356 mutex_lock(&onyx->mutex);
82357 - onyx->open_count++;
82358 + local_inc(&onyx->open_count);
82359 mutex_unlock(&onyx->mutex);
82360
82361 return 0;
82362 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
82363 struct onyx *onyx = cii->codec_data;
82364
82365 mutex_lock(&onyx->mutex);
82366 - onyx->open_count--;
82367 - if (!onyx->open_count)
82368 + if (local_dec_and_test(&onyx->open_count))
82369 onyx->spdif_locked = onyx->analog_locked = 0;
82370 mutex_unlock(&onyx->mutex);
82371
82372 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
82373 index ffd2025..df062c9 100644
82374 --- a/sound/aoa/codecs/onyx.h
82375 +++ b/sound/aoa/codecs/onyx.h
82376 @@ -11,6 +11,7 @@
82377 #include <linux/i2c.h>
82378 #include <asm/pmac_low_i2c.h>
82379 #include <asm/prom.h>
82380 +#include <asm/local.h>
82381
82382 /* PCM3052 register definitions */
82383
82384 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
82385 index 4c1cc51..16040040 100644
82386 --- a/sound/core/oss/pcm_oss.c
82387 +++ b/sound/core/oss/pcm_oss.c
82388 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
82389 if (in_kernel) {
82390 mm_segment_t fs;
82391 fs = snd_enter_user();
82392 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
82393 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
82394 snd_leave_user(fs);
82395 } else {
82396 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
82397 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
82398 }
82399 if (ret != -EPIPE && ret != -ESTRPIPE)
82400 break;
82401 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
82402 if (in_kernel) {
82403 mm_segment_t fs;
82404 fs = snd_enter_user();
82405 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
82406 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
82407 snd_leave_user(fs);
82408 } else {
82409 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
82410 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
82411 }
82412 if (ret == -EPIPE) {
82413 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
82414 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
82415 struct snd_pcm_plugin_channel *channels;
82416 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
82417 if (!in_kernel) {
82418 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
82419 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
82420 return -EFAULT;
82421 buf = runtime->oss.buffer;
82422 }
82423 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
82424 }
82425 } else {
82426 tmp = snd_pcm_oss_write2(substream,
82427 - (const char __force *)buf,
82428 + (const char __force_kernel *)buf,
82429 runtime->oss.period_bytes, 0);
82430 if (tmp <= 0)
82431 goto err;
82432 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
82433 struct snd_pcm_runtime *runtime = substream->runtime;
82434 snd_pcm_sframes_t frames, frames1;
82435 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
82436 - char __user *final_dst = (char __force __user *)buf;
82437 + char __user *final_dst = (char __force_user *)buf;
82438 if (runtime->oss.plugin_first) {
82439 struct snd_pcm_plugin_channel *channels;
82440 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
82441 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
82442 xfer += tmp;
82443 runtime->oss.buffer_used -= tmp;
82444 } else {
82445 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
82446 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
82447 runtime->oss.period_bytes, 0);
82448 if (tmp <= 0)
82449 goto err;
82450 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
82451 size1);
82452 size1 /= runtime->channels; /* frames */
82453 fs = snd_enter_user();
82454 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
82455 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
82456 snd_leave_user(fs);
82457 }
82458 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
82459 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
82460 index 91cdf943..4085161 100644
82461 --- a/sound/core/pcm_compat.c
82462 +++ b/sound/core/pcm_compat.c
82463 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
82464 int err;
82465
82466 fs = snd_enter_user();
82467 - err = snd_pcm_delay(substream, &delay);
82468 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
82469 snd_leave_user(fs);
82470 if (err < 0)
82471 return err;
82472 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
82473 index bf3bf43..3826cbc 100644
82474 --- a/sound/core/pcm_native.c
82475 +++ b/sound/core/pcm_native.c
82476 @@ -2803,11 +2803,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
82477 switch (substream->stream) {
82478 case SNDRV_PCM_STREAM_PLAYBACK:
82479 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
82480 - (void __user *)arg);
82481 + (void __force_user *)arg);
82482 break;
82483 case SNDRV_PCM_STREAM_CAPTURE:
82484 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
82485 - (void __user *)arg);
82486 + (void __force_user *)arg);
82487 break;
82488 default:
82489 result = -EINVAL;
82490 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
82491 index 5cf8d65..912a79c 100644
82492 --- a/sound/core/seq/seq_device.c
82493 +++ b/sound/core/seq/seq_device.c
82494 @@ -64,7 +64,7 @@ struct ops_list {
82495 int argsize; /* argument size */
82496
82497 /* operators */
82498 - struct snd_seq_dev_ops ops;
82499 + struct snd_seq_dev_ops *ops;
82500
82501 /* registred devices */
82502 struct list_head dev_list; /* list of devices */
82503 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
82504
82505 mutex_lock(&ops->reg_mutex);
82506 /* copy driver operators */
82507 - ops->ops = *entry;
82508 + ops->ops = entry;
82509 ops->driver |= DRIVER_LOADED;
82510 ops->argsize = argsize;
82511
82512 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
82513 dev->name, ops->id, ops->argsize, dev->argsize);
82514 return -EINVAL;
82515 }
82516 - if (ops->ops.init_device(dev) >= 0) {
82517 + if (ops->ops->init_device(dev) >= 0) {
82518 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
82519 ops->num_init_devices++;
82520 } else {
82521 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
82522 dev->name, ops->id, ops->argsize, dev->argsize);
82523 return -EINVAL;
82524 }
82525 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
82526 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
82527 dev->status = SNDRV_SEQ_DEVICE_FREE;
82528 dev->driver_data = NULL;
82529 ops->num_init_devices--;
82530 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
82531 index 2d5514b..3afae9c 100644
82532 --- a/sound/drivers/mts64.c
82533 +++ b/sound/drivers/mts64.c
82534 @@ -29,6 +29,7 @@
82535 #include <sound/initval.h>
82536 #include <sound/rawmidi.h>
82537 #include <sound/control.h>
82538 +#include <asm/local.h>
82539
82540 #define CARD_NAME "Miditerminal 4140"
82541 #define DRIVER_NAME "MTS64"
82542 @@ -67,7 +68,7 @@ struct mts64 {
82543 struct pardevice *pardev;
82544 int pardev_claimed;
82545
82546 - int open_count;
82547 + local_t open_count;
82548 int current_midi_output_port;
82549 int current_midi_input_port;
82550 u8 mode[MTS64_NUM_INPUT_PORTS];
82551 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
82552 {
82553 struct mts64 *mts = substream->rmidi->private_data;
82554
82555 - if (mts->open_count == 0) {
82556 + if (local_read(&mts->open_count) == 0) {
82557 /* We don't need a spinlock here, because this is just called
82558 if the device has not been opened before.
82559 So there aren't any IRQs from the device */
82560 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
82561
82562 msleep(50);
82563 }
82564 - ++(mts->open_count);
82565 + local_inc(&mts->open_count);
82566
82567 return 0;
82568 }
82569 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82570 struct mts64 *mts = substream->rmidi->private_data;
82571 unsigned long flags;
82572
82573 - --(mts->open_count);
82574 - if (mts->open_count == 0) {
82575 + if (local_dec_return(&mts->open_count) == 0) {
82576 /* We need the spinlock_irqsave here because we can still
82577 have IRQs at this point */
82578 spin_lock_irqsave(&mts->lock, flags);
82579 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82580
82581 msleep(500);
82582
82583 - } else if (mts->open_count < 0)
82584 - mts->open_count = 0;
82585 + } else if (local_read(&mts->open_count) < 0)
82586 + local_set(&mts->open_count, 0);
82587
82588 return 0;
82589 }
82590 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
82591 index b953fb4..1999c01 100644
82592 --- a/sound/drivers/opl4/opl4_lib.c
82593 +++ b/sound/drivers/opl4/opl4_lib.c
82594 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
82595 MODULE_DESCRIPTION("OPL4 driver");
82596 MODULE_LICENSE("GPL");
82597
82598 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
82599 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
82600 {
82601 int timeout = 10;
82602 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
82603 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
82604 index 8364855..59f2e2b 100644
82605 --- a/sound/drivers/portman2x4.c
82606 +++ b/sound/drivers/portman2x4.c
82607 @@ -48,6 +48,7 @@
82608 #include <sound/initval.h>
82609 #include <sound/rawmidi.h>
82610 #include <sound/control.h>
82611 +#include <asm/local.h>
82612
82613 #define CARD_NAME "Portman 2x4"
82614 #define DRIVER_NAME "portman"
82615 @@ -85,7 +86,7 @@ struct portman {
82616 struct pardevice *pardev;
82617 int pardev_claimed;
82618
82619 - int open_count;
82620 + local_t open_count;
82621 int mode[PORTMAN_NUM_INPUT_PORTS];
82622 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
82623 };
82624 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
82625 index ea995af..f1bfa37 100644
82626 --- a/sound/firewire/amdtp.c
82627 +++ b/sound/firewire/amdtp.c
82628 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
82629 ptr = s->pcm_buffer_pointer + data_blocks;
82630 if (ptr >= pcm->runtime->buffer_size)
82631 ptr -= pcm->runtime->buffer_size;
82632 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
82633 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
82634
82635 s->pcm_period_pointer += data_blocks;
82636 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
82637 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
82638 */
82639 void amdtp_out_stream_update(struct amdtp_out_stream *s)
82640 {
82641 - ACCESS_ONCE(s->source_node_id_field) =
82642 + ACCESS_ONCE_RW(s->source_node_id_field) =
82643 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
82644 }
82645 EXPORT_SYMBOL(amdtp_out_stream_update);
82646 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
82647 index b680c5e..061b7a0 100644
82648 --- a/sound/firewire/amdtp.h
82649 +++ b/sound/firewire/amdtp.h
82650 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
82651 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
82652 struct snd_pcm_substream *pcm)
82653 {
82654 - ACCESS_ONCE(s->pcm) = pcm;
82655 + ACCESS_ONCE_RW(s->pcm) = pcm;
82656 }
82657
82658 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
82659 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
82660 index d428ffe..751ef78 100644
82661 --- a/sound/firewire/isight.c
82662 +++ b/sound/firewire/isight.c
82663 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
82664 ptr += count;
82665 if (ptr >= runtime->buffer_size)
82666 ptr -= runtime->buffer_size;
82667 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
82668 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
82669
82670 isight->period_counter += count;
82671 if (isight->period_counter >= runtime->period_size) {
82672 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
82673 if (err < 0)
82674 return err;
82675
82676 - ACCESS_ONCE(isight->pcm_active) = true;
82677 + ACCESS_ONCE_RW(isight->pcm_active) = true;
82678
82679 return 0;
82680 }
82681 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
82682 {
82683 struct isight *isight = substream->private_data;
82684
82685 - ACCESS_ONCE(isight->pcm_active) = false;
82686 + ACCESS_ONCE_RW(isight->pcm_active) = false;
82687
82688 mutex_lock(&isight->mutex);
82689 isight_stop_streaming(isight);
82690 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
82691
82692 switch (cmd) {
82693 case SNDRV_PCM_TRIGGER_START:
82694 - ACCESS_ONCE(isight->pcm_running) = true;
82695 + ACCESS_ONCE_RW(isight->pcm_running) = true;
82696 break;
82697 case SNDRV_PCM_TRIGGER_STOP:
82698 - ACCESS_ONCE(isight->pcm_running) = false;
82699 + ACCESS_ONCE_RW(isight->pcm_running) = false;
82700 break;
82701 default:
82702 return -EINVAL;
82703 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
82704 index 7bd5e33..1fcab12 100644
82705 --- a/sound/isa/cmi8330.c
82706 +++ b/sound/isa/cmi8330.c
82707 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
82708
82709 struct snd_pcm *pcm;
82710 struct snd_cmi8330_stream {
82711 - struct snd_pcm_ops ops;
82712 + snd_pcm_ops_no_const ops;
82713 snd_pcm_open_callback_t open;
82714 void *private_data; /* sb or wss */
82715 } streams[2];
82716 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
82717 index b2b3c01..e1c1e1f 100644
82718 --- a/sound/oss/sb_audio.c
82719 +++ b/sound/oss/sb_audio.c
82720 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
82721 buf16 = (signed short *)(localbuf + localoffs);
82722 while (c)
82723 {
82724 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82725 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82726 if (copy_from_user(lbuf8,
82727 userbuf+useroffs + p,
82728 locallen))
82729 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
82730 index 7d8803a..559f8d0 100644
82731 --- a/sound/oss/swarm_cs4297a.c
82732 +++ b/sound/oss/swarm_cs4297a.c
82733 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
82734 {
82735 struct cs4297a_state *s;
82736 u32 pwr, id;
82737 - mm_segment_t fs;
82738 int rval;
82739 #ifndef CONFIG_BCM_CS4297A_CSWARM
82740 u64 cfg;
82741 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
82742 if (!rval) {
82743 char *sb1250_duart_present;
82744
82745 +#if 0
82746 + mm_segment_t fs;
82747 fs = get_fs();
82748 set_fs(KERNEL_DS);
82749 -#if 0
82750 val = SOUND_MASK_LINE;
82751 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
82752 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
82753 val = initvol[i].vol;
82754 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
82755 }
82756 + set_fs(fs);
82757 // cs4297a_write_ac97(s, 0x18, 0x0808);
82758 #else
82759 // cs4297a_write_ac97(s, 0x5e, 0x180);
82760 cs4297a_write_ac97(s, 0x02, 0x0808);
82761 cs4297a_write_ac97(s, 0x18, 0x0808);
82762 #endif
82763 - set_fs(fs);
82764
82765 list_add(&s->list, &cs4297a_devs);
82766
82767 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
82768 index e5a7e19..4049063 100644
82769 --- a/sound/pci/hda/hda_codec.h
82770 +++ b/sound/pci/hda/hda_codec.h
82771 @@ -614,7 +614,7 @@ struct hda_bus_ops {
82772 /* notify power-up/down from codec to controller */
82773 void (*pm_notify)(struct hda_bus *bus);
82774 #endif
82775 -};
82776 +} __no_const;
82777
82778 /* template to pass to the bus constructor */
82779 struct hda_bus_template {
82780 @@ -714,6 +714,7 @@ struct hda_codec_ops {
82781 #endif
82782 void (*reboot_notify)(struct hda_codec *codec);
82783 };
82784 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
82785
82786 /* record for amp information cache */
82787 struct hda_cache_head {
82788 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
82789 struct snd_pcm_substream *substream);
82790 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
82791 struct snd_pcm_substream *substream);
82792 -};
82793 +} __no_const;
82794
82795 /* PCM information for each substream */
82796 struct hda_pcm_stream {
82797 @@ -802,7 +803,7 @@ struct hda_codec {
82798 const char *modelname; /* model name for preset */
82799
82800 /* set by patch */
82801 - struct hda_codec_ops patch_ops;
82802 + hda_codec_ops_no_const patch_ops;
82803
82804 /* PCM to create, set by patch_ops.build_pcms callback */
82805 unsigned int num_pcms;
82806 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
82807 index 0da778a..bc38b84 100644
82808 --- a/sound/pci/ice1712/ice1712.h
82809 +++ b/sound/pci/ice1712/ice1712.h
82810 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
82811 unsigned int mask_flags; /* total mask bits */
82812 struct snd_akm4xxx_ops {
82813 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
82814 - } ops;
82815 + } __no_const ops;
82816 };
82817
82818 struct snd_ice1712_spdif {
82819 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
82820 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82821 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82822 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82823 - } ops;
82824 + } __no_const ops;
82825 };
82826
82827
82828 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
82829 index bddc405..2c0733c 100644
82830 --- a/sound/pci/ymfpci/ymfpci.h
82831 +++ b/sound/pci/ymfpci/ymfpci.h
82832 @@ -358,7 +358,7 @@ struct snd_ymfpci {
82833 spinlock_t reg_lock;
82834 spinlock_t voice_lock;
82835 wait_queue_head_t interrupt_sleep;
82836 - atomic_t interrupt_sleep_count;
82837 + atomic_unchecked_t interrupt_sleep_count;
82838 struct snd_info_entry *proc_entry;
82839 const struct firmware *dsp_microcode;
82840 const struct firmware *controller_microcode;
82841 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
82842 index 62b2363..ee77972 100644
82843 --- a/sound/pci/ymfpci/ymfpci_main.c
82844 +++ b/sound/pci/ymfpci/ymfpci_main.c
82845 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
82846 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
82847 break;
82848 }
82849 - if (atomic_read(&chip->interrupt_sleep_count)) {
82850 - atomic_set(&chip->interrupt_sleep_count, 0);
82851 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82852 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82853 wake_up(&chip->interrupt_sleep);
82854 }
82855 __end:
82856 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
82857 continue;
82858 init_waitqueue_entry(&wait, current);
82859 add_wait_queue(&chip->interrupt_sleep, &wait);
82860 - atomic_inc(&chip->interrupt_sleep_count);
82861 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
82862 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
82863 remove_wait_queue(&chip->interrupt_sleep, &wait);
82864 }
82865 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
82866 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
82867 spin_unlock(&chip->reg_lock);
82868
82869 - if (atomic_read(&chip->interrupt_sleep_count)) {
82870 - atomic_set(&chip->interrupt_sleep_count, 0);
82871 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82872 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82873 wake_up(&chip->interrupt_sleep);
82874 }
82875 }
82876 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
82877 spin_lock_init(&chip->reg_lock);
82878 spin_lock_init(&chip->voice_lock);
82879 init_waitqueue_head(&chip->interrupt_sleep);
82880 - atomic_set(&chip->interrupt_sleep_count, 0);
82881 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82882 chip->card = card;
82883 chip->pci = pci;
82884 chip->irq = -1;
82885 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
82886 new file mode 100644
82887 index 0000000..50f2f2f
82888 --- /dev/null
82889 +++ b/tools/gcc/.gitignore
82890 @@ -0,0 +1 @@
82891 +size_overflow_hash.h
82892 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
82893 new file mode 100644
82894 index 0000000..1d09b7e
82895 --- /dev/null
82896 +++ b/tools/gcc/Makefile
82897 @@ -0,0 +1,43 @@
82898 +#CC := gcc
82899 +#PLUGIN_SOURCE_FILES := pax_plugin.c
82900 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
82901 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
82902 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
82903 +
82904 +ifeq ($(PLUGINCC),$(HOSTCC))
82905 +HOSTLIBS := hostlibs
82906 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
82907 +else
82908 +HOSTLIBS := hostcxxlibs
82909 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
82910 +endif
82911 +
82912 +$(HOSTLIBS)-y := constify_plugin.so
82913 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
82914 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
82915 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
82916 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
82917 +$(HOSTLIBS)-y += colorize_plugin.so
82918 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
82919 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
82920 +
82921 +always := $($(HOSTLIBS)-y)
82922 +
82923 +constify_plugin-objs := constify_plugin.o
82924 +stackleak_plugin-objs := stackleak_plugin.o
82925 +kallocstat_plugin-objs := kallocstat_plugin.o
82926 +kernexec_plugin-objs := kernexec_plugin.o
82927 +checker_plugin-objs := checker_plugin.o
82928 +colorize_plugin-objs := colorize_plugin.o
82929 +size_overflow_plugin-objs := size_overflow_plugin.o
82930 +latent_entropy_plugin-objs := latent_entropy_plugin.o
82931 +
82932 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
82933 +
82934 +quiet_cmd_build_size_overflow_hash = GENHASH $@
82935 + cmd_build_size_overflow_hash = \
82936 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
82937 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
82938 + $(call if_changed,build_size_overflow_hash)
82939 +
82940 +targets += size_overflow_hash.h
82941 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
82942 new file mode 100644
82943 index 0000000..d41b5af
82944 --- /dev/null
82945 +++ b/tools/gcc/checker_plugin.c
82946 @@ -0,0 +1,171 @@
82947 +/*
82948 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82949 + * Licensed under the GPL v2
82950 + *
82951 + * Note: the choice of the license means that the compilation process is
82952 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82953 + * but for the kernel it doesn't matter since it doesn't link against
82954 + * any of the gcc libraries
82955 + *
82956 + * gcc plugin to implement various sparse (source code checker) features
82957 + *
82958 + * TODO:
82959 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
82960 + *
82961 + * BUGS:
82962 + * - none known
82963 + */
82964 +#include "gcc-plugin.h"
82965 +#include "config.h"
82966 +#include "system.h"
82967 +#include "coretypes.h"
82968 +#include "tree.h"
82969 +#include "tree-pass.h"
82970 +#include "flags.h"
82971 +#include "intl.h"
82972 +#include "toplev.h"
82973 +#include "plugin.h"
82974 +//#include "expr.h" where are you...
82975 +#include "diagnostic.h"
82976 +#include "plugin-version.h"
82977 +#include "tm.h"
82978 +#include "function.h"
82979 +#include "basic-block.h"
82980 +#include "gimple.h"
82981 +#include "rtl.h"
82982 +#include "emit-rtl.h"
82983 +#include "tree-flow.h"
82984 +#include "target.h"
82985 +
82986 +extern void c_register_addr_space (const char *str, addr_space_t as);
82987 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82988 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82989 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82990 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82991 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82992 +
82993 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82994 +extern rtx emit_move_insn(rtx x, rtx y);
82995 +
82996 +int plugin_is_GPL_compatible;
82997 +
82998 +static struct plugin_info checker_plugin_info = {
82999 + .version = "201111150100",
83000 +};
83001 +
83002 +#define ADDR_SPACE_KERNEL 0
83003 +#define ADDR_SPACE_FORCE_KERNEL 1
83004 +#define ADDR_SPACE_USER 2
83005 +#define ADDR_SPACE_FORCE_USER 3
83006 +#define ADDR_SPACE_IOMEM 0
83007 +#define ADDR_SPACE_FORCE_IOMEM 0
83008 +#define ADDR_SPACE_PERCPU 0
83009 +#define ADDR_SPACE_FORCE_PERCPU 0
83010 +#define ADDR_SPACE_RCU 0
83011 +#define ADDR_SPACE_FORCE_RCU 0
83012 +
83013 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
83014 +{
83015 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
83016 +}
83017 +
83018 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
83019 +{
83020 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
83021 +}
83022 +
83023 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
83024 +{
83025 + return default_addr_space_valid_pointer_mode(mode, as);
83026 +}
83027 +
83028 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
83029 +{
83030 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
83031 +}
83032 +
83033 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
83034 +{
83035 + return default_addr_space_legitimize_address(x, oldx, mode, as);
83036 +}
83037 +
83038 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
83039 +{
83040 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
83041 + return true;
83042 +
83043 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
83044 + return true;
83045 +
83046 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
83047 + return true;
83048 +
83049 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
83050 + return true;
83051 +
83052 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
83053 + return true;
83054 +
83055 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
83056 + return true;
83057 +
83058 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
83059 + return true;
83060 +
83061 + return subset == superset;
83062 +}
83063 +
83064 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
83065 +{
83066 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
83067 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
83068 +
83069 + return op;
83070 +}
83071 +
83072 +static void register_checker_address_spaces(void *event_data, void *data)
83073 +{
83074 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
83075 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
83076 + c_register_addr_space("__user", ADDR_SPACE_USER);
83077 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
83078 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
83079 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
83080 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
83081 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
83082 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
83083 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
83084 +
83085 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
83086 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
83087 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
83088 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
83089 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
83090 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
83091 + targetm.addr_space.convert = checker_addr_space_convert;
83092 +}
83093 +
83094 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83095 +{
83096 + const char * const plugin_name = plugin_info->base_name;
83097 + const int argc = plugin_info->argc;
83098 + const struct plugin_argument * const argv = plugin_info->argv;
83099 + int i;
83100 +
83101 + if (!plugin_default_version_check(version, &gcc_version)) {
83102 + error(G_("incompatible gcc/plugin versions"));
83103 + return 1;
83104 + }
83105 +
83106 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
83107 +
83108 + for (i = 0; i < argc; ++i)
83109 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83110 +
83111 + if (TARGET_64BIT == 0)
83112 + return 0;
83113 +
83114 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
83115 +
83116 + return 0;
83117 +}
83118 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
83119 new file mode 100644
83120 index 0000000..846aeb0
83121 --- /dev/null
83122 +++ b/tools/gcc/colorize_plugin.c
83123 @@ -0,0 +1,148 @@
83124 +/*
83125 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
83126 + * Licensed under the GPL v2
83127 + *
83128 + * Note: the choice of the license means that the compilation process is
83129 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83130 + * but for the kernel it doesn't matter since it doesn't link against
83131 + * any of the gcc libraries
83132 + *
83133 + * gcc plugin to colorize diagnostic output
83134 + *
83135 + */
83136 +
83137 +#include "gcc-plugin.h"
83138 +#include "config.h"
83139 +#include "system.h"
83140 +#include "coretypes.h"
83141 +#include "tree.h"
83142 +#include "tree-pass.h"
83143 +#include "flags.h"
83144 +#include "intl.h"
83145 +#include "toplev.h"
83146 +#include "plugin.h"
83147 +#include "diagnostic.h"
83148 +#include "plugin-version.h"
83149 +#include "tm.h"
83150 +
83151 +int plugin_is_GPL_compatible;
83152 +
83153 +static struct plugin_info colorize_plugin_info = {
83154 + .version = "201203092200",
83155 + .help = NULL,
83156 +};
83157 +
83158 +#define GREEN "\033[32m\033[2m"
83159 +#define LIGHTGREEN "\033[32m\033[1m"
83160 +#define YELLOW "\033[33m\033[2m"
83161 +#define LIGHTYELLOW "\033[33m\033[1m"
83162 +#define RED "\033[31m\033[2m"
83163 +#define LIGHTRED "\033[31m\033[1m"
83164 +#define BLUE "\033[34m\033[2m"
83165 +#define LIGHTBLUE "\033[34m\033[1m"
83166 +#define BRIGHT "\033[m\033[1m"
83167 +#define NORMAL "\033[m"
83168 +
83169 +static diagnostic_starter_fn old_starter;
83170 +static diagnostic_finalizer_fn old_finalizer;
83171 +
83172 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
83173 +{
83174 + const char *color;
83175 + char *newprefix;
83176 +
83177 + switch (diagnostic->kind) {
83178 + case DK_NOTE:
83179 + color = LIGHTBLUE;
83180 + break;
83181 +
83182 + case DK_PEDWARN:
83183 + case DK_WARNING:
83184 + color = LIGHTYELLOW;
83185 + break;
83186 +
83187 + case DK_ERROR:
83188 + case DK_FATAL:
83189 + case DK_ICE:
83190 + case DK_PERMERROR:
83191 + case DK_SORRY:
83192 + color = LIGHTRED;
83193 + break;
83194 +
83195 + default:
83196 + color = NORMAL;
83197 + }
83198 +
83199 + old_starter(context, diagnostic);
83200 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
83201 + return;
83202 + pp_destroy_prefix(context->printer);
83203 + pp_set_prefix(context->printer, newprefix);
83204 +}
83205 +
83206 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
83207 +{
83208 + old_finalizer(context, diagnostic);
83209 +}
83210 +
83211 +static void colorize_arm(void)
83212 +{
83213 + old_starter = diagnostic_starter(global_dc);
83214 + old_finalizer = diagnostic_finalizer(global_dc);
83215 +
83216 + diagnostic_starter(global_dc) = start_colorize;
83217 + diagnostic_finalizer(global_dc) = finalize_colorize;
83218 +}
83219 +
83220 +static unsigned int execute_colorize_rearm(void)
83221 +{
83222 + if (diagnostic_starter(global_dc) == start_colorize)
83223 + return 0;
83224 +
83225 + colorize_arm();
83226 + return 0;
83227 +}
83228 +
83229 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
83230 + .pass = {
83231 + .type = SIMPLE_IPA_PASS,
83232 + .name = "colorize_rearm",
83233 + .gate = NULL,
83234 + .execute = execute_colorize_rearm,
83235 + .sub = NULL,
83236 + .next = NULL,
83237 + .static_pass_number = 0,
83238 + .tv_id = TV_NONE,
83239 + .properties_required = 0,
83240 + .properties_provided = 0,
83241 + .properties_destroyed = 0,
83242 + .todo_flags_start = 0,
83243 + .todo_flags_finish = 0
83244 + }
83245 +};
83246 +
83247 +static void colorize_start_unit(void *gcc_data, void *user_data)
83248 +{
83249 + colorize_arm();
83250 +}
83251 +
83252 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83253 +{
83254 + const char * const plugin_name = plugin_info->base_name;
83255 + struct register_pass_info colorize_rearm_pass_info = {
83256 + .pass = &pass_ipa_colorize_rearm.pass,
83257 + .reference_pass_name = "*free_lang_data",
83258 + .ref_pass_instance_number = 1,
83259 + .pos_op = PASS_POS_INSERT_AFTER
83260 + };
83261 +
83262 + if (!plugin_default_version_check(version, &gcc_version)) {
83263 + error(G_("incompatible gcc/plugin versions"));
83264 + return 1;
83265 + }
83266 +
83267 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
83268 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
83269 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
83270 + return 0;
83271 +}
83272 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
83273 new file mode 100644
83274 index 0000000..92ed719
83275 --- /dev/null
83276 +++ b/tools/gcc/constify_plugin.c
83277 @@ -0,0 +1,331 @@
83278 +/*
83279 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
83280 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
83281 + * Licensed under the GPL v2, or (at your option) v3
83282 + *
83283 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
83284 + *
83285 + * Homepage:
83286 + * http://www.grsecurity.net/~ephox/const_plugin/
83287 + *
83288 + * Usage:
83289 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
83290 + * $ gcc -fplugin=constify_plugin.so test.c -O2
83291 + */
83292 +
83293 +#include "gcc-plugin.h"
83294 +#include "config.h"
83295 +#include "system.h"
83296 +#include "coretypes.h"
83297 +#include "tree.h"
83298 +#include "tree-pass.h"
83299 +#include "flags.h"
83300 +#include "intl.h"
83301 +#include "toplev.h"
83302 +#include "plugin.h"
83303 +#include "diagnostic.h"
83304 +#include "plugin-version.h"
83305 +#include "tm.h"
83306 +#include "function.h"
83307 +#include "basic-block.h"
83308 +#include "gimple.h"
83309 +#include "rtl.h"
83310 +#include "emit-rtl.h"
83311 +#include "tree-flow.h"
83312 +
83313 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
83314 +
83315 +int plugin_is_GPL_compatible;
83316 +
83317 +static struct plugin_info const_plugin_info = {
83318 + .version = "201205300030",
83319 + .help = "no-constify\tturn off constification\n",
83320 +};
83321 +
83322 +static void deconstify_tree(tree node);
83323 +
83324 +static void deconstify_type(tree type)
83325 +{
83326 + tree field;
83327 +
83328 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
83329 + tree type = TREE_TYPE(field);
83330 +
83331 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
83332 + continue;
83333 + if (!TYPE_READONLY(type))
83334 + continue;
83335 +
83336 + deconstify_tree(field);
83337 + }
83338 + TYPE_READONLY(type) = 0;
83339 + C_TYPE_FIELDS_READONLY(type) = 0;
83340 +}
83341 +
83342 +static void deconstify_tree(tree node)
83343 +{
83344 + tree old_type, new_type, field;
83345 +
83346 + old_type = TREE_TYPE(node);
83347 +
83348 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
83349 +
83350 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
83351 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
83352 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
83353 + DECL_FIELD_CONTEXT(field) = new_type;
83354 +
83355 + deconstify_type(new_type);
83356 +
83357 + TREE_READONLY(node) = 0;
83358 + TREE_TYPE(node) = new_type;
83359 +}
83360 +
83361 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83362 +{
83363 + tree type;
83364 +
83365 + *no_add_attrs = true;
83366 + if (TREE_CODE(*node) == FUNCTION_DECL) {
83367 + error("%qE attribute does not apply to functions", name);
83368 + return NULL_TREE;
83369 + }
83370 +
83371 + if (TREE_CODE(*node) == VAR_DECL) {
83372 + error("%qE attribute does not apply to variables", name);
83373 + return NULL_TREE;
83374 + }
83375 +
83376 + if (TYPE_P(*node)) {
83377 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
83378 + *no_add_attrs = false;
83379 + else
83380 + error("%qE attribute applies to struct and union types only", name);
83381 + return NULL_TREE;
83382 + }
83383 +
83384 + type = TREE_TYPE(*node);
83385 +
83386 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
83387 + error("%qE attribute applies to struct and union types only", name);
83388 + return NULL_TREE;
83389 + }
83390 +
83391 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
83392 + error("%qE attribute is already applied to the type", name);
83393 + return NULL_TREE;
83394 + }
83395 +
83396 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
83397 + error("%qE attribute used on type that is not constified", name);
83398 + return NULL_TREE;
83399 + }
83400 +
83401 + if (TREE_CODE(*node) == TYPE_DECL) {
83402 + deconstify_tree(*node);
83403 + return NULL_TREE;
83404 + }
83405 +
83406 + return NULL_TREE;
83407 +}
83408 +
83409 +static void constify_type(tree type)
83410 +{
83411 + TYPE_READONLY(type) = 1;
83412 + C_TYPE_FIELDS_READONLY(type) = 1;
83413 +}
83414 +
83415 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83416 +{
83417 + *no_add_attrs = true;
83418 + if (!TYPE_P(*node)) {
83419 + error("%qE attribute applies to types only", name);
83420 + return NULL_TREE;
83421 + }
83422 +
83423 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
83424 + error("%qE attribute applies to struct and union types only", name);
83425 + return NULL_TREE;
83426 + }
83427 +
83428 + *no_add_attrs = false;
83429 + constify_type(*node);
83430 + return NULL_TREE;
83431 +}
83432 +
83433 +static struct attribute_spec no_const_attr = {
83434 + .name = "no_const",
83435 + .min_length = 0,
83436 + .max_length = 0,
83437 + .decl_required = false,
83438 + .type_required = false,
83439 + .function_type_required = false,
83440 + .handler = handle_no_const_attribute,
83441 +#if BUILDING_GCC_VERSION >= 4007
83442 + .affects_type_identity = true
83443 +#endif
83444 +};
83445 +
83446 +static struct attribute_spec do_const_attr = {
83447 + .name = "do_const",
83448 + .min_length = 0,
83449 + .max_length = 0,
83450 + .decl_required = false,
83451 + .type_required = false,
83452 + .function_type_required = false,
83453 + .handler = handle_do_const_attribute,
83454 +#if BUILDING_GCC_VERSION >= 4007
83455 + .affects_type_identity = true
83456 +#endif
83457 +};
83458 +
83459 +static void register_attributes(void *event_data, void *data)
83460 +{
83461 + register_attribute(&no_const_attr);
83462 + register_attribute(&do_const_attr);
83463 +}
83464 +
83465 +static bool is_fptr(tree field)
83466 +{
83467 + tree ptr = TREE_TYPE(field);
83468 +
83469 + if (TREE_CODE(ptr) != POINTER_TYPE)
83470 + return false;
83471 +
83472 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
83473 +}
83474 +
83475 +static bool walk_struct(tree node)
83476 +{
83477 + tree field;
83478 +
83479 + if (TYPE_FIELDS(node) == NULL_TREE)
83480 + return false;
83481 +
83482 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
83483 + gcc_assert(!TYPE_READONLY(node));
83484 + deconstify_type(node);
83485 + return false;
83486 + }
83487 +
83488 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
83489 + tree type = TREE_TYPE(field);
83490 + enum tree_code code = TREE_CODE(type);
83491 +
83492 + if (node == type)
83493 + return false;
83494 + if (code == RECORD_TYPE || code == UNION_TYPE) {
83495 + if (!(walk_struct(type)))
83496 + return false;
83497 + } else if (!is_fptr(field) && !TREE_READONLY(field))
83498 + return false;
83499 + }
83500 + return true;
83501 +}
83502 +
83503 +static void finish_type(void *event_data, void *data)
83504 +{
83505 + tree type = (tree)event_data;
83506 +
83507 + if (type == NULL_TREE || type == error_mark_node)
83508 + return;
83509 +
83510 + if (TYPE_READONLY(type))
83511 + return;
83512 +
83513 + if (walk_struct(type))
83514 + constify_type(type);
83515 +}
83516 +
83517 +static unsigned int check_local_variables(void);
83518 +
83519 +struct gimple_opt_pass pass_local_variable = {
83520 + {
83521 + .type = GIMPLE_PASS,
83522 + .name = "check_local_variables",
83523 + .gate = NULL,
83524 + .execute = check_local_variables,
83525 + .sub = NULL,
83526 + .next = NULL,
83527 + .static_pass_number = 0,
83528 + .tv_id = TV_NONE,
83529 + .properties_required = 0,
83530 + .properties_provided = 0,
83531 + .properties_destroyed = 0,
83532 + .todo_flags_start = 0,
83533 + .todo_flags_finish = 0
83534 + }
83535 +};
83536 +
83537 +static unsigned int check_local_variables(void)
83538 +{
83539 + tree var;
83540 + referenced_var_iterator rvi;
83541 +
83542 +#if BUILDING_GCC_VERSION == 4005
83543 + FOR_EACH_REFERENCED_VAR(var, rvi) {
83544 +#else
83545 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
83546 +#endif
83547 + tree type = TREE_TYPE(var);
83548 +
83549 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
83550 + continue;
83551 +
83552 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
83553 + continue;
83554 +
83555 + if (!TYPE_READONLY(type))
83556 + continue;
83557 +
83558 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
83559 +// continue;
83560 +
83561 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
83562 +// continue;
83563 +
83564 + if (walk_struct(type)) {
83565 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
83566 + return 1;
83567 + }
83568 + }
83569 + return 0;
83570 +}
83571 +
83572 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83573 +{
83574 + const char * const plugin_name = plugin_info->base_name;
83575 + const int argc = plugin_info->argc;
83576 + const struct plugin_argument * const argv = plugin_info->argv;
83577 + int i;
83578 + bool constify = true;
83579 +
83580 + struct register_pass_info local_variable_pass_info = {
83581 + .pass = &pass_local_variable.pass,
83582 + .reference_pass_name = "*referenced_vars",
83583 + .ref_pass_instance_number = 1,
83584 + .pos_op = PASS_POS_INSERT_AFTER
83585 + };
83586 +
83587 + if (!plugin_default_version_check(version, &gcc_version)) {
83588 + error(G_("incompatible gcc/plugin versions"));
83589 + return 1;
83590 + }
83591 +
83592 + for (i = 0; i < argc; ++i) {
83593 + if (!(strcmp(argv[i].key, "no-constify"))) {
83594 + constify = false;
83595 + continue;
83596 + }
83597 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83598 + }
83599 +
83600 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
83601 + if (constify) {
83602 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
83603 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
83604 + }
83605 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83606 +
83607 + return 0;
83608 +}
83609 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
83610 new file mode 100755
83611 index 0000000..02c6bec
83612 --- /dev/null
83613 +++ b/tools/gcc/generate_size_overflow_hash.sh
83614 @@ -0,0 +1,94 @@
83615 +#!/bin/bash
83616 +
83617 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
83618 +
83619 +header1="size_overflow_hash.h"
83620 +database="size_overflow_hash.data"
83621 +n=65536
83622 +
83623 +usage() {
83624 +cat <<EOF
83625 +usage: $0 options
83626 +OPTIONS:
83627 + -h|--help help
83628 + -o header file
83629 + -d database file
83630 + -n hash array size
83631 +EOF
83632 + return 0
83633 +}
83634 +
83635 +while true
83636 +do
83637 + case "$1" in
83638 + -h|--help) usage && exit 0;;
83639 + -n) n=$2; shift 2;;
83640 + -o) header1="$2"; shift 2;;
83641 + -d) database="$2"; shift 2;;
83642 + --) shift 1; break ;;
83643 + *) break ;;
83644 + esac
83645 +done
83646 +
83647 +create_defines() {
83648 + for i in `seq 1 32`
83649 + do
83650 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
83651 + done
83652 + echo >> "$header1"
83653 +}
83654 +
83655 +create_structs () {
83656 + rm -f "$header1"
83657 +
83658 + create_defines
83659 +
83660 + cat "$database" | while read data
83661 + do
83662 + data_array=($data)
83663 + struct_hash_name="${data_array[0]}"
83664 + funcn="${data_array[1]}"
83665 + params="${data_array[2]}"
83666 + next="${data_array[5]}"
83667 +
83668 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
83669 +
83670 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
83671 + echo -en "\t.param\t= " >> "$header1"
83672 + line=
83673 + for param_num in ${params//-/ };
83674 + do
83675 + line="${line}PARAM"$param_num"|"
83676 + done
83677 +
83678 + echo -e "${line%?},\n};\n" >> "$header1"
83679 + done
83680 +}
83681 +
83682 +create_headers () {
83683 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
83684 +}
83685 +
83686 +create_array_elements () {
83687 + index=0
83688 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
83689 + do
83690 + data_array=($data)
83691 + i="${data_array[3]}"
83692 + hash="${data_array[4]}"
83693 + while [[ $index -lt $i ]]
83694 + do
83695 + echo -e "\t["$index"]\t= NULL," >> "$header1"
83696 + index=$(($index + 1))
83697 + done
83698 + index=$(($index + 1))
83699 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
83700 + done
83701 + echo '};' >> $header1
83702 +}
83703 +
83704 +create_structs
83705 +create_headers
83706 +create_array_elements
83707 +
83708 +exit 0
83709 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
83710 new file mode 100644
83711 index 0000000..a86e422
83712 --- /dev/null
83713 +++ b/tools/gcc/kallocstat_plugin.c
83714 @@ -0,0 +1,167 @@
83715 +/*
83716 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83717 + * Licensed under the GPL v2
83718 + *
83719 + * Note: the choice of the license means that the compilation process is
83720 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83721 + * but for the kernel it doesn't matter since it doesn't link against
83722 + * any of the gcc libraries
83723 + *
83724 + * gcc plugin to find the distribution of k*alloc sizes
83725 + *
83726 + * TODO:
83727 + *
83728 + * BUGS:
83729 + * - none known
83730 + */
83731 +#include "gcc-plugin.h"
83732 +#include "config.h"
83733 +#include "system.h"
83734 +#include "coretypes.h"
83735 +#include "tree.h"
83736 +#include "tree-pass.h"
83737 +#include "flags.h"
83738 +#include "intl.h"
83739 +#include "toplev.h"
83740 +#include "plugin.h"
83741 +//#include "expr.h" where are you...
83742 +#include "diagnostic.h"
83743 +#include "plugin-version.h"
83744 +#include "tm.h"
83745 +#include "function.h"
83746 +#include "basic-block.h"
83747 +#include "gimple.h"
83748 +#include "rtl.h"
83749 +#include "emit-rtl.h"
83750 +
83751 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83752 +
83753 +int plugin_is_GPL_compatible;
83754 +
83755 +static const char * const kalloc_functions[] = {
83756 + "__kmalloc",
83757 + "kmalloc",
83758 + "kmalloc_large",
83759 + "kmalloc_node",
83760 + "kmalloc_order",
83761 + "kmalloc_order_trace",
83762 + "kmalloc_slab",
83763 + "kzalloc",
83764 + "kzalloc_node",
83765 +};
83766 +
83767 +static struct plugin_info kallocstat_plugin_info = {
83768 + .version = "201111150100",
83769 +};
83770 +
83771 +static unsigned int execute_kallocstat(void);
83772 +
83773 +static struct gimple_opt_pass kallocstat_pass = {
83774 + .pass = {
83775 + .type = GIMPLE_PASS,
83776 + .name = "kallocstat",
83777 + .gate = NULL,
83778 + .execute = execute_kallocstat,
83779 + .sub = NULL,
83780 + .next = NULL,
83781 + .static_pass_number = 0,
83782 + .tv_id = TV_NONE,
83783 + .properties_required = 0,
83784 + .properties_provided = 0,
83785 + .properties_destroyed = 0,
83786 + .todo_flags_start = 0,
83787 + .todo_flags_finish = 0
83788 + }
83789 +};
83790 +
83791 +static bool is_kalloc(const char *fnname)
83792 +{
83793 + size_t i;
83794 +
83795 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
83796 + if (!strcmp(fnname, kalloc_functions[i]))
83797 + return true;
83798 + return false;
83799 +}
83800 +
83801 +static unsigned int execute_kallocstat(void)
83802 +{
83803 + basic_block bb;
83804 +
83805 + // 1. loop through BBs and GIMPLE statements
83806 + FOR_EACH_BB(bb) {
83807 + gimple_stmt_iterator gsi;
83808 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83809 + // gimple match:
83810 + tree fndecl, size;
83811 + gimple call_stmt;
83812 + const char *fnname;
83813 +
83814 + // is it a call
83815 + call_stmt = gsi_stmt(gsi);
83816 + if (!is_gimple_call(call_stmt))
83817 + continue;
83818 + fndecl = gimple_call_fndecl(call_stmt);
83819 + if (fndecl == NULL_TREE)
83820 + continue;
83821 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
83822 + continue;
83823 +
83824 + // is it a call to k*alloc
83825 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
83826 + if (!is_kalloc(fnname))
83827 + continue;
83828 +
83829 + // is the size arg the result of a simple const assignment
83830 + size = gimple_call_arg(call_stmt, 0);
83831 + while (true) {
83832 + gimple def_stmt;
83833 + expanded_location xloc;
83834 + size_t size_val;
83835 +
83836 + if (TREE_CODE(size) != SSA_NAME)
83837 + break;
83838 + def_stmt = SSA_NAME_DEF_STMT(size);
83839 + if (!def_stmt || !is_gimple_assign(def_stmt))
83840 + break;
83841 + if (gimple_num_ops(def_stmt) != 2)
83842 + break;
83843 + size = gimple_assign_rhs1(def_stmt);
83844 + if (!TREE_CONSTANT(size))
83845 + continue;
83846 + xloc = expand_location(gimple_location(def_stmt));
83847 + if (!xloc.file)
83848 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
83849 + size_val = TREE_INT_CST_LOW(size);
83850 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
83851 + break;
83852 + }
83853 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83854 +//debug_tree(gimple_call_fn(call_stmt));
83855 +//print_node(stderr, "pax", fndecl, 4);
83856 + }
83857 + }
83858 +
83859 + return 0;
83860 +}
83861 +
83862 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83863 +{
83864 + const char * const plugin_name = plugin_info->base_name;
83865 + struct register_pass_info kallocstat_pass_info = {
83866 + .pass = &kallocstat_pass.pass,
83867 + .reference_pass_name = "ssa",
83868 + .ref_pass_instance_number = 1,
83869 + .pos_op = PASS_POS_INSERT_AFTER
83870 + };
83871 +
83872 + if (!plugin_default_version_check(version, &gcc_version)) {
83873 + error(G_("incompatible gcc/plugin versions"));
83874 + return 1;
83875 + }
83876 +
83877 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
83878 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
83879 +
83880 + return 0;
83881 +}
83882 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
83883 new file mode 100644
83884 index 0000000..8856202
83885 --- /dev/null
83886 +++ b/tools/gcc/kernexec_plugin.c
83887 @@ -0,0 +1,432 @@
83888 +/*
83889 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83890 + * Licensed under the GPL v2
83891 + *
83892 + * Note: the choice of the license means that the compilation process is
83893 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83894 + * but for the kernel it doesn't matter since it doesn't link against
83895 + * any of the gcc libraries
83896 + *
83897 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
83898 + *
83899 + * TODO:
83900 + *
83901 + * BUGS:
83902 + * - none known
83903 + */
83904 +#include "gcc-plugin.h"
83905 +#include "config.h"
83906 +#include "system.h"
83907 +#include "coretypes.h"
83908 +#include "tree.h"
83909 +#include "tree-pass.h"
83910 +#include "flags.h"
83911 +#include "intl.h"
83912 +#include "toplev.h"
83913 +#include "plugin.h"
83914 +//#include "expr.h" where are you...
83915 +#include "diagnostic.h"
83916 +#include "plugin-version.h"
83917 +#include "tm.h"
83918 +#include "function.h"
83919 +#include "basic-block.h"
83920 +#include "gimple.h"
83921 +#include "rtl.h"
83922 +#include "emit-rtl.h"
83923 +#include "tree-flow.h"
83924 +
83925 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83926 +extern rtx emit_move_insn(rtx x, rtx y);
83927 +
83928 +#if BUILDING_GCC_VERSION <= 4006
83929 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
83930 +#endif
83931 +
83932 +int plugin_is_GPL_compatible;
83933 +
83934 +static struct plugin_info kernexec_plugin_info = {
83935 + .version = "201111291120",
83936 + .help = "method=[bts|or]\tinstrumentation method\n"
83937 +};
83938 +
83939 +static unsigned int execute_kernexec_reload(void);
83940 +static unsigned int execute_kernexec_fptr(void);
83941 +static unsigned int execute_kernexec_retaddr(void);
83942 +static bool kernexec_cmodel_check(void);
83943 +
83944 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
83945 +static void (*kernexec_instrument_retaddr)(rtx);
83946 +
83947 +static struct gimple_opt_pass kernexec_reload_pass = {
83948 + .pass = {
83949 + .type = GIMPLE_PASS,
83950 + .name = "kernexec_reload",
83951 + .gate = kernexec_cmodel_check,
83952 + .execute = execute_kernexec_reload,
83953 + .sub = NULL,
83954 + .next = NULL,
83955 + .static_pass_number = 0,
83956 + .tv_id = TV_NONE,
83957 + .properties_required = 0,
83958 + .properties_provided = 0,
83959 + .properties_destroyed = 0,
83960 + .todo_flags_start = 0,
83961 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83962 + }
83963 +};
83964 +
83965 +static struct gimple_opt_pass kernexec_fptr_pass = {
83966 + .pass = {
83967 + .type = GIMPLE_PASS,
83968 + .name = "kernexec_fptr",
83969 + .gate = kernexec_cmodel_check,
83970 + .execute = execute_kernexec_fptr,
83971 + .sub = NULL,
83972 + .next = NULL,
83973 + .static_pass_number = 0,
83974 + .tv_id = TV_NONE,
83975 + .properties_required = 0,
83976 + .properties_provided = 0,
83977 + .properties_destroyed = 0,
83978 + .todo_flags_start = 0,
83979 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83980 + }
83981 +};
83982 +
83983 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83984 + .pass = {
83985 + .type = RTL_PASS,
83986 + .name = "kernexec_retaddr",
83987 + .gate = kernexec_cmodel_check,
83988 + .execute = execute_kernexec_retaddr,
83989 + .sub = NULL,
83990 + .next = NULL,
83991 + .static_pass_number = 0,
83992 + .tv_id = TV_NONE,
83993 + .properties_required = 0,
83994 + .properties_provided = 0,
83995 + .properties_destroyed = 0,
83996 + .todo_flags_start = 0,
83997 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83998 + }
83999 +};
84000 +
84001 +static bool kernexec_cmodel_check(void)
84002 +{
84003 + tree section;
84004 +
84005 + if (ix86_cmodel != CM_KERNEL)
84006 + return false;
84007 +
84008 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
84009 + if (!section || !TREE_VALUE(section))
84010 + return true;
84011 +
84012 + section = TREE_VALUE(TREE_VALUE(section));
84013 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
84014 + return true;
84015 +
84016 + return false;
84017 +}
84018 +
84019 +/*
84020 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
84021 + */
84022 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
84023 +{
84024 + gimple asm_movabs_stmt;
84025 +
84026 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
84027 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
84028 + gimple_asm_set_volatile(asm_movabs_stmt, true);
84029 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
84030 + update_stmt(asm_movabs_stmt);
84031 +}
84032 +
84033 +/*
84034 + * find all asm() stmts that clobber r10 and add a reload of r10
84035 + */
84036 +static unsigned int execute_kernexec_reload(void)
84037 +{
84038 + basic_block bb;
84039 +
84040 + // 1. loop through BBs and GIMPLE statements
84041 + FOR_EACH_BB(bb) {
84042 + gimple_stmt_iterator gsi;
84043 +
84044 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
84045 + // gimple match: __asm__ ("" : : : "r10");
84046 + gimple asm_stmt;
84047 + size_t nclobbers;
84048 +
84049 + // is it an asm ...
84050 + asm_stmt = gsi_stmt(gsi);
84051 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
84052 + continue;
84053 +
84054 + // ... clobbering r10
84055 + nclobbers = gimple_asm_nclobbers(asm_stmt);
84056 + while (nclobbers--) {
84057 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
84058 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
84059 + continue;
84060 + kernexec_reload_fptr_mask(&gsi);
84061 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
84062 + break;
84063 + }
84064 + }
84065 + }
84066 +
84067 + return 0;
84068 +}
84069 +
84070 +/*
84071 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
84072 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
84073 + */
84074 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
84075 +{
84076 + gimple assign_intptr, assign_new_fptr, call_stmt;
84077 + tree intptr, old_fptr, new_fptr, kernexec_mask;
84078 +
84079 + call_stmt = gsi_stmt(*gsi);
84080 + old_fptr = gimple_call_fn(call_stmt);
84081 +
84082 + // create temporary unsigned long variable used for bitops and cast fptr to it
84083 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
84084 + add_referenced_var(intptr);
84085 + mark_sym_for_renaming(intptr);
84086 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
84087 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
84088 + update_stmt(assign_intptr);
84089 +
84090 + // apply logical or to temporary unsigned long and bitmask
84091 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
84092 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
84093 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
84094 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
84095 + update_stmt(assign_intptr);
84096 +
84097 + // cast temporary unsigned long back to a temporary fptr variable
84098 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
84099 + add_referenced_var(new_fptr);
84100 + mark_sym_for_renaming(new_fptr);
84101 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
84102 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
84103 + update_stmt(assign_new_fptr);
84104 +
84105 + // replace call stmt fn with the new fptr
84106 + gimple_call_set_fn(call_stmt, new_fptr);
84107 + update_stmt(call_stmt);
84108 +}
84109 +
84110 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
84111 +{
84112 + gimple asm_or_stmt, call_stmt;
84113 + tree old_fptr, new_fptr, input, output;
84114 + VEC(tree, gc) *inputs = NULL;
84115 + VEC(tree, gc) *outputs = NULL;
84116 +
84117 + call_stmt = gsi_stmt(*gsi);
84118 + old_fptr = gimple_call_fn(call_stmt);
84119 +
84120 + // create temporary fptr variable
84121 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
84122 + add_referenced_var(new_fptr);
84123 + mark_sym_for_renaming(new_fptr);
84124 +
84125 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
84126 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
84127 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
84128 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
84129 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
84130 + VEC_safe_push(tree, gc, inputs, input);
84131 + VEC_safe_push(tree, gc, outputs, output);
84132 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
84133 + gimple_asm_set_volatile(asm_or_stmt, true);
84134 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
84135 + update_stmt(asm_or_stmt);
84136 +
84137 + // replace call stmt fn with the new fptr
84138 + gimple_call_set_fn(call_stmt, new_fptr);
84139 + update_stmt(call_stmt);
84140 +}
84141 +
84142 +/*
84143 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
84144 + */
84145 +static unsigned int execute_kernexec_fptr(void)
84146 +{
84147 + basic_block bb;
84148 +
84149 + // 1. loop through BBs and GIMPLE statements
84150 + FOR_EACH_BB(bb) {
84151 + gimple_stmt_iterator gsi;
84152 +
84153 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
84154 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
84155 + tree fn;
84156 + gimple call_stmt;
84157 +
84158 + // is it a call ...
84159 + call_stmt = gsi_stmt(gsi);
84160 + if (!is_gimple_call(call_stmt))
84161 + continue;
84162 + fn = gimple_call_fn(call_stmt);
84163 + if (TREE_CODE(fn) == ADDR_EXPR)
84164 + continue;
84165 + if (TREE_CODE(fn) != SSA_NAME)
84166 + gcc_unreachable();
84167 +
84168 + // ... through a function pointer
84169 + fn = SSA_NAME_VAR(fn);
84170 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
84171 + continue;
84172 + fn = TREE_TYPE(fn);
84173 + if (TREE_CODE(fn) != POINTER_TYPE)
84174 + continue;
84175 + fn = TREE_TYPE(fn);
84176 + if (TREE_CODE(fn) != FUNCTION_TYPE)
84177 + continue;
84178 +
84179 + kernexec_instrument_fptr(&gsi);
84180 +
84181 +//debug_tree(gimple_call_fn(call_stmt));
84182 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
84183 + }
84184 + }
84185 +
84186 + return 0;
84187 +}
84188 +
84189 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
84190 +static void kernexec_instrument_retaddr_bts(rtx insn)
84191 +{
84192 + rtx btsq;
84193 + rtvec argvec, constraintvec, labelvec;
84194 + int line;
84195 +
84196 + // create asm volatile("btsq $63,(%%rsp)":::)
84197 + argvec = rtvec_alloc(0);
84198 + constraintvec = rtvec_alloc(0);
84199 + labelvec = rtvec_alloc(0);
84200 + line = expand_location(RTL_LOCATION(insn)).line;
84201 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
84202 + MEM_VOLATILE_P(btsq) = 1;
84203 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
84204 + emit_insn_before(btsq, insn);
84205 +}
84206 +
84207 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
84208 +static void kernexec_instrument_retaddr_or(rtx insn)
84209 +{
84210 + rtx orq;
84211 + rtvec argvec, constraintvec, labelvec;
84212 + int line;
84213 +
84214 + // create asm volatile("orq %%r10,(%%rsp)":::)
84215 + argvec = rtvec_alloc(0);
84216 + constraintvec = rtvec_alloc(0);
84217 + labelvec = rtvec_alloc(0);
84218 + line = expand_location(RTL_LOCATION(insn)).line;
84219 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
84220 + MEM_VOLATILE_P(orq) = 1;
84221 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
84222 + emit_insn_before(orq, insn);
84223 +}
84224 +
84225 +/*
84226 + * find all asm level function returns and forcibly set the highest bit of the return address
84227 + */
84228 +static unsigned int execute_kernexec_retaddr(void)
84229 +{
84230 + rtx insn;
84231 +
84232 + // 1. find function returns
84233 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
84234 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
84235 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
84236 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
84237 + rtx body;
84238 +
84239 + // is it a retn
84240 + if (!JUMP_P(insn))
84241 + continue;
84242 + body = PATTERN(insn);
84243 + if (GET_CODE(body) == PARALLEL)
84244 + body = XVECEXP(body, 0, 0);
84245 + if (!ANY_RETURN_P(body))
84246 + continue;
84247 + kernexec_instrument_retaddr(insn);
84248 + }
84249 +
84250 +// print_simple_rtl(stderr, get_insns());
84251 +// print_rtl(stderr, get_insns());
84252 +
84253 + return 0;
84254 +}
84255 +
84256 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84257 +{
84258 + const char * const plugin_name = plugin_info->base_name;
84259 + const int argc = plugin_info->argc;
84260 + const struct plugin_argument * const argv = plugin_info->argv;
84261 + int i;
84262 + struct register_pass_info kernexec_reload_pass_info = {
84263 + .pass = &kernexec_reload_pass.pass,
84264 + .reference_pass_name = "ssa",
84265 + .ref_pass_instance_number = 1,
84266 + .pos_op = PASS_POS_INSERT_AFTER
84267 + };
84268 + struct register_pass_info kernexec_fptr_pass_info = {
84269 + .pass = &kernexec_fptr_pass.pass,
84270 + .reference_pass_name = "ssa",
84271 + .ref_pass_instance_number = 1,
84272 + .pos_op = PASS_POS_INSERT_AFTER
84273 + };
84274 + struct register_pass_info kernexec_retaddr_pass_info = {
84275 + .pass = &kernexec_retaddr_pass.pass,
84276 + .reference_pass_name = "pro_and_epilogue",
84277 + .ref_pass_instance_number = 1,
84278 + .pos_op = PASS_POS_INSERT_AFTER
84279 + };
84280 +
84281 + if (!plugin_default_version_check(version, &gcc_version)) {
84282 + error(G_("incompatible gcc/plugin versions"));
84283 + return 1;
84284 + }
84285 +
84286 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
84287 +
84288 + if (TARGET_64BIT == 0)
84289 + return 0;
84290 +
84291 + for (i = 0; i < argc; ++i) {
84292 + if (!strcmp(argv[i].key, "method")) {
84293 + if (!argv[i].value) {
84294 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84295 + continue;
84296 + }
84297 + if (!strcmp(argv[i].value, "bts")) {
84298 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
84299 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
84300 + } else if (!strcmp(argv[i].value, "or")) {
84301 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
84302 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
84303 + fix_register("r10", 1, 1);
84304 + } else
84305 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
84306 + continue;
84307 + }
84308 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84309 + }
84310 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
84311 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
84312 +
84313 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
84314 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
84315 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
84316 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
84317 +
84318 + return 0;
84319 +}
84320 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
84321 new file mode 100644
84322 index 0000000..b8008f7
84323 --- /dev/null
84324 +++ b/tools/gcc/latent_entropy_plugin.c
84325 @@ -0,0 +1,295 @@
84326 +/*
84327 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
84328 + * Licensed under the GPL v2
84329 + *
84330 + * Note: the choice of the license means that the compilation process is
84331 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84332 + * but for the kernel it doesn't matter since it doesn't link against
84333 + * any of the gcc libraries
84334 + *
84335 + * gcc plugin to help generate a little bit of entropy from program state,
84336 + * used during boot in the kernel
84337 + *
84338 + * TODO:
84339 + * - add ipa pass to identify not explicitly marked candidate functions
84340 + * - mix in more program state (function arguments/return values, loop variables, etc)
84341 + * - more instrumentation control via attribute parameters
84342 + *
84343 + * BUGS:
84344 + * - LTO needs -flto-partition=none for now
84345 + */
84346 +#include "gcc-plugin.h"
84347 +#include "config.h"
84348 +#include "system.h"
84349 +#include "coretypes.h"
84350 +#include "tree.h"
84351 +#include "tree-pass.h"
84352 +#include "flags.h"
84353 +#include "intl.h"
84354 +#include "toplev.h"
84355 +#include "plugin.h"
84356 +//#include "expr.h" where are you...
84357 +#include "diagnostic.h"
84358 +#include "plugin-version.h"
84359 +#include "tm.h"
84360 +#include "function.h"
84361 +#include "basic-block.h"
84362 +#include "gimple.h"
84363 +#include "rtl.h"
84364 +#include "emit-rtl.h"
84365 +#include "tree-flow.h"
84366 +
84367 +int plugin_is_GPL_compatible;
84368 +
84369 +static tree latent_entropy_decl;
84370 +
84371 +static struct plugin_info latent_entropy_plugin_info = {
84372 + .version = "201207271820",
84373 + .help = NULL
84374 +};
84375 +
84376 +static unsigned int execute_latent_entropy(void);
84377 +static bool gate_latent_entropy(void);
84378 +
84379 +static struct gimple_opt_pass latent_entropy_pass = {
84380 + .pass = {
84381 + .type = GIMPLE_PASS,
84382 + .name = "latent_entropy",
84383 + .gate = gate_latent_entropy,
84384 + .execute = execute_latent_entropy,
84385 + .sub = NULL,
84386 + .next = NULL,
84387 + .static_pass_number = 0,
84388 + .tv_id = TV_NONE,
84389 + .properties_required = PROP_gimple_leh | PROP_cfg,
84390 + .properties_provided = 0,
84391 + .properties_destroyed = 0,
84392 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
84393 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
84394 + }
84395 +};
84396 +
84397 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
84398 +{
84399 + if (TREE_CODE(*node) != FUNCTION_DECL) {
84400 + *no_add_attrs = true;
84401 + error("%qE attribute only applies to functions", name);
84402 + }
84403 + return NULL_TREE;
84404 +}
84405 +
84406 +static struct attribute_spec latent_entropy_attr = {
84407 + .name = "latent_entropy",
84408 + .min_length = 0,
84409 + .max_length = 0,
84410 + .decl_required = true,
84411 + .type_required = false,
84412 + .function_type_required = false,
84413 + .handler = handle_latent_entropy_attribute,
84414 +#if BUILDING_GCC_VERSION >= 4007
84415 + .affects_type_identity = false
84416 +#endif
84417 +};
84418 +
84419 +static void register_attributes(void *event_data, void *data)
84420 +{
84421 + register_attribute(&latent_entropy_attr);
84422 +}
84423 +
84424 +static bool gate_latent_entropy(void)
84425 +{
84426 + tree latent_entropy_attr;
84427 +
84428 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
84429 + return latent_entropy_attr != NULL_TREE;
84430 +}
84431 +
84432 +static unsigned HOST_WIDE_INT seed;
84433 +static unsigned HOST_WIDE_INT get_random_const(void)
84434 +{
84435 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
84436 + return seed;
84437 +}
84438 +
84439 +static enum tree_code get_op(tree *rhs)
84440 +{
84441 + static enum tree_code op;
84442 + unsigned HOST_WIDE_INT random_const;
84443 +
84444 + random_const = get_random_const();
84445 +
84446 + switch (op) {
84447 + case BIT_XOR_EXPR:
84448 + op = PLUS_EXPR;
84449 + break;
84450 +
84451 + case PLUS_EXPR:
84452 + if (rhs) {
84453 + op = LROTATE_EXPR;
84454 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
84455 + break;
84456 + }
84457 +
84458 + case LROTATE_EXPR:
84459 + default:
84460 + op = BIT_XOR_EXPR;
84461 + break;
84462 + }
84463 + if (rhs)
84464 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
84465 + return op;
84466 +}
84467 +
84468 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
84469 +{
84470 + gimple_stmt_iterator gsi;
84471 + gimple assign;
84472 + tree addxorrol, rhs;
84473 + enum tree_code op;
84474 +
84475 + op = get_op(&rhs);
84476 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
84477 + assign = gimple_build_assign(local_entropy, addxorrol);
84478 + find_referenced_vars_in(assign);
84479 +//debug_bb(bb);
84480 + gsi = gsi_after_labels(bb);
84481 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
84482 + update_stmt(assign);
84483 +}
84484 +
84485 +static void perturb_latent_entropy(basic_block bb, tree rhs)
84486 +{
84487 + gimple_stmt_iterator gsi;
84488 + gimple assign;
84489 + tree addxorrol, temp;
84490 +
84491 + // 1. create temporary copy of latent_entropy
84492 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
84493 + add_referenced_var(temp);
84494 + mark_sym_for_renaming(temp);
84495 +
84496 + // 2. read...
84497 + assign = gimple_build_assign(temp, latent_entropy_decl);
84498 + find_referenced_vars_in(assign);
84499 + gsi = gsi_after_labels(bb);
84500 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84501 + update_stmt(assign);
84502 +
84503 + // 3. ...modify...
84504 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
84505 + assign = gimple_build_assign(temp, addxorrol);
84506 + find_referenced_vars_in(assign);
84507 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84508 + update_stmt(assign);
84509 +
84510 + // 4. ...write latent_entropy
84511 + assign = gimple_build_assign(latent_entropy_decl, temp);
84512 + find_referenced_vars_in(assign);
84513 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84514 + update_stmt(assign);
84515 +}
84516 +
84517 +static unsigned int execute_latent_entropy(void)
84518 +{
84519 + basic_block bb;
84520 + gimple assign;
84521 + gimple_stmt_iterator gsi;
84522 + tree local_entropy;
84523 +
84524 + if (!latent_entropy_decl) {
84525 + struct varpool_node *node;
84526 +
84527 + for (node = varpool_nodes; node; node = node->next) {
84528 + tree var = node->decl;
84529 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
84530 + continue;
84531 + latent_entropy_decl = var;
84532 +// debug_tree(var);
84533 + break;
84534 + }
84535 + if (!latent_entropy_decl) {
84536 +// debug_tree(current_function_decl);
84537 + return 0;
84538 + }
84539 + }
84540 +
84541 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
84542 +
84543 + // 1. create local entropy variable
84544 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
84545 + add_referenced_var(local_entropy);
84546 + mark_sym_for_renaming(local_entropy);
84547 +
84548 + // 2. initialize local entropy variable
84549 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
84550 + if (dom_info_available_p(CDI_DOMINATORS))
84551 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
84552 + gsi = gsi_start_bb(bb);
84553 +
84554 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
84555 +// gimple_set_location(assign, loc);
84556 + find_referenced_vars_in(assign);
84557 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84558 + update_stmt(assign);
84559 + bb = bb->next_bb;
84560 +
84561 + // 3. instrument each BB with an operation on the local entropy variable
84562 + while (bb != EXIT_BLOCK_PTR) {
84563 + perturb_local_entropy(bb, local_entropy);
84564 + bb = bb->next_bb;
84565 + };
84566 +
84567 + // 4. mix local entropy into the global entropy variable
84568 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
84569 + return 0;
84570 +}
84571 +
84572 +static void start_unit_callback(void *gcc_data, void *user_data)
84573 +{
84574 +#if BUILDING_GCC_VERSION >= 4007
84575 + seed = get_random_seed(false);
84576 +#else
84577 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
84578 + seed *= seed;
84579 +#endif
84580 +
84581 + if (in_lto_p)
84582 + return;
84583 +
84584 + // extern u64 latent_entropy
84585 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
84586 +
84587 + TREE_STATIC(latent_entropy_decl) = 1;
84588 + TREE_PUBLIC(latent_entropy_decl) = 1;
84589 + TREE_USED(latent_entropy_decl) = 1;
84590 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
84591 + DECL_EXTERNAL(latent_entropy_decl) = 1;
84592 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
84593 + DECL_INITIAL(latent_entropy_decl) = NULL;
84594 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
84595 +// varpool_finalize_decl(latent_entropy_decl);
84596 +// varpool_mark_needed_node(latent_entropy_decl);
84597 +}
84598 +
84599 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84600 +{
84601 + const char * const plugin_name = plugin_info->base_name;
84602 + struct register_pass_info latent_entropy_pass_info = {
84603 + .pass = &latent_entropy_pass.pass,
84604 + .reference_pass_name = "optimized",
84605 + .ref_pass_instance_number = 1,
84606 + .pos_op = PASS_POS_INSERT_BEFORE
84607 + };
84608 +
84609 + if (!plugin_default_version_check(version, &gcc_version)) {
84610 + error(G_("incompatible gcc/plugin versions"));
84611 + return 1;
84612 + }
84613 +
84614 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
84615 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84616 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
84617 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84618 +
84619 + return 0;
84620 +}
84621 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
84622 new file mode 100644
84623 index 0000000..67468e3
84624 --- /dev/null
84625 +++ b/tools/gcc/size_overflow_hash.data
84626 @@ -0,0 +1,3600 @@
84627 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
84628 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
84629 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
84630 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
84631 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
84632 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
84633 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
84634 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
84635 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
84636 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
84637 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
84638 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
84639 +_000014_hash kmemdup 2 64015 _000014_hash NULL
84640 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
84641 +_000016_hash memdup_user 2 59590 _000016_hash NULL
84642 +_000017_hash module_alloc 1 63630 _000017_hash NULL
84643 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
84644 +_000019_hash read_kcore 3 63488 _000019_hash NULL
84645 +_000020_hash read_ldt 2 47570 _000020_hash NULL
84646 +_000021_hash read_zero 3 19366 _000021_hash NULL
84647 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
84648 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
84649 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
84650 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
84651 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
84652 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
84653 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
84654 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
84655 +_000031_hash adu_write 3 30487 _000031_hash NULL
84656 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
84657 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
84658 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
84659 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
84660 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
84661 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
84662 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
84663 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
84664 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
84665 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
84666 +_000044_hash alloc_context 1 3194 _000044_hash NULL
84667 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
84668 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
84669 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
84670 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
84671 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
84672 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
84673 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
84674 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
84675 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
84676 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
84677 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
84678 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
84679 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
84680 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
84681 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
84682 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
84683 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
84684 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
84685 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
84686 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
84687 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
84688 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
84689 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
84690 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
84691 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
84692 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
84693 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
84694 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
84695 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
84696 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
84697 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
84698 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
84699 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
84700 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
84701 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
84702 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
84703 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
84704 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
84705 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
84706 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
84707 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
84708 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
84709 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
84710 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
84711 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
84712 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
84713 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
84714 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
84715 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
84716 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
84717 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
84718 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
84719 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
84720 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
84721 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
84722 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
84723 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
84724 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
84725 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
84726 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
84727 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
84728 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
84729 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
84730 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
84731 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
84732 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
84733 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
84734 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
84735 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
84736 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
84737 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
84738 +_000122_hash change_xattr 5 61390 _000122_hash NULL
84739 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
84740 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
84741 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
84742 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
84743 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
84744 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
84745 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
84746 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
84747 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
84748 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
84749 +_000133_hash cmm_write 3 2896 _000133_hash NULL
84750 +_000134_hash cm_write 3 36858 _000134_hash NULL
84751 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
84752 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
84753 +_000137_hash command_file_write 3 31318 _000137_hash NULL
84754 +_000138_hash command_write 3 58841 _000138_hash NULL
84755 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
84756 +_000140_hash concat_writev 3 21451 _000140_hash NULL
84757 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
84758 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
84759 +_000143_hash copy_items 6 50140 _000143_hash NULL
84760 +_000144_hash copy_macs 4 45534 _000144_hash NULL
84761 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
84762 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
84763 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
84764 +_000148_hash cosa_write 3 1774 _000148_hash NULL
84765 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
84766 +_000150_hash create_entry 2 33479 _000150_hash NULL
84767 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
84768 +_000153_hash create_xattr 5 54106 _000153_hash NULL
84769 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
84770 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
84771 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
84772 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
84773 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
84774 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
84775 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
84776 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
84777 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
84778 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
84779 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
84780 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
84781 +_000168_hash dev_config 3 8506 _000168_hash NULL
84782 +_000169_hash device_write 3 45156 _000169_hash NULL
84783 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
84784 +_000171_hash devres_alloc 2 551 _000171_hash NULL
84785 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
84786 +_000173_hash direct_entry 3 38836 _000173_hash NULL
84787 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
84788 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
84789 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
84790 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
84791 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
84792 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
84793 +_000180_hash dm_read 3 15674 _000180_hash NULL
84794 +_000181_hash dm_write 3 2513 _000181_hash NULL
84795 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
84796 +_000183_hash dns_query 3 9676 _000183_hash NULL
84797 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
84798 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
84799 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
84800 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
84801 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
84802 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
84803 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
84804 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
84805 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
84806 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
84807 +_000194_hash dsp_write 2 46218 _000194_hash NULL
84808 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
84809 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
84810 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
84811 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
84812 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
84813 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
84814 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
84815 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
84816 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
84817 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
84818 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
84819 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
84820 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
84821 +_000208_hash ep_read 3 58813 _000208_hash NULL
84822 +_000209_hash ep_write 3 59008 _000209_hash NULL
84823 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
84824 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
84825 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
84826 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
84827 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
84828 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
84829 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
84830 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
84831 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
84832 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
84833 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
84834 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
84835 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
84836 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
84837 +_000225_hash fl_create 5 56435 _000225_hash NULL
84838 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
84839 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
84840 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
84841 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
84842 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
84843 +_000231_hash get_arg 3 5694 _000231_hash NULL
84844 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
84845 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
84846 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
84847 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
84848 +_000236_hash get_registers 3 26187 _000236_hash NULL
84849 +_000237_hash get_scq 2 10897 _000237_hash NULL
84850 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
84851 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
84852 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
84853 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
84854 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
84855 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
84856 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
84857 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
84858 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
84859 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
84860 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
84861 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
84862 +_000250_hash handle_request 9 10024 _000250_hash NULL
84863 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
84864 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
84865 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
84866 +_000254_hash heap_init 2 49617 _000254_hash NULL
84867 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
84868 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
84869 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
84870 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
84871 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
84872 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
84873 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
84874 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
84875 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
84876 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
84877 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
84878 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
84879 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
84880 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
84881 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
84882 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
84883 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
84884 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
84885 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
84886 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
84887 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
84888 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
84889 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
84890 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
84891 +_000279_hash if_write 3 51756 _000279_hash NULL
84892 +_000280_hash ilo_write 3 64378 _000280_hash NULL
84893 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
84894 +_000282_hash init_data_container 1 60709 _000282_hash NULL
84895 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
84896 +_000284_hash insert_dent 7 65034 _000284_hash NULL
84897 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
84898 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
84899 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
84900 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
84901 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
84902 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
84903 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
84904 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
84905 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
84906 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
84907 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
84908 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
84909 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
84910 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
84911 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
84912 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
84913 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
84914 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
84915 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
84916 +_000304_hash isdn_read 3 50021 _000304_hash NULL
84917 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
84918 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
84919 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
84920 +_000308_hash iso_callback 3 43208 _000308_hash NULL
84921 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
84922 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
84923 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
84924 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
84925 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
84926 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
84927 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
84928 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
84929 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
84930 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
84931 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
84932 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
84933 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
84934 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
84935 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
84936 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
84937 +_000328_hash kone_receive 4 4690 _000328_hash NULL
84938 +_000329_hash kone_send 4 63435 _000329_hash NULL
84939 +_000330_hash krealloc 2 14908 _000330_hash NULL
84940 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
84941 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
84942 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
84943 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
84944 +_000335_hash kzalloc 1 54740 _000335_hash NULL
84945 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
84946 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
84947 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
84948 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
84949 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
84950 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
84951 +_000342_hash __lgread 4 31668 _000342_hash NULL
84952 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
84953 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
84954 +_000345_hash listxattr 3 12769 _000345_hash NULL
84955 +_000346_hash load_msg 2 95 _000346_hash NULL
84956 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
84957 +_000348_hash lp_write 3 9511 _000348_hash NULL
84958 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
84959 +_000350_hash mce_write 3 26201 _000350_hash NULL
84960 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
84961 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
84962 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
84963 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
84964 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
84965 +_000357_hash mem_rw 3 22085 _000357_hash NULL
84966 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
84967 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
84968 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
84969 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
84970 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
84971 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
84972 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
84973 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
84974 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
84975 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
84976 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
84977 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
84978 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
84979 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
84980 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
84981 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
84982 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
84983 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
84984 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
84985 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
84986 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
84987 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
84988 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
84989 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
84990 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
84991 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
84992 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
84993 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
84994 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
84995 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
84996 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
84997 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
84998 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
84999 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
85000 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
85001 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
85002 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
85003 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
85004 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
85005 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
85006 +_000404_hash nvram_write 3 3894 _000404_hash NULL
85007 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
85008 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
85009 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
85010 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
85011 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
85012 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
85013 +_000411_hash opticon_write 4 60775 _000411_hash NULL
85014 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
85015 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
85016 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
85017 +_000415_hash parse_command 2 37079 _000415_hash NULL
85018 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
85019 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
85020 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
85021 +_000419_hash pg_write 3 40766 _000419_hash NULL
85022 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
85023 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
85024 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
85025 +_000423_hash pkt_add 3 39897 _000423_hash NULL
85026 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
85027 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
85028 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
85029 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
85030 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
85031 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
85032 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
85033 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
85034 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
85035 +_000433_hash ppp_write 3 34034 _000433_hash NULL
85036 +_000434_hash pp_read 3 33210 _000434_hash NULL
85037 +_000435_hash pp_write 3 39554 _000435_hash NULL
85038 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
85039 +_000437_hash printer_write 3 60276 _000437_hash NULL
85040 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
85041 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
85042 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
85043 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
85044 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
85045 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
85046 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
85047 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
85048 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
85049 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
85050 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
85051 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
85052 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
85053 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
85054 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
85055 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
85056 +_000456_hash pt_write 3 40159 _000456_hash NULL
85057 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
85058 +_000458_hash r3964_write 4 57662 _000458_hash NULL
85059 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
85060 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
85061 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
85062 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
85063 +_000463_hash rbd_add 3 16366 _000463_hash NULL
85064 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
85065 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
85066 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
85067 +_000467_hash read 3 9397 _000467_hash NULL
85068 +_000468_hash read_buf 2 20469 _000468_hash NULL
85069 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
85070 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
85071 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
85072 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
85073 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
85074 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
85075 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
85076 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
85077 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
85078 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
85079 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
85080 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
85081 +_000481_hash revalidate 2 19043 _000481_hash NULL
85082 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
85083 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
85084 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
85085 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
85086 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
85087 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
85088 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
85089 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
85090 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
85091 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
85092 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
85093 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
85094 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
85095 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
85096 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
85097 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
85098 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
85099 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
85100 +_000500_hash savemem 3 58129 _000500_hash NULL
85101 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
85102 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
85103 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
85104 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
85105 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
85106 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
85107 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
85108 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
85109 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
85110 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
85111 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
85112 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
85113 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
85114 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
85115 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
85116 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
85117 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
85118 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
85119 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
85120 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
85121 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
85122 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
85123 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
85124 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
85125 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
85126 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
85127 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
85128 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
85129 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
85130 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
85131 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
85132 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
85133 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
85134 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
85135 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
85136 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
85137 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
85138 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
85139 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
85140 +_000542_hash set_registers 3 53582 _000542_hash NULL
85141 +_000543_hash setsockopt 5 54539 _000543_hash NULL
85142 +_000544_hash setup_req 3 5848 _000544_hash NULL
85143 +_000545_hash setxattr 4 37006 _000545_hash NULL
85144 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
85145 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
85146 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
85147 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
85148 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
85149 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
85150 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
85151 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
85152 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
85153 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
85154 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
85155 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
85156 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
85157 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
85158 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
85159 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
85160 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
85161 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
85162 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
85163 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
85164 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
85165 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
85166 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
85167 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
85168 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
85169 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
85170 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
85171 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
85172 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
85173 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
85174 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
85175 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
85176 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
85177 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
85178 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
85179 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
85180 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
85181 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
85182 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
85183 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
85184 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
85185 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
85186 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
85187 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
85188 +_000592_hash spidev_write 3 44510 _000592_hash NULL
85189 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
85190 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
85191 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
85192 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
85193 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
85194 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
85195 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
85196 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
85197 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
85198 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
85199 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
85200 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
85201 +_000606_hash tower_write 3 8580 _000606_hash NULL
85202 +_000607_hash tpm_write 3 50798 _000607_hash NULL
85203 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
85204 +_000609_hash trusted_update 3 12664 _000609_hash NULL
85205 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
85206 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
85207 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
85208 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
85209 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
85210 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
85211 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
85212 +_000617_hash uea_request 4 47613 _000617_hash NULL
85213 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
85214 +_000619_hash uio_write 3 43202 _000619_hash NULL
85215 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
85216 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
85217 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
85218 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
85219 +_000624_hash usblp_write 3 23178 _000624_hash NULL
85220 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
85221 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
85222 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
85223 +_000629_hash user_update 3 41332 _000629_hash NULL
85224 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
85225 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
85226 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
85227 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
85228 +_000635_hash vcs_write 3 3910 _000635_hash NULL
85229 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
85230 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
85231 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
85232 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
85233 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
85234 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
85235 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
85236 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
85237 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
85238 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
85239 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
85240 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
85241 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
85242 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
85243 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
85244 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
85245 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
85246 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
85247 +_000656_hash wdm_write 3 53735 _000656_hash NULL
85248 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
85249 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
85250 +_000659_hash write 3 62671 _000659_hash NULL
85251 +_000660_hash write_flush 3 50803 _000660_hash NULL
85252 +_000661_hash write_rio 3 54837 _000661_hash NULL
85253 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
85254 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
85255 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
85256 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
85257 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
85258 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
85259 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
85260 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
85261 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
85262 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
85263 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
85264 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
85265 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
85266 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
85267 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
85268 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
85269 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
85270 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
85271 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
85272 +_000683_hash add_res_range 4 21310 _000683_hash NULL
85273 +_000684_hash addtgt 3 54703 _000684_hash NULL
85274 +_000685_hash add_uuid 4 49831 _000685_hash NULL
85275 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
85276 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
85277 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
85278 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
85279 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
85280 +_000691_hash alloc_async 1 14208 _000691_hash NULL
85281 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
85282 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
85283 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
85284 +_000695_hash alloc_context 1 41283 _000695_hash NULL
85285 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
85286 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
85287 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
85288 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
85289 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
85290 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
85291 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
85292 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
85293 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
85294 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
85295 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
85296 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
85297 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
85298 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
85299 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
85300 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
85301 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
85302 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
85303 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
85304 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
85305 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
85306 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
85307 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
85308 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
85309 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
85310 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
85311 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
85312 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
85313 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
85314 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
85315 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
85316 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
85317 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
85318 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
85319 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
85320 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
85321 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
85322 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
85323 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
85324 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
85325 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
85326 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
85327 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
85328 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
85329 +_000746_hash audit_expand 2 2098 _000746_hash NULL
85330 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
85331 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
85332 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
85333 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
85334 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
85335 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
85336 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
85337 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
85338 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
85339 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
85340 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
85341 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
85342 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
85343 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
85344 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
85345 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
85346 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
85347 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
85348 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
85349 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
85350 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
85351 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
85352 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
85353 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
85354 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
85355 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
85356 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
85357 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
85358 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
85359 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
85360 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
85361 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
85362 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
85363 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
85364 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
85365 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
85366 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
85367 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
85368 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
85369 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
85370 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
85371 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
85372 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
85373 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
85374 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
85375 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
85376 +_000799_hash construct_key 3 11329 _000799_hash NULL
85377 +_000800_hash context_alloc 3 24645 _000800_hash NULL
85378 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
85379 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
85380 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
85381 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
85382 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
85383 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
85384 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
85385 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
85386 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
85387 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
85388 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
85389 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
85390 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
85391 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
85392 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
85393 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
85394 +_000819_hash depth_write 3 3021 _000819_hash NULL
85395 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
85396 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
85397 +_000822_hash dev_write 3 7708 _000822_hash NULL
85398 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
85399 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
85400 +_000825_hash disconnect 4 32521 _000825_hash NULL
85401 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
85402 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
85403 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
85404 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
85405 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
85406 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
85407 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
85408 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
85409 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
85410 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
85411 +_000837_hash do_pselect 1 62061 _000837_hash NULL
85412 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
85413 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
85414 +_000840_hash do_sync 1 9604 _000840_hash NULL
85415 +_000841_hash dup_array 3 33551 _000841_hash NULL
85416 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
85417 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
85418 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
85419 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
85420 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
85421 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
85422 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
85423 +_000849_hash enable_write 3 30456 _000849_hash NULL
85424 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
85425 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
85426 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
85427 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
85428 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
85429 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
85430 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
85431 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
85432 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
85433 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
85434 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
85435 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
85436 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
85437 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
85438 +_000864_hash fillonedir 3 41746 _000864_hash NULL
85439 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
85440 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
85441 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
85442 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
85443 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
85444 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
85445 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
85446 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
85447 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
85448 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
85449 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
85450 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
85451 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
85452 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
85453 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
85454 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
85455 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
85456 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
85457 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
85458 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
85459 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
85460 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
85461 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
85462 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
85463 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
85464 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
85465 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
85466 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
85467 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
85468 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
85469 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
85470 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
85471 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
85472 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
85473 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
85474 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
85475 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
85476 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
85477 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
85478 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
85479 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
85480 +_000909_hash if_writecmd 2 815 _000909_hash NULL
85481 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
85482 +_000912_hash init_ipath 1 48187 _000912_hash NULL
85483 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
85484 +_000915_hash init_q 4 132 _000915_hash NULL
85485 +_000916_hash init_state 2 60165 _000916_hash NULL
85486 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
85487 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
85488 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
85489 +_000920_hash interfaces 2 38859 _000920_hash NULL
85490 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
85491 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
85492 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
85493 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
85494 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
85495 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
85496 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
85497 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
85498 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
85499 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
85500 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
85501 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
85502 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
85503 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
85504 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
85505 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
85506 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
85507 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
85508 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
85509 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
85510 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
85511 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
85512 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
85513 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
85514 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
85515 +_000948_hash isdn_write 3 45863 _000948_hash NULL
85516 +_000949_hash isku_receive 4 54130 _000949_hash NULL
85517 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
85518 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
85519 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
85520 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
85521 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
85522 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
85523 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
85524 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
85525 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
85526 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
85527 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
85528 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
85529 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
85530 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
85531 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
85532 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
85533 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
85534 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
85535 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
85536 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
85537 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
85538 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
85539 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
85540 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
85541 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
85542 +_000977_hash lc_create 3 48662 _000977_hash NULL
85543 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
85544 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
85545 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
85546 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
85547 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
85548 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
85549 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
85550 +_000985_hash mem_read 3 57631 _000985_hash NULL
85551 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
85552 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
85553 +_000988_hash mem_write 3 22232 _000988_hash NULL
85554 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
85555 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
85556 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
85557 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
85558 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
85559 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
85560 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
85561 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
85562 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
85563 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
85564 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
85565 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
85566 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
85567 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
85568 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
85569 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
85570 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
85571 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
85572 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
85573 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
85574 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
85575 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
85576 +_001014_hash new_dir 3 31919 _001014_hash NULL
85577 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
85578 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
85579 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
85580 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
85581 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
85582 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
85583 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
85584 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
85585 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
85586 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
85587 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
85588 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
85589 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
85590 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
85591 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
85592 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
85593 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
85594 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
85595 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
85596 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
85597 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
85598 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
85599 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
85600 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
85601 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
85602 +_001046_hash osst_write 3 31581 _001046_hash NULL
85603 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
85604 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
85605 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
85606 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
85607 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
85608 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
85609 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
85610 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
85611 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
85612 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
85613 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
85614 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
85615 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
85616 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
85617 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
85618 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
85619 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
85620 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
85621 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
85622 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
85623 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
85624 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
85625 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
85626 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
85627 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
85628 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
85629 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
85630 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
85631 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
85632 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
85633 +_001083_hash proc_write 3 51003 _001083_hash NULL
85634 +_001084_hash profile_load 3 58267 _001084_hash NULL
85635 +_001085_hash profile_remove 3 8556 _001085_hash NULL
85636 +_001086_hash profile_replace 3 14652 _001086_hash NULL
85637 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
85638 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
85639 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
85640 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
85641 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
85642 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
85643 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
85644 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
85645 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
85646 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
85647 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
85648 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
85649 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
85650 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
85651 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
85652 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
85653 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
85654 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
85655 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
85656 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
85657 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
85658 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
85659 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
85660 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
85661 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
85662 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
85663 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
85664 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
85665 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
85666 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
85667 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
85668 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
85669 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
85670 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
85671 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
85672 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
85673 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
85674 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
85675 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
85676 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
85677 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
85678 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
85679 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
85680 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
85681 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
85682 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
85683 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
85684 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
85685 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
85686 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
85687 +_001139_hash self_check_write 5 50856 _001139_hash NULL
85688 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
85689 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
85690 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
85691 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
85692 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
85693 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
85694 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
85695 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
85696 +_001148_hash set_connectable 4 56458 _001148_hash NULL
85697 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
85698 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
85699 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
85700 +_001152_hash setkey 3 14987 _001152_hash NULL
85701 +_001153_hash set_le 4 30581 _001153_hash NULL
85702 +_001154_hash set_link_security 4 4502 _001154_hash NULL
85703 +_001155_hash set_local_name 4 55757 _001155_hash NULL
85704 +_001156_hash set_powered 4 12129 _001156_hash NULL
85705 +_001157_hash set_ssp 4 62411 _001157_hash NULL
85706 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
85707 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
85708 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
85709 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
85710 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
85711 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
85712 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
85713 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
85714 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
85715 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
85716 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
85717 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
85718 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
85719 +_001174_hash skb_pad 2 17302 _001174_hash NULL
85720 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
85721 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
85722 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
85723 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
85724 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
85725 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
85726 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
85727 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
85728 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
85729 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
85730 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
85731 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
85732 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
85733 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
85734 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
85735 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
85736 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
85737 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
85738 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
85739 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
85740 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
85741 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
85742 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
85743 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
85744 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
85745 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
85746 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
85747 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
85748 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
85749 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
85750 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
85751 +_001208_hash sound_write 3 5102 _001208_hash NULL
85752 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
85753 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
85754 +_001213_hash spidev_message 3 5518 _001213_hash NULL
85755 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
85756 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
85757 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
85758 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
85759 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
85760 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
85761 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
85762 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
85763 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
85764 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
85765 +_001227_hash st_write 3 16874 _001227_hash NULL
85766 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
85767 +_001229_hash symtab_init 2 61050 _001229_hash NULL
85768 +_001230_hash sys_bind 3 10799 _001230_hash NULL
85769 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
85770 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
85771 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
85772 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
85773 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
85774 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
85775 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
85776 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
85777 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
85778 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
85779 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
85780 +_001242_hash sys_select 1 38827 _001242_hash NULL
85781 +_001243_hash sys_semop 3 39457 _001243_hash NULL
85782 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
85783 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
85784 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
85785 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
85786 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
85787 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
85788 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
85789 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
85790 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
85791 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
85792 +_001254_hash timeout_write 3 50991 _001254_hash NULL
85793 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
85794 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
85795 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
85796 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
85797 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
85798 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
85799 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
85800 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
85801 +_001264_hash tty_write 3 5494 _001264_hash NULL
85802 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
85803 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
85804 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
85805 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
85806 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
85807 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
85808 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
85809 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
85810 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
85811 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
85812 +_001277_hash vhci_write 3 2224 _001277_hash NULL
85813 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
85814 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
85815 +_001281_hash vmalloc 1 15464 _001281_hash NULL
85816 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
85817 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
85818 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
85819 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
85820 +_001286_hash vzalloc 1 47421 _001286_hash NULL
85821 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
85822 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
85823 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
85824 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
85825 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
85826 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
85827 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
85828 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
85829 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
85830 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
85831 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
85832 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
85833 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
85834 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
85835 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
85836 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
85837 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
85838 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
85839 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
85840 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
85841 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
85842 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
85843 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
85844 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
85845 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
85846 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
85847 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
85848 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
85849 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
85850 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
85851 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
85852 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
85853 +_001319_hash add_child 4 45201 _001319_hash NULL
85854 +_001320_hash add_port 2 54941 _001320_hash NULL
85855 +_001321_hash adu_read 3 24177 _001321_hash NULL
85856 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
85857 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
85858 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
85859 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
85860 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
85861 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
85862 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
85863 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
85864 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
85865 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
85866 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
85867 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
85868 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
85869 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
85870 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
85871 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
85872 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
85873 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
85874 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
85875 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
85876 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
85877 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
85878 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
85879 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
85880 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
85881 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
85882 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
85883 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
85884 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
85885 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
85886 +_001356_hash async_setkey 3 35521 _001356_hash NULL
85887 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
85888 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
85889 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
85890 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
85891 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
85892 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
85893 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
85894 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
85895 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
85896 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
85897 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
85898 +_001370_hash ax25_output 2 22736 _001370_hash NULL
85899 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
85900 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
85901 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
85902 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
85903 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
85904 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
85905 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
85906 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
85907 +_001380_hash bm_init 2 13529 _001380_hash NULL
85908 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
85909 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
85910 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
85911 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
85912 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
85913 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
85914 +_001387_hash cache_read 3 24790 _001387_hash NULL
85915 +_001388_hash cache_write 3 13589 _001388_hash NULL
85916 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
85917 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
85918 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
85919 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
85920 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
85921 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
85922 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
85923 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
85924 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
85925 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
85926 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
85927 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
85928 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
85929 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
85930 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
85931 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
85932 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
85933 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
85934 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
85935 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
85936 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
85937 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
85938 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
85939 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
85940 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
85941 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
85942 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
85943 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
85944 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
85945 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
85946 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
85947 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
85948 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
85949 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
85950 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
85951 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
85952 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
85953 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
85954 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
85955 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
85956 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
85957 +_001435_hash do_readlink 2 43518 _001435_hash NULL
85958 +_001436_hash __do_replace 5 37227 _001436_hash NULL
85959 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
85960 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
85961 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
85962 +_001440_hash dump_midi 3 51040 _001440_hash NULL
85963 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
85964 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
85965 +_001443_hash ep0_read 3 38095 _001443_hash NULL
85966 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
85967 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
85968 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
85969 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
85970 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
85971 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
85972 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
85973 +_001451_hash filldir 3 55137 _001451_hash NULL
85974 +_001452_hash filldir64 3 46469 _001452_hash NULL
85975 +_001453_hash find_skb 2 20431 _001453_hash NULL
85976 +_001454_hash from_buffer 3 18625 _001454_hash NULL
85977 +_001455_hash fsm_init 2 16134 _001455_hash NULL
85978 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
85979 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
85980 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
85981 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
85982 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
85983 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
85984 +_001462_hash get_packet 3 41914 _001462_hash NULL
85985 +_001463_hash get_packet 3 5747 _001463_hash NULL
85986 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
85987 +_001465_hash get_skb 2 63008 _001465_hash NULL
85988 +_001466_hash get_subdir 3 62581 _001466_hash NULL
85989 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
85990 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
85991 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
85992 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
85993 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
85994 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
85995 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
85996 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
85997 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
85998 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
85999 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
86000 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
86001 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
86002 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
86003 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
86004 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
86005 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
86006 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
86007 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
86008 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
86009 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
86010 +_001489_hash ilo_read 3 32531 _001489_hash NULL
86011 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
86012 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
86013 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
86014 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
86015 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
86016 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
86017 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
86018 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
86019 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
86020 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
86021 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
86022 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
86023 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
86024 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
86025 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
86026 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
86027 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
86028 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
86029 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
86030 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
86031 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
86032 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
86033 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
86034 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
86035 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
86036 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
86037 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
86038 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
86039 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
86040 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
86041 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
86042 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
86043 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
86044 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
86045 +_001530_hash keyring_read 3 13438 _001530_hash NULL
86046 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
86047 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
86048 +_001533_hash kmp_init 2 41373 _001533_hash NULL
86049 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
86050 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
86051 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
86052 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
86053 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
86054 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
86055 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
86056 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
86057 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
86058 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
86059 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
86060 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
86061 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
86062 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
86063 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
86064 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
86065 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
86066 +_001552_hash mempool_create 1 29437 _001552_hash NULL
86067 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
86068 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
86069 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
86070 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
86071 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
86072 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
86073 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
86074 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
86075 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
86076 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
86077 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
86078 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
86079 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
86080 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
86081 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
86082 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
86083 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
86084 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
86085 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
86086 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
86087 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
86088 +_001575_hash new_skb 1 21148 _001575_hash NULL
86089 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
86090 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
86091 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
86092 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
86093 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
86094 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
86095 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
86096 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
86097 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
86098 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
86099 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
86100 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
86101 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
86102 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
86103 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
86104 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
86105 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
86106 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
86107 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
86108 +_001599_hash override_release 2 52032 _001599_hash NULL
86109 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
86110 +_001601_hash packet_snd 3 13634 _001601_hash NULL
86111 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
86112 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
86113 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
86114 +_001605_hash pg_read 3 17276 _001605_hash NULL
86115 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
86116 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
86117 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
86118 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
86119 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
86120 +_001611_hash printer_read 3 54851 _001611_hash NULL
86121 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
86122 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
86123 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
86124 +_001615_hash ptp_read 4 63251 _001615_hash NULL
86125 +_001616_hash pt_read 3 49136 _001616_hash NULL
86126 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
86127 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
86128 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
86129 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
86130 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
86131 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
86132 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
86133 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
86134 +_001625_hash read_flush 3 43851 _001625_hash NULL
86135 +_001626_hash read_profile 3 27859 _001626_hash NULL
86136 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
86137 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
86138 +_001629_hash refill_pool 2 19477 _001629_hash NULL
86139 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
86140 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
86141 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
86142 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
86143 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
86144 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
86145 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
86146 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
86147 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
86148 +_001640_hash rx 4 57944 _001640_hash NULL
86149 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
86150 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
86151 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
86152 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
86153 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
86154 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
86155 +_001647_hash scsi_register 2 49094 _001647_hash NULL
86156 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
86157 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
86158 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
86159 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
86160 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
86161 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
86162 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
86163 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
86164 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
86165 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
86166 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
86167 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
86168 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
86169 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
86170 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
86171 +_001663_hash send_command 4 10832 _001663_hash NULL
86172 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
86173 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
86174 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
86175 +_001667_hash set_arg 3 42824 _001667_hash NULL
86176 +_001668_hash sg_read 3 25799 _001668_hash NULL
86177 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
86178 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
86179 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
86180 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
86181 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
86182 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
86183 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
86184 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
86185 +_001680_hash skb_cow 2 26138 _001680_hash NULL
86186 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
86187 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
86188 +_001683_hash skb_padto 2 50759 _001683_hash NULL
86189 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
86190 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
86191 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
86192 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
86193 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
86194 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
86195 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
86196 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
86197 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
86198 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
86199 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
86200 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
86201 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
86202 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
86203 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
86204 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
86205 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
86206 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
86207 +_001704_hash store_msg 3 56417 _001704_hash NULL
86208 +_001705_hash str_to_user 2 11411 _001705_hash NULL
86209 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
86210 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
86211 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
86212 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
86213 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
86214 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
86215 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
86216 +_001713_hash syslog_print 2 307 _001713_hash NULL
86217 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
86218 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
86219 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
86220 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
86221 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
86222 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
86223 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
86224 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
86225 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
86226 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
86227 +_001727_hash team_options_register 3 20091 _001727_hash NULL
86228 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
86229 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
86230 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
86231 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
86232 +_001732_hash tipc_send 4 51238 _001732_hash NULL
86233 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
86234 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
86235 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
86236 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
86237 +_001737_hash tpm_read 3 50344 _001737_hash NULL
86238 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
86239 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
86240 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
86241 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
86242 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
86243 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
86244 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
86245 +_001746_hash uio_read 3 49300 _001746_hash NULL
86246 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
86247 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
86248 +_001749_hash unlink1 3 63059 _001749_hash NULL
86249 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
86250 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
86251 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
86252 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
86253 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
86254 +_001756_hash user_read 3 51881 _001756_hash NULL
86255 +_001757_hash vcs_read 3 8017 _001757_hash NULL
86256 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
86257 +_001759_hash venus_create 4 20555 _001759_hash NULL
86258 +_001760_hash venus_link 5 32165 _001760_hash NULL
86259 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
86260 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
86261 +_001763_hash venus_remove 4 59781 _001763_hash NULL
86262 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
86263 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
86264 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
86265 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
86266 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
86267 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
86268 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
86269 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
86270 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
86271 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
86272 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
86273 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
86274 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
86275 +_001780_hash wdm_read 3 6549 _001780_hash NULL
86276 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
86277 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
86278 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
86279 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
86280 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
86281 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
86282 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
86283 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
86284 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
86285 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
86286 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
86287 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
86288 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
86289 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
86290 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
86291 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
86292 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
86293 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
86294 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
86295 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
86296 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
86297 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
86298 +_001803_hash add_partition 2 55588 _001803_hash NULL
86299 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
86300 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
86301 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
86302 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
86303 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
86304 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
86305 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
86306 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
86307 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
86308 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
86309 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
86310 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
86311 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
86312 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
86313 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
86314 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
86315 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
86316 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
86317 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
86318 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
86319 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
86320 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
86321 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
86322 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
86323 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
86324 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
86325 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
86326 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
86327 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
86328 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
86329 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
86330 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
86331 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
86332 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
86333 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
86334 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
86335 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
86336 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
86337 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
86338 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
86339 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
86340 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
86341 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
86342 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
86343 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
86344 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
86345 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
86346 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
86347 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
86348 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
86349 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
86350 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
86351 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
86352 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
86353 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
86354 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
86355 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
86356 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
86357 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
86358 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
86359 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
86360 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
86361 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
86362 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
86363 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
86364 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
86365 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
86366 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
86367 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
86368 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
86369 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
86370 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
86371 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
86372 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
86373 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
86374 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
86375 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
86376 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
86377 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
86378 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
86379 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
86380 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
86381 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
86382 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
86383 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
86384 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
86385 +_001892_hash check_header 2 56930 _001892_hash NULL
86386 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
86387 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
86388 +_001895_hash console_store 4 36007 _001895_hash NULL
86389 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
86390 +_001897_hash create_subvol 4 30836 _001897_hash NULL
86391 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
86392 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
86393 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
86394 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
86395 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
86396 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
86397 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
86398 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
86399 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
86400 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
86401 +_001912_hash debug_output 3 18575 _001912_hash NULL
86402 +_001913_hash debug_read 3 19322 _001913_hash NULL
86403 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
86404 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
86405 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
86406 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
86407 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
86408 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
86409 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
86410 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
86411 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
86412 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
86413 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
86414 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
86415 +_001927_hash do_syslog 3 56807 _001927_hash NULL
86416 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
86417 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
86418 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
86419 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
86420 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
86421 +_001933_hash filter_read 3 61692 _001933_hash NULL
86422 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
86423 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
86424 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
86425 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
86426 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
86427 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
86428 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
86429 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
86430 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
86431 +_001943_hash handle_response 5 55951 _001943_hash NULL
86432 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
86433 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
86434 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
86435 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
86436 +_001948_hash help 4 14971 _001948_hash NULL
86437 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
86438 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
86439 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
86440 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
86441 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
86442 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
86443 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
86444 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
86445 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
86446 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
86447 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
86448 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
86449 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
86450 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
86451 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
86452 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
86453 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
86454 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
86455 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
86456 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
86457 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
86458 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
86459 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
86460 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
86461 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
86462 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
86463 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
86464 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
86465 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
86466 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
86467 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
86468 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
86469 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
86470 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
86471 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
86472 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
86473 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
86474 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
86475 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
86476 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
86477 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
86478 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
86479 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
86480 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
86481 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
86482 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
86483 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
86484 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
86485 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
86486 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
86487 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
86488 +_002001_hash ipw_write 3 59807 _002001_hash NULL
86489 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
86490 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
86491 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
86492 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
86493 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
86494 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
86495 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
86496 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
86497 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
86498 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
86499 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
86500 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
86501 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
86502 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
86503 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
86504 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
86505 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
86506 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
86507 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
86508 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
86509 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
86510 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
86511 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
86512 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
86513 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
86514 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
86515 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
86516 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
86517 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
86518 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
86519 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
86520 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
86521 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
86522 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
86523 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
86524 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
86525 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
86526 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
86527 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
86528 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
86529 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
86530 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
86531 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
86532 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
86533 +_002046_hash key_key_read 3 3241 _002046_hash NULL
86534 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
86535 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
86536 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
86537 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
86538 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
86539 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
86540 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
86541 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
86542 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
86543 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
86544 +_002058_hash l2down_create 4 21755 _002058_hash NULL
86545 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
86546 +_002060_hash l2up_create 3 6430 _002060_hash NULL
86547 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
86548 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
86549 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
86550 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
86551 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
86552 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
86553 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
86554 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
86555 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
86556 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
86557 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
86558 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
86559 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
86560 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
86561 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
86562 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
86563 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
86564 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
86565 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
86566 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
86567 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
86568 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
86569 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
86570 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
86571 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
86572 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
86573 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
86574 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
86575 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
86576 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
86577 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
86578 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
86579 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
86580 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
86581 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
86582 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
86583 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
86584 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
86585 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
86586 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
86587 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
86588 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
86589 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
86590 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
86591 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
86592 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
86593 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
86594 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
86595 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
86596 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
86597 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
86598 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
86599 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
86600 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
86601 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
86602 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
86603 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
86604 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
86605 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
86606 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
86607 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
86608 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
86609 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
86610 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
86611 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
86612 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
86613 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
86614 +_002136_hash osst_read 3 40237 _002136_hash NULL
86615 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
86616 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
86617 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
86618 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
86619 +_002143_hash page_readlink 3 23346 _002143_hash NULL
86620 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
86621 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
86622 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
86623 +_002148_hash pep_reply 5 50582 _002148_hash NULL
86624 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
86625 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
86626 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
86627 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
86628 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
86629 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
86630 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
86631 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
86632 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
86633 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
86634 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
86635 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
86636 +_002161_hash proc_read 3 43614 _002161_hash NULL
86637 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
86638 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
86639 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
86640 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
86641 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
86642 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
86643 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
86644 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
86645 +_002170_hash queues_read 3 24877 _002170_hash NULL
86646 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
86647 +_002172_hash rcname_read 3 25919 _002172_hash NULL
86648 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
86649 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
86650 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
86651 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
86652 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
86653 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
86654 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
86655 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
86656 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
86657 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
86658 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
86659 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
86660 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
86661 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
86662 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
86663 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
86664 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
86665 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
86666 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
86667 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
86668 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
86669 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
86670 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
86671 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
86672 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
86673 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
86674 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
86675 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
86676 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
86677 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
86678 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
86679 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
86680 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
86681 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
86682 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
86683 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
86684 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
86685 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
86686 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
86687 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
86688 +_002213_hash receive_packet 2 12367 _002213_hash NULL
86689 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
86690 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
86691 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
86692 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
86693 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
86694 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
86695 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
86696 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
86697 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
86698 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
86699 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
86700 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
86701 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
86702 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
86703 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
86704 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
86705 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
86706 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
86707 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
86708 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
86709 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
86710 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
86711 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
86712 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
86713 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
86714 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
86715 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
86716 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
86717 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
86718 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
86719 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
86720 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
86721 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
86722 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
86723 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
86724 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
86725 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
86726 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
86727 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
86728 +_002254_hash send_msg 4 37323 _002254_hash NULL
86729 +_002255_hash send_packet 4 52960 _002255_hash NULL
86730 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
86731 +_002257_hash sge_rx 3 50594 _002257_hash NULL
86732 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
86733 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
86734 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
86735 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
86736 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
86737 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
86738 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
86739 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
86740 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
86741 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
86742 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
86743 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
86744 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
86745 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
86746 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
86747 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
86748 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
86749 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
86750 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
86751 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
86752 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
86753 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
86754 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
86755 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
86756 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
86757 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
86758 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
86759 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
86760 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
86761 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
86762 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
86763 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
86764 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
86765 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
86766 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
86767 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
86768 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
86769 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
86770 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
86771 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
86772 +_002306_hash st_read 3 51251 _002306_hash NULL
86773 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
86774 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
86775 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
86776 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
86777 +_002311_hash sys_readv 3 50664 _002311_hash NULL
86778 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
86779 +_002313_hash sys_writev 3 28384 _002313_hash NULL
86780 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
86781 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
86782 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
86783 +_002317_hash teiup_create 3 43201 _002317_hash NULL
86784 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
86785 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
86786 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
86787 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
86788 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
86789 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
86790 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
86791 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
86792 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
86793 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
86794 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
86795 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
86796 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
86797 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
86798 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
86799 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
86800 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
86801 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
86802 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
86803 +_002341_hash um_idi_read 3 850 _002341_hash NULL
86804 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
86805 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
86806 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
86807 +_002345_hash use_pool 2 64607 _002345_hash NULL
86808 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
86809 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
86810 +_002348_hash vhci_read 3 47878 _002348_hash NULL
86811 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
86812 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
86813 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
86814 +_002353_hash waiters_read 3 40902 _002353_hash NULL
86815 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
86816 +_002355_hash write_pbl 4 59583 _002355_hash NULL
86817 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
86818 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
86819 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
86820 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
86821 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
86822 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
86823 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
86824 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
86825 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
86826 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
86827 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
86828 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
86829 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
86830 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
86831 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
86832 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
86833 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
86834 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
86835 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
86836 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
86837 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
86838 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
86839 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
86840 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
86841 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
86842 +_002382_hash bioset_create 1 5580 _002382_hash NULL
86843 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
86844 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
86845 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
86846 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
86847 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
86848 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
86849 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
86850 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
86851 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
86852 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
86853 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
86854 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
86855 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
86856 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
86857 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
86858 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
86859 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
86860 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
86861 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
86862 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
86863 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
86864 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
86865 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
86866 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
86867 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
86868 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
86869 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
86870 +_002411_hash depth_read 3 31112 _002411_hash NULL
86871 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
86872 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
86873 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
86874 +_002415_hash divas_write 3 63901 _002415_hash NULL
86875 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
86876 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
86877 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
86878 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
86879 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
86880 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
86881 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
86882 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
86883 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
86884 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
86885 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
86886 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
86887 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
86888 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
86889 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
86890 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
86891 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
86892 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
86893 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
86894 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
86895 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
86896 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
86897 +_002439_hash got_frame 2 16028 _002439_hash NULL
86898 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
86899 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
86900 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
86901 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
86902 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
86903 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
86904 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
86905 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
86906 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
86907 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
86908 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
86909 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
86910 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
86911 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
86912 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
86913 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
86914 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
86915 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
86916 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
86917 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
86918 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
86919 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
86920 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
86921 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
86922 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
86923 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
86924 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
86925 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
86926 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
86927 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
86928 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
86929 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
86930 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
86931 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
86932 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
86933 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
86934 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
86935 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
86936 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
86937 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
86938 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
86939 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
86940 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
86941 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
86942 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
86943 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
86944 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
86945 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
86946 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
86947 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
86948 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
86949 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
86950 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
86951 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
86952 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
86953 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
86954 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
86955 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
86956 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
86957 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
86958 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
86959 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
86960 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
86961 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
86962 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
86963 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
86964 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
86965 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
86966 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
86967 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
86968 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
86969 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
86970 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
86971 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
86972 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
86973 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
86974 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
86975 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
86976 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
86977 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
86978 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
86979 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
86980 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
86981 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
86982 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
86983 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
86984 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
86985 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
86986 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
86987 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
86988 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
86989 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
86990 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
86991 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
86992 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
86993 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
86994 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
86995 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
86996 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
86997 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
86998 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
86999 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
87000 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
87001 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
87002 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
87003 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
87004 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
87005 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
87006 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
87007 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
87008 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
87009 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
87010 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
87011 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
87012 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
87013 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
87014 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
87015 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
87016 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
87017 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
87018 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
87019 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
87020 +_002570_hash map_addr 6 4666 _002570_hash NULL
87021 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
87022 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
87023 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
87024 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
87025 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
87026 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
87027 +_002577_hash named_distribute 4 48544 _002577_hash NULL
87028 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
87029 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
87030 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
87031 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
87032 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
87033 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
87034 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
87035 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
87036 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
87037 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
87038 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
87039 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
87040 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
87041 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
87042 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
87043 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
87044 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
87045 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
87046 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
87047 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
87048 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
87049 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
87050 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
87051 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
87052 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
87053 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
87054 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
87055 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
87056 +_002612_hash power_read 3 15939 _002612_hash NULL
87057 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
87058 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
87059 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
87060 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
87061 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
87062 +_002618_hash prison_create 1 43623 _002618_hash NULL
87063 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
87064 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
87065 +_002621_hash _queue_data 4 54983 _002621_hash NULL
87066 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
87067 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
87068 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
87069 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
87070 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
87071 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
87072 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
87073 +_002629_hash read_dma 3 55086 _002629_hash NULL
87074 +_002630_hash read_fifo 3 826 _002630_hash NULL
87075 +_002631_hash read_tree_block 3 841 _002631_hash NULL
87076 +_002632_hash receive_copy 3 12216 _002632_hash NULL
87077 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
87078 +_002635_hash recv_msg 4 48709 _002635_hash NULL
87079 +_002636_hash recv_stream 4 30138 _002636_hash NULL
87080 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
87081 +_002638_hash request_key_async 4 6990 _002638_hash NULL
87082 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
87083 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
87084 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
87085 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
87086 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
87087 +_002644_hash rx_data 4 60442 _002644_hash NULL
87088 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
87089 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
87090 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
87091 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
87092 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
87093 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
87094 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
87095 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
87096 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
87097 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
87098 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
87099 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
87100 +_002658_hash send_stream 4 3397 _002658_hash NULL
87101 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
87102 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
87103 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
87104 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
87105 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
87106 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
87107 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
87108 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
87109 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
87110 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
87111 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
87112 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
87113 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
87114 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
87115 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
87116 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
87117 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
87118 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
87119 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
87120 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
87121 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
87122 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
87123 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
87124 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
87125 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
87126 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
87127 +_002690_hash timeout_read 3 47915 _002690_hash NULL
87128 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
87129 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
87130 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
87131 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
87132 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
87133 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
87134 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
87135 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
87136 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
87137 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
87138 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
87139 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
87140 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
87141 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
87142 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
87143 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
87144 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
87145 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
87146 +_002711_hash user_power_read 3 39414 _002711_hash NULL
87147 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
87148 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
87149 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
87150 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
87151 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
87152 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
87153 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
87154 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
87155 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
87156 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
87157 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
87158 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
87159 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
87160 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
87161 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
87162 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
87163 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
87164 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
87165 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
87166 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
87167 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
87168 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
87169 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
87170 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
87171 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
87172 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
87173 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
87174 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
87175 +_002740_hash do_trimming 3 26952 _002740_hash NULL
87176 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
87177 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
87178 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
87179 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
87180 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
87181 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
87182 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
87183 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
87184 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
87185 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
87186 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
87187 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
87188 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
87189 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
87190 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
87191 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
87192 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
87193 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
87194 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
87195 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
87196 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
87197 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
87198 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
87199 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
87200 +_002770_hash push_rx 3 28939 _002770_hash NULL
87201 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
87202 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
87203 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
87204 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
87205 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
87206 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
87207 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
87208 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
87209 +_002781_hash spi_execute 5 28736 _002781_hash NULL
87210 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
87211 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
87212 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
87213 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
87214 +_002786_hash ti_recv 4 22027 _002786_hash NULL
87215 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
87216 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
87217 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
87218 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
87219 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
87220 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
87221 +_002794_hash write_leb 5 36957 _002794_hash NULL
87222 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
87223 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
87224 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
87225 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
87226 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
87227 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
87228 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
87229 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
87230 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
87231 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
87232 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
87233 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
87234 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
87235 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
87236 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
87237 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
87238 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
87239 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
87240 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
87241 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
87242 +_002820_hash lock_loop 1 61681 _002820_hash NULL
87243 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
87244 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
87245 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
87246 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
87247 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
87248 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
87249 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
87250 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
87251 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
87252 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
87253 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
87254 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
87255 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
87256 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
87257 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
87258 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
87259 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
87260 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
87261 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
87262 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
87263 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
87264 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
87265 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
87266 +_002846_hash recover_head 3 17904 _002846_hash NULL
87267 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
87268 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
87269 +_002849_hash tcp_push 3 10680 _002849_hash NULL
87270 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
87271 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
87272 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
87273 +_002853_hash write_head 4 30481 _002853_hash NULL
87274 +_002854_hash write_node 4 33121 _002854_hash NULL
87275 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
87276 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
87277 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
87278 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
87279 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
87280 +_002861_hash amthi_read 4 45831 _002861_hash NULL
87281 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
87282 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
87283 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
87284 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
87285 +_002866_hash card_send_command 3 40757 _002866_hash NULL
87286 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
87287 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
87288 +_002869_hash create_log 2 8225 _002869_hash NULL
87289 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
87290 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
87291 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
87292 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
87293 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
87294 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
87295 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
87296 +_002877_hash fir16_create 3 5574 _002877_hash NULL
87297 +_002878_hash get_nodes 3 39012 _002878_hash NULL
87298 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
87299 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
87300 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
87301 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
87302 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
87303 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
87304 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
87305 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
87306 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
87307 +_002889_hash keymap_store 4 45406 _002889_hash NULL
87308 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
87309 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
87310 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
87311 +_002893_hash _malloc 1 54077 _002893_hash NULL
87312 +_002894_hash mei_read 3 6507 _002894_hash NULL
87313 +_002895_hash mei_write 3 4005 _002895_hash NULL
87314 +_002896_hash msg_set 3 51725 _002896_hash NULL
87315 +_002897_hash newpart 6 47485 _002897_hash NULL
87316 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
87317 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
87318 +_002900_hash packet_came 3 18072 _002900_hash NULL
87319 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
87320 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
87321 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
87322 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
87323 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
87324 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
87325 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
87326 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
87327 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
87328 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
87329 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
87330 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
87331 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
87332 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
87333 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
87334 +_002923_hash sep_read 3 17161 _002923_hash NULL
87335 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
87336 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
87337 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
87338 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
87339 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
87340 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
87341 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
87342 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
87343 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
87344 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
87345 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
87346 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
87347 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
87348 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
87349 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
87350 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
87351 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
87352 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
87353 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
87354 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
87355 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
87356 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
87357 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
87358 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
87359 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
87360 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
87361 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
87362 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
87363 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
87364 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
87365 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
87366 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
87367 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
87368 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
87369 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
87370 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
87371 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
87372 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
87373 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
87374 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
87375 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
87376 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
87377 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
87378 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
87379 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
87380 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
87381 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
87382 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
87383 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
87384 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
87385 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
87386 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
87387 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
87388 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
87389 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
87390 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
87391 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
87392 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
87393 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
87394 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
87395 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
87396 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
87397 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
87398 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
87399 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
87400 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
87401 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
87402 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
87403 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
87404 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
87405 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
87406 +_003003_hash flash_read 3 57843 _003003_hash NULL
87407 +_003004_hash flash_write 3 62354 _003004_hash NULL
87408 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
87409 +_003006_hash gather_array 3 56641 _003006_hash NULL
87410 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
87411 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
87412 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
87413 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
87414 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
87415 +_003013_hash init_cdev 1 8274 _003013_hash NULL
87416 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
87417 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
87418 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
87419 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
87420 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
87421 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
87422 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
87423 +_003021_hash options_write 3 47243 _003021_hash NULL
87424 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
87425 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
87426 +_003024_hash portnames_read 3 41958 _003024_hash NULL
87427 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
87428 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
87429 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
87430 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
87431 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
87432 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
87433 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
87434 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
87435 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
87436 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
87437 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
87438 +_003036_hash queue_reply 3 22416 _003036_hash NULL
87439 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
87440 +_003038_hash split 2 11691 _003038_hash NULL
87441 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
87442 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
87443 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
87444 +_003042_hash tunables_read 3 36385 _003042_hash NULL
87445 +_003043_hash tunables_write 3 59563 _003043_hash NULL
87446 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
87447 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
87448 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
87449 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
87450 +_003049_hash xsd_read 3 15653 _003049_hash NULL
87451 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
87452 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
87453 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
87454 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
87455 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
87456 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
87457 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
87458 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
87459 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
87460 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
87461 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
87462 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
87463 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
87464 +_003064_hash compat_readv 3 30273 _003064_hash NULL
87465 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
87466 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
87467 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
87468 +_003070_hash compat_writev 3 60063 _003070_hash NULL
87469 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
87470 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
87471 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
87472 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
87473 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
87474 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
87475 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
87476 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
87477 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
87478 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
87479 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
87480 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
87481 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
87482 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
87483 +_003085_hash agp_remap 2 30665 _003085_hash NULL
87484 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
87485 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
87486 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
87487 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
87488 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
87489 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
87490 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
87491 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
87492 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
87493 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
87494 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
87495 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
87496 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
87497 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
87498 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
87499 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
87500 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
87501 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
87502 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
87503 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
87504 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
87505 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
87506 +_003108_hash conf_read 3 55786 _003108_hash NULL
87507 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
87508 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
87509 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
87510 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
87511 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
87512 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
87513 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
87514 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
87515 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
87516 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
87517 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
87518 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
87519 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
87520 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
87521 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
87522 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
87523 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
87524 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
87525 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
87526 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
87527 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
87528 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
87529 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
87530 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
87531 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
87532 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
87533 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
87534 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
87535 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
87536 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
87537 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
87538 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
87539 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
87540 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
87541 +_003146_hash dvb_play 3 50814 _003146_hash NULL
87542 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
87543 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
87544 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
87545 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
87546 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
87547 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
87548 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
87549 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
87550 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
87551 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
87552 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
87553 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
87554 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
87555 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
87556 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
87557 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
87558 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
87559 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
87560 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
87561 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
87562 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
87563 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
87564 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
87565 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
87566 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
87567 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
87568 +_003175_hash get_info 3 55681 _003175_hash NULL
87569 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
87570 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
87571 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
87572 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
87573 +_003180_hash hsc_write 3 55875 _003180_hash NULL
87574 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
87575 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
87576 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
87577 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
87578 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
87579 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
87580 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
87581 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
87582 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
87583 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
87584 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
87585 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
87586 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
87587 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
87588 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
87589 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
87590 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
87591 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
87592 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
87593 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
87594 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
87595 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
87596 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
87597 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
87598 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
87599 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
87600 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
87601 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
87602 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
87603 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
87604 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
87605 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
87606 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
87607 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
87608 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
87609 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
87610 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
87611 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
87612 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
87613 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
87614 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
87615 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
87616 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
87617 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
87618 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
87619 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
87620 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
87621 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
87622 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
87623 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
87624 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
87625 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
87626 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
87627 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
87628 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
87629 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
87630 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
87631 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
87632 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
87633 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
87634 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
87635 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
87636 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
87637 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
87638 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
87639 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
87640 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
87641 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
87642 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
87643 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
87644 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
87645 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
87646 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
87647 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
87648 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
87649 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
87650 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
87651 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
87652 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
87653 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
87654 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
87655 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
87656 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
87657 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
87658 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
87659 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
87660 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
87661 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
87662 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
87663 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
87664 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
87665 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
87666 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
87667 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
87668 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
87669 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
87670 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
87671 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
87672 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
87673 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
87674 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
87675 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
87676 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
87677 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
87678 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
87679 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
87680 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
87681 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
87682 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
87683 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
87684 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
87685 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
87686 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
87687 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
87688 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
87689 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
87690 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
87691 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
87692 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
87693 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
87694 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
87695 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
87696 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
87697 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
87698 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
87699 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
87700 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
87701 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
87702 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
87703 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
87704 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
87705 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
87706 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
87707 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
87708 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
87709 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
87710 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
87711 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
87712 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
87713 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
87714 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
87715 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
87716 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
87717 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
87718 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
87719 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
87720 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
87721 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
87722 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
87723 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
87724 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
87725 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
87726 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
87727 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
87728 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
87729 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
87730 +_003340_hash alloc_private 2 22399 _003340_hash NULL
87731 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
87732 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
87733 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
87734 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
87735 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
87736 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
87737 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
87738 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
87739 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
87740 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
87741 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
87742 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
87743 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
87744 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
87745 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
87746 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
87747 +_003359_hash comedi_read 3 13199 _003359_hash NULL
87748 +_003360_hash comedi_write 3 47926 _003360_hash NULL
87749 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
87750 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
87751 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
87752 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
87753 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
87754 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
87755 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
87756 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
87757 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
87758 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
87759 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
87760 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
87761 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
87762 +_003377_hash dev_read 3 56369 _003377_hash NULL
87763 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
87764 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
87765 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
87766 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
87767 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
87768 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
87769 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
87770 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
87771 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
87772 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
87773 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
87774 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
87775 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
87776 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
87777 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
87778 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
87779 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
87780 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
87781 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
87782 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
87783 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
87784 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
87785 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
87786 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
87787 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
87788 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
87789 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
87790 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
87791 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
87792 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
87793 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
87794 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
87795 +_003412_hash fb_read 3 33506 _003412_hash NULL
87796 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
87797 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
87798 +_003415_hash fb_write 3 46924 _003415_hash NULL
87799 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
87800 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
87801 +_003418_hash fops_read 3 40672 _003418_hash NULL
87802 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
87803 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
87804 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
87805 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
87806 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
87807 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
87808 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
87809 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
87810 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
87811 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
87812 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
87813 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
87814 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
87815 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
87816 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
87817 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
87818 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
87819 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
87820 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
87821 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
87822 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
87823 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
87824 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
87825 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
87826 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
87827 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
87828 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
87829 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
87830 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
87831 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
87832 +_003451_hash lirc_write 3 20604 _003451_hash NULL
87833 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
87834 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
87835 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
87836 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
87837 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
87838 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
87839 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
87840 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
87841 +_003461_hash mmio_read 4 40348 _003461_hash NULL
87842 +_003462_hash netlink_send 5 38434 _003462_hash NULL
87843 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
87844 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
87845 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
87846 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
87847 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
87848 +_003468_hash odev_update 2 50169 _003468_hash NULL
87849 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
87850 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
87851 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
87852 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
87853 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
87854 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
87855 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
87856 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
87857 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
87858 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
87859 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
87860 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
87861 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
87862 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
87863 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
87864 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
87865 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
87866 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
87867 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
87868 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
87869 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
87870 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
87871 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
87872 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
87873 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
87874 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
87875 +_003497_hash play_iframe 3 8219 _003497_hash NULL
87876 +_003498_hash probes_write 3 29711 _003498_hash NULL
87877 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
87878 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
87879 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
87880 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
87881 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
87882 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
87883 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
87884 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
87885 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
87886 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
87887 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
87888 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
87889 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
87890 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
87891 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
87892 +_003514_hash qc_capture 3 19298 _003514_hash NULL
87893 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
87894 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
87895 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
87896 +_003518_hash Realloc 2 34961 _003518_hash NULL
87897 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
87898 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
87899 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
87900 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
87901 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
87902 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
87903 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
87904 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
87905 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
87906 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
87907 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
87908 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
87909 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
87910 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
87911 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
87912 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
87913 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
87914 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
87915 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
87916 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
87917 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
87918 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
87919 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
87920 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
87921 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
87922 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
87923 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
87924 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
87925 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
87926 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
87927 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
87928 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
87929 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
87930 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
87931 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
87932 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
87933 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
87934 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
87935 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
87936 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
87937 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
87938 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
87939 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
87940 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
87941 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
87942 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
87943 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
87944 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
87945 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
87946 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
87947 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
87948 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
87949 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
87950 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
87951 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
87952 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
87953 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
87954 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
87955 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
87956 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
87957 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
87958 +_003584_hash ts_read 3 44687 _003584_hash NULL
87959 +_003585_hash ts_write 3 64336 _003585_hash NULL
87960 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
87961 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
87962 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
87963 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
87964 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
87965 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
87966 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
87967 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
87968 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
87969 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
87970 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
87971 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
87972 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
87973 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
87974 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
87975 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
87976 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
87977 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
87978 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
87979 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
87980 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
87981 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
87982 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
87983 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
87984 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
87985 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
87986 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
87987 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
87988 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
87989 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
87990 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
87991 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
87992 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
87993 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
87994 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
87995 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
87996 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
87997 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
87998 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
87999 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
88000 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
88001 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
88002 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
88003 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
88004 +_003630_hash unifi_read 3 14899 _003630_hash NULL
88005 +_003631_hash unifi_write 3 65012 _003631_hash NULL
88006 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
88007 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
88008 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
88009 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
88010 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
88011 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
88012 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
88013 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
88014 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
88015 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
88016 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
88017 +_003645_hash vfd_write 3 14717 _003645_hash NULL
88018 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
88019 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
88020 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
88021 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
88022 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
88023 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
88024 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
88025 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
88026 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
88027 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
88028 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
88029 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
88030 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
88031 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
88032 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
88033 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
88034 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
88035 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
88036 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
88037 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
88038 +_003667_hash zoran_write 3 22404 _003667_hash NULL
88039 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
88040 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
88041 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
88042 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
88043 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
88044 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
88045 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
88046 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
88047 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
88048 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
88049 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
88050 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
88051 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
88052 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
88053 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
88054 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
88055 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
88056 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
88057 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
88058 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
88059 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
88060 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
88061 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
88062 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
88063 +_003696_hash qcam_read 3 13977 _003696_hash NULL
88064 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
88065 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
88066 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
88067 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
88068 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
88069 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
88070 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
88071 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
88072 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
88073 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
88074 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
88075 +_003710_hash update_macheader 7 1775 _003710_hash NULL
88076 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
88077 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
88078 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
88079 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
88080 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
88081 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
88082 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
88083 +_003718_hash vb2_read 3 42703 _003718_hash NULL
88084 +_003719_hash vb2_write 3 31948 _003719_hash NULL
88085 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
88086 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
88087 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
88088 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
88089 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
88090 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
88091 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
88092 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
88093 +_003729_hash vmap 2 15025 _003729_hash NULL
88094 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
88095 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
88096 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
88097 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
88098 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
88099 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
88100 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
88101 +_003740_hash bttv_read 3 11432 _003740_hash NULL
88102 +_003741_hash cx18_read 3 23699 _003741_hash NULL
88103 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
88104 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
88105 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
88106 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
88107 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
88108 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
88109 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
88110 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
88111 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
88112 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
88113 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
88114 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
88115 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
88116 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
88117 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
88118 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
88119 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
88120 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
88121 +_003766_hash video_read 3 28148 _003766_hash NULL
88122 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
88123 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
88124 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
88125 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
88126 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
88127 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
88128 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
88129 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
88130 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
88131 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
88132 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
88133 +_003783_hash do_test 1 15766 _003783_hash NULL
88134 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
88135 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
88136 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
88137 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
88138 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
88139 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
88140 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
88141 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
88142 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
88143 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
88144 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
88145 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
88146 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
88147 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
88148 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
88149 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
88150 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
88151 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
88152 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
88153 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
88154 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
88155 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
88156 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
88157 +_003814_hash vbi_read 3 63673 _003814_hash NULL
88158 +_003815_hash viacam_read 3 54526 _003815_hash NULL
88159 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
88160 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
88161 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
88162 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
88163 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
88164 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
88165 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
88166 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
88167 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
88168 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
88169 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
88170 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
88171 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
88172 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
88173 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
88174 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
88175 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
88176 +_003839_hash doc_probe 1 23285 _003839_hash NULL
88177 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
88178 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
88179 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
88180 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
88181 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
88182 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
88183 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
88184 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
88185 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
88186 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
88187 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
88188 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
88189 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
88190 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
88191 +_003858_hash register_device 2-3 60015 _003858_hash NULL
88192 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
88193 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
88194 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
88195 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
88196 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
88197 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
88198 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
88199 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
88200 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
88201 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
88202 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
88203 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
88204 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
88205 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
88206 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
88207 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
88208 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
88209 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
88210 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
88211 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
88212 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
88213 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
88214 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
88215 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
88216 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
88217 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
88218 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
88219 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
88220 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
88221 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
88222 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
88223 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
88224 +_003897_hash acl_alloc 1 35979 _003897_hash NULL
88225 +_003898_hash acl_alloc_stack_init 1 60630 _003898_hash NULL
88226 +_003899_hash create_table 2 16213 _003899_hash NULL
88227 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
88228 new file mode 100644
88229 index 0000000..1aa0dce
88230 --- /dev/null
88231 +++ b/tools/gcc/size_overflow_plugin.c
88232 @@ -0,0 +1,1865 @@
88233 +/*
88234 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
88235 + * Licensed under the GPL v2, or (at your option) v3
88236 + *
88237 + * Homepage:
88238 + * http://www.grsecurity.net/~ephox/overflow_plugin/
88239 + *
88240 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
88241 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
88242 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
88243 + *
88244 + * Usage:
88245 + * $ 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
88246 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
88247 + */
88248 +
88249 +#include "gcc-plugin.h"
88250 +#include "config.h"
88251 +#include "system.h"
88252 +#include "coretypes.h"
88253 +#include "tree.h"
88254 +#include "tree-pass.h"
88255 +#include "intl.h"
88256 +#include "plugin-version.h"
88257 +#include "tm.h"
88258 +#include "toplev.h"
88259 +#include "function.h"
88260 +#include "tree-flow.h"
88261 +#include "plugin.h"
88262 +#include "gimple.h"
88263 +#include "c-common.h"
88264 +#include "diagnostic.h"
88265 +#include "cfgloop.h"
88266 +
88267 +#if BUILDING_GCC_VERSION >= 4007
88268 +#include "c-tree.h"
88269 +#else
88270 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
88271 +#endif
88272 +
88273 +struct size_overflow_hash {
88274 + const struct size_overflow_hash * const next;
88275 + const char * const name;
88276 + const unsigned int param;
88277 +};
88278 +
88279 +#include "size_overflow_hash.h"
88280 +
88281 +enum marked {
88282 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
88283 +};
88284 +
88285 +#define __unused __attribute__((__unused__))
88286 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
88287 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
88288 +#define BEFORE_STMT true
88289 +#define AFTER_STMT false
88290 +#define CREATE_NEW_VAR NULL_TREE
88291 +#define CODES_LIMIT 32
88292 +#define MAX_PARAM 32
88293 +#define MY_STMT GF_PLF_1
88294 +#define NO_CAST_CHECK GF_PLF_2
88295 +
88296 +#if BUILDING_GCC_VERSION == 4005
88297 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
88298 +#endif
88299 +
88300 +int plugin_is_GPL_compatible;
88301 +void debug_gimple_stmt(gimple gs);
88302 +
88303 +static tree expand(struct pointer_set_t *visited, tree lhs);
88304 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
88305 +static tree report_size_overflow_decl;
88306 +static const_tree const_char_ptr_type_node;
88307 +static unsigned int handle_function(void);
88308 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
88309 +static tree get_size_overflow_type(gimple stmt, const_tree node);
88310 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
88311 +
88312 +static struct plugin_info size_overflow_plugin_info = {
88313 + .version = "20121113beta",
88314 + .help = "no-size-overflow\tturn off size overflow checking\n",
88315 +};
88316 +
88317 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
88318 +{
88319 + unsigned int arg_count;
88320 + enum tree_code code = TREE_CODE(*node);
88321 +
88322 + switch (code) {
88323 + case FUNCTION_DECL:
88324 + arg_count = type_num_arguments(TREE_TYPE(*node));
88325 + break;
88326 + case FUNCTION_TYPE:
88327 + case METHOD_TYPE:
88328 + arg_count = type_num_arguments(*node);
88329 + break;
88330 + default:
88331 + *no_add_attrs = true;
88332 + error("%s: %qE attribute only applies to functions", __func__, name);
88333 + return NULL_TREE;
88334 + }
88335 +
88336 + for (; args; args = TREE_CHAIN(args)) {
88337 + tree position = TREE_VALUE(args);
88338 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
88339 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
88340 + *no_add_attrs = true;
88341 + }
88342 + }
88343 + return NULL_TREE;
88344 +}
88345 +
88346 +static const char* get_asm_name(tree node)
88347 +{
88348 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
88349 +}
88350 +
88351 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
88352 +{
88353 + unsigned int arg_count, arg_num;
88354 + enum tree_code code = TREE_CODE(*node);
88355 +
88356 + switch (code) {
88357 + case FUNCTION_DECL:
88358 + arg_count = type_num_arguments(TREE_TYPE(*node));
88359 + break;
88360 + case FUNCTION_TYPE:
88361 + case METHOD_TYPE:
88362 + arg_count = type_num_arguments(*node);
88363 + break;
88364 + case FIELD_DECL:
88365 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
88366 + if (arg_num != 0) {
88367 + *no_add_attrs = true;
88368 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
88369 + }
88370 + return NULL_TREE;
88371 + default:
88372 + *no_add_attrs = true;
88373 + error("%qE attribute only applies to functions", name);
88374 + return NULL_TREE;
88375 + }
88376 +
88377 + for (; args; args = TREE_CHAIN(args)) {
88378 + tree position = TREE_VALUE(args);
88379 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
88380 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
88381 + *no_add_attrs = true;
88382 + }
88383 + }
88384 + return NULL_TREE;
88385 +}
88386 +
88387 +static struct attribute_spec size_overflow_attr = {
88388 + .name = "size_overflow",
88389 + .min_length = 1,
88390 + .max_length = -1,
88391 + .decl_required = true,
88392 + .type_required = false,
88393 + .function_type_required = false,
88394 + .handler = handle_size_overflow_attribute,
88395 +#if BUILDING_GCC_VERSION >= 4007
88396 + .affects_type_identity = false
88397 +#endif
88398 +};
88399 +
88400 +static struct attribute_spec intentional_overflow_attr = {
88401 + .name = "intentional_overflow",
88402 + .min_length = 1,
88403 + .max_length = -1,
88404 + .decl_required = true,
88405 + .type_required = false,
88406 + .function_type_required = false,
88407 + .handler = handle_intentional_overflow_attribute,
88408 +#if BUILDING_GCC_VERSION >= 4007
88409 + .affects_type_identity = false
88410 +#endif
88411 +};
88412 +
88413 +static void register_attributes(void __unused *event_data, void __unused *data)
88414 +{
88415 + register_attribute(&size_overflow_attr);
88416 + register_attribute(&intentional_overflow_attr);
88417 +}
88418 +
88419 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
88420 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
88421 +{
88422 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
88423 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
88424 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
88425 +
88426 + unsigned int m = 0x57559429;
88427 + unsigned int n = 0x5052acdb;
88428 + const unsigned int *key4 = (const unsigned int *)key;
88429 + unsigned int h = len;
88430 + unsigned int k = len + seed + n;
88431 + unsigned long long p;
88432 +
88433 + while (len >= 8) {
88434 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
88435 + len -= 8;
88436 + }
88437 + if (len >= 4) {
88438 + cwmixb(key4[0]) key4 += 1;
88439 + len -= 4;
88440 + }
88441 + if (len)
88442 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
88443 + cwmixb(h ^ (k + n));
88444 + return k ^ h;
88445 +
88446 +#undef cwfold
88447 +#undef cwmixa
88448 +#undef cwmixb
88449 +}
88450 +
88451 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
88452 +{
88453 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
88454 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
88455 + return fn ^ codes;
88456 +}
88457 +
88458 +static inline tree get_original_function_decl(tree fndecl)
88459 +{
88460 + if (DECL_ABSTRACT_ORIGIN(fndecl))
88461 + return DECL_ABSTRACT_ORIGIN(fndecl);
88462 + return fndecl;
88463 +}
88464 +
88465 +static inline gimple get_def_stmt(const_tree node)
88466 +{
88467 + gcc_assert(node != NULL_TREE);
88468 + gcc_assert(TREE_CODE(node) == SSA_NAME);
88469 + return SSA_NAME_DEF_STMT(node);
88470 +}
88471 +
88472 +static unsigned char get_tree_code(const_tree type)
88473 +{
88474 + switch (TREE_CODE(type)) {
88475 + case ARRAY_TYPE:
88476 + return 0;
88477 + case BOOLEAN_TYPE:
88478 + return 1;
88479 + case ENUMERAL_TYPE:
88480 + return 2;
88481 + case FUNCTION_TYPE:
88482 + return 3;
88483 + case INTEGER_TYPE:
88484 + return 4;
88485 + case POINTER_TYPE:
88486 + return 5;
88487 + case RECORD_TYPE:
88488 + return 6;
88489 + case UNION_TYPE:
88490 + return 7;
88491 + case VOID_TYPE:
88492 + return 8;
88493 + case REAL_TYPE:
88494 + return 9;
88495 + case VECTOR_TYPE:
88496 + return 10;
88497 + case REFERENCE_TYPE:
88498 + return 11;
88499 + case OFFSET_TYPE:
88500 + return 12;
88501 + case COMPLEX_TYPE:
88502 + return 13;
88503 + default:
88504 + debug_tree((tree)type);
88505 + gcc_unreachable();
88506 + }
88507 +}
88508 +
88509 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
88510 +{
88511 + gcc_assert(type != NULL_TREE);
88512 +
88513 + while (type && len < CODES_LIMIT) {
88514 + tree_codes[len] = get_tree_code(type);
88515 + len++;
88516 + type = TREE_TYPE(type);
88517 + }
88518 + return len;
88519 +}
88520 +
88521 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
88522 +{
88523 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
88524 + enum tree_code code = TREE_CODE(type);
88525 + size_t len = 0;
88526 +
88527 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
88528 +
88529 + arg = TYPE_ARG_TYPES(type);
88530 + // skip builtins __builtin_constant_p
88531 + if (!arg && DECL_BUILT_IN(fndecl))
88532 + return 0;
88533 +
88534 + if (TREE_CODE_CLASS(code) == tcc_type)
88535 + result = type;
88536 + else
88537 + result = DECL_RESULT(fndecl);
88538 +
88539 + gcc_assert(result != NULL_TREE);
88540 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
88541 +
88542 + if (arg == NULL_TREE) {
88543 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
88544 + arg_field = DECL_ARGUMENT_FLD(fndecl);
88545 + if (arg_field == NULL_TREE)
88546 + return 0;
88547 + arg = TREE_TYPE(arg_field);
88548 + len = add_type_codes(arg, tree_codes, len);
88549 + gcc_assert(len != 0);
88550 + return len;
88551 + }
88552 +
88553 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
88554 + while (arg && len < CODES_LIMIT) {
88555 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
88556 + arg = TREE_CHAIN(arg);
88557 + }
88558 +
88559 + gcc_assert(len != 0);
88560 + return len;
88561 +}
88562 +
88563 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
88564 +{
88565 + unsigned int hash;
88566 + const struct size_overflow_hash *entry;
88567 + unsigned char tree_codes[CODES_LIMIT];
88568 + size_t len;
88569 + const char *func_name = get_asm_name(fndecl);
88570 +
88571 + len = get_function_decl(fndecl, tree_codes);
88572 + if (len == 0)
88573 + return NULL;
88574 +
88575 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
88576 +
88577 + entry = size_overflow_hash[hash];
88578 + while (entry) {
88579 + if (!strcmp(entry->name, func_name))
88580 + return entry;
88581 + entry = entry->next;
88582 + }
88583 +
88584 + return NULL;
88585 +}
88586 +
88587 +static void check_arg_type(const_tree arg)
88588 +{
88589 + const_tree type = TREE_TYPE(arg);
88590 + enum tree_code code = TREE_CODE(type);
88591 +
88592 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
88593 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
88594 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
88595 +}
88596 +
88597 +static int find_arg_number(const_tree arg, tree func)
88598 +{
88599 + tree var;
88600 + unsigned int argnum = 1;
88601 +
88602 + if (TREE_CODE(arg) == SSA_NAME)
88603 + arg = SSA_NAME_VAR(arg);
88604 +
88605 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
88606 + if (strcmp(NAME(arg), NAME(var))) {
88607 + argnum++;
88608 + continue;
88609 + }
88610 + check_arg_type(var);
88611 + return argnum;
88612 + }
88613 + gcc_unreachable();
88614 +}
88615 +
88616 +static tree create_new_var(tree type)
88617 +{
88618 + tree new_var = create_tmp_var(type, "cicus");
88619 +
88620 + add_referenced_var(new_var);
88621 + mark_sym_for_renaming(new_var);
88622 + return new_var;
88623 +}
88624 +
88625 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
88626 +{
88627 + gimple assign;
88628 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88629 + tree type = TREE_TYPE(rhs1);
88630 + tree lhs = create_new_var(type);
88631 +
88632 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
88633 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
88634 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88635 +
88636 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
88637 + update_stmt(assign);
88638 + gimple_set_plf(assign, MY_STMT, true);
88639 + return assign;
88640 +}
88641 +
88642 +static bool is_bool(const_tree node)
88643 +{
88644 + const_tree type;
88645 +
88646 + if (node == NULL_TREE)
88647 + return false;
88648 +
88649 + type = TREE_TYPE(node);
88650 + if (!INTEGRAL_TYPE_P(type))
88651 + return false;
88652 + if (TREE_CODE(type) == BOOLEAN_TYPE)
88653 + return true;
88654 + if (TYPE_PRECISION(type) == 1)
88655 + return true;
88656 + return false;
88657 +}
88658 +
88659 +static tree cast_a_tree(tree type, tree var)
88660 +{
88661 + gcc_assert(type != NULL_TREE);
88662 + gcc_assert(var != NULL_TREE);
88663 + gcc_assert(fold_convertible_p(type, var));
88664 +
88665 + return fold_convert(type, var);
88666 +}
88667 +
88668 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
88669 +{
88670 + gimple assign;
88671 +
88672 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
88673 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
88674 + gcc_unreachable();
88675 +
88676 + if (lhs == CREATE_NEW_VAR)
88677 + lhs = create_new_var(dst_type);
88678 +
88679 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
88680 +
88681 + if (!gsi_end_p(*gsi)) {
88682 + location_t loc = gimple_location(gsi_stmt(*gsi));
88683 + gimple_set_location(assign, loc);
88684 + }
88685 +
88686 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88687 +
88688 + if (before)
88689 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
88690 + else
88691 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
88692 + update_stmt(assign);
88693 + gimple_set_plf(assign, MY_STMT, true);
88694 +
88695 + return assign;
88696 +}
88697 +
88698 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
88699 +{
88700 + gimple assign;
88701 + gimple_stmt_iterator gsi;
88702 +
88703 + if (rhs == NULL_TREE)
88704 + return NULL_TREE;
88705 +
88706 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
88707 + return rhs;
88708 +
88709 + gsi = gsi_for_stmt(stmt);
88710 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
88711 + gimple_set_plf(assign, MY_STMT, true);
88712 + return gimple_get_lhs(assign);
88713 +}
88714 +
88715 +static tree cast_to_TI_type(gimple stmt, tree node)
88716 +{
88717 + gimple_stmt_iterator gsi;
88718 + gimple cast_stmt;
88719 + tree type = TREE_TYPE(node);
88720 +
88721 + if (types_compatible_p(type, intTI_type_node))
88722 + return node;
88723 +
88724 + gsi = gsi_for_stmt(stmt);
88725 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88726 + gimple_set_plf(cast_stmt, MY_STMT, true);
88727 + return gimple_get_lhs(cast_stmt);
88728 +}
88729 +
88730 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
88731 +{
88732 + tree lhs;
88733 + gimple_stmt_iterator gsi;
88734 +
88735 + if (rhs1 == NULL_TREE) {
88736 + debug_gimple_stmt(oldstmt);
88737 + error("%s: rhs1 is NULL_TREE", __func__);
88738 + gcc_unreachable();
88739 + }
88740 +
88741 + if (gimple_code(oldstmt) == GIMPLE_ASM)
88742 + lhs = rhs1;
88743 + else
88744 + lhs = gimple_get_lhs(oldstmt);
88745 +
88746 + gsi = gsi_for_stmt(oldstmt);
88747 + pointer_set_insert(visited, oldstmt);
88748 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
88749 + basic_block next_bb, cur_bb;
88750 + const_edge e;
88751 +
88752 + gcc_assert(before == false);
88753 + gcc_assert(stmt_can_throw_internal(oldstmt));
88754 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
88755 + gcc_assert(!gsi_end_p(gsi));
88756 +
88757 + cur_bb = gimple_bb(oldstmt);
88758 + next_bb = cur_bb->next_bb;
88759 + e = find_edge(cur_bb, next_bb);
88760 + gcc_assert(e != NULL);
88761 + gcc_assert(e->flags & EDGE_FALLTHRU);
88762 +
88763 + gsi = gsi_after_labels(next_bb);
88764 + gcc_assert(!gsi_end_p(gsi));
88765 +
88766 + before = true;
88767 + oldstmt = gsi_stmt(gsi);
88768 + }
88769 +
88770 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
88771 +}
88772 +
88773 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
88774 +{
88775 + gimple stmt;
88776 + gimple_stmt_iterator gsi;
88777 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
88778 +
88779 + if (gimple_plf(oldstmt, MY_STMT))
88780 + return lhs;
88781 +
88782 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
88783 + rhs1 = gimple_assign_rhs1(oldstmt);
88784 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
88785 + }
88786 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
88787 + rhs2 = gimple_assign_rhs2(oldstmt);
88788 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
88789 + }
88790 +
88791 + stmt = gimple_copy(oldstmt);
88792 + gimple_set_location(stmt, gimple_location(oldstmt));
88793 + gimple_set_plf(stmt, MY_STMT, true);
88794 +
88795 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
88796 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
88797 +
88798 + size_overflow_type = get_size_overflow_type(oldstmt, node);
88799 +
88800 + if (is_bool(lhs))
88801 + new_var = SSA_NAME_VAR(lhs);
88802 + else
88803 + new_var = create_new_var(size_overflow_type);
88804 + new_var = make_ssa_name(new_var, stmt);
88805 + gimple_set_lhs(stmt, new_var);
88806 +
88807 + if (rhs1 != NULL_TREE) {
88808 + if (!gimple_assign_cast_p(oldstmt) && TREE_CODE_CLASS(gimple_assign_rhs_code(oldstmt)) != tcc_comparison)
88809 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
88810 + gimple_assign_set_rhs1(stmt, rhs1);
88811 + }
88812 +
88813 + if (rhs2 != NULL_TREE)
88814 + gimple_assign_set_rhs2(stmt, rhs2);
88815 +#if BUILDING_GCC_VERSION >= 4007
88816 + if (rhs3 != NULL_TREE)
88817 + gimple_assign_set_rhs3(stmt, rhs3);
88818 +#endif
88819 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
88820 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
88821 +
88822 + gsi = gsi_for_stmt(oldstmt);
88823 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
88824 + update_stmt(stmt);
88825 + pointer_set_insert(visited, oldstmt);
88826 + return gimple_get_lhs(stmt);
88827 +}
88828 +
88829 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
88830 +{
88831 + basic_block bb;
88832 + gimple phi;
88833 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
88834 +
88835 + bb = gsi_bb(gsi);
88836 +
88837 + phi = create_phi_node(result, bb);
88838 + gsi = gsi_last(phi_nodes(bb));
88839 + gsi_remove(&gsi, false);
88840 +
88841 + gsi = gsi_for_stmt(oldstmt);
88842 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
88843 + gimple_set_bb(phi, bb);
88844 + gimple_set_plf(phi, MY_STMT, true);
88845 + return phi;
88846 +}
88847 +
88848 +static basic_block create_a_first_bb(void)
88849 +{
88850 + basic_block first_bb;
88851 +
88852 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88853 + if (dom_info_available_p(CDI_DOMINATORS))
88854 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
88855 + return first_bb;
88856 +}
88857 +
88858 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
88859 +{
88860 + basic_block bb;
88861 + const_gimple newstmt;
88862 + gimple_stmt_iterator gsi;
88863 + bool before = BEFORE_STMT;
88864 +
88865 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
88866 + gsi = gsi_for_stmt(get_def_stmt(arg));
88867 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
88868 + return gimple_get_lhs(newstmt);
88869 + }
88870 +
88871 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
88872 + gsi = gsi_after_labels(bb);
88873 + if (bb->index == 0) {
88874 + bb = create_a_first_bb();
88875 + gsi = gsi_start_bb(bb);
88876 + }
88877 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
88878 + return gimple_get_lhs(newstmt);
88879 +}
88880 +
88881 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
88882 +{
88883 + gimple newstmt;
88884 + gimple_stmt_iterator gsi;
88885 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
88886 + gimple def_newstmt = get_def_stmt(new_rhs);
88887 +
88888 + gsi_insert = gsi_insert_after;
88889 + gsi = gsi_for_stmt(def_newstmt);
88890 +
88891 + switch (gimple_code(get_def_stmt(arg))) {
88892 + case GIMPLE_PHI:
88893 + newstmt = gimple_build_assign(new_var, new_rhs);
88894 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
88895 + gsi_insert = gsi_insert_before;
88896 + break;
88897 + case GIMPLE_ASM:
88898 + case GIMPLE_CALL:
88899 + newstmt = gimple_build_assign(new_var, new_rhs);
88900 + break;
88901 + case GIMPLE_ASSIGN:
88902 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
88903 + break;
88904 + default:
88905 + /* unknown gimple_code (handle_build_new_phi_arg) */
88906 + gcc_unreachable();
88907 + }
88908 +
88909 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
88910 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
88911 + gimple_set_plf(newstmt, MY_STMT, true);
88912 + update_stmt(newstmt);
88913 + return newstmt;
88914 +}
88915 +
88916 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
88917 +{
88918 + const_gimple newstmt;
88919 + gimple def_stmt;
88920 + tree new_rhs;
88921 +
88922 + new_rhs = expand(visited, arg);
88923 + if (new_rhs == NULL_TREE)
88924 + return NULL_TREE;
88925 +
88926 + def_stmt = get_def_stmt(new_rhs);
88927 + if (gimple_code(def_stmt) == GIMPLE_NOP)
88928 + return NULL_TREE;
88929 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
88930 +
88931 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
88932 + return gimple_get_lhs(newstmt);
88933 +}
88934 +
88935 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
88936 +{
88937 + gimple phi, oldstmt = get_def_stmt(orig_result);
88938 + tree new_result, size_overflow_type;
88939 + unsigned int i;
88940 + unsigned int n = gimple_phi_num_args(oldstmt);
88941 +
88942 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
88943 +
88944 + new_result = create_new_var(size_overflow_type);
88945 +
88946 + pointer_set_insert(visited, oldstmt);
88947 + phi = overflow_create_phi_node(oldstmt, new_result);
88948 + for (i = 0; i < n; i++) {
88949 + tree arg, lhs;
88950 +
88951 + arg = gimple_phi_arg_def(oldstmt, i);
88952 + if (is_gimple_constant(arg))
88953 + arg = cast_a_tree(size_overflow_type, arg);
88954 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
88955 + if (lhs == NULL_TREE)
88956 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
88957 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
88958 + }
88959 +
88960 + update_stmt(phi);
88961 + return gimple_phi_result(phi);
88962 +}
88963 +
88964 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
88965 +{
88966 + const_gimple assign;
88967 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88968 + tree origtype = TREE_TYPE(orig_rhs);
88969 +
88970 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
88971 +
88972 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88973 + return gimple_get_lhs(assign);
88974 +}
88975 +
88976 +static void change_rhs1(gimple stmt, tree new_rhs1)
88977 +{
88978 + tree assign_rhs;
88979 + const_tree rhs = gimple_assign_rhs1(stmt);
88980 +
88981 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
88982 + gimple_assign_set_rhs1(stmt, assign_rhs);
88983 + update_stmt(stmt);
88984 +}
88985 +
88986 +static bool check_mode_type(const_gimple stmt)
88987 +{
88988 + const_tree lhs = gimple_get_lhs(stmt);
88989 + const_tree lhs_type = TREE_TYPE(lhs);
88990 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88991 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88992 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88993 +
88994 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88995 + return false;
88996 +
88997 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88998 + return false;
88999 +
89000 + return true;
89001 +}
89002 +
89003 +static bool check_undefined_integer_operation(const_gimple stmt)
89004 +{
89005 + const_gimple def_stmt;
89006 + const_tree lhs = gimple_get_lhs(stmt);
89007 + const_tree rhs1 = gimple_assign_rhs1(stmt);
89008 + const_tree rhs1_type = TREE_TYPE(rhs1);
89009 + const_tree lhs_type = TREE_TYPE(lhs);
89010 +
89011 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
89012 + return false;
89013 +
89014 + def_stmt = get_def_stmt(rhs1);
89015 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
89016 + return false;
89017 +
89018 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
89019 + return false;
89020 + return true;
89021 +}
89022 +
89023 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
89024 +{
89025 + const_tree rhs1, lhs, rhs1_type, lhs_type;
89026 + enum machine_mode lhs_mode, rhs_mode;
89027 + gimple def_stmt = get_def_stmt(no_const_rhs);
89028 +
89029 + if (!gimple_assign_cast_p(def_stmt))
89030 + return false;
89031 +
89032 + rhs1 = gimple_assign_rhs1(def_stmt);
89033 + lhs = gimple_get_lhs(def_stmt);
89034 + rhs1_type = TREE_TYPE(rhs1);
89035 + lhs_type = TREE_TYPE(lhs);
89036 + rhs_mode = TYPE_MODE(rhs1_type);
89037 + lhs_mode = TYPE_MODE(lhs_type);
89038 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
89039 + return false;
89040 +
89041 + return true;
89042 +}
89043 +
89044 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
89045 +{
89046 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
89047 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
89048 + const_tree rhs1_type = TREE_TYPE(rhs1);
89049 + const_tree lhs_type = TREE_TYPE(lhs);
89050 +
89051 + new_rhs1 = expand(visited, rhs1);
89052 +
89053 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
89054 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89055 +
89056 + if (gimple_plf(stmt, MY_STMT))
89057 + return lhs;
89058 +
89059 + if (gimple_plf(stmt, NO_CAST_CHECK))
89060 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
89061 +
89062 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
89063 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
89064 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
89065 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
89066 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89067 + }
89068 +
89069 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
89070 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
89071 +
89072 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
89073 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
89074 +
89075 + change_rhs1(stmt, new_rhs1);
89076 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
89077 +
89078 + rhs1 = gimple_assign_rhs1(stmt);
89079 + rhs1_type = TREE_TYPE(rhs1);
89080 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
89081 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
89082 +
89083 + if (!check_mode_type(stmt))
89084 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89085 +
89086 + size_overflow_type = get_size_overflow_type(stmt, lhs);
89087 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
89088 +
89089 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
89090 +
89091 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89092 +}
89093 +
89094 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
89095 +{
89096 + gimple def_stmt = get_def_stmt(lhs);
89097 + tree rhs1 = gimple_assign_rhs1(def_stmt);
89098 +
89099 + if (is_gimple_constant(rhs1))
89100 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89101 +
89102 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
89103 + switch (TREE_CODE(rhs1)) {
89104 + case SSA_NAME:
89105 + return handle_unary_rhs(visited, def_stmt);
89106 + case ARRAY_REF:
89107 + case BIT_FIELD_REF:
89108 + case ADDR_EXPR:
89109 + case COMPONENT_REF:
89110 + case INDIRECT_REF:
89111 +#if BUILDING_GCC_VERSION >= 4006
89112 + case MEM_REF:
89113 +#endif
89114 + case PARM_DECL:
89115 + case TARGET_MEM_REF:
89116 + case VAR_DECL:
89117 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89118 +
89119 + default:
89120 + debug_gimple_stmt(def_stmt);
89121 + debug_tree(rhs1);
89122 + gcc_unreachable();
89123 + }
89124 +}
89125 +
89126 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
89127 +{
89128 + gimple cond_stmt;
89129 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
89130 +
89131 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
89132 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
89133 + update_stmt(cond_stmt);
89134 +}
89135 +
89136 +static tree create_string_param(tree string)
89137 +{
89138 + tree i_type, a_type;
89139 + const int length = TREE_STRING_LENGTH(string);
89140 +
89141 + gcc_assert(length > 0);
89142 +
89143 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
89144 + a_type = build_array_type(char_type_node, i_type);
89145 +
89146 + TREE_TYPE(string) = a_type;
89147 + TREE_CONSTANT(string) = 1;
89148 + TREE_READONLY(string) = 1;
89149 +
89150 + return build1(ADDR_EXPR, ptr_type_node, string);
89151 +}
89152 +
89153 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
89154 +{
89155 + gimple func_stmt;
89156 + const_gimple def_stmt;
89157 + const_tree loc_line;
89158 + tree loc_file, ssa_name, current_func;
89159 + expanded_location xloc;
89160 + char ssa_name_buf[256];
89161 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
89162 +
89163 + def_stmt = get_def_stmt(arg);
89164 + xloc = expand_location(gimple_location(def_stmt));
89165 +
89166 + if (!gimple_has_location(def_stmt)) {
89167 + xloc = expand_location(gimple_location(stmt));
89168 + if (!gimple_has_location(stmt))
89169 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
89170 + }
89171 +
89172 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
89173 +
89174 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
89175 + loc_file = create_string_param(loc_file);
89176 +
89177 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
89178 + current_func = create_string_param(current_func);
89179 +
89180 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
89181 + ssa_name = build_string(256, ssa_name_buf);
89182 + ssa_name = create_string_param(ssa_name);
89183 +
89184 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
89185 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
89186 +
89187 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
89188 +}
89189 +
89190 +static void __unused print_the_code_insertions(const_gimple stmt)
89191 +{
89192 + location_t loc = gimple_location(stmt);
89193 +
89194 + inform(loc, "Integer size_overflow check applied here.");
89195 +}
89196 +
89197 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
89198 +{
89199 + basic_block cond_bb, join_bb, bb_true;
89200 + edge e;
89201 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89202 +
89203 + cond_bb = gimple_bb(stmt);
89204 + if (before)
89205 + gsi_prev(&gsi);
89206 + if (gsi_end_p(gsi))
89207 + e = split_block_after_labels(cond_bb);
89208 + else
89209 + e = split_block(cond_bb, gsi_stmt(gsi));
89210 + cond_bb = e->src;
89211 + join_bb = e->dest;
89212 + e->flags = EDGE_FALSE_VALUE;
89213 + e->probability = REG_BR_PROB_BASE;
89214 +
89215 + bb_true = create_empty_bb(cond_bb);
89216 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
89217 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
89218 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
89219 +
89220 + if (dom_info_available_p(CDI_DOMINATORS)) {
89221 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
89222 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
89223 + }
89224 +
89225 + if (current_loops != NULL) {
89226 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
89227 + add_bb_to_loop(bb_true, cond_bb->loop_father);
89228 + }
89229 +
89230 + insert_cond(cond_bb, arg, cond_code, type_value);
89231 + insert_cond_result(bb_true, stmt, arg, min);
89232 +
89233 +// print_the_code_insertions(stmt);
89234 +}
89235 +
89236 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
89237 +{
89238 + const_tree rhs_type = TREE_TYPE(rhs);
89239 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
89240 +
89241 + gcc_assert(rhs_type != NULL_TREE);
89242 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
89243 + return;
89244 +
89245 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
89246 +
89247 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
89248 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
89249 +
89250 + gcc_assert(!TREE_OVERFLOW(type_max));
89251 +
89252 + cast_rhs_type = TREE_TYPE(cast_rhs);
89253 + type_max_type = TREE_TYPE(type_max);
89254 + type_min_type = TREE_TYPE(type_min);
89255 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
89256 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
89257 +
89258 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
89259 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
89260 +}
89261 +
89262 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
89263 +{
89264 + gimple change_rhs_def_stmt;
89265 + tree lhs = gimple_get_lhs(def_stmt);
89266 + tree lhs_type = TREE_TYPE(lhs);
89267 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
89268 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
89269 +
89270 + if (change_rhs == NULL_TREE)
89271 + return get_size_overflow_type(def_stmt, lhs);
89272 +
89273 + change_rhs_def_stmt = get_def_stmt(change_rhs);
89274 +
89275 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
89276 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
89277 +
89278 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
89279 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
89280 +
89281 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
89282 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
89283 +
89284 + if (!types_compatible_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
89285 + debug_gimple_stmt(def_stmt);
89286 + gcc_unreachable();
89287 + }
89288 +
89289 + return get_size_overflow_type(def_stmt, lhs);
89290 +}
89291 +
89292 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
89293 +{
89294 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
89295 + return false;
89296 + if (!is_gimple_constant(rhs))
89297 + return false;
89298 + return true;
89299 +}
89300 +
89301 +static bool is_subtraction_special(const_gimple stmt)
89302 +{
89303 + gimple rhs1_def_stmt, rhs2_def_stmt;
89304 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
89305 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
89306 + const_tree rhs1 = gimple_assign_rhs1(stmt);
89307 + const_tree rhs2 = gimple_assign_rhs2(stmt);
89308 +
89309 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
89310 + return false;
89311 +
89312 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
89313 +
89314 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
89315 + return false;
89316 +
89317 + rhs1_def_stmt = get_def_stmt(rhs1);
89318 + rhs2_def_stmt = get_def_stmt(rhs2);
89319 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
89320 + return false;
89321 +
89322 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
89323 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
89324 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
89325 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
89326 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
89327 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
89328 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
89329 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
89330 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
89331 + return false;
89332 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
89333 + return false;
89334 +
89335 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
89336 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
89337 + return true;
89338 +}
89339 +
89340 +static tree get_def_stmt_rhs(const_tree var)
89341 +{
89342 + tree rhs1, def_stmt_rhs1;
89343 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
89344 +
89345 + def_stmt = get_def_stmt(var);
89346 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
89347 +
89348 + rhs1 = gimple_assign_rhs1(def_stmt);
89349 + rhs1_def_stmt = get_def_stmt(rhs1);
89350 + gcc_assert(gimple_code(rhs1_def_stmt) != GIMPLE_NOP);
89351 + if (!gimple_assign_cast_p(rhs1_def_stmt))
89352 + return rhs1;
89353 +
89354 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
89355 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
89356 +
89357 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
89358 + case GIMPLE_CALL:
89359 + case GIMPLE_NOP:
89360 + case GIMPLE_ASM:
89361 + return def_stmt_rhs1;
89362 + case GIMPLE_ASSIGN:
89363 + return rhs1;
89364 + default:
89365 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
89366 + gcc_unreachable();
89367 + }
89368 +}
89369 +
89370 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
89371 +{
89372 + tree new_rhs1, new_rhs2;
89373 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
89374 + gimple assign, stmt = get_def_stmt(lhs);
89375 + tree rhs1 = gimple_assign_rhs1(stmt);
89376 + tree rhs2 = gimple_assign_rhs2(stmt);
89377 +
89378 + if (!is_subtraction_special(stmt))
89379 + return NULL_TREE;
89380 +
89381 + new_rhs1 = expand(visited, rhs1);
89382 + new_rhs2 = expand(visited, rhs2);
89383 +
89384 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
89385 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
89386 +
89387 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
89388 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
89389 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
89390 + }
89391 +
89392 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
89393 + new_lhs = gimple_get_lhs(assign);
89394 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
89395 +
89396 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
89397 +}
89398 +
89399 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
89400 +{
89401 + const_gimple def_stmt;
89402 +
89403 + if (TREE_CODE(rhs) != SSA_NAME)
89404 + return false;
89405 +
89406 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
89407 + return false;
89408 +
89409 + def_stmt = get_def_stmt(rhs);
89410 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
89411 + return false;
89412 +
89413 + return true;
89414 +}
89415 +
89416 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
89417 +{
89418 + tree new_rhs, size_overflow_type, orig_rhs;
89419 + void (*gimple_assign_set_rhs)(gimple, tree);
89420 + tree rhs1 = gimple_assign_rhs1(stmt);
89421 + tree rhs2 = gimple_assign_rhs2(stmt);
89422 + tree lhs = gimple_get_lhs(stmt);
89423 +
89424 + if (change_rhs == NULL_TREE)
89425 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89426 +
89427 + if (new_rhs2 == NULL_TREE) {
89428 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
89429 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
89430 + orig_rhs = rhs1;
89431 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
89432 + } else {
89433 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
89434 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
89435 + orig_rhs = rhs2;
89436 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
89437 + }
89438 +
89439 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
89440 +
89441 + if (check_overflow)
89442 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
89443 +
89444 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
89445 + gimple_assign_set_rhs(stmt, new_rhs);
89446 + update_stmt(stmt);
89447 +
89448 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89449 +}
89450 +
89451 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
89452 +{
89453 + tree rhs1, rhs2, new_lhs;
89454 + gimple def_stmt = get_def_stmt(lhs);
89455 + tree new_rhs1 = NULL_TREE;
89456 + tree new_rhs2 = NULL_TREE;
89457 +
89458 + rhs1 = gimple_assign_rhs1(def_stmt);
89459 + rhs2 = gimple_assign_rhs2(def_stmt);
89460 +
89461 + /* no DImode/TImode division in the 32/64 bit kernel */
89462 + switch (gimple_assign_rhs_code(def_stmt)) {
89463 + case RDIV_EXPR:
89464 + case TRUNC_DIV_EXPR:
89465 + case CEIL_DIV_EXPR:
89466 + case FLOOR_DIV_EXPR:
89467 + case ROUND_DIV_EXPR:
89468 + case TRUNC_MOD_EXPR:
89469 + case CEIL_MOD_EXPR:
89470 + case FLOOR_MOD_EXPR:
89471 + case ROUND_MOD_EXPR:
89472 + case EXACT_DIV_EXPR:
89473 + case POINTER_PLUS_EXPR:
89474 + case BIT_AND_EXPR:
89475 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89476 + default:
89477 + break;
89478 + }
89479 +
89480 + new_lhs = handle_integer_truncation(visited, lhs);
89481 + if (new_lhs != NULL_TREE)
89482 + return new_lhs;
89483 +
89484 + if (TREE_CODE(rhs1) == SSA_NAME)
89485 + new_rhs1 = expand(visited, rhs1);
89486 + if (TREE_CODE(rhs2) == SSA_NAME)
89487 + new_rhs2 = expand(visited, rhs2);
89488 +
89489 + if (is_a_neg_overflow(def_stmt, rhs2))
89490 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
89491 + if (is_a_neg_overflow(def_stmt, rhs1))
89492 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
89493 +
89494 + if (is_a_constant_overflow(def_stmt, rhs2))
89495 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
89496 + if (is_a_constant_overflow(def_stmt, rhs1))
89497 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
89498 +
89499 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
89500 +}
89501 +
89502 +#if BUILDING_GCC_VERSION >= 4007
89503 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
89504 +{
89505 + if (is_gimple_constant(rhs))
89506 + return cast_a_tree(size_overflow_type, rhs);
89507 + if (TREE_CODE(rhs) != SSA_NAME)
89508 + return NULL_TREE;
89509 + return expand(visited, rhs);
89510 +}
89511 +
89512 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
89513 +{
89514 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
89515 + gimple def_stmt = get_def_stmt(lhs);
89516 +
89517 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
89518 +
89519 + rhs1 = gimple_assign_rhs1(def_stmt);
89520 + rhs2 = gimple_assign_rhs2(def_stmt);
89521 + rhs3 = gimple_assign_rhs3(def_stmt);
89522 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
89523 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
89524 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
89525 +
89526 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
89527 +}
89528 +#endif
89529 +
89530 +static tree get_size_overflow_type(gimple stmt, const_tree node)
89531 +{
89532 + const_tree type;
89533 +
89534 + gcc_assert(node != NULL_TREE);
89535 +
89536 + type = TREE_TYPE(node);
89537 +
89538 + if (gimple_plf(stmt, MY_STMT))
89539 + return TREE_TYPE(node);
89540 +
89541 + switch (TYPE_MODE(type)) {
89542 + case QImode:
89543 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
89544 + case HImode:
89545 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
89546 + case SImode:
89547 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89548 + case DImode:
89549 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
89550 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89551 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
89552 + default:
89553 + debug_tree((tree)node);
89554 + error("%s: unsupported gcc configuration.", __func__);
89555 + gcc_unreachable();
89556 + }
89557 +}
89558 +
89559 +static tree expand_visited(gimple def_stmt)
89560 +{
89561 + const_gimple next_stmt;
89562 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
89563 +
89564 + gsi_next(&gsi);
89565 + next_stmt = gsi_stmt(gsi);
89566 +
89567 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
89568 +
89569 + switch (gimple_code(next_stmt)) {
89570 + case GIMPLE_ASSIGN:
89571 + return gimple_get_lhs(next_stmt);
89572 + case GIMPLE_PHI:
89573 + return gimple_phi_result(next_stmt);
89574 + case GIMPLE_CALL:
89575 + return gimple_call_lhs(next_stmt);
89576 + default:
89577 + return NULL_TREE;
89578 + }
89579 +}
89580 +
89581 +static tree expand(struct pointer_set_t *visited, tree lhs)
89582 +{
89583 + gimple def_stmt;
89584 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
89585 +
89586 + if (is_gimple_constant(lhs))
89587 + return NULL_TREE;
89588 +
89589 + if (TREE_CODE(lhs) == ADDR_EXPR)
89590 + return NULL_TREE;
89591 +
89592 + if (code == REAL_TYPE)
89593 + return NULL_TREE;
89594 +
89595 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
89596 +
89597 +
89598 + def_stmt = get_def_stmt(lhs);
89599 +
89600 + if (!def_stmt)
89601 + return NULL_TREE;
89602 +
89603 + if (gimple_plf(def_stmt, MY_STMT))
89604 + return lhs;
89605 +
89606 + if (pointer_set_contains(visited, def_stmt))
89607 + return expand_visited(def_stmt);
89608 +
89609 + switch (gimple_code(def_stmt)) {
89610 + case GIMPLE_NOP:
89611 + return NULL_TREE;
89612 + case GIMPLE_PHI:
89613 + return build_new_phi(visited, lhs);
89614 + case GIMPLE_CALL:
89615 + case GIMPLE_ASM:
89616 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89617 + case GIMPLE_ASSIGN:
89618 + switch (gimple_num_ops(def_stmt)) {
89619 + case 2:
89620 + return handle_unary_ops(visited, lhs);
89621 + case 3:
89622 + return handle_binary_ops(visited, lhs);
89623 +#if BUILDING_GCC_VERSION >= 4007
89624 + case 4:
89625 + return handle_ternary_ops(visited, lhs);
89626 +#endif
89627 + }
89628 + default:
89629 + debug_gimple_stmt(def_stmt);
89630 + error("%s: unknown gimple code", __func__);
89631 + gcc_unreachable();
89632 + }
89633 +}
89634 +
89635 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
89636 +{
89637 + const_gimple assign;
89638 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89639 + tree origtype = TREE_TYPE(origarg);
89640 +
89641 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
89642 +
89643 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89644 +
89645 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
89646 + update_stmt(stmt);
89647 +}
89648 +
89649 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
89650 +{
89651 + const char *origid;
89652 + tree arg;
89653 + const_tree origarg;
89654 +
89655 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
89656 + return true;
89657 +
89658 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
89659 + while (origarg && *argnum) {
89660 + (*argnum)--;
89661 + origarg = TREE_CHAIN(origarg);
89662 + }
89663 +
89664 + gcc_assert(*argnum == 0);
89665 +
89666 + gcc_assert(origarg != NULL_TREE);
89667 + origid = NAME(origarg);
89668 + *argnum = 0;
89669 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
89670 + if (!strcmp(origid, NAME(arg)))
89671 + return true;
89672 + (*argnum)++;
89673 + }
89674 + return false;
89675 +}
89676 +
89677 +static bool skip_types(const_tree var)
89678 +{
89679 + switch (TREE_CODE(var)) {
89680 + case ADDR_EXPR:
89681 +#if BUILDING_GCC_VERSION >= 4006
89682 + case MEM_REF:
89683 +#endif
89684 + case ARRAY_REF:
89685 + case BIT_FIELD_REF:
89686 + case INDIRECT_REF:
89687 + case TARGET_MEM_REF:
89688 + case VAR_DECL:
89689 + return true;
89690 + default:
89691 + break;
89692 + }
89693 + return false;
89694 +}
89695 +
89696 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
89697 +{
89698 + gimple phi = get_def_stmt(result);
89699 + unsigned int i, n = gimple_phi_num_args(phi);
89700 +
89701 + if (!phi)
89702 + return false;
89703 +
89704 + pointer_set_insert(visited, phi);
89705 + for (i = 0; i < n; i++) {
89706 + const_tree arg = gimple_phi_arg_def(phi, i);
89707 + if (pre_expand(visited, arg))
89708 + return true;
89709 + }
89710 + return false;
89711 +}
89712 +
89713 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
89714 +{
89715 + gimple def_stmt = get_def_stmt(lhs);
89716 + const_tree rhs;
89717 +
89718 + if (!def_stmt)
89719 + return false;
89720 +
89721 + rhs = gimple_assign_rhs1(def_stmt);
89722 + if (pre_expand(visited, rhs))
89723 + return true;
89724 + return false;
89725 +}
89726 +
89727 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
89728 +{
89729 + bool rhs1_found, rhs2_found;
89730 + gimple def_stmt = get_def_stmt(lhs);
89731 + const_tree rhs1, rhs2;
89732 +
89733 + if (!def_stmt)
89734 + return false;
89735 +
89736 + rhs1 = gimple_assign_rhs1(def_stmt);
89737 + rhs2 = gimple_assign_rhs2(def_stmt);
89738 + rhs1_found = pre_expand(visited, rhs1);
89739 + rhs2_found = pre_expand(visited, rhs2);
89740 +
89741 + return rhs1_found || rhs2_found;
89742 +}
89743 +
89744 +static const_tree search_field_decl(const_tree comp_ref)
89745 +{
89746 + const_tree field = NULL_TREE;
89747 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
89748 +
89749 + for (i = 0; i < len; i++) {
89750 + field = TREE_OPERAND(comp_ref, i);
89751 + if (TREE_CODE(field) == FIELD_DECL)
89752 + break;
89753 + }
89754 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
89755 + return field;
89756 +}
89757 +
89758 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
89759 +{
89760 + const_tree attr, p;
89761 +
89762 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
89763 + if (!attr || !TREE_VALUE(attr))
89764 + return MARKED_NO;
89765 +
89766 + p = TREE_VALUE(attr);
89767 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
89768 + return MARKED_NOT_INTENTIONAL;
89769 +
89770 + do {
89771 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
89772 + return MARKED_YES;
89773 + p = TREE_CHAIN(p);
89774 + } while (p);
89775 +
89776 + return MARKED_NO;
89777 +}
89778 +
89779 +static void print_missing_msg(tree func, unsigned int argnum)
89780 +{
89781 + unsigned int new_hash;
89782 + size_t len;
89783 + unsigned char tree_codes[CODES_LIMIT];
89784 + location_t loc = DECL_SOURCE_LOCATION(func);
89785 + const char *curfunc = get_asm_name(func);
89786 +
89787 + len = get_function_decl(func, tree_codes);
89788 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
89789 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
89790 +}
89791 +
89792 +static unsigned int search_missing_attribute(const_tree arg)
89793 +{
89794 + const_tree type = TREE_TYPE(arg);
89795 + tree func = get_original_function_decl(current_function_decl);
89796 + unsigned int argnum;
89797 + const struct size_overflow_hash *hash;
89798 +
89799 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
89800 +
89801 + if (TREE_CODE(type) == POINTER_TYPE)
89802 + return 0;
89803 +
89804 + argnum = find_arg_number(arg, func);
89805 + if (argnum == 0)
89806 + return 0;
89807 +
89808 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
89809 + return argnum;
89810 +
89811 + hash = get_function_hash(func);
89812 + if (!hash || !(hash->param & (1U << argnum))) {
89813 + print_missing_msg(func, argnum);
89814 + return 0;
89815 + }
89816 + return argnum;
89817 +}
89818 +
89819 +static bool is_already_marked(const_tree lhs)
89820 +{
89821 + unsigned int argnum;
89822 + const_tree fndecl;
89823 +
89824 + argnum = search_missing_attribute(lhs);
89825 + fndecl = get_original_function_decl(current_function_decl);
89826 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
89827 + return true;
89828 + return false;
89829 +}
89830 +
89831 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
89832 +{
89833 + const_gimple def_stmt;
89834 +
89835 + if (is_gimple_constant(lhs))
89836 + return false;
89837 +
89838 + if (skip_types(lhs))
89839 + return false;
89840 +
89841 + if (TREE_CODE(lhs) == PARM_DECL)
89842 + return is_already_marked(lhs);
89843 +
89844 + if (TREE_CODE(lhs) == COMPONENT_REF) {
89845 + const_tree field, attr;
89846 +
89847 + field = search_field_decl(lhs);
89848 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
89849 + if (!attr || !TREE_VALUE(attr))
89850 + return false;
89851 + return true;
89852 + }
89853 +
89854 + def_stmt = get_def_stmt(lhs);
89855 +
89856 + if (!def_stmt)
89857 + return false;
89858 +
89859 + if (pointer_set_contains(visited, def_stmt))
89860 + return false;
89861 +
89862 + switch (gimple_code(def_stmt)) {
89863 + case GIMPLE_NOP:
89864 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
89865 + return is_already_marked(lhs);
89866 + return false;
89867 + case GIMPLE_PHI:
89868 + return walk_phi(visited, lhs);
89869 + case GIMPLE_CALL:
89870 + case GIMPLE_ASM:
89871 + return false;
89872 + case GIMPLE_ASSIGN:
89873 + switch (gimple_num_ops(def_stmt)) {
89874 + case 2:
89875 + return walk_unary_ops(visited, lhs);
89876 + case 3:
89877 + return walk_binary_ops(visited, lhs);
89878 + }
89879 + default:
89880 + debug_gimple_stmt((gimple)def_stmt);
89881 + error("%s: unknown gimple code", __func__);
89882 + gcc_unreachable();
89883 + }
89884 +}
89885 +
89886 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
89887 +{
89888 + struct pointer_set_t *visited;
89889 + bool is_found;
89890 + enum marked is_marked;
89891 + location_t loc;
89892 +
89893 + visited = pointer_set_create();
89894 + is_found = pre_expand(visited, arg);
89895 + pointer_set_destroy(visited);
89896 +
89897 + is_marked = mark_status(fndecl, argnum + 1);
89898 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
89899 + return true;
89900 +
89901 + if (is_found) {
89902 + loc = DECL_SOURCE_LOCATION(fndecl);
89903 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
89904 + return true;
89905 + }
89906 + return false;
89907 +}
89908 +
89909 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
89910 +{
89911 + struct pointer_set_t *visited;
89912 + tree arg, newarg;
89913 + bool match;
89914 +
89915 + match = get_function_arg(&argnum, fndecl);
89916 + if (!match)
89917 + return;
89918 + gcc_assert(gimple_call_num_args(stmt) > argnum);
89919 + arg = gimple_call_arg(stmt, argnum);
89920 + if (arg == NULL_TREE)
89921 + return;
89922 +
89923 + if (is_gimple_constant(arg))
89924 + return;
89925 +
89926 + if (search_attributes(fndecl, arg, argnum))
89927 + return;
89928 +
89929 + if (TREE_CODE(arg) != SSA_NAME)
89930 + return;
89931 +
89932 + check_arg_type(arg);
89933 +
89934 + visited = pointer_set_create();
89935 + newarg = expand(visited, arg);
89936 + pointer_set_destroy(visited);
89937 +
89938 + if (newarg == NULL_TREE)
89939 + return;
89940 +
89941 + change_function_arg(stmt, arg, argnum, newarg);
89942 +
89943 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
89944 +}
89945 +
89946 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
89947 +{
89948 + tree p = TREE_VALUE(attr);
89949 + do {
89950 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
89951 + p = TREE_CHAIN(p);
89952 + } while (p);
89953 +}
89954 +
89955 +static void handle_function_by_hash(gimple stmt, tree fndecl)
89956 +{
89957 + tree orig_fndecl;
89958 + unsigned int num;
89959 + const struct size_overflow_hash *hash;
89960 +
89961 + orig_fndecl = get_original_function_decl(fndecl);
89962 + if (C_DECL_IMPLICIT(orig_fndecl))
89963 + return;
89964 + hash = get_function_hash(orig_fndecl);
89965 + if (!hash)
89966 + return;
89967 +
89968 + for (num = 1; num <= MAX_PARAM; num++)
89969 + if (hash->param & (1U << num))
89970 + handle_function_arg(stmt, fndecl, num - 1);
89971 +}
89972 +
89973 +static void set_plf_false(void)
89974 +{
89975 + basic_block bb;
89976 +
89977 + FOR_ALL_BB(bb) {
89978 + gimple_stmt_iterator si;
89979 +
89980 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89981 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89982 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89983 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89984 + }
89985 +}
89986 +
89987 +static unsigned int handle_function(void)
89988 +{
89989 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89990 +
89991 + set_plf_false();
89992 +
89993 + do {
89994 + gimple_stmt_iterator gsi;
89995 + next = bb->next_bb;
89996 +
89997 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89998 + tree fndecl, attr;
89999 + gimple stmt = gsi_stmt(gsi);
90000 +
90001 + if (!(is_gimple_call(stmt)))
90002 + continue;
90003 + fndecl = gimple_call_fndecl(stmt);
90004 + if (fndecl == NULL_TREE)
90005 + continue;
90006 + if (gimple_call_num_args(stmt) == 0)
90007 + continue;
90008 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
90009 + if (!attr || !TREE_VALUE(attr))
90010 + handle_function_by_hash(stmt, fndecl);
90011 + else
90012 + handle_function_by_attribute(stmt, attr, fndecl);
90013 + gsi = gsi_for_stmt(stmt);
90014 + next = gimple_bb(stmt)->next_bb;
90015 + }
90016 + bb = next;
90017 + } while (bb);
90018 + return 0;
90019 +}
90020 +
90021 +static struct gimple_opt_pass size_overflow_pass = {
90022 + .pass = {
90023 + .type = GIMPLE_PASS,
90024 + .name = "size_overflow",
90025 + .gate = NULL,
90026 + .execute = handle_function,
90027 + .sub = NULL,
90028 + .next = NULL,
90029 + .static_pass_number = 0,
90030 + .tv_id = TV_NONE,
90031 + .properties_required = PROP_cfg | PROP_referenced_vars,
90032 + .properties_provided = 0,
90033 + .properties_destroyed = 0,
90034 + .todo_flags_start = 0,
90035 + .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
90036 + }
90037 +};
90038 +
90039 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
90040 +{
90041 + tree fntype;
90042 +
90043 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
90044 +
90045 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
90046 + fntype = build_function_type_list(void_type_node,
90047 + const_char_ptr_type_node,
90048 + unsigned_type_node,
90049 + const_char_ptr_type_node,
90050 + const_char_ptr_type_node,
90051 + NULL_TREE);
90052 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
90053 +
90054 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
90055 + TREE_PUBLIC(report_size_overflow_decl) = 1;
90056 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
90057 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
90058 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
90059 +}
90060 +
90061 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
90062 +{
90063 + int i;
90064 + const char * const plugin_name = plugin_info->base_name;
90065 + const int argc = plugin_info->argc;
90066 + const struct plugin_argument * const argv = plugin_info->argv;
90067 + bool enable = true;
90068 +
90069 + struct register_pass_info size_overflow_pass_info = {
90070 + .pass = &size_overflow_pass.pass,
90071 + .reference_pass_name = "ssa",
90072 + .ref_pass_instance_number = 1,
90073 + .pos_op = PASS_POS_INSERT_AFTER
90074 + };
90075 +
90076 + if (!plugin_default_version_check(version, &gcc_version)) {
90077 + error(G_("incompatible gcc/plugin versions"));
90078 + return 1;
90079 + }
90080 +
90081 + for (i = 0; i < argc; ++i) {
90082 + if (!strcmp(argv[i].key, "no-size-overflow")) {
90083 + enable = false;
90084 + continue;
90085 + }
90086 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
90087 + }
90088 +
90089 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
90090 + if (enable) {
90091 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
90092 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
90093 + }
90094 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
90095 +
90096 + return 0;
90097 +}
90098 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
90099 new file mode 100644
90100 index 0000000..38d2014
90101 --- /dev/null
90102 +++ b/tools/gcc/stackleak_plugin.c
90103 @@ -0,0 +1,313 @@
90104 +/*
90105 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
90106 + * Licensed under the GPL v2
90107 + *
90108 + * Note: the choice of the license means that the compilation process is
90109 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
90110 + * but for the kernel it doesn't matter since it doesn't link against
90111 + * any of the gcc libraries
90112 + *
90113 + * gcc plugin to help implement various PaX features
90114 + *
90115 + * - track lowest stack pointer
90116 + *
90117 + * TODO:
90118 + * - initialize all local variables
90119 + *
90120 + * BUGS:
90121 + * - none known
90122 + */
90123 +#include "gcc-plugin.h"
90124 +#include "config.h"
90125 +#include "system.h"
90126 +#include "coretypes.h"
90127 +#include "tree.h"
90128 +#include "tree-pass.h"
90129 +#include "flags.h"
90130 +#include "intl.h"
90131 +#include "toplev.h"
90132 +#include "plugin.h"
90133 +//#include "expr.h" where are you...
90134 +#include "diagnostic.h"
90135 +#include "plugin-version.h"
90136 +#include "tm.h"
90137 +#include "function.h"
90138 +#include "basic-block.h"
90139 +#include "gimple.h"
90140 +#include "rtl.h"
90141 +#include "emit-rtl.h"
90142 +
90143 +extern void print_gimple_stmt(FILE *, gimple, int, int);
90144 +
90145 +int plugin_is_GPL_compatible;
90146 +
90147 +static int track_frame_size = -1;
90148 +static const char track_function[] = "pax_track_stack";
90149 +static const char check_function[] = "pax_check_alloca";
90150 +static bool init_locals;
90151 +
90152 +static struct plugin_info stackleak_plugin_info = {
90153 + .version = "201203140940",
90154 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
90155 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
90156 +};
90157 +
90158 +static bool gate_stackleak_track_stack(void);
90159 +static unsigned int execute_stackleak_tree_instrument(void);
90160 +static unsigned int execute_stackleak_final(void);
90161 +
90162 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
90163 + .pass = {
90164 + .type = GIMPLE_PASS,
90165 + .name = "stackleak_tree_instrument",
90166 + .gate = gate_stackleak_track_stack,
90167 + .execute = execute_stackleak_tree_instrument,
90168 + .sub = NULL,
90169 + .next = NULL,
90170 + .static_pass_number = 0,
90171 + .tv_id = TV_NONE,
90172 + .properties_required = PROP_gimple_leh | PROP_cfg,
90173 + .properties_provided = 0,
90174 + .properties_destroyed = 0,
90175 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
90176 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
90177 + }
90178 +};
90179 +
90180 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
90181 + .pass = {
90182 + .type = RTL_PASS,
90183 + .name = "stackleak_final",
90184 + .gate = gate_stackleak_track_stack,
90185 + .execute = execute_stackleak_final,
90186 + .sub = NULL,
90187 + .next = NULL,
90188 + .static_pass_number = 0,
90189 + .tv_id = TV_NONE,
90190 + .properties_required = 0,
90191 + .properties_provided = 0,
90192 + .properties_destroyed = 0,
90193 + .todo_flags_start = 0,
90194 + .todo_flags_finish = TODO_dump_func
90195 + }
90196 +};
90197 +
90198 +static bool gate_stackleak_track_stack(void)
90199 +{
90200 + return track_frame_size >= 0;
90201 +}
90202 +
90203 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
90204 +{
90205 + gimple check_alloca;
90206 + tree fntype, fndecl, alloca_size;
90207 +
90208 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
90209 + fndecl = build_fn_decl(check_function, fntype);
90210 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
90211 +
90212 + // insert call to void pax_check_alloca(unsigned long size)
90213 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
90214 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
90215 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
90216 +}
90217 +
90218 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
90219 +{
90220 + gimple track_stack;
90221 + tree fntype, fndecl;
90222 +
90223 + fntype = build_function_type_list(void_type_node, NULL_TREE);
90224 + fndecl = build_fn_decl(track_function, fntype);
90225 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
90226 +
90227 + // insert call to void pax_track_stack(void)
90228 + track_stack = gimple_build_call(fndecl, 0);
90229 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
90230 +}
90231 +
90232 +#if BUILDING_GCC_VERSION == 4005
90233 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
90234 +{
90235 + tree fndecl;
90236 +
90237 + if (!is_gimple_call(stmt))
90238 + return false;
90239 + fndecl = gimple_call_fndecl(stmt);
90240 + if (!fndecl)
90241 + return false;
90242 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
90243 + return false;
90244 +// print_node(stderr, "pax", fndecl, 4);
90245 + return DECL_FUNCTION_CODE(fndecl) == code;
90246 +}
90247 +#endif
90248 +
90249 +static bool is_alloca(gimple stmt)
90250 +{
90251 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
90252 + return true;
90253 +
90254 +#if BUILDING_GCC_VERSION >= 4007
90255 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
90256 + return true;
90257 +#endif
90258 +
90259 + return false;
90260 +}
90261 +
90262 +static unsigned int execute_stackleak_tree_instrument(void)
90263 +{
90264 + basic_block bb, entry_bb;
90265 + bool prologue_instrumented = false, is_leaf = true;
90266 +
90267 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
90268 +
90269 + // 1. loop through BBs and GIMPLE statements
90270 + FOR_EACH_BB(bb) {
90271 + gimple_stmt_iterator gsi;
90272 +
90273 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
90274 + gimple stmt;
90275 +
90276 + stmt = gsi_stmt(gsi);
90277 +
90278 + if (is_gimple_call(stmt))
90279 + is_leaf = false;
90280 +
90281 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
90282 + if (!is_alloca(stmt))
90283 + continue;
90284 +
90285 + // 2. insert stack overflow check before each __builtin_alloca call
90286 + stackleak_check_alloca(&gsi);
90287 +
90288 + // 3. insert track call after each __builtin_alloca call
90289 + stackleak_add_instrumentation(&gsi);
90290 + if (bb == entry_bb)
90291 + prologue_instrumented = true;
90292 + }
90293 + }
90294 +
90295 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
90296 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
90297 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
90298 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
90299 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
90300 + return 0;
90301 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
90302 + return 0;
90303 +
90304 + // 4. insert track call at the beginning
90305 + if (!prologue_instrumented) {
90306 + gimple_stmt_iterator gsi;
90307 +
90308 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
90309 + if (dom_info_available_p(CDI_DOMINATORS))
90310 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
90311 + gsi = gsi_start_bb(bb);
90312 + stackleak_add_instrumentation(&gsi);
90313 + }
90314 +
90315 + return 0;
90316 +}
90317 +
90318 +static unsigned int execute_stackleak_final(void)
90319 +{
90320 + rtx insn;
90321 +
90322 + if (cfun->calls_alloca)
90323 + return 0;
90324 +
90325 + // keep calls only if function frame is big enough
90326 + if (get_frame_size() >= track_frame_size)
90327 + return 0;
90328 +
90329 + // 1. find pax_track_stack calls
90330 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
90331 + // 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))
90332 + rtx body;
90333 +
90334 + if (!CALL_P(insn))
90335 + continue;
90336 + body = PATTERN(insn);
90337 + if (GET_CODE(body) != CALL)
90338 + continue;
90339 + body = XEXP(body, 0);
90340 + if (GET_CODE(body) != MEM)
90341 + continue;
90342 + body = XEXP(body, 0);
90343 + if (GET_CODE(body) != SYMBOL_REF)
90344 + continue;
90345 + if (strcmp(XSTR(body, 0), track_function))
90346 + continue;
90347 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
90348 + // 2. delete call
90349 + insn = delete_insn_and_edges(insn);
90350 +#if BUILDING_GCC_VERSION >= 4007
90351 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
90352 + insn = delete_insn_and_edges(insn);
90353 +#endif
90354 + }
90355 +
90356 +// print_simple_rtl(stderr, get_insns());
90357 +// print_rtl(stderr, get_insns());
90358 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
90359 +
90360 + return 0;
90361 +}
90362 +
90363 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
90364 +{
90365 + const char * const plugin_name = plugin_info->base_name;
90366 + const int argc = plugin_info->argc;
90367 + const struct plugin_argument * const argv = plugin_info->argv;
90368 + int i;
90369 + struct register_pass_info stackleak_tree_instrument_pass_info = {
90370 + .pass = &stackleak_tree_instrument_pass.pass,
90371 +// .reference_pass_name = "tree_profile",
90372 + .reference_pass_name = "optimized",
90373 + .ref_pass_instance_number = 1,
90374 + .pos_op = PASS_POS_INSERT_BEFORE
90375 + };
90376 + struct register_pass_info stackleak_final_pass_info = {
90377 + .pass = &stackleak_final_rtl_opt_pass.pass,
90378 + .reference_pass_name = "final",
90379 + .ref_pass_instance_number = 1,
90380 + .pos_op = PASS_POS_INSERT_BEFORE
90381 + };
90382 +
90383 + if (!plugin_default_version_check(version, &gcc_version)) {
90384 + error(G_("incompatible gcc/plugin versions"));
90385 + return 1;
90386 + }
90387 +
90388 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
90389 +
90390 + for (i = 0; i < argc; ++i) {
90391 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
90392 + if (!argv[i].value) {
90393 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
90394 + continue;
90395 + }
90396 + track_frame_size = atoi(argv[i].value);
90397 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
90398 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
90399 + continue;
90400 + }
90401 + if (!strcmp(argv[i].key, "initialize-locals")) {
90402 + if (argv[i].value) {
90403 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
90404 + continue;
90405 + }
90406 + init_locals = true;
90407 + continue;
90408 + }
90409 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
90410 + }
90411 +
90412 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
90413 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
90414 +
90415 + return 0;
90416 +}
90417 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
90418 index 6789d78..4afd019e 100644
90419 --- a/tools/perf/util/include/asm/alternative-asm.h
90420 +++ b/tools/perf/util/include/asm/alternative-asm.h
90421 @@ -5,4 +5,7 @@
90422
90423 #define altinstruction_entry #
90424
90425 + .macro pax_force_retaddr rip=0, reload=0
90426 + .endm
90427 +
90428 #endif
90429 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
90430 index d617f69..6b445d2 100644
90431 --- a/virt/kvm/kvm_main.c
90432 +++ b/virt/kvm/kvm_main.c
90433 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
90434
90435 static cpumask_var_t cpus_hardware_enabled;
90436 static int kvm_usage_count = 0;
90437 -static atomic_t hardware_enable_failed;
90438 +static atomic_unchecked_t hardware_enable_failed;
90439
90440 struct kmem_cache *kvm_vcpu_cache;
90441 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
90442 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
90443 /* We can read the guest memory with __xxx_user() later on. */
90444 if (user_alloc &&
90445 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
90446 - !access_ok(VERIFY_WRITE,
90447 + !__access_ok(VERIFY_WRITE,
90448 (void __user *)(unsigned long)mem->userspace_addr,
90449 mem->memory_size)))
90450 goto out;
90451 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
90452
90453 if (r) {
90454 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
90455 - atomic_inc(&hardware_enable_failed);
90456 + atomic_inc_unchecked(&hardware_enable_failed);
90457 printk(KERN_INFO "kvm: enabling virtualization on "
90458 "CPU%d failed\n", cpu);
90459 }
90460 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
90461
90462 kvm_usage_count++;
90463 if (kvm_usage_count == 1) {
90464 - atomic_set(&hardware_enable_failed, 0);
90465 + atomic_set_unchecked(&hardware_enable_failed, 0);
90466 on_each_cpu(hardware_enable_nolock, NULL, 1);
90467
90468 - if (atomic_read(&hardware_enable_failed)) {
90469 + if (atomic_read_unchecked(&hardware_enable_failed)) {
90470 hardware_disable_all_nolock();
90471 r = -EBUSY;
90472 }
90473 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
90474 kvm_arch_vcpu_put(vcpu);
90475 }
90476
90477 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90478 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90479 struct module *module)
90480 {
90481 int r;
90482 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90483 if (!vcpu_align)
90484 vcpu_align = __alignof__(struct kvm_vcpu);
90485 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
90486 - 0, NULL);
90487 + SLAB_USERCOPY, NULL);
90488 if (!kvm_vcpu_cache) {
90489 r = -ENOMEM;
90490 goto out_free_3;
90491 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90492 if (r)
90493 goto out_free;
90494
90495 - kvm_chardev_ops.owner = module;
90496 - kvm_vm_fops.owner = module;
90497 - kvm_vcpu_fops.owner = module;
90498 + pax_open_kernel();
90499 + *(void **)&kvm_chardev_ops.owner = module;
90500 + *(void **)&kvm_vm_fops.owner = module;
90501 + *(void **)&kvm_vcpu_fops.owner = module;
90502 + pax_close_kernel();
90503
90504 r = misc_register(&kvm_dev);
90505 if (r) {